Fawkes API  Fawkes Development Version
qa_bb_objpos.cpp
00001 
00002 /***************************************************************************
00003  *  qa_bb_objpos.h - BlackBoard QA: open a few ObjectPositionInterfaces
00004  *
00005  *  Created: Mon Jan 12 13:46:16 2009
00006  *  Copyright  2006-2009  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/remote.h>
00028 #include <blackboard/local.h>
00029 #include <blackboard/exceptions.h>
00030 #include <blackboard/bbconfig.h>
00031 #include <netcomm/fawkes/server_thread.h>
00032 
00033 #include <interfaces/ObjectPositionInterface.h>
00034 
00035 #include <core/exceptions/system.h>
00036 #include <utils/logging/liblogger.h>
00037 #include <utils/time/tracker.h>
00038 
00039 #include <signal.h>
00040 #include <cstdlib>
00041 
00042 #include <iostream>
00043 #include <vector>
00044 
00045 using namespace std;
00046 using namespace fawkes;
00047 
00048 bool quit = false;
00049 
00050 void handle_signal(int signum)
00051 {
00052   quit = true;
00053 }
00054 
00055 int
00056 main(int argc, char **argv)
00057 {
00058   signal(SIGINT, handle_signal);
00059 
00060   LibLogger::init();
00061   //BlackBoard *bb = new RemoteBlackBoard("localhost", 1910);
00062   LocalBlackBoard *lbb = new LocalBlackBoard(BLACKBOARD_MEMSIZE);
00063   BlackBoard *bb = lbb;
00064   FawkesNetworkServerThread *netthread = new FawkesNetworkServerThread(1910);
00065   netthread->start();
00066   lbb->start_nethandler(netthread);
00067 
00068   std::list<ObjectPositionInterface *> interfaces;
00069 
00070   cout << "Opening interfaces" << endl;
00071   for (int i = 1; i <= 15; ++i) {
00072     char tmp[100];
00073     sprintf(tmp, "legtracker Leg %i", i);
00074     printf("   %s\n", tmp);
00075     ObjectPositionInterface *iface = bb->open_for_writing<ObjectPositionInterface>(tmp);
00076     interfaces.push_back(iface);
00077   }
00078 
00079   srand(time(NULL));
00080 
00081   TimeTracker tt;
00082   unsigned int ttc_write = tt.add_class("Write");
00083 
00084   int u = 0;
00085   while ( ! quit) {
00086     for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
00087       int r = rand() % 1000000;
00088       (*i)->set_world_x((float)r);
00089       (*i)->set_world_y((float)r+1);
00090       (*i)->set_world_z((float)r+2);
00091       tt.ping_start(ttc_write);
00092       (*i)->write();
00093       tt.ping_end(ttc_write);
00094     }
00095     if ( ++u > 20000 ) {
00096       tt.print_to_stdout();
00097       tt.reset();
00098       u = 0;
00099     }
00100     //sleep(1);
00101   }
00102 
00103   for (std::list<ObjectPositionInterface *>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
00104     bb->close(*i);
00105   }
00106 
00107   delete bb;
00108   LibLogger::finalize();
00109 }
00110 
00111 
00112 /// @endcond