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 DISTRIBUTEDDATAFWK_SRC_PIPE_HANDLER_H 17 #define DISTRIBUTEDDATAFWK_SRC_PIPE_HANDLER_H 18 19 #include <set> 20 #include <mutex> 21 #include <string> 22 #include <map> 23 #include "log_print.h" 24 #include "reporter.h" 25 #include "app_data_change_listener.h" 26 #include "softbus_adapter.h" 27 28 #ifdef LOG_TAG 29 #undef LOG_TAG 30 #endif 31 #define LOG_TAG "AppPipeHandler" 32 33 namespace OHOS { 34 namespace AppDistributedKv { 35 class AppPipeHandler { 36 public: 37 ~AppPipeHandler(); 38 explicit AppPipeHandler(const PipeInfo &pipeInfo); 39 40 // add DataChangeListener to watch data change; 41 Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo); 42 // stop DataChangeListener to watch data change; 43 Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo); 44 // Send data to other device, function will be called back after sent to notify send result. 45 std::pair<Status, int32_t> SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, 46 uint32_t totalLength, const MessageInfo &info); 47 bool IsSameStartedOnPeer(const struct PipeInfo &pipeInfo, const struct DeviceId &peer); 48 49 void SetMessageTransFlag(const PipeInfo &pipeInfo, bool flag); 50 51 int CreateSessionServer(const std::string &sessionName) const; 52 53 int RemoveSessionServer(const std::string &sessionName) const; 54 private: 55 PipeInfo pipeInfo_; 56 std::shared_ptr<SoftBusAdapter> softbusAdapter_ {}; 57 }; 58 } // namespace AppDistributedKv 59 } // namespace OHOS 60 #undef LOG_TAG 61 #endif /* DISTRIBUTEDDATAFWK_SRC_PIPE_HANDLER_H */ 62