1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H
18 
19 #include <memory>
20 
21 #include "cloud_download_callback.h"
22 #include "cloud_sync_callback.h"
23 #include "cloud_sync_common.h"
24 
25 namespace OHOS::FileManagement::CloudSync {
26 class CloudSyncManager {
27 public:
28     static CloudSyncManager &GetInstance();
29     /**
30      * @brief 注册
31      *
32      * @param callback 注册同步回调
33      * @return int32_t 同步返回执行结果
34      */
35     virtual int32_t RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,
36                                      const std::string &bundleName = "") = 0;
37     /**
38      * @brief 注册
39      *
40      * @param callback 卸载同步回调
41      * @return int32_t 返回执行结果
42      */
43     virtual int32_t UnRegisterCallback(const std::string &bundleName = "") = 0;
44     /**
45      * @brief 启动同步
46      *
47      * @return int32_t 同步返回执行结果
48      */
49     virtual int32_t StartSync(const std::string &bundleName = "") = 0;
50     /**
51      * @brief 启动同步
52      *
53      * @param forceFlag 是否强制继续同步,当前仅支持低电量下暂停后继续上传
54      * @param callback 注册同步回调
55      * @return int32_t 同步返回执行结果
56      */
57     virtual int32_t StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback) = 0;
58     /**
59      * @brief 触发同步
60      *
61      * @param bundleName 应用包名
62      * @param userId 用户ID
63      * @return int32_t 同步返回执行结果
64      */
65     virtual int32_t TriggerSync(const std::string &bundleName, const int32_t &userId) = 0;
66     /**
67      * @brief 停止同步
68      *
69      * @return int32_t 同步返回执行结果
70      */
71     virtual int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) = 0;
72     /**
73      * @brief 清理水位
74      *
75      * @return int32_t 同步返回执行结果
76      */
77     virtual int32_t ResetCursor(const std::string &bundleName = "") = 0;
78     /**
79      * @brief 切换应用云同步开关
80      *
81      * @param accoutId 账号ID
82      * @param bundleName 应用包名
83      * @param status 应用开关状态
84      * @return int32_t 同步返回执行结果
85      */
86     virtual int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) = 0;
87     /**
88      * @brief 云数据变化触发同步
89      *
90      * @param accoutId 账号ID
91      * @param bundleName 应用包名
92      * @return int32_t 同步返回执行结果
93      */
94     virtual int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) = 0;
95     virtual int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) = 0;
96     virtual int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) = 0;
97     virtual int32_t DisableCloud(const std::string &accoutId) = 0;
98     /**
99      * @brief 云账号退出选择保留或清除云数据
100      *
101      * @param accoutId 账号ID
102      * @param cleanOptions 说明云文件如何处理的方式
103      * @return int32_t 同步返回执行结果
104      */
105     virtual int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) = 0;
106     virtual int32_t StartDownloadFile(const std::string &path) = 0;
107     virtual int32_t StartFileCache(const std::string &path) = 0;
108     virtual int32_t StartFileCache(const std::vector<std::string> &pathVec, int64_t &downloadId,
109                                    std::bitset<FIELD_KEY_MAX_SIZE> fieldkey = FIELDKEY_CONTENT,
110                                    const std::shared_ptr<CloudDownloadCallback> downloadCallback = nullptr) = 0;
111     virtual int32_t StopDownloadFile(const std::string &path, bool needClean = false) = 0;
112     virtual int32_t StopFileCache(const int64_t &downloadId, bool needClean = false) = 0;
113     virtual int32_t RegisterDownloadFileCallback(const std::shared_ptr<CloudDownloadCallback> downloadCallback) = 0;
114     virtual int32_t UnregisterDownloadFileCallback() = 0;
115     virtual int32_t GetSyncTime(int64_t &syncTime, const std::string &bundleName = "") = 0;
116     virtual int32_t CleanCache(const std::string &uri) = 0;
117 };
118 } // namespace OHOS::FileManagement::CloudSync
119 
120 #endif // OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H
121