Fawkes API  Fawkes Development Version
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 #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 /// @endcond