Debian Codegraph @

Server/Z21/Z21Server.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 <vector>
27
28 #include "ControlInterface.h"
29 #include "Logger/Logger.h"
30 #include "Manager.h"
31 #include "Network/UdpServer.h"
32
33 namespace Server { namespace Z21
34 {
35 class Z21Client;
36
37 class Z21Server : public ControlInterface, private Network::UdpServer
38 {
39 public:
40 static const unsigned short Z21Port = 21105;
41
42 Z21Server() = delete;
43 Z21Server(const Z21Server&) = delete;
44 Z21Server& operator=(const Z21Server&) = delete;
45
46 Z21Server(Manager& manager, const unsigned short port);
47 ~Z21Server();
48
49 void Start() override;
50
51 void Stop() override;
52
53 bool NextUpdate(unsigned int& updateIDClient, std::string& s);
54
55 inline const std::string& GetName() const override
56 {
57 static const std::string Z21Name("Z21Server");
58 return Z21Name;
59 }
60
61 void Booster(const ControlType controlType, const BoosterState status) override;
62
63 void LocoBaseOrientation(const ControlType controlType,
64 const DataModel::LocoBase* loco,
65 const Orientation direction) override;
66
67 void LocoBaseFunction(const ControlType controlType,
68 const DataModel::LocoBase* loco,
69 const DataModel::LocoFunctionNr function,
70 const DataModel::LocoFunctionState on) override;
71
72 void LocoBaseSpeed(const ControlType controlType,
73 const DataModel::LocoBase* loco,
74 const Speed speed) override;
75
76 void AccessoryState(const ControlType controlType, const DataModel::Accessory* accessory) override;
77
78 void SwitchState(const ControlType controlType, const DataModel::Switch* mySwitch) override;
79
80 void SignalState(const ControlType controlType, const DataModel::Signal* signal) override;
81
82 protected:
83 Network::UdpClient* UdpClientFactory(const int serverSocket,
84 const struct sockaddr_storage* clientAddress) override;
85
86 private:
87 Logger::Logger* logger;
88 Manager& manager;
89 unsigned int lastClientID;
90
91 ssize_t ParseData(const unsigned char* buffer,
92 const ssize_t bufferLength,
93 const struct sockaddr_storage* clientAddress);
94
95 void ParseXHeader(const unsigned char* buffer);
96
97 void ParseDB0(const unsigned char* buffer);
98
99 void AccessoryBaseState(const DataModel::AccessoryBase* accessoryBase);
100 };
101 }} // namespace Server::Z21