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_COMMUNICATION_PROVIDER_H 17 #define DISTRIBUTEDDATA_COMMUNICATION_PROVIDER_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "app_data_change_listener.h" 23 #include "app_device_status_change_listener.h" 24 #include "app_types.h" 25 #include "visibility.h" 26 namespace OHOS { 27 namespace ObjectStore { 28 class CommunicationProvider { 29 public: 30 // constructor CommunicationProvider()31 KVSTORE_API CommunicationProvider(){}; 32 33 // destructor ~CommunicationProvider()34 KVSTORE_API virtual ~CommunicationProvider(){}; 35 36 // add DeviceChangeListener to watch device change 37 KVSTORE_API 38 virtual Status StartWatchDeviceChange(const AppDeviceStatusChangeListener *observer, const PipeInfo &pipeInfo) = 0; 39 40 // stop DeviceChangeListener to watch device change 41 KVSTORE_API 42 virtual Status StopWatchDeviceChange(const AppDeviceStatusChangeListener *observer, const PipeInfo &pipeInfo) = 0; 43 44 // add DataChangeListener to watch data change 45 KVSTORE_API 46 virtual Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) = 0; 47 48 // stop DataChangeListener to watch data change 49 KVSTORE_API virtual Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) = 0; 50 51 // Send data to other device, function will be called back after sent to notify send result 52 KVSTORE_API 53 virtual Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &DataInfo, 54 uint32_t totalLength, const MessageInfo &info = { MessageType::DEFAULT }) = 0; 55 56 // Get online deviceList 57 KVSTORE_API virtual std::vector<DeviceInfo> GetDeviceList() const = 0; 58 59 // Get local device information 60 KVSTORE_API virtual DeviceInfo GetLocalDevice() const = 0; 61 62 // start one server to listen data from other devices; 63 KVSTORE_API virtual Status Start(const PipeInfo &pipeInfo) = 0; 64 65 // stop server 66 KVSTORE_API virtual Status Stop(const PipeInfo &pipeInfo) = 0; 67 68 // user should use this method to get instance of CommunicationProvider; 69 KVSTORE_API static CommunicationProvider &GetInstance(); 70 71 // check peer device pipeInfo Process 72 KVSTORE_API virtual bool IsSameStartedOnPeer(const PipeInfo &pipeInfo, const DeviceId &peer) const = 0; 73 }; 74 } // namespace ObjectStore 75 } // namespace OHOS 76 #endif // DISTRIBUTEDDATA_COMMUNICATION_PROVIDER_H 77