Fawkes API
Fawkes Development Version
|
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 #include <utils/system/dynamic_module/module.h> 00033 00034 #include <string> 00035 #include <utility> 00036 00037 namespace fawkes { 00038 #if 0 /* just to make Emacs auto-indent happy */ 00039 } 00040 #endif 00041 00042 class ThreadCollector; 00043 class Plugin; 00044 class PluginLoader; 00045 class Mutex; 00046 class PluginListMessage; 00047 class Configuration; 00048 #ifdef HAVE_INOTIFY 00049 class FamThread; 00050 #endif 00051 class PluginManagerListener; 00052 00053 class PluginManager 00054 : public fawkes::ConfigurationChangeHandler, 00055 public FamListener 00056 { 00057 public: 00058 PluginManager(ThreadCollector *thread_collector, 00059 Configuration *config, 00060 const char *meta_plugin_prefix, 00061 Module::ModuleFlags module_flags = Module::MODULE_FLAGS_DEFAULT, 00062 bool init_cache = true); 00063 ~PluginManager(); 00064 00065 void set_module_flags(Module::ModuleFlags flags); 00066 void init_pinfo_cache(); 00067 00068 // for ConfigurationChangeHandler 00069 virtual void config_tag_changed(const char *new_location); 00070 virtual void config_value_changed(const Configuration::ValueIterator *v); 00071 virtual void config_comment_changed(const Configuration::ValueIterator *v); 00072 virtual void config_value_erased(const char *path); 00073 00074 // for FamListener 00075 virtual void fam_event(const char *filename, unsigned int mask); 00076 00077 void load(const char *plugin_list); 00078 void unload(const char *plugin_name); 00079 00080 bool is_loaded(const char *plugin_name); 00081 00082 std::list<std::string> get_loaded_plugins(); 00083 std::list<std::pair<std::string, std::string> > get_available_plugins(); 00084 00085 void add_listener(PluginManagerListener *listener); 00086 void remove_listener(PluginManagerListener *listener); 00087 00088 void lock(); 00089 bool try_lock(); 00090 void unlock(); 00091 00092 private: 00093 void notify_loaded(const char *plugin_name); 00094 void notify_unloaded(const char *plugin_name); 00095 00096 std::list<std::string> parse_plugin_list(const char *plugin_type_list); 00097 00098 private: 00099 ThreadCollector *thread_collector; 00100 PluginLoader *plugin_loader; 00101 Mutex *__mutex; 00102 00103 LockList<Plugin *> plugins; 00104 LockList<Plugin *>::iterator pit; 00105 LockList<Plugin *>::reverse_iterator rpit; 00106 00107 LockMap< std::string, std::string > __meta_plugins; 00108 LockMap< std::string, std::string >::iterator __mpit; 00109 00110 unsigned int next_plugin_id; 00111 std::map< std::string, unsigned int > plugin_ids; 00112 00113 LockList<std::pair<std::string, std::string> > __pinfo_cache; 00114 00115 LockList<PluginManagerListener *> __listeners; 00116 LockList<PluginManagerListener *>::iterator __lit; 00117 00118 Configuration *__config; 00119 std::string __meta_plugin_prefix; 00120 00121 #ifdef HAVE_INOTIFY 00122 FamThread *__fam_thread; 00123 #else 00124 void *__fam_thread; 00125 #endif 00126 }; 00127 00128 } // end namespace fawkes 00129 00130 #endif