• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "mock_distributed_kv_data_manager.h"
17 #include "mock_single_kv_store.h"
18 
19 namespace OHOS {
20 namespace DistributedKv {
21 std::shared_ptr<IDistributedKvDataManager> IDistributedKvDataManager::kvDataMgr_ = nullptr;
22 
GetOrCreateDistributedKvDataManager()23 std::shared_ptr<IDistributedKvDataManager> IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()
24 {
25     if (!kvDataMgr_) {
26         kvDataMgr_ = std::make_shared<DistributedKvDataManagerMock>();
27     }
28     return kvDataMgr_;
29 }
30 
ReleaseDistributedKvDataManager()31 void IDistributedKvDataManager::ReleaseDistributedKvDataManager()
32 {
33     kvDataMgr_.reset();
34     kvDataMgr_ = nullptr;
35 }
36 
DistributedKvDataManager()37 DistributedKvDataManager::DistributedKvDataManager()
38 {}
39 
~DistributedKvDataManager()40 DistributedKvDataManager::~DistributedKvDataManager()
41 {}
42 
GetSingleKvStore(const Options & options,const AppId & appId,const StoreId & storeId,std::shared_ptr<SingleKvStore> & singleKvStore)43 Status DistributedKvDataManager::GetSingleKvStore(const Options &options, const AppId &appId, const StoreId &storeId,
44     std::shared_ptr<SingleKvStore> &singleKvStore)
45 {
46     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->GetSingleKvStore(
47         options, appId, storeId, singleKvStore);
48 }
49 
GetAllKvStoreId(const AppId & appId,std::vector<StoreId> & storeIds,int32_t subUser)50 Status DistributedKvDataManager::GetAllKvStoreId(const AppId &appId, std::vector<StoreId> &storeIds, int32_t subUser)
51 {
52     (void)subUser;
53     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->GetAllKvStoreId(appId, storeIds);
54 }
55 
CloseKvStore(const AppId & appId,const StoreId & storeId,int32_t subUser)56 Status DistributedKvDataManager::CloseKvStore(const AppId &appId, const StoreId &storeId, int32_t subUser)
57 {
58     (void)subUser;
59     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->CloseKvStore(appId, storeId);
60 }
61 
CloseKvStore(const AppId & appId,std::shared_ptr<SingleKvStore> & kvStore)62 Status DistributedKvDataManager::CloseKvStore(const AppId &appId, std::shared_ptr<SingleKvStore> &kvStore)
63 {
64     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->CloseKvStore(appId, kvStore);
65 }
66 
CloseAllKvStore(const AppId & appId,int32_t subUser)67 Status DistributedKvDataManager::CloseAllKvStore(const AppId &appId, int32_t subUser)
68 {
69     (void)subUser;
70     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->CloseAllKvStore(appId);
71 }
72 
DeleteKvStore(const AppId & appId,const StoreId & storeId,const std::string & path,int32_t subUser)73 Status DistributedKvDataManager::DeleteKvStore(const AppId &appId, const StoreId &storeId, const std::string &path,
74     int32_t subUser)
75 {
76     (void)subUser;
77     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->DeleteKvStore(appId, storeId, path);
78 }
79 
DeleteAllKvStore(const AppId & appId,const std::string & path,int32_t subUser)80 Status DistributedKvDataManager::DeleteAllKvStore(const AppId &appId, const std::string &path, int32_t subUser)
81 {
82     (void)subUser;
83     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->DeleteAllKvStore(appId, path);
84 }
85 
RegisterKvStoreServiceDeathRecipient(std::shared_ptr<KvStoreDeathRecipient> deathRecipient)86 void DistributedKvDataManager::RegisterKvStoreServiceDeathRecipient(
87     std::shared_ptr<KvStoreDeathRecipient> deathRecipient)
88 {
89     IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->RegisterKvStoreServiceDeathRecipient(
90         deathRecipient);
91 }
92 
UnRegisterKvStoreServiceDeathRecipient(std::shared_ptr<KvStoreDeathRecipient> deathRecipient)93 void DistributedKvDataManager::UnRegisterKvStoreServiceDeathRecipient(
94     std::shared_ptr<KvStoreDeathRecipient> deathRecipient)
95 {
96     IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->UnRegisterKvStoreServiceDeathRecipient(
97         deathRecipient);
98 }
99 
SetExecutors(std::shared_ptr<ExecutorPool> executors)100 void DistributedKvDataManager::SetExecutors(std::shared_ptr<ExecutorPool> executors)
101 {
102     IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->SetExecutors(
103         executors);
104 }
105 
SetEndpoint(std::shared_ptr<Endpoint> endpoint)106 Status DistributedKvDataManager::SetEndpoint(std::shared_ptr<Endpoint> endpoint)
107 {
108     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->SetEndpoint(endpoint);
109 }
110 
PutSwitch(const AppId & appId,const SwitchData & data)111 Status DistributedKvDataManager::PutSwitch(const AppId &appId, const SwitchData &data)
112 {
113     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->PutSwitch(appId, data);
114 }
115 
GetSwitch(const AppId & appId,const std::string & networkId)116 std::pair<Status, SwitchData> DistributedKvDataManager::GetSwitch(const AppId &appId, const std::string &networkId)
117 {
118     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->GetSwitch(appId, networkId);
119 }
120 
SubscribeSwitchData(const AppId & appId,std::shared_ptr<KvStoreObserver> observer)121 Status DistributedKvDataManager::SubscribeSwitchData(const AppId &appId, std::shared_ptr<KvStoreObserver> observer)
122 {
123     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->SubscribeSwitchData(appId, observer);
124 }
125 
UnsubscribeSwitchData(const AppId & appId,std::shared_ptr<KvStoreObserver> observer)126 Status DistributedKvDataManager::UnsubscribeSwitchData(const AppId &appId, std::shared_ptr<KvStoreObserver> observer)
127 {
128     return IDistributedKvDataManager::GetOrCreateDistributedKvDataManager()->UnsubscribeSwitchData(appId, observer);
129 }
130 }  // namespace DistributedKv
131 }  // namespace OHOS