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 "ikvstore_sync_callback.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 }; 36 struct DevBrief { 37 std::string uuid; 38 std::string networkId; 39 }; 40 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.KVFeature"); 41 42 API_EXPORT KVDBService() = default; 43 44 API_EXPORT virtual ~KVDBService() = default; 45 46 virtual Status GetStoreIds(const AppId &appId, std::vector<StoreId> &storeIds) = 0; 47 virtual Status BeforeCreate(const AppId &appId, const StoreId &storeId, const Options &options) = 0; 48 virtual Status AfterCreate( 49 const AppId &appId, const StoreId &storeId, const Options &options, const std::vector<uint8_t> &password) = 0; 50 virtual Status Delete(const AppId &appId, const StoreId &storeId) = 0; 51 virtual Status Sync(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 52 virtual Status SyncExt(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 53 virtual Status RegisterSyncCallback(const AppId &appId, sptr<IKvStoreSyncCallback> callback) = 0; 54 virtual Status UnregisterSyncCallback(const AppId &appId) = 0; 55 virtual Status SetSyncParam(const AppId &appId, const StoreId &storeId, const KvSyncParam &syncParam) = 0; 56 virtual Status GetSyncParam(const AppId &appId, const StoreId &storeId, KvSyncParam &syncParam) = 0; 57 virtual Status EnableCapability(const AppId &appId, const StoreId &storeId) = 0; 58 virtual Status DisableCapability(const AppId &appId, const StoreId &storeId) = 0; 59 virtual Status SetCapability(const AppId &appId, const StoreId &storeId, const std::vector<std::string> &local, 60 const std::vector<std::string> &remote) = 0; 61 virtual Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 62 virtual Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 63 virtual Status Subscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 64 virtual Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 65 virtual Status GetBackupPassword( 66 const AppId &appId, const StoreId &storeId, std::vector<uint8_t> &password) = 0; 67 }; 68 } // namespace OHOS::DistributedKv 69 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H 70