Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * network_handler.h - BlackBoard Network Handler 00004 * 00005 * Created: Sat Mar 01 15:57:59 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 __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 00036 class Interface; 00037 class BlackBoard; 00038 class FawkesNetworkHub; 00039 class BlackBoardNetHandlerInterfaceListener; 00040 00041 class BlackBoardNetworkHandler 00042 : public Thread, 00043 public FawkesNetworkHandler 00044 { 00045 public: 00046 BlackBoardNetworkHandler(BlackBoard *blackboard, 00047 FawkesNetworkHub *hub); 00048 ~BlackBoardNetworkHandler(); 00049 00050 /* from FawkesNetworkHandler interface */ 00051 virtual void handle_network_message(FawkesNetworkMessage *msg); 00052 virtual void client_connected(unsigned int clid); 00053 virtual void client_disconnected(unsigned int clid); 00054 virtual void loop(); 00055 00056 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00057 protected: virtual void run() { Thread::run(); } 00058 00059 private: 00060 void send_opensuccess(unsigned int clid, Interface *interface); 00061 void send_openfailure(unsigned int clid, unsigned int errno); 00062 00063 00064 BlackBoard *__bb; 00065 LockQueue< FawkesNetworkMessage * > __inbound_queue; 00066 00067 // All interfaces, key is the instance serial, value the interface 00068 LockMap< unsigned int, Interface * > __interfaces; 00069 LockMap< unsigned int, Interface * >::iterator __iit; 00070 00071 std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *> __listeners; 00072 std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *>::iterator __lit; 00073 00074 // Map from instance serial to clid 00075 LockMap<unsigned int, unsigned int > __serial_to_clid; 00076 00077 // Interfaces per client, key is the client ID, value a list of interfaces opened by client 00078 LockMap< unsigned int, std::list<Interface *> > __client_interfaces; 00079 std::list<Interface *>::iterator __ciit; 00080 00081 FawkesNetworkHub *__nhub; 00082 }; 00083 00084 } // end namespace fawkes 00085 00086 #endif