GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/Session.h
Date: 2024-12-15 04:08:34
Exec Total Coverage
Lines: 1 3 33.3%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright 2010 Richard Hacker (lerichi at gmx dot net)
6 *
7 * This file is part of the pdserv library.
8 *
9 * The pdserv library is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * The pdserv library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *****************************************************************************/
23
24 #ifndef MSRSESSION_H
25 #define MSRSESSION_H
26
27 // Version der MSR_LIBRARIES
28 #define _VERSION 6
29 #define _PATCHLEVEL 0
30 #define _SUBLEVEL 10
31
32
33 #define MSR_VERSION (((_VERSION) << 16) + ((_PATCHLEVEL) << 8) + (_SUBLEVEL))
34
35 /* List of the MSR protocol features, this server implementation supports.
36 *
37 * pushparameters: Parameters are sent to the client on change
38 * binparameters: Parameters can be transferred in binary format
39 * eventchannels: Channels can be transferred only on change
40 * statistics: Display statistical information about connected clients
41 * pmtime: The time of a parameter change is transferred
42 * aic: Ansychronous input channels are supported
43 * messages: Channels with the attribute "messagetyp" are monitored and are
44 * sent as clear text message on change (V:6.0.10)
45 * polite: Server will not send any messages such as <pu> or <log> by itself
46 * list: Server understands <list> command
47 * login: SASL authentication is supported
48 * history: the message_history command is supported
49 * xsap: the xsap command is supported
50 * group: the server can handle xsad/data grouping
51 * (since commit 62b47b39 from 2014, before version 3)
52 */
53
54 #define MSR_FEATURES \
55 "pushparameters," \
56 "binparameters," \
57 "eventchannels," \
58 "statistics," \
59 "pmtime," \
60 "aic," \
61 "messages," \
62 "polite," \
63 "list," \
64 "login," \
65 "history," \
66 "xsap," \
67 "group"
68
69
70 #include "../Session.h"
71 #include "../PThread.h"
72 #include "../TCP.h"
73 #include "XmlParser.h"
74 #include "XmlElement.h"
75
76 #include <vector>
77 #include <set>
78 #include <queue>
79 #include <cstdio>
80
81 namespace PdServ {
82 class Task;
83 class Parameter;
84 class Variable;
85 struct TaskStatistics;
86 struct SessionStatistics;
87 }
88
89 class ParameterData;
90
91 namespace MsrProto {
92
93 class SubscriptionManager;
94 class Server;
95 class Parameter;
96
97 class Session:
98 public net::TCPSession,
99 public PdServ::Session {
100 public:
101 Session( Server *s, net::TCPServer* tcp);
102
103 void close();
104
105 void broadcast(Session *s, const struct timespec& ts,
106 const std::string &action, const std::string &element);
107 void parameterChanged(const Parameter*,
108 const char* data, const struct timespec*);
109 void setAIC(const Parameter* p);
110 void getSessionStatistics(PdServ::SessionStatistics &stats) const;
111 XmlElement createElement(const char *name);
112
113 const struct timespec *getTaskTime(const PdServ::Task* task) const;
114 const PdServ::TaskStatistics *getTaskStatistics(
115 const PdServ::Task* task) const;
116
117 double *getDouble() const {
118 return &tmp.dbl;
119 }
120
121 protected:
122 ~Session();
123 private:
124
125 Server * const server;
126
127 size_t inBytes;
128 size_t outBytes;
129
130 std::ostream xmlstream;
131
132 std::string commandId;
133 uint32_t eventId;
134
135 size_t getReceiveBufSize() const;
136
137 // Protection for inter-session communication
138 pthread::Mutex mutex;
139
140 typedef std::set<const PdServ::Variable*> PdServVariableSet;
141 PdServVariableSet knownVariables;
142
143 // List of parameters that have changed
144 typedef std::set<const Parameter*> ParameterSet;
145 ParameterSet changedParameter;
146
147 bool parameterMonitor;
148 ParameterSet parameterMonitorSet;
149 std::queue<ParameterData*> parameterMonitorData;
150
151 // Asynchronous input channels.
152 // These are actually parameters that are misused as input streams.
153 // Parameters in this set are not announced as changed as often as
154 // real parameters are.
155 typedef std::set<const PdServ::Parameter*> MainParameterSet;
156 MainParameterSet aic;
157 size_t aicDelay; // When 0, notify that aic's have changed
158
159 // Broadcast list.
160 typedef struct {
161 struct timespec ts;
162 std::string action;
163 std::string message;
164 44 } Broadcast;
165 typedef std::list<const Broadcast*> BroadcastList;
166 BroadcastList broadcastList;
167
168 typedef std::vector<SubscriptionManager*> SubscriptionManagerVector;
169 SubscriptionManagerVector subscriptionManager;
170 const SubscriptionManager *timeTask;
171
172 // Temporary memory space needed to handle statistic channels
173 union {
174 uint32_t uint32;
175 double dbl;
176 } mutable tmp;
177
178 void sendGreeting();
179 // Reimplemented from pthread::Thread
180 void run() override;
181
182 protected:
183 void initial() override;
184 void final() override;
185
186 // Reimplemented from PdServ::Session
187 ssize_t write(const void* buf, size_t len) override;
188 ssize_t read( void* buf, size_t len) override;
189 private:
190 std::string peerAddr(char sep) const override;
191 std::string localAddr(char sep) const override;
192
193 void processCommand(const XmlParser*);
194 // Management variables
195 bool p_running;
196 bool writeAccess;
197 bool quiet;
198 bool polite;
199 bool echoOn;
200 std::string remoteHostName;
201 std::string client;
202
203 // Here are all the commands the MSR protocol supports
204 void broadcast(const XmlParser*);
205 void echo(const XmlParser*);
206 void ping(const XmlParser*);
207 void readChannel(const XmlParser*);
208 void listDirectory(const XmlParser*);
209 void readParameter(const XmlParser*);
210 void readParamValues(const XmlParser*);
211 void readStatistics(const XmlParser*);
212 void messageHistory(const XmlParser*);
213 void remoteHost(const XmlParser*);
214 void writeParameter(const XmlParser*);
215 void xsad(const XmlParser*);
216 void xsod(const XmlParser*);
217 void xsap(const XmlParser*);
218 void xsop(const XmlParser*);
219 void authenticate(const XmlParser*);
220 };
221
222 }
223 #endif //MSRSESSION_H
224