Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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
31namespace ola {
32
33class PluginAdaptor;
34
39 public :
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
110struct 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
118class Plugin: public AbstractPlugin {
119 public :
120 explicit Plugin(PluginAdaptor *plugin_adaptor):
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
168 Plugin(const Plugin &) = delete;
169 const Plugin &operator=(const Plugin &) = delete;
170};
171} // namespace ola
172
173// interface functions
174typedef ola::AbstractPlugin* create_t(ola::PluginAdaptor *plugin_adaptor);
175
176#endif // INCLUDE_OLAD_PLUGIN_H_
Helper macros.
Definition Plugin.h:38
virtual bool LoadPreferences()=0
Load the preferences for a plugin and set defaults.
virtual void SetEnabledState(bool enable)=0
Set the plugin's enabled state.
virtual bool Start()=0
Start the plugin.
virtual std::string Description() const =0
virtual std::string PreferenceConfigLocation() const =0
The location for preferences.
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.
virtual bool Stop()=0
Stop the plugin.
Definition PluginAdaptor.h:41
Definition Plugin.h:118
bool LoadPreferences()
Load the preferences for a plugin and set defaults.
Definition Plugin.cpp:33
virtual bool Stop()
Stop the plugin.
Definition Plugin.cpp:99
virtual bool Start()
Start the plugin.
Definition Plugin.cpp:79
virtual ola_plugin_id Id() const =0
Get the plugin ID of this plugin.
virtual bool SetDefaultPreferences()
Definition Plugin.h:159
bool IsEnabled() const
Is the plugin enabled?
Definition Plugin.cpp:70
void SetEnabledState(bool enable)
Set the plugin's enabled state.
Definition Plugin.cpp:74
virtual std::string PluginPrefix() const =0
The prefix to use for storing configuration files.
std::string PreferenceConfigLocation() const
The location for preferences.
Definition Plugin.cpp:66
Definition Preferences.h:148
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
Definition Plugin.h:111