Fawkes API  Fawkes Development Version
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 PluginListMessage;
00051 class Configuration;
00052 class FamThread;
00053 
00054 class PluginNetworkHandler
00055 : public fawkes::Thread,
00056   public fawkes::FawkesNetworkHandler,
00057   public fawkes::PluginManagerListener
00058 {
00059  public:
00060   PluginNetworkHandler(PluginManager *manager, FawkesNetworkHub *hub);
00061   ~PluginNetworkHandler();
00062 
00063   virtual void handle_network_message(FawkesNetworkMessage *msg);
00064   virtual void client_connected(unsigned int clid);
00065   virtual void client_disconnected(unsigned int clid);
00066 
00067   virtual void loop();
00068 
00069   virtual void plugin_loaded(const char *plugin_name);
00070   virtual void plugin_unloaded(const char *plugin_name);
00071 
00072  private:
00073   PluginListMessage * list_avail();
00074   PluginListMessage * list_loaded();
00075   void send_load_failure(const char *plugin_name, unsigned int client_id);
00076   void send_load_success(const char *plugin_name, unsigned int client_id);
00077   void send_unload_failure(const char *plugin_name, unsigned int client_id);
00078   void send_unload_success(const char *plugin_name, unsigned int client_id);
00079   void send_loaded(const char *plugin_name);
00080   void send_unloaded(const char *plugin_name);
00081 
00082   void load(const char *plugin_list, unsigned int clid);
00083   void unload(const char *plugin_list, unsigned int clid);
00084 
00085  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00086  protected: virtual void run() { Thread::run(); }
00087 
00088  private:
00089   PluginManager     *__manager;
00090   FawkesNetworkHub  *__hub;
00091 
00092   LockQueue< FawkesNetworkMessage * > __inbound_queue;
00093 
00094   LockList<unsigned int>           __subscribers;
00095   LockList<unsigned int>::iterator __ssit;
00096 };
00097 
00098 } // end namespace fawkes
00099 
00100 #endif