qa_bb_openall.cpp

00001
00002 /***************************************************************************
00003  *  qa_bb_openall.h - BlackBoard interface QA
00004  *
00005  *  Created: Fri Jun 29 13:44:04 2007 (on flight to RoboCup 2007, Atlanta)
00006  *  Copyright  2006-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 
00025 /// @cond QA
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                                        /* master */  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 /// @endcond