]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkPackage.cxx
Merge branch 'wt-version'
[bbtk.git] / kernel / src / bbtkPackage.cxx
index 2df7c250ca08e9cdde24b5153be982bda7965b90..91cdb518372b220f124b1de33af8dc5c22c8912a 100644 (file)
@@ -1,25 +1,47 @@
-/*=========================================================================
-                                                                                
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  This software is governed by the CeCILL-B license under French law and
+ #  abiding by the rules of distribution of free software. You can  use,
+ #  modify and/ or redistribute the software under the terms of the CeCILL-B
+ #  license as circulated by CEA, CNRS and INRIA at the following URL
+ #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ #  or in the file LICENSE.txt.
+ #
+ #  As a counterpart to the access to the source code and  rights to copy,
+ #  modify and redistribute granted by the license, users are provided only
+ #  with a limited warranty  and the software's author,  the holder of the
+ #  economic rights,  and the successive licensors  have only  limited
+ #  liability.
+ #
+ #  The fact that you are presently reading this means that you have had
+ #  knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
+
+/*=========================================================================                                                                               
   Program:   bbtk
   Module:    $RCSfile: bbtkPackage.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/10/10 12:25:09 $
-  Version:   $Revision: 1.21 $
-                                                                                
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
-  l'Image). All rights reserved. See doc/license.txt or
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-                                                                                
-     This software is distributed WITHOUT ANY WARRANTY; without even
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-     PURPOSE.  See the above copyright notices for more information.
-                                                                                
+  Date:      $Date: 2012/11/16 08:49:01 $
+  Version:   $Revision: 1.37 $
 =========================================================================*/
+
+
+
 /**
  *\file
  *\brief Class bbtk::Package : registers black boxes descriptors and is able to create instances of the black boxes registered.
  */
 #include "bbtkPackage.h"
+#include "bbtkComplexBlackBoxDescriptor.h"
 #include "bbtkMessageManager.h"
 #include "bbtkConfigurationFile.h"
 #include <fstream>
@@ -36,16 +58,14 @@ namespace bbtk
   Package::Pointer Package::New(const std::string& name,
                                const std::string& author,
                                const std::string& description,
-                               const std::string& version,
-                               const std::string& BBTKVersion) 
+                               const std::string& version) 
   {
     bbtkDebugMessage("object",1,"##> Package::New('"<<name<<"',...)"
                     <<bbtkendl);
     Package::Pointer p = MakePointer(new Package(name,
                                               author,
                                               description,
-                                              version,
-                                              BBTKVersion));
+                                              version));
     bbtkDebugMessage("object",2,"<## Package::New('"<<name<<"',...)"
                     <<bbtkendl);
     return p;
@@ -57,8 +77,7 @@ namespace bbtk
   Package::Package(const std::string& name,
                   const std::string& author,
                   const std::string& description,
-                  const std::string& version,
-                  const std::string& BBTKVersion) 
+                  const std::string& version) 
     :
     mDynamicLibraryHandler(0),
     mName(name),
@@ -66,8 +85,10 @@ namespace bbtk
     mDescription(description),
     mVersion(version)
   {
-    bbtkDebugMessage("object",2,"==> Package::Package('"<<name<<"',...)"
+
+    bbtkDebugMessage("object",2,"==> Package('"<<name<<"',...)"
                     <<bbtkendl);
+
     std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
     char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
     std::string url = default_doc_dir; 
@@ -100,8 +121,7 @@ namespace bbtk
   /// Dtor
   Package::~Package()
   {
-    bbtkDebugMessage("object",2,"==> Package::~Package(\""<<mName<<"\")"<<bbtkendl);
-    bbtkDebugMessage("object",2,"<== Package::~Package(\""<<mName<<"\")"<<bbtkendl);
+    bbtkDebugMessage("object",2,"==> ~Package(\""<<mName<<"\")"<<bbtkendl);
   }
   //==========================================================================
 
@@ -112,20 +132,20 @@ namespace bbtk
   {
     // Try to release descriptor
     std::string packname = pack.lock()->GetName();
-
+    
     bbtkDebugMessage("package",5,"--- Releasing descriptor '"
                     <<packname<<"::"<<descname<<"'"<<bbtkendl);
-
-
-    Package::BlackBoxMapType::iterator desc = 
-      pack.lock()->GetBlackBoxMap().find(descname);
-    if (desc ==  pack.lock()->GetBlackBoxMap().end())
+    
+    
+    Package::DescriptorMapType::iterator desc = 
+      pack.lock()->GetDescriptorMap().find(descname);
+    if (desc ==  pack.lock()->GetDescriptorMap().end())
       {
        bbtkDebugMessage("package",5,
                         "    Descriptor has already been released"
-                        <<bbtkendl);
+                       <<bbtkendl);
        return;
-      }
+                 }
     //    bbtkDebugMessage("package",3,
     //              "    Trying unreferencing it ... "<<std::endl);
     BlackBoxDescriptor::WeakPointer pdesc = desc->second;
@@ -137,21 +157,18 @@ namespace bbtk
        if (pack.expired()) 
          {
            bbtkDebugMessage("package",2,
-                            "     ... and caused its package death"
+                             "     ... and caused its package death"
                             <<bbtkendl);
            return;
-         }
-       desc = pack.lock()->GetBlackBoxMap().find(descname);
-       if (desc !=  pack.lock()->GetBlackBoxMap().end())
-         pack.lock()->GetBlackBoxMap().erase(desc);
-      }
-    else 
-      {
-       bbtkDebugMessage("package",5,"    ... Descriptor still alive ("
-                        <<pdesc.use_count()<<" refs)"
-                        <<bbtkendl);
-       pack.lock()->GetBlackBoxMap()[descname] = pdesc.lock();
-      }
+         } // pack.expired
+       desc = pack.lock()->GetDescriptorMap().find(descname);
+       if (desc !=  pack.lock()->GetDescriptorMap().end())       pack.lock()->GetDescriptorMap().erase(desc);
+      }   else    {  //pdesc.expired
+      bbtkDebugMessage("package",5,"    ... Descriptor still alive ("
+                      <<pdesc.use_count()<<" refs)"
+                      <<bbtkendl);
+      pack.lock()->GetDescriptorMap()[descname] = pdesc.lock();
+    } // pdesc.expired
   }
   //==========================================================================
 
