• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cloud_file_core.h"
17 
18 #include <memory>
19 #include <sys/types.h>
20 
21 #include "cloud_sync_manager.h"
22 #include "dfs_error.h"
23 #include "utils_log.h"
24 
25 namespace OHOS::FileManagement::CloudSync {
26 using namespace std;
27 
Constructor()28 FsResult<CloudFileCore *> CloudFileCore::Constructor()
29 {
30     std::unique_ptr<CloudFileCore> cloudfile = std::make_unique<CloudFileCore>();
31     return FsResult<CloudFileCore *>::Success(cloudfile.release());
32 }
33 
GetCallbackImpl(bool isInit)34 std::shared_ptr<CloudDownloadCallbackImplAni> CloudFileCore::GetCallbackImpl(bool isInit)
35 {
36     if (callback_ == nullptr && isInit) {
37         callback_ = std::make_shared<CloudDownloadCallbackImplAni>();
38     }
39     return callback_;
40 }
41 
DoStart(const string & uri)42 FsResult<void> CloudFileCore::DoStart(const string &uri)
43 {
44     LOGI("Start begin");
45     auto callbackImpl = GetCallbackImpl(true);
46     int32_t ret = callbackImpl->StartDownloadInner(uri);
47     if (ret != E_OK) {
48         LOGE("Start Download failed! ret = %{public}d", ret);
49         return FsResult<void>::Error(Convert2ErrNum(ret));
50     }
51 
52     LOGI("Start Download Success!");
53     return FsResult<void>::Success();
54 }
55 
DoOn(const string & event,const shared_ptr<CloudDownloadCallbackImplAni> callback)56 FsResult<void> CloudFileCore::DoOn(const string &event, const shared_ptr<CloudDownloadCallbackImplAni> callback)
57 {
58     return FsResult<void>::Success();
59 }
60 
DoOff(const string & event,const optional<shared_ptr<CloudDownloadCallbackImplAni>> & callback)61 FsResult<void> CloudFileCore::DoOff(const string &event,
62                                     const optional<shared_ptr<CloudDownloadCallbackImplAni>> &callback)
63 {
64     return FsResult<void>::Success();
65 }
66 
DoStop(const string & uri,bool needClean)67 FsResult<void> CloudFileCore::DoStop(const string &uri, bool needClean)
68 {
69     LOGI("Stop begin");
70     auto callbackImpl = GetCallbackImpl(false);
71     if (callbackImpl == nullptr) {
72         LOGE("Failed to stop download, callback is null!");
73         return FsResult<void>::Error(E_INVAL_ARG);
74     }
75     int32_t ret = callbackImpl->StopDownloadInner(uri);
76     if (ret != E_OK) {
77         LOGE("Stop Download failed! ret = %{public}d", ret);
78         return FsResult<void>::Error(Convert2ErrNum(ret));
79     }
80 
81     LOGI("Stop Download Success!");
82     return FsResult<void>::Success();
83 }
84 } // namespace OHOS::FileManagement::CloudSync