Fawkes API
Fawkes Development Version
|
Fawkes Plugin Manager. More...
#include <>>
Public Member Functions | |
PluginManager (ThreadCollector *thread_collector, Configuration *config, const char *meta_plugin_prefix, Module::ModuleFlags module_flags=Module::MODULE_FLAGS_DEFAULT, bool init_cache=true) | |
Constructor. More... | |
~PluginManager () | |
Destructor. More... | |
void | set_module_flags (Module::ModuleFlags flags) |
Set flags to open modules with. More... | |
void | init_pinfo_cache () |
Initialize plugin info cache. More... | |
virtual void | config_tag_changed (const char *new_location) |
Called whenever the tag has changed. More... | |
virtual void | config_value_changed (const Configuration::ValueIterator *v) |
Called whenever a watched value has changed. More... | |
virtual void | config_comment_changed (const Configuration::ValueIterator *v) |
Called whenever a comment of a watched value has changed. More... | |
virtual void | config_value_erased (const char *path) |
Called whenever a value has been erased from the config. More... | |
virtual void | fam_event (const char *filename, unsigned int mask) |
Event has been raised. More... | |
void | load (const std::string &plugin_list) |
Load plugin. More... | |
void | load (const std::list< std::string > &plugin_list) |
Load plugin. More... | |
void | unload (const std::string &plugin_name) |
Unload plugin. More... | |
bool | is_loaded (const std::string &plugin_name) |
Check if plugin is loaded. More... | |
bool | is_meta_plugin (const std::string &plugin_name) |
Check if plugin is a meta plugin. More... | |
std::list< std::string > | get_meta_plugin_children (const std::string &plugin_name) |
Get meta plugin children. More... | |
std::list< std::string > | get_loaded_plugins () |
Get list of loaded plugins. More... | |
std::list< std::pair< std::string, std::string > > | get_available_plugins () |
Generate list of all available plugins. More... | |
void | add_listener (PluginManagerListener *listener) |
Add listener. More... | |
void | remove_listener (PluginManagerListener *listener) |
Remove listener. More... | |
void | lock () |
Lock plugin manager. More... | |
bool | try_lock () |
Try to lock plugin manager. More... | |
void | unlock () |
Unlock plugin manager. More... | |
![]() | |
ConfigurationChangeHandler (const char *path_prefix) | |
Constructor. More... | |
virtual | ~ConfigurationChangeHandler () |
Destructor. More... | |
const char * | config_monitor_prefix () |
Which path prefix shall be monitored. More... | |
![]() | |
virtual | ~FamListener () |
Virtual empty destructor. More... | |
Additional Inherited Members | |
![]() | |
static const unsigned int | FAM_ACCESS = 0x00000001 |
File was accessed. More... | |
static const unsigned int | FAM_MODIFY = 0x00000002 |
File was modified. More... | |
static const unsigned int | FAM_ATTRIB = 0x00000004 |
Metadata changed. More... | |
static const unsigned int | FAM_CLOSE_WRITE = 0x00000008 |
Writtable file was closed. More... | |
static const unsigned int | FAM_CLOSE_NOWRITE = 0x00000010 |
Unwrittable file closed. More... | |
static const unsigned int | FAM_CLOSE = (FAM_CLOSE_WRITE | FAM_CLOSE_NOWRITE) |
Close. More... | |
static const unsigned int | FAM_OPEN = 0x00000020 |
File was opened. More... | |
static const unsigned int | FAM_MOVED_FROM = 0x00000040 |
File was moved from X. More... | |
static const unsigned int | FAM_MOVED_TO = 0x00000080 |
File was moved to Y. More... | |
static const unsigned int | FAM_MOVE = (FAM_MOVED_FROM | FAM_MOVED_TO) |
Moves. More... | |
static const unsigned int | FAM_CREATE = 0x00000100 |
Subfile was created. More... | |
static const unsigned int | FAM_DELETE = 0x00000200 |
Subfile was deleted. More... | |
static const unsigned int | FAM_DELETE_SELF = 0x00000400 |
Self was deleted. More... | |
static const unsigned int | FAM_MOVE_SELF = 0x00000800 |
Self was moved. More... | |
static const unsigned int | FAM_UNMOUNT = 0x00002000 |
Backing fs was unmounted. More... | |
static const unsigned int | FAM_Q_OVERFLOW = 0x00004000 |
Event queued overflowed. More... | |
static const unsigned int | FAM_IGNORED = 0x00008000 |
File was ignored. More... | |
static const unsigned int | FAM_ONLYDIR = 0x01000000 |
Only watch the path if it is a directory. More... | |
static const unsigned int | FAM_DONT_FOLLOW = 0x02000000 |
Do not follow a sym link. More... | |
static const unsigned int | FAM_MASK_ADD = 0x20000000 |
Add to the mask of an already existing watch. More... | |
static const unsigned int | FAM_ISDIR = 0x40000000 |
Event occurred against dir. More... | |
static const unsigned int | FAM_ONESHOT = 0x80000000 |
Only send event once. More... | |
static const unsigned int | FAM_ALL_EVENTS |
All events which a program can wait on. More... | |
Fawkes Plugin Manager.
This class provides a manager for the plugins used in fawkes. It can load and unload modules.
fawkes::PluginManager::PluginManager | ( | ThreadCollector * | thread_collector, |
Configuration * | config, | ||
const char * | meta_plugin_prefix, | ||
Module::ModuleFlags | module_flags = Module::MODULE_FLAGS_DEFAULT , |
||
bool | init_cache = true |
||
) |
Constructor.
thread_collector | thread manager plugin threads will be added to and removed from appropriately. |
config | Fawkes configuration |
meta_plugin_prefix | Path prefix for meta plugins |
module_flags | flags to use to open plugin modules |
init_cache | true to initialize the plugin cache, false to skip this step. Note that some functions like transmitting a list of available plugins is unavailable until the cache has been initialized. You can defer initialization of the cache if required. |
Definition at line 85 of file manager.cpp.
References fawkes::Configuration::add_change_handler(), fawkes::FamThread::get_fam(), fawkes::PluginLoader::get_module_manager(), init_pinfo_cache(), fawkes::LibLogger::log_warn(), fawkes::ModuleManager::set_open_flags(), and fawkes::Thread::start().
fawkes::PluginManager::~PluginManager | ( | ) |
Destructor.
Definition at line 121 of file manager.cpp.
References fawkes::Thread::cancel(), fawkes::ThreadCollector::force_remove(), fawkes::Thread::join(), fawkes::LockList< Type >::lock(), fawkes::Configuration::rem_change_handler(), fawkes::PluginLoader::unload(), and fawkes::LockList< Type >::unlock().
void fawkes::PluginManager::add_listener | ( | PluginManagerListener * | listener | ) |
Add listener.
Listeners are notified of plugin load and unloda events.
listener | listener to add |
Definition at line 603 of file manager.cpp.
Referenced by fawkes::PluginNetworkHandler::PluginNetworkHandler().
|
virtual |
Called whenever a comment of a watched value has changed.
v | value iterator for the specific value |
Implements fawkes::ConfigurationChangeHandler.
Definition at line 519 of file manager.cpp.
|
virtual |
Called whenever the tag has changed.
This function can be used to detect when data from another tag has been loaded.
new_tag | new tag |
Implements fawkes::ConfigurationChangeHandler.
Definition at line 491 of file manager.cpp.
|
virtual |
Called whenever a watched value has changed.
v | value iterator for the specific value |
Implements fawkes::ConfigurationChangeHandler.
Definition at line 496 of file manager.cpp.
References fawkes::Configuration::ValueIterator::get_string(), fawkes::Configuration::ValueIterator::is_string(), fawkes::LockList< Type >::lock(), fawkes::Configuration::ValueIterator::path(), and fawkes::LockList< Type >::unlock().
|
virtual |
Called whenever a value has been erased from the config.
path | path of value |
Implements fawkes::ConfigurationChangeHandler.
Definition at line 524 of file manager.cpp.
References fawkes::LockList< Type >::lock(), and fawkes::LockList< Type >::unlock().
|
virtual |
Event has been raised.
filename | name of the file that triggered the event |
mask | mask indicating the event. Currently inotify event flags are used, see inotify.h. |
Implements fawkes::FamListener.
Definition at line 539 of file manager.cpp.
References fawkes::FamListener::FAM_CREATE, fawkes::FamListener::FAM_DELETE, fawkes::FamListener::FAM_ISDIR, fawkes::FamListener::FAM_MODIFY, fawkes::FamListener::FAM_MOVED_FROM, fawkes::FamListener::FAM_MOVED_TO, fawkes::PluginLoader::get_description(), fawkes::PluginLoader::is_loaded(), fawkes::LockList< Type >::lock(), fawkes::LibLogger::log_info(), fawkes::LibLogger::log_warn(), and fawkes::LockList< Type >::unlock().
std::list< std::pair< std::string, std::string > > fawkes::PluginManager::get_available_plugins | ( | ) |
Generate list of all available plugins.
Definition at line 218 of file manager.cpp.
Referenced by XmlRpcPluginMethods::plugin_list::execute().
std::list< std::string > fawkes::PluginManager::get_loaded_plugins | ( | ) |
Get list of loaded plugins.
Definition at line 234 of file manager.cpp.
References fawkes::LockMap< KeyType, ValueType, LessKey >::lock(), and fawkes::LockMap< KeyType, ValueType, LessKey >::unlock().
Referenced by XmlRpcPluginMethods::plugin_list::execute().
std::list< std::string > fawkes::PluginManager::get_meta_plugin_children | ( | const std::string & | plugin_name | ) |
Get meta plugin children.
plugin_name | plugin to check |
Definition at line 287 of file manager.cpp.
References fawkes::Configuration::get_string().
void fawkes::PluginManager::init_pinfo_cache | ( | ) |
Initialize plugin info cache.
Definition at line 161 of file manager.cpp.
References fawkes::PluginLoader::get_description(), fawkes::Configuration::ValueIterator::get_string(), fawkes::Configuration::ValueIterator::is_string(), fawkes::LockList< Type >::lock(), fawkes::LibLogger::log_warn(), fawkes::Configuration::ValueIterator::next(), fawkes::Configuration::ValueIterator::path(), fawkes::Configuration::search(), and fawkes::LockList< Type >::unlock().
Referenced by PluginManager().
bool fawkes::PluginManager::is_loaded | ( | const std::string & | plugin_name | ) |
Check if plugin is loaded.
plugin_name | plugin to check if it is loaded |
Definition at line 257 of file manager.cpp.
References fawkes::PluginLoader::is_loaded().
Referenced by fawkes::PluginNetworkHandler::loop().
bool fawkes::PluginManager::is_meta_plugin | ( | const std::string & | plugin_name | ) |
Check if plugin is a meta plugin.
plugin_name | plugin to check |
Definition at line 272 of file manager.cpp.
References fawkes::Configuration::is_string().
void fawkes::PluginManager::load | ( | const std::list< std::string > & | plugin_list | ) |
Load plugin.
The loading is interrupted if any of the plugins does not load properly. The already loaded plugins are not unloaded, but kept.
plugin_list | string containing a comma-separated list of plugins to load. The plugin list can contain meta plugins. |
Definition at line 337 of file manager.cpp.
References fawkes::ThreadCollector::add(), fawkes::Exception::append(), fawkes::LockMap< KeyType, ValueType, LessKey >::erase_locked(), fawkes::Configuration::get_string(), fawkes::Configuration::get_strings(), fawkes::Configuration::is_list(), fawkes::PluginLoader::load(), load(), lock(), fawkes::LockMap< KeyType, ValueType, LessKey >::lock(), fawkes::LibLogger::log_debug(), fawkes::LibLogger::log_info(), fawkes::LockMap< KeyType, ValueType, LessKey >::mutex(), fawkes::str_join(), fawkes::Plugin::threads(), fawkes::PluginLoader::unload(), and fawkes::LockMap< KeyType, ValueType, LessKey >::unlock().
void fawkes::PluginManager::load | ( | const std::string & | plugin_list | ) |
Load plugin.
The loading is interrupted if any of the plugins does not load properly. The already loaded plugins are not unloaded, but kept.
plugin_list | list of plugin names to load. The plugin list can contain meta plugins. |
Definition at line 325 of file manager.cpp.
Referenced by XmlRpcPluginMethods::plugin_load::execute(), load(), and fawkes::FawkesMainThread::once().
void fawkes::PluginManager::lock | ( | ) |
Lock plugin manager.
This is an utility method that you can use for mutual access to the plugin manager. The mutex is not used internally, but meant to be used from callers.
Definition at line 661 of file manager.cpp.
References fawkes::Mutex::lock().
Referenced by load(), fawkes::FawkesMainThread::loop(), and unload().
void fawkes::PluginManager::remove_listener | ( | PluginManagerListener * | listener | ) |
Remove listener.
listener | listener to remove |
Definition at line 616 of file manager.cpp.
Referenced by fawkes::PluginNetworkHandler::~PluginNetworkHandler().
void fawkes::PluginManager::set_module_flags | ( | Module::ModuleFlags | flags | ) |
Set flags to open modules with.
flags | flags to pass to modules when opening them |
Definition at line 154 of file manager.cpp.
References fawkes::PluginLoader::get_module_manager(), and fawkes::ModuleManager::set_open_flags().
bool fawkes::PluginManager::try_lock | ( | ) |
Try to lock plugin manager.
This is an utility method that you can use for mutual access to the plugin manager. The mutex is not used internally, but meant to be used from callers.
Definition at line 673 of file manager.cpp.
References fawkes::Mutex::try_lock().
void fawkes::PluginManager::unload | ( | const std::string & | plugin_name | ) |
Unload plugin.
Note that this method does not allow to pass a list of plugins, but it will only accept a single plugin at a time.
plugin_name | plugin to unload, can be a meta plugin. |
Definition at line 427 of file manager.cpp.
References fawkes::LockMap< KeyType, ValueType, LessKey >::erase_locked(), lock(), fawkes::LockMap< KeyType, ValueType, LessKey >::lock(), fawkes::LibLogger::log_error(), fawkes::LibLogger::log_info(), fawkes::ThreadCollector::remove(), fawkes::PluginLoader::unload(), and fawkes::LockMap< KeyType, ValueType, LessKey >::unlock().
Referenced by XmlRpcPluginMethods::plugin_unload::execute().
void fawkes::PluginManager::unlock | ( | ) |
Unlock plugin manager.
Definition at line 680 of file manager.cpp.
References fawkes::Mutex::unlock().
Referenced by fawkes::FawkesMainThread::loop().