@@ -165,7 +182,7 @@ namespace bbtk
                     packname<<"')"<<bbtkendl);
 
     long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
-    long ndesc = pack.lock()->GetBlackBoxMap().size();
+    long ndesc = pack.lock()->GetDescriptorMap().size();
     long nrefs = pack.use_count();
 
     bbtkDebugMessage("package",5," "<<nrefs<<" refs / "
@@ -199,9 +216,9 @@ namespace bbtk
 
        // The list of descriptors names at start
        std::vector<std::string> descnamelist;
-       BlackBoxMapType::iterator i;
-       for (i=pack.lock()->mBlackBoxMap.begin();
-            i!= pack.lock()->mBlackBoxMap.end();
+       DescriptorMapType::iterator i;
+       for (i=pack.lock()->mDescriptorMap.begin();
+            i!= pack.lock()->mDescriptorMap.end();
             ++i)
          descnamelist.push_back(i->first);
 
@@ -219,19 +236,24 @@ namespace bbtk
                                 <<"') : package expired during release : bailing out"<<bbtkendl);
                break;
              }
-           
-           PackageReleaseBlackBoxDescriptorInternal(pack,*descname);
-           
+  
+#if defined(MACOSX)
+                 BlackBoxDescriptor::Pointer desc = pack.lock()->mDescriptorMap[*descname];
+                 if ( (dyn==0) || (boost::dynamic_pointer_cast<ComplexBlackBoxDescriptor>(desc)) )
+                 {
+                         PackageReleaseBlackBoxDescriptorInternal(pack,*descname);
+                 } 
+#else
+                 PackageReleaseBlackBoxDescriptorInternal(pack,*descname);
+#endif
+
          }
 
        //
        UnLoadDynamicLibrary(pack);
        // Unload orphan dl packages 
        Package::UnLoadReleasedDynamicallyLoadedPackages();
-       
 
-       
-       
       }
     
 #ifdef BBTK_COMPILE_DEBUG_MESSAGES
