void ppg_instrument_add_visualizer (PpgInstrument *instrument, const gchar *name) { PpgInstrumentPrivate *priv; PpgVisualizer *visualizer = NULL; PpgVisualizerFactory *factory; PpgVisualizer* (*factory_func) (gpointer user_data); gint i; g_return_if_fail(PPG_IS_INSTRUMENT(instrument)); g_return_if_fail(name != NULL); priv = instrument->priv; for (i = 0; i < priv->factories->len; i++) { factory = &g_array_index(priv->factories, PpgVisualizerFactory, i); if (g_str_equal(factory->entry->name, name)) { if ((factory_func = (gpointer)factory->entry->callback)) { visualizer = factory_func(factory->user_data); } } } if (visualizer) { g_signal_emit(instrument, signals[VISUALIZER_ADDED], 0, visualizer); } }
unsigned int IOFactory::findPlugins( const std::string &path ) { boost::filesystem::path p( path ); if ( !exists( p ) ) { LOG( Runtime, warning ) << util::MSubject( p ) << " not found"; return 0; } if ( !boost::filesystem::is_directory( p ) ) { LOG( Runtime, warning ) << util::MSubject( p ) << " is no directory"; return 0; } LOG( Runtime, info ) << "Scanning " << util::MSubject( p ) << " for plugins"; boost::regex pluginFilter( std::string( "^" ) + DL_PREFIX + "isisImageFormat_" + "[[:word:]]+" + DL_SUFFIX + "$", boost::regex::perl | boost::regex::icase ); unsigned int ret = 0; for ( boost::filesystem::directory_iterator itr( p ); itr != boost::filesystem::directory_iterator(); ++itr ) { if ( boost::filesystem::is_directory( *itr ) )continue; if ( boost::regex_match( itr->path().filename().string(), pluginFilter ) ) { const std::string pluginName = itr->path().native(); #ifdef WIN32 HINSTANCE handle = LoadLibrary( pluginName.c_str() ); #else void *handle = dlopen( pluginName.c_str(), RTLD_NOW ); #endif if ( handle ) { #ifdef WIN32 image_io::FileFormat* ( *factory_func )() = ( image_io::FileFormat * ( * )() )GetProcAddress( handle, "factory" ); #else image_io::FileFormat* ( *factory_func )() = ( image_io::FileFormat * ( * )() )dlsym( handle, "factory" ); #endif if ( factory_func ) { FileFormatPtr io_class( factory_func(), _internal::pluginDeleter( handle, pluginName ) ); if ( registerFileFormat( io_class ) ) { io_class->plugin_file = pluginName; ret++; } else { LOG( Runtime, warning ) << "failed to register plugin " << util::MSubject( pluginName ); } } else { #ifdef WIN32 LOG( Runtime, warning ) << "could not get format factory function from " << util::MSubject( pluginName ); FreeLibrary( handle ); #else LOG( Runtime, warning ) << "could not get format factory function from " << util::MSubject( pluginName ) << ":" << util::MSubject( dlerror() ); dlclose( handle ); #endif } } else #ifdef WIN32 LOG( Runtime, warning ) << "Could not load library " << util::MSubject( pluginName ); #else LOG( Runtime, warning ) << "Could not load library " << util::MSubject( pluginName ) << ":" << util::MSubject( dlerror() ); #endif } else { LOG( Runtime, verbose_info ) << "Ignoring " << *itr << " because it doesn't match " << pluginFilter.str(); } } return ret; }