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