24 #include <utils/system/dynamic_module/module_dl.h> 25 #include <utils/system/dynamic_module/module_manager_template.h> 26 #include <core/plugin.h> 27 #include <plugin/loader.h> 41 cout <<
"Plugin name: " << p->
name() << endl;
57 cout <<
"Doh, symbol not found" << endl;
60 cout <<
"Yeah, we got the symbol" << endl;
62 PluginFactoryFunc pff = (PluginFactoryFunc)m->
get_symbol(
"plugin_factory");
63 PluginDestroyFunc pdf = (PluginDestroyFunc)m->
get_symbol(
"plugin_destroy");
65 if ( (pff != NULL) && (pdf != NULL) ) {
68 success = test_plugin(p);
76 cout <<
"pff == NULL" << endl;
79 cout <<
"pdf == NULL" << endl;
84 cout <<
"Could not open module" << endl;
99 main(
int argc,
char **argv)
105 cout <<
"Running plain module tests" << endl;
106 ModuleDL *m =
new ModuleDL(PLUGINDIR
"/test_splugin.so");
113 success = test_module(m);
117 cout <<
"SUCCESSFULLY tested plain module" << endl;
119 cout <<
"FAILED plain module tests, aborting further tests" << endl;
124 cout << endl << endl <<
"Running ModuleManagerTemplate tests" << endl;
125 ModuleManagerTemplate<ModuleDL> mm(PLUGINDIR);
126 Module *mod = mm.open_module(
"test_plugin.so");
128 cout <<
"Failed to retrieve module from manager" << endl;
131 cout <<
"Retrieved module from module manager" << endl;
134 success = test_module(mod);
136 cout <<
"Testing ref count" << endl;
137 cout <<
"RefCount (should be 1): " << mod->
get_ref_count() << endl;
138 cout <<
"Retrieving module twice, again" << endl;
139 mm.open_module(
"test_plugin.so");
140 mm.open_module(
"test_plugin.so");
141 cout <<
"RefCount (should be 3): " << mod->
get_ref_count() << endl;
142 cout <<
"Closing module twice" << endl;
143 mm.close_module(mod);
144 mm.close_module(mod);
145 cout <<
"RefCount (should be 1): " << mod->
get_ref_count() << endl;
146 cout <<
"Finally closing module" << endl;
147 mm.close_module(mod);
148 if ( mm.module_opened(
"test_plugin.so") ) {
149 cout <<
"Plugin still opened, bug!" << endl;
152 cout <<
"Plugin has been unloaded from module manager" << endl;
157 cout <<
"SUCCESSFULLY tested module manager" << endl;
159 cout <<
"FAILED module manager tests, aborting further tests" << endl;
165 cout << endl << endl <<
"Running PluginLoader tests" << endl;
170 p = pl->
load(
"test_plugin");
171 success = test_plugin(p);
175 cout <<
"Could not load plugin" << endl;
182 cout <<
"SUCCESSFULLY tested PluginLoader" << endl;
184 cout <<
"FAILED module manager tests, aborting further tests" << endl;
Fawkes library namespace.
This exception is thrown if the requested plugin could not be loaded.
virtual unsigned int get_ref_count()
Get the reference count of this module.
const char * name() const
Get the name of the plugin.
This class manages plugins.
void unload(Plugin *plugin)
Unload the given plugin This will unload the given plugin.
Dynamic module loader for Linux, FreeBSD, and MacOS X.
Base class for exceptions in Fawkes.
void print_trace()
Prints trace to stderr.
virtual void * get_symbol(const char *symbol_name)
Get a symbol from the module.
virtual bool has_symbol(const char *symbol_name)
Check if the module has the given symbol.
Plugin * load(const char *plugin_name)
Load a specific plugin The plugin loader is clever and guarantees that every plugin is only loaded on...