Fawkes API  Fawkes Development Version
manager.h
1 
2 /***************************************************************************
3  * manager.h - Fawkes plugin manager
4  *
5  * Created: Wed Nov 15 23:28:01 2006
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _PLUGIN_MANAGER_H_
25 #define _PLUGIN_MANAGER_H_
26 
27 #include <config/change_handler.h>
28 #include <core/utils/lock_list.h>
29 #include <core/utils/lock_map.h>
30 #include <utils/system/dynamic_module/module.h>
31 #include <utils/system/fam.h>
32 
33 #include <string>
34 #include <utility>
35 
36 namespace fawkes {
37 
38 class ThreadCollector;
39 class Plugin;
40 class PluginLoader;
41 class Mutex;
42 class PluginListMessage;
43 class Configuration;
44 class FamThread;
45 class PluginManagerListener;
46 
47 class PluginManager : public fawkes::ConfigurationChangeHandler, public FamListener
48 {
49 public:
50  PluginManager(ThreadCollector * thread_collector,
51  Configuration * config,
52  const char * meta_plugin_prefix,
54  bool init_cache = true);
56 
58  void init_pinfo_cache();
59 
60  // for ConfigurationChangeHandler
61  virtual void config_tag_changed(const char *new_location);
64  virtual void config_value_erased(const char *path);
65 
66  // for FamListener
67  virtual void fam_event(const char *filename, unsigned int mask);
68 
69  void load(const std::string &plugin_list);
70  void load(const std::list<std::string> &plugin_list);
71  void unload(const std::string &plugin_name);
72 
73  bool is_loaded(const std::string &plugin_name);
74  bool is_meta_plugin(const std::string &plugin_name);
75 
76  std::list<std::string> get_meta_plugin_children(const std::string &plugin_name);
77 
78  std::list<std::string> get_loaded_plugins();
79  std::list<std::pair<std::string, std::string>> get_available_plugins();
80 
81  void add_listener(PluginManagerListener *listener);
82  void remove_listener(PluginManagerListener *listener);
83 
84  void lock();
85  bool try_lock();
86  void unlock();
87 
88 private:
89  void notify_loaded(const char *plugin_name);
90  void notify_unloaded(const char *plugin_name);
91 
92  std::list<std::string> parse_plugin_list(const char *plugin_type_list);
93 
94 private:
95  ThreadCollector *thread_collector;
96  PluginLoader * plugin_loader;
97  Mutex * mutex_;
98 
99  LockList<Plugin *> plugins;
102 
105 
106  unsigned int next_plugin_id;
107  std::map<std::string, unsigned int> plugin_ids;
108 
110 
113 
114  Configuration *config_;
115  std::string meta_plugin_prefix_;
116 
117  FamThread *fam_thread_;
118 };
119 
120 } // end namespace fawkes
121 
122 #endif
fawkes::ThreadCollector
Definition: thread_collector.h:38
fawkes::Module::ModuleFlags
ModuleFlags
Flags for the loading process.
Definition: module.h:49
fawkes::PluginManager::init_pinfo_cache
void init_pinfo_cache()
Initialize plugin info cache.
Definition: manager.cpp:165
fawkes::PluginManager::try_lock
bool try_lock()
Try to lock plugin manager.
Definition: manager.cpp:677
fawkes::PluginManager::is_loaded
bool is_loaded(const std::string &plugin_name)
Check if plugin is loaded.
Definition: manager.cpp:261
fawkes::LockMap
Definition: lock_map.h:39
fawkes::PluginManager::unlock
void unlock()
Unlock plugin manager.
Definition: manager.cpp:684
fawkes::Mutex
Definition: mutex.h:36
fawkes::PluginManager::lock
void lock()
Lock plugin manager.
Definition: manager.cpp:665
fawkes::PluginManager::set_module_flags
void set_module_flags(Module::ModuleFlags flags)
Set flags to open modules with.
Definition: manager.cpp:158
fawkes::LockList
Definition: thread.h:42
fawkes::PluginManagerListener
Definition: listener.h:33
fawkes::ConfigurationChangeHandler
Definition: change_handler.h:35
fawkes::PluginManager::remove_listener
void remove_listener(PluginManagerListener *listener)
Remove listener.
Definition: manager.cpp:620
fawkes::PluginLoader
Definition: loader.h:61
fawkes::PluginManager::get_available_plugins
std::list< std::pair< std::string, std::string > > get_available_plugins()
Generate list of all available plugins.
Definition: manager.cpp:222
fawkes::FamThread
Definition: fam_thread.h:36
fawkes::PluginManager::get_loaded_plugins
std::list< std::string > get_loaded_plugins()
Get list of loaded plugins.
Definition: manager.cpp:238
fawkes::PluginManager::config_comment_changed
virtual void config_comment_changed(const Configuration::ValueIterator *v)
Definition: manager.cpp:523
fawkes::Configuration::ValueIterator
Definition: config.h:75
fawkes::Configuration
Definition: config.h:68
fawkes::PluginManager::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.
Definition: manager.cpp:89
fawkes::PluginManager::get_meta_plugin_children
std::list< std::string > get_meta_plugin_children(const std::string &plugin_name)
Get meta plugin children.
Definition: manager.cpp:291
fawkes
fawkes::PluginManager::load
void load(const std::string &plugin_list)
Load plugin.
Definition: manager.cpp:329
fawkes::PluginManager::is_meta_plugin
bool is_meta_plugin(const std::string &plugin_name)
Check if plugin is a meta plugin.
Definition: manager.cpp:276
fawkes::PluginManager::add_listener
void add_listener(PluginManagerListener *listener)
Add listener.
Definition: manager.cpp:607
Plugin
Plugin representation for JSON transfer.
Definition: Plugin.h:25
fawkes::PluginManager::config_tag_changed
virtual void config_tag_changed(const char *new_location)
Definition: manager.cpp:495
fawkes::Module::MODULE_FLAGS_DEFAULT
Default flags, these are MODULE_BIND_GLOBAL, MODULE_BIND_NOW and MODULE_BIND_DEEP.
Definition: module.h:51
fawkes::PluginManager::~PluginManager
~PluginManager()
Destructor.
Definition: manager.cpp:125
fawkes::PluginManager::unload
void unload(const std::string &plugin_name)
Unload plugin.
Definition: manager.cpp:431
fawkes::PluginManager::config_value_erased
virtual void config_value_erased(const char *path)
Definition: manager.cpp:528
fawkes::PluginManager::fam_event
virtual void fam_event(const char *filename, unsigned int mask)
Definition: manager.cpp:543
fawkes::PluginManager::config_value_changed
virtual void config_value_changed(const Configuration::ValueIterator *v)
Definition: manager.cpp:500