X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkPackage.cxx;h=236953e51c7a65482bbf9f26adc1a9cec54355dc;hb=551b02f0819a98e9595a81570b1d1174f398f34d;hp=7b50aefd251f3e9ef3503a424fc8c3de3623a6d4;hpb=d74933e88492b90684ad0648d9ca7eb9d6ecb720;p=bbtk.git diff --git a/kernel/src/bbtkPackage.cxx b/kernel/src/bbtkPackage.cxx index 7b50aef..236953e 100644 --- a/kernel/src/bbtkPackage.cxx +++ b/kernel/src/bbtkPackage.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkPackage.cxx,v $ Language: C++ - Date: $Date: 2008/01/30 12:14:43 $ - Version: $Revision: 1.2 $ + Date: $Date: 2008/05/09 10:39:46 $ + Version: $Revision: 1.18 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -28,6 +28,30 @@ namespace bbtk { + + + + //========================================================================== + /// Creates a new package + Package::Pointer Package::New(const std::string& name, + const std::string& author, + const std::string& description, + const std::string& version, + const std::string& BBTKVersion) + { + bbtkDebugMessage("object",1,"##> Package::New('"< Package::Package('"<second; - } - // Adaptors are also stored in the black box map : hence already deleted + bbtkDebugMessage("object",2,"==> Package::~Package(\""<GetName(); + + bbtkDebugMessage("package",5,"--- Releasing descriptor '" + <GetBlackBoxMap().find(descname); + if (desc == pack.lock()->GetBlackBoxMap().end()) + { + bbtkDebugMessage("package",5, + " Descriptor has already been released" + <second; + desc->second.reset(); + // if it is dead : remove it + if (pdesc.expired()) + { + bbtkDebugMessage("package",2," ==> '"<GetBlackBoxMap().find(descname); + if (desc != pack.lock()->GetBlackBoxMap().end()) + pack.lock()->GetBlackBoxMap().erase(desc); + } + else + { + bbtkDebugMessage("package",5," ... Descriptor still alive (" + <GetBlackBoxMap()[descname] = pdesc.lock(); + } + } + //========================================================================== + + + //========================================================================== + /// Release + void Package::Release(Package::WeakPointer pack) + { + std::string packname = pack.lock()->mName; + bbtkDebugMessage("package",1,"==> Package::Release('"<< + packname<<"')"<mDynamicLibraryHandler ? 1:0; + long ndesc = pack.lock()->GetBlackBoxMap().size(); + long nrefs = pack.use_count(); + + bbtkDebugMessage("package",5," "< No more external ref : checking descriptors" + < descnamelist; + BlackBoxMapType::iterator i; + for (i=pack.lock()->mBlackBoxMap.begin(); + i!= pack.lock()->mBlackBoxMap.end(); + ++i) + descnamelist.push_back(i->first); + + // Iterator over the initial names + std::vector::iterator descname; + for (descname=descnamelist.begin(); + descname!=descnamelist.end(); + ++descname) + { + // Is package still alive ? + if (pack.expired()) + { + bbtkDebugMessage("package",1,"--- Package::Release('"<< + packname + <<"') : package expired during release : bailing out"<mDynamicLibraryHandler ? 1:0; + long ndesc = pack.lock()->GetBlackBoxMap().size(); + long nrefs = pack.use_count(); + + bbtkDebugMessage("package",1," ... Package still alive (" + <mName; + std::string dname = descr.lock()->GetTypeName(); + bbtkDebugMessage("package",3,"==> Package::ReleaseBlackBoxDescriptor('"<< + packname<<"','"< Package::OpenDynamicLibrary(" + < Package::CreateFromDynamicLibrary(" + <mDynamicLibraryHandler = h; + p->mDLDeletePackageFunction = df; + + std::string separator = + ConfigurationFile::GetInstance().Get_file_separator (); + //BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH) + std::string docreldoc = + separator + "bbdoc" + separator + pkgname + separator + "index.html"; + std::string reldoc = + ".." + separator + ".." + docreldoc; + std::string doc = path + separator + ".." + separator + + BBTK_STRINGIFY_SYMBOL(BBTK_DOC_REL_PATH) + + docreldoc; + + p->SetDocURL(doc); + p->SetDocRelativeURL(reldoc); + + bbtkDebugMessage("package",2,"<== Package::CreateFromDynamicLibrary(" + <mDynamicLibraryHandler)) + return; + + + std::string packname = pack.lock()->GetName(); + bbtkDebugMessage("package",5,"==> Package::UnLoadDynamicLibrary('" + <GetBlackBoxMap().empty()) + { + + bbtkDebugMessage("package",5," Package not empty ... abort" + < dynamic library for package '" + < package '"< Package::UnLoadReleasedDynamicallyLoadedPackages()"<::iterator i; + for (i=mReleasedDynamicallyLoadedPackages.begin(); + i!=mReleasedDynamicallyLoadedPackages.end(); + ++i) + { + if (!i->expired()) UnLoad(*i); + } + bbtkDebugMessage("package",5,"<== Package::UnLoadReleasedDynamicallyLoadedPackages()"<GetName(); + bbtkDebugMessage("package",6,"==> Package::UnLoad("<mDynamicLibraryHandler; + + // deletes the package + p->mDLDeletePackageFunction(); + + // closes the dl handler +#if defined(__GNUC__) + dlclose(h); +#elif defined(_WIN32) + FreeLibrary(h); +#endif + bbtkDebugMessage("package",1,"==> dynamic library for package '" + < with name - BlackBox* Package::NewBlackBox(const std::string& type, - const std::string& name) const + BlackBox::Pointer Package::NewBlackBox(const std::string& type, + const std::string& name) const { - bbtkDebugMessageInc("Core",8,"Package<"<::NewBlackBox(\""<::NewBlackBox(\""<second->CreateInstance(name); - bbtkDebugDecTab("Core",8); + BlackBox::Pointer bb =i->second->NewBlackBox(name); + bbtkDebugDecTab("Kernel",8); return bb; } @@ -120,107 +665,238 @@ namespace bbtk //========================================================================== /// Creates an instance of an adaptor of input type and /// output type with name - BlackBox* Package::NewAdaptor(TypeInfo typein, - TypeInfo typeout, - const std::string& name) const + BlackBox::Pointer Package::NewAdaptor(const DataInfo& typein, + const DataInfo& typeout, + const std::string& name) const { - bbtkDebugMessageInc("Core",8,"Package<"<::NewAdaptor(<" - <,<" - <,\"" + bbtkDebugMessageInc("Kernel",8,"Package<"<::NewAdaptor(" + <second->CreateInstance(name); - bbtkDebugDecTab("Core",8); + BlackBox::Pointer bb =i->second.lock()->NewBlackBox(name); + bbtkDebugDecTab("Kernel",8); return bb; } //========================================================================== + //========================================================================== + /// Creates an instance of an adaptor of input type and + /// output type with name + BlackBox::Pointer Package::NewWidgetAdaptor(const DataInfo& typein, + const DataInfo& typeout, + const std::string& name) const + { + bbtkDebugMessageInc("Kernel",8,"Package<"<::NewWidgetAdaptor(" + <second.lock()->NewBlackBox(name); + bbtkDebugDecTab("Kernel",8); + return bb; + + } + //========================================================================== + //========================================================================== + /// Returns true is the package contains + /// an adaptor of input type and + /// output type + /// If successfull then adaptor contains the black box type name + bool Package::FindWidgetAdaptor(const DataInfo& typein, + const DataInfo& typeout, + std::string& adaptor) const + { + bbtkDebugMessageInc("Kernel",8,"Package<"<::FindWidgetAdaptor(" + <second.lock()->GetTypeName(); + bbtkDebugDecTab("Kernel",8); + return true; + + } + //========================================================================== + + + + //========================================================================== + /// Returns true is the package contains + /// an adaptor of input type and + /// output type + /// If successfull then adaptor contains the black box type name + bool Package::FindAdaptor(const DataInfo& typein, + const DataInfo& typeout, + std::string& adaptor) const + { + bbtkDebugMessageInc("Kernel",8,"Package<"<::FindAdaptor(" + <second.lock()->GetTypeName(); + bbtkDebugDecTab("Kernel",8); + return true; + + } + //========================================================================== + + //========================================================================== /// Registers a black box descriptor in the package - bool Package::RegisterBlackBox(BlackBoxDescriptor* d) + bool Package::RegisterBlackBox(BlackBoxDescriptor::Pointer d) { - bbtkDebugMessageInc("Core",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\")"<::RegisterBlackBox(\""<GetTypeName()<<"\")"<GetTypeName()); + if (i!=mBlackBoxMap.end()) + { + bbtkWarning("Package<"< : Trying to register box type <" + <GetTypeName()<<"> which is already in the package"); + return false; + } + mBlackBoxMap[d->GetTypeName()] = d; - d->SetPackage(this); + // d->Reference(); + d->SetPackage(GetThisPointer()); // If it is a default adaptor, also register it in the adaptors map - if ( d->GetCategory() == BlackBoxDescriptor::DEFAULT_ADAPTOR) + if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR ) { + bbtkDebugMessage("Kernel",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\") : The box is an adaptor, inserting it in adaptors map ..."<GetInputDescriptor("In")->GetTypeInfo(); TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo(); - AdaptorKey key(typein,typeout); - AdaptorMapType::const_iterator i = mAdaptorMap.find(key); + DataInfo infoin(typein,d->GetInputDescriptor("In")->GetNature()); + DataInfo infoout(typeout,d->GetOutputDescriptor("Out")->GetNature()); + AdaptorKey key(infoin,infoout,d->GetKind()); + + AdaptorMapType::const_iterator i; + i = mAdaptorMap.find(key); if (i == mAdaptorMap.end()) { - bbtkDebugMessage("Core",8,"The box is an adaptor, inserting it in adaptors map ..."< : trying to register black box <" - <GetTypeName() - <<"> as default adaptor but there is already a default adaptor registered (<" - <second->GetTypeName()<<">)"); + if (i->second.lock()->GetTypeName() != d->GetTypeName()) + { + bbtkError("Package <"< : trying to register black box <" + <GetTypeName() + <<"> as default adaptor but there is already a default adaptor registered (<" + <second.lock()->GetTypeName()<<">)"); + } + } + } + // If it is a default adaptor, also register it in the adaptors map + else if ( d->GetKind() == BlackBoxDescriptor::DEFAULT_GUI) + { + bbtkDebugMessage("Kernel",8,"Package<"<::RegisterBlackBox(\""<GetTypeName()<<"\") : The box is a widget adaptor, inserting it in adaptors map ..."<GetOutputDescriptor("Out")->GetTypeInfo(); + DataInfo infoin(typeid(void),""); + DataInfo infoout(typeout,d->GetOutputDescriptor("Out")->GetNature()); + AdaptorKey key(infoin,infoout,d->GetKind()); + + AdaptorMapType::const_iterator i; + i = mAdaptorMap.find(key); + if (i == mAdaptorMap.end()) + { + mAdaptorMap[key] = d; + } + // If already an adaptor registered : error + else + { + if (i->second.lock()->GetTypeName() != d->GetTypeName()) + { + bbtkError("Package <"< : trying to register black box <" + <GetTypeName() + <<"> as default widget adaptor but there is already a default adaptor registered (<" + <second.lock()->GetTypeName()<<">)"); + } } } - bbtkDebugDecTab("Core",8); + + bbtkDebugDecTab("Kernel",8); return true; } //========================================================================== - - //========================================================================== - /// UnRegisters a black box descriptor from the package - void Package::UnRegisterBlackBox(const std::string& name) + //=================================================================== + void Package::CheckBoxes() const { - bbtkDebugMessageInc("Core",8,"Package<"<::UnRegisterBlackBox(\""< does not contains the black box <"<"); - } - mBlackBoxMap.erase(i); - // Is it also in the adaptors map ? - /* - AdaptorMapType::iterator j = mAdaptorMap.find(name); - if (j != mAdaptorMap.end()) + bbtkMessage("debug",1,"****** Checking Package "<<(void*)this + <<" ["<second->Check(true); } - */ - bbtkDebugDecTab("Core",8); + bbtkMessage("debug",1,"****** Checking Package "<<(void*)this + <<" ["<::ChangeBlackBoxName(\""<::ChangeBlackBoxName(\""< does not contains the black box <"<"); } @@ -228,27 +904,10 @@ namespace bbtk mBlackBoxMap[newname] = i->second; mBlackBoxMap.erase(i); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); } //========================================================================== - /* - - //========================================================================== - /// Registers an adaptor descriptor in the package - bool Package::RegisterAdaptor(BlackBoxDescriptor* d) - { - bbtkDebugMessage("Core",8,"Package<"<::RegisterAdaptor(\""<GetTypeName()<<"\")"<GetInputDescriptor("In")->GetTypeInfo(); - TypeInfo typeout = d->GetOutputDescriptor("Out")->GetTypeInfo(); - AdaptorKey key(typein,typeout); - - mAdaptorMap[key] = d; - return true; - } - //========================================================================== - */ //========================================================================== @@ -257,7 +916,7 @@ namespace bbtk { unsigned int lmax = 0; std::vector names; - std::vector categs; + std::vector kinds; std::vector descrs; BlackBoxMapType::const_iterator i; @@ -266,25 +925,25 @@ namespace bbtk ++i) { if ( adaptors || - ( i->second->GetCategory() == BlackBoxDescriptor::STANDARD) ) + ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) ) { std::string name(" "); name += i->second->GetTypeName(); names.push_back(name); - std::string categ; - if ( i->second->GetCategory() == BlackBoxDescriptor::ADAPTOR ) + std::string kind; + if ( i->second->GetKind() == BlackBoxDescriptor::ADAPTOR ) { - categ = std::string("[A]"); + kind = std::string("[A]"); } - else if ( i->second->GetCategory() == + else if ( i->second->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR ) { - categ = std::string("[DA]"); + kind = std::string("[DA]"); } - categs.push_back(categ); + kinds.push_back(kind); - unsigned int l = name.size()+categ.size(); + unsigned int l = name.size()+kind.size(); if (l>lmax) lmax = l; std::string descr; @@ -301,7 +960,7 @@ namespace bbtk std::string offs; offs.append(lmax+3,' '); std::vector::iterator ni,ci,di; - for (ni = names.begin(), ci = categs.begin(), di = descrs.begin(); + for (ni = names.begin(), ci = kinds.begin(), di = descrs.begin(); ni != names.end(); ++ni, ++ci, ++di) { std::string space; @@ -331,11 +990,11 @@ namespace bbtk i!=mBlackBoxMap.end(); ++i) { - if ( i->second->GetCategory() != BlackBoxDescriptor::STANDARD ) + if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD ) { bbtkMessage("Help",1, " "<second->GetTypeName()); - if ( i->second->GetCategory() == + if ( i->second->GetKind() == BlackBoxDescriptor::DEFAULT_ADAPTOR ) { bbtkMessage("Help",1, @@ -374,18 +1033,18 @@ namespace bbtk /// Prints help on a black box void Package::HelpBlackBox(const std::string& name, bool full) const { - bbtkDebugMessageInc("Core",8,"Package<"<::HelpBlackBox(\"" + bbtkDebugMessageInc("Kernel",8,"Package<"<::HelpBlackBox(\"" < does not contains the black box <"<"); } // bbtkMessage("Help",1,"["<second->GetHelp(full); - bbtkDebugDecTab("Core",8); + bbtkDebugDecTab("Kernel",8); } //========================================================================== @@ -395,16 +1054,16 @@ namespace bbtk /// Returns true iff the package contains the box of name boxname bool Package::ContainsBlackBox(const std::string& name) const { - bbtkDebugMessageInc("Core",8,"Package<"<::HelpBlackBox(\"" + bbtkDebugMessageInc("Kernel",8,"Package<"<::HelpBlackBox(\"" <::CreateHtmlPage(\"" + bbtkDebugMessageInc("Kernel",9,"Package<"<::CreateHtmlPage(\"" < Author(s) : " << GetAuthor() << "\n"; s << " Author(s) : " - << GetKeyword() << "\n"; + << GetCategory() << "\n"; s << " Version : " << GetVersion() << "\n"; s << " bbtk Version : " - << GetBBTKVersion() << "\n"; + << bbtk::GetVersion() << "\n"; s << "\n"; } @@ -527,16 +1186,17 @@ namespace bbtk BlackBoxMapType::const_iterator i; for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end(); ++i) { - if ( i->second->GetCategory() != BlackBoxDescriptor::STANDARD) + if ( i->second->GetKind() != BlackBoxDescriptor::STANDARD) continue; std::string name = i->second->GetTypeName(); Utilities::html_format(name); std::string descr = i->second->GetDescription(); + Utilities::html_format(descr); s << ""; s << ""; - s << "
  • " <"; s << " "; @@ -546,7 +1206,7 @@ namespace bbtk s << "\n"; - s << "
  • \n"; + s << "\n"; s << "\n"; //------------------- @@ -561,7 +1221,7 @@ namespace bbtk s << "

    \n"; for (i=mBlackBoxMap.begin(); i!=mBlackBoxMap.end();++i) { - if ( i->second->GetCategory() == BlackBoxDescriptor::STANDARD) + if ( i->second->GetKind() == BlackBoxDescriptor::STANDARD) continue; std::string name = i->second->GetTypeName(); @@ -570,7 +1230,7 @@ namespace bbtk s << ""; s << " "; @@ -579,7 +1239,7 @@ namespace bbtk } s << "
    "; - s << "
  • " <"; s << "
  • \n"; - s << "\n"; + s << "\n"; s << "\n"; } @@ -601,9 +1261,11 @@ namespace bbtk // Computes output directory from filename to pass it to // BlackBoxDescriptor::InsertHtmlHelp std::string dir; - std::string::size_type slash_position = - filename.find_last_of(ConfigurationFile::GetInstance().Get_file_separator ()); - if (slash_position != std::string::npos) { + + std::string::size_type slash_position = filename.find_last_of("/\\"); + + + if (slash_position != std::string::npos) { if (slash_position == 0) slash_position = 1; dir = filename.substr(0,slash_position); @@ -624,8 +1286,9 @@ namespace bbtk ptm = gmtime ( &rawtime ); s << "


    \n"; - s << "Automatically generated by "< from " - < on " + s << "Automatically generated by "< "//from " + // < + <<"on " << ptm->tm_mday << "/" << ptm->tm_mon << "/" << ptm->tm_year+1900 << " - " << ptm->tm_hour << ":" << ptm->tm_min << " GMT\n"; s << "\n"; @@ -633,8 +1296,64 @@ namespace bbtk //---------------------- // End - bbtkDebugDecTab("Core",9); + bbtkDebugDecTab("Kernel",9); + } + //========================================================================== + + //========================================================================== + std::string Package::GetObjectName() const + { + return std::string("Package '")+mName+std::string("'"); } //========================================================================== + + //========================================================================== + std::string Package::GetObjectInfo() const + { + std::stringstream i; + i << " - "<second->GetObjectRecursiveSize(); + } + return s; + } + //========================================================================== + + //========================================================================== + std::set + Package::mReleasedDynamicallyLoadedPackages; + //========================================================================== }