Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
9dfad4a0
Commit
9dfad4a0
authored
9 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Task #7520: Provide MessageContent::Property objects for all defined XML entities
parent
2ed32dd3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
LCS/MessageBus/include/MessageBus/Message.h
+55
-15
55 additions, 15 deletions
LCS/MessageBus/include/MessageBus/Message.h
LCS/MessageBus/src/Message.cc
+56
-28
56 additions, 28 deletions
LCS/MessageBus/src/Message.cc
LCS/MessageBus/test/tMessage.cc
+16
-16
16 additions, 16 deletions
LCS/MessageBus/test/tMessage.cc
with
127 additions
and
59 deletions
LCS/MessageBus/include/MessageBus/Message.h
+
55
−
15
View file @
9dfad4a0
...
@@ -45,7 +45,7 @@ class MessageContent
...
@@ -45,7 +45,7 @@ class MessageContent
{
{
public:
public:
// Construct a message
// Construct a message
MessageContent
()
{}
;
MessageContent
();
// With header info
// With header info
MessageContent
(
MessageContent
(
...
@@ -80,20 +80,52 @@ public:
...
@@ -80,20 +80,52 @@ public:
virtual
~
MessageContent
();
virtual
~
MessageContent
();
/*
* A 'Property' is getter/setter for a part of the message content.
*
* It provides a string interface.
*/
class
Property
{
public:
// normal getters and setters
void
set
(
const
std
::
string
&
value
)
{
itsContent
->
setXMLvalue
(
itsKey
,
value
);
}
std
::
string
get
()
const
{
return
itsContent
->
getXMLvalue
(
itsKey
);
}
// C++ operator overloading
void
operator
=
(
const
std
::
string
&
value
)
{
set
(
value
);
}
operator
std
::
string
()
const
{
return
get
();
}
bool
operator
==
(
const
Property
&
other
)
const
{
return
(
std
::
string
)
*
this
==
(
std
::
string
)
other
;
}
bool
operator
==
(
const
std
::
string
&
other
)
const
{
return
(
std
::
string
)
*
this
==
other
;
}
bool
operator
==
(
const
char
*
other
)
const
{
return
(
std
::
string
)
*
this
==
std
::
string
(
other
);
}
private
:
Property
()
:
itsContent
(
0
),
itsKey
(
""
)
{}
void
attach
(
MessageContent
*
content
,
const
std
::
string
&
key
)
{
itsContent
=
content
;
itsKey
=
key
;
}
MessageContent
*
itsContent
;
std
::
string
itsKey
;
friend
class
MessageContent
;
};
// Return properties of the constructed or received message
// Return properties of the constructed or received message
std
::
string
system
()
const
{
return
(
getXMLvalue
(
"message/header/system"
));
}
Property
system
;
std
::
string
headerVersion
()
const
{
return
(
getXMLvalue
(
"message/header/version"
));
}
Property
headerVersion
;
std
::
string
protocol
()
const
{
return
(
getXMLvalue
(
"message/header/protocol/name"
));
}
Property
protocol
;
std
::
string
protocolVersion
()
const
{
return
(
getXMLvalue
(
"message/header/protocol/version"
));
}
Property
protocolVersion
;
std
::
string
from
()
const
{
return
(
getXMLvalue
(
"message/header/source/name"
));
}
std
::
string
forUser
()
const
{
return
(
getXMLvalue
(
"message/header/source/user"
));
}
Property
name
;
std
::
string
uuid
()
const
{
return
(
getXMLvalue
(
"message/header/source/uuid"
));
}
Property
user
;
std
::
string
summary
()
const
{
return
(
getXMLvalue
(
"message/header/source/summary"
));
}
Property
uuid
;
std
::
string
timestamp
()
const
{
return
(
getXMLvalue
(
"message/header/source/timestamp"
));
}
Property
summary
;
std
::
string
momid
()
const
{
return
(
getXMLvalue
(
"message/header/ids/momid"
));
}
Property
timestamp
;
std
::
string
sasid
()
const
{
return
(
getXMLvalue
(
"message/header/ids/sasid"
));
}
Property
momid
;
std
::
string
payload
()
const
{
return
(
getXMLvalue
(
"message/payload"
));
}
Property
sasid
;
std
::
string
header
()
const
{
return
(
getXMLvalue
(
"message/header"
));
}
Property
payload
;
Property
header
;
// Return a QPID message with our content
// Return a QPID message with our content
qpid
::
messaging
::
Message
qpidMsg
()
const
;
qpid
::
messaging
::
Message
qpidMsg
()
const
;
...
@@ -111,15 +143,23 @@ public:
...
@@ -111,15 +143,23 @@ public:
void
setXMLvalue
(
const
std
::
string
&
key
,
const
std
::
string
&
data
);
void
setXMLvalue
(
const
std
::
string
&
key
,
const
std
::
string
&
data
);
private
:
private
:
void
addProperties
();
// -- datamembers --
// -- datamembers --
std
::
string
itsContent
;
std
::
string
itsContent
;
};
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
MessageContent
&
msg
)
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
MessageContent
&
msg
)
{
{
return
(
msg
.
print
(
os
));
return
(
msg
.
print
(
os
));
}
}
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
MessageContent
::
Property
&
prop
)
{
os
<<
(
std
::
string
)
prop
;
return
os
;
}
class
Message
class
Message
{
{
public:
public:
...
...
This diff is collapsed.
Click to expand it.
LCS/MessageBus/src/Message.cc
+
56
−
28
View file @
9dfad4a0
...
@@ -84,6 +84,11 @@ static string _uuid() {
...
@@ -84,6 +84,11 @@ static string _uuid() {
return
uuid
.
str
();
return
uuid
.
str
();
}
}
MessageContent
::
MessageContent
()
{
addProperties
();
}
MessageContent
::
MessageContent
(
const
std
::
string
&
from
,
MessageContent
::
MessageContent
(
const
std
::
string
&
from
,
const
std
::
string
&
forUser
,
const
std
::
string
&
forUser
,
const
std
::
string
&
summary
,
const
std
::
string
&
summary
,
...
@@ -94,29 +99,55 @@ MessageContent::MessageContent(const std::string &from,
...
@@ -94,29 +99,55 @@ MessageContent::MessageContent(const std::string &from,
:
:
itsContent
(
LOFAR_MSG_TEMPLATE
)
itsContent
(
LOFAR_MSG_TEMPLATE
)
{
{
setXMLvalue
(
"message/header/system"
,
LOFAR
::
system
);
addProperties
();
setXMLvalue
(
"message/header/version"
,
LOFAR
::
headerVersion
);
setXMLvalue
(
"message/header/protocol/name"
,
protocol
);
this
->
system
=
LOFAR
::
system
;
setXMLvalue
(
"message/header/protocol/version"
,
protocolVersion
);
this
->
headerVersion
=
LOFAR
::
headerVersion
;
setXMLvalue
(
"message/header/source/name"
,
from
);
setXMLvalue
(
"message/header/source/user"
,
forUser
);
this
->
protocol
=
protocol
;
setXMLvalue
(
"message/header/source/uuid"
,
_uuid
());
this
->
protocolVersion
=
protocolVersion
;
setXMLvalue
(
"message/header/source/summary"
,
summary
);
this
->
name
=
from
;
setXMLvalue
(
"message/header/source/timestamp"
,
_timestamp
());
this
->
user
=
forUser
;
setXMLvalue
(
"message/header/ids/momid"
,
momid
);
this
->
uuid
=
_uuid
();
setXMLvalue
(
"message/header/ids/sasid"
,
sasid
);
this
->
summary
=
summary
;
this
->
timestamp
=
_timestamp
();
this
->
momid
=
momid
;
this
->
sasid
=
sasid
;
}
}
MessageContent
::
MessageContent
(
const
qpid
::
messaging
::
Message
&
qpidMsg
)
MessageContent
::
MessageContent
(
const
qpid
::
messaging
::
Message
&
qpidMsg
)
:
:
itsContent
(
qpidMsg
.
getContent
())
itsContent
(
qpidMsg
.
getContent
())
{
{
addProperties
();
}
}
MessageContent
::~
MessageContent
()
MessageContent
::~
MessageContent
()
{
{
}
}
void
MessageContent
::
addProperties
()
{
system
.
attach
(
this
,
"message/header/system"
);
headerVersion
.
attach
(
this
,
"message/header/version"
);
protocol
.
attach
(
this
,
"message/header/protocol/name"
);
protocolVersion
.
attach
(
this
,
"message/header/protocol/version"
);
name
.
attach
(
this
,
"message/header/source/name"
);
user
.
attach
(
this
,
"message/header/source/user"
);
uuid
.
attach
(
this
,
"message/header/source/uuid"
);
summary
.
attach
(
this
,
"message/header/source/summary"
);
timestamp
.
attach
(
this
,
"message/header/source/timestamp"
);
momid
.
attach
(
this
,
"message/header/ids/momid"
);
sasid
.
attach
(
this
,
"message/header/ids/sasid"
);
payload
.
attach
(
this
,
"message/payload"
);
header
.
attach
(
this
,
"message/header"
);
}
qpid
::
messaging
::
Message
MessageContent
::
qpidMsg
()
const
{
qpid
::
messaging
::
Message
MessageContent
::
qpidMsg
()
const
{
qpid
::
messaging
::
Message
qpidMsg
;
qpid
::
messaging
::
Message
qpidMsg
;
...
@@ -139,27 +170,24 @@ void MessageContent::setTXTPayload (const std::string &payload)
...
@@ -139,27 +170,24 @@ void MessageContent::setTXTPayload (const std::string &payload)
std
::
string
MessageContent
::
short_desc
()
const
std
::
string
MessageContent
::
short_desc
()
const
{
{
return
formatString
(
"[%s] [sasid %s] %s"
,
uuid
().
c_str
(),
sasid
().
c_str
(),
summary
().
c_str
());
return
formatString
(
"[%s] [sasid %s] %s"
,
uuid
.
get
().
c_str
(),
sasid
.
get
().
c_str
(),
summary
.
get
().
c_str
());
}
}
std
::
ostream
&
MessageContent
::
print
(
std
::
ostream
&
os
)
const
std
::
ostream
&
MessageContent
::
print
(
std
::
ostream
&
os
)
const
{
{
os
<<
"system : "
<<
system
()
<<
endl
;
os
<<
"system : "
<<
system
<<
endl
;
os
<<
"systemversion : "
<<
headerVersion
()
<<
endl
;
os
<<
"systemversion : "
<<
headerVersion
<<
endl
;
os
<<
"protocolName : "
<<
protocol
()
<<
endl
;
os
<<
"protocolName : "
<<
protocol
<<
endl
;
os
<<
"protocolVersion: "
<<
protocolVersion
()
<<
endl
;
os
<<
"protocolVersion: "
<<
protocolVersion
<<
endl
;
os
<<
"summary : "
<<
summary
()
<<
endl
;
os
<<
"summary : "
<<
summary
<<
endl
;
os
<<
"timestamp : "
<<
timestamp
()
<<
endl
;
os
<<
"timestamp : "
<<
timestamp
<<
endl
;
os
<<
"source : "
<<
from
()
<<
endl
;
os
<<
"source (name) : "
<<
name
<<
endl
;
os
<<
"user : "
<<
forUser
()
<<
endl
;
os
<<
"user : "
<<
user
<<
endl
;
os
<<
"uuid : "
<<
uuid
()
<<
endl
;
os
<<
"uuid : "
<<
uuid
<<
endl
;
os
<<
"momid : "
<<
momid
()
<<
endl
;
os
<<
"momid : "
<<
momid
<<
endl
;
os
<<
"sasid : "
<<
sasid
()
<<
endl
;
os
<<
"sasid : "
<<
sasid
<<
endl
;
os
<<
"payload : "
<<
payload
()
<<
endl
;
os
<<
"payload : "
<<
payload
<<
endl
;
os
<<
"BEGIN FULL PACKET"
<<
endl
;
return
(
os
);
os
<<
itsContent
<<
endl
;
os
<<
"END FULL PACKET"
<<
endl
;
return
(
os
);
}
}
string
MessageContent
::
getXMLvalue
(
const
string
&
key
)
const
string
MessageContent
::
getXMLvalue
(
const
string
&
key
)
const
...
...
This diff is collapsed.
Click to expand it.
LCS/MessageBus/test/tMessage.cc
+
16
−
16
View file @
9dfad4a0
...
@@ -36,30 +36,30 @@ SUITE(MessageContent) {
...
@@ -36,30 +36,30 @@ SUITE(MessageContent) {
TEST
(
newmsg
)
{
TEST
(
newmsg
)
{
// Create a message from scratch
// Create a message from scratch
MessageContent
msg
(
"
FROM
"
,
"
FOR
USER"
,
"SUMMARY"
,
"PROTOCOL"
,
"1.2"
,
"MOMID"
,
"SASID"
);
MessageContent
msg
(
"
NAME
"
,
"USER"
,
"SUMMARY"
,
"PROTOCOL"
,
"1.2"
,
"MOMID"
,
"SASID"
);
CHECK_EQUAL
(
"
FROM
"
,
msg
.
from
());
CHECK_EQUAL
(
"
NAME
"
,
msg
.
name
.
get
());
CHECK_EQUAL
(
"
FOR
USER"
,
msg
.
forUser
());
CHECK_EQUAL
(
"USER"
,
msg
.
user
.
get
());
CHECK_EQUAL
(
"SUMMARY"
,
msg
.
summary
());
CHECK_EQUAL
(
"SUMMARY"
,
msg
.
summary
.
get
());
CHECK_EQUAL
(
"PROTOCOL"
,
msg
.
protocol
());
CHECK_EQUAL
(
"PROTOCOL"
,
msg
.
protocol
.
get
());
CHECK_EQUAL
(
"1.2"
,
msg
.
protocolVersion
());
CHECK_EQUAL
(
"1.2"
,
msg
.
protocolVersion
.
get
());
CHECK_EQUAL
(
"MOMID"
,
msg
.
momid
());
CHECK_EQUAL
(
"MOMID"
,
msg
.
momid
.
get
());
CHECK_EQUAL
(
"SASID"
,
msg
.
sasid
());
CHECK_EQUAL
(
"SASID"
,
msg
.
sasid
.
get
());
}
}
TEST
(
existingmsg
)
{
TEST
(
existingmsg
)
{
MessageContent
orig
(
"
FROM
"
,
"
FOR
USER"
,
"SUMMARY"
,
"PROTOCOL"
,
"1.2"
,
"MOMID"
,
"SASID"
);
MessageContent
orig
(
"
NAME
"
,
"USER"
,
"SUMMARY"
,
"PROTOCOL"
,
"1.2"
,
"MOMID"
,
"SASID"
);
// Create a qpid message and parse it again
// Create a qpid message and parse it again
MessageContent
copy
(
orig
.
qpidMsg
());
MessageContent
copy
(
orig
.
qpidMsg
());
CHECK_EQUAL
(
orig
.
from
()
,
copy
.
from
()
);
CHECK_EQUAL
(
orig
.
name
,
copy
.
name
);
CHECK_EQUAL
(
orig
.
forUser
(),
copy
.
forU
ser
()
);
CHECK_EQUAL
(
orig
.
user
,
copy
.
u
ser
);
CHECK_EQUAL
(
orig
.
summary
()
,
copy
.
summary
()
);
CHECK_EQUAL
(
orig
.
summary
,
copy
.
summary
);
CHECK_EQUAL
(
orig
.
protocol
()
,
copy
.
protocol
()
);
CHECK_EQUAL
(
orig
.
protocol
,
copy
.
protocol
);
CHECK_EQUAL
(
orig
.
protocolVersion
()
,
copy
.
protocolVersion
()
);
CHECK_EQUAL
(
orig
.
protocolVersion
,
copy
.
protocolVersion
);
CHECK_EQUAL
(
orig
.
momid
()
,
copy
.
momid
()
);
CHECK_EQUAL
(
orig
.
momid
,
copy
.
momid
);
CHECK_EQUAL
(
orig
.
sasid
()
,
copy
.
sasid
()
);
CHECK_EQUAL
(
orig
.
sasid
,
copy
.
sasid
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment