Skip to content
Snippets Groups Projects
Commit 5890ae56 authored by Ruud Overeem's avatar Ruud Overeem
Browse files

Task #7367: Minimal implementation of lofar message class including unit test.

parent 247d65d4
No related branches found
No related tags found
No related merge requests found
...@@ -74,14 +74,16 @@ public: ...@@ -74,14 +74,16 @@ public:
virtual ~Message(); virtual ~Message();
// Return properties of the constructed or received message // Return properties of the constructed or received message
std::string system() const; std::string system() const { return (getXMLvalue("message.header.system")); }
std::string headerVersion() const; std::string headerVersion() const { return (getXMLvalue("message.header.version")); }
std::string payload() const; std::string payload() const { return (getXMLvalue("message.payload")); }
std::string from() const; std::string from() const { return (getXMLvalue("message.header.request.source")); }
std::string forUser() const; std::string forUser() const { return (getXMLvalue("message.header.request.user")); }
std::string summary() const; std::string uuid() const { return (getXMLvalue("message.header.request.uuid")); }
std::string toService() const; std::string summary() const { return (getXMLvalue("message.header.request.summary")); }
std::string toVersion() const; 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 // Construct the given fields as a QPID message
qpid::messaging::Message getQpidMsg() const { return (itsQpidMsg); } qpid::messaging::Message getQpidMsg() const { return (itsQpidMsg); }
...@@ -90,6 +92,9 @@ public: ...@@ -90,6 +92,9 @@ public:
std::string getRawContent() const { return (itsQpidMsg.getContent()); } std::string getRawContent() const { return (itsQpidMsg.getContent()); }
private: private:
// Internal very simple XML parser to get a key from the XML content.
string getXMLvalue(const string& key) const;
// datamembers // datamembers
qpid::messaging::Message itsQpidMsg; qpid::messaging::Message itsQpidMsg;
}; };
......
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
//# Includes //# Includes
#include <Common/LofarLogger.h> #include <Common/LofarLogger.h>
#include <Common/lofar_string.h> #include <Common/lofar_string.h>
#include <Common/StringUtil.h>
#include <MessageBus/Message.h> #include <MessageBus/Message.h>
namespace LOFAR { namespace LOFAR {
using namespace StringUtil;
const string LOFAR_MSG_TEMPLATE = "\ const string LOFAR_MSG_TEMPLATE = "\
<message>\n\ <message>\n\
...@@ -64,10 +66,9 @@ Message::Message(const std::string &from, ...@@ -64,10 +66,9 @@ Message::Message(const std::string &from,
cout << itsQpidMsg.getContent() << endl; 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; cout << itsQpidMsg.getContent() << endl;
} }
...@@ -103,45 +104,33 @@ void Message::setListPayload(const qpid::types::Variant::List &payload) ...@@ -103,45 +104,33 @@ void Message::setListPayload(const qpid::types::Variant::List &payload)
} }
// Return properties of the constructed or received message string Message::getXMLvalue(const string& key) const
std::string Message::system() const
{ {
return "???"; // get copy of content
} vector<string> labels = split(key, '.');
string content(itsQpidMsg.getContent());
std::string Message::headerVersion() const
{ // loop over subkeys
return "???"; string::size_type offset = 0;
} string::size_type begin;
string::size_type end;
std::string Message::payload() const for (size_t i = 0; i < labels.size(); ++i) {
{ // define tags to find
return "???"; string startTag("<"+labels[i]+">");
} string stopTag ("</"+labels[i]+">");
// search begin tag
std::string Message::from() const begin = content.find(startTag, offset);
{ if (begin == string::npos) {
return "???"; return ("???");
} }
// search end tag
std::string Message::forUser() const begin+=startTag.size();
{ end = content.find(stopTag, begin);
return "???"; if (end == string::npos) {
} return ("???");
}
std::string Message::summary() const }
{ return (content.substr(begin, end - begin));
return "???";
}
std::string Message::toService() const
{
return "???";
}
std::string Message::toVersion() const
{
return "???";
} }
......
...@@ -78,6 +78,17 @@ int main(int argc, char* argv[]) { ...@@ -78,6 +78,17 @@ int main(int argc, char* argv[]) {
string KVmapje("abc=[aap,noot,mies]\nmyInteger=5\nmyDouble=3.14"); string KVmapje("abc=[aap,noot,mies]\nmyInteger=5\nmyDouble=3.14");
msg1.setTXTPayload(KVmapje); 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); return (0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment