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 
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
~PluginManager()
Destructor.
Definition: manager.cpp:121
void set_module_flags(Module::ModuleFlags flags)
Set flags to open modules with.
Definition: manager.cpp:154
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
Definition: manager.cpp:539
std::list< std::pair< std::string, std::string > > get_available_plugins()
Generate list of all available plugins.
Definition: manager.cpp:218
void init_pinfo_cache()
Initialize plugin info cache.
Definition: manager.cpp:161
Fawkes library namespace.
bool try_lock()
Try to lock plugin manager.
Definition: manager.cpp:673
Interface for configuration change handling.
virtual void config_comment_changed(const Configuration::ValueIterator *v)
Called whenever a comment of a watched value has changed.
Definition: manager.cpp:519
std::list< std::string > get_meta_plugin_children(const std::string &plugin_name)
Get meta plugin children.
Definition: manager.cpp:287
Fawkes Plugin Manager.
Definition: manager.h:47
This class manages plugins.
Definition: loader.h:57
ModuleFlags
Flags for the loading process.
Definition: module.h:44
Map with a lock.
Definition: lock_map.h:35
void lock()
Lock plugin manager.
Definition: manager.cpp:661
PluginManager listener.
Definition: listener.h:29
void add_listener(PluginManagerListener *listener)
Add listener.
Definition: manager.cpp:603
Plugin representation for JSON transfer.
Definition: Plugin.h:26
virtual void config_tag_changed(const char *new_location)
Called whenever the tag has changed.
Definition: manager.cpp:491
List with a lock.
Definition: thread.h:43
void remove_listener(PluginManagerListener *listener)
Remove listener.
Definition: manager.cpp:616
File Alteration Monitor Listener.
Definition: fam.h:35
void unload(const std::string &plugin_name)
Unload plugin.
Definition: manager.cpp:427
std::list< std::string > get_loaded_plugins()
Get list of loaded plugins.
Definition: manager.cpp:234
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:85
void load(const std::string &plugin_list)
Load plugin.
Definition: manager.cpp:325
virtual void config_value_changed(const Configuration::ValueIterator *v)
Called whenever a watched value has changed.
Definition: manager.cpp:496
virtual void config_value_erased(const char *path)
Called whenever a value has been erased from the config.
Definition: manager.cpp:524
Iterator interface to iterate over config values.
Definition: config.h:71
bool is_loaded(const std::string &plugin_name)
Check if plugin is loaded.
Definition: manager.cpp:257
FileAlterationMonitor thread wrapper.
Definition: fam_thread.h:32
bool is_meta_plugin(const std::string &plugin_name)
Check if plugin is a meta plugin.
Definition: manager.cpp:272
void unlock()
Unlock plugin manager.
Definition: manager.cpp:680
Mutex mutual exclusion lock.
Definition: mutex.h:32
Default flags, these are MODULE_BIND_GLOBAL, MODULE_BIND_NOW and MODULE_BIND_DEEP.
Definition: module.h:46
Interface for configuration handling.
Definition: config.h:64