2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.14 $
34 =========================================================================*/
39 * \brief Class bbtk::BlackBoxOutputConnector :
42 #include "bbtkBlackBoxOutputConnector.h"
43 #include "bbtkMessageManager.h"
44 #include "bbtkBlackBox.h"
45 //#include <algorithm>
50 //========================================================================
52 class BlackBoxOutputConnector::Pimpl
55 Pimpl() : mStatus(OUTOFDATE) {}
56 Pimpl(const Pimpl&) {}
58 BlackBoxWeakPointer mBox;
59 /// The vector of output connections
60 ConnectionVector mConnection;
61 /// The status of the output
63 /// The output changed signal
64 BlackBox::OutputChangeSignalType mChangeSignal;
66 //========================================================================
68 //========================================================================
69 BBTK_IMPL_PIMPL(BlackBoxOutputConnector)
70 //========================================================================
73 //======================================================================
74 BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b)
76 bbtkDebugMessage("kernel",9,
78 <<"] BlackBoxOutputConnector()"<<std::endl);
82 //======================================================================
85 //======================================================================
86 BlackBoxOutputConnector::~BlackBoxOutputConnector()
88 bbtkDebugMessage("kernel",9,
89 "[DEAD BOX] ==> ~BlackBoxOutputConnector()"
92 ConnectionVector::iterator i;
93 for (i=mConnection.begin();
96 (*i) = Connection::WeakPointer();
98 p->mConnection.clear();
101 bbtkDebugMessage("kernel",9,
102 "[DEAD BOX] <== ~BlackBoxOutputConnector()"
105 //======================================================================
107 //======================================================================
109 void BlackBoxOutputConnector::SetConnection(Connection* c)
111 bbtkDebugMessage("kernel",9,
112 "["<<p->mBox.lock()->bbGetName()
113 <<"] BlackBoxOutputConnector::SetConnection("
114 <<c<<")"<<std::endl);
115 p->mConnection.push_back(c);
116 // AddChangeObserver(boost::bind(&Connection::SignalChange,c));
118 //======================================================================
121 //======================================================================
122 void BlackBoxOutputConnector::UnsetConnection(Connection* c)
124 bbtkDebugMessage("kernel",9,"["<<p->mBox.lock()->bbGetName()
125 <<"] BlackBoxOutputConnector::UnsetConnection("
126 <<c<<")"<<std::endl);
130 bbtkInternalError(p->mBox.lock()->bbGetFullName()
131 <<": BlackBoxOutputConnector::UnsetConnection("
132 <<c<<") : invalid connection");
136 //Connection::WeakPointer w(c);
137 ConnectionVector::iterator i;
138 // = find(mConnection.begin(),mConnection.end(),c);
139 for (i=p->mConnection.begin();
140 i!=p->mConnection.end();
145 if (i==p->mConnection.end())
147 bbtkInternalError(p->mBox.lock()->bbGetFullName()
148 <<": BlackBoxOutputConnector::UnsetConnection("
150 <<") : connection is absent from connections list");
152 p->mConnection.erase(i);
153 // RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
157 //======================================================================
159 //======================================================================
160 const BlackBoxOutputConnector::ConnectionVector&
161 BlackBoxOutputConnector::GetConnectionVector() const
163 return p->mConnection;
165 //======================================================================
167 //======================================================================
168 /// Returns the status of the input
169 IOStatus BlackBoxOutputConnector::GetStatus() const
173 //======================================================================
175 //======================================================================
176 /// Sets the status of the input
177 void BlackBoxOutputConnector::SetStatus( IOStatus s )
181 //======================================================================
183 //======================================================================
184 void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
185 const std::string& output )
187 IOStatus s = OUTOFDATE; //mStatus;
188 //if (s==UPTODATE) s=MODIFIED;
190 bbtkDebugMessage("change",2,
191 "["<<box->bbGetName()
192 <<"] ==> BlackBoxOutputConnector::SignalChange('"
193 <<output<<"','"<<GetIOStatusString(s)<<"') ["
197 // std::cout<<"BlackBoxOutputConnector::SignalChange("
198 // <<box->bbGetName()<<",'"
199 // <<output<<"')"<<std::endl;
200 p->mChangeSignal(box,output,s);
202 bbtkDebugMessage("change",2,
203 "["<<box->bbGetName()
204 <<"] <== BlackBoxOutputConnector::SignalChange('"
205 <<output<<"','"<<GetIOStatusString(s)<<"') ["
209 //======================================================================
211 //======================================================================
212 void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
214 // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
215 p->mChangeSignal.connect(f);
217 //======================================================================
219 //======================================================================
220 /// Removes the function f from the list of functions to call when
221 /// the output changes (TO WRITE)
222 void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
224 bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
226 //mChangeSignal.disconnect(f);
228 //======================================================================