1 /* 2 * Copyright (c) 2021-2023 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 #ifndef STREAM_SESSION_H 16 #define STREAM_SESSION_H 17 18 #include <list> 19 #include <memory> 20 #include <map> 21 22 #include <sys/socket.h> 23 #include <sys/un.h> 24 25 #include "nocopyable.h" 26 27 #include "net_packet.h" 28 #include "proto.h" 29 30 namespace OHOS { 31 namespace Msdp { 32 namespace DeviceStatus { 33 class StreamSession; 34 using SessionPtr = std::shared_ptr<StreamSession>; 35 class StreamSession : public std::enable_shared_from_this<StreamSession> { 36 public: 37 StreamSession(const std::string &programName, int32_t moduleType, int32_t fd, int32_t uid, int32_t pid); 38 DISALLOW_COPY_AND_MOVE(StreamSession); 39 virtual ~StreamSession() = default; 40 41 bool SendMsg(const char *buf, size_t size) const; 42 bool SendMsg(NetPacket &pkt) const; 43 void Close(); 44 GetPid()45 int32_t GetPid() const 46 { 47 return pid_; 48 } 49 GetSharedPtr()50 SessionPtr GetSharedPtr() 51 { 52 return shared_from_this(); 53 } 54 GetFd()55 int32_t GetFd() const 56 { 57 return fd_; 58 } 59 GetDescript()60 const std::string& GetDescript() const 61 { 62 return descript_; 63 } 64 SetTokenType(int32_t type)65 void SetTokenType(int32_t type) 66 { 67 tokenType_ = type; 68 } 69 70 void UpdateDescript(); 71 protected: 72 std::string descript_; 73 int32_t fd_ { -1 }; 74 const int32_t pid_ { -1 }; 75 int32_t tokenType_ { TokenType::TOKEN_INVALID }; 76 }; 77 } // namespace Msdp 78 } // namespace OHOS 79 } // namespace DeviceStatus 80 #endif // STREAM_SESSION_H