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#include "session_impl.h" 17 18#include "session.h" 19#include "session_mock.h" 20#include "softbus_errcode.h" 21#include "trans_log.h" 22 23namespace Communication { 24namespace SoftBus { 25SessionImpl::SessionImpl() : sessionId_(-1), isServer_(false), peerUid_(-1), peerPid_(-1) {} 26 27int64_t SessionImpl::GetChannelId() const 28{ 29 return sessionId_; 30} 31 32void SessionImpl::SetSessionId(int sessionId) 33{ 34 sessionId_ = sessionId; 35} 36 37int SessionImpl::GetSessionId() const 38{ 39 return sessionId_; 40} 41 42void SessionImpl::SetMySessionName(const std::string &name) 43{ 44 sessionName_ = name; 45} 46 47const std::string &SessionImpl::GetMySessionName() const 48{ 49 return sessionName_; 50} 51 52void SessionImpl::SetPeerSessionName(const std::string &name) 53{ 54 peerSessionName_ = name; 55} 56 57const std::string &SessionImpl::GetPeerSessionName() const 58{ 59 return peerSessionName_; 60} 61 62void SessionImpl::SetPeerDeviceId(const std::string &name) 63{ 64 peerDeviceId_ = name; 65} 66 67const std::string &SessionImpl::GetPeerDeviceId() const 68{ 69 return peerDeviceId_; 70} 71 72void SessionImpl::SetDeviceId(const std::string &name) 73{ 74 deviceId_ = name; 75} 76 77void SessionImpl::SetIsServer(bool isServer) 78{ 79 isServer_ = isServer; 80} 81 82void SessionImpl::SetPeerUid(uid_t peerUid) 83{ 84 peerUid_ = peerUid; 85} 86 87void SessionImpl::SetPeerPid(pid_t peerPid) 88{ 89 peerPid_ = peerPid; 90} 91 92const std::string &SessionImpl::GetDeviceId() const 93{ 94 return deviceId_; 95} 96 97uid_t SessionImpl::GetPeerUid() const 98{ 99 return peerUid_; 100} 101 102pid_t SessionImpl::GetPeerPid() const 103{ 104 return peerPid_; 105} 106 107bool SessionImpl::IsServerSide() const 108{ 109 return isServer_; 110} 111 112int SessionImpl::SendBytes(const void *buf, ssize_t len) const 113{ 114 if (buf == nullptr || len <= 0 || len > MAX_BYTES_LENGTH) { 115 TRANS_LOGW(TRANS_BYTES, "Invalid params"); 116 return SOFTBUS_INVALID_PARAM; 117 } 118 return SendBytesInner(sessionId_, buf, len); 119} 120} // namespace SoftBus 121} // namespace Communication 122