bbsync_plugin.cpp

00001 
00002 /***************************************************************************
00003  *  bbsync_plugin.cpp - Fawkes BlackBoardSynchronization Plugin
00004  *
00005  *  Created: Fri Jun 29 11:47:53 2007 (on flight to RoboCup 2007, Atlanta)
00006  *  Copyright  2006  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.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include "bbsync_plugin.h"
00024 #include "sync_thread.h"
00025 
00026 #include <set>
00027 
00028 using namespace fawkes;
00029 
00030 /** @class BlackBoardSynchronizationPlugin "bbsync_plugin.h"
00031  * BlackBoard synchronization plugin.
00032  * This plugin synchronizes one or more (or even all) interfaces of two or
00033  * more Fawkes instances over the network.
00034  *
00035  * @author Tim Niemueller
00036  */
00037 
00038 /** Constructor.
00039  * @param config Fawkes configuration
00040  */
00041 BlackBoardSynchronizationPlugin::BlackBoardSynchronizationPlugin(Configuration *config)
00042   : Plugin(config)
00043 {
00044   std::set<std::string> peers;
00045   std::set<std::string> ignored_peers;
00046 
00047   std::string prefix = "/fawkes/bbsync/";
00048   std::string peers_prefix = prefix + "peers/";
00049 
00050   Configuration::ValueIterator *i = config->search(peers_prefix.c_str());
00051   while (i->next()) {
00052     std::string peer = std::string(i->path()).substr(peers_prefix.length());
00053     peer = peer.substr(0, peer.find("/"));
00054 
00055     if ( (peers.find(peer) == peers.end()) &&
00056          (ignored_peers.find(peer) == ignored_peers.end()) ) {
00057 
00058       std::string peer_prefix = peers_prefix + peer + "/";
00059 
00060       bool active = true;
00061       try {
00062         active = config->get_bool((peer_prefix + "active").c_str());
00063       } catch (Exception &e) {} // ignored, assume enabled
00064 
00065       if (active) {
00066         //printf("Adding sync thread for peer %s\n", peer.c_str());
00067         BlackBoardSynchronizationThread *sync_thread;
00068         sync_thread = new BlackBoardSynchronizationThread(prefix, peer_prefix, peer);
00069         peers.insert(peer);
00070         thread_list.push_back(sync_thread);
00071       } else {
00072         //printf("Ignoring sync peer %s\n", peer.c_str());
00073         ignored_peers.insert(peer);
00074       }
00075     }
00076   }
00077   delete i;
00078 
00079   if ( thread_list.empty() ) {
00080     throw Exception("No synchronization peers configured, aborting");
00081   } else {
00082   }
00083 }
00084 
00085 PLUGIN_DESCRIPTION("Synchronize with remote Fawkes BlackBoards")
00086 EXPORT_PLUGIN(BlackBoardSynchronizationPlugin)

Generated on Tue Feb 22 13:31:28 2011 for Fawkes API by  doxygen 1.4.7