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

Merge branch 'plug-in' of ssh://manu@192.168.1.105/~manu/dev/sflphone into plugins

Conflicts:

	src/plug-in/plugininterface.h
	src/plug-in/test/pluginTest.cpp
	test/pluginmanagerTest.cpp
parents 4a1abced 3cc24f26
Branches
Tags
No related merge requests found
#ifndef PLUGIN_INTERFACE_H
#define PLUGIN_INTERFACE_H
#include <string>
#include "global.h"
#include "plugin.h"
/*
* @file plugininterface.h
* @brief Define a plugin object
*/
namespace sflphone {
class Plugin;
class PluginInterface {
public:
PluginInterface( const std::string &name ){
_name = name;
}
virtual ~PluginInterface() {}
inline std::string getInterfaceName (void) { return _name; }
/**
* Return the minimal core version required so that the plugin could work
* @return int The version required
*/
virtual int initFunc () = 0;
virtual int registerFunc (Plugin **plugin) = 0;
private:
PluginInterface &operator =(const PluginInterface &plugin);
std::string _name;
};
typedef PluginInterface* createFunc (void);
typedef void destroyFunc( PluginInterface* );
}
#endif //PLUGIN_INTERFACE_H
#include "../plugininterface.h"
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "../plugin.h"
namespace sflphone {
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
class PluginTest : public PluginInterface {
public:
PluginTest( const std::string &name ):PluginInterface( name ){
}
class PluginTest : public Plugin {
virtual int initFunc (void)
{
return 0;
public:
PluginTest( const std::string &name )
:Plugin( name ) {
}
virtual int registerFunc (Plugin **plugin)
{
Plugin *ret;
virtual int initFunc (PluginInfo **info) {
ret = new Plugin(this);
ret->_name = getInterfaceName();
ret->_required = 1;
ret->_version_major=1;
ret->_version_minor=0;
(*info)->_plugin = this;
(*info)->_major_version = MAJOR_VERSION;
(*info)->_minor_version = MINOR_VERSION;
(*info)->_name = getPluginName();
*plugin = ret;
return 0;
}
};
return 0;
}
};
}
extern "C" ::sflphone::PluginInterface* create (void){
return new ::sflphone::PluginTest("test");
extern "C" Plugin* createPlugin (void){
return new PluginTest("mytest");
}
extern "C" void* destroy( ::sflphone::PluginInterface *p ){
extern "C" void destroyPlugin (Plugin *p){
delete p;
}
......@@ -19,32 +19,77 @@
#include <stdio.h>
#include <sstream>
#include <dlfcn.h>
#include "pluginmanagerTest.h"
using std::cout;
using std::endl;
#define PLUGIN_TEST_DIR "/usr/lib/sflphone/plugins/"
#define PLUGIN_TEST_DESC "mytest"
#define PLUGIN_TEST_NAME "/usr/lib/sflphone/plugins/libplugintest.so"
void PluginManagerTest::setUp(){
_pm = ::sflphone::PluginManager::instance();
// Instanciate the plugin manager singleton
_pm = PluginManager::instance();
library = 0;
plugin = 0;
}
void PluginManagerTest::testLoadDynamicLibrary(){
CPPUNIT_ASSERT(_pm->loadDynamicLibrary(PLUGIN_TEST_NAME) != NULL);
}
void PluginManagerTest::testLoadPluginDirectory(){
CPPUNIT_ASSERT(_pm->loadPlugins() == 0);
void PluginManagerTest::testUnloadDynamicLibrary(){
library = _pm->loadDynamicLibrary(PLUGIN_TEST_NAME);
CPPUNIT_ASSERT(library != NULL);
CPPUNIT_ASSERT(_pm->unloadDynamicLibrary(library) == 0 );
}
void PluginManagerTest::testLoadPlugin(){
CPPUNIT_ASSERT(_pm->loadPlugins() == 0);
//CPPUNIT_ASSERT( _pm->isPluginLoaded("test") == NULL );
void PluginManagerTest::testInstanciatePlugin(){
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
CPPUNIT_ASSERT(library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL);
}
void PluginManagerTest::testInitPlugin(){
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
CPPUNIT_ASSERT(library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (plugin!=NULL);
CPPUNIT_ASSERT (plugin->getPluginName() == PLUGIN_TEST_DESC);
}
void PluginManagerTest::testRegisterPlugin(){
// First load the default directory
_pm->loadPlugins();
// Resolve the symbol
library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
CPPUNIT_ASSERT(library != NULL);
CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false);
CPPUNIT_ASSERT (_pm->registerPlugin (plugin, library) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
}
void PluginManagerTest::testLoadPlugins (){
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
}
void PluginManagerTest::testUnloadPlugins (){
CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true);
CPPUNIT_ASSERT (_pm->unloadPlugins () == 0);
CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false);
}
void PluginManagerTest::tearDown(){
// Delete the plugin manager object
delete _pm; _pm=0;
if(plugin)
delete plugin; plugin = 0;
if(library)
delete library; library = 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment