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 <netcomm/fawkes/handler.h>
28 #include <core/utils/lock_list.h>
29 #include <core/utils/lock_map.h>
30 #include <config/change_handler.h>
31 #include <utils/system/fam.h>
32 #include <utils/system/dynamic_module/module.h>
33 
34 #include <string>
35 #include <utility>
36 
37 namespace fawkes {
38 #if 0 /* just to make Emacs auto-indent happy */
39 }
40 #endif
41 
42 class ThreadCollector;
43 class Plugin;
44 class PluginLoader;
45 class Mutex;
46 class PluginListMessage;
47 class Configuration;
48 #ifdef HAVE_INOTIFY
49 class FamThread;
50 #endif
51 class PluginManagerListener;
52 
55  public FamListener
56 {
57  public:
58  PluginManager(ThreadCollector *thread_collector,
59  Configuration *config,
60  const char *meta_plugin_prefix,
62  bool init_cache = true);
64 
66  void init_pinfo_cache();
67 
68  // for ConfigurationChangeHandler
69  virtual void config_tag_changed(const char *new_location);
72  virtual void config_value_erased(const char *path);
73 
74  // for FamListener
75  virtual void fam_event(const char *filename, unsigned int mask);
76 
77  void load(const char *plugin_list);
78  void unload(const char *plugin_name);
79 
80  bool is_loaded(const char *plugin_name);
81 
82  std::list<std::string> get_loaded_plugins();
83  std::list<std::pair<std::string, std::string> > get_available_plugins();
84 
85  void add_listener(PluginManagerListener *listener);
86  void remove_listener(PluginManagerListener *listener);
87 
88  void lock();
89  bool try_lock();
90  void unlock();
91 
92  private:
93  void notify_loaded(const char *plugin_name);
94  void notify_unloaded(const char *plugin_name);
95 
96  std::list<std::string> parse_plugin_list(const char *plugin_type_list);
97 
98  private:
99  ThreadCollector *thread_collector;
100  PluginLoader *plugin_loader;
101  Mutex *__mutex;
102 
103  LockList<Plugin *> plugins;
106 
109 
110  unsigned int next_plugin_id;
111  std::map< std::string, unsigned int > plugin_ids;
112 
114 
117 
118  Configuration *__config;
119  std::string __meta_plugin_prefix;
120 
121 #ifdef HAVE_INOTIFY
122  FamThread *__fam_thread;
123 #else
124  void *__fam_thread;
125 #endif
126 };
127 
128 } // end namespace fawkes
129 
130 #endif
~PluginManager()
Destructor.
Definition: manager.cpp:124
void set_module_flags(Module::ModuleFlags flags)
Set flags to open modules with.
Definition: manager.cpp:151
virtual void fam_event(const char *filename, unsigned int mask)
Event has been raised.
Definition: manager.cpp:484
std::list< std::pair< std::string, std::string > > get_available_plugins()
Generate list of all available plugins.
Definition: manager.cpp:213
void init_pinfo_cache()
Initialize plugin info cache.
Definition: manager.cpp:159
Fawkes library namespace.
bool try_lock()
Try to lock plugin manager.
Definition: manager.cpp:612
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:463
Thread collector.
Fawkes Plugin Manager.
Definition: manager.h:53
This class manages plugins.
Definition: loader.h:61
ModuleFlags
Flags for the loading process.
Definition: module.h:44
void lock()
Lock plugin manager.
Definition: manager.cpp:599
PluginManager listener.
Definition: listener.h:32
void add_listener(PluginManagerListener *listener)
Add listener.
Definition: manager.cpp:542
virtual void config_tag_changed(const char *new_location)
Called whenever the tag has changed.
Definition: manager.cpp:435
void load(const char *plugin_list)
Load plugin.
Definition: manager.cpp:297
List with a lock.
Definition: thread.h:40
void remove_listener(PluginManagerListener *listener)
Remove listener.
Definition: manager.cpp:555
File Alteration Monitor Listener.
Definition: fam.h:35
std::list< std::string > get_loaded_plugins()
Get list of loaded plugins.
Definition: manager.cpp:229
void unload(const char *plugin_name)
Unload plugin.
Definition: manager.cpp:375
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:88
virtual void config_value_changed(const Configuration::ValueIterator *v)
Called whenever a watched value has changed.
Definition: manager.cpp:440
virtual void config_value_erased(const char *path)
Called whenever a value has been erased from the config.
Definition: manager.cpp:468
bool is_loaded(const char *plugin_name)
Check if plugin is loaded.
Definition: manager.cpp:253
Iterator interface to iterate over config values.
Definition: config.h:68
FileAlterationMonitor thread wrapper.
Definition: fam_thread.h:35
void unlock()
Unlock plugin manager.
Definition: manager.cpp:619
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:63