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" #include "../plugin.h"
namespace sflphone { #define MAJOR_VERSION 1
#define MINOR_VERSION 0
class PluginTest : public PluginInterface { class PluginTest : public Plugin {
public:
PluginTest( const std::string &name ):PluginInterface( name ){
}
virtual int initFunc (void) public:
{ PluginTest( const std::string &name )
return 0; :Plugin( name ) {
} }
virtual int registerFunc (Plugin **plugin) virtual int initFunc (PluginInfo **info) {
{
Plugin *ret;
ret = new Plugin(this); (*info)->_plugin = this;
(*info)->_major_version = MAJOR_VERSION;
ret->_name = getInterfaceName(); (*info)->_minor_version = MINOR_VERSION;
ret->_required = 1; (*info)->_name = getPluginName();
ret->_version_major=1;
ret->_version_minor=0;
*plugin = ret; return 0;
return 0; }
} };
};
} extern "C" Plugin* createPlugin (void){
extern "C" ::sflphone::PluginInterface* create (void){ return new PluginTest("mytest");
return new ::sflphone::PluginTest("test");
} }
extern "C" void* destroy( ::sflphone::PluginInterface *p ){ extern "C" void destroyPlugin (Plugin *p){
delete p; delete p;
} }
...@@ -19,32 +19,77 @@ ...@@ -19,32 +19,77 @@
#include <stdio.h> #include <stdio.h>
#include <sstream> #include <sstream>
#include <dlfcn.h>
#include "pluginmanagerTest.h" #include "pluginmanagerTest.h"
using std::cout; using std::cout;
using std::endl; 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(){ 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(){ void PluginManagerTest::testUnloadDynamicLibrary(){
CPPUNIT_ASSERT(_pm->loadPlugins() == 0); library = _pm->loadDynamicLibrary(PLUGIN_TEST_NAME);
CPPUNIT_ASSERT(library != NULL);
CPPUNIT_ASSERT(_pm->unloadDynamicLibrary(library) == 0 );
} }
void PluginManagerTest::testLoadPlugin(){ void PluginManagerTest::testInstanciatePlugin(){
CPPUNIT_ASSERT(_pm->loadPlugins() == 0); library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
//CPPUNIT_ASSERT( _pm->isPluginLoaded("test") == NULL ); 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(){ void PluginManagerTest::testRegisterPlugin(){
// First load the default directory library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME);
_pm->loadPlugins(); CPPUNIT_ASSERT(library != NULL);
// Resolve the symbol 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(){ void PluginManagerTest::tearDown(){
// Delete the plugin manager object // Delete the plugin manager object
delete _pm; _pm=0; 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