Debian Codegraph @

Server/CS2/CS2Server.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 <map>
24 #include <mutex>
25 #include <sstream>
26 #include <thread>
27 #include <vector>
28
29 #include <sys/socket.h>
30
31 #include "ControlInterface.h"
32 #include "Logger/Logger.h"
33 #include "Manager.h"
34 #include "Network/UdpServer.h"
35
36 namespace Server { namespace CS2
37 {
38 class CS2Client;
39
40 class CS2Server : public ControlInterface, private Network::TcpServer
41 {
42 public:
43 static const unsigned short CS2ReceiverPort = 15731;
44 static const unsigned short CS2SenderPort = 15730;
45
46 CS2Server() = delete;
47 CS2Server(const CS2Server&) = delete;
48 CS2Server& operator=(const CS2Server&) = delete;
49
50 CS2Server(Manager& manager);
51 ~CS2Server();
52
53 void Start() override;
54
55 void Stop() override;
56
57 void Work(Network::TcpConnection* connection) override;
58
59 inline const std::string& GetName() const override
60 {
61 static const std::string CS2Name("CS2Server");
62 return CS2Name;
63 }
64
65 void Booster(const ControlType controlType, const BoosterState status) override;
66
67 void LocoBaseOrientation(const ControlType controlType,
68 const DataModel::LocoBase* loco,
69 const Orientation direction) override;
70
71 void LocoBaseFunction(const ControlType controlType,
72 const DataModel::LocoBase* loco,
73 const DataModel::LocoFunctionNr function,
74 const DataModel::LocoFunctionState on) override;
75
76 void LocoBaseSpeed(const ControlType controlType,
77 const DataModel::LocoBase* loco,
78 const Speed speed) override;
79
80 void AccessoryState(const ControlType controlType, const DataModel::Accessory* accessory) override;
81
82 void SwitchState(const ControlType controlType, const DataModel::Switch* mySwitch) override;
83
84 void SignalState(const ControlType controlType, const DataModel::Signal* signal) override;
85
86 private:
87 Logger::Logger* logger;
88 Manager& manager;
89 std::vector<CS2Client*> clients;
90 unsigned int lastClientID;
91
92 bool runUdp;
93 std::thread udpServerThread;
94 int udpServerSocket;
95
96 void AccessoryBaseState(const DataModel::AccessoryBase* accessoryBase);
97
98 void CleanUpClients();
99
100 void StartUdpServer();
101
102 void TerminateUdpServer();
103
104 void UdpSocketCreateBindListen(int family, struct sockaddr* address);
105
106 void UdpWorker();
107 };
108 }} // namespace Server::CS2