plugin.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
24 #ifndef PLUGIN_H
25 #define PLUGIN_H
26 
27 #include "typedefs.h"
29 #include "linked_list.h"
30 #include "memory_allocations.h"
31 #include "grassroots_server.h"
32 
33 
34 #ifdef __cplusplus
35  extern "C" {
36 #endif
37 
38 
39 /*********** FORWARD DECLARATION ****************/
40 struct ServicesArray;
41 struct Client;
42 struct Handler;
43 struct JobsManager;
44 
45 
51 typedef enum PluginStatus
52 {
55 
58 
61 
64 
65 } PluginStatus;
66 
67 
73 typedef enum PluginNature
74 {
76  PN_UNKNOWN = -1,
77 
80 
83 
86 
89 
92 
95 } PluginNature;
96 
97 
102 typedef union PluginValue
103 {
109 
114  struct Client *pv_client_p;
115 
121 
122 
128 
129 
135 
136 } PluginValue;
137 
138 
139 
140 
151 typedef struct Plugin
152 {
156  char *pl_path_s;
157 
163 
167  char *pl_name_s;
168 
173 
178 
183 
188 
189 
190  GrassrootsServer *pl_server_p;
191 } Plugin;
192 
193 
194 
203 typedef struct PluginListNode
204 {
207 
210 
214 
215 
216 /***********************************/
217 /********** API METHODS **********/
218 /***********************************/
219 
220 
221 
232 GRASSROOTS_SERVICE_MANAGER_API const char *GetPluginConfigName (const Plugin * const plugin_p);
233 
246 GRASSROOTS_SERVICE_MANAGER_API Plugin *AllocatePlugin (const char * const path_s, GrassrootsServer *server_p);
247 
248 
256 GRASSROOTS_SERVICE_MANAGER_API void FreePlugin (Plugin * const plugin_p);
257 
258 
272 GRASSROOTS_SERVICE_MANAGER_API bool OpenPlugin (Plugin * const plugin_p);
273 
274 
284 GRASSROOTS_SERVICE_MANAGER_API void ClosePlugin (Plugin * const plugin_p);
285 
286 
297 GRASSROOTS_SERVICE_MANAGER_API void *GetSymbolFromPlugin (Plugin *plugin_p, const char * const symbol_s);
298 
299 
307 GRASSROOTS_SERVICE_MANAGER_API PluginListNode *AllocatePluginListNode (Plugin * const plugin_p);
308 
309 
316 GRASSROOTS_SERVICE_MANAGER_API void FreePluginListNode (ListItem * const node_p);
317 
318 
332 GRASSROOTS_SERVICE_MANAGER_API char *DeterminePluginName (const char * const full_plugin_path_s);
333 
334 
345 GRASSROOTS_SERVICE_MANAGER_API char *MakePluginName (const char * const name_s);
346 
347 
348 
355 GRASSROOTS_SERVICE_MANAGER_API void IncrementPluginOpenCount (Plugin *plugin_p);
356 
357 
365 GRASSROOTS_SERVICE_MANAGER_API void DecrementPluginOpenCount (Plugin *plugin_p);
366 
367 
374 GRASSROOTS_SERVICE_MANAGER_API void ClearPluginValue (Plugin * const plugin_p);
375 
376 
377 /***********************************/
378 /********* LOCAL METHODS *********/
379 /***********************************/
380 
381 
382 GRASSROOTS_SERVICE_MANAGER_LOCAL bool InitBasePlugin (Plugin * const plugin_p, const char * const path_p, GrassrootsServer *server_p);
383 
384 GRASSROOTS_SERVICE_MANAGER_LOCAL void ClearBasePlugin (Plugin * const plugin_p);
385 
386 
387 GRASSROOTS_SERVICE_MANAGER_LOCAL void ClearPluginPath (Plugin * const plugin_p);
388 
389 
390 #ifdef __cplusplus
391 }
392 #endif
393 
394 #endif /* #ifndef PLUGIN_H */
void * GetSymbolFromPlugin(Plugin *plugin_p, const char *const symbol_s)
Get a symbol from a Plugin.
void FreePlugin(Plugin *const plugin_p)
Free a Plugin.
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43
The Plugin creates a ServersManager.
Definition: plugin.h:91
The Plugin creates a Handler.
Definition: plugin.h:85
No attempt to load a plugin of this type yet.
Definition: plugin.h:54
PluginStatus
The current status of a Plugin.
Definition: plugin.h:51
Plugin * pln_plugin_p
The plugin.
Definition: plugin.h:209
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:36
PluginValue pl_value
The data specific for the PluginNature of this Plugin.
Definition: plugin.h:182
The Plugin creates a JobsManager.
Definition: plugin.h:88
char * pl_path_s
The path of the plugin.
Definition: plugin.h:156
struct ServersManager * pv_servers_manager_p
If pl_type is PN_SERVERS_MANAGER then this will point to a valid JobsManager.
Definition: plugin.h:134
A union datatype that abstracts the different types of plugins that are avaialble.
Definition: plugin.h:102
A doubly-linked list.
void DecrementPluginOpenCount(Plugin *plugin_p)
Decrement the number of objects that this Plugin has open.
Plugin is in the process of closing.
Definition: plugin.h:63
Plugin * AllocatePlugin(const char *const path_s, GrassrootsServer *server_p)
The following functions are platform-specific.
The number of different PluginTypes.
Definition: plugin.h:94
struct ServicesArray * pv_services_p
If pl_type is PN_SERVICE then this will point to a ServicesArray of Services available.
Definition: plugin.h:108
A Plugin is a dynamically-loaded component to provide a piece of functionality.
Definition: plugin.h:151
A ListNode for LinkedLists that also stores a plugin value.
Definition: plugin.h:203
MEM_FLAG pln_plugin_flag
How the memory for the Plugin is stored and freed.
Definition: plugin.h:212
void FreePluginListNode(ListItem *const node_p)
Free a PluginListNode.
The Plugin creates a Client.
Definition: plugin.h:82
const char * GetPluginConfigName(const Plugin *const plugin_p)
Get the string with the platform-specific plugin parts e.g.
struct JobsManager * pv_jobs_manager_p
If pl_type is PN_JOBS_MANAGER then this will point to a valid JobsManager.
Definition: plugin.h:127
PluginNature pl_type
The type of this Plugin e.g.
Definition: plugin.h:177
PluginListNode * AllocatePluginListNode(Plugin *const plugin_p)
Create a new PluginListNode.
The Plugin creates a Service.
Definition: plugin.h:79
struct Handler * pv_handler_p
If pl_type is PN_HANDLER then this will point to a valid Handler.
Definition: plugin.h:120
char * DeterminePluginName(const char *const full_plugin_path_s)
Get the platform-independent Plugin name from a platform-specific filename possibly spanning multiple...
void ClearPluginValue(Plugin *const plugin_p)
Clear all values in a given Plugin ready for it to be reused.
A datatype for monitoring ServiceJobs.
Definition: jobs_manager.h:99
int32 pl_open_count
The count of how many current tasks have this Plugin open.
Definition: plugin.h:187
A datatype for having a set of Services.
Definition: service.h:408
void IncrementPluginOpenCount(Plugin *plugin_p)
Increment the number of objects that this Plugin has open.
ListItem pln_node
The ListNode.
Definition: plugin.h:206
Unknown type of Plugin.
Definition: plugin.h:76
char * pl_name_s
A multi-platform name for the Plugin.
Definition: plugin.h:167
PluginStatus pl_status
The current status of the Plugin.
Definition: plugin.h:172
MEM_FLAG pl_path_mem
Memory ownership of the path variable.
Definition: plugin.h:162
Plugin of this type failed to previously load.
Definition: plugin.h:60
struct Client * pv_client_p
If pl_type is PN_CLIENT then this will point to a valid Client.
Definition: plugin.h:114
Definition: grassroots_server.h:44
A Handler is a datatype for accessing data.
Definition: handler.h:72
Plugin of this type has been loaded successfully.
Definition: plugin.h:57
char * MakePluginName(const char *const name_s)
Make the platform-specific filename for a given Plugin name.
bool OpenPlugin(Plugin *const plugin_p)
Open a Plugin in preparation for getting the actual component.
PluginNature
The type of module that the Plugin contains.
Definition: plugin.h:73
A datatype for monitoring ExternalServers.
Definition: servers_manager.h:141
void ClosePlugin(Plugin *const plugin_p)
Close a Plugin.