Async 1.7.0
AsyncPlugin.h
Go to the documentation of this file.
1
31#ifndef ASYNC_PLUGIN_INCLUDED
32#define ASYNC_PLUGIN_INCLUDED
33
34
35/****************************************************************************
36 *
37 * System Includes
38 *
39 ****************************************************************************/
40
41#include <string>
42
43
44/****************************************************************************
45 *
46 * Project Includes
47 *
48 ****************************************************************************/
49
50
51
52/****************************************************************************
53 *
54 * Local Includes
55 *
56 ****************************************************************************/
57
58
59
60/****************************************************************************
61 *
62 * Forward declarations
63 *
64 ****************************************************************************/
65
66
67
68/****************************************************************************
69 *
70 * Namespace
71 *
72 ****************************************************************************/
73
74namespace Async
75{
76
77
78/****************************************************************************
79 *
80 * Forward declarations of classes inside of the declared namespace
81 *
82 ****************************************************************************/
83
84
85
86/****************************************************************************
87 *
88 * Defines & typedefs
89 *
90 ****************************************************************************/
91
92
93
94/****************************************************************************
95 *
96 * Exported Global Variables
97 *
98 ****************************************************************************/
99
100
101
102/****************************************************************************
103 *
104 * Class definitions
105 *
106 ****************************************************************************/
107
109{
110};
111
121class Plugin : public PluginBase
122{
123 public:
128 static Plugin* load(const std::string& path);
129
137 template <class T>
138 static T* load(const std::string& path)
139 {
140 Plugin* p = Plugin::load(path);
141 if (p == nullptr)
142 {
143 return nullptr;
144 }
145 T* demop = dynamic_cast<T*>(p);
146 if (demop == nullptr)
147 {
148 std::cerr << "*** ERROR: Could not load plugin \"" << path
149 << "\": Not a \"" << T::typeName() << "\" plugin"
150 << std::endl;
151 delete p;
152 }
153 return demop;
154 }
155
156 static void unload(Plugin* p);
157
161 Plugin(void);
162
166 Plugin(const Plugin&) = delete;
167
171 Plugin& operator=(const Plugin&) = delete;
172
177 void* pluginHandle(void) const { return m_handle; }
178
186 const std::string& pluginPath(void) const { return m_plugin_path; }
187
188 protected:
192 virtual ~Plugin(void);
193
194 private:
195 typedef Plugin* (*ConstructFunc)(void);
196
197 void* m_handle = nullptr;
198 std::string m_plugin_path;
199
200 void setHandle(void* handle) { m_handle = handle; }
201
202}; /* class Plugin */
203
204
205} /* namespace Async */
206
207#endif /* ASYNC_PLUGIN_INCLUDED */
208
209/*
210 * This file has not been truncated
211 */
A base class for making a class into a dynamic loadable plugin.
static void unload(Plugin *p)
Plugin(const Plugin &)=delete
Disallow copy construction.
virtual ~Plugin(void)
Destructor.
static T * load(const std::string &path)
Load the plugin from the specified path returning correct type.
Plugin(void)
Default constructor.
void * pluginHandle(void) const
Retrieve the handle returned from the dlopen function.
const std::string & pluginPath(void) const
Retrieve the path used to find the plugin.
Plugin & operator=(const Plugin &)=delete
Disallow copy assignment.
static Plugin * load(const std::string &path)
Load the plugin from the specified path.
Namespace for the asynchronous programming classes.