Fawkes API  Fawkes Development Version
qa_bb_openall.cpp
1 
2 /***************************************************************************
3  * qa_bb_openall.h - BlackBoard interface QA
4  *
5  * Created: Fri Jun 29 13:44:04 2007 (on flight to RoboCup 2007, Atlanta)
6  * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 
25 /// @cond QA
26 
27 #include <blackboard/local.h>
28 #include <blackboard/exceptions.h>
29 #include <blackboard/bbconfig.h>
30 
31 #include <interfaces/TestInterface.h>
32 
33 #include <core/exceptions/system.h>
34 #include <logging/liblogger.h>
35 
36 #include <signal.h>
37 #include <cstdlib>
38 #include <cstdio>
39 
40 #include <iostream>
41 #include <vector>
42 
43 using namespace std;
44 using namespace fawkes;
45 
46 
47 int
48 main(int argc, char **argv)
49 {
50  LibLogger::init();
51  BlackBoard *bb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
52 
53  TestInterface *ti_writer_1;
54  TestInterface *ti_writer_2;
55  TestInterface *ti_writer_3;
56  TestInterface *ti_writer_4;
57  TestInterface *ti_writer_5;
58  TestInterface *ti_writer_6;
59 
60  try {
61  cout << "Opening interfaces.. " << flush;
62  ti_writer_1 = bb->open_for_writing<TestInterface>("SomeID 1");
63  ti_writer_2 = bb->open_for_writing<TestInterface>("SomeID 2");
64  ti_writer_3 = bb->open_for_writing<TestInterface>("SomeID 3");
65  ti_writer_4 = bb->open_for_writing<TestInterface>("AnotherID 1");
66  ti_writer_5 = bb->open_for_writing<TestInterface>("AnotherID 2");
67  ti_writer_6 = bb->open_for_writing<TestInterface>("AnotherID 3");
68  cout << "success" << endl;
69  } catch (Exception &e) {
70  cout << "failed! Aborting" << endl;
71  e.print_trace();
72  exit(1);
73  }
74 
75  std::list<Interface *> readers = bb->open_multiple_for_reading("TestInterface");
76  for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
77  printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
78  bb->close(*i);
79  }
80 
81  const char* pattern = "AnotherID *";
82  readers = bb->open_multiple_for_reading("TestInterface", pattern);
83  printf("Found %zu interfaces with pattern \"%s\"\n", readers.size(), pattern);
84  for (std::list<Interface *>::iterator i = readers.begin(); i != readers.end(); ++i) {
85  printf("Opened reader for interface %s of type %s\n", (*i)->id(), (*i)->type());
86  bb->close(*i);
87  }
88 
89  bb->close(ti_writer_1);
90  bb->close(ti_writer_2);
91  bb->close(ti_writer_3);
92  bb->close(ti_writer_4);
93  bb->close(ti_writer_5);
94  bb->close(ti_writer_6);
95 
96  delete bb;
97  LibLogger::finalize();
98 }
99 
100 
101 /// @endcond
Fawkes library namespace.
STL namespace.
Local BlackBoard.
Definition: local.h:44
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
The BlackBoard abstract class.
Definition: blackboard.h:48
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
TestInterface Fawkes BlackBoard Interface.
Definition: TestInterface.h:33
virtual void close(Interface *interface)=0
Close interface.