1 /*=========================================================================
3 Module: $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
5 Date: $Date: 2009/05/28 08:12:05 $
6 Version: $Revision: 1.12 $
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 //======================================================================
46 BlackBoxOutputConnector::BlackBoxOutputConnector(BlackBox::Pointer b)
50 bbtkDebugMessage("kernel",9,
52 <<"] BlackBoxOutputConnector()"<<std::endl);
54 //======================================================================
57 //======================================================================
58 BlackBoxOutputConnector::~BlackBoxOutputConnector()
60 bbtkDebugMessage("kernel",9,
61 "[NULL"//<<mBox.lock()->bbGetName()
62 <<"] ==> ~BlackBoxOutputConnector()"
65 ConnectionVector::iterator i;
66 for (i=mConnection.begin();
69 (*i) = Connection::WeakPointer();
72 bbtkDebugMessage("kernel",9,
73 "[NULL"//<<mBox.lock()->bbGetName()
74 <<"] <== ~BlackBoxOutputConnector()"
77 //======================================================================
79 //======================================================================
81 void BlackBoxOutputConnector::SetConnection(Connection* c)
83 bbtkDebugMessage("kernel",9,
84 "["<<mBox.lock()->bbGetName()
85 <<"] BlackBoxOutputConnector::SetConnection("
87 mConnection.push_back(c);
88 // AddChangeObserver(boost::bind(&Connection::SignalChange,c));
90 //======================================================================
93 //======================================================================
94 void BlackBoxOutputConnector::UnsetConnection(Connection* c)
96 bbtkDebugMessage("kernel",9,"["<<mBox.lock()->bbGetName()
97 <<"] BlackBoxOutputConnector::UnsetConnection("
102 bbtkInternalError(mBox.lock()->bbGetFullName()
103 <<": BlackBoxOutputConnector::UnsetConnection("
104 <<c<<") : invalid connection");
108 //Connection::WeakPointer w(c);
109 ConnectionVector::iterator i;
110 // = find(mConnection.begin(),mConnection.end(),c);
111 for (i=mConnection.begin();
112 i!=mConnection.end();
117 if (i==mConnection.end())
119 bbtkInternalError(mBox.lock()->bbGetFullName()
120 <<": BlackBoxOutputConnector::UnsetConnection("
122 <<") : connection is absent from connections list");
124 mConnection.erase(i);
125 // RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
129 //======================================================================
132 //======================================================================
133 void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
134 const std::string& output )
136 IOStatus s = OUTOFDATE; //mStatus;
137 //if (s==UPTODATE) s=MODIFIED;
139 bbtkDebugMessage("change",2,
140 "["<<box->bbGetName()
141 <<"] ==> BlackBoxOutputConnector::SignalChange('"
142 <<output<<"','"<<GetIOStatusString(s)<<"') ["
146 // std::cout<<"BlackBoxOutputConnector::SignalChange("
147 // <<box->bbGetName()<<",'"
148 // <<output<<"')"<<std::endl;
149 mChangeSignal(box,output,s);
151 bbtkDebugMessage("change",2,
152 "["<<box->bbGetName()
153 <<"] <== BlackBoxOutputConnector::SignalChange('"
154 <<output<<"','"<<GetIOStatusString(s)<<"') ["
158 //======================================================================
160 void BlackBoxOutputConnector::SetModifiedStatus()
162 bbtkDebugMessage("modified",2,
163 "==> BlackBoxOutputConnector::SetModifiedStatus() ["
166 ConnectionVector::iterator i;
167 for (i=mConnection.begin();i!=mConnection.end();++i)
169 (*i)->SetModifiedStatus();
176 //======================================================================
177 void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
179 bbtkDebugMessage("change",2,
180 "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
183 if (mChangeTime.Set(t))
187 bbtkDebugMessage("change",2,
188 "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
192 //======================================================================
195 //======================================================================
196 void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
198 bbtkDebugMessage("change",2,
199 "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
202 mChangeTime.Set(ChangeTime::GetCurrentTime());
205 bbtkDebugMessage("change",2,
206 "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
210 //======================================================================
214 //======================================================================
215 void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
217 // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
218 mChangeSignal.connect(f);
220 //======================================================================
222 //======================================================================
223 /// Removes the function f from the list of functions to call when
224 /// the output changes (TO WRITE)
225 void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
227 bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
229 //mChangeSignal.disconnect(f);
231 //======================================================================