• 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_H
16 #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H
17 #include <limits>
18 #include <memory>
19 #include "ikvstore_observer.h"
20 #include "ikvdb_notifier.h"
21 #include "iremote_broker.h"
22 #include "kvstore_death_recipient.h"
23 #include "single_kvstore.h"
24 #include "types.h"
25 namespace OHOS::DistributedKv {
26 class KVDBService {
27 public:
28     using SingleKVStore = SingleKvStore;
29     struct SyncInfo {
30         uint64_t seqId = std::numeric_limits<uint64_t>::max();
31         int32_t mode = PUSH_PULL;
32         uint32_t delay = 0;
33         std::vector<std::string> devices;
34         std::string query;
35         uint64_t syncId = 0;
36         int32_t triggerMode = 0;
37         bool isRetry = true;
38     };
39     enum PasswordType {
40         BACKUP_SECRET_KEY = 0,
41         SECRET_KEY = 1,
42         BUTTON,
43     };
44     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.KVFeature");
45 
46     API_EXPORT KVDBService() = default;
47 
48     API_EXPORT virtual ~KVDBService() = default;
49 
50     virtual Status GetStoreIds(const AppId &appId, int32_t subUser, std::vector<StoreId> &storeIds) = 0;
51     virtual Status BeforeCreate(const AppId &appId, const StoreId &storeId, const Options &options) = 0;
52     virtual Status AfterCreate(
53         const AppId &appId, const StoreId &storeId, const Options &options, const std::vector<uint8_t> &password) = 0;
54     virtual Status Delete(const AppId &appId, const StoreId &storeId, int32_t subUser) = 0;
55     virtual Status Close(const AppId &appId, const StoreId &storeId, int32_t subUser) = 0;
56     virtual Status Sync(const AppId &appId, const StoreId &storeId, int32_t subUser, SyncInfo &syncInfo) = 0;
57     virtual Status RegServiceNotifier(const AppId &appId, sptr<IKVDBNotifier> notifier) = 0;
58     virtual Status UnregServiceNotifier(const AppId &appId) = 0;
59     virtual Status SetSyncParam(const AppId &appId, const StoreId &storeId, int32_t subUser,
60         const KvSyncParam &syncParam) = 0;
61     virtual Status GetSyncParam(const AppId &appId, const StoreId &storeId, int32_t subUser,
62         KvSyncParam &syncParam) = 0;
63     virtual Status EnableCapability(const AppId &appId, const StoreId &storeId, int32_t subUser) = 0;
64     virtual Status DisableCapability(const AppId &appId, const StoreId &storeId, int32_t subUser) = 0;
65     virtual Status SetCapability(const AppId &appId, const StoreId &storeId, int32_t subUser,
66         const std::vector<std::string> &local, const std::vector<std::string> &remote) = 0;
67     virtual Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, int32_t subUser,
68         const SyncInfo &syncInfo) = 0;
69     virtual Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, int32_t subUser,
70         const SyncInfo &syncInfo) = 0;
71     virtual Status Subscribe(const AppId &appId, const StoreId &storeId, int32_t subUser,
72         sptr<IKvStoreObserver> observer) = 0;
73     virtual Status Unsubscribe(const AppId &appId, const StoreId &storeId, int32_t subUser,
74         sptr<IKvStoreObserver> observer) = 0;
75     virtual Status GetBackupPassword(const AppId &appId, const StoreId &storeId, int32_t subUser,
76         std::vector<std::vector<uint8_t>> &passwords, int32_t passwordType) = 0;
77     virtual Status CloudSync(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0;
78     virtual Status NotifyDataChange(const AppId &appId, const StoreId &storeId, uint64_t delay) = 0;
79     virtual Status PutSwitch(const AppId &appId, const SwitchData &data) = 0;
80     virtual Status GetSwitch(const AppId &appId, const std::string &networkId, SwitchData &data) = 0;
81     virtual Status SubscribeSwitchData(const AppId &appId) = 0;
82     virtual Status UnsubscribeSwitchData(const AppId &appId) = 0;
83     virtual Status SetConfig(const AppId &appId, const StoreId &storeId, const StoreConfig &storeConfig) = 0;
84     virtual Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, int32_t subUser,
85         const std::string &device) = 0;
86 };
87 } // namespace OHOS::DistributedKv
88 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H