From 32b036d1c3b375447c9918f2b9e30b4606569380 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <manu@manu-eeepc.(none)> Date: Tue, 27 Jan 2009 20:18:31 -0500 Subject: [PATCH] api plugin for registration --- src/plug-in/Makefile.am | 2 +- src/plug-in/plugin.cpp | 27 --------------------- src/plug-in/plugin.h | 43 --------------------------------- src/plug-in/plugin_api.h | 43 ++++++++++++--------------------- src/plug-in/pluginmanager.cpp | 2 +- src/plug-in/pluginmanager.h | 17 ++++++++++--- src/plug-in/test/Makefile.am | 8 +++--- src/plug-in/test/pluginTest.cpp | 25 ++++++++++++------- 8 files changed, 51 insertions(+), 116 deletions(-) delete mode 100644 src/plug-in/plugin.cpp delete mode 100644 src/plug-in/plugin.h diff --git a/src/plug-in/Makefile.am b/src/plug-in/Makefile.am index 3e386fcc6e..9f31ec25ae 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 4954370765..0000000000 --- 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 100d6ea5b4..0000000000 --- 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 66f078b5cb..7222154592 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 6012a59bde..54f757216e 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 651a0902f8..5330b8764f 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 f52231a05a..6809be2c0a 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 2e467dbe1b..6249a886fa 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; } -- GitLab