]> 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/10 09:33:18 $
6   Version:   $Revision: 1.11 $
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     //    std::cout<<"BlackBoxOutputConnector::SignalChange("
134     //       <<box->bbGetFullName()<<",'"
135     //       <<output<<"')"<<std::endl;
136     mChangeSignal(box,output,s);
137     
138     bbtkDebugMessage("change",2,
139                      "<== BlackBoxOutputConnector::SignalChange("
140                      <<box->bbGetFullName()<<",'"
141                      <<output<<"','"<<GetIOStatusString(s)<<"') ["
142                      <<this<<"]"
143                      <<std::endl);
144   }
145   //======================================================================
146  /*
147   void BlackBoxOutputConnector::SetModifiedStatus()
148   {
149     bbtkDebugMessage("modified",2,
150                      "==> BlackBoxOutputConnector::SetModifiedStatus() ["
151                      <<this<<"]"
152                      <<std::endl);
153     ConnectionVector::iterator i;
154     for (i=mConnection.begin();i!=mConnection.end();++i) 
155       {
156         (*i)->SetModifiedStatus();
157       }
158     
159     
160    }
161   */
162   /*
163   //======================================================================
164   void BlackBoxOutputConnector::SetChangeTime(const ChangeTime& t)
165   {
166     bbtkDebugMessage("change",2,
167                      "==> BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
168                      <<this<<"]"
169                      <<std::endl);
170     if (mChangeTime.Set(t))
171       {
172         mChangeSignal(this);
173       }
174     bbtkDebugMessage("change",2,
175                      "<== BlackBoxOutputConnector::SetChangeTime("<<t<<") ["
176                      <<this<<"]"
177                      <<std::endl);
178   }
179   //======================================================================
180   */
181   /*
182  //======================================================================
183   void BlackBoxOutputConnector::SetChangeTimeToCurrentTime()
184   {
185     bbtkDebugMessage("change",2,
186                      "==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
187                      <<this<<"]"
188                      <<std::endl);
189     mChangeTime.Set(ChangeTime::GetCurrentTime());
190     mChangeSignal(this);
191     
192     bbtkDebugMessage("change",2,
193                      "<==> BlackBoxOutputConnector::SetChangeTimetoCurrentTime() ["
194                      <<this<<"]"
195                      <<std::endl);
196   }
197   //======================================================================
198   */
199
200
201   //======================================================================
202   void BlackBoxOutputConnector::AddChangeObserver(OutputChangeCallbackType f)
203   { 
204     //    std::cout << "BlackBoxOutputConnector::AddChangeObserver" << std::endl;
205     mChangeSignal.connect(f); 
206   }
207   //======================================================================
208   
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)
213   { 
214     bbtkError("BlackBoxOutputConnector::RemoveChangeObserver not implemented");
215     
216     //mChangeSignal.disconnect(f);
217   }
218   //======================================================================
219 }
220 // namespace bbtk
221