26 #include <blackboard/bbconfig.h>
27 #include <blackboard/exceptions.h>
28 #include <blackboard/interface_listener.h>
29 #include <blackboard/local.h>
30 #include <blackboard/remote.h>
31 #include <core/exceptions/system.h>
32 #include <interface/interface_info.h>
33 #include <interfaces/TestInterface.h>
34 #include <netcomm/fawkes/client.h>
35 #include <netcomm/fawkes/server_thread.h>
36 #include <utils/time/time.h>
51 signal_handler(
int signum)
62 int expval = ti_reader->
test_int() + 1;
65 printf(
"Sent with message ID %u\n", msgid);
68 cout <<
"Error, more than one message! flushing." << endl;
78 "Received message of ID %u, Message improperly detected to be a SetTestStringMessage\n",
84 printf(
"Received message with ID %u (enqueue time: %s)\n",
91 cout <<
"BUG: caught write denied exception" << endl;
96 cout <<
"Illegal message '" << ti_writer->
msgq_first()->
type() <<
"' type received" << endl;
107 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected " << expval << endl;
110 printf(
"No message in queue, if network test this means the message was dropped\n");
128 reader_bb_ = reader_bb;
129 writer_bb_ = writer_bb;
131 bbil_add_data_interface(reader_);
132 bbil_add_message_interface(writer_);
134 reader_bb_->register_listener(
this);
135 writer_bb_->register_listener(
this);
141 reader_bb_->unregister_listener(
this);
142 writer_bb_->unregister_listener(
this);
146 bb_interface_message_received(
Interface *interface,
Message *message) noexcept
149 if (interface == writer_) {
150 printf(
"%s: Forwarding message\n", bbil_name());
154 reader_->msgq_enqueue(m);
155 message->set_id(m->
id());
160 printf(
"%s: Message received for unknown interface\n", bbil_name());
164 printf(
"%s: Exception when message received\n", bbil_name());
171 bb_interface_data_refreshed(
Interface *interface) noexcept
174 if (interface == reader_) {
177 writer_->copy_values(reader_);
181 printf(
"%s: Data changed for unknown interface", bbil_name());
184 printf(
"%s: Exception when data changed\n", bbil_name());
198 main(
int argc,
char **argv)
200 signal(SIGINT, signal_handler);
213 for (InterfaceInfoList::iterator i = infl->begin(); i != infl->end(); ++i) {
214 const unsigned char *hash = (*i).hash();
215 char phash[INTERFACE_HASH_SIZE_ * 2 + 1];
216 memset(phash, 0,
sizeof(phash));
217 for (
unsigned int j = 0; j < INTERFACE_HASH_SIZE_; ++j) {
218 sprintf(&phash[j * 2],
"%02x", hash[j]);
220 printf(
"%s::%s (%s), w:%i r:%u s:%u\n",
234 cout <<
"Opening interfaces.. " << flush;
241 cout <<
"failed! Aborting" << endl;
247 cout <<
"Trying to open second writer.. " << flush;
250 rbb->
close(ti_writer_two);
251 cout <<
"BUG: Detection of second writer did NOT work!" << endl;
254 cout <<
"exception caught as expected, detected and prevented second writer!" << endl;
258 cout <<
"Trying to open third writer.. " << flush;
261 cout <<
"No exception as expected, different ID ok!" << endl;
262 rbb->
close(ti_writer_three);
264 cout <<
"BUG: Third writer with different ID detected as another writer!" << endl;
270 <<
"Running data tests ==================================================" << endl;
272 cout <<
"Writing initial value (" << TestInterface::TEST_CONSTANT <<
") into interface as TestInt"
278 cout <<
"BUG: caught write denied exception" << endl;
282 cout <<
"Giving some time to have value processed" << endl;
285 cout <<
"Reading value from reader interface.. " << flush;
288 if (val == TestInterface::TEST_CONSTANT) {
289 cout <<
" success, value is " << ti_reader->
test_int() <<
" as expected" << endl;
291 cout <<
" failure, value is " << ti_reader->
test_int() <<
", expected "
292 << TestInterface::TEST_CONSTANT << endl;
295 cout <<
"Closing interfaces.. " << flush;
297 rbb->
close(ti_reader);
298 rbb->
close(ti_writer);
299 cout <<
"done" << endl;
301 cout <<
"failed" << endl;
307 <<
"Starting MESSAGING tests" << endl
308 <<
"Press Ctrl-C to continue with next test" << endl
314 printf(
"Writer serial: %u shifted: %u\n", ti_writer->
serial(), ti_writer->
serial() << 16);
315 printf(
"Reader serial: %u shifted: %u\n", ti_reader->
serial(), ti_reader->
serial() << 16);
317 test_messaging(ti_reader, ti_writer);
319 rbb->
close(ti_reader);
320 lbb->
close(ti_writer);
324 <<
"Starting MESSAGING tests, doing repeater scenario" << endl
325 <<
"Press Ctrl-C to continue with next test" << endl
350 printf(
"Writer serial: %u shifted: %u\n", ti_writer->
serial(), ti_writer->
serial() << 16);
351 printf(
"Reader serial: %u shifted: %u\n", ti_reader->
serial(), ti_reader->
serial() << 16);
355 test_messaging(ti_reader, ti_writer);
358 lbb->
close(ti_reader);
359 rbb->
close(ti_writer);
360 rep_rbb->
close(rep_reader);
361 lbb->
close(rep_writer);
365 cout <<
"Tests done" << endl;
Synchronize two interfaces.
BlackBoard interface listener.
Thrown if a writer is already active on an interface that writing has been requested for.
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 InterfaceInfoList * list_all()=0
Get list of all currently existing interfaces.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void close(Interface *interface)=0
Close interface.
Base class for exceptions in Fawkes.
void print_trace() noexcept
Prints trace to stderr.
Interface information list.
This exception is thrown if a write has been attempted on a read-only interface.
Base class for all Fawkes BlackBoard interfaces.
bool msgq_first_is()
Check if first message has desired type.
const char * hash_printable() const
Get printable interface hash.
void msgq_pop()
Erase first message from queue.
Message * msgq_first()
Get the first message from the message queue.
unsigned int msgq_enqueue(Message *message, bool proxy=false)
Enqueue message at end of queue.
unsigned int msgq_size()
Get size of message queue.
void write()
Write from local copy into BlackBoard memory.
Uuid serial() const
Get instance serial of interface.
void msgq_flush()
Flush all messages.
void read()
Read from BlackBoard into local copy.
virtual void start_nethandler(FawkesNetworkHub *hub)
Start network handler.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
const char * type() const
Get message type.
const Time * time_enqueued() const
Get time when message was enqueued.
void set_hops(unsigned int hops)
Set number of hops.
unsigned int id() const
Get message ID.
void unref()
Decrement reference count and conditionally delete this instance.
void ref()
Increment reference count.
SetTestIntMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
int32_t test_int() const
Get test_int value.
SetTestStringMessage Fawkes BlackBoard Interface Message.
TestInterface Fawkes BlackBoard Interface.
void set_test_int(const int32_t new_test_int)
Set test_int value.
int32_t test_int() const
Get test_int value.
void start(bool wait=true)
Call this method to start the thread.
const char * str(bool utc=false) const
Output function.
Fawkes library namespace.