Fawkes API  Fawkes Development Version
connection_dispatcher.h
1 
2 /***************************************************************************
3  * connection_dispatcher.h - Network connection listener and dispatcher
4  *
5  * Created: Mon Oct 20 15:02:47 2008
6  * Copyright 2008 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 _LIBS_GUI_UTILS_CONNECTION_DISPATCHER_H_
25 #define _LIBS_GUI_UTILS_CONNECTION_DISPATCHER_H_
26 
27 #include <core/utils/lock_queue.h>
28 #include <glibmm/dispatcher.h>
29 #include <netcomm/fawkes/client_handler.h>
30 #include <netcomm/fawkes/component_ids.h>
31 
32 #include <cstddef>
33 
34 namespace fawkes {
35 class FawkesNetworkClient;
36 class FawkesNetworkMessage;
37 
38 class ConnectionDispatcher : public FawkesNetworkClientHandler
39 {
40 public:
41  ConnectionDispatcher(unsigned int cid = FAWKES_CID_OBSERVER_MODE);
42  ConnectionDispatcher(const char * hostname,
43  unsigned short int port,
44  unsigned int cid = FAWKES_CID_OBSERVER_MODE);
45  virtual ~ConnectionDispatcher();
46 
47  void set_cid(unsigned int cid);
48  void set_client(FawkesNetworkClient *client);
50 
51  sigc::signal<void> signal_connected();
52  sigc::signal<void> signal_disconnected();
53  sigc::signal<void, FawkesNetworkMessage *> signal_message_received();
54 
55  virtual void deregistered(unsigned int id) throw();
56  virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id) throw();
57  virtual void connection_died(unsigned int id) throw();
58  virtual void connection_established(unsigned int id) throw();
59 
60  operator bool();
61 
62 protected:
63  virtual void on_connection_established();
64  virtual void on_connection_died();
65  virtual void on_message_received();
66 
67 private:
68  void connect_signals();
69 
70 private:
71  unsigned int cid_;
72  FawkesNetworkClient *client_;
73  bool client_owned_;
74 
75  Glib::Dispatcher dispatcher_connected_;
76  Glib::Dispatcher dispatcher_disconnected_;
77  Glib::Dispatcher dispatcher_message_received_;
78 
79  sigc::signal<void> signal_connected_;
80  sigc::signal<void> signal_disconnected_;
81  sigc::signal<void, FawkesNetworkMessage *> signal_message_received_;
82 
83  LockQueue<FawkesNetworkMessage *> queue_message_received_;
84 };
85 
86 } // namespace fawkes
87 
88 #endif
fawkes::ConnectionDispatcher::signal_message_received
sigc::signal< void, FawkesNetworkMessage * > signal_message_received()
Get "message received" signal.
Definition: connection_dispatcher.cpp:210
fawkes::ConnectionDispatcher::ConnectionDispatcher
ConnectionDispatcher(unsigned int cid=FAWKES_CID_OBSERVER_MODE)
Constructor.
Definition: connection_dispatcher.cpp:45
fawkes::ConnectionDispatcher::on_connection_established
virtual void on_connection_established()
Internal event handler.
Definition: connection_dispatcher.cpp:148
fawkes::ConnectionDispatcher::set_client
void set_client(FawkesNetworkClient *client)
Set Fawkes network client.
Definition: connection_dispatcher.cpp:113
fawkes::ConnectionDispatcher::connection_established
virtual void connection_established(unsigned int id)
Definition: connection_dispatcher.cpp:199
fawkes::ConnectionDispatcher::on_message_received
virtual void on_message_received()
Internal event handler.
Definition: connection_dispatcher.cpp:166
fawkes::ConnectionDispatcher::deregistered
virtual void deregistered(unsigned int id)
Definition: connection_dispatcher.cpp:179
fawkes::ConnectionDispatcher::signal_connected
sigc::signal< void > signal_connected()
Get "connected" signal.
Definition: connection_dispatcher.cpp:220
fawkes
fawkes::ConnectionDispatcher::set_cid
void set_cid(unsigned int cid)
Set component ID.
Definition: connection_dispatcher.cpp:97
fawkes::ConnectionDispatcher::on_connection_died
virtual void on_connection_died()
Internal event handler.
Definition: connection_dispatcher.cpp:157
fawkes::ConnectionDispatcher::signal_disconnected
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
Definition: connection_dispatcher.cpp:231
fawkes::LockQueue< FawkesNetworkMessage * >
fawkes::FawkesNetworkMessage
Definition: message.h:80
fawkes::FawkesNetworkClient
Definition: client.h:55
fawkes::ConnectionDispatcher::~ConnectionDispatcher
virtual ~ConnectionDispatcher()
Destructor.
Definition: connection_dispatcher.cpp:74
fawkes::ConnectionDispatcher::get_client
FawkesNetworkClient * get_client()
Get client.
Definition: connection_dispatcher.cpp:130
fawkes::ConnectionDispatcher::connection_died
virtual void connection_died(unsigned int id)
Definition: connection_dispatcher.cpp:193
fawkes::ConnectionDispatcher::inbound_received
virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id)
Definition: connection_dispatcher.cpp:185