Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
handler.h
1 
2 /***************************************************************************
3  * handler.h - BlackBoard Network Handler
4  *
5  * Created: Sat Mar 01 15:57:59 2008
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FAWKES_BLACKBOARD_NETWORK_HANDLER_H_
25 #define __FAWKES_BLACKBOARD_NETWORK_HANDLER_H_
26 
27 #include <core/threading/thread.h>
28 #include <netcomm/fawkes/handler.h>
29 
30 #include <core/utils/lock_queue.h>
31 #include <core/utils/lock_map.h>
32 #include <list>
33 
34 namespace fawkes {
35 #if 0 /* just to make Emacs auto-indent happy */
36 }
37 #endif
38 
39 class Interface;
40 class BlackBoard;
41 class FawkesNetworkHub;
42 class BlackBoardNetHandlerInterfaceListener;
43 class BlackBoardNetHandlerInterfaceObserver;
44 
46 : public Thread,
48 {
49  public:
51  FawkesNetworkHub *hub);
53 
54  /* from FawkesNetworkHandler interface */
55  virtual void handle_network_message(FawkesNetworkMessage *msg);
56  virtual void client_connected(unsigned int clid);
57  virtual void client_disconnected(unsigned int clid);
58  virtual void loop();
59 
60  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
61  protected: virtual void run() { Thread::run(); }
62 
63  private:
64  void send_opensuccess(unsigned int clid, Interface *interface);
65  void send_openfailure(unsigned int clid, unsigned int errno);
66 
67 
68  BlackBoard *__bb;
70 
71  // All interfaces, key is the instance serial, value the interface
74 
75  std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *> __listeners;
76  std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *>::iterator __lit;
77 
79 
80  // Map from instance serial to clid
81  LockMap<unsigned int, unsigned int > __serial_to_clid;
82 
83  // Interfaces per client, key is the client ID, value a list of interfaces opened by client
85  std::list<Interface *>::iterator __ciit;
86 
87  FawkesNetworkHub *__nhub;
88 };
89 
90 } // end namespace fawkes
91 
92 #endif