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