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 PROCESS_COMMUNICATION_IMPL_H
17 #define PROCESS_COMMUNICATION_IMPL_H
18 
19 #include "iprocess_communicator.h"
20 #include "types.h"
21 #include "end_point.h"
22 
23 namespace OHOS {
24 namespace DistributedKv {
25 
26 class ProcessCommunicationImpl : public DistributedDB::IProcessCommunicator {
27 public:
28     using DBStatus = DistributedDB::DBStatus;
29     using OnDeviceChange = DistributedDB::OnDeviceChange;
30     using OnDataReceive = DistributedDB::OnDataReceive;
31 
32     API_EXPORT explicit ProcessCommunicationImpl(std::shared_ptr<Endpoint> endpoint);
33     API_EXPORT ~ProcessCommunicationImpl() override;
34 
35     DBStatus Start(const std::string &processLabel) override;
36     DBStatus Stop() override;
37 
38     DBStatus RegOnDeviceChange(const OnDeviceChange &callback) override;
39     DBStatus RegOnDataReceive(const OnDataReceive &callback) override;
40 
41     DBStatus SendData(const DistributedDB::DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) override;
42     uint32_t GetMtuSize() override;
43     uint32_t GetMtuSize(const DistributedDB::DeviceInfos &devInfo) override;
44     DistributedDB::DeviceInfos GetLocalDeviceInfos() override;
45     std::vector<DistributedDB::DeviceInfos> GetRemoteOnlineDeviceInfosList() override;
46     bool IsSameProcessLabelStartedOnPeerDevice(const DistributedDB::DeviceInfos &peerDevInfo) override;
47     std::shared_ptr<DistributedDB::ExtendHeaderHandle> GetExtendHeaderHandle(
48         const DistributedDB::ExtendInfo &paramInfo) override;
49 private:
50 
51     std::shared_ptr<Endpoint> endpoint_;
52     bool isCreateSessionServer_ = false;
53 };
54 }  // namespace AppDistributedKv
55 }  // namespace OHOS
56 #endif // PROCESS_COMMUNICATION_IMPL_H