]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxOutputConnector.cxx
*** empty log message ***
[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 14:02:15 $
6   Version:   $Revision: 1.10 $
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           IOStatus s = OUTOFDATE; //mStatus;
124           //if (s==UPTODATE) s=MODIFIED;
125           
126           bbtkDebugMessage("change",2,
127                      "==> BlackBoxOutputConnector::SignalChange("
128                      <<box->bbGetFullName()<<",'"
129                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
130                      <<this<<"]"
131                      <<std::endl);
132
133    mChangeSignal(box,output,s);
134
135     bbtkDebugMessage("change",2,
136                      "<== BlackBoxOutputConnector::SignalChange("
137                      <<box->bbGetFullName()<<",'"
138                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
139                      <<this<<"]"
140                      <<std::endl);
141   }
142   //======================================================================
143  /*
144   void BlackBoxOutputConnector::SetModifiedStatus()
145   {
146     bbtkDebugMessage("modified",2,
147                      "==> BlackBoxOutputConnector::SetModifiedStatus() ["
148                      <<this<<"]"
149                      <<std::endl);
150     ConnectionVector::iterator i;
151     for (i=mConnection.begin();i!=mConnection.end();++i) 
152       {
153         (*i)->SetModifiedStatus();
154       }
155     
156     
157    }
158   */
159   /*
160   //======================================================================
161   void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
162   {
163     bbtkDebugMessage("change",2,
164                      "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
165                      <<this<<"]"
166                      <<std::endl);
167     if (mChangeTime.Set(t))
168       {
169         mChangeSignal(this);
170       }
171     bbtkDebugMessage("change",2,
172                      "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
173                      <<this<<"]"
174                      <<std::endl);
175   }
176   //======================================================================
177   */
178   /*
179  //======================================================================
180   void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
181   {
182     bbtkDebugMessage("change",2,
183                      "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
184                      <<this<<"]"
185                      <<std::endl);
186     mChangeTime.Set(ChangeTime::GetCurrentTime());
187     mChangeSignal(this);
188     
189     bbtkDebugMessage("change",2,
190                      "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
191                      <<this<<"]"
192                      <<std::endl);
193   }
194   //======================================================================
195   */
196
197
198   //======================================================================
199   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
200   { 
201     mChangeSignal.connect(f); 
202   }
203   //======================================================================
204   
205   //======================================================================
206   /// Removes the function f from the list of functions to call when 
207   /// the output changes (TO WRITE)
208   void BlackBoxOutputConnector::RemoveChangeObserver(OutputChangeCallbackType f)
209   { 
210     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
211     
212     //mChangeSignal.disconnect(f);
213   }
214   //======================================================================
215 }
216 // namespace bbtk
217