Fawkes API  Fawkes Development Version
connection_dispatcher.h
00001 
00002 /***************************************************************************
00003  *  connection_dispatcher.h - Network connection listener and dispatcher
00004  *
00005  *  Created: Mon Oct 20 15:02:47 2008
00006  *  Copyright  2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __LIBS_GUI_UTILS_CONNECTION_DISPATCHER_H_
00025 #define __LIBS_GUI_UTILS_CONNECTION_DISPATCHER_H_
00026 
00027 #include <cstddef>
00028 #include <glibmm/dispatcher.h>
00029 #include <netcomm/fawkes/client_handler.h>
00030 #include <netcomm/fawkes/component_ids.h>
00031 #include <core/utils/lock_queue.h>
00032 
00033 namespace fawkes {
00034 class FawkesNetworkClient;
00035 class FawkesNetworkMessage;
00036 
00037 class ConnectionDispatcher
00038 : public FawkesNetworkClientHandler
00039 {
00040  public:
00041   ConnectionDispatcher(unsigned int cid = FAWKES_CID_OBSERVER_MODE);
00042   ConnectionDispatcher(const char *hostname, unsigned short int port,
00043                        unsigned int cid = FAWKES_CID_OBSERVER_MODE);
00044   virtual ~ConnectionDispatcher();
00045 
00046   void set_cid(unsigned int cid);
00047   void set_client(FawkesNetworkClient *client);
00048   FawkesNetworkClient *   get_client();
00049 
00050   sigc::signal<void>                         signal_connected();
00051   sigc::signal<void>                         signal_disconnected();
00052   sigc::signal<void, FawkesNetworkMessage *> signal_message_received();
00053 
00054   virtual void deregistered(unsigned int id) throw();
00055   virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id) throw();
00056   virtual void connection_died(unsigned int id) throw();
00057   virtual void connection_established(unsigned int id) throw();
00058 
00059   operator bool();
00060 
00061  protected:
00062   virtual void on_connection_established();
00063   virtual void on_connection_died();
00064   virtual void on_message_received();
00065 
00066  private:
00067   void connect_signals();
00068 
00069  private:
00070   unsigned int                                   __cid;
00071   FawkesNetworkClient                           *__client;
00072   bool                                           __client_owned;
00073 
00074   Glib::Dispatcher                               __dispatcher_connected;
00075   Glib::Dispatcher                               __dispatcher_disconnected;
00076   Glib::Dispatcher                               __dispatcher_message_received;
00077 
00078   sigc::signal<void>                             __signal_connected;
00079   sigc::signal<void>                             __signal_disconnected;
00080   sigc::signal<void, FawkesNetworkMessage *>     __signal_message_received;
00081 
00082   LockQueue<FawkesNetworkMessage *>              __queue_message_received;
00083 };
00084 
00085 }
00086 
00087 #endif