r3370 - in trunk/libmutil: . source
erik at minisip.org
erik at minisip.org
Fri Aug 17 15:02:42 CEST 2007
Author: erik
Date: 2007-08-17 15:02:42 +0200 (Fri, 17 Aug 2007)
New Revision: 3370
Added:
trunk/libmutil/source/LibraryPosix.cxx
trunk/libmutil/source/MPluginPosix.cxx
Removed:
trunk/libmutil/source/Library.cxx
trunk/libmutil/source/MPlugin.cxx
Modified:
trunk/libmutil/Makefile.am
Log:
* Rename Library.{h,cxx} -> LibraryPosix.{h,cxx} and MPlugin.{h,cxx} to
MPluginPosix.{h,cxx}.
Those files can not be compiled in MSVS.
Modified: trunk/libmutil/Makefile.am
===================================================================
--- trunk/libmutil/Makefile.am 2007-08-15 14:30:15 UTC (rev 3369)
+++ trunk/libmutil/Makefile.am 2007-08-17 13:02:42 UTC (rev 3370)
@@ -46,7 +46,7 @@
mutil_src = \
source/CriticalSection.cxx \
source/MemObject.cxx \
- source/Library.cxx \
+ source/LibraryPosix.cxx \
source/MessageRouter.cxx \
source/Exception.cxx \
source/massert.cxx \
@@ -60,7 +60,7 @@
source/vmd5.cxx \
source/CommandString.cxx \
source/XMLParser.cxx \
- source/MPlugin.cxx \
+ source/MPluginPosix.cxx \
source/CircularBuffer.cxx \
source/SipUri.cxx \
source/CacheItem.cxx \
Deleted: trunk/libmutil/source/Library.cxx
===================================================================
--- trunk/libmutil/source/Library.cxx 2007-08-15 14:30:15 UTC (rev 3369)
+++ trunk/libmutil/source/Library.cxx 2007-08-17 13:02:42 UTC (rev 3370)
@@ -1,90 +0,0 @@
-/*
- Copyright (C) 2004-2006 the Minisip Team
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/*
- * Copyright (C) 2004-2006
- *
- * Authors: Erik Eliasson <eliasson at it.kth.se>
- * Johan Bilien <jobi at via.ecp.fr>
- * Mikael Magnusson <mikma at users.sourceforge.net>
-*/
-
-#include<config.h>
-#include<libmutil/Library.h>
-#include<libmutil/massert.h>
-
-#include<iostream>
-
-// Use ltdl symbols defined in ltdl.c
-#define LT_SCOPE extern
-#include<ltdl.h>
-
-using namespace std;
-
-int Library::refCount;
-
-Library::Library(const string &path_):path(path_){
-
- if( refCount == 0 )
- lt_dlinit();
-
- refCount++;
-
- handle = lt_dlopenext(path.c_str());
-#ifdef DEBUG_OUTPUT
- if( !handle ){
- cerr << "Library: " << lt_dlerror() << endl;
- }
-#endif
-}
-
-Library::~Library(){
- if(handle){
- lt_dlclose((lt_dlhandle)handle);
- handle=NULL;
- }
-
- refCount--;
- if( refCount == 0 )
- lt_dlexit();
-}
-
-void *Library::getFunctionPtr(string name){
- void * ptr = lt_dlsym((lt_dlhandle)handle, name.c_str());
- return ptr;
-}
-
-MRef<Library *> Library::open(const string &path){
- MRef<Library *> ret = new Library(path);
- if(ret->handle){
- const lt_dlinfo *info;
-
- info = lt_dlgetinfo( (lt_dlhandle)ret->handle );
- if( info && info->filename ){
- ret->path = info->filename;
- }
-
- return ret;
- }
- ret = NULL;
- return ret;
-}
-
-const string &Library::getPath(){
- return path;
-}
Copied: trunk/libmutil/source/LibraryPosix.cxx (from rev 3369, trunk/libmutil/source/Library.cxx)
===================================================================
--- trunk/libmutil/source/LibraryPosix.cxx (rev 0)
+++ trunk/libmutil/source/LibraryPosix.cxx 2007-08-17 13:02:42 UTC (rev 3370)
@@ -0,0 +1,90 @@
+/*
+ Copyright (C) 2004-2006 the Minisip Team
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ * Copyright (C) 2004-2006
+ *
+ * Authors: Erik Eliasson <eliasson at it.kth.se>
+ * Johan Bilien <jobi at via.ecp.fr>
+ * Mikael Magnusson <mikma at users.sourceforge.net>
+*/
+
+#include<config.h>
+#include<libmutil/Library.h>
+#include<libmutil/massert.h>
+
+#include<iostream>
+
+// Use ltdl symbols defined in ltdl.c
+#define LT_SCOPE extern
+#include<ltdl.h>
+
+using namespace std;
+
+int Library::refCount;
+
+Library::Library(const string &path_):path(path_){
+
+ if( refCount == 0 )
+ lt_dlinit();
+
+ refCount++;
+
+ handle = lt_dlopenext(path.c_str());
+#ifdef DEBUG_OUTPUT
+ if( !handle ){
+ cerr << "Library: " << lt_dlerror() << endl;
+ }
+#endif
+}
+
+Library::~Library(){
+ if(handle){
+ lt_dlclose((lt_dlhandle)handle);
+ handle=NULL;
+ }
+
+ refCount--;
+ if( refCount == 0 )
+ lt_dlexit();
+}
+
+void *Library::getFunctionPtr(string name){
+ void * ptr = lt_dlsym((lt_dlhandle)handle, name.c_str());
+ return ptr;
+}
+
+MRef<Library *> Library::open(const string &path){
+ MRef<Library *> ret = new Library(path);
+ if(ret->handle){
+ const lt_dlinfo *info;
+
+ info = lt_dlgetinfo( (lt_dlhandle)ret->handle );
+ if( info && info->filename ){
+ ret->path = info->filename;
+ }
+
+ return ret;
+ }
+ ret = NULL;
+ return ret;
+}
+
+const string &Library::getPath(){
+ return path;
+}
Deleted: trunk/libmutil/source/MPlugin.cxx
===================================================================
--- trunk/libmutil/source/MPlugin.cxx 2007-08-15 14:30:15 UTC (rev 3369)
+++ trunk/libmutil/source/MPlugin.cxx 2007-08-17 13:02:42 UTC (rev 3370)
@@ -1,295 +0,0 @@
-/*
- Copyright (C) 2004-2006 the Minisip Team
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/*
- * Copyright (C) 2004-2006
- *
- * Authors: Erik Eliasson <eliasson at it.kth.se>
- * Johan Bilien <jobi at via.ecp.fr>
- * Mikael Magnusson <mikma at users.sourceforge.net>
-*/
-
-
-#include<config.h>
-
-#include<libmutil/dbg.h>
-#include<libmutil/MPlugin.h>
-#include<libmutil/Library.h>
-
-// Use ltdl symbols defined in ltdl.c
-#define LT_SCOPE extern
-#include<ltdl.h>
-
-using namespace std;
-
-MRef<MPluginManager*> MPluginManager::instance;
-
-MPlugin::MPlugin(MRef<Library*> lib): library( lib ){
-}
-
-MPlugin::MPlugin(): library( NULL ){
-}
-
-MPlugin::~MPlugin(){
-}
-
-string MPlugin::getMemObjectType() const{
- return "MPlugin";
-}
-
-MPluginManager::MPluginManager(){
- lt_dlinit();
- libraries.clear();
-}
-
-MPluginManager::~MPluginManager(){
- libraries.clear();
- registries.clear();
- lt_dlexit();
-}
-
-MRef<MPluginManager*> MPluginManager::getInstance(){
- if( !instance ){
- instance = new MPluginManager();
- }
-
- return instance;
-}
-
-list<string> * MPluginManager::getListFromLibrary( MRef<Library *> lib ){
- MPlugin::lister listerFunction;
-
- listerFunction = (MPlugin::lister)lib->getFunctionPtr( "listPlugins" );
-
- if( listerFunction ){
- return listerFunction( lib );
- }
-
- return NULL;
-}
-
-int32_t MPluginManager::loadFromFile( const std::string &filename ){
- int32_t nPlugins = 0;
- list<string> * entryPoints;
- MRef<Library *> lib;
- list< MRef<Library *> >::iterator iLib;
-
- lib = Library::open( filename );
-
- if( !lib ){
- mdbg << "MPluginManager: Can't load " << filename << endl;
- // Continue;
- return -1;
- }
-
- for( iLib = libraries.begin(); iLib != libraries.end(); iLib++ ){
- MRef<Library *> cur = *iLib;
-
- if( cur->getPath() == lib->getPath() ){
- mdbg << "MPluginManager: Already loaded " << filename << endl;
- return -1;
- }
- }
-
- entryPoints = getListFromLibrary( lib );
-
- if( entryPoints ){
- list<string>::iterator iEP;
- for( iEP = entryPoints->begin();
- iEP!= entryPoints->end();
- iEP ++ ){
- MRef<MPlugin *> p;
-
- p = loadFromLibrary( lib, *iEP );
- if( p ){
- if( registerPlugin( p ) ){
- nPlugins ++;
- }
- }
- else {
- merr << "MPluginManager: No plugin for ep: " << *iEP << endl;
- }
- }
- }
- else{
- merr << "MPluginManager: No entrypoints in " << filename << endl;
- }
-
- if( nPlugins > 0 ){
- libraries.push_back( lib );
- }
- else {
- mdbg << "MPluginManager: No plugins loaded from " << lib->getPath() << endl;
- }
- return nPlugins;
-}
-
-struct ltdl_info {
- ltdl_info() : manager(NULL),nTotalPlugins(0){}
- ~ltdl_info(){manager=NULL;}
-
- MRef<MPluginManager *> manager;
- int32_t nTotalPlugins;
-};
-
-static int ltdl_callback(const char *filename, lt_ptr data){
- ltdl_info *info = (ltdl_info*)data;
- int32_t nPlugins;
-
- nPlugins = info->manager->loadFromFile( filename );
-
- if( nPlugins > 0 ){
- info->nTotalPlugins += nPlugins;
- }
-
- // Continue;
- return 0;
-}
-
-int32_t MPluginManager::loadFromDirectory( const string &path ){
- ltdl_info info;
- info.manager = this;
-
- int res = lt_dlforeachfile(path.c_str(), ltdl_callback, &info);
- if( res < 0 ){
- merr << lt_dlerror() << endl;
- }
- return info.nTotalPlugins;
-}
-
-MRef<MPlugin *> MPluginManager::loadFromLibrary( const string &file,
- const string &entryPoint ){
- MRef<Library *> lib = NULL;
- list< MRef<Library *> >::iterator iLib;
- MRef<MPlugin *> p;
- bool newLib = false;
-
- for( iLib = libraries.begin(); iLib != libraries.end(); iLib ++ ){
- if( (*iLib)->getPath() == file ){
- lib = *iLib;
- }
- }
-
- /* This library hasn't been opened yet */
- if( !lib ){
- lib = Library::open( file );
- if( lib ){
- newLib = true;
- }
- }
-
- p = loadFromLibrary( lib, entryPoint );
-
- if( p && newLib ){
- libraries.push_back( lib );
- }
-
- return p;
-}
-
-
-MRef<MPlugin *> MPluginManager::loadFromLibrary( MRef<Library *> lib,
- const string &entryPoint ){
- MPlugin::creator creatorFunction;
-
- if( !lib ){
- /* This library doen't exist or couldn't be opened */
- return NULL;
- }
-
- creatorFunction = (MPlugin::creator)(lib->Library::getFunctionPtr(
- entryPoint ));
-
- if( creatorFunction ){
- MRef<MPlugin *> pp = creatorFunction( lib );
-
- if( !pp.isNull() ){
- mdbg << "MPluginManager: loaded " << pp->getName() << "(" << pp->getDescription() << ")" << endl;
- return pp;
- }
- }
-
- return NULL;
-}
-
-bool MPluginManager::registerPlugin( MRef<MPlugin *> p ){
- std::list< MPluginRegistry * >::iterator iReg;
-
-
- for( iReg = registries.begin(); iReg != registries.end(); iReg ++ ){
- if( (*iReg)->getPluginType() == p->getPluginType() ){
- (*iReg)->registerPlugin( p );
- return true;
- }
- }
-
- merr << "MPluginManager: Can't find registry for " << p->getPluginType() << endl;
- return false;
-}
-
-void MPluginManager::addRegistry( MPluginRegistry * registry ){
- registries.push_back( registry );
-}
-
-void MPluginManager::removeRegistry( MPluginRegistry * registry ){
- registries.remove( registry );
-}
-
-bool MPluginManager::setSearchPath( const std::string &searchPath ){
- mdbg << "MPluginManager: setSearchPath " << searchPath << endl;
-
- bool res = lt_dlsetsearchpath( searchPath.c_str() );
- return res;
-}
-
-void MPluginRegistry::registerPlugin( MRef<MPlugin *> p ){
- plugins.push_back( p );
-}
-
-MPluginRegistry::MPluginRegistry(){
- manager = MPluginManager::getInstance();
- manager->addRegistry( this );
-}
-
-MPluginRegistry::~MPluginRegistry(){
- plugins.clear();
- manager->removeRegistry( this );
-}
-
-MRef<MPlugin*> MPluginRegistry::findPlugin( std::string name ){
- list< MRef<MPlugin *> >::iterator iter;
- list< MRef<MPlugin *> >::iterator last = plugins.end();
-
- for( iter = plugins.begin(); iter != last; iter++ ){
- MRef<MPlugin *> plugin = *iter;
-
- if( plugin->getName() == name ){
- return plugin;
- }
- }
-
- return NULL;
-}
-
-MPluginRegistry::const_iterator MPluginRegistry::begin() const{
- return plugins.begin();
-}
-
-MPluginRegistry::const_iterator MPluginRegistry::end() const{
- return plugins.end();
-}
Copied: trunk/libmutil/source/MPluginPosix.cxx (from rev 3369, trunk/libmutil/source/MPlugin.cxx)
===================================================================
--- trunk/libmutil/source/MPluginPosix.cxx (rev 0)
+++ trunk/libmutil/source/MPluginPosix.cxx 2007-08-17 13:02:42 UTC (rev 3370)
@@ -0,0 +1,295 @@
+/*
+ Copyright (C) 2004-2006 the Minisip Team
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ * Copyright (C) 2004-2006
+ *
+ * Authors: Erik Eliasson <eliasson at it.kth.se>
+ * Johan Bilien <jobi at via.ecp.fr>
+ * Mikael Magnusson <mikma at users.sourceforge.net>
+*/
+
+
+#include<config.h>
+
+#include<libmutil/dbg.h>
+#include<libmutil/MPlugin.h>
+#include<libmutil/Library.h>
+
+// Use ltdl symbols defined in ltdl.c
+#define LT_SCOPE extern
+#include<ltdl.h>
+
+using namespace std;
+
+MRef<MPluginManager*> MPluginManager::instance;
+
+MPlugin::MPlugin(MRef<Library*> lib): library( lib ){
+}
+
+MPlugin::MPlugin(): library( NULL ){
+}
+
+MPlugin::~MPlugin(){
+}
+
+string MPlugin::getMemObjectType() const{
+ return "MPlugin";
+}
+
+MPluginManager::MPluginManager(){
+ lt_dlinit();
+ libraries.clear();
+}
+
+MPluginManager::~MPluginManager(){
+ libraries.clear();
+ registries.clear();
+ lt_dlexit();
+}
+
+MRef<MPluginManager*> MPluginManager::getInstance(){
+ if( !instance ){
+ instance = new MPluginManager();
+ }
+
+ return instance;
+}
+
+list<string> * MPluginManager::getListFromLibrary( MRef<Library *> lib ){
+ MPlugin::lister listerFunction;
+
+ listerFunction = (MPlugin::lister)lib->getFunctionPtr( "listPlugins" );
+
+ if( listerFunction ){
+ return listerFunction( lib );
+ }
+
+ return NULL;
+}
+
+int32_t MPluginManager::loadFromFile( const std::string &filename ){
+ int32_t nPlugins = 0;
+ list<string> * entryPoints;
+ MRef<Library *> lib;
+ list< MRef<Library *> >::iterator iLib;
+
+ lib = Library::open( filename );
+
+ if( !lib ){
+ mdbg << "MPluginManager: Can't load " << filename << endl;
+ // Continue;
+ return -1;
+ }
+
+ for( iLib = libraries.begin(); iLib != libraries.end(); iLib++ ){
+ MRef<Library *> cur = *iLib;
+
+ if( cur->getPath() == lib->getPath() ){
+ mdbg << "MPluginManager: Already loaded " << filename << endl;
+ return -1;
+ }
+ }
+
+ entryPoints = getListFromLibrary( lib );
+
+ if( entryPoints ){
+ list<string>::iterator iEP;
+ for( iEP = entryPoints->begin();
+ iEP!= entryPoints->end();
+ iEP ++ ){
+ MRef<MPlugin *> p;
+
+ p = loadFromLibrary( lib, *iEP );
+ if( p ){
+ if( registerPlugin( p ) ){
+ nPlugins ++;
+ }
+ }
+ else {
+ merr << "MPluginManager: No plugin for ep: " << *iEP << endl;
+ }
+ }
+ }
+ else{
+ merr << "MPluginManager: No entrypoints in " << filename << endl;
+ }
+
+ if( nPlugins > 0 ){
+ libraries.push_back( lib );
+ }
+ else {
+ mdbg << "MPluginManager: No plugins loaded from " << lib->getPath() << endl;
+ }
+ return nPlugins;
+}
+
+struct ltdl_info {
+ ltdl_info() : manager(NULL),nTotalPlugins(0){}
+ ~ltdl_info(){manager=NULL;}
+
+ MRef<MPluginManager *> manager;
+ int32_t nTotalPlugins;
+};
+
+static int ltdl_callback(const char *filename, lt_ptr data){
+ ltdl_info *info = (ltdl_info*)data;
+ int32_t nPlugins;
+
+ nPlugins = info->manager->loadFromFile( filename );
+
+ if( nPlugins > 0 ){
+ info->nTotalPlugins += nPlugins;
+ }
+
+ // Continue;
+ return 0;
+}
+
+int32_t MPluginManager::loadFromDirectory( const string &path ){
+ ltdl_info info;
+ info.manager = this;
+
+ int res = lt_dlforeachfile(path.c_str(), ltdl_callback, &info);
+ if( res < 0 ){
+ merr << lt_dlerror() << endl;
+ }
+ return info.nTotalPlugins;
+}
+
+MRef<MPlugin *> MPluginManager::loadFromLibrary( const string &file,
+ const string &entryPoint ){
+ MRef<Library *> lib = NULL;
+ list< MRef<Library *> >::iterator iLib;
+ MRef<MPlugin *> p;
+ bool newLib = false;
+
+ for( iLib = libraries.begin(); iLib != libraries.end(); iLib ++ ){
+ if( (*iLib)->getPath() == file ){
+ lib = *iLib;
+ }
+ }
+
+ /* This library hasn't been opened yet */
+ if( !lib ){
+ lib = Library::open( file );
+ if( lib ){
+ newLib = true;
+ }
+ }
+
+ p = loadFromLibrary( lib, entryPoint );
+
+ if( p && newLib ){
+ libraries.push_back( lib );
+ }
+
+ return p;
+}
+
+
+MRef<MPlugin *> MPluginManager::loadFromLibrary( MRef<Library *> lib,
+ const string &entryPoint ){
+ MPlugin::creator creatorFunction;
+
+ if( !lib ){
+ /* This library doen't exist or couldn't be opened */
+ return NULL;
+ }
+
+ creatorFunction = (MPlugin::creator)(lib->Library::getFunctionPtr(
+ entryPoint ));
+
+ if( creatorFunction ){
+ MRef<MPlugin *> pp = creatorFunction( lib );
+
+ if( !pp.isNull() ){
+ mdbg << "MPluginManager: loaded " << pp->getName() << "(" << pp->getDescription() << ")" << endl;
+ return pp;
+ }
+ }
+
+ return NULL;
+}
+
+bool MPluginManager::registerPlugin( MRef<MPlugin *> p ){
+ std::list< MPluginRegistry * >::iterator iReg;
+
+
+ for( iReg = registries.begin(); iReg != registries.end(); iReg ++ ){
+ if( (*iReg)->getPluginType() == p->getPluginType() ){
+ (*iReg)->registerPlugin( p );
+ return true;
+ }
+ }
+
+ merr << "MPluginManager: Can't find registry for " << p->getPluginType() << endl;
+ return false;
+}
+
+void MPluginManager::addRegistry( MPluginRegistry * registry ){
+ registries.push_back( registry );
+}
+
+void MPluginManager::removeRegistry( MPluginRegistry * registry ){
+ registries.remove( registry );
+}
+
+bool MPluginManager::setSearchPath( const std::string &searchPath ){
+ mdbg << "MPluginManager: setSearchPath " << searchPath << endl;
+
+ bool res = lt_dlsetsearchpath( searchPath.c_str() );
+ return res;
+}
+
+void MPluginRegistry::registerPlugin( MRef<MPlugin *> p ){
+ plugins.push_back( p );
+}
+
+MPluginRegistry::MPluginRegistry(){
+ manager = MPluginManager::getInstance();
+ manager->addRegistry( this );
+}
+
+MPluginRegistry::~MPluginRegistry(){
+ plugins.clear();
+ manager->removeRegistry( this );
+}
+
+MRef<MPlugin*> MPluginRegistry::findPlugin( std::string name ){
+ list< MRef<MPlugin *> >::iterator iter;
+ list< MRef<MPlugin *> >::iterator last = plugins.end();
+
+ for( iter = plugins.begin(); iter != last; iter++ ){
+ MRef<MPlugin *> plugin = *iter;
+
+ if( plugin->getName() == name ){
+ return plugin;
+ }
+ }
+
+ return NULL;
+}
+
+MPluginRegistry::const_iterator MPluginRegistry::begin() const{
+ return plugins.begin();
+}
+
+MPluginRegistry::const_iterator MPluginRegistry::end() const{
+ return plugins.end();
+}
More information about the Minisip-devel
mailing list