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 RegisterSyncCallback(const AppId &appId, sptr<IKvStoreSyncCallback> callback) = 0; 53 virtual Status UnregisterSyncCallback(const AppId &appId) = 0; 54 virtual Status SetSyncParam(const AppId &appId, const StoreId &storeId, const KvSyncParam &syncParam) = 0; 55 virtual Status GetSyncParam(const AppId &appId, const StoreId &storeId, KvSyncParam &syncParam) = 0; 56 virtual Status EnableCapability(const AppId &appId, const StoreId &storeId) = 0; 57 virtual Status DisableCapability(const AppId &appId, const StoreId &storeId) = 0; 58 virtual Status SetCapability(const AppId &appId, const StoreId &storeId, const std::vector<std::string> &local, 59 const std::vector<std::string> &remote) = 0; 60 virtual Status AddSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 61 virtual Status RmvSubscribeInfo(const AppId &appId, const StoreId &storeId, const SyncInfo &syncInfo) = 0; 62 virtual Status Subscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 63 virtual Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr<IKvStoreObserver> observer) = 0; 64 virtual Status GetBackupPassword( 65 const AppId &appId, const StoreId &storeId, std::vector<uint8_t> &password) = 0; 66 67 protected: 68 enum TransId : int32_t { 69 TRANS_HEAD, 70 TRANS_GET_STORE_IDS = TRANS_HEAD, 71 TRANS_BEFORE_CREATE, 72 TRANS_AFTER_CREATE, 73 TRANS_DELETE, 74 TRANS_SYNC, 75 TRANS_REGISTER_CALLBACK, 76 TRANS_UNREGISTER_CALLBACK, 77 TRANS_SET_SYNC_PARAM, 78 TRANS_GET_SYNC_PARAM, 79 TRANS_ENABLE_CAP, 80 TRANS_DISABLE_CAP, 81 TRANS_SET_CAP, 82 TRANS_ADD_SUB, 83 TRANS_RMV_SUB, 84 TRANS_SUB, 85 TRANS_UNSUB, 86 TRANS_GET_PASSWORD, 87 TRANS_BUTT, 88 }; 89 }; 90 } // namespace OHOS::DistributedKv 91 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H 92