1 /*=========================================================================
3 Module: $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
5 Date: $Date: 2008/12/10 09:33:18 $
6 Version: $Revision: 1.11 $
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()
49 bbtkDebugMessage("Kernel",9,"BlackBoxOutputConnector::BlackBoxOutputConnector()"<<std::endl);
51 //======================================================================
54 //======================================================================
55 BlackBoxOutputConnector::~BlackBoxOutputConnector()
57 bbtkDebugMessage("Kernel",9,
58 "==> BlackBoxOutputConnector::~BlackBoxOutputConnector()"
61 ConnectionVector::iterator i;
62 for (i=mConnection.begin();
65 (*i) = Connection::WeakPointer();
68 bbtkDebugMessage("Kernel",9,
69 "<== BlackBoxOutputConnector::~BlackBoxOutputConnector()"
72 //======================================================================
74 //======================================================================
76 void BlackBoxOutputConnector::SetConnection(Connection* c)
78 bbtkDebugMessage("Kernel",9,"BlackBoxOutputConnector::SetConnection("
80 mConnection.push_back(c);
81 // AddChangeObserver(boost::bind(&Connection::SignalChange,c));
83 //======================================================================
86 //======================================================================
87 void BlackBoxOutputConnector::UnsetConnection(Connection* c)
89 bbtkDebugMessageInc("Kernel",9,"BlackBoxOutputConnector::UnsetConnection("
94 bbtkInternalError("BlackBoxOutputConnector::UnsetConnection("<<c<<") : invalid connection");
98 //Connection::WeakPointer w(c);
99 ConnectionVector::iterator i;
100 // = find(mConnection.begin(),mConnection.end(),c);
101 for (i=mConnection.begin();
102 i!=mConnection.end();
107 if (i==mConnection.end())
109 bbtkInternalError("BlackBoxOutputConnector::UnsetConnection("<<c<<") : connection is absent from connections list");
111 mConnection.erase(i);
112 // RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
114 bbtkDebugDecTab("Kernel",9);
116 //======================================================================
119 //======================================================================
120 void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
121 const std::string& output )
123 IOStatus s = OUTOFDATE; //mStatus;
124 //if (s==UPTODATE) s=MODIFIED;
126 bbtkDebugMessage("change",2,
127 "==> BlackBoxOutputConnector::SignalChange("
128 <<box->bbGetFullName()<<",'"
129 <<output<<"','"<<GetIOStatusString(s)<<"') ["
133 // std::cout<<"BlackBoxOutputConnector::SignalChange("
134 // <<box->bbGetFullName()<<",'"
135 // <<output<<"')"<<std::endl;
136 mChangeSignal(box,output,s);
138 bbtkDebugMessage("change",2,
139 "<== BlackBoxOutputConnector::SignalChange("
140 <<box->bbGetFullName()<<",'"
141 <<output<<"','"<<GetIOStatusString(s)<<"') ["
145 //======================================================================
147 void BlackBoxOutputConnector::SetModifiedStatus()
149 bbtkDebugMessage("modified",2,
150 "==> BlackBoxOutputConnector::SetModifiedStatus() ["
153 ConnectionVector::iterator i;
154 for (i=mConnection.begin();i!=mConnection.end();++i)
156 (*i)->SetModifiedStatus();
163 //======================================================================
164 void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
166 bbtkDebugMessage("change",2,
167 "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
170 if (mChangeTime.Set(t))
174 bbtkDebugMessage("change",2,
175 "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
179 //======================================================================
182 //======================================================================
183 void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
185 bbtkDebugMessage("change",2,
186 "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
189 mChangeTime.Set(ChangeTime::GetCurrentTime());
192 bbtkDebugMessage("change",2,
193 "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
197 //======================================================================
201 //======================================================================
202 void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
204 // std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
205 mChangeSignal.connect(f);
207 //======================================================================
209 //======================================================================
210 /// Removes the function f from the list of functions to call when
211 /// the output changes (TO WRITE)
212 void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
214 bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
216 //mChangeSignal.disconnect(f);
218 //======================================================================