@@ -242,7 +264,7 @@ namespace bbtk
     if (!pack.expired())
       {
        long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
-       long ndesc = pack.lock()->GetBlackBoxMap().size();
+       long ndesc = pack.lock()->GetDescriptorMap().size();
        long nrefs = pack.use_count();
        
        bbtkDebugMessage("package",1," ... Package still alive ("
@@ -275,7 +297,7 @@ namespace bbtk
                     <<descr.use_count()<<bbtkendl);
 
     long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
-    long ndesc = pack.lock()->GetBlackBoxMap().size();
+    long ndesc = pack.lock()->GetDescriptorMap().size();
     long nrefs = pack.use_count();
 
     bbtkDebugMessage("package",5," "<<nrefs<<" refs / "
@@ -291,7 +313,13 @@ namespace bbtk
     //  and descallocated (reset) by PACKAGENAMEDeletePackage())
     if (nrefs == ndesc + dyn) 
       {
-       PackageReleaseBlackBoxDescriptorInternal(pack,dname);
+#if defined(MACOSX)
+                 //
+                 if (dyn==0)
+                         PackageReleaseBlackBoxDescriptorInternal(pack,dname);
+#else
+                 PackageReleaseBlackBoxDescriptorInternal(pack,dname);
+#endif 
       }
     
     // If the package is released and dynamically loaded 
@@ -305,7 +333,7 @@ namespace bbtk
     if (!pack.expired())
       {
        long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
-       long ndesc = pack.lock()->GetBlackBoxMap().size();
+       long ndesc = pack.lock()->GetDescriptorMap().size();
        long nrefs = pack.use_count();
        
        bbtkDebugMessage("package",3," ... Package still alive ("
@@ -330,11 +358,8 @@ namespace bbtk
   /// to test that a dyn lib is a valid bbtk package lib
   /// NB : The BBTK version exported from the library 
   ///      is tested against the current bbtk version
-  DynamicLibraryHandler Package::OpenDynamicLibrary
-  ( const std::string& libname,
-    const std::string& package_name,
-    DLGetPackageFunction& getpack,
-    DLDeletePackageFunction& delpack)
+  DynamicLibraryHandler Package::OpenDynamicLibrary( const std::string& libname,const std::string& package_name,
+                                                                                                        DLGetPackageFunction& getpack, DLDeletePackageFunction& delpack)
   {
     bbtkDebugMessage("package",3,"==> Package::OpenDynamicLibrary("
                     <<libname<<")"<<std::endl);
@@ -342,12 +367,13 @@ namespace bbtk
 
     // Open shared lib
     void *handler;
-    handler = dlopen(libname.c_str(),
-                    BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
+    handler = dlopen(libname.c_str(), BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
+//EED     handler = dlopen(libname.c_str(), RTLD_LAZY | RTLD_LOCAL );
+         
     if (!handler)
       {
-       bbtkMessage("package",2,
-                   "Could not open shared library [" <<libname<<"] : "
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading could not open shared library [" <<libname<<"] : "
                    <<dlerror() << std::endl);
        return 0;
       }
@@ -356,15 +382,13 @@ namespace bbtk
 
     // Loads the Package bbtk version function 
     std::string getvername(package_name);
-    getvername += 
-      BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
-    DLGetPackageBBTKVersionFunction getbbtkversion 
-      = (DLGetPackageBBTKVersionFunction)(dlsym(handler,getvername.c_str()));
+    getvername += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
+    DLGetPackageBBTKVersionFunction getbbtkversion  = (DLGetPackageBBTKVersionFunction)(dlsym(handler,getvername.c_str()));
     if (!getbbtkversion)
       {
        bbtkDebugMessage("package",3,"***"<<std::endl);
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<getvername<<"] :"<<dlerror()<< std::endl);
        dlclose(handler);
@@ -374,14 +398,16 @@ namespace bbtk
     bbtkDebugMessage("package",3,"* Symbol ["<<getvername
                     <<"] found"<<std::endl);
     // version matches ?
+
     if (getbbtkversion() != bbtk::GetVersion())
       {
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading: "<<package_name
+                       <<" - Shared library ["<<libname
                    <<"] was build with bbtk version "
                    <<getbbtkversion()
                    <<" but the current program runs with version "
-                   <<bbtk::GetVersion()<<" : cannot load it"<<std::endl);
+                   <<bbtk::GetVersion()<<" : cannot load it. You have to recompile your BBTK-Package."<<std::endl);
        dlclose(handler);
        return 0;
        
@@ -394,8 +420,8 @@ namespace bbtk
     getpack = (DLGetPackageFunction)(dlsym(handler, getpackname.c_str()));
     if (!getpack)
       {
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<getpackname<<"] :"<<dlerror()<< std::endl);
        dlclose(handler);
@@ -410,8 +436,8 @@ namespace bbtk
     delpack = (DLDeletePackageFunction)(dlsym(handler, delpackname.c_str()));
     if (!delpack)
       {
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<delpackname<<"] :"<<dlerror()<< std::endl);
        dlclose(handler);
@@ -427,8 +453,8 @@ namespace bbtk
     handler = LoadLibrary(libname.c_str());
     if (!handler)
       {
-       bbtkMessage("package",2,
-                   "Could not open shared library [" <<libname<<"]"
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR..  could not open shared library [" <<libname<<"]"
                    << std::endl);
        DWORD dwErrorCode = 0;
        dwErrorCode = GetLastError();
@@ -441,16 +467,14 @@ namespace bbtk
     
     // Loads the Package bbtk version function 
     std::string getvername(package_name);
-    getvername += 
-      BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
-    DLGetPackageBBTKVersionFunction getbbtkversion 
-      = (DLGetPackageBBTKVersionFunction)(GetProcAddress(handler,
-                                                       getvername.c_str()));
+    getvername += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
+    DLGetPackageBBTKVersionFunction getbbtkversion = (DLGetPackageBBTKVersionFunction)(GetProcAddress(handler, getvername.c_str()));
+         
     if (!getbbtkversion)
       {
        FreeLibrary(handler);
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<getbbtkversion<<"] not found"<< std::endl);
        return 0;
@@ -459,15 +483,15 @@ namespace bbtk
     // version matches ?
     if (getbbtkversion() != bbtk::GetVersion())
       {
-       FreeLibrary(handler);
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
-                   <<"] was build with bbtk version "
-                   <<getbbtkversion()
-                   <<" but the current program runs with version "
-                   <<bbtk::GetVersion()<<" : cannot load it"<<std::endl);
-       return 0;
-       
+                 FreeLibrary(handler);
+                 bbtkMessage("package",0,
+                               "BBTK ..ERROR.. loading: "<<package_name
+                               <<" - Shared library ["<<libname
+                               <<"] was build with bbtk version "
+                               <<getbbtkversion()
+                               <<" but the current program runs with version "
+                               <<bbtk::GetVersion()<<" : cannot load it. You have to recompile your BBTK-Package."<<std::endl);
+                 return 0;
       }
 
      // Loads the Package get function
@@ -477,8 +501,8 @@ namespace bbtk
     if (!getpack)
       {
        FreeLibrary(handler);
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<getpackname<<"] not found"<< std::endl);
        return 0;
@@ -491,8 +515,8 @@ namespace bbtk
     if (!delpack)
       {
        FreeLibrary(handler);
-       bbtkMessage("package",2,
-                   "Shared library ["<<libname
+       bbtkMessage("package",0,
+                   "BBTK ..ERROR.. loading shared library ["<<libname
                    <<"] is not a valid bbtk package."
                    <<" Symbol ["<<delpackname<<"] not found"<< std::endl);
        return 0;
@@ -554,25 +578,23 @@ namespace bbtk
   {
     if (pack.expired() || (!pack.lock()->mDynamicLibraryHandler))
       return;
-    
-    
+
     std::string packname = pack.lock()->GetName();
     bbtkDebugMessage("package",5,"==> Package::UnLoadDynamicLibrary('"
                     <<packname<<"')"
                     <<std::endl);
-    
-    if (!pack.lock()->GetBlackBoxMap().empty())
+
+    if (!pack.lock()->GetDescriptorMap().empty())
       {
-       
+
        bbtkDebugMessage("package",5,"   Package not empty ... abort"
                         <<std::endl);
        return;
        /*
        bbtkGlobalError("Package::UnLoadDynamicLibrary('"<<packname<<") : "
-                       <<"BlackBoxMap not empty "
+                       <<"DescriptorMap not empty "
                        <<BBTK_INTERNAL_ERROR_MESSAGE);
        */
-       
       }
 
     if (pack.use_count()!=1)
@@ -595,13 +617,11 @@ namespace bbtk
        bbtkDebugMessage("package",1,"==> package '"<<packname
                         <<"' put in the 'to unload' list"
                         <<std::endl);
-
       }
 
     bbtkDebugMessage("package",5,"<== Package::UnLoadDynamicLibrary('"
                     <<packname<<"')"
-                    <<std::endl);
-    
+                    <<std::endl); 
   }
   //==========================================================================
 
@@ -613,12 +633,17 @@ namespace bbtk
     bbtkDebugMessage("package",5,"==> Package::UnLoadReleasedDynamicallyLoadedPackages()"<<std::endl);
 
     std::set<Package::WeakPointer>::iterator i;
-    for (i=mReleasedDynamicallyLoadedPackages.begin();
-        i!=mReleasedDynamicallyLoadedPackages.end();
-        ++i)
-      {
-       if (!i->expired()) UnLoad(*i);
-      }
+
+//JCP- 21-04-09
+       if(mReleasedDynamicallyLoadedPackages.size()>0){
+               for (i=mReleasedDynamicallyLoadedPackages.begin();
+               i!=mReleasedDynamicallyLoadedPackages.end();
+               ++i)
+               {
+               if (!i->expired()) UnLoad(*i);
+               }
+       }
+//JCP- 21-04-09
     bbtkDebugMessage("package",5,"<== Package::UnLoadReleasedDynamicallyLoadedPackages()"<<std::endl);
   }
   //==========================================================================
@@ -638,7 +663,13 @@ namespace bbtk
     
     // closes the dl handler
 #if defined(__GNUC__)  
-    dlclose(h);  
+         if (dlclose(h)!=0)
+         {
+                 printf("EED Package::UnLoad ERROR %s\n", packname.c_str() );
+                 bbtkWarning("Failed to close dynamic library for package '"<<packname
+                                         <<"'"<<std::endl);
+         }  
+         
 #elif defined(_WIN32)
     FreeLibrary(h);
 #endif
@@ -650,21 +681,32 @@ namespace bbtk
   }
   //==========================================================================
 
+       bool Package::ifBoxExist( std::string type)     
+    {
+               bool ok=false;
+               DescriptorMapType::const_iterator i = mDescriptorMap.find(type);
+               if (i != mDescriptorMap.end())  
+               {
+                       ok=true;
+               }
+               return ok;
+    }
+       
   //==========================================================================
   /// Creates an instance of a black box of type <type> with name <name>
   BlackBox::Pointer Package::NewBlackBox(const std::string& type, 
                                         const std::string& name) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<">::NewBlackBox(\""<<type<<"\",\""<<name<<"\")"<<bbtkendl);
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<">::NewBlackBox(\""<<type<<"\",\""<<name<<"\")"<<bbtkendl);
     
-    BlackBoxMapType::const_iterator i = mBlackBoxMap.find(type);
-    if (i == mBlackBoxMap.end())  
+    DescriptorMapType::const_iterator i = mDescriptorMap.find(type);
+    if (i == mDescriptorMap.end())  
     {
-          bbtkDebugDecTab("Kernel",8);
+          bbtkDebugDecTab("kernel",8);
           return BlackBox::Pointer();
     }
     BlackBox::Pointer bb =i->second->NewBlackBox(name);
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return bb;   
 
   }
@@ -679,7 +721,7 @@ namespace bbtk
                                const DataInfo& typeout,
                                const std::string& name) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
                        ">::NewAdaptor("
                        <<typein<<","
                        <<typeout<<",\""
