1 /* 2 * Copyright (c) 2021 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 16 #ifndef END_POINT_H 17 #define END_POINT_H 18 19 #include <tuple> 20 #include <map> 21 #include <mutex> 22 #include <functional> 23 #include "types.h" 24 25 namespace OHOS { 26 namespace DistributedKv { 27 struct StoreBriefInfo { 28 std::string userId; 29 std::string appId; 30 std::string storeId; 31 std::string deviceId; 32 int32_t instanceId = 0; 33 std::map<std::string, std::string> extraConditions; 34 }; 35 36 class API_EXPORT Endpoint { 37 public: 38 39 using RecvHandler = std::function<void(const std::string &identifier, const uint8_t *data, uint32_t length)>; 40 41 /** 42 * @brief Constructor. 43 */ 44 API_EXPORT Endpoint() = default; 45 46 /** 47 * @brief Destructor. 48 */ ~Endpoint()49 API_EXPORT virtual ~Endpoint() {}; 50 51 /** 52 * @brief Start the Process Communicator. 53 * @param processLabel Identifies current process. 54 * @return Return SUCCESS for success, others for failure. 55 */ 56 virtual Status Start() = 0; 57 58 /** 59 * @brief Start the Process Communicator. 60 * @return Return SUCCESS for success, others for failure. 61 */ 62 virtual Status Stop() = 0; 63 64 /** 65 * @brief Close all opened kvstores for this appId. 66 * @param callback Callback to register data change. 67 * @return Return SUCCESS for success, others for failure. 68 */ 69 virtual Status RegOnDataReceive(const RecvHandler &callback) = 0; 70 71 /** 72 * @brief Used to send data to the softbus. 73 * @param dstDevInfo Target device ID. 74 * @param data Pointer to data to be send. 75 * @param length Data length. 76 * @return Return SUCCESS for success, others for failure. 77 */ 78 virtual Status SendData(const std::string &dtsIdentifier, const uint8_t *data, uint32_t length) = 0; 79 80 /** 81 * @brief Obtains the size of maximum unit sent by the bottom layer. 82 * @param devInfo Remote device ID. 83 * @return Data size. 84 */ 85 virtual uint32_t GetMtuSize(const std::string &identifier) = 0; 86 87 /** 88 * @brief Obtains the ID of the loacl device info. 89 * @return loacl device info. 90 */ 91 virtual std::string GetLocalDeviceInfos() = 0; 92 93 /** 94 * @brief Determines whether the device has the capability of data of this level. 95 * @param devId Target device ID. 96 * @param option Security params. 97 * @return Return true for success, false for failure. 98 */ 99 virtual bool IsSaferThanDevice(int securityLevel, const std::string &devId) = 0; 100 101 /** 102 * @brief Verify sync permission. 103 * @param param Params for sync permission. 104 * @param flag The direction of sync. 105 * @return Return true for success, false for failure. 106 */ 107 virtual bool HasDataSyncPermission(const StoreBriefInfo ¶m, uint8_t flag) = 0; 108 }; 109 } // namespace DistributedKv 110 } // namespace OHOS 111 #endif // END_POINT_H 112