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