#ifndef __JDB_JREPLYMESSAGE__ #define __JDB_JREPLYMESSAGE__ #include #include #include #include #include #include "JNet/JTag.hh" #include "JLang/JException.hh" #include "JLang/JWhiteSpacesFacet.hh" #include "JDAQ/JDAQTags.hh" #include "JDatalogString.hh" namespace JDB {} namespace JPP { using namespace JDB; } namespace JDB { using JLANG::JParseError; /** * Auxiliary data structure for reply message. */ struct JReplyMessage { /** * Default constructor. */ JReplyMessage() {} /** * Copy constructor. * * \param datalog data log */ JReplyMessage(const JDatalogString& datalog) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; if (datalog.source == RC_REPLY.toString()) { this->tag = datalog.source; istringstream is(datalog.data); const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), TOKEN_DELIMETER)); is.imbue(loc); if (is >> this->key >> this->ip >> this->nickname >> this->event >>this->state && this->key == RUN_CONTROL_CLIENT) { } else { THROW(JParseError, "Invalid string " << datalog.source << " " << datalog.data); } } else { THROW(JParseError, "Invalid source " << datalog.source); } } /** * Get match. * * \param message message * \return true if message matches; else false */ bool match(const JReplyMessage& message) const { if (!message.nickname.empty() && message.nickname != nickname) { return false; } if (!message.ip .empty() && message.ip != ip) { return false; } if (!message.event .empty() && message.event != event) { return false; } if (!message.state .empty() && message.state != state) { return false; } return true; } /** * Read message from input. * * \param in input stream * \param object message * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JReplyMessage& object) { return in >> object.key >> object.ip >> object.nickname >> object.event >> object.state; } /** * Write message to output. * * \param out output stream * \param object message * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JReplyMessage& object) { return out << object.key << object.ip << object.nickname << object.event << object.state; } std::string tag; std::string key; std::string ip; std::string nickname; std::string event; std::string state; }; } #endif