bbtkBlackBoxOutputConnector.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2009/06/08 14:50:03 $
00006   Version:   $Revision: 1.13 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00037 #include "bbtkBlackBoxOutputConnector.h"
00038 #include "bbtkMessageManager.h"
00039 #include "bbtkBlackBox.h"
00040 //#include <algorithm>
00041 
00042 namespace bbtk
00043 {
00044 
00045   //========================================================================
00047   class BlackBoxOutputConnector::Pimpl
00048   {
00049   public:
00050     Pimpl() : mStatus(OUTOFDATE) {}
00051     Pimpl(const Pimpl&) {}
00053     BlackBoxWeakPointer mBox;
00055     ConnectionVector mConnection;
00057     IOStatus mStatus;
00059     BlackBox::OutputChangeSignalType mChangeSignal;
00060 
00061 
00062   };
00063   //========================================================================
00064 
00065   //========================================================================
00066   BBTK_IMPL_PIMPL(BlackBoxOutputConnector)
00067   //========================================================================
00068 
00069 
00070   //======================================================================
00071   BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b) 
00072   {
00073     bbtkDebugMessage("kernel",9,
00074                      "["<<b->bbGetName()
00075                      <<"] BlackBoxOutputConnector()"<<std::endl);
00076     PimplConstruct();
00077     p->mBox = b;
00078   }
00079   //======================================================================
00080 
00081 
00082   //======================================================================
00083   BlackBoxOutputConnector::~BlackBoxOutputConnector() 
00084   {
00085     bbtkDebugMessage("kernel",9,
00086                      "[DEAD BOX] ==> ~BlackBoxOutputConnector()"
00087                      <<std::endl);
00088     /*
00089     ConnectionVector::iterator i;
00090     for (i=mConnection.begin();
00091          i!=mConnection.end();
00092          ++i)
00093       (*i) = Connection::WeakPointer();
00094     */
00095     p->mConnection.clear();
00096     PimplDestruct();
00097   
00098     bbtkDebugMessage("kernel",9,
00099                      "[DEAD BOX] <== ~BlackBoxOutputConnector()"
00100                      <<std::endl);
00101   }
00102   //======================================================================
00103 
00104   //======================================================================
00106   void BlackBoxOutputConnector::SetConnection(Connection* c)
00107   {
00108     bbtkDebugMessage("kernel",9,
00109                      "["<<p->mBox.lock()->bbGetName()
00110                      <<"] BlackBoxOutputConnector::SetConnection("
00111                      <<c<<")"<<std::endl);
00112     p->mConnection.push_back(c);
00113     //    AddChangeObserver(boost::bind(&Connection::SignalChange,c));
00114   }
00115   //======================================================================
00116 
00117 
00118   //======================================================================
00119   void BlackBoxOutputConnector::UnsetConnection(Connection* c)
00120   {
00121     bbtkDebugMessage("kernel",9,"["<<p->mBox.lock()->bbGetName()
00122                      <<"] BlackBoxOutputConnector::UnsetConnection("
00123                      <<c<<")"<<std::endl);
00124 
00125     if (!c) 
00126       {
00127         bbtkInternalError(p->mBox.lock()->bbGetFullName()
00128                           <<": BlackBoxOutputConnector::UnsetConnection("
00129                           <<c<<") : invalid connection");
00130 
00131       }
00132     //    c->Check();
00133     //Connection::WeakPointer w(c);
00134     ConnectionVector::iterator i;
00135     //  = find(mConnection.begin(),mConnection.end(),c);
00136     for (i=p->mConnection.begin();
00137          i!=p->mConnection.end();
00138          ++i)
00139       {
00140         if (*i==c) break;
00141       }
00142     if (i==p->mConnection.end())
00143       {
00144         bbtkInternalError(p->mBox.lock()->bbGetFullName()
00145                           <<": BlackBoxOutputConnector::UnsetConnection("
00146                           <<c
00147                           <<") : connection is absent from connections list");
00148       }
00149     p->mConnection.erase(i);
00150     //    RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
00151 
00152 
00153   }
00154   //======================================================================
00155   
00156   //======================================================================
00157   const BlackBoxOutputConnector::ConnectionVector& 
00158   BlackBoxOutputConnector::GetConnectionVector() const
00159   { 
00160     return p->mConnection; 
00161   }
00162   //======================================================================
00163   
00164   //======================================================================
00166   IOStatus BlackBoxOutputConnector::GetStatus() const 
00167   { 
00168     return p->mStatus; 
00169   }
00170   //======================================================================
00171 
00172   //======================================================================
00174   void BlackBoxOutputConnector::SetStatus( IOStatus s ) 
00175   {
00176     p->mStatus = s; 
00177   }
00178   //======================================================================
00179   
00180   //======================================================================
00181   void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
00182                                               const std::string& output )
00183   {
00184     IOStatus s = OUTOFDATE; //mStatus;
00185     //if (s==UPTODATE) s=MODIFIED;
00186     
00187     bbtkDebugMessage("change",2,
00188                      "["<<box->bbGetName()
00189                      <<"] ==> BlackBoxOutputConnector::SignalChange('"
00190                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
00191                      <<this<<"]"
00192                      <<std::endl);
00193     
00194     //    std::cout<<"BlackBoxOutputConnector::SignalChange("
00195     //       <<box->bbGetName()<<",'"
00196     //       <<output<<"')"<<std::endl;
00197     p->mChangeSignal(box,output,s);
00198     
00199     bbtkDebugMessage("change",2,
00200                      "["<<box->bbGetName()
00201                      <<"] <== BlackBoxOutputConnector::SignalChange('"
00202                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
00203                      <<this<<"]"
00204                      <<std::endl);
00205   }
00206   //======================================================================
00207 
00208   //======================================================================
00209   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
00210   { 
00211     //    std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
00212     p->mChangeSignal.connect(f); 
00213   }
00214   //======================================================================
00215   
00216   //======================================================================
00219   void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
00220   { 
00221     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
00222     
00223     //mChangeSignal.disconnect(f);
00224   }
00225   //======================================================================
00226 }
00227 // namespace bbtk
00228 

Generated on Thu May 31 14:12:03 2012 for BBTK by  doxygen 1.5.7.1