Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JReplyMessage.hh
Go to the documentation of this file.
1#ifndef __JDB_JREPLYMESSAGE__
2#define __JDB_JREPLYMESSAGE__
3
4#include <string>
5#include <istream>
6#include <ostream>
7#include <sstream>
8#include <iomanip>
9
10#include "JNet/JTag.hh"
11
12#include "JLang/JException.hh"
14
15#include "JDAQ/JDAQTags.hh"
16
17#include "JDatalogString.hh"
18
19
20namespace JDB {}
21namespace JPP { using namespace JDB; }
22
23namespace JDB {
24
26
27
28 /**
29 * Auxiliary data structure for reply message.
30 */
32 /**
33 * Default constructor.
34 */
37
38
39 /**
40 * Copy constructor.
41 *
42 * \param datalog data log
43 */
45 {
46 using namespace std;
47 using namespace JPP;
48 using namespace KM3NETDAQ;
49
50 if (datalog.source == RC_REPLY.toString()) {
51
52 this->tag = datalog.source;
53
54 istringstream is(datalog.data);
55
56 const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), TOKEN_DELIMETER));
57
58 is.imbue(loc);
59
60 if (is >> this->key >> this->ip >> this->nickname >> this->event >>this->state && this->key == RUN_CONTROL_CLIENT) {
61
62 } else {
63
64 THROW(JParseError, "Invalid string " << datalog.source << " " << datalog.data);
65 }
66
67 } else {
68
69 THROW(JParseError, "Invalid source " << datalog.source);
70 }
71 }
72
73
74 /**
75 * Get match.
76 *
77 * \param message message
78 * \return true if message matches; else false
79 */
80 bool match(const JReplyMessage& message) const
81 {
82 if (!message.nickname.empty() && message.nickname != nickname) { return false; }
83 if (!message.ip .empty() && message.ip != ip) { return false; }
84 if (!message.event .empty() && message.event != event) { return false; }
85 if (!message.state .empty() && message.state != state) { return false; }
86
87 return true;
88 }
89
90
91 /**
92 * Read message from input.
93 *
94 * \param in input stream
95 * \param object message
96 * \return input stream
97 */
98 friend inline std::istream& operator>>(std::istream& in, JReplyMessage& object)
99 {
100 return in >> object.key
101 >> object.ip
102 >> object.nickname
103 >> object.event
104 >> object.state;
105 }
106
107
108 /**
109 * Write message to output.
110 *
111 * \param out output stream
112 * \param object message
113 * \return output stream
114 */
115 friend inline std::ostream& operator<<(std::ostream& out, const JReplyMessage& object)
116 {
117 return out << object.key
118 << object.ip
119 << object.nickname
120 << object.event
121 << object.state;
122 }
123
124
125 std::string tag;
126 std::string key;
127 std::string ip;
128 std::string nickname;
129 std::string event;
130 std::string state;
131 };
132}
133
134#endif
Fixed parameters and ControlHost tags for KM3NeT DAQ.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
ControlHost tag.
Exception for parsing value.
Auxiliary class to specify white space character(s) in currect locale.
char * loc(char *orig)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Auxiliary data structure for datalog strings.
Auxiliary data structure for reply message.
JReplyMessage(const JDatalogString &datalog)
Copy constructor.
friend std::istream & operator>>(std::istream &in, JReplyMessage &object)
Read message from input.
JReplyMessage()
Default constructor.
bool match(const JReplyMessage &message) const
Get match.
friend std::ostream & operator<<(std::ostream &out, const JReplyMessage &object)
Write message to output.