1 /* 2 * Copyright (c) 2022-2023 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 COORDINATION_SOFTBUS_ADAPTER_H 17 #define COORDINATION_SOFTBUS_ADAPTER_H 18 19 #include <condition_variable> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <string> 24 25 #include "nocopyable.h" 26 #include "session.h" 27 28 #include "coordination_util.h" 29 30 namespace OHOS { 31 namespace Msdp { 32 namespace DeviceStatus { 33 class CoordinationSoftbusAdapter { 34 public: 35 virtual ~CoordinationSoftbusAdapter(); 36 37 enum MessageId { 38 MIN_ID = 0, 39 DRAGGING_DATA = 1, 40 STOPDRAG_DATA = 2, 41 IS_PULL_UP = 3, 42 MAX_ID = 50 43 }; 44 struct DataPacket { 45 MessageId messageId; 46 uint32_t dataLen { 0 }; 47 uint8_t data[0]; 48 }; 49 50 int32_t StartRemoteCoordination(const std::string &localNetworkId, const std::string &remoteNetworkId); 51 int32_t StartRemoteCoordinationResult(const std::string &remoteNetworkId, bool isSuccess, 52 const std::string &startDeviceDhid, int32_t xPercent, int32_t yPercent); 53 int32_t StopRemoteCoordination(const std::string &remoteNetworkId, bool isUnchained); 54 int32_t StopRemoteCoordinationResult(const std::string &remoteNetworkId, bool isSuccess); 55 int32_t StartCoordinationOtherResult(const std::string &originNetworkId, const std::string &remoteNetworkId); 56 int32_t Init(); 57 void Release(); 58 int32_t OpenInputSoftbus(const std::string &remoteNetworkId); 59 void CloseInputSoftbus(const std::string &remoteNetworkId); 60 int32_t OnSessionOpened(int32_t sessionId, int32_t result); 61 void OnSessionClosed(int32_t sessionId); 62 void OnBytesReceived(int32_t sessionId, const void* data, uint32_t dataLen); 63 void RegisterRecvFunc(MessageId messageId, std::function<void(void*, uint32_t)> callback); 64 int32_t SendData(const std::string &deviceId, MessageId messageId, void* data, uint32_t dataLen); 65 static std::shared_ptr<CoordinationSoftbusAdapter> GetInstance(); 66 int32_t NotifyUnchainedResult(const std::string &localNetworkId, 67 const std::string &remoteNetworkId, bool isSuccess); 68 int32_t NotifyFilterAdded(const std::string &remoteNetworkId); 69 void ConfigTcpAlive(); 70 71 private: 72 CoordinationSoftbusAdapter() = default; 73 DISALLOW_COPY_AND_MOVE(CoordinationSoftbusAdapter); 74 std::string FindDevice(int32_t sessionId); 75 int32_t SendMsg(int32_t sessionId, const std::string &message); 76 bool CheckDeviceSessionState(const std::string &remoteNetworkId); 77 void HandleSessionData(int32_t sessionId, const std::string &messageData); 78 void HandleCoordinationSessionData(int32_t sessionId, const JsonParser &parser); 79 int32_t WaitSessionOpend(const std::string &remoteNetworkId, int32_t sessionId); 80 void ResponseNotifyFilterAdded(); 81 82 std::map<std::string, int32_t> sessionDevMap_; 83 std::map<std::string, bool> channelStatusMap_; 84 std::mutex operationMutex_; 85 std::string localSessionName_; 86 std::condition_variable openSessionWaitCond_; 87 ISessionListener sessListener_; 88 std::map<MessageId, std::function<void(void*, uint32_t)>> registerRecvMap_; 89 int32_t sessionId_ { -1 }; 90 }; 91 } // namespace DeviceStatus 92 } // namespace Msdp 93 } // namespace OHOS 94 #define COOR_SOFTBUS_ADAPTER CoordinationSoftbusAdapter::GetInstance() 95 #endif // COORDINATION_SOFTBUS_ADAPTER_H