24 template<
typename PluginT,
typename InitDataT >
25 PluginFactory< PluginT, InitDataT >&
32 template<
typename PluginT,
typename InitDataT >
42 template<
typename PluginT,
typename InitDataT >
46 if( plugin.handles( initData ))
47 return plugin.constructor( initData );
49 LBTHROW( std::runtime_error(
"No plugin implementation available for " +
50 boost::lexical_cast<std::string>( initData )));
53 template<
typename PluginT,
typename InitDataT >
57 _plugins.push_back( plugin );
60 template<
typename PluginT,
typename InitDataT >
64 typename Plugins::iterator i =
65 std::find( _plugins.begin(), _plugins.end(), plugin );
66 if( i == _plugins.end( ))
73 template<
typename PluginT,
typename InitDataT >
77 BOOST_FOREACH(
typename PluginMap::value_type& plugin, _libraries )
82 template<
typename PluginT,
typename InitDataT >
85 const std::string& pattern )
91 BOOST_FOREACH(
const std::string& path, unique )
92 _load( result, version, path, pattern );
96 template< typename PluginT, typename InitDataT >
98 const
std::
string& path,
99 const
std::
string& pattern )
102 _load( loaded, version, path, pattern );
106 template<
typename PluginT,
typename InitDataT >
109 const std::string& path,
110 const std::string& pattern )
113 const std::string regex( pattern +
".dll" );
115 const std::string regex(
"lib" + pattern +
".dylib" );
117 const std::string regex(
"lib" + pattern +
".so" );
121 BOOST_FOREACH(
const std::string& lib, libs )
130 typedef int( *GetVersion_t )();
131 typedef bool( *Register_t )();
134 "LunchboxPluginGetVersion" );
136 "LunchboxPluginRegister" );
137 const bool matchesVersion = getVersion && (getVersion() == version);
139 if( !getVersion || !registerFunc || !matchesVersion )
141 LBERROR <<
"Disable " << lib <<
": "
142 << ( getVersion ?
"" :
143 "Symbol for LunchboxPluginGetVersion missing " )
144 << ( registerFunc ?
"" :
145 "Symbol for LunchboxPluginRegister missing " );
146 if( getVersion && !matchesVersion )
147 LBERROR <<
"Plugin version " << getVersion() <<
" does not"
148 <<
" match application version " << version;
157 _libraries.insert( std::make_pair( dso, _plugins.back( )));
158 result.push_back( dso );
159 LBINFO <<
"Enabled plugin " << lib << std::endl;
166 template<
typename PluginT,
typename InitDataT >
169 typename PluginMap::iterator i = _libraries.find( dso );
170 if( i == _libraries.end( ))
174 const bool ret = deregister( i->second );
175 _libraries.erase( i );
LUNCHBOX_API void * getFunctionPointer(const std::string &functionName) const
Helper to access dynamic shared objects (DSO)
LUNCHBOX_API bool isOpen() const
DSOs load(const int version, const std::string &path, const std::string &pattern)
Load all compatible plugin libraries from a directory matching a pattern.
std::vector< std::string > Strings
A vector of std::strings.
PluginT * create(const InitDataT &initData)
Create a plugin instance.
#define LBINFO
Output an informational message to the per-thread Log.
Factory for Plugin classes.
LUNCHBOX_API Strings searchDirectory(const std::string &directory, const std::string &pattern)
Retrieve a list of files in a directory matching a boost::regex pattern.
#define LBERROR
Output an error message to the per-thread Log stream.
bool deregister(const Plugin< PluginT, InitDataT > &plugin)
Deregister a plugin type.
bool unload(DSO *dso)
Unload and deregister a previously loaded plugin.
Abstraction layer and common utilities for multi-threaded programming.
Manages a class deriving from a PluginT interface.
static PluginFactory & getInstance()
Get the single class instance.
void register_(const Plugin< PluginT, InitDataT > &plugin)
Register a plugin type.
void usort(C &c)
Uniquely sort and eliminate duplicates in a container.
#define LBTHROW(exc)
Log a std::exception if topic LOG_EXCEPTION is set before throwing exception.
void deregisterAll()
Unregister all plugin types.