27 #include <blackboard/local.h>
28 #include <blackboard/remote.h>
29 #include <blackboard/exceptions.h>
30 #include <blackboard/bbconfig.h>
32 #include <interfaces/TestInterface.h>
34 #include <core/threading/thread.h>
35 #include <core/exceptions/system.h>
36 #include <utils/time/time.h>
46 using namespace fawkes;
52 signal_handler(
int signum)
59 #define BLACKBOARD_MEMSIZE 2 * 1024 * 1024
60 #define BLACKBOARD_MAGIC_TOKEN "FawkesBlackBoard"
63 main(
int argc,
char **argv)
68 signal(SIGINT, signal_handler);
77 cout <<
"Opening interfaces.. " << flush;
80 cout <<
"success" << endl;
82 cout <<
"failed! Aborting" << endl;
87 cout <<
"Writing initial value ("
88 << TestInterface::TEST_CONSTANT <<
") into interface as TestInt" << endl;
93 cout <<
"BUG: caught write denied exception" << endl;
97 cout <<
"Reading value from reader interface.. " << flush;
100 if ( val == TestInterface::TEST_CONSTANT ) {
101 cout <<
" success, value is " << ti_reader->
test_int() <<
" as expected" << endl;
103 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected "
104 << TestInterface::TEST_CONSTANT << endl;
107 printf(
"Reader instance serial: %u\n", ti_reader->
serial());
109 cout <<
"Harnessing message queues by excessively sending messages" << endl
110 <<
"Press Ctrl-C to stop testing. No output means everything is fine" << endl;
112 int expval = ti_reader->
test_int() + 1;
115 printf(
"Sent with message ID %u\n", msgid);
118 cout <<
"Error, more than one message! flushing." << endl;
127 printf(
"Received message of ID %u, Message improperly detected to be a SetTestStringMessage\n", msg->
id());
131 printf(
"Received message with ID %u (enqueue time: %s)\n", m2->
id(),
137 cout <<
"BUG: caught write denied exception" << endl;
142 cout <<
"Illegal message '" << ti_writer->
msgq_first()->
type() <<
"' type received" << endl;
150 if ( val == expval ) {
153 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected "
157 printf(
"No message in queue, if network test this means the message was dropped\n");
163 bb->
close(ti_reader);
164 bb->
close(ti_writer);
168 cout <<
"Tests done" << endl;
170 Thread::destroy_main();
unsigned short serial() const
Get instance serial of interface.
const char * type() const
Get message type.
void write()
Write from local copy into BlackBoard memory.
unsigned int id() const
Get message ID.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier)=0
Open interface for writing.
unsigned int msgq_size()
Get size of message queue.
int32_t test_int() const
Get test_int value.
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.
void read()
Read from BlackBoard into local copy.
int32_t test_int() const
Get test_int value.
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.
const Time * time_enqueued() const
Get time when message was enqueued.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier)=0
Open interface for reading.
void msgq_flush()
Flush all messages.
const char * str(bool utc=false) const
Output function.
Message * msgq_first()
Get the first message from the message queue.
The BlackBoard abstract class.
SetTestStringMessage Fawkes BlackBoard Interface Message.
This exception is thrown if a write has been attempted on a read-only interface.
TestInterface Fawkes BlackBoard Interface.
virtual void close(Interface *interface)=0
Close interface.