remote.h

00001 
00002 /***************************************************************************
00003  *  remote.h - Remote BlackBoard using the Fawkes network protocol
00004  *
00005  *  Created: Mon Mar 03 10:52:28 2008
00006  *  Copyright  2006-2008  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 #ifndef __BLACKBOARD_REMOTE_H_
00025 #define __BLACKBOARD_REMOTE_H_
00026 
00027 #include <blackboard/blackboard.h>
00028 #include <netcomm/fawkes/client_handler.h>
00029 #include <core/utils/lock_map.h>
00030 #include <core/exceptions/software.h>
00031 
00032 #include <list>
00033 
00034 namespace fawkes {
00035 
00036 class FawkesNetworkClient;
00037 class FawkesNetworkMessage;
00038 class Mutex;
00039 class WaitCondition;
00040 class Interface;
00041 class InterfaceInfoList;
00042 
00043 class BlackBoardInstanceFactory;
00044 class BlackBoardNotifier;
00045 class BlackBoardInterfaceProxy;
00046 class BlackBoardInterfaceListener;
00047 class BlackBoardInterfaceObserver;
00048 
00049 class RemoteBlackBoard
00050 : public BlackBoard,
00051   public FawkesNetworkClientHandler
00052 {
00053  public:
00054   RemoteBlackBoard(FawkesNetworkClient *client);
00055   RemoteBlackBoard(const char *hostname, unsigned short int port);
00056   virtual ~RemoteBlackBoard();
00057 
00058   virtual Interface *  open_for_reading(const char *interface_type, const char *identifier);
00059   virtual Interface *  open_for_writing(const char *interface_type, const char *identifier);
00060   virtual void         close(Interface *interface);
00061 
00062   virtual InterfaceInfoList *  list_all();
00063   virtual bool                 is_alive() const throw();
00064   virtual bool                 try_aliveness_restore() throw();
00065 
00066   std::list<Interface *>  open_multiple_for_reading(const char *interface_type,
00067                                                     const char *id_pattern = "*");
00068 
00069   void register_listener(BlackBoardInterfaceListener *listener, unsigned int flags);
00070   void unregister_listener(BlackBoardInterfaceListener *listener);
00071 
00072   void register_observer(BlackBoardInterfaceObserver *observer, unsigned int flags);
00073   void unregister_observer(BlackBoardInterfaceObserver *observer);
00074 
00075 
00076   /* for FawkesNetworkClientHandler */
00077   virtual void          deregistered(unsigned int id) throw();
00078   virtual void          inbound_received(FawkesNetworkMessage *msg,
00079                                          unsigned int id) throw();
00080   virtual void          connection_died(unsigned int id) throw();
00081   virtual void          connection_established(unsigned int id) throw();
00082 
00083 
00084   /* extensions for RemoteBlackBoard */
00085 
00086  private: /* methods */
00087   void        open_interface(const char *type, const char *identifier,
00088                              bool writer, Interface *iface);
00089   Interface * open_interface(const char *type, const char *identifier, bool writer);
00090   void        reopen_interfaces();
00091 
00092 
00093  private: /* members */
00094   Mutex *__mutex;
00095   FawkesNetworkClient  *__fnc;
00096   bool                  __fnc_owner;
00097   FawkesNetworkMessage *__m;
00098   BlackBoardNotifier   *__notifier;
00099   BlackBoardInstanceFactory *__instance_factory;
00100   LockMap<unsigned int, BlackBoardInterfaceProxy *> __proxies;
00101   LockMap<unsigned int, BlackBoardInterfaceProxy *>::iterator __pit;
00102   std::list<BlackBoardInterfaceProxy *> __invalid_proxies;
00103   std::list<BlackBoardInterfaceProxy *>::iterator __ipit;
00104 
00105   Mutex         *__wait_mutex;
00106   WaitCondition *__wait_cond;
00107 };
00108 
00109 } // end namespace fawkes
00110 
00111 #endif

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