]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxInputConnector.cxx
Feature #1774
[bbtk.git] / kernel / src / bbtkBlackBoxInputConnector.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbtkBlackBoxInputConnector.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:49:01 $
33   Version:   $Revision: 1.12 $
34 =========================================================================*/
35
36
37 /**
38  *  \file 
39  *  \brief Class bbtk::BlackBoxInputConnector : 
40  */
41 #include "bbtkBlackBoxInputConnector.h"
42 #include "bbtkMessageManager.h"
43 #include "bbtkBlackBox.h"
44
45 namespace bbtk
46 {
47
48   //========================================================================
49   /// The Pimpl
50   class BlackBoxInputConnector::Pimpl
51   {
52   public:
53     Pimpl() : mConnection(0), mStatus(MODIFIED) {}
54       
55     /// 
56     BlackBoxWeakPointer mBox;
57     /// The connection plugged into the input
58     Connection* mConnection;
59     /// The status of the input (UPTODATE | MODIFIED | OUTOFDATE)
60     IOStatus mStatus;
61
62   };
63   //========================================================================
64
65   //========================================================================
66   BBTK_IMPL_PIMPL(BlackBoxInputConnector)
67   //========================================================================
68
69
70   //========================================================================
71   BlackBoxInputConnector::BlackBoxInputConnector(BlackBox::Pointer b)  
72   //: mBox(b), mConnection(0), mStatus(MODIFIED)
73   {
74     bbtkDebugMessage("kernel",9,
75                      "["<<b->bbGetName()
76                      <<"] BlackBoxInputConnector()"<<std::endl);
77     PimplConstruct();
78     p->mBox = b;
79   }
80   //========================================================================
81
82   //========================================================================
83   BlackBoxInputConnector::~BlackBoxInputConnector() 
84   {
85     bbtkDebugMessage("kernel",9,
86                      "[DEAD BOX] ~BlackBoxInputConnector()"
87                      <<std::endl);
88     PimplDestruct();
89   }
90   //========================================================================
91
92   //========================================================================
93   /// Returns the connection plugged into this input (const)
94   Connection* BlackBoxInputConnector::GetConnection() const 
95   { 
96     return p->mConnection; 
97   }
98   //========================================================================
99   
100
101   //========================================================================
102   /// Returns true iff a connection is connected to it
103     bool BlackBoxInputConnector::IsConnected() const 
104   { 
105     return (p->mConnection != 0); 
106   }
107    //========================================================================
108    
109
110    //========================================================================
111    /// Returns the status of the input 
112     IOStatus BlackBoxInputConnector::GetStatus() const 
113    { 
114      return p->mStatus; 
115    }
116   //========================================================================
117
118   //========================================================================
119     /// Sets the status of the input 
120     void BlackBoxInputConnector::SetStatus(IOStatus s) 
121     { 
122       p->mStatus = s; 
123     }
124    //========================================================================
125    
126     
127
128   //========================================================================
129     /// Returns the black box which owns the connector
130     BlackBoxPointer BlackBoxInputConnector::GetBlackBox() const 
131     { 
132       return p->mBox.lock(); 
133     } 
134
135   //========================================================================
136
137   //========================================================================
138   void BlackBoxInputConnector::SetConnection(Connection* c) 
139   { 
140     bbtkDebugMessage("kernel",9,
141                      "["<<p->mBox.lock()->bbGetName()
142                      <<"] BlackBoxInputConnector::SetConnection("<<c<<")"<<std::endl);
143     p->mConnection = c; 
144   }
145   //========================================================================
146
147   //========================================================================
148   void BlackBoxInputConnector::UnsetConnection(Connection* c) 
149   { 
150     bbtkDebugMessage("kernel",9,
151                      "["<<p->mBox.lock()->bbGetName()
152                      <<"] BlackBoxInputConnector::UnsetConnection("
153                      <<c<<")"<<std::endl);
154     p->mConnection = 0; 
155   }
156   //========================================================================
157   
158   //========================================================================
159   void BlackBoxInputConnector::RecursiveExecute()
160   {
161     // If connected and OUTOFDATE : recursive update
162     // Post-update status is updated by the connection 
163     // (either MODIFIED or OUTOFDATE)
164     if ( p->mConnection && (p->mStatus == OUTOFDATE) )
165       {
166         p->mConnection->RecursiveExecute();
167       }
168     else
169       {
170         if (!p->mBox.expired())
171           bbtkDebugMessage("process",5,"["<<p->mBox.lock()->bbGetName()
172                            <<"] --> BlackBoxInputConnector::RecursiveExecute() : "
173                            <<"No connection or input not Out-of-date : nothing to do"
174                            <<std::endl);
175         else
176           bbtkDebugMessage("process",5,
177                            "[DEAD BOX] --> BlackBoxInputConnector::RecursiveExecute() : "
178                            <<"No connection or input not Out-of-date : nothing to do"
179                            <<std::endl);
180           
181       }
182   }
183   //========================================================================
184
185 }
186 // namespace bbtk
187