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 <core/utils/lock_map.h>
29 #include <core/utils/lock_queue.h>
30 #include <netcomm/fawkes/handler.h>
31 
32 #include <list>
33 
34 namespace fawkes {
35 
36 class Interface;
37 class BlackBoard;
38 class FawkesNetworkHub;
39 class BlackBoardNetHandlerInterfaceListener;
40 class BlackBoardNetHandlerInterfaceObserver;
41 
43 {
44 public:
47 
48  /* from FawkesNetworkHandler interface */
50  virtual void client_connected(unsigned int clid);
51  virtual void client_disconnected(unsigned int clid);
52  virtual void loop();
53 
54  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
55 protected:
56  virtual void
57  run()
58  {
59  Thread::run();
60  }
61 
62 private:
63  void send_opensuccess(unsigned int clid, Interface *interface);
64  void send_openfailure(unsigned int clid, unsigned int error_code);
65 
66  BlackBoard * bb_;
67  LockQueue<FawkesNetworkMessage *> inbound_queue_;
68 
69  // All interfaces, key is the instance serial, value the interface
72 
73  std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *> listeners_;
74  std::map<unsigned int, BlackBoardNetHandlerInterfaceListener *>::iterator lit_;
75 
77 
78  // Map from instance serial to clid
80 
81  // Interfaces per client, key is the client ID, value a list of interfaces opened by client
83  std::list<Interface *>::iterator ciit_;
84 
85  FawkesNetworkHub *nhub_;
86 };
87 
88 } // end namespace fawkes
89 
90 #endif
fawkes::LockMap
Map with a lock.
Definition: lock_map.h:36
fawkes::BlackBoardNetworkHandler::handle_network_message
virtual void handle_network_message(FawkesNetworkMessage *msg)
Handle network message.
Definition: handler.cpp:399
fawkes::BlackBoardNetworkHandler::~BlackBoardNetworkHandler
~BlackBoardNetworkHandler()
Destructor.
Definition: handler.cpp:67
fawkes::BlackBoard
The BlackBoard abstract class.
Definition: blackboard.h:46
fawkes::FawkesNetworkHandler
Network handler abstract base class.
Definition: handler.h:32
fawkes::BlackBoardNetHandlerInterfaceObserver
Interface observer for blackboard network handler.
Definition: interface_observer.h:35
fawkes::BlackBoardNetworkHandler::loop
virtual void loop()
Process all network messages that have been received.
Definition: handler.cpp:83
fawkes::BlackBoardNetworkHandler
BlackBoard Network Handler.
Definition: handler.h:43
fawkes
Fawkes library namespace.
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
fawkes::BlackBoardNetworkHandler::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: handler.h:57
fawkes::BlackBoardNetworkHandler::client_disconnected
virtual void client_disconnected(unsigned int clid)
Client disconnected.
Definition: handler.cpp:419
fawkes::Thread::run
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:918
fawkes::LockQueue< FawkesNetworkMessage * >
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::BlackBoardNetworkHandler::client_connected
virtual void client_connected(unsigned int clid)
Client connected.
Definition: handler.cpp:410
fawkes::FawkesNetworkMessage
Representation of a message that is sent over the network.
Definition: message.h:77
fawkes::FawkesNetworkHub
Fawkes Network Hub.
Definition: hub.h:34
fawkes::BlackBoardNetworkHandler::BlackBoardNetworkHandler
BlackBoardNetworkHandler(BlackBoard *blackboard, FawkesNetworkHub *hub)
Constructor.
Definition: handler.cpp:55