From 55c0a6d10429a101517af807907a059c9e17b2f1 Mon Sep 17 00:00:00 2001
From: Ruud Overeem <overeem@astron.nl>
Date: Tue, 3 Feb 2015 14:56:29 +0000
Subject: [PATCH] Task #7342: Update to new header format.

---
 LCS/MessageBus/include/MessageBus/Message.h | 39 +++++++++++++--------
 LCS/MessageBus/src/LofarMsgTemplate.txt     | 14 +++++---
 LCS/MessageBus/src/Message.cc               | 31 ++++++++++------
 LCS/MessageBus/test/tMessage.cc             |  2 +-
 4 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/LCS/MessageBus/include/MessageBus/Message.h b/LCS/MessageBus/include/MessageBus/Message.h
index 09bbff90813..1ea13accad7 100644
--- a/LCS/MessageBus/include/MessageBus/Message.h
+++ b/LCS/MessageBus/include/MessageBus/Message.h
@@ -55,11 +55,17 @@ public:
     // Human-readable summary describing this request
     const std::string &summary,
 
-    // Service to send this message to
-    const std::string &toService,
+    // Protocol of the contents of the message
+    const std::string &protocol,
 
     // Version of the protocol we're using to describe the payload
-    const std::string &toVersion
+    const std::string &protocolVersion,
+
+    // momID of the information (if available)
+    const std::string &momID,
+
+    // sasID of the information (if available)
+    const std::string &sasID
   );
 
   // Parse a message
@@ -77,16 +83,19 @@ public:
   virtual ~Message();
 
   // Return properties of the constructed or received message
-  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")); }
+  std::string system() const		  { return (getXMLvalue("message.header.system")); }
+  std::string headerVersion() const   { return (getXMLvalue("message.header.version")); }
+  std::string protocol() const		  { return (getXMLvalue("message.header.protocol.name")); }
+  std::string protocolVersion() const { return (getXMLvalue("message.header.protocol.version")); }
+  std::string from() const			  { return (getXMLvalue("message.header.source.name")); }
+  std::string forUser() const		  { return (getXMLvalue("message.header.source.user")); }
+  std::string uuid() const			  { return (getXMLvalue("message.header.source.uuid")); }
+  std::string summary() const		  { return (getXMLvalue("message.header.source.summary")); }
+  std::string timestamp() const		  { return (getXMLvalue("message.header.source.timestamp")); }
+  std::string momid() const			  { return (getXMLvalue("message.header.ids.momid")); }
+  std::string sasis() const			  { return (getXMLvalue("message.header.ids.sasid")); }
+  std::string payload() const		  { return (getXMLvalue("message.payload")); }
+  std::string header() const		  { return (getXMLvalue("message.header")); }
 
   // Construct the given fields as a QPID message
   qpid::messaging::Message& qpidMsg() { return (itsQpidMsg); }
@@ -97,10 +106,10 @@ public:
   // function for printing
   std::ostream& print (std::ostream& os) const;
 
-private:
-  // Internal very simple XML parser to get a key from the XML content.
+  // Very simple XML parser to get a key from the XML content.
   std::string getXMLvalue(const std::string& key) const;
 
+private:
   // -- datamembers -- 
   qpid::messaging::Message itsQpidMsg;
 };
diff --git a/LCS/MessageBus/src/LofarMsgTemplate.txt b/LCS/MessageBus/src/LofarMsgTemplate.txt
index 79833ea998e..796df813bad 100644
--- a/LCS/MessageBus/src/LofarMsgTemplate.txt
+++ b/LCS/MessageBus/src/LofarMsgTemplate.txt
@@ -3,17 +3,21 @@
    <header>
       <system>LOFAR</system>
       <version>1.0.0</version>
-      <service>
+      <protocol>
          <name>%s</name>
          <version>%s</version>
-      </service>
-      <request>
-         <source>%s</source>
+      </protocol>
+      <source>
+         <name>%s</name>
          <user>%s</user>
          <uuid>%s</uuid>
          <timestamp>%s</timestamp>
          <summary>%s</summary>
