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 virtual DevBrief GetLocalDevice() = 0; 67 virtual std::vector<DevBrief> GetRemoteDevices() = 0; 68 69 protected: 70 enum TransId : int32_t { 71 TRANS_HEAD, 72 TRANS_GET_STORE_IDS = TRANS_HEAD, 73 TRANS_BEFORE_CREATE, 74 TRANS_AFTER_CREATE, 75 TRANS_DELETE, 76 TRANS_SYNC, 77 TRANS_REGISTER_CALLBACK, 78 TRANS_UNREGISTER_CALLBACK, 79 TRANS_SET_SYNC_PARAM, 80 TRANS_GET_SYNC_PARAM, 81 TRANS_ENABLE_CAP, 82 TRANS_DISABLE_CAP, 83 TRANS_SET_CAP, 84 TRANS_ADD_SUB, 85 TRANS_RMV_SUB, 86 TRANS_SUB, 87 TRANS_UNSUB, 88 TRANS_GET_PASSWORD, 89 TRANS_NO_APPID_BEGIN, 90 TRANS_GET_LOCAL_DEVICE = TRANS_NO_APPID_BEGIN, 91 TRANS_GET_REMOTE_DEVICES, 92 TRANS_NO_APPID_END, 93 TRANS_BUTT = TRANS_NO_APPID_END, 94 }; 95 }; 96 } // namespace OHOS::DistributedKv 97 #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_KVDB_SERVICE_H 98