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 DEVICE_COOPERATE_SOFTBUS_ADAPTER_H 17 #define DEVICE_COOPERATE_SOFTBUS_ADAPTER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include "nocopyable.h" 24 #include "session.h" 25 26 #include "i_multimodal_input_connect.h" 27 28 namespace OHOS { 29 namespace MMI { 30 class DeviceCooperateSoftbusAdapter { 31 public: 32 virtual ~DeviceCooperateSoftbusAdapter(); 33 static std::shared_ptr<DeviceCooperateSoftbusAdapter> GetInstance(); 34 int32_t StartRemoteCooperate(const std::string &localDeviceId, const std::string &remoteDeviceId); 35 int32_t StartRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess, 36 const std::string &startDhid, int32_t xPercent, int32_t yPercent); 37 int32_t StopRemoteCooperate(const std::string &remoteDeviceId); 38 int32_t StopRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess); 39 int32_t StartCooperateOtherResult(const std::string &remoteDeviceId, const std::string &srcNetworkId); 40 41 int32_t Init(); 42 void Release(); 43 int32_t OpenInputSoftbus(const std::string &remoteDevId); 44 void CloseInputSoftbus(const std::string &remoteDevId); 45 46 int32_t OnSessionOpened(int32_t sessionId, int32_t result); 47 void OnSessionClosed(int32_t sessionId); 48 void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); 49 50 private: 51 DeviceCooperateSoftbusAdapter() = default; 52 DISALLOW_COPY_AND_MOVE(DeviceCooperateSoftbusAdapter); 53 std::string FindDevice(int32_t sessionId); 54 int32_t SendMsg(int32_t sessionId, const std::string &message); 55 bool CheckDeviceSessionState(const std::string &remoteDevId); 56 void HandleSessionData(int32_t sessionId, const std::string& messageData); 57 int32_t WaitSessionOpend(const std::string &remoteDevId, int32_t sessionId); 58 std::map<std::string, int32_t> sessionDevMap_; 59 std::map<std::string, bool> channelStatusMap_; 60 std::mutex operationMutex_; 61 std::string localSessionName_; 62 std::condition_variable openSessionWaitCond_; 63 ISessionListener sessListener_; 64 }; 65 } // namespace MMI 66 } // namespace OHOS 67 #define DevCooperateSoftbusAdapter DeviceCooperateSoftbusAdapter::GetInstance() 68 #endif // DEVICE_COOPERATE_SOFTBUS_ADAPTER_H 69