• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef SOCKET_SESSION_H
17 #define SOCKET_SESSION_H
18 
19 #include "nocopyable.h"
20 
21 #include "i_epoll_event_source.h"
22 #include "i_socket_session.h"
23 
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 class SocketSession final : public ISocketSession, public IEpollEventSource {
28 public:
29     SocketSession(const std::string &programName, int32_t moduleType,
30                   int32_t tokenType, int32_t fd, int32_t uid, int32_t pid);
31     DISALLOW_COPY_AND_MOVE(SocketSession);
32     ~SocketSession();
33 
34     bool SendMsg(NetPacket &pkt) const override;
35 
36     int32_t GetUid() const override;
37     int32_t GetPid() const override;
38     std::string ToString() const override;
39 
40     int32_t GetFd() const override;
41     void Dispatch(const struct epoll_event &ev) override;
42 
43 private:
44     bool SendMsg(const char *buf, size_t size) const;
45 
46 private:
47     int32_t fd_ { -1 };
48     int32_t uid_ { -1 };
49     int32_t pid_ { -1 };
50     int32_t tokenType_ { TokenType::TOKEN_INVALID };
51 };
52 
GetUid()53 inline int32_t SocketSession::GetUid() const
54 {
55     return uid_;
56 }
57 
GetPid()58 inline int32_t SocketSession::GetPid() const
59 {
60     return pid_;
61 }
62 
GetFd()63 inline int32_t SocketSession::GetFd() const
64 {
65     return fd_;
66 }
67 } // namespace Msdp
68 } // namespace OHOS
69 } // namespace DeviceStatus
70 #endif // SOCKET_SESSION_H