Open Lighting Architecture  Latest Git
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 
54  virtual std::string PreferenceConfigLocation() const = 0;
55 
60  virtual bool IsEnabled() const = 0;
61 
67  virtual void SetEnabledState(bool enable) = 0;
68 
75  virtual bool Start() = 0;
76 
83  virtual bool Stop() = 0;
84 
89  virtual ola_plugin_id Id() const = 0;
90 
95  virtual std::string Name() const = 0;
96 
101  virtual std::string Description() const = 0;
102 
103  virtual void ConflictsWith(std::set<ola_plugin_id> *conflict_set) const = 0;
104 
105  // used to sort plugins
106  virtual bool operator<(const AbstractPlugin &other) const = 0;
107 };
108 
109 
110 struct PluginLessThan: public std::binary_function<AbstractPlugin*,
111  AbstractPlugin*, bool> {
112  bool operator()(AbstractPlugin *x, AbstractPlugin *y) {
113  return x->Id() < y->Id();
114  }
115 };
116 
117 
118 class Plugin: public AbstractPlugin {
119  public :
120  explicit Plugin(PluginAdaptor *plugin_adaptor):
121  AbstractPlugin(),
122  m_plugin_adaptor(plugin_adaptor),
123  m_preferences(NULL),
124  m_enabled(false) {
125  }
126  virtual ~Plugin() {}
127 
128  bool LoadPreferences();
129  std::string PreferenceConfigLocation() const;
130  bool IsEnabled() const;
131  void SetEnabledState(bool enable);
132  virtual bool Start();
133  virtual bool Stop();
134  // return true if this plugin is enabled by default
135  virtual bool DefaultMode() const { return true; }
136  virtual ola_plugin_id Id() const = 0;
137 
143  virtual std::string PluginPrefix() const = 0;
144 
145  // by default we don't conflict with any other plugins
146  virtual void ConflictsWith(std::set<ola_plugin_id>*) const {}
147 
148  bool operator<(const AbstractPlugin &other) const {
149  return Id() < other.Id();
150  }
151 
152  protected:
153  virtual bool StartHook() { return 0; }
154  virtual bool StopHook() { return 0; }
155 
159  virtual bool SetDefaultPreferences() { return true; }
160 
161  PluginAdaptor *m_plugin_adaptor;
162  class Preferences *m_preferences; // preferences container
163  static const char ENABLED_KEY[];
164 
165  private:
166  bool m_enabled; // are we running
167 
169 };
170 } // namespace ola
171 
172 // interface functions
173 typedef ola::AbstractPlugin* create_t(ola::PluginAdaptor *plugin_adaptor);
174 
175 #endif // INCLUDE_OLAD_PLUGIN_H_
virtual void SetEnabledState(bool enable)=0
Set the plugin&#39;s enabled state.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
Definition: Plugin.h:118
virtual bool LoadPreferences()=0
Load the preferences for a plugin and set defaults.
Definition: PluginAdaptor.h:41
Definition: Plugin.h:110
virtual bool SetDefaultPreferences()
Definition: Plugin.h:159
virtual bool Start()=0
Start the plugin.
Definition: Preferences.h:147
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual std::string PreferenceConfigLocation() const =0
The location for preferences.
virtual bool Stop()=0
Stop the plugin.
virtual std::string Description() const =0
virtual bool IsEnabled() const =0
Is the plugin enabled?
virtual ola_plugin_id Id() const =0
Get the plugin ID of this plugin.
virtual std::string Name() const =0
Get the plugin name.
Definition: Plugin.h:38