• 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 BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_PREFERENCES_DATABASE_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_PREFERENCES_DATABASE_H
18 
19 #include <mutex>
20 #include <string>
21 #include <vector>
22 
23 #include "distributed_kv_data_manager.h"
24 #include "singleton.h"
25 
26 #include "distributed_database_callback.h"
27 #include "distributed_device_callback.h"
28 #include "distributed_flow_control.h"
29 
30 namespace OHOS {
31 namespace Notification {
32 class DistributedPreferencesDatabase : private DistributedFlowControl {
33 public:
34     using Entry = DistributedKv::Entry;
35 
36     DistributedPreferencesDatabase();
37     ~DistributedPreferencesDatabase();
38 
39     bool PutToDistributedDB(const std::string &key, const std::string &value);
40     bool GetFromDistributedDB(const std::string &key, std::string &value);
41     bool GetEntriesFromDistributedDB(const std::string &prefixKey, std::vector<Entry> &entries);
42     bool DeleteToDistributedDB(const std::string &key);
43     bool ClearDatabase(void);
44 
45 private:
46     void GetKvDataManager(void);
47     bool CheckKvDataManager(void);
48     void GetKvStore(void);
49     bool CheckKvStore(void);
50 
51 private:
52     std::mutex mutex_;
53     std::unique_ptr<DistributedKv::DistributedKvDataManager> kvDataManager_;
54     std::shared_ptr<DistributedKv::SingleKvStore> kvStore_;
55 
56     DISALLOW_COPY_AND_MOVE(DistributedPreferencesDatabase);
57 };
58 }  // namespace Notification
59 }  // namespace OHOS
60 
61 #endif /* BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_DATABASE_H */