-      </request>
+      </source>
+      <ids>
+         <momid>%s</momid>
+         <sasid>%s</sasid>
+      </ids>
    </header>
    <payload>
 %s
diff --git a/LCS/MessageBus/src/Message.cc b/LCS/MessageBus/src/Message.cc
index 85633153d5f..d2d056cebf9 100644
--- a/LCS/MessageBus/src/Message.cc
+++ b/LCS/MessageBus/src/Message.cc
@@ -37,17 +37,21 @@ const string LOFAR_MSG_TEMPLATE = "\
    <header>\n\
       <system>LOFAR</system>\n\
       <version>1.0.0</version>\n\
-      <service>\n\
+      <protocol>\n\
          <name>%s</name>\n\
          <version>%s</version>\n\
-      </service>\n\
-      <request>\n\
-         <source>%s</source>\n\
+      </protocol>\n\
+      <source>\n\
+         <name>%s</name>\n\
          <user>%s</user>\n\
          <uuid>%s</uuid>\n\
          <timestamp>%s</timestamp>\n\
          <summary>%s</summary>\n\
-      </request>\n\
+      </source>\n\
+      <ids>\n\
+         <momid>%s</momid>\n\
+         <sasid>%s</sasid>\n\
+      </ids>\n\
    </header>\n\
    <payload>\n\
 %s\n\
@@ -57,11 +61,14 @@ const string LOFAR_MSG_TEMPLATE = "\
 Message::Message(const std::string &from,
 				 const std::string &forUser,
 				 const std::string &summary,
-				 const std::string &toService,
-				 const std::string &toVersion) 
+				 const std::string &protocol,
+				 const std::string &protocolVersion,
+				 const std::string &momid,
+				 const std::string &sasid) 
 {	
-	itsQpidMsg.setContent(formatString(LOFAR_MSG_TEMPLATE.c_str(), toService.c_str(), toVersion.c_str(),
-										from.c_str(), forUser.c_str(), "", "", summary.c_str(), "%s"));
+	itsQpidMsg.setContent(formatString(LOFAR_MSG_TEMPLATE.c_str(), protocol.c_str(), protocolVersion.c_str(),
+										from.c_str(), forUser.c_str(), "", "", summary.c_str(), 
+										momid.c_str(), sasid.c_str(), "%s"));
 
 	cout << itsQpidMsg.getContent() << endl;
 }
@@ -102,13 +109,15 @@ std::ostream& Message::print (std::ostream& os) const
 {
 	os << "system         : " << system() << endl;
     os << "systemversion  : " << headerVersion() << endl;
-    os << "serviceName    : " << toService() << endl;
-    os << "serviceVersion : " << toVersion() << endl;
+    os << "protocolName   : " << protocol() << endl;
+    os << "protocolVersion: " << protocolVersion() << endl;
     os << "summary        : " << summary() << endl;
     os << "timestamp      : " << timestamp() << endl;
     os << "source         : " << from() << endl;
     os << "user           : " << forUser() << endl;
     os << "uuid           : " << uuid() << endl;
+    os << "momid          : " << momid() << endl;
+    os << "sasid          : " << sasis() << endl;
     os << "payload        : " << payload() << endl;
 	return (os);
 }
diff --git a/LCS/MessageBus/test/tMessage.cc b/LCS/MessageBus/test/tMessage.cc
index 38077c04773..cd0c4a8e49d 100644
--- a/LCS/MessageBus/test/tMessage.cc
+++ b/LCS/MessageBus/test/tMessage.cc
@@ -70,7 +70,7 @@ int main(int argc, char* argv[]) {
 		return (1);
 	}
 
-	Message	msg1("mySubSystem", "user", "some test message", "lofar.observation.start", "1.0");
+	Message	msg1("mySubSystem", "user", "some test message", "lofar.observation.start", "1.0", "12345", "54321");
 
 	qpid::messaging::Message	qpMsg("Qpid message");
 	Message		msg2(qpMsg);
-- 
GitLab