Async 1.8.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
116{
117 public:
122 static Plugin* load(const std::string& path);
123
131 template <class T>
132 static T* load(const std::string& path)
133 {
134 Plugin* p = Plugin::load(path);
135 if (p == nullptr)
136 {
137 return nullptr;
138 }
139 T* plugin = dynamic_cast<T*>(p);
140 if (plugin == nullptr)
141 {
142 std::cerr << "*** ERROR: Could not load plugin \"" << path
143 << "\": Not a \"" << T::typeName() << "\" plugin"
144 << std::endl;
145 delete p;
146 }
147 return plugin;
148 }
149
150 static void unload(Plugin* p);
151
155 Plugin(void);
156
160 Plugin(const Plugin&) = delete;
161
165 Plugin& operator=(const Plugin&) = delete;
166
171 void* pluginHandle(void) const { return m_handle; }
172
180 const std::string& pluginPath(void) const { return m_plugin_path; }
181
182 protected:
186 virtual ~Plugin(void);
187
188 private:
189 typedef Plugin* (*ConstructFunc)(void);
190
191 void* m_handle = nullptr;
192 std::string m_plugin_path;
193
194 void setHandle(void* handle) { m_handle = handle; }
195
196}; /* class Plugin */
197
198
199} /* namespace Async */
200
201#endif /* ASYNC_PLUGIN_INCLUDED */
202
203/*
204 * This file has not been truncated
205 */
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.