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