handler.h

00001 
00002 /***************************************************************************
00003  *  handler.h - Fawkes plugin network handler
00004  *
00005  *  Created: Thu Feb 12 10:23:02 2009
00006  *  Copyright  2006-2009  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 __PLUGIN_NET_HANDLER_H_
00025 #define __PLUGIN_NET_HANDLER_H_
00026 
00027 #include <netcomm/fawkes/handler.h>
00028 #include <core/threading/thread.h>
00029 #include <core/utils/lock_queue.h>
00030 #include <core/utils/lock_list.h>
00031 #include <core/utils/lock_map.h>
00032 #include <config/change_handler.h>
00033 #include <utils/system/fam.h>
00034 #include <plugin/listener.h>
00035 
00036 #include <map>
00037 #include <list>
00038 #include <string>
00039 #include <utility>
00040 
00041 namespace fawkes {
00042 #if 0 /* just to make Emacs auto-indent happy */
00043 }
00044 #endif
00045 
00046 class ThreadCollector;
00047 class FawkesNetworkHub;
00048 class Plugin;
00049 class PluginLoader;
00050 class Mutex;
00051 class PluginListMessage;
00052 class Configuration;
00053 class FamThread;
00054 
00055 class PluginNetworkHandler
00056 : public fawkes::Thread,
00057   public fawkes::FawkesNetworkHandler,
00058   public fawkes::PluginManagerListener
00059 {
00060  public:
00061   PluginNetworkHandler(PluginManager *manager, FawkesNetworkHub *hub,
00062                        Mutex *mutex = NULL);
00063   ~PluginNetworkHandler();
00064 
00065   virtual void handle_network_message(FawkesNetworkMessage *msg);
00066   virtual void client_connected(unsigned int clid);
00067   virtual void client_disconnected(unsigned int clid);
00068 
00069   virtual void loop();
00070 
00071   virtual void plugin_loaded(const char *plugin_name);
00072   virtual void plugin_unloaded(const char *plugin_name);
00073 
00074  private:
00075   PluginListMessage * list_avail();
00076   PluginListMessage * list_loaded();
00077   void send_load_failure(const char *plugin_name, unsigned int client_id);
00078   void send_load_success(const char *plugin_name, unsigned int client_id);
00079   void send_unload_failure(const char *plugin_name, unsigned int client_id);
00080   void send_unload_success(const char *plugin_name, unsigned int client_id);
00081   void send_loaded(const char *plugin_name);
00082   void send_unloaded(const char *plugin_name);
00083 
00084   void load(const char *plugin_list, unsigned int clid);
00085   void unload(const char *plugin_list, unsigned int clid);
00086 
00087  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00088  protected: virtual void run() { Thread::run(); }
00089 
00090  private:
00091   Mutex             *__mutex;
00092 
00093   PluginManager     *__manager;
00094   FawkesNetworkHub  *__hub;
00095 
00096   LockQueue< FawkesNetworkMessage * > __inbound_queue;
00097 
00098   LockList<unsigned int>           __subscribers;
00099   LockList<unsigned int>::iterator __ssit;
00100 };
00101 
00102 } // end namespace fawkes
00103 
00104 #endif

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1