1 /* 2 * Copyright (c) 2022-2024 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_SOFTBUS_SESSION_H 17 #define OHOS_DM_SOFTBUS_SESSION_H 18 19 #include <map> 20 #include <memory> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include "inner_session.h" 26 #include "session.h" 27 #include "socket.h" 28 #include "softbus_session_callback.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 class SoftbusSession { 33 public: 34 static int OnSessionOpened(int sessionId, int result); 35 static void OnSessionClosed(int sessionId); 36 static void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen); 37 static void OnUnbindSessionOpened(int32_t socket, PeerSocketInfo info); 38 39 public: 40 SoftbusSession(); 41 ~SoftbusSession(); 42 43 /** 44 * @tc.name: SoftbusSession::RegisterSessionCallback 45 * @tc.desc: RegisterSessionCallback of the Softbus Session 46 * @tc.type: FUNC 47 */ 48 int32_t RegisterSessionCallback(std::shared_ptr<ISoftbusSessionCallback> callback); 49 50 /** 51 * @tc.name: SoftbusSession::UnRegisterSessionCallback 52 * @tc.desc: UnRegister SessionCallback of the Softbus Session 53 * @tc.type: FUNC 54 */ 55 int32_t UnRegisterSessionCallback(); 56 57 /** 58 * @tc.name: SoftbusSession::OpenAuthSession 59 * @tc.desc: Open AuthSession of the Softbus Session 60 * @tc.type: FUNC 61 */ 62 int32_t OpenAuthSession(const std::string &deviceId); 63 64 /** 65 * @tc.name: SoftbusSession::CloseAuthSession 66 * @tc.desc: Close AuthSession of the Softbus Session 67 * @tc.type: FUNC 68 */ 69 int32_t CloseAuthSession(int32_t sessionId); 70 71 /** 72 * @tc.name: SoftbusSession::SendData 73 * @tc.desc: Send Data of the Softbus Session 74 * @tc.type: FUNC 75 */ 76 int32_t SendData(int32_t sessionId, std::string &message); 77 78 /** 79 * @tc.name: SoftbusSession::GetPeerDeviceId 80 * @tc.desc: Get Peer DeviceId of the Softbus Session 81 * @tc.type: FUNC 82 */ 83 int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId); 84 int32_t OpenUnbindSession(const std::string &netWorkId); 85 int32_t CloseUnbindSession(int32_t socket); 86 int32_t SendHeartbeatData(int32_t sessionId, std::string &message); 87 88 private: 89 static std::shared_ptr<ISoftbusSessionCallback> sessionCallback_; 90 ISocketListener iSocketListener_; 91 }; 92 } // namespace DistributedHardware 93 } // namespace OHOS 94 #endif // OHOS_DM_SOFTBUS_SESSION_H 95