Fawkes API  Fawkes Development Version
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 */
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 error_code);
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
BlackBoardNetworkHandler(BlackBoard *blackboard, FawkesNetworkHub *hub)
Constructor.
Definition: handler.cpp:57
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
virtual void loop()
Process all network messages that have been received.
Definition: handler.cpp:88
Representation of a message that is sent over the network.
Definition: message.h:75
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: handler.h:61
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Interface observer for blackboard network handler.
Map with a lock.
Definition: lock_map.h:37
virtual void client_disconnected(unsigned int clid)
Client disconnected.
Definition: handler.cpp:409
Fawkes Network Hub.
Definition: hub.h:33
virtual void client_connected(unsigned int clid)
Client connected.
Definition: handler.cpp:399
Network handler abstract base class.
Definition: handler.h:31
~BlackBoardNetworkHandler()
Destructor.
Definition: handler.cpp:71
The BlackBoard abstract class.
Definition: blackboard.h:48
BlackBoard Network Handler.
Definition: handler.h:45
virtual void handle_network_message(FawkesNetworkMessage *msg)
Handle network message.
Definition: handler.cpp:387