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