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 DISTRIBUTEDDATAMGR_APP_PIPE_MGR_H
17 #define DISTRIBUTEDDATAMGR_APP_PIPE_MGR_H
18 
19 #include <map>
20 #include <mutex>
21 #include "app_data_change_listener.h"
22 #include "app_pipe_handler.h"
23 #include "data_buffer.h"
24 #include "log_print.h"
25 
26 namespace OHOS {
27 namespace AppDistributedKv {
28 class AppPipeMgr {
29 public:
AppPipeMgr()30     explicit AppPipeMgr() {}
~AppPipeMgr()31     ~AppPipeMgr() {}
32     // add DataChangeListener to watch data change;
33     Status StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo);
34 
35     // stop DataChangeListener to watch data change;
36     Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo);
37 
38     // Send data to other device, function will be called back after sent to notify send result.
39     std::pair<Status, int32_t> SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo,
40         uint32_t totalLength, const MessageInfo &info);
41     // start server
42     Status Start(const PipeInfo &pipeInfo);
43     // stop server
44     Status Stop(const PipeInfo &pipeInfo);
45 
46     bool IsSameStartedOnPeer(const struct PipeInfo &pipeInfo, const struct DeviceId &peer);
47 
48     void SetMessageTransFlag(const PipeInfo &pipeInfo, bool flag);
49 private:
50     std::mutex dataBusMapMutex_ {};
51     std::map<std::string, std::shared_ptr<AppPipeHandler>> dataBusMap_ {};
52 };
53 }  // namespace AppDistributedKv
54 }  // namespace OHOS
55 #endif // DISTRIBUTEDDATAMGR_APP_PIPE_MGR_H
56