Line data Source code
1 : /** \file staticNode.hpp
2 : * \brief The MagAO-X Instrument Graph staticNode header file
3 : *
4 : * \ingroup instGraph_files
5 : */
6 :
7 : #ifndef staticNode_hpp
8 : #define staticNode_hpp
9 :
10 : #include "xigNode.hpp"
11 :
12 : /// An instGraph node which is static, with status set at config time and not changing.
13 : class staticNode : public xigNode
14 : {
15 :
16 : protected:
17 : std::set<std::string> m_inputsOn; ///< inputs which are always on
18 : std::set<std::string> m_inputsOff; ///< inputs which are always off
19 :
20 : std::set<std::string> m_outputsOn; ///< outputs which are always on
21 : std::set<std::string> m_outputsOff; ///< outputs which are always off
22 :
23 : public:
24 : /// Only c'tor. Must be constructed with node name and a parent graph.
25 : staticNode( const std::string &name, /** [in] the name of this node*/
26 : ingr::instGraphXML *parentGraph /** [in] the graph which this node belongs to*/
27 : );
28 :
29 : /// Get the always on inputs
30 : /**
31 : * \returns the value of m_inputsOn
32 : */
33 : const std::set<std::string> &inputsOn() const;
34 :
35 : /// Get the always off inputs
36 : /**
37 : * \returns the value of m_inputsOff
38 : */
39 : const std::set<std::string> &inputsOff() const;
40 :
41 : /// Get the always on outputs
42 : /**
43 : * \returns the value of m_outputsOn
44 : */
45 : const std::set<std::string> &outputsOn() const;
46 :
47 : /// Get the always off outputs
48 : /**
49 : * \returns the value of m_outputsOff
50 : */
51 : const std::set<std::string> &outputsOff() const;
52 :
53 : public:
54 : /// INDI SetProperty callback
55 : virtual int handleSetProperty( const pcf::IndiProperty &ipRecv /**< [in] the received INDI property to handle*/ );
56 :
57 : /// Toggle all puts to their static state
58 : virtual void togglePutsAll();
59 :
60 : /// Toggle all puts on
61 : virtual void togglePutsOn();
62 :
63 : /// Toggle all puts off
64 : virtual void togglePutsOff();
65 :
66 : /// Configure this node form an appConfigurator.
67 : void loadConfig( mx::app::appConfigurator &config /**< [in] the loaded configuration */ );
68 : };
69 :
70 2 : staticNode::staticNode( const std::string &name, ingr::instGraphXML *parentGraph ) : xigNode( name, parentGraph )
71 : {
72 2 : }
73 :
74 3 : const std::set<std::string> &staticNode::inputsOn() const
75 : {
76 3 : return m_inputsOn;
77 : }
78 :
79 3 : const std::set<std::string> &staticNode::inputsOff() const
80 : {
81 3 : return m_inputsOff;
82 : }
83 :
84 3 : const std::set<std::string> &staticNode::outputsOn() const
85 : {
86 3 : return m_outputsOn;
87 : }
88 :
89 3 : const std::set<std::string> &staticNode::outputsOff() const
90 : {
91 3 : return m_outputsOff;
92 : }
93 :
94 0 : inline int staticNode::handleSetProperty( const pcf::IndiProperty &ipRecv )
95 : {
96 : static_cast<void>( ipRecv );
97 :
98 0 : return 0;
99 : }
100 :
101 2 : inline void staticNode::togglePutsAll()
102 : {
103 : try
104 : {
105 4 : for( auto &iput : m_inputsOn )
106 : {
107 2 : m_node->input( iput )->state( ingr::putState::on );
108 : }
109 : }
110 0 : catch( const std::exception &e )
111 : {
112 0 : std::string msg = XIGN_EXCEPTION( "staticNode::togglePutsAll", "exception changing state on inputs" );
113 0 : msg += "\n ";
114 0 : msg += e.what();
115 0 : throw std::runtime_error( msg );
116 0 : }
117 :
118 : try
119 : {
120 4 : for( auto &iput : m_inputsOff )
121 : {
122 2 : m_node->input( iput )->state( ingr::putState::off );
123 : }
124 : }
125 0 : catch( const std::exception &e )
126 : {
127 0 : std::string msg = XIGN_EXCEPTION( "staticNode::togglePutsAll", "parent graph is null" );
128 0 : msg += "\n ";
129 0 : msg += e.what();
130 0 : throw std::runtime_error( msg );
131 0 : }
132 :
133 : try
134 : {
135 4 : for( auto &iput : m_outputsOn )
136 : {
137 2 : m_node->output( iput )->state( ingr::putState::on );
138 : }
139 : }
140 0 : catch( const std::exception &e )
141 : {
142 0 : std::string msg = XIGN_EXCEPTION( "staticNode::togglePutsAll", "parent graph is null" );
143 0 : msg += "\n ";
144 0 : msg += e.what();
145 0 : throw std::runtime_error( msg );
146 0 : }
147 :
148 : try
149 : {
150 4 : for( auto &iput : m_outputsOff )
151 : {
152 2 : m_node->output( iput )->state( ingr::putState::off );
153 : }
154 : }
155 0 : catch( const std::exception &e )
156 : {
157 0 : std::string msg = XIGN_EXCEPTION( "staticNode::togglePutsAll", "parent graph is null" );
158 0 : msg += "\n ";
159 0 : msg += e.what();
160 0 : throw std::runtime_error( msg );
161 0 : }
162 2 : }
163 :
164 0 : inline void staticNode::togglePutsOn()
165 : {
166 0 : togglePutsAll();
167 0 : }
168 :
169 0 : inline void staticNode::togglePutsOff()
170 : {
171 0 : togglePutsAll();
172 0 : }
173 :
174 2 : inline void staticNode::loadConfig( mx::app::appConfigurator &config )
175 : {
176 2 : if( !m_parentGraph )
177 : {
178 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "parent graph is null" );
179 0 : throw std::runtime_error( msg );
180 0 : }
181 :
182 2 : std::string type;
183 2 : config.configUnused( type, mx::app::iniFile::makeKey( name(), "type" ) );
184 :
185 2 : if( type != "static" )
186 : {
187 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "node type is not static" );
188 0 : throw std::runtime_error( msg );
189 0 : }
190 :
191 2 : std::vector<std::string> inputsOn;
192 2 : config.configUnused( inputsOn, mx::app::iniFile::makeKey( name(), "inputsOn" ) );
193 :
194 : try
195 : {
196 2 : m_inputsOn.clear();
197 4 : for( auto &in : inputsOn )
198 : {
199 2 : m_inputsOn.insert( in );
200 : }
201 : }
202 0 : catch(const std::exception & e)
203 : {
204 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "exception caught loading inputsOn" );
205 0 : msg += "\n ";
206 0 : msg += e.what();
207 0 : }
208 :
209 2 : std::vector<std::string> inputsOff;
210 2 : config.configUnused( inputsOff, mx::app::iniFile::makeKey( name(), "inputsOff" ) );
211 :
212 : try
213 : {
214 2 : m_inputsOff.clear();
215 4 : for( auto &in : inputsOff )
216 : {
217 2 : m_inputsOff.insert( in );
218 : }
219 : }
220 0 : catch(const std::exception & e)
221 : {
222 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "exception caught loading inputsOff" );
223 0 : msg += "\n ";
224 0 : msg += e.what();
225 0 : }
226 :
227 2 : std::vector<std::string> outputsOn;
228 2 : config.configUnused( outputsOn, mx::app::iniFile::makeKey( name(), "outputsOn" ) );
229 : try
230 : {
231 2 : m_outputsOn.clear();
232 4 : for( auto &out : outputsOn )
233 : {
234 2 : m_outputsOn.insert( out );
235 : }
236 : }
237 0 : catch(const std::exception & e)
238 : {
239 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "exception caught loading outputsOn" );
240 0 : msg += "\n ";
241 0 : msg += e.what();
242 0 : }
243 :
244 2 : std::vector<std::string> outputsOff;
245 2 : config.configUnused( outputsOff, mx::app::iniFile::makeKey( name(), "outputsOff" ) );
246 : try
247 : {
248 2 : m_outputsOff.clear();
249 4 : for( auto &out : outputsOff )
250 : {
251 2 : m_outputsOff.insert( out );
252 : }
253 : }
254 0 : catch(const std::exception & e)
255 : {
256 0 : std::string msg = XIGN_EXCEPTION( "staticNode::loadConfig", "exception caught loading outputsOff" );
257 0 : msg += "\n ";
258 0 : msg += e.what();
259 0 : }
260 :
261 2 : togglePutsAll();
262 2 : }
263 :
264 : #endif // staticNode_hpp
|