X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.cxx;h=58ae9594c317d3447ce6112633eeb90dbdec934b;hb=4ad5b5ee44357ad873bc8c43230defb6d0a79879;hp=ae3ea1f770e2cdaa517a3cf27417b44510e70796;hpb=5ca30b861f60def2666a1c675e8b45df0a713f95;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index ae3ea1f..58ae959 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ Language: C++ -Date: $Date: 2008/02/08 10:05:38 $ -Version: $Revision: 1.3 $ +Date: $Date: 2008/04/18 12:59:15 $ +Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -35,12 +35,70 @@ PURPOSE. See the above copyright notices for more information. namespace bbtk { + + + static bool bbmgSomeBoxExecuting = false; + static bool bbmgFreezeExecution = false; + static std::set bbmgExecutionList; + + //========================================================================= + BlackBox::Deleter::Deleter() + { + } + //========================================================================= + + //========================================================================= + void BlackBox::Deleter::Delete(Object* p) + { + BlackBox* b = dynamic_cast(p); + if (!b) + { + bbtkInternalError("BlackBox::Deleter::Delete("<GetObjectName() + <<"["<GetObjectName();//b->bbGetNameWithParent(); + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<bbGetDescriptor(); + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<bbDelete(); + + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""<GetPackage(); + if (!pack.expired()) + { + Package::ReleaseBlackBoxDescriptor(pack,desc); + } + else + { + bbtkDebugMessage("object",2,"##> BlackBox::Deleter(\""< BlackBox::Deleter(\""< BlackBox::BlackBox(\"" + < BlackBox::BlackBox(" + < BlackBox::~BlackBox() ["<bbDesallocateConnectors(); - //printf("EED BlackBox::~BlackBox 02 \n"); - bbtkDebugDecTab("Kernel",7); - } - //========================================================================= - - //========================================================================= - /// Destruction method of a black box - void BlackBox::bbDelete() - { - bbtkDebugMessage("Kernel",5,"BlackBox::bbDelete() [" - <bbUserDelete(); + bbtkDebugMessage("object",4,"<== BlackBox::~BlackBox() ["< BlackBox::bbExecute() [" <bbGetDescriptor()->GetTypeName()+">"; + return this->bbGetNameWithParent()+"<"+this->bbGetDescriptor()->GetTypeName()+">"; } //========================================================================= @@ -125,9 +178,9 @@ namespace bbtk /// Returns the name with the name of the parent prepended if any std::string BlackBox::bbGetNameWithParent() const { - if (bbmParent) + if (bbmParent.lock()) { - return bbmParent->bbGetNameWithParent() + ":" + bbmName; + return bbmParent.lock()->bbGetNameWithParent() + ":" + bbmName; } else { @@ -217,7 +270,7 @@ namespace bbtk { bbtkDebugMessage("Kernel",8,"* Allocate \""<first<<"\""<second->GetName()] - = new BlackBoxInputConnector(this); + = new BlackBoxInputConnector(GetThisPointer()); } const BlackBoxDescriptor::OutputDescriptorMapType& omap = bbGetDescriptor()->GetOutputDescriptorMap(); @@ -386,7 +439,7 @@ namespace bbtk bbtkDebugMessage("Process",9, "-> Execution triggered by Reactive mode or BoxExecute input change"<bbSetStatus(MODIFIED); - bbGlobalAddToExecutionList( this ); + bbGlobalAddToExecutionList( GetThisPointer() ); } else if ( bbGetStatus() == MODIFIED ) //! this->bbIsUptodate()) { @@ -465,10 +518,10 @@ namespace bbtk } if (reaction) bbGlobalProcessExecutionList(); - bbtkDebugMessageDec("Process",5, - "<= BlackBox::bbSignalOutputModification(" - < to the connection c - void BlackBox::bbConnectInput( const std::string& name, Connection* c) + void BlackBox::bbConnectInput( const std::string& name, Connection::Pointer c) { bbtkDebugMessageInc("Kernel",7, "BlackBox::bbConnectInput(\""< to the connection c - void BlackBox::bbConnectOutput( const std::string& name, Connection* c) + void BlackBox::bbConnectOutput( const std::string& name, Connection::Pointer c) { bbtkDebugMessageInc("Kernel",7, "BlackBox::bbConnectOutput(\""< from the connection c - void BlackBox::bbDisconnectInput( const std::string& name, Connection* c) + void BlackBox::bbDisconnectInput( const std::string& name, Connection::Pointer c) { + if (!c) return; bbtkDebugMessageInc("Kernel",7, "BlackBox::bbDisconnectInput(\""< from the connection c - void BlackBox::bbDisconnectOutput( const std::string& name, Connection* c) + void BlackBox::bbDisconnectOutput( const std::string& name, Connection::Pointer c) { + if (!c) return; bbtkDebugMessageInc("Kernel",7, "BlackBox::bbDisconnectOutput(\""<GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - a = NewAdaptor( - bbGetOutputType(output), - typeid(std::string), - ""); - } catch (bbtk::Exception e) + Factory::Pointer f = p->GetFactorySet().begin()->lock(); + BlackBox::Pointer a; + try + { + a = f->NewAdaptor( + bbGetOutputType(output), + typeid(std::string), + ""); + } catch (bbtk::Exception e) + { + } + if (a){ + // bbUpdate(); + a->bbSetInput("In",bbGetOutput(output)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } else { + v="? (no adaptor found)"; + } + } + else { + v="? (no factory found)"; } - if (a!=NULL){ - // bbUpdate(); - a->bbSetInput("In",bbGetOutput(output)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; - } else { - v="? (no adaptor found)"; - } - } else { - // bbUpdate(); - v = bbGetOutput(output).unsafe_get() ; - } + } + else + { + // bbUpdate(); + v = bbGetOutput(output).unsafe_get() ; + } return v; } //========================================================================= @@ -682,28 +749,38 @@ namespace bbtk // Looks for the adaptor if (bbGetInputType(input) != typeid(std::string)) { - BlackBox* a = 0; - try + // Look for factory + Package::Pointer p = bbGetDescriptor()->GetPackage(); + if ((p != 0) && ( ! p->GetFactorySet().empty() ) ) { - a = NewAdaptor( - bbGetInputType(input), - typeid(std::string), - ""); - }catch (bbtk::Exception e) - { - } - if (a!=NULL) - { - // bbUpdate(); - a->bbSetInput("In",bbGetInput(input)); - a->bbExecute(); - v = a->bbGetOutput("Out").unsafe_get() ; + Factory::Pointer f = p->GetFactorySet().begin()->lock(); + BlackBox::Pointer a; + try + { + a = f->NewAdaptor( + bbGetInputType(input), + typeid(std::string), + ""); + }catch (bbtk::Exception e) + { + } + if (a) + { + // bbUpdate(); + a->bbSetInput("In",bbGetInput(input)); + a->bbExecute(); + v = a->bbGetOutput("Out").unsafe_get() ; + } + else + { + v="? (no adaptor found)"; + } } else { - v="? (no adaptor found)"; + v="? (no factory found)"; } - } + } else { v = bbGetInput(input).unsafe_get() ; @@ -753,22 +830,24 @@ namespace bbtk //========================================================================= /// Write Graphviz-dot description in file void BlackBox::bbWriteDotFileBlackBox(FILE *ff, - BlackBox *parentblackbox, + BlackBox::Pointer parentblackbox, int detail, int level, bool instanceOrtype, bool relative_link ) - { + { InputConnectorMapType::iterator i; // label std::string labelStr; std::string valueStr(""); - if (detail==0) - { - labelStr = bbGetName() ; - } else { - labelStr = bbGetName(); - labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] "; + + if (detail==0) { + labelStr = bbGetName() ; +//EED 18 Fev 2008 + labelStr = labelStr + "\\n[" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "]"; + } else { + labelStr = bbGetName(); + labelStr = labelStr + " [" +this->bbGetDescriptor()->GetPackage()->GetName()+"::"+ bbGetTypeName() + "] "; } SubsBrackets(labelStr); @@ -834,15 +913,15 @@ namespace bbtk // std::cout << labelStr << std::endl; // Relation Input - if (this!=parentblackbox){ + if (GetThisPointer()!=parentblackbox){ for ( i = mInputConnectorMap.begin(); i != mInputConnectorMap.end(); ++i ) { if (i->second) { - Connection* con = i->second->GetConnection(); + Connection::Pointer con = i->second->GetConnection(); if (con!=NULL){ - BlackBox *a=con->GetBlackBoxFrom(); - BlackBox *b=con->GetBlackBoxTo(); + BlackBox::Pointer a=con->GetBlackBoxFrom(); + BlackBox::Pointer b=con->GetBlackBoxTo(); fprintf(ff," "); a->bbWriteDotInputOutputName(ff,false,detail,level); if (detail==1) @@ -867,7 +946,7 @@ namespace bbtk //========================================================================= - void BlackBox::bbShowRelations(BlackBox *parentblackbox, + void BlackBox::bbShowRelations(BlackBox::Pointer parentblackbox, int detail, int level /*,Factory *factory*/ ) { @@ -900,7 +979,7 @@ namespace bbtk ivalue.push_back(bbGetInputAsString(i->first)); if (ivalue.back().size()>valuelmax) valuelmax = ivalue.back().size(); std::string s(""); - Connection* con = i->second->GetConnection(); + Connection::Pointer con = i->second->GetConnection(); if (con!=0){ s = con->GetBlackBoxFrom()->bbGetName(); s += "."; @@ -919,14 +998,15 @@ namespace bbtk ovalue.push_back(bbGetOutputAsString(o->first)); if (ovalue.back().size()>valuelmax) valuelmax = ovalue.back().size(); std::vector ss; - const std::vector& con = o->second->GetConnectionVector(); - std::vector::const_iterator c; + const std::vector& con + = o->second->GetConnectionVector(); + std::vector::const_iterator c; for (c=con.begin();c!=con.end();++c) { std::string s; - s = (*c)->GetBlackBoxTo()->bbGetName(); + s = (*c).lock()->GetBlackBoxTo()->bbGetName(); s += "."; - s += (*c)->GetBlackBoxToInput(); + s += (*c).lock()->GetBlackBoxToInput(); ss.push_back(s); } // if con oconn.push_back(ss); @@ -995,7 +1075,7 @@ namespace bbtk "=> BlackBox::bbGlobalProcessExecutionList()" <::iterator i; + std::set::iterator i; for (i=bbmgExecutionList.begin(); i!=bbmgExecutionList.end(); ++i) @@ -1014,13 +1094,50 @@ namespace bbtk } //========================================================================= + bool BlackBox::bbGlobalGetSomeBoxExecuting() + { + return bbmgSomeBoxExecuting; + } + + void BlackBox::bbGlobalSetSomeBoxExecuting(bool b) + { + bbmgSomeBoxExecuting = b; + } + + void BlackBox::bbGlobalSetFreezeExecution(bool b) + { + bbmgFreezeExecution = b; + } + + bool BlackBox::bbGlobalGetFreezeExecution() + { + return bbmgFreezeExecution; + } + + void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b ) + { + bbmgExecutionList.insert(b); + } + + //========================================================================= // Static members initialization +/*EED bool BlackBox::bbmgSomeBoxExecuting = false; bool BlackBox::bbmgFreezeExecution = false; std::set BlackBox::bbmgExecutionList; +*/ //========================================================================= + //========================================================================= + void BlackBox::Check(bool recursive) + { + bbtkMessage("Debug",1,"*** Checking Black Box "<<(void*)this<<" ["<