26 #include <blackboard/bbconfig.h>
27 #include <blackboard/exceptions.h>
28 #include <blackboard/interface_listener.h>
29 #include <blackboard/interface_observer.h>
30 #include <blackboard/local.h>
31 #include <blackboard/remote.h>
32 #include <core/exceptions/system.h>
33 #include <core/threading/thread.h>
34 #include <interfaces/TestInterface.h>
35 #include <logging/liblogger.h>
52 bbio_add_observed_create(
"TestInterface",
"AnotherID *");
53 bbio_add_observed_destroy(
"TestInterface");
57 bb_interface_created(
const char *type,
const char *
id)
throw()
59 printf(
"BBIO: Interface %s of type %s has been created\n",
id, type);
63 bb_interface_destroyed(
const char *type,
const char *
id)
throw()
65 printf(
"BBIO: Interface %s of type %s has been destroyed\n",
id, type);
69 bb_interface_data_changed(
Interface *interface)
throw()
71 printf(
"BBIL: Data in interface %s has been modified\n", interface->uid());
75 bb_interface_message_received(
Interface *interface,
Message *message)
throw()
77 printf(
"BBIL: Message of type %s for interface %s has been received\n",
81 if (strcmp(message->type(),
"SetTestStringMessage") == 0) {
82 printf(
"BBIL: Received message of type %s, unregistering from inside "
85 bbil_remove_message_interface(interface);
86 bb_->update_listener(
this);
92 bb_interface_writer_added(
Interface *interface,
unsigned int instance_serial)
throw()
94 printf(
"BBIL: Writer has been added to interface %s/%u (event serial %u)\n",
101 bb_interface_writer_removed(
Interface *interface,
unsigned int instance_serial)
throw()
103 printf(
"BBIL: Writer has been removed from interface %s/%u (event serial %u)\n",
110 bb_interface_reader_added(
Interface *interface,
unsigned int instance_serial)
throw()
112 printf(
"BBIL: Reader has been added to interface %s/%u (event serial %u)\n",
119 bb_interface_reader_removed(
Interface *interface,
unsigned int instance_serial)
throw()
121 printf(
"BBIL: Reader has been removed from interface %s/%u (event serial %u)\n",
128 add_interface(
Interface *interface)
throw()
130 printf(
"Listener: Adding interface %s (this: %p)\n", interface->uid(),
this);
131 bbil_add_data_interface(interface);
133 if (!interface->is_writer()) {
134 printf(
"Trying to add non-writing instance as message listener, this will fail\n");
136 bbil_add_message_interface(interface);
137 if (!interface->is_writer()) {
138 printf(
"Did not fail!? BUG!\n");
141 if (!interface->is_writer()) {
142 printf(
"Failed as expected (%s). Good.\n", e.
what());
145 bbil_add_reader_interface(interface);
146 bbil_add_writer_interface(interface);
154 main(
int argc,
char **argv)
162 QaBBEventListener qabbel(bb);
175 cout <<
"Opening interfaces.. (SomeID *)" << endl;
181 qabbel.add_interface(ti_writer_1);
182 qabbel.add_interface(ti_writer_2);
183 qabbel.add_interface(ti_reader_2);
187 cout <<
"Opening interfaces.. (SomeID 3, should NOT trigger BBIO)" << endl;
189 cout <<
"Opening interfaces.. (AnotherID *, SHOULD trigger BBIO)" << endl;
193 cout <<
"success" << endl;
195 cout <<
"failed! Aborting" << endl;
204 for (std::list<TestInterface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
205 printf(
"Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
211 const char *pattern =
"AnotherID *";
213 printf(
"Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern);
214 for (std::list<TestInterface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
215 printf(
"Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
221 printf(
"Sending a message to test message received event\n");
224 printf(
"Message ID = %u, enqueued messages: %u\n", msg_id, ti_writer_1->
msgq_size());
226 printf(
"Sending message triggering update in event handler\n");
230 printf(
"Sending another message, should NOT trigger BBIL!\n");
233 printf(
"Another message sent!\n");
235 printf(
"Removing writer 1. BBIL output should appear\n");
236 bb->
close(ti_writer_1);
237 printf(
"Removing writer 1 DONE\n");
242 printf(
"Removing other writers. No warning should appear.\n");
243 bb->
close(ti_writer_2);
244 bb->
close(ti_writer_3);
245 bb->
close(ti_writer_4);
246 bb->
close(ti_writer_5);
247 bb->
close(ti_writer_6);
249 bb->
close(ti_reader_1);
250 bb->
close(ti_reader_2);
255 Thread::destroy_main();
256 LibLogger::finalize();
BlackBoard interface listener.
BlackBoard interface observer.
The BlackBoard abstract class.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
void print_trace()
Prints trace to stderr.
virtual const char * what() const
Get primary string.
Base class for all Fawkes BlackBoard interfaces.
unsigned int msgq_size()
Get size of message queue.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
SetTestIntMessage Fawkes BlackBoard Interface Message.
SetTestStringMessage Fawkes BlackBoard Interface Message.
TestInterface Fawkes BlackBoard Interface.
Fawkes library namespace.