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 SESSION_IMPL_H 17 #define SESSION_IMPL_H 18 19 #include <cstdint> 20 #include <list> 21 #include <memory> 22 #include <string> 23 #include <unistd.h> 24 #include "CommDefs.h" 25 #include "ISessionListener.h" 26 27 namespace Communication { 28 namespace SoftBus { 29 class SessionImpl : public std::enable_shared_from_this<SessionImpl>, public Session { 30 public: 31 static constexpr int TYPE_MSG = 1; 32 33 static constexpr int TYPE_BYTES = 2; 34 35 static constexpr int TYPE_FILE = 4; 36 37 SessionImpl(); 38 39 ~SessionImpl() override = default; 40 41 int GetSessionId() const override; 42 43 void SetSessionId(int sessionId) override; 44 45 void SetMySessionName(const std::string &name) override; 46 47 const std::string &GetMySessionName() const override; 48 49 void SetPeerSessionName(const std::string &name) override; 50 51 const std::string &GetPeerSessionName() const override; 52 53 void SetPeerDeviceId(const std::string &name) override; 54 55 const std::string &GetPeerDeviceId() const override; 56 57 const std::string &GetDeviceId() const override; 58 59 void SetDeviceId(const std::string &name) override; 60 61 void SetIsServer(bool isServer) override; 62 63 void SetPeerUid(uid_t peerUid) override; 64 65 void SetPeerPid(pid_t peerPid) override; 66 67 int64_t GetChannelId() const override; 68 69 uid_t GetPeerUid() const override; 70 71 pid_t GetPeerPid() const override; 72 73 bool IsServerSide() const override; 74 75 int SendBytes(const void *buf, ssize_t len) const override; 76 77 private: 78 NO_COPY_AND_ASSIGN(SessionImpl); 79 80 const int MAX_BYTES_LENGTH = 128 * 1024 * 1024; 81 const std::string nullString_ = ""; 82 const std::string noSession_ = "[Session]null"; 83 84 int sessionId_; 85 std::string sessionName_; 86 std::string peerSessionName_; 87 std::string deviceId_; 88 std::string peerDeviceId_; 89 bool isServer_; 90 uid_t peerUid_; 91 pid_t peerPid_; 92 }; 93 } // namespace SoftBus 94 } // namespace Communication 95 96 #endif // SESSION_IMPL_H 97