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

api plugin for registration

parent f3ba96b6
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ include ../../globals.mak
noinst_LTLIBRARIES = libplugin.la
noinst_HEADERS=plugin_api.h
SUBDIRS=test
libplugin_la_SOURCES = \
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
#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* create_t( void* );
typedef int destroy_t( Plugin* );
typedef Plugin* createFunc( void* );
typedef void destroyFunc( Plugin* );
}
#ifdef __cplusplus
}
#endif
#endif //PLUGIN_API_H
#endif //PLUGIN_H
......@@ -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;
......
......@@ -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 */
......
......@@ -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
#include "../plugin_api.h"
namespace sflphone {
class PluginTest : public Plugin {
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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment