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 "communication_provider.h" 20 #include <set> 21 #include "app_device_handler.h" 22 #include "app_pipe_mgr.h" 23 24 namespace OHOS { 25 namespace AppDistributedKv { 26 class CommunicationProviderImpl : public CommunicationProvider { 27 public: 28 CommunicationProviderImpl(AppPipeMgr &appPipeMgr, AppDeviceHandler &deviceHandler); 29 30 virtual ~CommunicationProviderImpl(); 31 32 // add DeviceChangeListener to watch device change; 33 Status StartWatchDeviceChange(const AppDeviceStatusChangeListener *observer, const PipeInfo &pipeInfo) override; 34 35 // stop watching device change; 36 Status StopWatchDeviceChange(const AppDeviceStatusChangeListener *observer, const PipeInfo &pipeInfo) override; 37 38 // add DataChangeListener to watch data change; 39 Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; 40 41 // stop watching data change; 42 Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; 43 44 // Send data to other device, function will be called back after sent to notify send result. 45 Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, 46 const MessageInfo &info) override; 47 48 // Get online deviceList 49 std::vector<DeviceInfo> GetDeviceList() const override; 50 51 // Get local device information 52 DeviceInfo GetLocalDevice() const override; 53 54 // start 1 server to listen data from other devices; 55 Status Start(const PipeInfo &pipeInfo) override; 56 57 // stop server 58 Status Stop(const PipeInfo &pipeInfo) override; 59 60 bool IsSameStartedOnPeer(const PipeInfo &pipeInfo, const DeviceId &peer) const override; 61 std::string GetUuidByNodeId(const std::string &nodeId) const override; 62 std::string GetUdidByNodeId(const std::string &nodeId) const override; 63 DeviceInfo GetLocalBasicInfo() const override; 64 std::vector<DeviceInfo> GetRemoteNodesBasicInfo() const override; 65 std::string ToNodeId(const std::string &id) const override; 66 void SetMessageTransFlag(const struct PipeInfo &pipeInfo, bool flag) override; 67 protected: 68 virtual Status Initialize(); 69 70 static std::mutex mutex_; 71 private: 72 AppPipeMgr &appPipeMgr_; 73 AppDeviceHandler &appDeviceHandler_; 74 }; 75 } // namespace AppDistributedKv 76 } // namespace OHOS 77 #endif /* DISTRIBUTEDDATA_SRC_COMMUNICATION_PROVIDER_IMPL_H */ 78