• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICE_PROXY_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H
18 
19 #include "iremote_proxy.h"
20 #include "system_ability_load_callback_stub.h"
21 
22 #include "i_cloud_sync_service.h"
23 
24 namespace OHOS::FileManagement::CloudSync {
25 class CloudSyncServiceProxy : public IRemoteProxy<ICloudSyncService> {
26 public:
CloudSyncServiceProxy(const sptr<IRemoteObject> & impl)27     explicit CloudSyncServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ICloudSyncService>(impl) {}
~CloudSyncServiceProxy()28     ~CloudSyncServiceProxy() override {}
29 
30     static sptr<ICloudSyncService> GetInstance();
31     static void InvaildInstance();
32     int32_t UnRegisterCallbackInner() override;
33     int32_t RegisterCallbackInner(const sptr<IRemoteObject> &remoteObject) override;
34     int32_t StartSyncInner(bool forceFlag) override;
35     int32_t TriggerSyncInner(const std::string &bundleName, const int32_t &userId) override;
36     int32_t StopSyncInner() override;
37     int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) override;
38     int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) override;
39     int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override;
40     int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) override;
41     int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override;
42     int32_t DisableCloud(const std::string &accoutId) override;
43     int32_t StartDownloadFile(const std::string &uri) override;
44     int32_t StartFileCache(const std::string &uri) override;
45     int32_t StopDownloadFile(const std::string &uri) override;
46     int32_t RegisterDownloadFileCallback(const sptr<IRemoteObject> &downloadCallback) override;
47     int32_t UnregisterDownloadFileCallback() override;
48     int32_t UploadAsset(const int32_t userId, const std::string &request, std::string &result) override;
49     int32_t DownloadFile(const int32_t userId, const std::string &bundleName, AssetInfoObj &assetInfoObj) override;
50     int32_t DownloadAsset(const uint64_t taskId, const int32_t userId,
51                           const std::string &bundleName,
52                           const std::string &networkId,
53                           AssetInfoObj &assetInfoObj) override;
54     int32_t RegisterDownloadAssetCallback(const sptr<IRemoteObject> &remoteObject) override;
55     int32_t DeleteAsset(const int32_t userId, const std::string &uri) override;
56     int32_t GetSyncTimeInner(int64_t &syncTime) override;
57     int32_t CleanCacheInner(const std::string &uri) override;
58 
59     class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub {
60     public:
61         void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
62         void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
63 
64         std::condition_variable proxyConVar_;
65         std::atomic<bool> isLoadSuccess_{false};
66     };
67 
68 private:
69     static inline std::mutex proxyMutex_;
70     static inline std::mutex downloadMutex_;
71     static inline sptr<ICloudSyncService> serviceProxy_;
72     static inline BrokerDelegator<CloudSyncServiceProxy> delegator_;
73 };
74 } // namespace OHOS::FileManagement::CloudSync
75 
76 #endif // OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H
77