00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <blackboard/local.h>
00028 #include <blackboard/exceptions.h>
00029 #include <blackboard/bbconfig.h>
00030
00031 #include <interfaces/TestInterface.h>
00032
00033 #include <core/exceptions/system.h>
00034 #include <utils/logging/liblogger.h>
00035
00036 #include <signal.h>
00037 #include <cstdlib>
00038 #include <cstdio>
00039
00040 #include <iostream>
00041 #include <vector>
00042
00043 using namespace std;
00044 using namespace fawkes;
00045
00046
00047 int
00048 main(int argc, char **argv)
00049 {
00050 LibLogger::init();
00051 BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
00052
00053 TestInterface *ti_writer_1;
00054 TestInterface *ti_writer_2;
00055 TestInterface *ti_writer_3;
00056 TestInterface *ti_writer_4;
00057 TestInterface *ti_writer_5;
00058 TestInterface *ti_writer_6;
00059
00060 try {
00061 cout << "Opening interfaces.. " << flush;
00062 ti_writer_1 = bb->open_for_writing<TestInterface>("SomeID 1");
00063 ti_writer_2 = bb->open_for_writing<TestInterface>("SomeID 2");
00064 ti_writer_3 = bb->open_for_writing<TestInterface>("SomeID 3");
00065 ti_writer_4 = bb->open_for_writing<TestInterface>("AnotherID 1");
00066 ti_writer_5 = bb->open_for_writing<TestInterface>("AnotherID 2");
00067 ti_writer_6 = bb->open_for_writing<TestInterface>("AnotherID 3");
00068 cout << "success" << endl;
00069 } catch (Exception &e) {
00070 cout << "failed! Aborting" << endl;
00071 e.print_trace();
00072 exit(1);
00073 }
00074
00075 std::list<Interface *> readers = bb->open_multiple_for_reading("TestInterface");
00076 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
00077 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
00078 bb->close(*i);
00079 }
00080
00081 const char* pattern = "AnotherID *";
00082 readers = bb->open_multiple_for_reading("TestInterface", pattern);
00083 printf("Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern);
00084 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
00085 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
00086 bb->close(*i);
00087 }
00088
00089 bb->close(ti_writer_1);
00090 bb->close(ti_writer_2);
00091 bb->close(ti_writer_3);
00092 bb->close(ti_writer_4);
00093 bb->close(ti_writer_5);
00094 bb->close(ti_writer_6);
00095
00096 delete bb;
00097 LibLogger::finalize();
00098 }
00099
00100
00101