manager.h

00001 
00002 /***************************************************************************
00003  *  manager.h - Fawkes plugin manager
00004  *
00005  *  Created: Wed Nov 15 23:28:01 2006
00006  *  Copyright  2006-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 __PLUGIN_MANAGER_H_
00025 #define __PLUGIN_MANAGER_H_
00026 
00027 #include <netcomm/fawkes/handler.h>
00028 #include <core/utils/lock_list.h>
00029 #include <core/utils/lock_map.h>
00030 #include <config/change_handler.h>
00031 #include <utils/system/fam.h>
00032 
00033 #include <string>
00034 #include <utility>
00035 
00036 namespace fawkes {
00037 #if 0 /* just to make Emacs auto-indent happy */
00038 }
00039 #endif
00040 
00041 class ThreadCollector;
00042 class Plugin;
00043 class PluginLoader;
00044 class Mutex;
00045 class PluginListMessage;
00046 class Configuration;
00047 #ifdef HAVE_INOTIFY
00048 class FamThread;
00049 #endif
00050 class PluginManagerListener;
00051 
00052 class PluginManager
00053 : public fawkes::ConfigurationChangeHandler,
00054   public FamListener
00055 {
00056  public:
00057   PluginManager(ThreadCollector *thread_collector,
00058                 Configuration *config,
00059                 const char *meta_plugin_prefix);
00060   ~PluginManager();
00061 
00062   // for ConfigurationChangeHandler
00063   virtual void config_tag_changed(const char *new_tag);
00064   virtual void config_value_changed(const char *path, bool is_default, int value);
00065   virtual void config_value_changed(const char *path, bool is_default, unsigned int value);
00066   virtual void config_value_changed(const char *path, bool is_default, float value);
00067   virtual void config_value_changed(const char *path, bool is_default, bool value);
00068   virtual void config_value_changed(const char *path, bool is_default, const char *value);
00069   virtual void config_comment_changed(const char *path, bool is_default, const char *comment);
00070   virtual void config_value_erased(const char *path, bool is_default);
00071 
00072   // for FamListener
00073   virtual void fam_event(const char *filename, unsigned int mask);
00074 
00075   void load(const char *plugin_list);
00076   void unload(const char *plugin_name);
00077 
00078   bool is_loaded(const char *plugin_name);
00079 
00080   std::list<std::string>                           get_loaded_plugins();
00081   std::list<std::pair<std::string, std::string> >  get_available_plugins();
00082 
00083   void add_listener(PluginManagerListener *listener);
00084   void remove_listener(PluginManagerListener *listener);
00085 
00086  private:
00087   void init_pinfo_cache();
00088   void notify_loaded(const char *plugin_name);
00089   void notify_unloaded(const char *plugin_name);
00090 
00091   std::list<std::string>  parse_plugin_list(const char *plugin_type_list);
00092 
00093  private:
00094   ThreadCollector   *thread_collector;
00095   PluginLoader      *plugin_loader;
00096 
00097   LockMap< std::string, Plugin * > plugins;
00098   LockMap< std::string, Plugin * >::iterator pit;
00099   LockMap< std::string, Plugin * >::reverse_iterator rpit;
00100 
00101   LockMap< std::string, std::string > __meta_plugins;
00102   LockMap< std::string, std::string >::iterator __mpit;
00103 
00104   unsigned int next_plugin_id;
00105   std::map< std::string, unsigned int > plugin_ids;
00106 
00107   LockList<std::pair<std::string, std::string> > __pinfo_cache;
00108 
00109   LockList<PluginManagerListener *>           __listeners;
00110   LockList<PluginManagerListener *>::iterator __lit;
00111 
00112   Configuration *__config;
00113   std::string __meta_plugin_prefix;
00114 
00115 #ifdef HAVE_INOTIFY
00116   FamThread *__fam_thread;
00117 #else
00118   void *__fam_thread;
00119 #endif
00120 };
00121 
00122 } // end namespace fawkes
00123 
00124 #endif

Generated on Tue Feb 22 13:32:28 2011 for Fawkes API by  doxygen 1.4.7