1 /*=========================================================================
3 Module: $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
5 Date: $Date: 2009/06/08 14:50:03 $
6 Version: $Revision: 1.13 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
34 * \brief Class bbtk::BlackBoxOutputConnector :
37 #include "bbtkBlackBoxOutputConnector.h"
38 #include "bbtkMessageManager.h"
39 #include "bbtkBlackBox.h"
40 //#include <algorithm>
45 //========================================================================
47 class BlackBoxOutputConnector::Pimpl
50 Pimpl() : mStatus(OUTOFDATE) {}
51 Pimpl(const Pimpl&) {}
53 BlackBoxWeakPointer mBox;
54 /// The vector of output connections
55 ConnectionVector mConnection;
56 /// The status of the output
58 /// The output changed signal
59 BlackBox::OutputChangeSignalType mChangeSignal;
63 //========================================================================
65 //========================================================================
66 BBTK_IMPL_PIMPL(BlackBoxOutputConnector)
67 //========================================================================
70 //======================================================================
71 BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b)
73 bbtkDebugMessage("kernel",9,
75 <<"] BlackBoxOutputConnector()"<<std::endl);
79 //======================================================================
82 //======================================================================
83 BlackBoxOutputConnector::~BlackBoxOutputConnector()
85 bbtkDebugMessage("kernel",9,
86 "[DEAD BOX] ==> ~BlackBoxOutputConnector()"
89 ConnectionVector::iterator i;
90 for (i=mConnection.begin();
93 (*i) = Connection::WeakPointer();
95 p->mConnection.clear();
98 bbtkDebugMessage("kernel",9,
99 "[DEAD BOX] <== ~BlackBoxOutputConnector()"
102 //======================================================================
104 //======================================================================
106 void BlackBoxOutputConnector::SetConnection(Connection* c)
108 bbtkDebugMessage("kernel",9,
109 "["<<p->mBox.lock()->bbGetName()
110 <<"] BlackBoxOutputConnector::SetConnection("
111 <<c<<")"<<std::endl);
112 p->mConnection.push_back(c);
113 // AddChangeObserver(boost::bind(&Connection::SignalChange,c));
115 //======================================================================
118 //======================================================================
119 void BlackBoxOutputConnector::UnsetConnection(Connection* c)
121 bbtkDebugMessage("kernel",9,"["<<p->mBox.lock()->bbGetName()
122 <<"] BlackBoxOutputConnector::UnsetConnection("
123 <<c<<")"<<std::endl);
127 bbtkInternalError(p->mBox.lock()->bbGetFullName()
128 <<": BlackBoxOutputConnector::UnsetConnection("
129 <<c<<") : invalid connection");
133 //Connection::WeakPointer w(c);
134 ConnectionVector::iterator i;
135 // = find(mConnection.begin(),mConnection.end(),c);
136 for (i=p->mConnection.begin();
137 i!=p->mConnection.end();
142 if (i==p->mConnection.end())
144 bbtkInternalError(p->mBox.lock()->bbGetFullName()
145 <<": BlackBoxOutputConnector::UnsetConnection("
147 <<") : connection is absent from connections list");
149 p->mConnection.erase(i);
150 // RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
154 //======================================================================
156 //======================================================================
157 const BlackBoxOutputConnector::ConnectionVector&
158 BlackBoxOutputConnector::GetConnectionVector() const
160 return p->mConnection;
162 //======================================================================
164 //======================================================================
165 /// Returns the status of the input
166 IOStatus BlackBoxOutputConnector::GetStatus() const
170 //======================================================================
172 //======================================================================
173 /// Sets the status of the input
174 void BlackBoxOutputConnector::SetStatus( IOStatus s )
178 //======================================================================
180 //======================================================================
181 void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
182 const std::string& output )
184 IOStatus s = OUTOFDATE; //mStatus;
185 //if (s==UPTODATE) s=MODIFIED;
187 bbtkDebugMessage("change",2,
188 "["<<box->bbGetName()
189 <<"] ==> BlackBoxOutputConnector::SignalChange('"
190 <<output<<"','"<<GetIOStatusString(s)<<"') ["
194 // std::cout<<"BlackBoxOutputConnector::SignalChange("
195 // <<box->bbGetName()<<",'"
196 // <<output<<"')"<<std::endl;
197 p->mChangeSignal(box,output,s);
199 bbtkDebugMessage("change",2,
200 "["<<box->bbGetName()
201 <<"] <== BlackBoxOutputConnector::SignalChange('"
202 <<output<<"','"<<GetIOStatusString(s)<<"') ["
206 //======================================================================
208 //======================================================================
209 void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
211 // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
212 p->mChangeSignal.connect(f);
214 //======================================================================
216 //======================================================================
217 /// Removes the function f from the list of functions to call when
218 /// the output changes (TO WRITE)
219 void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
221 bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
223 //mChangeSignal.disconnect(f);
225 //======================================================================