1 /*
2 * Copyright (c) 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 #include "softbus_session_proxy.h"
17
18 #include "avsession_log.h"
19 #include "avsession_errors.h"
20 #include "softbus_session_manager.h"
21 #include "softbus_session_utils.h"
22 #include "migrate_avsession_constant.h"
23
24 namespace OHOS::AVSession {
~SoftbusSessionProxy()25 SoftbusSessionProxy::~SoftbusSessionProxy() {}
26
ConnectServer(int socketId)27 void SoftbusSessionProxy::ConnectServer(int socketId)
28 {
29 std::string networkId;
30 int ret = SoftbusSessionManager::GetInstance().ObtainPeerDeviceId(socketId, networkId);
31 CHECK_AND_RETURN_LOG(ret == AVSESSION_SUCCESS, "obtain peer network id failed");
32 SLOGI("ConnectServer for device:%{public}s",
33 SoftbusSessionUtils::AnonymizeDeviceId(networkId).c_str());
34 OnConnectSession(socketId);
35 char message[] = {GetCharacteristic(), MESSAGE_CODE_CONNECT_SERVER, '\0'};
36 SendByte(socketId, std::string(message));
37 OnConnectServer(networkId);
38 }
39
40 //LCOV_EXCL_START
DisconnectServer(int socketId)41 void SoftbusSessionProxy::DisconnectServer(int socketId)
42 {
43 std::string networkId;
44 int ret = SoftbusSessionManager::GetInstance().ObtainPeerDeviceId(socketId, networkId);
45 CHECK_AND_RETURN_LOG(ret == AVSESSION_SUCCESS, "obtain peer network id failed");
46 SLOGI("DisconnectServer for device:%{public}s",
47 SoftbusSessionUtils::AnonymizeDeviceId(networkId).c_str());
48 OnDisConnectSession(socketId);
49 OnDisconnectServer(networkId);
50 }
51 //LCOV_EXCL_STOP
52 } // namespace OHOS::AVSession