@@ -690,11 +732,11 @@ namespace bbtk
     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
     if (i == mAdaptorMap.end())  
       {
-       bbtkDebugDecTab("Kernel",8);
+       bbtkDebugDecTab("kernel",8);
        return BlackBox::Pointer();
       }
     BlackBox::Pointer bb =i->second.lock()->NewBlackBox(name);
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return bb;   
 
   }
@@ -707,7 +749,7 @@ namespace bbtk
                                      const DataInfo& typeout,
                                      const std::string& name) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
                        ">::NewWidgetAdaptor("
                        <<typein<<","
                        <<typeout<<",\""
@@ -718,11 +760,11 @@ namespace bbtk
     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
     if (i == mAdaptorMap.end())  
       {
-       bbtkDebugDecTab("Kernel",8);
+       bbtkDebugDecTab("kernel",8);
        return BlackBox::Pointer();
       }
     BlackBox::Pointer bb =i->second.lock()->NewBlackBox(name);
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return bb;   
 
   }
@@ -739,7 +781,7 @@ namespace bbtk
                                  const DataInfo& typeout,
                                  std::string& adaptor) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
                        ">::FindWidgetAdaptor("
                        <<typein<<","
                        <<typeout<<")"<<bbtkendl);
@@ -752,11 +794,11 @@ namespace bbtk
     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
     if (i == mAdaptorMap.end())  
       {
-       bbtkDebugDecTab("Kernel",8);
+       bbtkDebugDecTab("kernel",8);
        return false;
       }
     adaptor = i->second.lock()->GetTypeName();
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return true;   
 
   }
@@ -773,7 +815,7 @@ namespace bbtk
                            const DataInfo& typeout,
                            std::string& adaptor) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
                        ">::FindAdaptor("
                        <<typein<<","
                        <<typeout<<")"<<bbtkendl);
@@ -783,11 +825,11 @@ namespace bbtk
     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
     if (i == mAdaptorMap.end())  
       {
-       bbtkDebugDecTab("Kernel",8);
+       bbtkDebugDecTab("kernel",8);
        return false;
       }
     adaptor = i->second.lock()->GetTypeName();
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return true;   
 
   }
@@ -796,26 +838,26 @@ namespace bbtk
 
   //==========================================================================
   /// Registers a black box descriptor in the package
-  bool Package::RegisterBlackBox(BlackBoxDescriptor::Pointer d) 
+  bool Package::Register(BlackBoxDescriptor::Pointer d) 
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<">::RegisterBlackBox(\""<<d->GetTypeName()<<"\")"<<std::endl);
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\")"<<std::endl);
     
-    BlackBoxMapType::iterator i = mBlackBoxMap.find(d->GetTypeName());
-    if (i!=mBlackBoxMap.end())
+    DescriptorMapType::iterator i = mDescriptorMap.find(d->GetTypeName());
+    if (i!=mDescriptorMap.end())
       {
        bbtkWarning("Package<"<<GetName()<<"> : Trying to register box type <"
                    <<d->GetTypeName()<<"> which is already in the package");
        return false;
       }
 
-    mBlackBoxMap[d->GetTypeName()] = d;
+    mDescriptorMap[d->GetTypeName()] = d;
     //    d->Reference();
     d->SetPackage(GetThisPointer<Package>());
     
     // If it is a default adaptor, also register it in the adaptors map
     if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR )
       {
-       bbtkDebugMessage("Kernel",8,"Package<"<<GetName()<<">::RegisterBlackBox(\""<<d->GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<<std::endl);   
+       bbtkDebugMessage("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<<std::endl);   
        
        TypeInfo typein = d->GetInputDescriptor("In")->GetTypeInfo();
        TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo();
@@ -845,7 +887,7 @@ namespace bbtk
     // If it is a default adaptor, also register it in the adaptors map
     else if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_GUI)
       {
-       bbtkDebugMessage("Kernel",8,"Package<"<<GetName()<<">::RegisterBlackBox(\""<<d->GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<<std::endl);   
+       bbtkDebugMessage("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<<std::endl);   
        
        TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo();
        DataInfo infoin(typeid(void),"");
@@ -873,20 +915,20 @@ namespace bbtk
       }
     
 
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
    
     return true;
   }
   //==========================================================================
   
   //===================================================================
-  void Package::CheckBoxes() const
+  void Package::Check() const
   {
     bbtkMessage("debug",1,"****** Checking Package "<<(void*)this
                <<" ["<<GetName()<<"]"<<std::endl);
-    BlackBoxMapType::const_iterator i;
-    for (i=mBlackBoxMap.begin();
-        i!=mBlackBoxMap.end();
+    DescriptorMapType::const_iterator i;
+    for (i=mDescriptorMap.begin();
+        i!=mDescriptorMap.end();
         ++i) 
       {
        i->second->Check(true);
@@ -899,39 +941,40 @@ namespace bbtk
 
   //==========================================================================
   /// Changes the name of a black box type
-  void Package::ChangeBlackBoxName( const std::string& oldname, const std::string& newname )
+  void Package::ChangeDescriptorName( const std::string& oldname, const std::string& newname )
   { 
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<">::ChangeBlackBoxName(\""<<oldname<<"\",\""<<newname<<"\")"<<std::endl);
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
+                       <<">::ChangeDescriptorName(\""<<oldname
+                       <<"\",\""<<newname<<"\")"<<std::endl);
     // Looking into the bb map
-    BlackBoxMapType::iterator i = mBlackBoxMap.find(oldname);
-    if (i == mBlackBoxMap.end())  
+    DescriptorMapType::iterator i = mDescriptorMap.find(oldname);
+    if (i == mDescriptorMap.end())  
       {
-         bbtkDebugDecTab("Kernel",8);
-         bbtkError("ChangeBlackBoxName : The package <"<<GetName()<<"> does not contains the black box <"<<oldname<<">");
+         bbtkDebugDecTab("kernel",8);
+         bbtkError("ChangeDescriptorName : The package <"<<GetName()<<"> does not contains the black box <"<<oldname<<">");
       }
 
     i->second->SetTypeName(newname);
-    mBlackBoxMap[newname] = i->second;
-    mBlackBoxMap.erase(i);
+    mDescriptorMap[newname] = i->second;
+    mDescriptorMap.erase(i);
 
-    bbtkDebugDecTab("Kernel",8);    
+    bbtkDebugDecTab("kernel",8);    
   }
   //==========================================================================
 
 
 
   //==========================================================================
-  /// Displays the list of black boxes of the package
-  void Package::PrintBlackBoxes(bool description, bool adaptors) const
+  void Package::PrintHelpListDescriptors(bool description, bool adaptors) const
   {
     unsigned int lmax = 0;
     std::vector<std::string> names;
     std::vector<std::string> kinds;
     std::vector<std::string> descrs;
 
-    BlackBoxMapType::const_iterator i;
-    for (i=mBlackBoxMap.begin();
-        i!=mBlackBoxMap.end();
+    DescriptorMapType::const_iterator i;
+    for (i=mDescriptorMap.begin();
+        i!=mDescriptorMap.end();
         ++i) 
       {
        if ( adaptors || 
@@ -975,15 +1018,15 @@ namespace bbtk
       {
        std::string space;
        space.append(lmax - ni->size() - ci->size(),' ');
-       bbtkMessage("Help",1,*ni << space << *ci );
+       bbtkMessage("help",1,*ni << space << *ci );
        std::string d(*di);
        unsigned int dmax = 75 - lmax;
        //      while (d.size() > dmax ) 
        //  {
        if (d.size()>dmax) 
-         bbtkMessage("Help",1,d.substr(0,dmax) << "..." << std::endl);
+         bbtkMessage("help",1,d.substr(0,dmax) << "..." << std::endl);
        else 
-         bbtkMessage("Help",1,d << std::endl);
+         bbtkMessage("help",1,d << std::endl);
        //    d = d.substr(dmax,d.size());
        //  }
       }
@@ -993,30 +1036,30 @@ namespace bbtk
 
   //==========================================================================
   /// Displays the list of adaptors of the package
-  void Package::PrintAdaptors(bool description) const
+  void Package::PrintHelpListAdaptors(bool description) const
   {
-    BlackBoxMapType::const_iterator i;
-    for (i=mBlackBoxMap.begin();
-        i!=mBlackBoxMap.end();
+    DescriptorMapType::const_iterator i;
+    for (i=mDescriptorMap.begin();
+        i!=mDescriptorMap.end();
         ++i) 
       {
        if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD ) 
          {
-           bbtkMessage("Help",1,
+           bbtkMessage("help",1,
                        "  "<<i->second->GetTypeName());
            if ( i->second->GetKind() == 
                 BlackBoxDescriptor::DEFAULT_ADAPTOR )
              {
-               bbtkMessage("Help",1,
+               bbtkMessage("help",1,
                            " [default]");
              }  
            if (description) 
              {
-               bbtkMessage("Help",1,
+               bbtkMessage("help",1,
                            " : "<<i->second->GetDescription());
 
              } 
-           bbtkMessage("Help",1,std::endl);
+           bbtkMessage("help",1,std::endl);
          }
       } 
     /*
@@ -1025,36 +1068,37 @@ namespace bbtk
         i!=mAdaptorMap.end();
         ++i) 
       {
-       bbtkMessage("Help",1,
+       bbtkMessage("help",1,
                    "  "<<i->second->GetTypeName());
        if (detail_level>0) 
          {
-           bbtkMessage("Help",1,
+           bbtkMessage("help",1,
                        " : "<<i->second->GetDescription());
   
          } 
-       bbtkMessage("Help",1,std::endl);
+       bbtkMessage("help",1,std::endl);
       }
     */ 
   }
   //==========================================================================
 
   //==========================================================================
-  /// Prints help on a black box
-  void Package::HelpBlackBox(const std::string& name, bool full) const
+  /// Prints help on a black box descriptor
+  void Package::PrintHelpDescriptor(const std::string& name, bool full) const
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<">::HelpBlackBox(\""
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
+                       <<">::PrintHelpDescriptor(\""
                        <<name<<"\")"<<bbtkendl);
 
-    BlackBoxMapType::const_iterator i = mBlackBoxMap.find(name);
-    if (i == mBlackBoxMap.end())  
+    DescriptorMapType::const_iterator i = mDescriptorMap.find(name);
+    if (i == mDescriptorMap.end())  
       {
-       bbtkDebugDecTab("Kernel",8);
+       bbtkDebugDecTab("kernel",8);
        bbtkError("The package <"<<GetName()<<"> does not contains the black box <"<<name<<">");
       }
-    //    bbtkMessage("Help",1,"["<<GetName()<<"] ");
+    //    bbtkMessage("help",1,"["<<GetName()<<"] ");
     i->second->GetHelp(full);
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
 
   }
   //==========================================================================
@@ -1062,18 +1106,19 @@ namespace bbtk
 
   //==========================================================================
   /// Returns true iff the package contains the box of name boxname
-  bool Package::ContainsBlackBox(const std::string& name) const 
+  bool Package::ContainsDescriptor(const std::string& name) const 
   {
-    bbtkDebugMessageInc("Kernel",8,"Package<"<<GetName()<<">::HelpBlackBox(\""
+    bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
+                       <<">::ContainsDescriptor(\""
                        <<name<<"\")"<<bbtkendl);
     
-    BlackBoxMapType::const_iterator i = mBlackBoxMap.find(name);
-    if (i == mBlackBoxMap.end())  
+    DescriptorMapType::const_iterator i = mDescriptorMap.find(name);
+    if (i == mDescriptorMap.end())  
     {
-      bbtkDebugDecTab("Kernel",8);
+      bbtkDebugDecTab("kernel",8);
       return false;
     }
-    bbtkDebugDecTab("Kernel",8);
+    bbtkDebugDecTab("kernel",8);
     return true;
   }
   //==========================================================================
@@ -1090,9 +1135,11 @@ namespace bbtk
                               int level,
                               bool relative_link ) const
   {
-    bbtkDebugMessageInc("Kernel",9,"Package<"<<GetName()<<">::CreateHtmlPage(\""
+    bbtkDebugMessageInc("kernel",9,"Package<"<<GetName()<<">::CreateHtmlPage(\""
                        <<filename<<"\")"<<bbtkendl);
 
+//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1133"<<std::endl;
+
     //---------------------
     // Open output file
     std::ofstream s;
@@ -1183,7 +1230,7 @@ namespace bbtk
          << bbtk::GetVersion() << "</TD></TR>\n";
        s << "</TABLE>\n";
       }
-
+//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1225"<<std::endl;
     //-------------------
     // Table of contents
     // Black boxes list
@@ -1193,65 +1240,65 @@ namespace bbtk
 
     s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
 
-    BlackBoxMapType::const_iterator i;
-    for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i) 
-      {
-       if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD) 
-         continue;
+    DescriptorMapType::const_iterator i;
+//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1236"<<std::endl;
+    for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i) {
+               if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD) 
+                       continue;
        
-       std::string name = i->second->GetTypeName();
-       Utilities::html_format(name);
-       std::string descr = i->second->GetDescription();
-       //Utilities::html_format(descr);
-
-        s << "<TR>";
-       s << "<TD style='vertical-align: top;'>";
-       s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
-         <<"\" href=\"#"<<name<<"\">"
-         <<name<<"</a>";
-       s << "</TD> ";
-       s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
-        s << "</TR>\n";
-      }    
-    s << "</TABLE>\n";
+               std::string name = i->second->GetTypeName();
+               Utilities::html_format(name);
+               std::string descr = i->second->GetDescription();
+               //Utilities::html_format(descr);
+//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1246"<<std::endl;
+               s << "<TR>";
+               s << "<TD style='vertical-align: top;'>";
+               s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
+               <<"\" href=\"#"<<name<<"\">"
+               <<name<<"</a>";
+               s << "</TD> ";
+               s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
+               s << "</TR>\n";
+               }    
+               s << "</TABLE>\n";
+
+
+               s << "</ul>\n";
+               s << "</div>\n";
     
+               //-------------------
+               // Adaptors list
+               if (mAdaptorMap.size()>0) 
+               {
+                       //  s << "<div class=\"contents\">\n";
+                       s << "<p><b> Adaptors : </b>\n";
+                       s << "<ul>\n";
+//std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1268"<<std::endl;
+                       //    DescriptorMapType::const_iterator i;
+                       s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
+                       for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end();++i) 
+                       {
+                               if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) 
+                                       continue;
     
-    s << "</ul>\n";
-    s << "</div>\n";
-    
-    //-------------------
-    // Adaptors list
-    if (mAdaptorMap.size()>0) 
-      {
-       //  s << "<div class=\"contents\">\n";
-       s << "<p><b> Adaptors : </b>\n";
-       s << "<ul>\n";
-
-       //    BlackBoxMapType::const_iterator i;
-       s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
-       for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end();++i) 
-         {
-           if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) 
-             continue;
-    
-           std::string name = i->second->GetTypeName();
-           Utilities::html_format(name);
-           std::string descr = i->second->GetDescription();
-    
-           s << "<TR>";
-           s << "<TD style='vertical-align: top;'>";
-           s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
-             <<"\" href=\"#"<<name<<"\">"
-             <<name<<"</a>";
-           s << "</TD> ";
-           s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
-           s << "</TR>\n";
-         }    
-       s << "</TABLE>\n";
-
-       s << "</ul>\n";
-       s << "</div>\n";
-      }
+                               std::string name = i->second->GetTypeName();
+                               Utilities::html_format(name);
+                               std::string descr = i->second->GetDescription();
+                   
+                               s << "<TR>";
+                               s << "<TD style='vertical-align: top;'>";
+                               s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
+                                 <<"\" href=\"#"<<name<<"\">"
+                                 <<name<<"</a>";
+                               s << "</TD> ";
+                               s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
+                               s << "</TR>\n";
+                       }    
+                       s << "</TABLE>\n";
+
+                       s << "</ul>\n";
+                       s << "</div>\n";
+               }
     
     
     //  s << "<div class=\"node\">\n";
