Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plugin.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * Plugin.h
17  * Header file for plugin class - plugins inherit from this.
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLAD_PLUGIN_H_
22 #define INCLUDE_OLAD_PLUGIN_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/plugin_id.h>
26 
27 #include <set>
28 #include <string>
29 #include <functional>
30 
31 namespace ola {
32 
33 class PluginAdaptor;
34 
39  public :
40  AbstractPlugin() {}
41  virtual ~AbstractPlugin() {}
42 
46  virtual bool LoadPreferences() = 0;
47 
52  virtual std::string PreferenceSource() const = 0;
53 
58  virtual bool IsEnabled() const = 0;
59 
64  virtual bool Start() = 0;
65 
70  virtual bool Stop() = 0;
71 
76  virtual ola_plugin_id Id() const = 0;
77 
82  virtual std::string Name() const = 0;
83 
88  virtual std::string Description() const = 0;
89 
90  virtual void ConflictsWith(std::set<ola_plugin_id> *conflict_set) = 0;
91 
92  // used to sort plugins
93  virtual bool operator<(const AbstractPlugin &other) const = 0;
94 };
95 
96 
97 struct PluginLessThan: public std::binary_function<AbstractPlugin*,
98  AbstractPlugin*, bool> {
99  bool operator()(AbstractPlugin *x, AbstractPlugin *y) {
100  return x->Id() < y->Id();
101  }
102 };
103 
104 
105 class Plugin: public AbstractPlugin {
106  public :
107  explicit Plugin(PluginAdaptor *plugin_adaptor):
108  AbstractPlugin(),
109  m_plugin_adaptor(plugin_adaptor),
110  m_preferences(NULL),
111  m_enabled(false) {
112  }
113  virtual ~Plugin() {}
114 
115  bool LoadPreferences();
116  std::string PreferenceSource() const;
117  bool IsEnabled() const;
118  virtual bool Start();
119  virtual bool Stop();
120  // return true if this plugin is enabled by default
121  virtual bool DefaultMode() const { return true; }
122  virtual ola_plugin_id Id() const = 0;
123 
129  virtual std::string PluginPrefix() const = 0;
130 
131  // by default we don't conflict with any other plugins
132  virtual void ConflictsWith(std::set<ola_plugin_id>*) {}
133 
134  bool operator<(const AbstractPlugin &other) const {
135  return Id() < other.Id();
136  }
137 
138  protected:
139  virtual bool StartHook() { return 0; }
140  virtual bool StopHook() { return 0; }
141 
145  virtual bool SetDefaultPreferences() { return true; }
146 
147  PluginAdaptor *m_plugin_adaptor;
148  class Preferences *m_preferences; // preferences container
149  static const char ENABLED_KEY[];
150 
151  private:
152  bool m_enabled; // are we running
153 
155 };
156 } // namespace ola
157 
158 // interface functions
159 typedef ola::AbstractPlugin* create_t(ola::PluginAdaptor *plugin_adaptor);
160 
161 #endif // INCLUDE_OLAD_PLUGIN_H_