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 "kvstore_sync_callback_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, 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) override; 38 Status Sync(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) override; 39 Status RegisterSyncCallback(const AppId &appId, sptr<IKvStoreSyncCallback> callback) override; 40 Status UnregisterSyncCallback(const AppId &appIdd) override; 41 Status SetSyncParam(const AppId &appId, const StoreId &storeId, const KvSyncParam &syncParam) override; 42 Status GetSyncParam(const AppId &appId, const StoreId &storeId, KvSyncParam &syncParam) override; 43 Status EnableCapability(const AppId &appId, const StoreId &storeId) override; 44 Status DisableCapability(const AppId &appId, const StoreId &storeId) override; 45 Status SetCapability(const AppId &appId, const StoreId &storeId, const std::vector<std::string> &local, 46 const std::vector<std::string> &remote) override; 47 Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) override; 48 Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) override; 49 Status Subscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) override; 50 Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) override; 51 Status GetBackupPassword(const AppId &appId, const StoreId &storeId, std::vector<uint8_t> &password) override; 52 sptr<KvStoreSyncCallbackClient> GetSyncAgent(const AppId &appId); 53 54 protected: 55 explicit KVDBServiceClient(const sptr<IRemoteObject> &object); 56 virtual ~KVDBServiceClient() = default; 57 58 private: 59 class ServiceDeath : public KvStoreDeathRecipient { 60 public: 61 ServiceDeath() = default; 62 virtual ~ServiceDeath() = default; 63 void OnRemoteDied() override; 64 }; 65 static std::mutex mutex_; 66 static std::shared_ptr<KVDBServiceClient> instance_; 67 static std::atomic_bool isWatched_; 68 sptr<IRemoteObject> remote_; 69 std::mutex agentMtx_; 70 sptr<KvStoreSyncCallbackClient> syncAgent_; 71 }; 72 } // namespace OHOS::DistributedKv 73 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_CLIENT_H 74