X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=kernel%2Fsrc%2FbbtkConnection.cxx;h=37c0eb6be1448122aacd7f025324e4f973e34329;hb=8dd53a72bc1dd1ca2c6e2763c0aeb51c77ee352e;hp=4a6b7059e426b6db6e9a90df2c4b6becb6ddfd47;hpb=50a1ea04e85dcca944eceff2524e8ca06e373a63;p=bbtk.git diff --git a/kernel/src/bbtkConnection.cxx b/kernel/src/bbtkConnection.cxx index 4a6b705..37c0eb6 100644 --- a/kernel/src/bbtkConnection.cxx +++ b/kernel/src/bbtkConnection.cxx @@ -1,20 +1,33 @@ -/*========================================================================= - +/*========================================================================= Program: bbtk Module: $RCSfile: bbtkConnection.cxx,v $ Language: C++ - Date: $Date: 2008/04/25 13:37:48 $ - Version: $Revision: 1.13 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See doc/license.txt or - http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - + Date: $Date: 2009/03/30 14:42:16 $ + Version: $Revision: 1.20 $ =========================================================================*/ + +/* --------------------------------------------------------------------- + +* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) +* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux +* +* This software is governed by the CeCILL-B license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL-B +* license as circulated by CEA, CNRS and INRIA at the following URL +* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +* or in the file LICENSE.txt. +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited +* liability. +* +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL-B license and that you accept its terms. +* ------------------------------------------------------------------------ */ + /** *\file *\brief Class bbtk::Connection @@ -24,9 +37,17 @@ #include "bbtkFactory.h" #include "bbtkBlackBox.h" #include "bbtkMessageManager.h" +#include "bbtkBlackBoxOutputConnector.h" namespace bbtk { + const std::string IOSTATUS_STRING[3] = + {"Up-to-date","Modified","Out-of-date"}; + + const std::string& GetIOStatusString(IOStatus s) + { return IOSTATUS_STRING[s]; } + + //================================================================== Connection::Pointer Connection::New(BlackBox::Pointer from, const std::string& output, BlackBox::Pointer to, @@ -45,6 +66,7 @@ namespace bbtk <bbGetOutputType(output) == typeid(Data) ) { - bbtkWarning("Connection '" - <bbGetName()<<"."<bbGetName()<<"."<() <<"> : type compatibility with '" @@ -134,6 +154,125 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, } + mFrom = from; + mOriginalFrom = from; + mTo = to; + mOriginalTo = to; + mInput = mOriginalInput = input; + mOutput = mOriginalOutput = output; + + // Lock this pointer !!! + //Pointer p = MakePointer(this,true); + from->bbConnectOutput(output,this); + to->bbConnectInput(input,this); + + from->bbGetOutputConnector(output).AddChangeObserver(boost::bind(&bbtk::Connection::OnOutputChange,this, _1, _2, _3)); + + + bbtkDebugMessage("connection",1,"<== Connection::Connection(\"" + <bbGetFullName()<<"\",\""<bbGetFullName()<<"\",\""< Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""< Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""<bbGetName()<<"\",\""< Connection::Connection(\"" + <bbGetName()<<"\",\""<bbGetName()<<"\",\""< Connection::Connection(\"" + <bbGetFullName()<<"\",\""<bbGetFullName()<<"\",\""<bbHasOutput(output) ) + { + bbtkError("The box \""<bbGetTypeName()<< + "\" has no output \""<bbHasInput(input) ) + { + bbtkError("The box \""<bbGetTypeName()<< + "\" has no input \""<bbGetInputConnectorMap().find(input)->second->IsConnected()) + { + bbtkError("The input \""<bbGetName() + <<"\" is already connected"); + } + + // std::string t1 ( from->bbGetOutputType(output).name() ); + // std::string t2 ( to->bbGetInputType(input).name() ); + // if //( t1 != t2 ) + if ( from->bbGetOutputType(output) != + to->bbGetInputType(input) ) + { + if ( from->bbGetOutputType(output) == typeid(Data) ) + { + bbtkWarning("Connection '" + <bbGetName()<<"."<() + <<"> : type compatibility with '" + <bbGetName()<<"."<bbGetInputType(input) == typeid(Data) ) + { + bbtkDebugMessage("Kernel",8," -> '"<()<<" : can receive any data" + <bbConnectOutput(output,this); to->bbConnectInput(input,this); + from->bbGetOutputConnector(output).AddChangeObserver(boost::bind(&bbtk::Connection::OnOutputChange,this, _1, _2, _3)); bbtkDebugMessage("connection",1,"<== Connection::Connection(\"" <bbGetFullName()<<"\",\""< Connection::BackwardUpdate() [" + bbtkDebugMessage("process",4, + "===> Connection::RecursiveExecute() [" <bbBackwardUpdate(GetThisPointer()); + /* + // If box from already executing : nothing to do + if (mFrom->bbGetExecuting()) + { + bbtkDebugMessage("process",3, + " -> "<bbGetName() + <<" already executing : abort"<bbSetModifiedStatus(); + mFrom->bbRecursiveExecute(GetThisPointer()); - bbtkDebugMessage("process",5, - "<=== Connection::BackwardUpdate() [" + TransferData(); + + // Transfer status + IOStatus s = MODIFIED; + if ( mFrom->bbGetOutputConnector(mOutput).GetStatus() == OUTOFDATE) + { + s = OUTOFDATE; + } + mTo->bbGetInputConnector(mInput).SetStatus(s); + + bbtkDebugMessage("process",4, + " --> '"<bbGetName()<<"."<bbGetInputConnector(mInput)<<"] " + <<"' new status '" + <bbForwardUpdate(this); - - bbtkDebugDecTab("process",2); - } - //================================================================== - */ //================================================================== /// Transfers the data from the source output to the target input @@ -269,8 +417,14 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, <bbGetInputType(mInput)) <<">"<bbGetOutput(mOutput).type() == typeid(void)) + { + bbtkDebugMessage("data",3, + " -> Source is void : nothing to transfer!"<bbGetOutput(mOutput) + else if (mFrom->bbGetOutput(mOutput) .contains( mTo->bbGetInputType(mInput) ) ) { bbtkDebugMessage("data",3, @@ -348,24 +502,25 @@ Connection::Connection(BlackBox::Pointer from, const std::string& output, } //================================================================== - + //================================================================== - /// Modified - void Connection::SetModifiedStatus() + /// From.Output change propagation + void Connection::OnOutputChange(bbtk::BlackBox::Pointer, const std::string&, + IOStatus status) { - bbtkDebugMessage("modified",2, - "==> Connection::SetModifiedStatus() [" + bbtkDebugMessage("change",2, + "==> Connection::OnOutputChange(" + <bbGetInputConnectorMap().find("In")->second; + mAdaptor->bbSetStatusAndPropagate(ac,status); + } - if (mAdaptor) mAdaptor->bbSetModifiedStatus(); - - mTo->bbSetModifiedStatus( mTo->bbGetInputConnectorMap().find(mInput)->second ); + mTo->bbSetStatusAndPropagate( mTo->bbGetInputConnectorMap().find(mInput)->second, status); - /* - bbtkDebugMessage("modified",2, - "==> Connection::SetModifiedStatus() [" - <