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 DISTRIBUTEDDATA_SRC_COMMUNICATION_PROVIDER_IMPL_H 17 #define DISTRIBUTEDDATA_SRC_COMMUNICATION_PROVIDER_IMPL_H 18 19 #include <set> 20 21 #include "app_pipe_mgr.h" 22 #include "communication_provider.h" 23 24 namespace OHOS { 25 namespace AppDistributedKv { 26 class CommunicationProviderImpl : public CommunicationProvider { 27 public: 28 explicit CommunicationProviderImpl(AppPipeMgr &appPipeMgr); 29 30 virtual ~CommunicationProviderImpl(); 31 32 // add DataChangeListener to watch data change; 33 Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; 34 35 // stop watching data change; 36 Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; 37 38 // Send data to other device, function will be called back after sent to notify send result. 39 std::pair<Status, int32_t> SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, 40 uint32_t totalLength, const MessageInfo &info) override; 41 42 // start 1 server to listen data from other devices; 43 Status Start(const PipeInfo &pipeInfo) override; 44 45 // stop server 46 Status Stop(const PipeInfo &pipeInfo) override; 47 48 bool IsSameStartedOnPeer(const PipeInfo &pipeInfo, const DeviceId &peer) const override; 49 void SetMessageTransFlag(const struct PipeInfo &pipeInfo, bool flag) override; 50 51 Status Broadcast(const PipeInfo &pipeInfo, const LevelInfo &levelInfo) override; 52 int32_t ListenBroadcastMsg(const PipeInfo &pipeInfo, 53 std::function<void(const std::string &, const LevelInfo &)> listener) override; 54 55 protected: 56 virtual Status Initialize(); 57 58 static std::mutex mutex_; 59 60 private: 61 AppPipeMgr &appPipeMgr_; 62 }; 63 } // namespace AppDistributedKv 64 } // namespace OHOS 65 #endif /* DISTRIBUTEDDATA_SRC_COMMUNICATION_PROVIDER_IMPL_H */ 66