SET(
examples_SOURCES
+ example_GuessPlugins
example_LoadPluginsFile
example_LoadPluginsDirectory
example_ReadWriteImage
--- /dev/null
+#include <iostream>
+#include <cpPlugins/Interface.h>
+
+int main( int argc, char* argv[] )
+{
+ // Load interface
+ cpPlugins::Interface interface;
+ interface.GuessAccesiblePlugins( );
+
+ // Show loaded filters
+ auto filters = interface.GetFilters( );
+ for( auto cIt = filters.begin( ); cIt != filters.end( ); ++cIt )
+ {
+ std::cout << "Category: " << cIt->first << std::endl;
+ for( auto nIt = cIt->second.begin( ); nIt != cIt->second.end( ); ++nIt )
+ std::cout
+ << "\tFilter: " << *nIt
+ << std::endl;
+
+ } // rof
+ return( 0 );
+}
+
+// eof - $RCSfile$
int main( int argc, char* argv[] )
{
- if( argc < 4 )
+ if( argc < 3 )
{
std::cerr
<< "Usage: " << argv[ 0 ]
- << " plugins_library input_image(s) output_image" << std::endl;
+ << " input_image(s) output_image" << std::endl;
return( 1 );
} // fi
// Load interface
int ret = 0;
cpPlugins::Interface interface;
- try
- {
- interface.LoadPluginFile( argv[ 1 ] );
- }
- catch( std::exception& err )
- {
- std::cerr
- << "Interface load failed on \"" << argv[ 1 ] << "\": "
- << err.what( )
- << std::endl;
- ret = 1;
-
- } // fi
+ interface.GuessAccesiblePlugins( );
// Create filters
cpPlugins::ProcessObject::Pointer reader;
if( reader.IsNull( ) )
{
std::cerr
- << "\"IO::ImageReader\" creation failed from \""
- << argv[ 1 ] << "\""
+ << "\"IO::ImageReader\" creation failed."
<< std::endl;
ret = 1;
if( writer.IsNull( ) )
{
std::cerr
- << "\"IO::ImageWriter\" creation failed from \""
- << argv[ 1 ] << "\""
+ << "\"IO::ImageWriter\" creation failed."
<< std::endl;
ret = 1;
catch( std::exception& err )
{
std::cerr
- << "Filter creation failed on \"" << argv[ 1 ] << "\": "
+ << "Filter creation failed: "
<< err.what( )
<< std::endl;
ret = 1;
{
// Configure filters
auto reader_params = reader->GetParameters( );
- for( int i = 2; i < argc - 1; ++i )
+ for( int i = 1; i < argc - 1; ++i )
reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] );
auto writer_params = writer->GetParameters( );
writer_params->SetSaveFileName( "FileName", argv[ argc - 1 ] );
int main( int argc, char* argv[] )
{
- if( argc < 4 )
+ if( argc < 3 )
{
std::cerr
<< "Usage: " << argv[ 0 ]
- << " plugins_library input_image(s) output_image" << std::endl;
+ << " input_image(s) output_image" << std::endl;
return( 1 );
} // fi
// Load interface
int ret = 0;
cpPlugins::Interface interface;
- try
- {
- interface.LoadPluginFile( argv[ 1 ] );
- }
- catch( std::exception& err )
- {
- std::cerr
- << "Interface load failed on \"" << argv[ 1 ] << "\": "
- << err.what( )
- << std::endl;
- ret = 1;
-
- } // fi
+ interface.GuessAccesiblePlugins( );
// Create filters
cpPlugins::Workspace workspace;
// Configure filters
auto reader_params = reader->GetParameters( );
- for( int i = 2; i < argc - 1; ++i )
+ for( int i = 1; i < argc - 1; ++i )
reader_params->AddToOpenFileNameList( "FileNames", argv[ i ] );
auto writer_params = writer->GetParameters( );
writer_params->SetSaveFileName( "FileName", argv[ argc - 1 ] );
m_TreeWidget( NULL ),
m_Editor( NULL )
{
- // Prepare plugins interface
+ this->m_Interface.GuessAccesiblePlugins( );
+
QFileInfo info( argv[ 0 ] );
if( info.exists( ) )
{
- this->m_Interface.LoadConfiguration( cpPlugins_CONFIG_FILE );
- this->_LoadPluginsFromPath( this->m_PluginsPath );
- this->m_PluginsPath = info.canonicalPath( ).toStdString( );
-
- } // fi
- QDir exec_dir( "." );
- if( exec_dir.exists( ) )
- {
- this->_LoadPluginsFromPath( exec_dir.canonicalPath( ).toStdString( ) );
- this->m_PluginsPath = exec_dir.canonicalPath( ).toStdString( );
+ auto exec_dir = info.canonicalPath( ).toStdString( );
+ this->_LoadPluginsFromPath( exec_dir );
} // fi
+ this->_UpdateLoadedPlugins( );
// Prepare workspace
this->m_Workspace.SetInterface( &( this->m_Interface ) );
return( this->m_Filters );
}
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::
+GuessAccesiblePlugins( )
+{
+ // Load environment configuration
+ char* path = std::getenv( "cpPlugins_PATHS" );
+ if( path != NULL )
+ {
+ std::vector< std::string > tokens;
+ cpPlugins::TokenizeString( tokens, path, "#" );
+ for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt )
+ try { this->LoadPluginDir( *tIt ); } catch( ... ) { }
+
+ } // fi
+
+ // Load local path
+ auto lpath = cpPlugins::CanonicalPath( "." );
+ try { this->LoadPluginDir( lpath ); } catch( ... ) { }
+}
+
// -------------------------------------------------------------------------
bool cpPlugins::Interface::
LoadConfiguration( const std::string& filename )
this->UnloadAll( );
std::string line;
while( std::getline( in, line ) )
- {
- try
- {
- this->LoadPluginFile( line );
- }
- catch( ... )
- {
- // Do nothing
-
- } // yrt
-
- } // elihw
+ try { this->LoadPluginFile( line ); } catch( ... ) { }
return( true );
}
);
count++;
}
- catch( ... )
- {
- // Ignore errors
- } // yrt
+ catch( ... ) { }
+
} // elihw
closedir( dir );
}
const TFilters& GetFilters( );
+ void GuessAccesiblePlugins( );
+
bool LoadConfiguration( const std::string& filename );
bool SaveConfiguration( const std::string& filename ) const;
void LoadPluginFile( const std::string& filename );