Open Lighting Architecture: include/olad/Plugin.h Source File

| 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
38 class AbstractPlugin {
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
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_
Macro.h
Helper macros.
ola::AbstractPlugin
Definition Plugin.h:38
ola::AbstractPlugin::LoadPreferences
virtual bool LoadPreferences()=0
Load the preferences for a plugin and set defaults.
ola::AbstractPlugin::SetEnabledState
virtual void SetEnabledState(bool enable)=0
Set the plugin's enabled state.
ola::AbstractPlugin::Start
virtual bool Start()=0
Start the plugin.
ola::AbstractPlugin::Description
virtual std::string Description() const =0
ola::AbstractPlugin::PreferenceConfigLocation
virtual std::string PreferenceConfigLocation() const =0
The location for preferences.
ola::AbstractPlugin::IsEnabled
virtual bool IsEnabled() const =0
Is the plugin enabled?
ola::AbstractPlugin::Id
virtual ola_plugin_id Id() const =0
Get the plugin ID of this plugin.
ola::AbstractPlugin::Name
virtual std::string Name() const =0
Get the plugin name.
ola::AbstractPlugin::Stop
virtual bool Stop()=0
Stop the plugin.
ola::PluginAdaptor
Definition PluginAdaptor.h:41
ola::Plugin
Definition Plugin.h:118
ola::Plugin::LoadPreferences
bool LoadPreferences()
Load the preferences for a plugin and set defaults.
Definition Plugin.cpp:33
ola::Plugin::Stop
virtual bool Stop()
Stop the plugin.
Definition Plugin.cpp:99
ola::Plugin::Start
virtual bool Start()
Start the plugin.
Definition Plugin.cpp:79
ola::Plugin::Id
virtual ola_plugin_id Id() const =0
Get the plugin ID of this plugin.
ola::Plugin::SetDefaultPreferences
virtual bool SetDefaultPreferences()
Definition Plugin.h:159
ola::Plugin::IsEnabled
bool IsEnabled() const
Is the plugin enabled?
Definition Plugin.cpp:70
ola::Plugin::SetEnabledState
void SetEnabledState(bool enable)
Set the plugin's enabled state.
Definition Plugin.cpp:74
ola::Plugin::PluginPrefix
virtual std::string PluginPrefix() const =0
The prefix to use for storing configuration files.
ola::Plugin::PreferenceConfigLocation
std::string PreferenceConfigLocation() const
The location for preferences.
Definition Plugin.cpp:66
ola::Preferences
Definition Preferences.h:148
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::PluginLessThan
Definition Plugin.h:111