Fawkes API  Fawkes Development Version
qa_bb_objpos.cpp
1 
2 /***************************************************************************
3  * qa_bb_objpos.h - BlackBoard QA: open a few ObjectPositionInterfaces
4  *
5  * Created: Mon Jan 12 13:46:16 2009
6  * Copyright 2006-2009 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/remote.h>
28 #include <blackboard/local.h>
29 #include <blackboard/exceptions.h>
30 #include <blackboard/bbconfig.h>
31 #include <netcomm/fawkes/server_thread.h>
32 
33 #include <interfaces/ObjectPositionInterface.h>
34 
35 #include <core/exceptions/system.h>
36 #include <logging/liblogger.h>
37 #include <utils/time/tracker.h>
38 
39 #include <signal.h>
40 #include <cstdlib>
41 
42 #include <iostream>
43 #include <vector>
44 
45 using namespace std;
46 using namespace fawkes;
47 
48 bool quit = false;
49 
50 void handle_signal(int signum)
51 {
52  quit = true;
53 }
54 
55 int
56 main(int argc, char **argv)
57 {
58  signal(SIGINT, handle_signal);
59 
60  LibLogger::init();
61  //BlackBoard *bb = new RemoteBlackBoard("localhost", 1910);
62  LocalBlackBoard *lbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
63  BlackBoard *bb = lbb;
65  netthread->start();
66  lbb->start_nethandler(netthread);
67 
68  std::list<ObjectPositionInterface *> interfaces;
69 
70  cout << "Opening interfaces" << endl;
71  for (int i = 1; i <= 15; ++i) {
72  char tmp[100];
73  sprintf(tmp, "legtracker Leg %i", i);
74  printf(" %s\n", tmp);
76  interfaces.push_back(iface);
77  }
78 
79  srand(time(NULL));
80 
81  TimeTracker tt;
82  unsigned int ttc_write = tt.add_class("Write");
83 
84  int u = 0;
85  while ( ! quit) {
86  for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
87  int r = rand() % 1000000;
88  (*i)->set_world_x((float)r);
89  (*i)->set_world_y((float)r+1);
90  (*i)->set_world_z((float)r+2);
91  tt.ping_start(ttc_write);
92  (*i)->write();
93  tt.ping_end(ttc_write);
94  }
95  if ( ++u > 20000 ) {
96  tt.print_to_stdout();
97  tt.reset();
98  u = 0;
99  }
100  //sleep(1);
101  }
102 
103  for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
104  bb->close(*i);
105  }
106 
107  delete bb;
108  LibLogger::finalize();
109 }
110 
111 
112 /// @endcond
void ping_start(unsigned int cls)
Start of given class task.
Definition: tracker.cpp:228
ObjectPositionInterface Fawkes BlackBoard Interface.
Fawkes library namespace.
STL namespace.
Local BlackBoard.
Definition: local.h:44
virtual void start_nethandler(FawkesNetworkHub *hub)
Start network handler.
Definition: local.cpp:209
unsigned int add_class(std::string name)
Add a new class.
Definition: tracker.cpp:156
Time tracking utility.
Definition: tracker.h:38
void ping_end(unsigned int cls)
End of given class task.
Definition: tracker.cpp:254
void reset(std::string comment="")
Reset times.
Definition: tracker.cpp:116
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:317
The BlackBoard abstract class.
Definition: blackboard.h:48
Fawkes Network Thread.
Definition: server_thread.h:46
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
void start(bool wait=true)
Call this method to start the thread.
Definition: thread.cpp:511
virtual void close(Interface *interface)=0
Close interface.