• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMUNICATION_PROVIDER_H
17 #define DISTRIBUTEDDATA_COMMUNICATION_PROVIDER_H
18 
19 #include <functional>
20 #include <memory>
21 #include <vector>
22 
23 #include "app_data_change_listener.h"
24 #include "app_device_change_listener.h"
25 #include "idevice_query.h"
26 namespace OHOS {
27 namespace AppDistributedKv {
28 class CommunicationProvider {
29 public:
30     // constructor
CommunicationProvider()31     API_EXPORT CommunicationProvider() {}
32 
33     // destructor
~CommunicationProvider()34     API_EXPORT virtual ~CommunicationProvider() {}
35 
36     // user should use this method to get instance of CommunicationProvider;
37     API_EXPORT static CommunicationProvider &GetInstance();
38 
39     API_EXPORT static std::shared_ptr<CommunicationProvider> MakeCommunicationProvider();
40     // add DeviceChangeListener to watch device change
41     virtual Status StartWatchDeviceChange(const AppDeviceChangeListener *observer, const PipeInfo &pipeInfo) = 0;
42 
43     // stop DeviceChangeListener to watch device change
44     virtual Status StopWatchDeviceChange(const AppDeviceChangeListener *observer, const PipeInfo &pipeInfo) = 0;
45 
46     // add DataChangeListener to watch data change
47     virtual Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) = 0;
48 
49     // stop DataChangeListener to watch data change
50     virtual Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) = 0;
51 
52     // Send data to other device, function will be called back after sent to notify send result
53     virtual Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size,
54         const MessageInfo &info = { MessageType::DEFAULT }) = 0;
55 
56     // Get online deviceList
57     virtual std::vector<DeviceInfo> GetRemoteDevices() const = 0;
58 
59     // Get deviceInfo by id
60     virtual DeviceInfo GetDeviceInfo(const std::string &networkId) const = 0;
61 
62     // Get local device information
63     virtual DeviceInfo GetLocalDevice() const = 0;
64 
65     // start one server to listen data from other devices;
66     virtual Status Start(const PipeInfo &pipeInfo) = 0;
67 
68     // stop server
69     virtual Status Stop(const PipeInfo &pipeInfo) = 0;
70 
71     // check peer device pipeInfo Process
72     virtual bool IsSameStartedOnPeer(const PipeInfo &pipeInfo, const DeviceId &peer) const = 0;
73 
74     virtual void SetDeviceQuery(std::shared_ptr<IDeviceQuery> deviceQuery) = 0;
75     virtual std::string GetUuidByNodeId(const std::string &nodeId) const = 0;
76     virtual std::string GetUdidByNodeId(const std::string &nodeId) const = 0;
77     virtual DeviceInfo GetLocalBasicInfo() const = 0;
78     virtual std::string ToNodeId(const std::string &id) const = 0;
79     virtual void SetMessageTransFlag(const PipeInfo &pipeInfo, bool flag) = 0;
80 
81     virtual int32_t Broadcast(const PipeInfo &pipeInfo, uint16_t mask) = 0;
82     virtual int32_t ListenBroadcastMsg(const PipeInfo &pipeInfo,
83         std::function<void(const std::string &, uint16_t)> listener) = 0;
84 };
85 } // namespace AppDistributedKv
86 } // namespace OHOS
87 #endif // DISTRIBUTEDDATA_COMMUNICATION_PROVIDER_H
88