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 CPP_SESSION_H
17#define CPP_SESSION_H
18
19#include <cstdint>
20#include <string>
21#include <unistd.h>
22#include "CommDefs.h"
23
24namespace Communication {
25namespace SoftBus {
26class COMM_EXPORT Session {
27public:
28    enum {
29        TYPE_MESSAGE = 0x01,
30        TYPE_BYTES = 0x02,
31        TYPE_FILE = 0x04,
32        TYPE_STREAM = 0x08,
33    };
34
35    enum RouteType {
36        WIFI_STA = 1,
37        WIFI_P2P = 2,
38        BT_BR = 3,
39        BT_BLE = 4,
40        LOOPBACK = 5,
41    };
42
43    enum SessionStatus {
44        INIT,
45        OPENING,
46        OPENED,
47        CONNECTING,
48        CONNECTED,
49        CLOSING,
50        CLOSED,
51    };
52
53    Session() = default;
54    virtual ~Session() = default;
55
56    virtual const std::string &GetMySessionName() const = 0;
57
58    virtual const std::string &GetPeerSessionName() const = 0;
59
60    virtual const std::string &GetDeviceId() const = 0;
61
62    virtual const std::string &GetPeerDeviceId() const = 0;
63
64    virtual int64_t GetChannelId() const = 0;
65
66    virtual uid_t GetPeerUid() const = 0;
67
68    virtual pid_t GetPeerPid() const = 0;
69
70    virtual bool IsServerSide() const = 0;
71
72    virtual int SendBytes(const void *buf, ssize_t len) const = 0;
73
74    virtual int GetSessionId() const = 0;
75
76    virtual void SetSessionId(int sessionId) = 0;
77
78    virtual void SetMySessionName(const std::string &name) = 0;
79
80    virtual void SetPeerSessionName(const std::string &name) = 0;
81
82    virtual void SetPeerDeviceId(const std::string &name) = 0;
83
84    virtual void SetDeviceId(const std::string &name) = 0;
85
86    virtual void SetIsServer(bool isServer) = 0;
87
88    virtual void SetPeerUid(uid_t peerUid) = 0;
89
90    virtual void SetPeerPid(pid_t peerPid) = 0;
91
92private:
93    NO_COPY_AND_ASSIGN(Session);
94};
95} // namespace SoftBus
96} // namespace Communication
97
98#endif // CPP_SESSION_H
99