]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 20 Mar 2016 21:40:38 +0000 (16:40 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Sun, 20 Mar 2016 21:40:38 +0000 (16:40 -0500)
lib/cpPlugins/Interface.cxx
lib/cpPlugins/Interface.h

index 6c6e0f8f66812db1e601fb2287359c32d78cd6bf..58e468d29e114cc2b802a22fab6cb1b8f90d07f2 100644 (file)
@@ -80,6 +80,12 @@ LoadPluginFile( const std::string& filename )
       filename +
       std::string( "\" does not exist." )
       );
+
+  // Check if it was already loaded
+  if( this->m_DynLibraries.find( canonical_fn ) != this->m_DynLibraries.end( ) )
+    return;
+
+  // Ok, try to load the library
   void* hnd = Self::_DLOpen( canonical_fn );
   if( hnd == NULL )
     throw std::runtime_error(
@@ -136,21 +142,34 @@ LoadPluginFile( const std::string& filename )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::Interface::
+unsigned int cpPlugins::Interface::
 LoadPluginDir( const std::string& dirname )
 {
-#error ACA VOY
-  DIR *dir;
-  struct dirent *ent;
-  if( (dir = opendir ( dirname.c_str( ) ) ) != NULL)
+  DIR* dir;
+  struct dirent* ent;
+  unsigned int count = 0;
+  if( ( dir = opendir( dirname.c_str( ) ) ) != NULL )
   {
-    while ((ent = readdir (dir)) != NULL) {
-      printf ("%s\n", ent->d_name);
-    }
-    closedir (dir);
-  } else {
-    std::cerr << "error" << std::endl;
+    while( ( ent = readdir( dir ) ) != NULL )
+    {
+      try
+      {
+        this->LoadPluginFile( ent->d_name );
+        count++;
+      }
+      catch( ... )
+      {
+        // Ignore errors
+      } // yrt
+    } // elihw
+    closedir( dir );
   }
+  else
+    throw std::runtime_error(
+      std::string( "cpPlugins::Interface: Could not load directory " ) +
+      std::string( "\"" ) +  dirname + std::string( "\"" )
+      );
+  return( count );
 }
 
 // -------------------------------------------------------------------------
index 7c9681a06175e83c6c511ff622d45eceaaf86291..451c0e07e062c66989ca3f6c8c101719d20dc3e6 100644 (file)
@@ -32,7 +32,7 @@ namespace cpPlugins
     bool LoadConfiguration( const std::string& filename );
     bool SaveConfiguration( const std::string& filename ) const;
     void LoadPluginFile( const std::string& filename );
-    void LoadPluginDir( const std::string& dirname );
+    unsigned int LoadPluginDir( const std::string& dirname );
     void UnloadAll( );
 
     cpPlugins::ProcessObject::Pointer Create(