@@ -1270,23 +1317,23 @@ namespace bbtk
     //-------------------
     // Computes output directory from filename to pass it to 
     // BlackBoxDescriptor::InsertHtmlHelp
-    std::string dir;
+               std::string dir;
 
-    std::string::size_type slash_position = filename.find_last_of("/\\");
+               std::string::size_type slash_position = filename.find_last_of("/\\");
 
 
-       if (slash_position != std::string::npos) {
-      if (slash_position == 0)
-         slash_position = 1;  
-      dir = filename.substr(0,slash_position);
-    }
+               if (slash_position != std::string::npos) {
+                       if (slash_position == 0)
+                        slash_position = 1;  
+                       dir = filename.substr(0,slash_position);
+               }
 
-    for (i=mBlackBoxMap.begin();
-        i!=mBlackBoxMap.end();
-        ++i) 
-      {
-       i->second->InsertHtmlHelp(s,detail,level,dir,relative_link);
-      }    
+               for (i=mDescriptorMap.begin();
+                i!=mDescriptorMap.end();
+                ++i) 
+               {
+                       i->second->InsertHtmlHelp(s,detail,level,dir,relative_link);
+               }    
 
     //----------------------
     // Footer 
@@ -1306,7 +1353,7 @@ namespace bbtk
     //----------------------
 
     // End
