26 #include <blackboard/bbconfig.h> 27 #include <blackboard/exceptions.h> 28 #include <blackboard/local.h> 29 #include <blackboard/remote.h> 30 #include <core/exceptions/system.h> 31 #include <core/threading/thread.h> 32 #include <interfaces/TestInterface.h> 33 #include <utils/time/time.h> 47 signal_handler(
int signum)
53 #define BLACKBOARD_MEMSIZE 2 * 1024 * 1024 54 #define BLACKBOARD_MAGIC_TOKEN "FawkesBlackBoard" 57 main(
int argc,
char **argv)
61 signal(SIGINT, signal_handler);
70 cout <<
"Opening interfaces.. " << flush;
73 cout <<
"success" << endl;
75 cout <<
"failed! Aborting" << endl;
80 cout <<
"Writing initial value (" << TestInterface::TEST_CONSTANT <<
") into interface as TestInt" 86 cout <<
"BUG: caught write denied exception" << endl;
90 cout <<
"Reading value from reader interface.. " << flush;
93 if (val == TestInterface::TEST_CONSTANT) {
94 cout <<
" success, value is " << ti_reader->
test_int() <<
" as expected" << endl;
96 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected " 97 << TestInterface::TEST_CONSTANT << endl;
100 printf(
"Reader instance serial: %u\n", ti_reader->
serial());
102 cout <<
"Harnessing message queues by excessively sending messages" << endl
103 <<
"Press Ctrl-C to stop testing. No output means everything is fine" << endl;
105 int expval = ti_reader->
test_int() + 1;
108 printf(
"Sent with message ID %u\n", msgid);
111 cout <<
"Error, more than one message! flushing." << endl;
121 "Received message of ID %u, Message improperly detected to be a SetTestStringMessage\n",
127 printf(
"Received message with ID %u (enqueue time: %s)\n",
134 cout <<
"BUG: caught write denied exception" << endl;
139 cout <<
"Illegal message '" << ti_writer->
msgq_first()->
type() <<
"' type received" << endl;
150 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected " << expval << endl;
153 printf(
"No message in queue, if network test this means the message was dropped\n");
159 bb->
close(ti_reader);
160 bb->
close(ti_writer);
164 cout <<
"Tests done" << endl;
166 Thread::destroy_main();
const Time * time_enqueued() const
Get time when message was enqueued.
unsigned int id() const
Get message ID.
const char * str(bool utc=false) const
Output function.
Fawkes library namespace.
int32_t test_int() const
Get test_int value.
void write()
Write from local copy into BlackBoard memory.
unsigned int msgq_size()
Get size of message queue.
void set_test_int(const int32_t new_test_int)
Set test_int value.
void msgq_pop()
Erase first message from queue.
Base class for exceptions in Fawkes.
Message * msgq_first()
Get the first message from the message queue.
unsigned short serial() const
Get instance serial of interface.
void read()
Read from BlackBoard into local copy.
SetTestIntMessage Fawkes BlackBoard Interface Message.
bool msgq_first_is()
Check if first message has desired type.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
void print_trace()
Prints trace to stderr.
int32_t test_int() const
Get test_int value.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
void msgq_flush()
Flush all messages.
The BlackBoard abstract class.
SetTestStringMessage Fawkes BlackBoard Interface Message.
This exception is thrown if a write has been attempted on a read-only interface.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
const char * type() const
Get message type.
TestInterface Fawkes BlackBoard Interface.
virtual void close(Interface *interface)=0
Close interface.