Skip to content
Snippets Groups Projects
Commit 32b036d1 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

api plugin for registration

parent f3ba96b6
Branches
Tags
No related merge requests found
...@@ -2,7 +2,7 @@ include ../../globals.mak ...@@ -2,7 +2,7 @@ include ../../globals.mak
noinst_LTLIBRARIES = libplugin.la noinst_LTLIBRARIES = libplugin.la
noinst_HEADERS=plugin_api.h SUBDIRS=test
libplugin_la_SOURCES = \ libplugin_la_SOURCES = \
pluginmanager.cpp pluginmanager.cpp
......
#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
}
#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
#ifndef PLUGIN_API_H #ifndef PLUGIN_H
#define PLUGIN_API_H #define PLUGIN_H
#include <string> #include <string>
#include "global.h" #include "global.h"
/* /*
* @file plugin_api.h * @file plugin.h
* @brief Define a plugin object * @brief Define a plugin object
*/ */
...@@ -18,23 +18,14 @@ extern "C" { ...@@ -18,23 +18,14 @@ extern "C" {
class PluginManager; class PluginManager;
typedef struct PluginApi_Version{ class Plugin {
int version;
int revision;
}
typedef struct Register_Params{
PluginApi_Version plugin_version;
create_t create_func;
destroy_t destroy_func;
}Register_Params;
class PluginApi {
public: public:
PluginApi( const std::string &name ); Plugin( const std::string &name ){
//Plugin( const Plugin &plugin ); _name = name;
virtual ~PluginApi() {} }
virtual ~Plugin() {}
public: public:
/** /**
...@@ -43,23 +34,21 @@ extern "C" { ...@@ -43,23 +34,21 @@ extern "C" {
*/ */
virtual int getCoreVersion() const = 0; virtual int getCoreVersion() const = 0;
/**
* Register the plugin to the plugin manager
*/
virtual void registerPlugin( PluginManager & ) = 0;
private: private:
PluginApi &operator =(const PluginApi &plugin); Plugin &operator =(const Plugin &plugin);
std::string _name;
}; };
typedef Plugin* create_t( void* ); typedef Plugin* createFunc( void* );
typedef int destroy_t( Plugin* );
typedef void destroyFunc( Plugin* );
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif //PLUGIN_API_H #endif //PLUGIN_H
...@@ -48,7 +48,7 @@ int ::sflphone::PluginManager::loadPlugins( const std::string &path ) ...@@ -48,7 +48,7 @@ int ::sflphone::PluginManager::loadPlugins( const std::string &path )
return result; 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; if(_loadedPlugins.empty()) return NULL;
......
...@@ -6,14 +6,23 @@ ...@@ -6,14 +6,23 @@
* @brief Base class of the plugin manager * @brief Base class of the plugin manager
*/ */
#include "plugin.h" #include "plugin_api.h"
#include "global.h" #include "global.h"
#include <map> #include <map>
#include <string> #include <string>
namespace sflphone { namespace sflphone {
typedef struct {
Plugin *plugin;
createFunc *create_func;
destroyFunc *destroy_func;
std::string name;
} PluginWrap;
class PluginManager { class PluginManager {
public: public:
...@@ -44,7 +53,9 @@ namespace sflphone { ...@@ -44,7 +53,9 @@ namespace sflphone {
* @param name The name of the plugin looked for * @param name The name of the plugin looked for
* @return Plugin* The pointer on the plugin or NULL if not found * @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: private:
/** /**
...@@ -61,7 +72,7 @@ namespace sflphone { ...@@ -61,7 +72,7 @@ namespace sflphone {
void unloadDynamicLibrary( void * pluginHandlePtr ); void unloadDynamicLibrary( void * pluginHandlePtr );
/* Map of plugins associated by their string name */ /* 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; pluginMap _loadedPlugins;
/* The unique static instance */ /* The unique static instance */
......
...@@ -8,14 +8,12 @@ INSTALL_PLUGIN_RULE = install-libplugintest_so ...@@ -8,14 +8,12 @@ INSTALL_PLUGIN_RULE = install-libplugintest_so
noinst_PROGRAMS = libplugintest.so noinst_PROGRAMS = libplugintest.so
noinst_HEADERS = plugin_api.h
install-exec-local: install-libplugintest_so install-exec-local: install-libplugintest_so
uninstall-local: uninstall-libplugintest_so uninstall-local: uninstall-libplugintest_so
install-libplugintest_so: libplugintest.so install-libplugintest_so: libplugintest.so
mkdir -p $(sflpluginsdir) mkdir -p $(sflplugindir)
$(INSTALL_PROGRAM) libplugintest.so $(sflpluginsdir) $(INSTALL_PROGRAM) libplugintest.so $(sflplugindir)
uninstall-libplugintest_so: uninstall-libplugintest_so:
rm -f $(sflpluginsdir)/libplugintest.so rm -f $(sflplugindir)/libplugintest.so
#include "../plugin_api.h" #include "../plugin_api.h"
namespace sflphone {
class PluginTest : public Plugin { class PluginTest : public Plugin {
public: public:
PluginTest():Plugin(){ PluginTest( const std::string &name ):Plugin( name ){
}
virtual int getCoreVersion() const{
return 1;
} }
}; };
extern "C" Plugin* create_t( void * ){ }
return new PluginTest(); 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; delete p;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment