1 /* 2 * Copyright (c) 2024-2025 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 OHOS_DM_COMM_TOOL_H 17 #define OHOS_DM_COMM_TOOL_H 18 19 #include "dm_transport.h" 20 #include "dm_transport_msg.h" 21 22 namespace OHOS { 23 namespace DistributedHardware { 24 25 class DMCommTool : public std::enable_shared_from_this<DMCommTool> { 26 public: 27 DMCommTool(); 28 virtual ~DMCommTool() = default; 29 static std::shared_ptr<DMCommTool> GetInstance(); 30 void Init(); 31 void UnInit(); 32 33 int32_t SendUserIds(const std::string rmtNetworkId, const std::vector<uint32_t> &foregroundUserIds, 34 const std::vector<uint32_t> &backgroundUserIds); 35 void RspLocalFrontOrBackUserIds(const std::string rmtNetworkId, const std::vector<uint32_t> &foregroundUserIds, 36 const std::vector<uint32_t> &backgroundUserIds, int32_t socketId); 37 int32_t CreateUserStopMessage(int32_t stopUserId, std::string &msgStr); 38 int32_t SendMsg(const std::string rmtNetworkId, int32_t msgType, const std::string &msg); 39 int32_t SendUserStop(const std::string rmtNetworkId, int32_t stopUserId); 40 int32_t ParseUserStopMessage(const std::string &msgStr, int32_t &stopUserId); 41 void ProcessReceiveUserStopEvent(const std::shared_ptr<InnerCommMsg> commMsg); 42 void RspUserStop(const std::string rmtNetworkId, int32_t socketId, int32_t stopUserId); 43 void ProcessResponseUserStopEvent(const std::shared_ptr<InnerCommMsg> commMsg); 44 45 class DMCommToolEventHandler : public AppExecFwk::EventHandler { 46 public: 47 DMCommToolEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> runner, 48 std::shared_ptr<DMCommTool> dmCommToolPtr); 49 ~DMCommToolEventHandler() override = default; 50 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 51 private: 52 std::weak_ptr<DMCommTool> dmCommToolWPtr_; 53 }; 54 std::shared_ptr<DMCommTool::DMCommToolEventHandler> GetEventHandler(); 55 const std::shared_ptr<DMTransport> GetDMTransportPtr(); 56 57 void ProcessReceiveUserIdsEvent(const std::shared_ptr<InnerCommMsg> commMsg); 58 void ProcessResponseUserIdsEvent(const std::shared_ptr<InnerCommMsg> commMsg); 59 int32_t SendLogoutAccountInfo(const std::string &rmtNetworkId, const std::string &accountId, int32_t userId); 60 void ProcessReceiveLogoutEvent(const std::shared_ptr<InnerCommMsg> commMsg); 61 private: 62 std::shared_ptr<DMTransport> dmTransportPtr_; 63 std::shared_ptr<DMCommTool::DMCommToolEventHandler> eventHandler_; 64 }; 65 } // DistributedHardware 66 } // OHOS 67 #endif