API
 
Loading...
Searching...
No Matches
xigNode.hpp
Go to the documentation of this file.
1/** \file xigNode.hpp
2 * \brief The base MagAO-X instGraph node header file
3 *
4 * \ingroup instGraph_files
5 */
6
7#ifndef xigNode_hpp
8#define xigNode_hpp
9
10#include <instGraph/instGraphXML.hpp>
11
12#include "../../INDI/libcommon/IndiProperty.hpp"
13
14std::string xign_exception( const std::string &src, const std::string &expl, const std::string &file, int line )
15{
16 std::string msg = src + ": " + expl;
17 msg += " at ";
18 msg += file;
19 msg += " " + std::to_string( line );
20
21 return msg;
22}
23
24#define XIGN_EXCEPTION( src, expl ) xign_exception( src, expl, __FILE__, __LINE__ )
25
26/// Implementation of basic instGraph node interface for MagAO-X
27/** This class is pure virtual, derived classes must implement handleSetProperty.
28 *
29 */
31{
32 protected:
33 std::set<std::string> m_keys; ///< The INDI keys (device.property) which this node subscribes to
34
35 ingr::instGraphXML *m_parentGraph{ nullptr }; ///< The parent instGraph that this node is a part of
36
37 ingr::instNode *m_node{ nullptr }; ///< The underlying instGraph node
38
39 int m_changes{ 0 }; ///< Counter that can be incremented when changes are detected. Set to 0 when graph is updated.
40
41 public:
42 xigNode() = delete; // default c'tor is deleted
43
44 /// Constructor.
45 /**
46 * Default c'tor is deleted. Must supply both node name and a parentGraph with a node with the same name in it.
47 */
48 xigNode( const std::string &name, /**< [in] the name of the node */
49 ingr::instGraphXML *parentGraph /**< [in] the parent instGraph */ );
50
51 /// Get the name of this node
52 /**
53 * \returns the nodes' name (the value of m_name).
54 */
55 std::string name();
56
57 /// Get the set holding the INDI keys for this node
58 /**
59 * \returns a const reference to m_keys
60 */
61 const std::set<std::string> &keys();
62
63 /// Add a key to the set
64 void key( const std::string &nkey );
65
66 /// Get the pointer to the underlying node.
67 /**
68 * \returns the node pointer, which can not be nullptr after construction
69 */
70 ingr::instNode *node();
71
72 /// INDI SetProperty callback
73 /**
74 * This is a pure virtual function in xigNode.
75 */
76 virtual int
77 handleSetProperty( const pcf::IndiProperty &ipRecv /**< [in] the received INDI property to handle*/ ) = 0;
78
79 /// Change the state of all inputs and all outputs to on.
80 virtual void togglePutsOn();
81
82 /// Change the state of all inputs and all outputs to off.
83 virtual void togglePutsOff();
84
85#ifdef XWC_XIGNODE_TEST
86 // allow setting m_parentGraph to null for testing
87 void setParentGraphNull()
88 {
89 m_parentGraph = nullptr;
90 }
91#endif
92};
93
94inline xigNode::xigNode( const std::string &name, ingr::instGraphXML *parentGraph ) : m_parentGraph( parentGraph )
95{
96 if( m_parentGraph == nullptr )
97 {
98 std::string msg = XIGN_EXCEPTION( "xigNode::loadConfig", "parent graph is null" );
99 throw std::runtime_error( msg );
100 }
101
102 // This will throw if name is not in the parent's nodes
103 m_node = m_parentGraph->node( name );
104}
105
106inline std::string xigNode::name()
107{
108 return m_node->name();
109}
110
111inline const std::set<std::string> &xigNode::keys()
112{
113 return m_keys;
114}
115
116inline void xigNode::key( const std::string &nkey )
117{
118 m_keys.insert( nkey );
119}
120
121inline ingr::instNode *xigNode::node()
122{
123 return m_node; // b/c of constructor, this can't be null
124}
125
127{
128 for( auto &&iput : m_node->inputs() )
129 {
130 //iput.second->enabled(true);
131 iput.second->state( ingr::putState::on );
132 }
133
134 for( auto &&oput : m_node->outputs() )
135 {
136 //oput.second->enabled(true);
137 oput.second->state( ingr::putState::on );
138 }
139}
140
142{
143 for( auto &&iput : m_node->inputs() )
144 {
145 //iput.second->enabled(false);
146 iput.second->state( ingr::putState::off );
147 }
148
149 for( auto &&oput : m_node->outputs() )
150 {
151 //oput.second->enabled(false);
152 oput.second->state( ingr::putState::off );
153 }
154}
155
156#endif // xigNode_hpp
Implementation of basic instGraph node interface for MagAO-X.
Definition xigNode.hpp:31
virtual int handleSetProperty(const pcf::IndiProperty &ipRecv)=0
INDI SetProperty callback.
xigNode()=delete
void key(const std::string &nkey)
Add a key to the set.
Definition xigNode.hpp:116
ingr::instNode * m_node
The underlying instGraph node.
Definition xigNode.hpp:37
virtual void togglePutsOn()
Change the state of all inputs and all outputs to on.
Definition xigNode.hpp:126
int m_changes
Counter that can be incremented when changes are detected. Set to 0 when graph is updated.
Definition xigNode.hpp:39
std::set< std::string > m_keys
The INDI keys (device.property) which this node subscribes to.
Definition xigNode.hpp:33
ingr::instGraphXML * m_parentGraph
The parent instGraph that this node is a part of.
Definition xigNode.hpp:35
ingr::instNode * node()
Get the pointer to the underlying node.
Definition xigNode.hpp:121
std::string name()
Get the name of this node.
Definition xigNode.hpp:106
virtual void togglePutsOff()
Change the state of all inputs and all outputs to off.
Definition xigNode.hpp:141
const std::set< std::string > & keys()
Get the set holding the INDI keys for this node.
Definition xigNode.hpp:111
#define XIGN_EXCEPTION(src, expl)
Definition xigNode.hpp:24
std::string xign_exception(const std::string &src, const std::string &expl, const std::string &file, int line)
Definition xigNode.hpp:14