]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxOutputConnector.cxx
* Major changes on IOStatus update / propagation
[bbtk.git] / kernel / src / bbtkBlackBoxOutputConnector.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBoxOutputConnector.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/08 12:54:00 $
6   Version:   $Revision: 1.9 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *  \file 
34  *  \brief Class bbtk::BlackBoxOutputConnector : 
35  */
36
37 #include "bbtkBlackBoxOutputConnector.h"
38 #include "bbtkMessageManager.h"
39 #include "bbtkBlackBox.h"
40 //#include <algorithm>
41
42 namespace bbtk
43 {
44
45   //======================================================================
46   BlackBoxOutputConnector::BlackBoxOutputConnector() 
47     : mStatus(OUTOFDATE)
48   {
49     bbtkDebugMessage("Kernel",9,"BlackBoxOutputConnector::BlackBoxOutputConnector()"<<std::endl);
50   }
51   //======================================================================
52
53
54   //======================================================================
55   BlackBoxOutputConnector::~BlackBoxOutputConnector() 
56   {
57     bbtkDebugMessage("Kernel",9,
58                      "==> BlackBoxOutputConnector::~BlackBoxOutputConnector()"
59                      <<std::endl);
60     /*
61     ConnectionVector::iterator i;
62     for (i=mConnection.begin();
63          i!=mConnection.end();
64          ++i)
65       (*i) = Connection::WeakPointer();
66     */
67     mConnection.clear();
68     bbtkDebugMessage("Kernel",9,
69                      "<== BlackBoxOutputConnector::~BlackBoxOutputConnector()"
70                      <<std::endl);
71   }
72   //======================================================================
73
74   //======================================================================
75   ///
76   void BlackBoxOutputConnector::SetConnection(Connection* c)
77   {
78     bbtkDebugMessage("Kernel",9,"BlackBoxOutputConnector::SetConnection("
79                      <<c<<")"<<std::endl);
80     mConnection.push_back(c);
81     //    AddChangeObserver(boost::bind(&Connection::SignalChange,c));
82   }
83   //======================================================================
84
85
86   //======================================================================
87   void BlackBoxOutputConnector::UnsetConnection(Connection* c)
88   {
89     bbtkDebugMessageInc("Kernel",9,"BlackBoxOutputConnector::UnsetConnection("
90                      <<c<<")"<<std::endl);
91
92     if (!c) 
93       {
94         bbtkInternalError("BlackBoxOutputConnector::UnsetConnection("<<c<<") : invalid connection");
95
96       }
97     //    c->Check();
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();
103          ++i)
104       {
105         if (*i==c) break;
106       }
107     if (i==mConnection.end())
108       {
109         bbtkInternalError("BlackBoxOutputConnector::UnsetConnection("<<c<<") : connection is absent from connections list");
110       }
111     mConnection.erase(i);
112     //    RemoveChangeObserver(boost::bind(&Connection::SignalChange,c));
113
114     bbtkDebugDecTab("Kernel",9);
115   }
116   //======================================================================
117
118   
119    //======================================================================
120   void BlackBoxOutputConnector::SignalChange( BlackBox::Pointer box,
121                                               const std::string& output )
122   {
123     bbtkDebugMessage("change",2,
124                      "==> BlackBoxOutputConnector::SignalChange("
125                      <<box->bbGetFullName()<<",'"
126                      <<output<<"','"<<GetIOStatusString(mStatus)<<"') ["
127                      <<this<<"]"
128                      <<std::endl);
129
130     mChangeSignal(box,output,mStatus);
131
132     bbtkDebugMessage("change",2,
133                      "<== BlackBoxOutputConnector::SignalChange("
134                      <<box->bbGetFullName()<<",'"
135                      <<output<<"','"<<GetIOStatusString(mStatus)<<"') ["
136                      <<this<<"]"
137                      <<std::endl);
138   }
139   //======================================================================
140  /*
141   void BlackBoxOutputConnector::SetModifiedStatus()
142   {
143     bbtkDebugMessage("modified",2,
144                      "==> BlackBoxOutputConnector::SetModifiedStatus() ["
145                      <<this<<"]"
146                      <<std::endl);
147     ConnectionVector::iterator i;
148     for (i=mConnection.begin();i!=mConnection.end();++i) 
149       {
150         (*i)->SetModifiedStatus();
151       }
152     
153     
154    }
155   */
156   /*
157   //======================================================================
158   void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
159   {
160     bbtkDebugMessage("change",2,
161                      "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
162                      <<this<<"]"
163                      <<std::endl);
164     if (mChangeTime.Set(t))
165       {
166         mChangeSignal(this);
167       }
168     bbtkDebugMessage("change",2,
169                      "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
170                      <<this<<"]"
171                      <<std::endl);
172   }
173   //======================================================================
174   */
175   /*
176  //======================================================================
177   void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
178   {
179     bbtkDebugMessage("change",2,
180                      "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
181                      <<this<<"]"
182                      <<std::endl);
183     mChangeTime.Set(ChangeTime::GetCurrentTime());
184     mChangeSignal(this);
185     
186     bbtkDebugMessage("change",2,
187                      "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
188                      <<this<<"]"
189                      <<std::endl);
190   }
191   //======================================================================
192   */
193
194
195   //======================================================================
196   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
197   { 
198     mChangeSignal.connect(f); 
199   }
200   //======================================================================
201   
202   //======================================================================
203   /// Removes the function f from the list of functions to call when 
204   /// the output changes (TO WRITE)
205   void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
206   { 
207     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
208     
209     //mChangeSignal.disconnect(f);
210   }
211   //======================================================================
212 }
213 // namespace bbtk
214