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 }; 38 enum PasswordType { 39 BACKUP_SECRET_KEY = 0, 40 SECRET_KEY = 1, 41 BUTTON, 42 }; 43 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.KVFeature"); 44 45 API_EXPORT KVDBService() = default; 46 47 API_EXPORT virtual ~KVDBService() = default; 48 49 virtual Status GetStoreIds(const AppId &appId, std::vector<StoreId> &storeIds) = 0; 50 virtual Status BeforeCreate(const AppId &appId, const StoreId &storeId, const Options &options) = 0; 51 virtual Status AfterCreate( 52 const AppId &appId, const StoreId &storeId, const Options &options, const std::vector<uint8_t> &password) = 0; 53 virtual Status Delete(const AppId &appId, const StoreId &storeId) = 0; 54 virtual Status Close(const AppId &appId, const StoreId &storeId) = 0; 55 virtual Status Sync(const AppId &appId, const StoreId &storeId, SyncInfo &syncInfo) = 0; 56 virtual Status RegServiceNotifier(const AppId &appId, sptr<IKVDBNotifier> notifier) = 0; 57 virtual Status UnregServiceNotifier(const AppId &appId) = 0; 58 virtual Status SetSyncParam(const AppId &appId, const StoreId &storeId, const KvSyncParam &syncParam) = 0; 59 virtual Status GetSyncParam(const AppId &appId, const StoreId &storeId, KvSyncParam &syncParam) = 0; 60 virtual Status EnableCapability(const AppId &appId, const StoreId &storeId) = 0; 61 virtual Status DisableCapability(const AppId &appId, const StoreId &storeId) = 0; 62 virtual Status SetCapability(const AppId &appId, const StoreId &storeId, const std::vector<std::string> &local, 63 const std::vector<std::string> &remote) = 0; 64 virtual Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 65 virtual Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 66 virtual Status Subscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 67 virtual Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 68 virtual Status GetBackupPassword( 69 const AppId &appId, const StoreId &storeId, std::vector<uint8_t> &password, int32_t passwordType) = 0; 70 virtual Status CloudSync(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 71 virtual Status NotifyDataChange(const AppId &appId, const StoreId &storeId, uint64_t delay) = 0; 72 virtual Status PutSwitch(const AppId &appId, const SwitchData &data) = 0; 73 virtual Status GetSwitch(const AppId &appId, const std::string &networkId, SwitchData &data) = 0; 74 virtual Status SubscribeSwitchData(const AppId &appId) = 0; 75 virtual Status UnsubscribeSwitchData(const AppId &appId) = 0; 76 virtual Status SetConfig(const AppId &appId, const StoreId &storeId, const StoreConfig &storeConfig) = 0; 77 virtual Status RemoveDeviceData(const AppId &appId, const StoreId &storeId, const std::string &device) = 0; 78 }; 79 } // namespace OHOS::DistributedKv 80 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H