GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/msrproto/Session.h
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 0 3 0.0%
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 //Liste der Features der aktuellen rtlib-Version, wichtig, muß aktuell gehalten werden
36 //da der Testmanager sich auf die Features verläßt
37
38 #define MSR_FEATURES "pushparameters,binparameters,maschinehalt,eventchannels,statistics,pmtime,aic,messages,polite"
39
40 /* pushparameters: Parameter werden vom Echtzeitprozess an den Userprozess gesendet bei Änderung
41 binparameters: Parameter können Binär übertragen werden
42 maschinehalt: Rechner kann durch Haltbefehl heruntergefahren werden
43 eventchannels: Kanäle werden nur bei Änderung übertragen
44 statistics: Statistische Informationen über die anderen verbundenen Echtzeitprozesses
45 pmtime: Die Zeit der Änderungen eines Parameters wird vermerkt und übertragen
46 aic: ansychrone Input Kanäle
47 messages: Kanäle mit dem Attribut: "messagetyp" werden von der msr_lib überwacht und bei Änderung des Wertes als Klartextmeldung verschickt V:6.0.10
48
49 */
50
51 #include "../Session.h"
52 #include "XmlParser.h"
53 #include "XmlElement.h"
54
55 #include <commoncpp/thread.h>
56 #include <commoncpp/tcp.h>
57 #include <map>
58 #include <set>
59 #include <cstdio>
60
61 namespace PdServ {
62 class Parameter;
63 class SessionTaskData;
64 class Task;
65 class TaskStatistics;
66 class SessionStatistics;
67 }
68
69 namespace MsrProto {
70
71 class SubscriptionManager;
72 class TaskStatistics;
73 class SessionStatistics;
74 class Server;
75 class Parameter;
76 class Subscription;
77
78 class Session: public ost::Thread, public PdServ::Session {
79 public:
80 Session( Server *s, ost::TCPSocket *socket);
81 ~Session();
82
83 void broadcast(Session *s, const struct timespec& ts,
84 const std::string &action, const std::string &element);
85 void parameterChanged(const Parameter*);
86 void setAIC(const Parameter* p);
87 void getSessionStatistics(PdServ::SessionStatistics &stats) const;
88
89 const struct timespec *getTaskTime(const PdServ::Task *) const;
90 const PdServ::TaskStatistics *getTaskStatistics(
91 const PdServ::Task *) const;
92
93 double *getDouble() const {
94 return &tmp.dbl;
95 }
96
97 class TCPStream: public ost::Socket, public std::streambuf {
98 public:
99 TCPStream(ost::TCPSocket *socket);
100 ~TCPStream();
101
102 int read(char *buf, size_t n, timeout_t timeout);
103
104 XmlElement createElement(const char *name);
105
106 size_t inBytes;
107 size_t outBytes;
108
109 std::string peer;
110 std::string commandId;
111
112 private:
113 std::ostream os;
114
115 FILE *file;
116
117 // Reimplemented from std::streambuf
118 int overflow ( int c );
119 std::streamsize xsputn ( const char * s, std::streamsize n );
120 int sync();
121 };
122
123 private:
124 Server * const server;
125
126 TCPStream tcp;
127
128 std::ostream xmlstream;
129
130 // Protection for inter-session communication
131 ost::Semaphore mutex;
132
133 // List of parameters that have changed
134 typedef std::set<const Parameter*> ParameterSet;
135 ParameterSet changedParameter;
136
137 // Asynchronous input channels.
138 // These are actually parameters that are misused as input streams.
139 // Parameters in this set are not announced as changed as often as
140 // real parameters are.
141 typedef std::set<const PdServ::Parameter*> MainParameterSet;
142 MainParameterSet aic;
143 size_t aicDelay; // When 0, notify that aic's have changed
144
145 // Broadcast list.
146 typedef struct {
147 struct timespec ts;
148 std::string action;
149 std::string message;
150 } Broadcast;
151 typedef std::list<const Broadcast*> BroadcastList;
152 BroadcastList broadcastList;
153
154 typedef std::map<const PdServ::Task*, SubscriptionManager*>
155 SubscriptionManagerMap;
156 SubscriptionManagerMap subscriptionManager;
157 const SubscriptionManager *timeTask;
158
159 // Temporary memory space needed to handle statistic channels
160 union {
161 uint32_t uint32;
162 double dbl;
163 } mutable tmp;
164
165 // Reimplemented from ost::Thread
166 void initial();
167 void run();
168 void final();
169
170 // // Reimplemented from PdServ::Session
171 // void newSignal(const PdServ::Task *task, const PdServ::Signal *);
172 // void newSignalData(const PdServ::SessionTaskData*,
173 // const struct timespec *);
174
175 void processCommand(const XmlParser::Element&);
176 // Management variables
177 bool writeAccess;
178 bool quiet;
179 bool polite;
180 bool echoOn;
181 std::string peer;
182 std::string client;
183
184 // Here are all the commands the MSR protocol supports
185 void broadcast(const XmlParser::Element&);
186 void echo(const XmlParser::Element&);
187 void ping(const XmlParser::Element&);
188 void readChannel(const XmlParser::Element&);
189 void listDirectory(const XmlParser::Element&);
190 void readParameter(const XmlParser::Element&);
191 void readParamValues(const XmlParser::Element&);
192 void readStatistics(const XmlParser::Element&);
193 void remoteHost(const XmlParser::Element&);
194 void writeParameter(const XmlParser::Element&);
195 void xsad(const XmlParser::Element&);
196 void xsod(const XmlParser::Element&);
197 };
198
199 }
200 #endif //MSRSESSION_H
201