diff --git a/src/plug-in/Makefile.am b/src/plug-in/Makefile.am index 3e386fcc6e6aa1da0a4cbbd2ab4108979513d6a4..9f31ec25aec6b78929e9710cd0bdd2711331b299 100644 --- a/src/plug-in/Makefile.am +++ b/src/plug-in/Makefile.am @@ -2,7 +2,7 @@ include ../../globals.mak noinst_LTLIBRARIES = libplugin.la -noinst_HEADERS=plugin_api.h +SUBDIRS=test libplugin_la_SOURCES = \ pluginmanager.cpp diff --git a/src/plug-in/plugin.cpp b/src/plug-in/plugin.cpp deleted file mode 100644 index 495437076549dee7c9bafbdc5ca6782076400d97..0000000000000000000000000000000000000000 --- a/src/plug-in/plugin.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "plugin.h" - -::sflphone::Plugin::Plugin( const std::string &filename UNUSED ) -{ - //TODO IMPLEMENT -} - -::sflphone::Plugin::Plugin( const Plugin &plugin UNUSED ) -{ - //TODO IMPLEMENT -} - -::sflphone::Plugin::~Plugin() -{ - //TODO IMPLEMENT -} - -int ::sflphone::Plugin::getCoreVersion( void ) const -{ - //TODO IMPLEMENT - return 1; -} - -void ::sflphone::Plugin::registerPlugin( PluginManager & ) -{ - //TODO IMPLEMENT -} diff --git a/src/plug-in/plugin.h b/src/plug-in/plugin.h deleted file mode 100644 index 100d6ea5b40bc618e3e6cae9c4435b9b192af676..0000000000000000000000000000000000000000 --- a/src/plug-in/plugin.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef PLUGIN_H -#define PLUGIN_H - -#include <string> - -#include "global.h" - -/* - * @file plugin.h - * @brief Define a plugin object - */ - -namespace sflphone { - -class PluginManager; - - class Plugin { - - public: - Plugin( const std::string &name ); - //Plugin( const Plugin &plugin ); - virtual ~Plugin() {} - - public: - /** - * Return the minimal core version required so that the plugin could work - * @return int The version required - */ - virtual int getCoreVersion() const = 0; - - /** - * Register the plugin to the plugin manager - */ - virtual void registerPlugin( PluginManager & ) = 0; - - private: - Plugin &operator =(const Plugin &plugin); - - }; -} - -#endif //PLUGIN_H - diff --git a/src/plug-in/plugin_api.h b/src/plug-in/plugin_api.h index 66f078b5cb02dbbd655b9370e05fe0e096215749..72221545920fea833a7480b3427ccc080016681c 100644 --- a/src/plug-in/plugin_api.h +++ b/src/plug-in/plugin_api.h @@ -1,12 +1,12 @@ -#ifndef PLUGIN_API_H -#define PLUGIN_API_H +#ifndef PLUGIN_H +#define PLUGIN_H #include <string> #include "global.h" /* - * @file plugin_api.h + * @file plugin.h * @brief Define a plugin object */ @@ -18,23 +18,14 @@ extern "C" { class PluginManager; - typedef struct PluginApi_Version{ - int version; - int revision; - } - - typedef struct Register_Params{ - PluginApi_Version plugin_version; - create_t create_func; - destroy_t destroy_func; - }Register_Params; - - class PluginApi { + class Plugin { public: - PluginApi( const std::string &name ); - //Plugin( const Plugin &plugin ); - virtual ~PluginApi() {} + Plugin( const std::string &name ){ + _name = name; + } + + virtual ~Plugin() {} public: /** @@ -43,23 +34,21 @@ extern "C" { */ virtual int getCoreVersion() const = 0; - /** - * Register the plugin to the plugin manager - */ - virtual void registerPlugin( PluginManager & ) = 0; - private: - PluginApi &operator =(const PluginApi &plugin); + Plugin &operator =(const Plugin &plugin); + std::string _name; }; + + typedef Plugin* createFunc( void* ); + + typedef void destroyFunc( Plugin* ); - typedef Plugin* create_t( void* ); - typedef int destroy_t( Plugin* ); } #ifdef __cplusplus } #endif -#endif //PLUGIN_API_H +#endif //PLUGIN_H diff --git a/src/plug-in/pluginmanager.cpp b/src/plug-in/pluginmanager.cpp index 6012a59bde292396b2f70fdce8d0a1d458ef8aa7..54f757216e12a79c356ab8464259a3b837a12541 100644 --- a/src/plug-in/pluginmanager.cpp +++ b/src/plug-in/pluginmanager.cpp @@ -48,7 +48,7 @@ int ::sflphone::PluginManager::loadPlugins( const std::string &path ) return result; } -::sflphone::Plugin* ::sflphone::PluginManager::isPluginLoaded( const std::string &name ) +::sflphone::PluginWrap* ::sflphone::PluginManager::isPluginLoaded( const std::string &name ) { if(_loadedPlugins.empty()) return NULL; diff --git a/src/plug-in/pluginmanager.h b/src/plug-in/pluginmanager.h index 651a0902f8e0db872052a2b0c234c66866ee92f1..5330b8764fd0cb080e13937d69a7041d247074f8 100644 --- a/src/plug-in/pluginmanager.h +++ b/src/plug-in/pluginmanager.h @@ -6,14 +6,23 @@ * @brief Base class of the plugin manager */ -#include "plugin.h" +#include "plugin_api.h" #include "global.h" #include <map> #include <string> + namespace sflphone { + typedef struct { + Plugin *plugin; + createFunc *create_func; + destroyFunc *destroy_func; + std::string name; + } PluginWrap; + + class PluginManager { public: @@ -44,7 +53,9 @@ namespace sflphone { * @param name The name of the plugin looked for * @return Plugin* The pointer on the plugin or NULL if not found */ - Plugin* isPluginLoaded( const std::string &name ); + PluginWrap* isPluginLoaded( const std::string &name ); + + int initPlugins( void ); private: /** @@ -61,7 +72,7 @@ namespace sflphone { void unloadDynamicLibrary( void * pluginHandlePtr ); /* Map of plugins associated by their string name */ - typedef std::map<std::string, ::sflphone::Plugin*> pluginMap; + typedef std::map<std::string, ::sflphone::PluginWrap*> pluginMap; pluginMap _loadedPlugins; /* The unique static instance */ diff --git a/src/plug-in/test/Makefile.am b/src/plug-in/test/Makefile.am index f52231a05acf7593b76ab730f5838cef2c3fb728..6809be2c0a185e16f72edcef1b57103fbcbea8f8 100644 --- a/src/plug-in/test/Makefile.am +++ b/src/plug-in/test/Makefile.am @@ -8,14 +8,12 @@ INSTALL_PLUGIN_RULE = install-libplugintest_so noinst_PROGRAMS = libplugintest.so -noinst_HEADERS = plugin_api.h - install-exec-local: install-libplugintest_so uninstall-local: uninstall-libplugintest_so install-libplugintest_so: libplugintest.so - mkdir -p $(sflpluginsdir) - $(INSTALL_PROGRAM) libplugintest.so $(sflpluginsdir) + mkdir -p $(sflplugindir) + $(INSTALL_PROGRAM) libplugintest.so $(sflplugindir) uninstall-libplugintest_so: - rm -f $(sflpluginsdir)/libplugintest.so + rm -f $(sflplugindir)/libplugintest.so diff --git a/src/plug-in/test/pluginTest.cpp b/src/plug-in/test/pluginTest.cpp index 2e467dbe1babdff773d46d4adff4a041d37cd2fa..6249a886fae85e2028f3f105b32c6fbfd95d59e8 100644 --- a/src/plug-in/test/pluginTest.cpp +++ b/src/plug-in/test/pluginTest.cpp @@ -1,15 +1,22 @@ #include "../plugin_api.h" -class PluginTest : public Plugin { - public: - PluginTest():Plugin(){ - } -}; - -extern "C" Plugin* create_t( void * ){ - return new PluginTest(); +namespace sflphone { + + class PluginTest : public Plugin { + public: + PluginTest( const std::string &name ):Plugin( name ){ + } + + virtual int getCoreVersion() const{ + return 1; + } + }; + +} +extern "C" ::sflphone::Plugin* create_t( void * ){ + return new ::sflphone::PluginTest("test"); } -extern "C" void* destroy_t( Plugin *p ){ +extern "C" void* destroy_t( ::sflphone::Plugin *p ){ delete p; }