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 OHOS_DCAMERA_SOFTBUS_ADAPTER_H 17 #define OHOS_DCAMERA_SOFTBUS_ADAPTER_H 18 19 #include <mutex> 20 #include <map> 21 #include <unistd.h> 22 23 #include "session.h" 24 #include "single_instance.h" 25 26 #include "dcamera_softbus_session.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 typedef enum { 31 DCAMERA_CHANNLE_ROLE_SOURCE = 0, 32 DCAMERA_CHANNLE_ROLE_SINK = 1, 33 } DCAMERA_CHANNEL_ROLE; 34 35 class DCameraSoftbusAdapter { 36 DECLARE_SINGLE_INSTANCE_BASE(DCameraSoftbusAdapter); 37 38 public: 39 int32_t CreateSoftbusSessionServer(std::string sessionName, DCAMERA_CHANNEL_ROLE role); 40 int32_t DestroySoftbusSessionServer(std::string sessionName); 41 int32_t OpenSoftbusSession(std::string mySessName, std::string peerSessName, int32_t sessionMode, 42 std::string peerDevId); 43 int32_t CloseSoftbusSession(int32_t sessionId); 44 int32_t SendSofbusBytes(int32_t sessionId, std::shared_ptr<DataBuffer>& buffer); 45 int32_t SendSofbusStream(int32_t sessionId, std::shared_ptr<DataBuffer>& buffer); 46 int32_t GetLocalNetworkId(std::string& myDevId); 47 48 int32_t OnSourceSessionOpened(int32_t sessionId, int32_t result); 49 void OnSourceSessionClosed(int32_t sessionId); 50 void OnSourceBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); 51 void OnSourceMessageReceived(int32_t sessionId, const void *data, uint32_t dataLen); 52 void OnSourceStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, 53 const StreamFrameInfo *param); 54 55 int32_t OnSinkSessionOpened(int32_t sessionId, int32_t result); 56 void OnSinkSessionClosed(int32_t sessionId); 57 void OnSinkBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); 58 void OnSinkMessageReceived(int32_t sessionId, const void *data, uint32_t dataLen); 59 void OnSinkStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, 60 const StreamFrameInfo *param); 61 62 public: 63 std::map<std::string, std::shared_ptr<DCameraSoftbusSession>> sourceSessions_; 64 std::map<std::string, std::shared_ptr<DCameraSoftbusSession>> sinkSessions_; 65 66 private: 67 DCameraSoftbusAdapter(); 68 ~DCameraSoftbusAdapter(); 69 70 int32_t DCameraSoftbusSourceGetSession(int32_t sessionId, std::shared_ptr<DCameraSoftbusSession>& session); 71 int32_t DCameraSoftbusSinkGetSession(int32_t sessionId, std::shared_ptr<DCameraSoftbusSession>& session); 72 int32_t DCameraSoftbusGetSessionById(int32_t sessionId, std::shared_ptr<DCameraSoftbusSession>& session); 73 74 private: 75 std::mutex optLock_; 76 const string PKG_NAME = "ohos.dhardware.dcamera"; 77 static const uint32_t DCAMERA_SESSION_NAME_MAX_LEN = 128; 78 map<DCAMERA_CHANNEL_ROLE, ISessionListener> sessListeners_; 79 std::map<std::string, uint32_t> sessionTotal_; 80 static const uint32_t DCAMERA_LINK_TYPE_MAX = 4; 81 static const uint32_t DCAMERA_LINK_TYPE_INDEX_2 = 2; 82 std::mutex idMapLock_; 83 std::map<int32_t, std::shared_ptr<DCameraSoftbusSession>> sessionIdMap_; 84 }; 85 } // namespace DistributedHardware 86 } // namespace OHOS 87 #endif // OHOS_DCAMERA_SOFTBUS_ADAPTER_H 88