Debian Codegraph @

Server/CS2/CS2Client.h

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include <ctime>
24
25 #include "Hardware/LocoCache.h"
26 #include "Hardware/Protocols/MaerklinCANCommon.h"
27 #include "Network/TcpConnection.h"
28 #include "Utils/Utils.h"
29
30 namespace Server { namespace CS2
31 {
32 class CS2Server;
33
34 class CS2Client : protected Hardware::Protocols::MaerklinCANCommon
35 {
36 public:
37 CS2Client() = delete;
38 CS2Client(const CS2Client&) = delete;
39 CS2Client& operator=(const CS2Client&) = delete;
40
41 inline CS2Client(const unsigned int id,
42 Network::TcpConnection* connection, // connection must be deleted after using!
43 Manager& manager)
44 : MaerklinCANCommon("affeaffe",
45 ControlIdCS2Server,
46 &manager,
47 true,
48 Logger::Logger::GetLogger("CS2Client # " + std::to_string(id))),
49 id(id),
50 connection(connection),
51 terminated(false)
52 {
53 Init();
54 }
55
56 virtual ~CS2Client()
57 {
58 }
59
60 inline void Stop()
61 {
62 run = false;
63 }
64
65 inline bool IsTerminated()
66 {
67 return terminated;
68 }
69
70 protected:
71 void Receiver() override;
72
73 void Send(const unsigned char* buffer) override;
74
75 private:
76 void ReceiverImpl();
77
78 virtual void CacheSave(__attribute__((unused)) Hardware::LocoCacheEntry& entry) override
79 {
80 }
81
82 virtual void CacheSave(__attribute__((unused)) Hardware::LocoCacheEntry& entry, __attribute__((unused)) const std::string& oldMatchKey) override
83 {
84 }
85
86 virtual LocoID CacheDelete(__attribute__((unused)) const std::string& matchKey) override
87 {
88 return LocoNone;
89 }
90
91 virtual void CacheUpdateSlaves() override
92 {
93 }
94
95 static const unsigned char CANCommandBufferLength = 13;
96
97 unsigned int id;
98 Network::TcpConnection* connection;
99 bool terminated;
100 };
101 }} // namespace Server::CS2
102