-    bbtkDebugDecTab("Kernel",9);
+    bbtkDebugDecTab("kernel",9);
   }
   //==========================================================================
   
@@ -1321,7 +1368,7 @@ namespace bbtk
   std::string Package::GetObjectInfo() const 
   {
     std::stringstream i;
-    i << "  - "<<mBlackBoxMap.size() << " boxes" << std::endl;
+    i << "  - "<<mDescriptorMap.size() << " boxes" << std::endl;
     if (mDynamicLibraryHandler) 
       {
        i<< "  - Loaded from dynamic library"<<std::endl;
@@ -1352,18 +1399,29 @@ namespace bbtk
     size_t s = Superclass::GetObjectRecursiveSize();
     s += Package::GetObjectInternalSize();
     
-    BlackBoxMapType::const_iterator i;
-    for (i = mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i )
+    DescriptorMapType::const_iterator i;
+    for (i = mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i )
       {
        s += i->second->GetObjectRecursiveSize();
       }
     return s;
   }
   //==========================================================================
-  
+  void  Package::GetBoxesInside(NodeTreeC& tree, int cont) 
+  {
+               DescriptorMapType::const_iterator i;
+               std::cout<<"*********a********"<<std::endl;
+               for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i) 
+               {
+                       i->second->GetBoxesInside(tree, cont);
+                       std::cout<<"*****************"<<std::endl;
+               }    
+  }
+       //==========================================================================
   //==========================================================================
   std::set<Package::WeakPointer> 
   Package::mReleasedDynamicallyLoadedPackages;
   //==========================================================================
+
 }