00001 #ifndef OBT_PLUGIN_LOADER_H 00002 #define OBT_PLUGIN_LOADER_H 00003 00004 #ifdef _MSC_VER 00005 #include <windows.h> 00006 #endif 00007 00008 #include <string> 00009 #include <list> 00010 00011 #include "OBTSingleton.h" 00012 #include "OBTPluginInterface.h" 00013 #include "OBTTrace.h" 00014 #include <typeinfo> 00015 00016 namespace OBT 00017 { 00018 00019 class PluginInformation ; 00020 class OldPlugin ; 00021 struct PluginImpl ; 00022 00045 class OBT_API PluginLoaderImpl 00046 { 00047 public: 00082 PluginInterface* load( const std::string& path, const std::string& name = std::string(), 00083 const std::string& prm = std::string() ) ; 00084 00097 template< class PluginType > 00098 PluginType* loadT( const std::string& path, const std::string& name = std::string(), 00099 const std::string& prm = std::string() ) 00100 { 00101 PluginInterface* plugin = load( path, name, prm ) ; 00102 PluginType* pluginType = dynamic_cast< PluginType* >( plugin ) ; 00103 if( 0 != plugin && 0 == pluginType ) 00104 { 00105 TRACE_ERROR( "Unable to get the plugin object of type [" << typeid( (PluginType*)0 ).name() << "] for the plugin \"" << getPath( path, name ) << "\"" ) ; 00106 unload( plugin ) ; 00107 } 00108 return pluginType ; 00109 } 00110 00116 bool unload( PluginInterface* plugin ) ; 00117 private: 00119 friend class OBT::Singleton< PluginLoaderImpl > ; 00121 PluginLoaderImpl() {} 00125 virtual ~PluginLoaderImpl() ; 00126 00128 00129 PluginLoaderImpl( const PluginLoaderImpl& ) ; 00130 PluginLoaderImpl& operator = ( const PluginLoaderImpl& ) ; 00132 00134 00135 friend class OBT::PluginInterface ; 00136 friend class OBT::OldPlugin ; 00137 void unloadAndCheckForPluginDeletion( PluginImpl* pluginImpl ) ; 00138 typedef bool ( *InitFunc )( const char* configurationFile ) ; 00139 typedef bool ( *FinishFunc )() ; 00140 typedef const PluginInformation& ( *GetInformationFunc )() ; 00141 typedef PluginInterface* ( *PluginGetFunc )() ; 00142 template< typename FuncType > FuncType getFunc( OBT_PLUGIN_HANDLE handle, const char* funcName ) const ; 00143 std::string getPath( const std::string& path, const std::string& name ) const ; 00144 OBT_PLUGIN_HANDLE loadCall( const char* path ) const ; 00145 std::string errorMsgCall() const ; 00146 void unloadCall( OBT_PLUGIN_HANDLE handle ) const ; 00147 typedef std::list< PluginImpl* > PluginsList ; 00148 PluginsList::iterator find( PluginInterface* plugin ) ; 00149 PluginsList::iterator find( const std::string& path ) ; 00150 PluginsList _plugins ; 00152 } ; 00153 00154 typedef Singleton< PluginLoaderImpl > PluginLoader ; 00155 } 00156 00157 #endif // OBT_PLUGIN_LOADER_H