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 <cstddef>
28 #include <glibmm/dispatcher.h>
29 #include <netcomm/fawkes/client_handler.h>
30 #include <netcomm/fawkes/component_ids.h>
31 #include <core/utils/lock_queue.h>
32 
33 namespace fawkes {
34 class FawkesNetworkClient;
35 class FawkesNetworkMessage;
36 
39 {
40  public:
41  ConnectionDispatcher(unsigned int cid = FAWKES_CID_OBSERVER_MODE);
42  ConnectionDispatcher(const char *hostname, unsigned short int port,
43  unsigned int cid = FAWKES_CID_OBSERVER_MODE);
44  virtual ~ConnectionDispatcher();
45 
46  void set_cid(unsigned int cid);
47  void set_client(FawkesNetworkClient *client);
49 
50  sigc::signal<void> signal_connected();
51  sigc::signal<void> signal_disconnected();
52  sigc::signal<void, FawkesNetworkMessage *> signal_message_received();
53 
54  virtual void deregistered(unsigned int id) throw();
55  virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id) throw();
56  virtual void connection_died(unsigned int id) throw();
57  virtual void connection_established(unsigned int id) throw();
58 
59  operator bool();
60 
61  protected:
62  virtual void on_connection_established();
63  virtual void on_connection_died();
64  virtual void on_message_received();
65 
66  private:
67  void connect_signals();
68 
69  private:
70  unsigned int __cid;
71  FawkesNetworkClient *__client;
72  bool __client_owned;
73 
74  Glib::Dispatcher __dispatcher_connected;
75  Glib::Dispatcher __dispatcher_disconnected;
76  Glib::Dispatcher __dispatcher_message_received;
77 
78  sigc::signal<void> __signal_connected;
79  sigc::signal<void> __signal_disconnected;
80  sigc::signal<void, FawkesNetworkMessage *> __signal_message_received;
81 
82  LockQueue<FawkesNetworkMessage *> __queue_message_received;
83 };
84 
85 }
86 
87 #endif
Message handler for FawkesNetworkClient.
sigc::signal< void > signal_disconnected()
Get "disconnected" signal.
sigc::signal< void > signal_connected()
Get "connected" signal.
Simple Fawkes network client.
Definition: client.h:52
Fawkes library namespace.
Representation of a message that is sent over the network.
Definition: message.h:75
void set_client(FawkesNetworkClient *client)
Set Fawkes network client.
ConnectionDispatcher(unsigned int cid=FAWKES_CID_OBSERVER_MODE)
Constructor.
virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id)
Called for incoming messages.
virtual void on_message_received()
Internal event handler.
virtual void on_connection_died()
Internal event handler.
virtual void connection_established(unsigned int id)
Client has established a connection.
void set_cid(unsigned int cid)
Set component ID.
virtual void connection_died(unsigned int id)
Client connection died.
virtual ~ConnectionDispatcher()
Destructor.
Queue with a lock.
Definition: lock_queue.h:43
virtual void on_connection_established()
Internal event handler.
sigc::signal< void, FawkesNetworkMessage * > signal_message_received()
Get "message received" signal.
FawkesNetworkClient * get_client()
Get client.
Watches network client events and dispatches them as signals.
virtual void deregistered(unsigned int id)
This handler has been deregistered.