]> Creatis software - bbtk.git/blob - kernel/src/bbtkPackage.cxx
#2536 BBTK Feature New Normal wt-version Package
[bbtk.git] / kernel / src / bbtkPackage.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28
29 /*=========================================================================                                                                               
30   Program:   bbtk
31   Module:    $RCSfile: bbtkPackage.cxx,v $
32   Language:  C++
33   Date:      $Date: 2012/11/16 08:49:01 $
34   Version:   $Revision: 1.37 $
35 =========================================================================*/
36
37
38
39 /**
40  *\file
41  *\brief Class bbtk::Package : registers black boxes descriptors and is able to create instances of the black boxes registered.
42  */
43 #include "bbtkPackage.h"
44 #include "bbtkComplexBlackBoxDescriptor.h"
45 #include "bbtkMessageManager.h"
46 #include "bbtkConfigurationFile.h"
47 #include <fstream>
48 #include <time.h>
49 #include "bbtkUtilities.h"
50
51 namespace bbtk
52 {
53   
54
55
56   //==========================================================================
57   /// Creates a new package
58   Package::Pointer Package::New(const std::string& name,
59                                 const std::string& author,
60                                 const std::string& description,
61                                 const std::string& version) 
62   {
63     bbtkDebugMessage("object",1,"##> Package::New('"<<name<<"',...)"
64                      <<bbtkendl);
65     Package::Pointer p = MakePointer(new Package(name,
66                                                author,
67                                                description,
68                                                version));
69     bbtkDebugMessage("object",2,"<## Package::New('"<<name<<"',...)"
70                      <<bbtkendl);
71     return p;
72   }
73   //==========================================================================
74
75   //==========================================================================
76   /// Ctor with the name of the package
77   Package::Package(const std::string& name,
78                    const std::string& author,
79                    const std::string& description,
80                    const std::string& version) 
81     :
82     mDynamicLibraryHandler(0),
83     mName(name),
84     mAuthor(author),
85     mDescription(description),
86     mVersion(version)
87   {
88
89     bbtkDebugMessage("object",2,"==> Package('"<<name<<"',...)"
90                      <<bbtkendl);
91
92     std::string default_doc_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
93     char c = default_doc_dir.c_str()[strlen(default_doc_dir.c_str())-1];
94     std::string url = default_doc_dir; 
95     if (c != '/' && c !='\\') url = url + "/";
96     url = url +  "temp_dir/" + name + "/index.html";    
97     
98     SetDocURL(url);
99     SetDocRelativeURL("Relative url not set");
100
101     /*
102     std::string relurl(BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH));
103     relurl += "/packages/"+name+"/bbdoc/index.html";
104     std::string url = ConfigurationFile::GetInstance().Get_url()
105       + relurl; 
106     SetDocURL(url);
107     SetDocRelativeURL(relurl);   
108     */
109
110     //    std::cout  << "   url=["<<url<<"]"<<std::endl;
111     //    std::cout  << "relurl=["<<relurl<<"]"<<std::endl;
112     bbtkDebugMessage("object",2,"<== Package::Package('"<<name<<"',...) OK"
113                      <<bbtkendl);
114
115   }
116   //==========================================================================
117
118
119
120   //==========================================================================
121   /// Dtor
122   Package::~Package()
123   {
124     bbtkDebugMessage("object",2,"==> ~Package(\""<<mName<<"\")"<<bbtkendl);
125   }
126   //==========================================================================
127
128
129   //==========================================================================
130   void PackageReleaseBlackBoxDescriptorInternal(Package::WeakPointer pack,
131                                                 const std::string& descname)
132   {
133     // Try to release descriptor
134     std::string packname = pack.lock()->GetName();
135     
136     bbtkDebugMessage("package",5,"--- Releasing descriptor '"
137                      <<packname<<"::"<<descname<<"'"<<bbtkendl);
138     
139     
140     Package::DescriptorMapType::iterator desc = 
141       pack.lock()->GetDescriptorMap().find(descname);
142     if (desc ==  pack.lock()->GetDescriptorMap().end())
143       {
144         bbtkDebugMessage("package",5,
145                          "    Descriptor has already been released"
146                         <<bbtkendl);
147         return;
148                   }
149     //    bbtkDebugMessage("package",3,
150     //               "    Trying unreferencing it ... "<<std::endl);
151     BlackBoxDescriptor::WeakPointer pdesc = desc->second;
152     desc->second.reset();
153     // if it is dead : remove it 
154     if (pdesc.expired()) 
155       {
156         bbtkDebugMessage("package",2," ==> '"<<packname<<"::"<<descname<<"' Descriptor expired"<<bbtkendl);
157         if (pack.expired()) 
158           {
159             bbtkDebugMessage("package",2,
160                              "     ... and caused its package death"
161                              <<bbtkendl);
162             return;
163           } // pack.expired
164         desc = pack.lock()->GetDescriptorMap().find(descname);
165         if (desc !=  pack.lock()->GetDescriptorMap().end())       pack.lock()->GetDescriptorMap().erase(desc);
166       }   else    {  //pdesc.expired
167       bbtkDebugMessage("package",5,"    ... Descriptor still alive ("
168                        <<pdesc.use_count()<<" refs)"
169                        <<bbtkendl);
170       pack.lock()->GetDescriptorMap()[descname] = pdesc.lock();
171     } // pdesc.expired
172   }
173   //==========================================================================
174
175
176   //==========================================================================
177   /// Release
178   void Package::Release(Package::WeakPointer pack)
179   {
180     std::string packname = pack.lock()->mName;
181     bbtkDebugMessage("package",1,"==> Package::Release('"<<
182                      packname<<"')"<<bbtkendl);
183
184     long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
185     long ndesc = pack.lock()->GetDescriptorMap().size();
186     long nrefs = pack.use_count();
187
188     bbtkDebugMessage("package",5," "<<nrefs<<" refs / "
189                      <<ndesc<<" descr / dyn="
190                      <<dyn<<std::endl);
191
192     // A package is "free" from any external reference iff :
193     // i) It is not dynamically loaded and nrefs == ndesc 
194     // (each desc references its package) or
195     // ii) It is dynamically loaded and nrefs == ndesc + 1
196     // (A dynamic library holds a static pointer on the package it contains
197     //  which is allocated when the PACKAGENAMEGetPackage() func is called,
198     //  and descallocated (reset) by PACKAGENAMEDeletePackage())
199     if (nrefs == ndesc + dyn) 
200       {
201         bbtkDebugMessage("package",5,
202                          " -> No more external ref : checking descriptors"
203                          <<bbtkendl);
204         // We must take care that removing refs on descriptors 
205         // can lead to their deletion which can in turn unref 
206         // internal boxes which can release their descriptors hence 
207         // call Package::ReleaseBlackBoxDescriptor 
208         // As a consequence during descriptors release :
209         // 1) The map can change dynamically : we cannot iterate over it 
210         //    as any iterator can become invalid
211         // 2) The package can auto-destruct : we must test its existence 
212         //    after each release
213         // We must also take care of not locking the package pointer 
214         // or any ref count check in Package::ReleaseBlackBoxDescriptor
215         // would be wrong
216
217         // The list of descriptors names at start
218         std::vector<std::string> descnamelist;
219         DescriptorMapType::iterator i;
220         for (i=pack.lock()->mDescriptorMap.begin();
221              i!= pack.lock()->mDescriptorMap.end();
222              ++i)
223           descnamelist.push_back(i->first);
224
225         // Iterator over the initial names
226         std::vector<std::string>::iterator descname;
227         for (descname=descnamelist.begin();
228              descname!=descnamelist.end();
229              ++descname)
230           {
231             // Is package still alive ?
232             if (pack.expired()) 
233               {
234                 bbtkDebugMessage("package",1,"--- Package::Release('"<<
235                                  packname
236                                  <<"') : package expired during release : bailing out"<<bbtkendl);
237                 break;
238               }
239   
240 #if defined(MACOSX)
241                   BlackBoxDescriptor::Pointer desc = pack.lock()->mDescriptorMap[*descname];
242                   if ( (dyn==0) || (boost::dynamic_pointer_cast<ComplexBlackBoxDescriptor>(desc)) )
243                   {
244                           PackageReleaseBlackBoxDescriptorInternal(pack,*descname);
245                   } 
246 #else
247                   PackageReleaseBlackBoxDescriptorInternal(pack,*descname);
248 #endif
249
250           }
251
252         //
253         UnLoadDynamicLibrary(pack);
254         // Unload orphan dl packages 
255         Package::UnLoadReleasedDynamicallyLoadedPackages();
256
257       }
258     
259 #ifdef BBTK_COMPILE_DEBUG_MESSAGES
260
261     bbtkDebugMessage("package",2,"<== Package::Release('"<<
262                      packname<<"')"<<bbtkendl);
263
264     if (!pack.expired())
265       {
266         long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
267         long ndesc = pack.lock()->GetDescriptorMap().size();
268         long nrefs = pack.use_count();
269         
270         bbtkDebugMessage("package",1," ... Package still alive ("
271                          <<nrefs<<" refs / "
272                          <<ndesc<<" descr / dyn="
273                          <<dyn<<")"<<std::endl);
274       }
275     else 
276       {
277         bbtkDebugMessage("package",1," ... Package has been released"
278                          <<std::endl);
279       }
280 #endif
281   }
282   //==========================================================================
283
284   //==========================================================================
285   /// "Releases" the package
286   /// Signals the package that it can free the given descriptor
287   /// if they are no more used and free itself if it is no
288   /// more used
289   /// Note : Any non-weak pointer on the package must have been freed
290   void Package::ReleaseBlackBoxDescriptor(Package::WeakPointer pack,
291                                           BlackBoxDescriptor::WeakPointer descr)
292   {
293     std::string packname = pack.lock()->mName;
294     std::string dname = descr.lock()->GetTypeName();    
295     bbtkDebugMessage("package",3,"==> Package::ReleaseBlackBoxDescriptor('"<<
296                      packname<<"','"<<dname<<"') : refs="
297                      <<descr.use_count()<<bbtkendl);
298
299     long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
300     long ndesc = pack.lock()->GetDescriptorMap().size();
301     long nrefs = pack.use_count();
302
303     bbtkDebugMessage("package",5," "<<nrefs<<" refs / "
304                      <<ndesc<<" descr / dynamically loaded = "
305                      <<dyn<<std::endl);
306
307     // A package is "free" from any external reference iff :
308     // i) It is not dynamically loaded and nrefs == ndesc 
309     // (each desc references its package) or
310     // ii) It is dynamically loaded and nrefs == ndesc + 1
311     // (A dynamic library holds a static pointer on the package it contains
312     //  which is allocated when the PACKAGENAMEGetPackage() func is called,
313     //  and descallocated (reset) by PACKAGENAMEDeletePackage())
314     if (nrefs == ndesc + dyn) 
315       {
316 #if defined(MACOSX)
317                   //
318                   if (dyn==0)
319                           PackageReleaseBlackBoxDescriptorInternal(pack,dname);
320 #else
321                   PackageReleaseBlackBoxDescriptorInternal(pack,dname);
322 #endif  
323       }
324     
325     // If the package is released and dynamically loaded 
326     // then put it in the static list mReleasedDynamicallyLoadedPackages
327     UnLoadDynamicLibrary(pack,false);
328         
329     bbtkDebugMessage("package",4,"<== Package::ReleaseBlackBoxDescriptor('"<<
330                      packname<<"','"<<dname<<"'): refs="
331                      <<descr.use_count()<<bbtkendl);
332     /*
333     if (!pack.expired())
334       {
335         long dyn = pack.lock()->mDynamicLibraryHandler ? 1:0; 
336         long ndesc = pack.lock()->GetDescriptorMap().size();
337         long nrefs = pack.use_count();
338         
339         bbtkDebugMessage("package",3," ... Package still alive ("
340                          <<nrefs<<" refs / "
341                          <<ndesc<<" descr / dyn="
342                          <<dyn<<")"<<std::endl);
343       }
344     else 
345       {
346         bbtkDebugMessage("package",3,"   ... Package has been released"
347                          <<std::endl);
348       }  
349     */
350   }
351   //==========================================================================    
352
353   //==========================================================================
354   /// Opens a dynamic library which contains a bbtk package
355   /// Returns the handler 
356   /// Load the package management symbols from the lib
357   /// returns false if a problem occured hence can be used 
358   /// to test that a dyn lib is a valid bbtk package lib
359   /// NB : The BBTK version exported from the library 
360   ///      is tested against the current bbtk version
361   DynamicLibraryHandler Package::OpenDynamicLibrary( const std::string& libname,const std::string& package_name,
362                                                                                                          DLGetPackageFunction& getpack, DLDeletePackageFunction& delpack)
363   {
364     bbtkDebugMessage("package",3,"==> Package::OpenDynamicLibrary("
365                      <<libname<<")"<<std::endl);
366 #if defined(__GNUC__)
367
368     // Open shared lib
369     void *handler;
370     handler = dlopen(libname.c_str(), BBTK_RTLD_TIME | BBTK_RTLD_SCOPE );
371 //EED     handler = dlopen(libname.c_str(), RTLD_LAZY | RTLD_LOCAL );
372           
373     if (!handler)
374       {
375         bbtkMessage("package",0,
376                     "BBTK ..ERROR.. loading could not open shared library [" <<libname<<"] : "
377                     <<dlerror() << std::endl);
378         return 0;
379       }
380
381     bbtkDebugMessage("package",3,"* Shared lib ["<<libname<<"] open"<<std::endl);
382
383     // Loads the Package bbtk version function 
384     std::string getvername(package_name);
385     getvername += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
386     DLGetPackageBBTKVersionFunction getbbtkversion  = (DLGetPackageBBTKVersionFunction)(dlsym(handler,getvername.c_str()));
387     if (!getbbtkversion)
388       {
389         bbtkDebugMessage("package",3,"***"<<std::endl);
390         bbtkMessage("package",0,
391                     "BBTK ..ERROR.. loading shared library ["<<libname
392                     <<"] is not a valid bbtk package."
393                     <<" Symbol ["<<getvername<<"] :"<<dlerror()<< std::endl);
394         dlclose(handler);
395         return 0;
396       }
397
398     bbtkDebugMessage("package",3,"* Symbol ["<<getvername
399                      <<"] found"<<std::endl);
400     // version matches ?
401     if (getbbtkversion() != bbtk::GetVersion())
402       {
403         bbtkMessage("package",0,
404                     "BBTK ..ERROR.. loading: "<<package_name
405                         <<" - Shared library ["<<libname
406                     <<"] was build with bbtk version "
407                     <<getbbtkversion()
408                     <<" but the current program runs with version "
409                     <<bbtk::GetVersion()<<" : cannot load it. You have to recompile your BBTK-Package."<<std::endl);
410         dlclose(handler);
411         return 0;
412         
413       }
414
415     bbtkDebugMessage("package",3,"* Package bbtk version '"<<getbbtkversion()<<"' matches"<<std::endl);
416             // Loads the Package get function
417     std::string getpackname(package_name);
418     getpackname += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_FUNCTION_NAME);
419     getpack = (DLGetPackageFunction)(dlsym(handler, getpackname.c_str()));
420     if (!getpack)
421       {
422         bbtkMessage("package",0,
423                     "BBTK ..ERROR.. loading shared library ["<<libname
424                     <<"] is not a valid bbtk package."
425                     <<" Symbol ["<<getpackname<<"] :"<<dlerror()<< std::endl);
426         dlclose(handler);
427         return 0;
428       }
429   
430     bbtkDebugMessage("package",3,"* Symbol ["<<getpackname<<"] found"<<std::endl);
431     // Loads the Package delete function
432                                           
433     std::string delpackname(package_name);
434     delpackname += BBTK_STRINGIFY_SYMBOL(BBTK_DEL_PACKAGE_FUNCTION_NAME);
435     delpack = (DLDeletePackageFunction)(dlsym(handler, delpackname.c_str()));
436     if (!delpack)
437       {
438         bbtkMessage("package",0,
439                     "BBTK ..ERROR.. loading shared library ["<<libname
440                     <<"] is not a valid bbtk package."
441                     <<" Symbol ["<<delpackname<<"] :"<<dlerror()<< std::endl);
442         dlclose(handler);
443         return 0;
444       }
445     bbtkDebugMessage("package",3,"* Symbol ["<<delpackname<<"] found"<<std::endl);                
446 #elif defined(_WIN32)
447     
448     HINSTANCE handler;
449     
450     SetErrorMode(0);
451     // Open shared lib
452     handler = LoadLibrary(libname.c_str());
453     if (!handler)
454       {
455         bbtkMessage("package",0,
456                     "BBTK ..ERROR..  could not open shared library [" <<libname<<"]"
457                     << std::endl);
458         DWORD dwErrorCode = 0;
459         dwErrorCode = GetLastError();
460         bbtkMessage("package",2,
461                 "Windows Error: [" << dwErrorCode <<"]"
462                 << std::endl);
463          
464         return 0;
465       }
466     
467     // Loads the Package bbtk version function 
468     std::string getvername(package_name);
469     getvername += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_BBTK_VERSION_FUNCTION_NAME);
470     DLGetPackageBBTKVersionFunction getbbtkversion = (DLGetPackageBBTKVersionFunction)(GetProcAddress(handler, getvername.c_str()));
471           
472     if (!getbbtkversion)
473       {
474         FreeLibrary(handler);
475         bbtkMessage("package",0,
476                     "BBTK ..ERROR.. loading shared library ["<<libname
477                     <<"] is not a valid bbtk package."
478                     <<" Symbol ["<<getbbtkversion<<"] not found"<< std::endl);
479         return 0;
480       }
481     
482     // version matches ?
483     if (getbbtkversion() != bbtk::GetVersion())
484       {
485                   FreeLibrary(handler);
486                   bbtkMessage("package",0,
487                                 "BBTK ..ERROR.. loading: "<<package_name
488                                 <<" - Shared library ["<<libname
489                                 <<"] was build with bbtk version "
490                                 <<getbbtkversion()
491                                 <<" but the current program runs with version "
492                                 <<bbtk::GetVersion()<<" : cannot load it. You have to recompile your BBTK-Package."<<std::endl);
493                   return 0;
494       }
495
496      // Loads the Package get function
497     std::string getpackname(package_name);
498     getpackname += BBTK_STRINGIFY_SYMBOL(BBTK_GET_PACKAGE_FUNCTION_NAME);
499     getpack = (DLGetPackageFunction)(GetProcAddress(handler, getpackname.c_str()));
500     if (!getpack)
501       {
502         FreeLibrary(handler);
503         bbtkMessage("package",0,
504                     "BBTK ..ERROR.. loading shared library ["<<libname
505                     <<"] is not a valid bbtk package."
506                     <<" Symbol ["<<getpackname<<"] not found"<< std::endl);
507         return 0;
508       }
509     
510     // Loads the Package delete function
511     std::string delpackname(package_name);
512     delpackname += BBTK_STRINGIFY_SYMBOL(BBTK_DEL_PACKAGE_FUNCTION_NAME);
513     delpack = (DLDeletePackageFunction)(GetProcAddress(handler, delpackname.c_str()));
514     if (!delpack)
515       {
516         FreeLibrary(handler);
517         bbtkMessage("package",0,
518                     "BBTK ..ERROR.. loading shared library ["<<libname
519                     <<"] is not a valid bbtk package."
520                     <<" Symbol ["<<delpackname<<"] not found"<< std::endl);
521         return 0;
522       }
523                                          
524 #else
525     bbtkError("neither __GNUC__ nor _WIN32 ?!? How did you compile ?");
526 #endif
527     
528     return handler;
529   }
530   //==========================================================================
531   
532   //==========================================================================
533   /// Loads a package from a dynamic library
534   Package::Pointer Package::CreateFromDynamicLibrary(const std::string& libname,
535                                                      const std::string& pkgname,
536                                                      const std::string& path)
537   {
538     bbtkDebugMessage("package",1,"==> Package::CreateFromDynamicLibrary("
539                      <<libname<<")"<<std::endl);
540
541     DLGetPackageFunction gf;
542     DLDeletePackageFunction df;
543     DynamicLibraryHandler h = Package::OpenDynamicLibrary(libname,
544                                                           pkgname,
545                                                           gf,df);
546     if (h==0) return Package::Pointer(); 
547     Package::Pointer p = gf();
548     p->mDynamicLibraryHandler = h;
549     p->mDLDeletePackageFunction = df;
550     
551     std::string separator =
552       ConfigurationFile::GetInstance().Get_file_separator ();
553     //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
554     std::string docreldoc = 
555       separator + "bbdoc" + separator + pkgname + separator + "index.html";
556     std::string reldoc = 
557       ".." + separator + ".." + docreldoc;
558     std::string doc = path + separator + ".." + separator
559       + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH)
560       + docreldoc;
561     
562     p->SetDocURL(doc);
563     p->SetDocRelativeURL(reldoc);
564     
565     bbtkDebugMessage("package",2,"<== Package::CreateFromDynamicLibrary("
566                      <<libname<<") .. OK"<<std::endl);
567     return p;
568   }
569   //==========================================================================
570
571
572
573
574   //==========================================================================
575   /// UnLoads the package dynamic library (if any)
576   void Package::UnLoadDynamicLibrary(Package::WeakPointer pack, bool doit)
577   {
578     if (pack.expired() || (!pack.lock()->mDynamicLibraryHandler))
579       return;
580
581     std::string packname = pack.lock()->GetName();
582     bbtkDebugMessage("package",5,"==> Package::UnLoadDynamicLibrary('"
583                      <<packname<<"')"
584                      <<std::endl);
585
586     if (!pack.lock()->GetDescriptorMap().empty())
587       {
588
589         bbtkDebugMessage("package",5,"   Package not empty ... abort"
590                          <<std::endl);
591         return;
592         /*
593         bbtkGlobalError("Package::UnLoadDynamicLibrary('"<<packname<<") : "
594                         <<"DescriptorMap not empty "
595                         <<BBTK_INTERNAL_ERROR_MESSAGE);
596         */
597       }
598
599     if (pack.use_count()!=1)
600       {
601         bbtkGlobalError("Package::UnLoadDynamicLibrary('"<<packname<<") : "
602                         <<"empty dl package with external refs"
603                         <<BBTK_INTERNAL_ERROR_MESSAGE);
604       } 
605
606     if (doit) 
607       {
608         UnLoad(pack);
609         bbtkDebugMessage("package",5,"==> dynamic library for package '"
610                          <<packname<<"' closed"
611                          <<std::endl);    
612       }
613     else 
614       {
615         mReleasedDynamicallyLoadedPackages.insert(pack);
616         bbtkDebugMessage("package",1,"==> package '"<<packname
617                          <<"' put in the 'to unload' list"
618                          <<std::endl);
619       }
620
621     bbtkDebugMessage("package",5,"<== Package::UnLoadDynamicLibrary('"
622                      <<packname<<"')"
623                      <<std::endl); 
624   }
625   //==========================================================================
626
627   //==========================================================================
628   /// UnLoads released packages that were loaded dynamically
629   /// see UnLoadDynamicLibrary and ReleaseBlackBoxDescriptor
630   void Package::UnLoadReleasedDynamicallyLoadedPackages()
631   {
632     bbtkDebugMessage("package",5,"==> Package::UnLoadReleasedDynamicallyLoadedPackages()"<<std::endl);
633
634     std::set<Package::WeakPointer>::iterator i;
635
636 //JCP- 21-04-09
637         if(mReleasedDynamicallyLoadedPackages.size()>0){
638                 for (i=mReleasedDynamicallyLoadedPackages.begin();
639                 i!=mReleasedDynamicallyLoadedPackages.end();
640                 ++i)
641                 {
642                 if (!i->expired()) UnLoad(*i);
643                 }
644         }
645 //JCP- 21-04-09
646     bbtkDebugMessage("package",5,"<== Package::UnLoadReleasedDynamicallyLoadedPackages()"<<std::endl);
647   }
648   //==========================================================================
649
650   //==========================================================================
651   void Package::UnLoad(Package::WeakPointer pack)
652   {
653     std::string packname = pack.lock()->GetName();
654     bbtkDebugMessage("package",6,"==> Package::UnLoad("<<packname<<")"<<std::endl);
655
656     Package* p = pack.lock().get();
657     
658     DynamicLibraryHandler h = p->mDynamicLibraryHandler;
659     
660     // deletes the package
661     p->mDLDeletePackageFunction();
662     
663     // closes the dl handler
664 #if defined(__GNUC__)  
665           if (dlclose(h)!=0)
666           {
667                   printf("EED Package::UnLoad ERROR %s\n", packname.c_str() );
668                   bbtkWarning("Failed to close dynamic library for package '"<<packname
669                                           <<"'"<<std::endl);
670           }  
671           
672 #elif defined(_WIN32)
673     FreeLibrary(h);
674 #endif
675
676     bbtkDebugMessage("package",1,"==> dynamic library for package '"
677                      <<packname<<"' closed"
678                      <<std::endl);    
679     bbtkDebugMessage("package",6,"   ... dynamic library unloaded"<<std::endl);
680   }
681   //==========================================================================
682
683         bool Package::ifBoxExist( std::string type)     
684     {
685                 bool ok=false;
686                 DescriptorMapType::const_iterator i = mDescriptorMap.find(type);
687                 if (i != mDescriptorMap.end())  
688                 {
689                         ok=true;
690                 }
691                 return ok;
692     }
693         
694   //==========================================================================
695   /// Creates an instance of a black box of type <type> with name <name>
696   BlackBox::Pointer Package::NewBlackBox(const std::string& type, 
697                                          const std::string& name) const
698   {
699     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<">::NewBlackBox(\""<<type<<"\",\""<<name<<"\")"<<bbtkendl);
700     
701     DescriptorMapType::const_iterator i = mDescriptorMap.find(type);
702     if (i == mDescriptorMap.end())  
703     {
704            bbtkDebugDecTab("kernel",8);
705            return BlackBox::Pointer();
706     }
707     BlackBox::Pointer bb =i->second->NewBlackBox(name);
708     bbtkDebugDecTab("kernel",8);
709     return bb;   
710
711   }
712   //==========================================================================
713
714
715
716   //==========================================================================
717   /// Creates an instance of an adaptor of input type <typein> and 
718   /// output type <typeout>  with name <name>
719   BlackBox::Pointer Package::NewAdaptor(const DataInfo& typein,
720                                 const DataInfo& typeout,
721                                 const std::string& name) const
722   {
723     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
724                         ">::NewAdaptor("
725                         <<typein<<","
726                         <<typeout<<",\""
727                         <<name<<"\")"<<bbtkendl);
728
729     AdaptorKey key(typein,typeout,
730                    BlackBoxDescriptor::DEFAULT_ADAPTOR);
731     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
732     if (i == mAdaptorMap.end())  
733       {
734         bbtkDebugDecTab("kernel",8);
735         return BlackBox::Pointer();
736       }
737     BlackBox::Pointer bb =i->second.lock()->NewBlackBox(name);
738     bbtkDebugDecTab("kernel",8);
739     return bb;   
740
741   }
742   //==========================================================================
743
744   //==========================================================================
745   /// Creates an instance of an adaptor of input type <typein> and 
746   /// output type <typeout>  with name <name>
747   BlackBox::Pointer Package::NewWidgetAdaptor(const DataInfo& typein,
748                                       const DataInfo& typeout,
749                                       const std::string& name) const
750   {
751     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
752                         ">::NewWidgetAdaptor("
753                         <<typein<<","
754                         <<typeout<<",\""
755                         <<name<<"\")"<<bbtkendl);
756
757     AdaptorKey key(typein,typeout,
758                    BlackBoxDescriptor::DEFAULT_GUI);
759     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
760     if (i == mAdaptorMap.end())  
761       {
762         bbtkDebugDecTab("kernel",8);
763         return BlackBox::Pointer();
764       }
765     BlackBox::Pointer bb =i->second.lock()->NewBlackBox(name);
766     bbtkDebugDecTab("kernel",8);
767     return bb;   
768
769   }
770   //==========================================================================
771
772
773
774   //==========================================================================
775   /// Returns true is the package contains 
776   /// an adaptor of input type <typein> and 
777   /// output type <typeout>
778   /// If successfull then adaptor contains the black box type name
779   bool Package::FindWidgetAdaptor(const DataInfo& typein,
780                                   const DataInfo& typeout,
781                                   std::string& adaptor) const
782   {
783     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
784                         ">::FindWidgetAdaptor("
785                         <<typein<<","
786                         <<typeout<<")"<<bbtkendl);
787    
788     AdaptorKey key(/*typein*/
789                    DataInfo(typeid(void),""),
790                    typeout,
791                    BlackBoxDescriptor::DEFAULT_GUI);
792     // First try to find a single widget adaptor
793     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
794     if (i == mAdaptorMap.end())  
795       {
796         bbtkDebugDecTab("kernel",8);
797         return false;
798       }
799     adaptor = i->second.lock()->GetTypeName();
800     bbtkDebugDecTab("kernel",8);
801     return true;   
802
803   }
804   //==========================================================================
805
806
807
808   //==========================================================================
809   /// Returns true is the package contains 
810   /// an adaptor of input type <typein> and 
811   /// output type <typeout>
812   /// If successfull then adaptor contains the black box type name
813   bool Package::FindAdaptor(const DataInfo& typein,
814                             const DataInfo& typeout,
815                             std::string& adaptor) const
816   {
817     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<
818                         ">::FindAdaptor("
819                         <<typein<<","
820                         <<typeout<<")"<<bbtkendl);
821     
822     AdaptorKey key(typein,typeout,
823                    BlackBoxDescriptor::DEFAULT_ADAPTOR);
824     AdaptorMapType::const_iterator i = mAdaptorMap.find(key);
825     if (i == mAdaptorMap.end())  
826       {
827         bbtkDebugDecTab("kernel",8);
828         return false;
829       }
830     adaptor = i->second.lock()->GetTypeName();
831     bbtkDebugDecTab("kernel",8);
832     return true;   
833
834   }
835   //==========================================================================
836
837
838   //==========================================================================
839   /// Registers a black box descriptor in the package
840   bool Package::Register(BlackBoxDescriptor::Pointer d) 
841   {
842     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\")"<<std::endl);
843     
844     DescriptorMapType::iterator i = mDescriptorMap.find(d->GetTypeName());
845     if (i!=mDescriptorMap.end())
846       {
847         bbtkWarning("Package<"<<GetName()<<"> : Trying to register box type <"
848                     <<d->GetTypeName()<<"> which is already in the package");
849         return false;
850       }
851
852     mDescriptorMap[d->GetTypeName()] = d;
853     //    d->Reference();
854     d->SetPackage(GetThisPointer<Package>());
855     
856     // If it is a default adaptor, also register it in the adaptors map
857     if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR )
858       {
859         bbtkDebugMessage("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<<std::endl);   
860         
861         TypeInfo typein = d->GetInputDescriptor("In")->GetTypeInfo();
862         TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo();
863         DataInfo infoin(typein,d->GetInputDescriptor("In")->GetNature());
864         DataInfo infoout(typeout,d->GetOutputDescriptor("Out")->GetNature());
865         AdaptorKey key(infoin,infoout,d->GetKind());
866         
867         AdaptorMapType::const_iterator i;
868         i = mAdaptorMap.find(key);        
869         if (i == mAdaptorMap.end())  
870           {
871             mAdaptorMap[key] = d;
872           }
873         // If already an adaptor registered : error
874         else 
875           {
876             if (i->second.lock()->GetTypeName() != d->GetTypeName()) 
877               {
878                 bbtkError("Package <"<<GetName()<<
879                           "> : trying to register black box <"
880                           <<d->GetTypeName()
881                           <<"> as default adaptor but there is already a default adaptor registered (<"
882                           <<i->second.lock()->GetTypeName()<<">)");
883               }
884           }
885       }
886     // If it is a default adaptor, also register it in the adaptors map
887     else if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_GUI)
888       {
889         bbtkDebugMessage("kernel",8,"Package<"<<GetName()<<">::Register(\""<<d->GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<<std::endl);   
890         
891         TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo();
892         DataInfo infoin(typeid(void),"");
893         DataInfo infoout(typeout,d->GetOutputDescriptor("Out")->GetNature());
894         AdaptorKey key(infoin,infoout,d->GetKind());
895
896         AdaptorMapType::const_iterator i;
897         i = mAdaptorMap.find(key);        
898         if (i == mAdaptorMap.end())  
899           {
900             mAdaptorMap[key] = d;
901           }
902         // If already an adaptor registered : error
903         else 
904           {
905             if (i->second.lock()->GetTypeName() != d->GetTypeName()) 
906               {
907                 bbtkError("Package <"<<GetName()<<
908                           "> : trying to register black box <"
909                           <<d->GetTypeName()
910                           <<"> as default widget adaptor but there is already a default adaptor registered (<"
911                           <<i->second.lock()->GetTypeName()<<">)");
912               }
913           }
914       }
915     
916
917     bbtkDebugDecTab("kernel",8);
918    
919     return true;
920   }
921   //==========================================================================
922   
923   //===================================================================
924   void Package::Check() const
925   {
926     bbtkMessage("debug",1,"****** Checking Package "<<(void*)this
927                 <<" ["<<GetName()<<"]"<<std::endl);
928     DescriptorMapType::const_iterator i;
929     for (i=mDescriptorMap.begin();
930          i!=mDescriptorMap.end();
931          ++i) 
932       {
933         i->second->Check(true);
934       }
935     bbtkMessage("debug",1,"****** Checking Package "<<(void*)this
936                 <<" ["<<GetName()<<"] ... OK"<<std::endl);
937   }
938   //===================================================================
939
940
941   //==========================================================================
942   /// Changes the name of a black box type
943   void Package::ChangeDescriptorName( const std::string& oldname, const std::string& newname )
944   { 
945     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
946                         <<">::ChangeDescriptorName(\""<<oldname
947                         <<"\",\""<<newname<<"\")"<<std::endl);
948     // Looking into the bb map
949     DescriptorMapType::iterator i = mDescriptorMap.find(oldname);
950     if (i == mDescriptorMap.end())  
951       {
952          bbtkDebugDecTab("kernel",8);
953          bbtkError("ChangeDescriptorName : The package <"<<GetName()<<"> does not contains the black box <"<<oldname<<">");
954       }
955
956     i->second->SetTypeName(newname);
957     mDescriptorMap[newname] = i->second;
958     mDescriptorMap.erase(i);
959
960     bbtkDebugDecTab("kernel",8);    
961   }
962   //==========================================================================
963
964
965
966   //==========================================================================
967   void Package::PrintHelpListDescriptors(bool description, bool adaptors) const
968   {
969     unsigned int lmax = 0;
970     std::vector<std::string> names;
971     std::vector<std::string> kinds;
972     std::vector<std::string> descrs;
973
974     DescriptorMapType::const_iterator i;
975     for (i=mDescriptorMap.begin();
976          i!=mDescriptorMap.end();
977          ++i) 
978       {
979         if ( adaptors || 
980              ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) ) 
981           {
982             std::string name("  ");
983             name += i->second->GetTypeName();
984             names.push_back(name);
985
986             std::string kind;
987             if ( i->second->GetKind() == BlackBoxDescriptor::ADAPTOR )
988               {
989                 kind = std::string("[A]");
990               }
991             else if ( i->second->GetKind() == 
992                       BlackBoxDescriptor::DEFAULT_ADAPTOR )
993               {
994                 kind = std::string("[DA]");
995               }
996             kinds.push_back(kind);
997
998             unsigned int l = name.size()+kind.size();
999             if (l>lmax) lmax = l;
1000
1001             std::string descr;
1002             if (description) 
1003               {
1004                 descr += " : ";
1005                 descr += i->second->GetDescription();
1006               } 
1007             descrs.push_back(descr);
1008           }
1009       } 
1010     
1011
1012     std::string offs;
1013     offs.append(lmax+3,' ');
1014     std::vector<std::string>::iterator ni,ci,di;
1015     for (ni = names.begin(), ci = kinds.begin(), di = descrs.begin();
1016          ni != names.end(); ++ni, ++ci, ++di)
1017       {
1018         std::string space;
1019         space.append(lmax - ni->size() - ci->size(),' ');
1020         bbtkMessage("help",1,*ni << space << *ci );
1021         std::string d(*di);
1022         unsigned int dmax = 75 - lmax;
1023         //      while (d.size() > dmax ) 
1024         //  {
1025         if (d.size()>dmax) 
1026           bbtkMessage("help",1,d.substr(0,dmax) << "..." << std::endl);
1027         else 
1028           bbtkMessage("help",1,d << std::endl);
1029         //    d = d.substr(dmax,d.size());
1030         //  }
1031       }
1032
1033   }
1034   //==========================================================================
1035
1036   //==========================================================================
1037   /// Displays the list of adaptors of the package
1038   void Package::PrintHelpListAdaptors(bool description) const
1039   {
1040     DescriptorMapType::const_iterator i;
1041     for (i=mDescriptorMap.begin();
1042          i!=mDescriptorMap.end();
1043          ++i) 
1044       {
1045         if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD ) 
1046           {
1047             bbtkMessage("help",1,
1048                         "  "<<i->second->GetTypeName());
1049             if ( i->second->GetKind() == 
1050                  BlackBoxDescriptor::DEFAULT_ADAPTOR )
1051               {
1052                 bbtkMessage("help",1,
1053                             " [default]");
1054               }  
1055             if (description) 
1056               {
1057                 bbtkMessage("help",1,
1058                             " : "<<i->second->GetDescription());
1059
1060               } 
1061             bbtkMessage("help",1,std::endl);
1062           }
1063       } 
1064     /*
1065     AdaptorMapType::const_iterator i;
1066     for (i=mAdaptorMap.begin();
1067          i!=mAdaptorMap.end();
1068          ++i) 
1069       {
1070         bbtkMessage("help",1,
1071                     "  "<<i->second->GetTypeName());
1072         if (detail_level>0) 
1073           {
1074             bbtkMessage("help",1,
1075                         " : "<<i->second->GetDescription());
1076   
1077           } 
1078         bbtkMessage("help",1,std::endl);
1079       }
1080     */ 
1081   }
1082   //==========================================================================
1083
1084   //==========================================================================
1085   /// Prints help on a black box descriptor
1086   void Package::PrintHelpDescriptor(const std::string& name, bool full) const
1087   {
1088     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
1089                         <<">::PrintHelpDescriptor(\""
1090                         <<name<<"\")"<<bbtkendl);
1091
1092     DescriptorMapType::const_iterator i = mDescriptorMap.find(name);
1093     if (i == mDescriptorMap.end())  
1094       {
1095         bbtkDebugDecTab("kernel",8);
1096         bbtkError("The package <"<<GetName()<<"> does not contains the black box <"<<name<<">");
1097       }
1098     //    bbtkMessage("help",1,"["<<GetName()<<"] ");
1099     i->second->GetHelp(full);
1100     bbtkDebugDecTab("kernel",8);
1101
1102   }
1103   //==========================================================================
1104
1105
1106   //==========================================================================
1107   /// Returns true iff the package contains the box of name boxname
1108   bool Package::ContainsDescriptor(const std::string& name) const 
1109   {
1110     bbtkDebugMessageInc("kernel",8,"Package<"<<GetName()
1111                         <<">::ContainsDescriptor(\""
1112                         <<name<<"\")"<<bbtkendl);
1113     
1114     DescriptorMapType::const_iterator i = mDescriptorMap.find(name);
1115     if (i == mDescriptorMap.end())  
1116     {
1117       bbtkDebugDecTab("kernel",8);
1118       return false;
1119     }
1120     bbtkDebugDecTab("kernel",8);
1121     return true;
1122   }
1123   //==========================================================================
1124
1125
1126  
1127   //==========================================================================
1128   void Package::CreateHtmlPage(const std::string& filename,
1129                                const std::string& caller,
1130                                const std::string& source,
1131                                const std::string& custom_header,
1132                                const std::string& custom_title,
1133                                int detail, 
1134                                int level,
1135                                bool relative_link ) const
1136   {
1137     bbtkDebugMessageInc("kernel",9,"Package<"<<GetName()<<">::CreateHtmlPage(\""
1138                         <<filename<<"\")"<<bbtkendl);
1139
1140 //std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1133"<<std::endl;
1141
1142     //---------------------
1143     // Open output file
1144     std::ofstream s;
1145     s.open(filename.c_str());
1146     if (!s.good()) 
1147     {
1148        bbtkError("Package "<<GetName()<<" : CreateHtmlPage : could not open file '"<<filename<<"'");
1149     }
1150     
1151     //----------------------
1152     // Html head
1153     std::string title = "BBTK Package "+GetName()+" "+GetVersion(); 
1154
1155     if (custom_title.length() != 0) title = custom_title;
1156
1157     s << "<html lang=\"en\">\n";
1158     s << "<head>\n";
1159     s << "<title>" << title << "</title>\n";
1160     s << "<meta http-equiv=\"Content-Type\" content=\"text/html\">\n";
1161     s << "<meta name=\"description\" content=\""<<title<<"\">\n";
1162     s << "<meta name=\"generator\" content=\"\">\n";
1163     s << "<link title=\"Top\" rel=\"top\" href=\"#Top\">\n";
1164     //<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
1165     s << "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"><style type=\"text/css\"><!--\n";
1166     s << "pre.display { font-family:inherit }\n";
1167     s << "pre.format  { font-family:inherit }\n";
1168     s << "pre.smalldisplay { font-family:inherit; font-size:smaller }\n";
1169     s << "pre.smallformat  { font-family:inherit; font-size:smaller }\n";
1170     s << "pre.smallexample { font-size:smaller }\n";
1171     s << "pre.smalllisp    { font-size:smaller }\n";
1172     s << "span.sc    { font-variant:small-caps }\n";
1173     s << "span.roman { font-family:serif; font-weight:normal; } \n";
1174     s << "span.sansserif { font-family:sans-serif; font-weight:normal; }\n"; 
1175     s << "--></style>\n";
1176     s << "</head>\n";
1177     //----------------------
1178
1179     //----------------------
1180     // Html body
1181     s << "<body>\n";
1182     s << "<a name=\"Top\"></a>\n"; 
1183     
1184     //----------------------
1185     // Header
1186     if ( custom_header.length() != 0) 
1187       {
1188         if ( custom_header != "none" )
1189           { 
1190             std::ifstream in;
1191             in.open(custom_header.c_str());    
1192             if (!in.good()) 
1193               {
1194                 bbtkError("Could not open file \""<<custom_header<<"\"");
1195               }
1196             char buffer[512];
1197             while (!in.eof()) 
1198               {
1199                 in.getline(buffer,512);
1200                 std::string line(buffer);
1201                 s << line;
1202               }
1203             in.close();
1204             s << "<hr>\n";
1205            
1206             /*   
1207             s << "<object data=\"" << custom_header 
1208               << "\" type = \"text/html\"\"style=\"width: 1200px; height: 400px;\"> Warning: "
1209               << custom_header <<" could not be embedded.</object>\n";
1210             
1211             s << "<hr>\n";
1212             */
1213           }
1214       }
1215
1216     else 
1217       {
1218         s << "<h1 class=\"settitle\">"<<title<<"</h1>\n";
1219         s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
1220         s << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> " 
1221           << GetDescription() << "</TD></TR>\n";
1222         s << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  " 
1223           << GetAuthor() << "</TD></TR>\n";
1224         s << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  " 
1225           << GetCategory() << "</TD></TR>\n";
1226         s << "<TR><TD style='vertical-align: top;'><b> Version </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> " 
1227           << GetVersion() << "</TD></TR>\n";
1228         s << "<TR><TD style='vertical-align: top;'><b> bbtk Version </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> " 
1229           << bbtk::GetVersion() << "</TD></TR>\n";
1230         s << "</TABLE>\n";
1231       }
1232 //std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1225"<<std::endl;
1233     //-------------------
1234     // Table of contents
1235     // Black boxes list
1236     //  s << "<div class=\"contents\">\n";
1237     s << "<p><b> Black Boxes : </b>\n";
1238     s << "<ul>\n";
1239
1240     s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
1241
1242     DescriptorMapType::const_iterator i;
1243 //std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1236"<<std::endl;
1244     for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i) {
1245                 if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD) 
1246                         continue;
1247         
1248                 std::string name = i->second->GetTypeName();
1249                 Utilities::html_format(name);
1250                 std::string descr = i->second->GetDescription();
1251                 //Utilities::html_format(descr);
1252 //std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1246"<<std::endl;
1253                 s << "<TR>";
1254                 s << "<TD style='vertical-align: top;'>";
1255                 s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
1256                 <<"\" href=\"#"<<name<<"\">"
1257                 <<name<<"</a>";
1258                 s << "</TD> ";
1259                 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1260                 s << "</TR>\n";
1261                 }    
1262                 s << "</TABLE>\n";
1263
1264
1265                 s << "</ul>\n";
1266                 s << "</div>\n";
1267     
1268                 //-------------------
1269                 // Adaptors list
1270                 if (mAdaptorMap.size()>0) 
1271                 {
1272                         //  s << "<div class=\"contents\">\n";
1273                         s << "<p><b> Adaptors : </b>\n";
1274                         s << "<ul>\n";
1275 //std::cout<<"JCP bbtkPackage.cxx void Package::CreateHtmlPage() ln 1268"<<std::endl;
1276                         //    DescriptorMapType::const_iterator i;
1277                         s << "<p><TABLE cellspacing=0  cellpadding=3>\n";
1278                         for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end();++i) 
1279                         {
1280                                 if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) 
1281                                         continue;
1282     
1283                                 std::string name = i->second->GetTypeName();
1284                                 Utilities::html_format(name);
1285                                 std::string descr = i->second->GetDescription();
1286                     
1287                                 s << "<TR>";
1288                                 s << "<TD style='vertical-align: top;'>";
1289                                 s << "&nbsp;&nbsp;&nbsp;<a name=\"toc_"<<name
1290                                   <<"\" href=\"#"<<name<<"\">"
1291                                   <<name<<"</a>";
1292                                 s << "</TD> ";
1293                                 s << " <TD style='vertical-align: top;'>" << descr << " </TD>";
1294                                 s << "</TR>\n";
1295                         }    
1296                         s << "</TABLE>\n";
1297
1298                         s << "</ul>\n";
1299                         s << "</div>\n";
1300                 }
1301     
1302     
1303     //  s << "<div class=\"node\">\n";
1304
1305     //    s << "<p><hr>\n";
1306     //    s << "<a name=\"Top\"></a>\n";
1307     //  s << "Top:&nbsp;<a rel=\"top\" accesskey=\"t\" href=\"#Top\">Top</a>\n";
1308     // s << "Previous:&nbsp;<a rel="previous" accesskey="p" href="#dir">(dir)</a>,
1309     // s << "Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>
1310     
1311     //    s << "</div>\n";
1312
1313     //----------------------
1314     // Boxes doc
1315
1316     //-------------------
1317     // Computes output directory from filename to pass it to 
1318     // BlackBoxDescriptor::InsertHtmlHelp
1319                 std::string dir;
1320
1321                 std::string::size_type slash_position = filename.find_last_of("/\\");
1322
1323
1324                 if (slash_position != std::string::npos) {
1325                         if (slash_position == 0)
1326                          slash_position = 1;  
1327                         dir = filename.substr(0,slash_position);
1328                 }
1329
1330                 for (i=mDescriptorMap.begin();
1331                  i!=mDescriptorMap.end();
1332                  ++i) 
1333                 {
1334                         i->second->InsertHtmlHelp(s,detail,level,dir,relative_link);
1335                 }    
1336
1337     //----------------------
1338     // Footer 
1339     time_t rawtime;
1340     tm * ptm;
1341     time ( &rawtime );
1342     ptm = gmtime ( &rawtime );
1343
1344     s << "<p><hr>\n";
1345     s << "Automatically generated by <b>"<<caller<<"</b> "//from <b>"
1346       //      <<source<<"</b>
1347       <<"on "
1348       << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900 
1349       << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n";
1350     s << "</body></html>\n"; 
1351     s.close();
1352     //----------------------
1353
1354     // End
1355     bbtkDebugDecTab("kernel",9);
1356   }
1357   //==========================================================================
1358   
1359   //==========================================================================
1360   std::string  Package::GetObjectName() const 
1361   { 
1362     return std::string("Package '")+mName+std::string("'"); 
1363   }
1364   //==========================================================================
1365
1366   //==========================================================================
1367   std::string Package::GetObjectInfo() const 
1368   {
1369     std::stringstream i;
1370     i << "  - "<<mDescriptorMap.size() << " boxes" << std::endl;
1371     if (mDynamicLibraryHandler) 
1372       {
1373         i<< "  - Loaded from dynamic library"<<std::endl;
1374       }
1375     return i.str();
1376   }
1377   //==========================================================================
1378
1379
1380   //==========================================================================
1381   size_t  Package::GetObjectSize() const 
1382   {
1383     size_t s = Superclass::GetObjectSize();
1384     s += Package::GetObjectInternalSize();
1385     return s;
1386   }
1387   //==========================================================================
1388   //==========================================================================
1389   size_t  Package::GetObjectInternalSize() const 
1390   {
1391     size_t s = sizeof(Package);
1392     return s;
1393   }
1394   //==========================================================================
1395   //==========================================================================
1396   size_t  Package::GetObjectRecursiveSize() const 
1397   {
1398     size_t s = Superclass::GetObjectRecursiveSize();
1399     s += Package::GetObjectInternalSize();
1400     
1401     DescriptorMapType::const_iterator i;
1402     for (i = mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i )
1403       {
1404         s += i->second->GetObjectRecursiveSize();
1405       }
1406     return s;
1407   }
1408   //==========================================================================
1409   void  Package::GetBoxesInside(NodeTreeC& tree, int cont) 
1410   {
1411                 DescriptorMapType::const_iterator i;
1412                 std::cout<<"*********a********"<<std::endl;
1413                 for (i=mDescriptorMap.begin(); i!=mDescriptorMap.end(); ++i) 
1414                 {
1415                         i->second->GetBoxesInside(tree, cont);
1416                         std::cout<<"*****************"<<std::endl;
1417                 }    
1418   }
1419         //==========================================================================
1420   //==========================================================================
1421   std::set<Package::WeakPointer> 
1422   Package::mReleasedDynamicallyLoadedPackages;
1423   //==========================================================================
1424
1425 }
1426