857bb2d9dc5333a63144b952bde4004b345c1263
[strongswan.git] / src / libstrongswan / plugins / plugin_loader.h
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Copyright (C) 2007 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup plugin_loader plugin_loader
19 * @{ @ingroup plugins
20 */
21
22 #ifndef PLUGIN_LOADER_H_
23 #define PLUGIN_LOADER_H_
24
25 typedef struct plugin_loader_t plugin_loader_t;
26
27 #include <collections/enumerator.h>
28
29 /* to avoid circular references we can't include plugin_feature.h */
30 struct plugin_feature_t;
31
32 /**
33 * The plugin_loader loads plugins from a directory and initializes them
34 */
35 struct plugin_loader_t {
36
37 /**
38 * Add static plugin features, not loaded via plugins.
39 *
40 * Similar to features provided by plugins they are evaluated during load(),
41 * and unloaded when unload() is called.
42 *
43 * If critical is TRUE load() will fail if any of the added features could
44 * not be loaded.
45 *
46 * @note The name should be unique otherwise a plugin with the same name is
47 * not loaded.
48 *
49 * @param name name of the component adding the features
50 * @param features array of plugin features
51 * @param count number of features in the array
52 * @param critical TRUE if the features are critical
53 */
54 void (*add_static_features) (plugin_loader_t *this, const char *name,
55 struct plugin_feature_t *features, int count,
56 bool critical);
57
58 /**
59 * Load a list of plugins from a directory.
60 *
61 * Each plugin in list may have a ending exclamation mark (!) to mark it
62 * as a critical plugin. If loading a critical plugin fails, plugin loading
63 * is aborted and FALSE is returned.
64 *
65 * @param path path containing loadable plugins, NULL for default
66 * @param list space separated list of plugins to load
67 * @return TRUE if all critical plugins loaded successfully
68 */
69 bool (*load)(plugin_loader_t *this, char *path, char *list);
70
71 /**
72 * Reload the configuration of one or multiple plugins.
73 *
74 * @param space separated plugin names to reload, NULL for all
75 * @return number of plugins that did support reloading
76 */
77 u_int (*reload)(plugin_loader_t *this, char *list);
78
79 /**
80 * Unload all loaded plugins.
81 */
82 void (*unload)(plugin_loader_t *this);
83
84 /**
85 * Create an enumerator over all loaded plugins.
86 *
87 * In addition to the plugin, the enumerator optionally provides a list of
88 * pointers to plugin features currently loaded.
89 * This list has to be destroyed.
90 *
91 * @return enumerator over plugin_t*, linked_list_t*
92 */
93 enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
94
95 /**
96 * Get a simple list the names of all loaded plugins.
97 *
98 * The function returns internal data, do not free.
99 *
100 * @return list of the names of all loaded plugins
101 */
102 char* (*loaded_plugins)(plugin_loader_t *this);
103
104 /**
105 * Unload loaded plugins, destroy plugin_loader instance.
106 */
107 void (*destroy)(plugin_loader_t *this);
108 };
109
110 /**
111 * Create a plugin_loader instance.
112 *
113 * @return plugin loader instance
114 */
115 plugin_loader_t *plugin_loader_create();
116
117 #endif /** PLUGIN_LOADER_H_ @}*/