diff --git a/LCS/MessageBus/include/MessageBus/Message.h b/LCS/MessageBus/include/MessageBus/Message.h index 34b03e4bbb84af2cf551c0e4ac1415e8e7b77dd4..32d001f6c7e6492dad633403cfac8d58082bf367 100644 --- a/LCS/MessageBus/include/MessageBus/Message.h +++ b/LCS/MessageBus/include/MessageBus/Message.h @@ -74,14 +74,16 @@ public: virtual ~Message(); // Return properties of the constructed or received message - std::string system() const; - std::string headerVersion() const; - std::string payload() const; - std::string from() const; - std::string forUser() const; - std::string summary() const; - std::string toService() const; - std::string toVersion() const; + std::string system() const { return (getXMLvalue("message.header.system")); } + std::string headerVersion() const { return (getXMLvalue("message.header.version")); } + std::string payload() const { return (getXMLvalue("message.payload")); } + std::string from() const { return (getXMLvalue("message.header.request.source")); } + std::string forUser() const { return (getXMLvalue("message.header.request.user")); } + std::string uuid() const { return (getXMLvalue("message.header.request.uuid")); } + std::string summary() const { return (getXMLvalue("message.header.request.summary")); } + std::string timestamp() const { return (getXMLvalue("message.header.request.timestamp")); } + std::string toService() const { return (getXMLvalue("message.header.service.name")); } + std::string toVersion() const { return (getXMLvalue("message.header.service.version")); } // Construct the given fields as a QPID message qpid::messaging::Message getQpidMsg() const { return (itsQpidMsg); } @@ -90,6 +92,9 @@ public: std::string getRawContent() const { return (itsQpidMsg.getContent()); } private: + // Internal very simple XML parser to get a key from the XML content. + string getXMLvalue(const string& key) const; + // datamembers qpid::messaging::Message itsQpidMsg; }; diff --git a/LCS/MessageBus/src/Message.cc b/LCS/MessageBus/src/Message.cc index 9c829aa9037192ad0f0de57d08060b4a6c9c35d6..8962f9653c3ccbdd46b6d681457395edeb34666a 100644 --- a/LCS/MessageBus/src/Message.cc +++ b/LCS/MessageBus/src/Message.cc @@ -26,9 +26,11 @@ //# Includes #include <Common/LofarLogger.h> #include <Common/lofar_string.h> +#include <Common/StringUtil.h> #include <MessageBus/Message.h> namespace LOFAR { + using namespace StringUtil; const string LOFAR_MSG_TEMPLATE = "\ <message>\n\ @@ -64,10 +66,9 @@ Message::Message(const std::string &from, cout << itsQpidMsg.getContent() << endl; } -Message::Message(const qpid::messaging::Message &qpidMsg) +Message::Message(const qpid::messaging::Message &qpidMsg) : + itsQpidMsg(qpidMsg) { - itsQpidMsg.setContent(formatString(LOFAR_MSG_TEMPLATE.c_str(), "", "", - "", "", "", "", "", qpidMsg.getContent().c_str())); cout << itsQpidMsg.getContent() << endl; } @@ -103,45 +104,33 @@ void Message::setListPayload(const qpid::types::Variant::List &payload) } -// Return properties of the constructed or received message -std::string Message::system() const +string Message::getXMLvalue(const string& key) const { - return "???"; -} - -std::string Message::headerVersion() const -{ - return "???"; -} - -std::string Message::payload() const -{ - return "???"; -} - -std::string Message::from() const -{ - return "???"; -} - -std::string Message::forUser() const -{ - return "???"; -} - -std::string Message::summary() const -{ - return "???"; -} - -std::string Message::toService() const -{ - return "???"; -} - -std::string Message::toVersion() const -{ - return "???"; + // get copy of content + vector<string> labels = split(key, '.'); + string content(itsQpidMsg.getContent()); + + // loop over subkeys + string::size_type offset = 0; + string::size_type begin; + string::size_type end; + for (size_t i = 0; i < labels.size(); ++i) { + // define tags to find + string startTag("<"+labels[i]+">"); + string stopTag ("</"+labels[i]+">"); + // search begin tag + begin = content.find(startTag, offset); + if (begin == string::npos) { + return ("???"); + } + // search end tag + begin+=startTag.size(); + end = content.find(stopTag, begin); + if (end == string::npos) { + return ("???"); + } + } + return (content.substr(begin, end - begin)); } diff --git a/LCS/MessageBus/test/tMessage.cc b/LCS/MessageBus/test/tMessage.cc index 34f86a4a57232d443d4a69037da41d6ffda039eb..e1d6f288e418dd631afa989f9d4f2cefc96b53cd 100644 --- a/LCS/MessageBus/test/tMessage.cc +++ b/LCS/MessageBus/test/tMessage.cc @@ -78,6 +78,17 @@ int main(int argc, char* argv[]) { string KVmapje("abc=[aap,noot,mies]\nmyInteger=5\nmyDouble=3.14"); msg1.setTXTPayload(KVmapje); + cout << "system : " << msg1.system() << endl; + cout << "systemversion : " << msg1.headerVersion() << endl; + cout << "serviceName : " << msg1.toService() << endl; + cout << "serviceVersion : " << msg1.toVersion() << endl; + cout << "summary : " << msg1.summary() << endl; + cout << "timestamp : " << msg1.timestamp() << endl; + cout << "source : " << msg1.from() << endl; + cout << "user : " << msg1.forUser() << endl; + cout << "uuid : " << msg1.uuid() << endl; + cout << "payload : " << msg1.payload() << endl; + return (0);