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/stdpaths.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/dynlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
@ -241,63 +242,31 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void )
|
|||
void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath,
|
||||
std::list< wxString >& aPluginList )
|
||||
{
|
||||
// list potential plugins given a search paths
|
||||
// note on typical plugin names:
|
||||
// Linux: *.so, *.so.* (note: *.so.* will not be supported)
|
||||
// MSWin: *.dll
|
||||
// OSX: *.dylib, *.bundle
|
||||
// list potential plugins given a search path
|
||||
|
||||
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 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;
|
||||
wd.Open( aPath );
|
||||
|
||||
if( !wd.IsOpened() )
|
||||
return;
|
||||
|
||||
nameFilter = wxT( "*" );
|
||||
nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) );
|
||||
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;
|
||||
checkPluginName( fName, aPluginList );
|
||||
|
||||
while( wd.GetNext( &lName ) )
|
||||
{
|
||||
fName = lp + lName;
|
||||
checkPluginName( fName, aPluginList );
|
||||
}
|
||||
}
|
||||
|
||||
++sExt;
|
||||
}
|
||||
|
||||
wd.Close();
|
||||
|
|
|
@ -146,10 +146,6 @@ elseif(NOT GLM_ENABLE_FAST_MATH)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if( WIN32 )
|
||||
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()
|
||||
target_link_libraries( 3d-viewer ${Boost_} ${wxWidgets_LIBRARIES} ${OPENGL_LIBRARIES} kicad_3dsg )
|
||||
|
||||
add_subdirectory( 3d_cache )
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <wx/dynload.h>
|
||||
|
||||
#include "pluginldr.h"
|
||||
|
||||
|
@ -35,7 +36,6 @@ KICAD_PLUGIN_LDR::KICAD_PLUGIN_LDR()
|
|||
m_checkClassVersion = NULL;
|
||||
m_getPluginName = NULL;
|
||||
m_getVersion = NULL;
|
||||
m_dlHandle = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -60,18 +60,9 @@ bool KICAD_PLUGIN_LDR::open( const wxString& aFullFileName, const char* aPluginC
|
|||
|
||||
m_fileName.clear();
|
||||
|
||||
#ifdef _WIN32
|
||||
// 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
|
||||
m_PluginLoader.Load( aFullFileName, wxDL_LAZY );
|
||||
|
||||
if( NULL == m_dlHandle )
|
||||
if( !m_PluginLoader.IsLoaded() )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
||||
|
@ -238,18 +229,7 @@ void KICAD_PLUGIN_LDR::close( void )
|
|||
m_checkClassVersion = NULL;
|
||||
m_getPluginName = NULL;
|
||||
m_getVersion = NULL;
|
||||
|
||||
if( NULL != m_dlHandle )
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
FreeLibrary( m_dlHandle );
|
||||
#else
|
||||
dlclose( m_dlHandle );
|
||||
#endif
|
||||
|
||||
m_dlHandle = NULL;
|
||||
}
|
||||
m_PluginLoader.Unload();
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,22 +32,11 @@
|
|||
|
||||
#include <string>
|
||||
#include <wx/string.h>
|
||||
#include <wx/dynload.h>
|
||||
|
||||
// helper functions to link functions
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
// helper function to link functions in the plugin
|
||||
#define LINK_ITEM( funcPtr, funcType, funcName ) \
|
||||
funcPtr = (funcType) GetProcAddress( m_dlHandle, funcName );
|
||||
|
||||
#else
|
||||
|
||||
#include <dlfcn.h>
|
||||
#define LINK_ITEM( funcPtr, funcType, funcName ) \
|
||||
*(void**) (&funcPtr) = dlsym( m_dlHandle, funcName );
|
||||
|
||||
#endif
|
||||
|
||||
funcPtr = (funcType) m_PluginLoader.GetSymbol( wxT( funcName ) )
|
||||
|
||||
// typedefs of the functions exported by the 3D Plugin Class
|
||||
typedef char const* (*GET_PLUGIN_CLASS) ( void );
|
||||
|
@ -99,12 +88,8 @@ protected:
|
|||
*/
|
||||
bool reopen( void );
|
||||
|
||||
// handle to the opened plugin
|
||||
#ifdef _WIN32
|
||||
HMODULE m_dlHandle;
|
||||
#else
|
||||
void* m_dlHandle;
|
||||
#endif
|
||||
// the plugin loader
|
||||
wxPluginManager m_PluginLoader;
|
||||
|
||||
public:
|
||||
KICAD_PLUGIN_LDR();
|
||||
|
|
Loading…
Reference in New Issue