qa_bb_openall.cpp
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
00039 #include <iostream>
00040 #include <vector>
00041
00042 using namespace std;
00043 using namespace fawkes;
00044
00045
00046 int
00047 main(int argc, char **argv)
00048 {
00049 LibLogger::init();
00050 BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE,
00051 BLACKBOARD_MAGIC_TOKEN,
00052 true);
00053
00054 TestInterface *ti_writer_1;
00055 TestInterface *ti_writer_2;
00056 TestInterface *ti_writer_3;
00057 TestInterface *ti_writer_4;
00058 TestInterface *ti_writer_5;
00059 TestInterface *ti_writer_6;
00060
00061 try {
00062 cout << "Opening interfaces.. " << flush;
00063 ti_writer_1 = bb->open_for_writing<TestInterface>("SomeID 1");
00064 ti_writer_2 = bb->open_for_writing<TestInterface>("SomeID 2");
00065 ti_writer_3 = bb->open_for_writing<TestInterface>("SomeID 3");
00066 ti_writer_4 = bb->open_for_writing<TestInterface>("AnotherID 1");
00067 ti_writer_5 = bb->open_for_writing<TestInterface>("AnotherID 2");
00068 ti_writer_6 = bb->open_for_writing<TestInterface>("AnotherID 3");
00069 cout << "success" << endl;
00070 } catch (Exception &e) {
00071 cout << "failed! Aborting" << endl;
00072 e.print_trace();
00073 exit(1);
00074 }
00075
00076 std::list<Interface *> readers = bb->open_multiple_for_reading("TestInterface");
00077 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
00078 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
00079 bb->close(*i);
00080 }
00081
00082 const char* pattern = "AnotherID *";
00083 readers = bb->open_multiple_for_reading("TestInterface", pattern);
00084 printf("Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern);
00085 for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
00086 printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
00087 bb->close(*i);
00088 }
00089
00090 bb->close(ti_writer_1);
00091 bb->close(ti_writer_2);
00092 bb->close(ti_writer_3);
00093 bb->close(ti_writer_4);
00094 bb->close(ti_writer_5);
00095 bb->close(ti_writer_6);
00096
00097 delete bb;
00098 LibLogger::finalize();
00099 }
00100
00101
00102