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:
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;
};
......
......@@ -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));
}
......
......@@ -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);
......
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