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