Fawkes API  Fawkes Development Version
handler.h
00001 
00002 /***************************************************************************
00003  *  handler.h - BlackBoard Network Handler
00004  *
00005  *  Created: Sat Mar 01 15:57:59 2008
00006  *  Copyright  2006-2011  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 __FAWKES_BLACKBOARD_NETWORK_HANDLER_H_
00025 #define __FAWKES_BLACKBOARD_NETWORK_HANDLER_H_
00026 
00027 #include <core/threading/thread.h>
00028 #include <netcomm/fawkes/handler.h>
00029 
00030 #include <core/utils/lock_queue.h>
00031 #include <core/utils/lock_map.h>
00032 #include <list>
00033 
00034 namespace fawkes {
00035 #if 0 /* just to make Emacs auto-indent happy */
00036 }
00037 #endif
00038 
00039 class Interface;
00040 class BlackBoard;
00041 class FawkesNetworkHub;
00042 class BlackBoardNetHandlerInterfaceListener;
00043 class BlackBoardNetHandlerInterfaceObserver;
00044 
00045 class BlackBoardNetworkHandler
00046 : public Thread,
00047   public FawkesNetworkHandler
00048 {
00049  public:
00050   BlackBoardNetworkHandler(BlackBoard *blackboard,
00051                            FawkesNetworkHub *hub);
00052   ~BlackBoardNetworkHandler();
00053 
00054   /* from FawkesNetworkHandler interface */
00055   virtual void handle_network_message(FawkesNetworkMessage *msg);
00056   virtual void client_connected(unsigned int clid);
00057   virtual void client_disconnected(unsigned int clid);
00058   virtual void loop();
00059 
00060  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00061  protected: virtual void run() { Thread::run(); }
00062 
00063  private:
00064   void send_opensuccess(unsigned int clid, Interface *interface);
00065   void send_openfailure(unsigned int clid, unsigned int errno);
00066 
00067 
00068   BlackBoard *__bb;
00069   LockQueue< FawkesNetworkMessage * >  __inbound_queue;
00070 
00071   // All interfaces, key is the instance serial, value the interface
00072   LockMap< unsigned int, Interface * > __interfaces;
00073   LockMap< unsigned int, Interface * >::iterator __iit;
00074 
00075   std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *>  __listeners;
00076   std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *>::iterator  __lit;
00077 
00078   BlackBoardNetHandlerInterfaceObserver *__observer;
00079 
00080   // Map from instance serial to clid
00081   LockMap<unsigned int, unsigned int > __serial_to_clid;
00082 
00083   // Interfaces per client, key is the client ID, value a list of interfaces opened by client
00084   LockMap< unsigned int, std::list<Interface *> > __client_interfaces;
00085   std::list<Interface *>::iterator __ciit;
00086 
00087   FawkesNetworkHub *__nhub;
00088 };
00089 
00090 } // end namespace fawkes
00091 
00092 #endif