Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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,
61  Module::ModuleFlags module_flags = Module::MODULE_FLAGS_DEFAULT,
62  bool init_cache = true);
63  ~PluginManager();
64 
65  void set_module_flags(Module::ModuleFlags flags);
66  void init_pinfo_cache();
67 
68  // for ConfigurationChangeHandler
69  virtual void config_tag_changed(const char *new_location);
70  virtual void config_value_changed(const Configuration::ValueIterator *v);
71  virtual void config_comment_changed(const Configuration::ValueIterator *v);
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
Interface for configuration change handling.
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
PluginManager listener.
Definition: listener.h:32
List with a lock.
Definition: thread.h:40
File Alteration Monitor Listener.
Definition: fam.h:35
Iterator interface to iterate over config values.
Definition: config.h:68
FileAlterationMonitor thread wrapper.
Definition: fam_thread.h:35
Mutex mutual exclusion lock.
Definition: mutex.h:32
Interface for configuration handling.
Definition: config.h:63