Debian Codegraph @

src/Session.h

raw
1 /*
2 * Copyright (C) 2010-2021 Team Kodi (https://kodi.tv)
3 * Copyright (C) 2010 Alwin Esch (Team Kodi)
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSE.md for more information.
7 */
8
9 #pragma once
10
11 #include "TCPSocket.h"
12
13 #include <atomic>
14 #include <kodi/addon-instance/PVR.h>
15 #include <memory>
16 #include <mutex>
17 #include <stdint.h>
18 #include <string>
19
20 class cResponsePacket;
21 class cRequestPacket;
22
23 namespace P8PLATFORM
24 {
25 class CTcpConnection;
26 }
27
28 class ATTR_DLL_LOCAL cVNSISession
29 {
30 public:
31 cVNSISession(kodi::addon::CInstancePVRClient& instance);
32 virtual ~cVNSISession();
33
34 virtual bool Open(const std::string& hostname, int port, const char* name = nullptr);
35 virtual void Close();
36
37 int GetProtocol() const { return m_protocol; }
38 const std::string& GetServerName() const { return m_server; }
39 const std::string& GetVersion() const { return m_version; }
40
41 enum eCONNECTIONSTATE
42 {
43 CONN_ESABLISHED = 0,
44 CONN_HOST_NOT_REACHABLE,
45 CONN_LOGIN_FAILED,
46 CONN_UNKNOWN
47 };
48
49 protected:
50 virtual bool Login();
51
52 std::unique_ptr<cResponsePacket> ReadMessage(int iInitialTimeout, int iDatapacketTimeout);
53 bool TransmitMessage(cRequestPacket* vrp);
54 std::unique_ptr<cResponsePacket> ReadResult(cRequestPacket* vrp);
55 bool ReadSuccess(cRequestPacket* m);
56 void SleepMs(int ms);
57
58 eCONNECTIONSTATE TryReconnect();
59 bool IsOpen();
60 virtual void OnDisconnect();
61 virtual void OnReconnect();
62 virtual void SignalConnectionLost();
63
64 std::string m_hostname;
65 int m_port;
66 std::string m_name;
67 std::recursive_mutex m_mutex;
68 int m_protocol = 0;
69 std::string m_server;
70 std::string m_version;
71 bool m_connectionLost = false;
72 std::atomic_bool m_abort = {false};
73
74 private:
75 bool ReadData(uint8_t* buffer, int totalBytes, int timeout);
76
77 vdrvnsi::TCPSocket* m_socket = nullptr;
78
79 kodi::addon::CInstancePVRClient& m_instance;
80 };