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 #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_CLIENT_H 16 #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_CLIENT_H 17 #include <functional> 18 #include "concurrent_map.h" 19 #include "iremote_broker.h" 20 #include "iremote_proxy.h" 21 #include "kvdb_service.h" 22 #include "kvdb_notifier_client.h" 23 #include "task_executor.h" 24 namespace OHOS::DistributedKv { 25 class KVDBServiceProxy : public KVDBService, public IRemoteBroker { 26 public: 27 using KVDBService::KVDBService; 28 }; 29 30 class KVDBServiceClient : public IRemoteProxy<KVDBServiceProxy> { 31 public: 32 static std::shared_ptr<KVDBServiceClient> GetInstance(); 33 Status GetStoreIds(const AppId &appId, int32_t subUser, std::vector<StoreId> &storeIds) override; 34 Status BeforeCreate(const AppId &appId, const StoreId &storeId, const Options &options) override; 35 Status AfterCreate(const AppId &appId, const StoreId &storeId, const Options &options, 36 const std::vector<uint8_t> &password) override; 37 Status Delete(const AppId &appId, const StoreId &storeId, int32_t subUser) override; 38 Status Close(const AppId &appId, const StoreId &storeId, int32_t subUser) override; 39 Status Sync(const AppId &appId, const StoreId &storeId, int32_t subUser, SyncInfo &syncInfo) override; 40 Status RegServiceNotifier(const AppId &appId, sptr<IKVDBNotifier> notifier) override; 41 Status UnregServiceNotifier(const AppId &appIdd) override; 42 Status SetSyncParam(const AppId &appId, const StoreId &storeId, int32_t subUser, 43 const KvSyncParam &syncParam) override; 44 Status GetSyncParam(const AppId &appId, const StoreId &storeId, int32_t subUser, KvSyncParam &syncParam) override; 45 Status EnableCapability(const AppId &appId, const StoreId &storeId, int32_t subUser) override; 46 Status DisableCapability(const AppId &appId, const StoreId &storeId, int32_t subUser) override; 47 Status SetCapability(const AppId &appId, const StoreId &storeId, int32_t subUser, 48 const std::vector<std::string> &local, const std::vector<std::string> &remote) override; 49 Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, int32_t subUser, 50 const SyncInfo &syncInfo) override; 51 Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, int32_t subUser, 52 const SyncInfo &syncInfo) override; 53 Status Subscribe(const AppId &appId, const StoreId &storeId, int32_t subUser, 54 sptr<IKvStoreObserver> observer) override; 55 Status Unsubscribe(const AppId &appId, const StoreId &storeId, int32_t subUser, 56 sptr<IKvStoreObserver> observer) override; 57 Status GetBackupPassword(const AppId &appId, const StoreId &storeId, int32_t subUser, 58 std::vector<std::vector<uint8_t>> &passwords, int32_t passwordType) override; 59 Status CloudSync(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) override; 60 Status NotifyDataChange(const AppId &appId, const StoreId &storeId, uint64_t delay) override; 61 Status PutSwitch(const AppId &appId, const SwitchData &data) override; 62 Status GetSwitch(const AppId &appId, const std::string &networkId, SwitchData &data) override; 63 Status SubscribeSwitchData(const AppId &appId) override; 64 Status UnsubscribeSwitchData(const AppId &appId) override; 65 Status SetConfig(const AppId &appId, const StoreId &storeId, const StoreConfig &storeConfig) override; 66 Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, int32_t subUser, 67 const std::string &device) override; 68 69 sptr<KVDBNotifierClient> GetServiceAgent(const AppId &appId); 70 71 protected: 72 explicit KVDBServiceClient(const sptr<IRemoteObject> &object); 73 virtual ~KVDBServiceClient() = default; 74 75 private: 76 class ServiceDeath : public KvStoreDeathRecipient { 77 public: 78 ServiceDeath() = default; 79 virtual ~ServiceDeath() = default; 80 void OnRemoteDied() override; 81 }; 82 static std::mutex mutex_; 83 static std::shared_ptr<KVDBServiceClient> instance_; 84 static std::atomic_bool isWatched_; 85 sptr<IRemoteObject> remote_; 86 std::mutex agentMtx_; 87 sptr<KVDBNotifierClient> serviceAgent_; 88 }; 89 } // namespace OHOS::DistributedKv 90 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_CLIENT_H