Replaced platform-dependent dynamic loading code with wxPluginManager
This commit is contained in:
parent
2bdc4d770b
commit
14bee875cf
|
@ -33,6 +33,7 @@
|
||||||
#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/dynlib.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
@ -241,63 +242,31 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
|
||||||
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath,
|
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath,
|
||||||
std::list< wxString >& aPluginList )
|
std::list< wxString >& aPluginList )
|
||||||
{
|
{
|
||||||
// list potential plugins given a search paths
|
// list potential plugins given a search path
|
||||||
// note on typical plugin names:
|
|
||||||
// Linux: *.so, *.so.* (note: *.so.* will not be supported)
|
|
||||||
// MSWin: *.dll
|
|
||||||
// OSX: *.dylib, *.bundle
|
|
||||||
|
|
||||||
std::list< wxString > nameFilter; // filter to apply to files
|
wxString nameFilter; // filter for user-loadable libraries (aka modules)
|
||||||
wxString lName; // stores name of enumerated files
|
wxString lName; // stores name of enumerated files
|
||||||
wxString fName; // full name of file
|
wxString fName; // full name of file
|
||||||
|
|
||||||
#ifdef __linux
|
|
||||||
|
|
||||||
nameFilter.push_back( wxString::FromUTF8Unchecked( "*.so" ) );
|
|
||||||
|
|
||||||
#elif defined _WIN32
|
|
||||||
|
|
||||||
nameFilter.push_back( wxString::FromUTF8Unchecked( "*.dll" ) );
|
|
||||||
|
|
||||||
#elif defined __APPLE__
|
|
||||||
|
|
||||||
nameFilter.push_back( wxString::FromUTF8Unchecked( "*.dylib" ) );
|
|
||||||
nameFilter.push_back( wxString::FromUTF8Unchecked( "*.bundle" ) );
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// note: we need to positively identify a supported OS here
|
|
||||||
// and add suffixes which may be used for 3D model plugins
|
|
||||||
// on the specific OS
|
|
||||||
#warning NOT IMPLEMENTED
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wxDir wd;
|
wxDir wd;
|
||||||
wd.Open( aPath );
|
wd.Open( aPath );
|
||||||
|
|
||||||
if( !wd.IsOpened() )
|
if( !wd.IsOpened() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
nameFilter = wxT( "*" );
|
||||||
|
nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) );
|
||||||
wxString lp = wd.GetNameWithSep();
|
wxString lp = wd.GetNameWithSep();
|
||||||
std::list< wxString >::iterator sExt = nameFilter.begin();
|
|
||||||
std::list< wxString >::iterator eExt = nameFilter.end();
|
|
||||||
|
|
||||||
while( sExt != eExt )
|
if( wd.GetFirst( &lName, nameFilter, wxDIR_FILES ) )
|
||||||
{
|
{
|
||||||
if( wd.GetFirst( &lName, *sExt, wxDIR_FILES ) )
|
fName = lp + lName;
|
||||||
|
checkPluginName( fName, aPluginList );
|
||||||
|
|
||||||
|
while( wd.GetNext( &lName ) )
|
||||||
{
|
{
|
||||||
fName = lp + lName;
|
fName = lp + lName;
|
||||||
checkPluginName( fName, aPluginList );
|
checkPluginName( fName, aPluginList );
|
||||||
|
|
||||||
while( wd.GetNext( &lName ) )
|
|
||||||
{
|
|
||||||
fName = lp + lName;
|
|
||||||
checkPluginName( fName, aPluginList );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++sExt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wd.Close();
|
wd.Close();
|
||||||
|
|
|
@ -146,10 +146,6 @@ elseif(NOT GLM_ENABLE_FAST_MATH)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if( WIN32 )
|
target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg )
|
||||||
target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg )
|
|
||||||
else()
|
|
||||||
target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg dl )
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory( 3d_cache )
|
add_subdirectory( 3d_cache )
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <wx/dynload.h>
|
||||||
|
|
||||||
#include "pluginldr.h"
|
#include "pluginldr.h"
|
||||||
|
|
||||||
|
@ -35,7 +36,6 @@ KICAD_PLUGIN_LDR::KICAD_PLUGIN_LDR()
|
||||||
m_checkClassVersion = NULL;
|
m_checkClassVersion = NULL;
|
||||||
m_getPluginName = NULL;
|
m_getPluginName = NULL;
|
||||||
m_getVersion = NULL;
|
m_getVersion = NULL;
|
||||||
m_dlHandle = NULL;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -60,18 +60,9 @@ bool KICAD_PLUGIN_LDR::open( const wxString& aFullFileName, const char* aPluginC
|
||||||
|
|
||||||
m_fileName.clear();
|
m_fileName.clear();
|
||||||
|
|
||||||
#ifdef _WIN32
|
m_PluginLoader.Load( aFullFileName, wxDL_LAZY );
|
||||||
// NOTE: MSWin uses UTF-16 encoding
|
|
||||||
#if defined( UNICODE ) || defined( _UNICODE )
|
|
||||||
m_dlHandle = LoadLibrary( aFullFileName.wc_str() );
|
|
||||||
#else
|
|
||||||
m_dlHandle = LoadLibrary( aFullFileName.ToUTF8() );
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
m_dlHandle = dlopen( aFullFileName.ToUTF8(), RTLD_LAZY | RTLD_LOCAL );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( NULL == m_dlHandle )
|
if( !m_PluginLoader.IsLoaded() )
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||||
|
@ -238,18 +229,7 @@ void KICAD_PLUGIN_LDR::close( void )
|
||||||
m_checkClassVersion = NULL;
|
m_checkClassVersion = NULL;
|
||||||
m_getPluginName = NULL;
|
m_getPluginName = NULL;
|
||||||
m_getVersion = NULL;
|
m_getVersion = NULL;
|
||||||
|
m_PluginLoader.Unload();
|
||||||
if( NULL != m_dlHandle )
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
FreeLibrary( m_dlHandle );
|
|
||||||
#else
|
|
||||||
dlclose( m_dlHandle );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_dlHandle = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,22 +32,11 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
#include <wx/dynload.h>
|
||||||
|
|
||||||
// helper functions to link functions
|
// helper function to link functions in the plugin
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#define LINK_ITEM( funcPtr, funcType, funcName ) \
|
#define LINK_ITEM( funcPtr, funcType, funcName ) \
|
||||||
funcPtr = (funcType) GetProcAddress( m_dlHandle, funcName );
|
funcPtr = (funcType) m_PluginLoader.GetSymbol( wxT( funcName ) )
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#define LINK_ITEM( funcPtr, funcType, funcName ) \
|
|
||||||
*(void**) (&funcPtr) = dlsym( m_dlHandle, funcName );
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// typedefs of the functions exported by the 3D Plugin Class
|
// typedefs of the functions exported by the 3D Plugin Class
|
||||||
typedef char const* (*GET_PLUGIN_CLASS) ( void );
|
typedef char const* (*GET_PLUGIN_CLASS) ( void );
|
||||||
|
@ -99,12 +88,8 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool reopen( void );
|
bool reopen( void );
|
||||||
|
|
||||||
// handle to the opened plugin
|
// the plugin loader
|
||||||
#ifdef _WIN32
|
wxPluginManager m_PluginLoader;
|
||||||
HMODULE m_dlHandle;
|
|
||||||
#else
|
|
||||||
void* m_dlHandle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KICAD_PLUGIN_LDR();
|
KICAD_PLUGIN_LDR();
|
||||||
|
|
Loading…
Reference in New Issue