Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
20 namespace JDB {}
21 namespace JPP { using namespace JDB; }
22 
23 namespace JDB {
24 
25  using JLANG::JParseError;
26 
27 
28  /**
29  * Auxiliary data structure for reply message.
30  */
31  struct JReplyMessage {
32  /**
33  * Default constructor.
34  */
36  {}
37 
38 
39  /**
40  * Copy constructor.
41  *
42  * \param datalog data log
43  */
44  JReplyMessage(const JDatalogString& datalog)
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 
131  };
132 }
133 
134 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
bool match(const JReplyMessage &message) const
Get match.
static const std::string TOKEN_DELIMETER
Definition: JDAQTags.hh:52
is
Definition: JDAQCHSM.chsm:167
static const std::string RUN_CONTROL_CLIENT
Definition: JDAQTags.hh:38
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:61
Auxiliary data structure for datalog strings.
then awk string
friend std::istream & operator>>(std::istream &in, JReplyMessage &object)
Read message from input.
std::string toString() const
Convert tag to string.
Definition: JTag.hh:171
JReplyMessage()
Default constructor.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
std::string nickname
Exception for parsing value.
Definition: JException.hh:196
Auxiliary data structure for reply message.
friend std::ostream & operator<<(std::ostream &out, const JReplyMessage &object)
Write message to output.
Fixed parameters and ControlHost tags for KM3NeT DAQ.
char * loc(char *orig)
JReplyMessage(const JDatalogString &datalog)
Copy constructor.
ControlHost tag.