25 #include <interface/message_queue.h> 28 #include <interfaces/test.h> 37 cout <<
"Iterating through messages:" << endl;
40 for ( i = mq->
begin(); i != mq->
end(); ++i) {
42 cout <<
"Message " << i.
id() <<
" int: " 44 <<
" type: " <<
typeid((*i)).name()
47 cout <<
"It's just a message" << endl;
49 cout <<
"Message " << i.
id() <<
" is not of correct type, it is " <<
typeid((*i)).name() << endl;
56 main(
int argc,
char **argv)
62 cout <<
"Message queue initialized, now appending three test messages" << endl;
69 cout <<
"m1 added with id " <<
id << endl;
71 cout <<
"m1 added with id " <<
id << endl;
73 cout <<
"m2 added with id " <<
id << endl;
75 cout <<
"m3 added with id " <<
id << endl;
77 cout <<
"m4 (of different type!) added with id " <<
id << endl;
79 cout <<
"Size is now " << mq->
size() << endl;
81 cout <<
"Unreferencing messages" << endl;
87 cout <<
"Appending m1 again" << endl;
89 cout <<
"m1 added with id " <<
id << endl;
90 cout <<
"Size is now " << mq->
size() << endl;
91 cout <<
"m1 refcount is now " << m1->
refcount() << endl;
95 cout <<
"Now removing message m1 once" << endl;
100 cout <<
"m1 has refcount " << m1->
refcount() << endl;
102 cout <<
"Now removing message m2" << endl;
106 cout <<
"Now removing message m4" << endl;
110 cout <<
"Size is now " << mq->
size() << endl;
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void unref()
Decrement reference count and conditionally delete this instance.
unsigned int id() const
Get ID of current element or 0 if element is end.
unsigned int refcount()
Get reference count for this instance.
MessageIterator end()
Get iterator to element beyond end of message queue list.
Fawkes library namespace.
MessageType * get() const
Get current message of given type.
Message queue used in interfaces.
bool is() const
Check if message is of given type.
unsigned int size() const
Get number of messages in queue.
SetTestIntMessage Fawkes BlackBoard Interface Message.
MessageIterator begin()
Get iterator to first element in message queue.
void append(Message *msg)
Append message to queue.
void remove(const Message *msg)
Remove message from queue.
void unlock()
Unlock message queue.
SetTestStringMessage Fawkes BlackBoard Interface Message.
void lock()
Lock message queue.