LCOV - code coverage report
Current view: top level - apps/xInstGraph/xigNodes - xigNode.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 86.8 % 38 33
Test Date: 2026-01-03 21:03:39 Functions: 100.0 % 9 9

            Line data    Source code
       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              : 
      14           24 : std::string xign_exception( const std::string &src, const std::string &expl, const std::string &file, int line )
      15              : {
      16           24 :     std::string msg = src + ": " + expl;
      17           24 :     msg += " at ";
      18           24 :     msg += file;
      19           24 :     msg += " " + std::to_string( line );
      20              : 
      21           24 :     return msg;
      22            0 : }
      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              :  */
      30              : class xigNode
      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            1 :     void setParentGraphNull()
      88              :     {
      89            1 :         m_parentGraph = nullptr;
      90            1 :     }
      91              : #endif
      92              : };
      93              : 
      94           45 : inline xigNode::xigNode( const std::string &name, ingr::instGraphXML *parentGraph ) : m_parentGraph( parentGraph )
      95              : {
      96           45 :     if( m_parentGraph == nullptr )
      97              :     {
      98           15 :         std::string msg = XIGN_EXCEPTION( "xigNode::loadConfig", "parent graph is null" );
      99            3 :         throw std::runtime_error( msg );
     100            3 :     }
     101              : 
     102              :     // This will throw if name is not in the parent's nodes
     103           42 :     m_node = m_parentGraph->node( name );
     104           45 : }
     105              : 
     106          362 : inline std::string xigNode::name()
     107              : {
     108          362 :     return m_node->name();
     109              : }
     110              : 
     111           17 : inline const std::set<std::string> &xigNode::keys()
     112              : {
     113           17 :     return m_keys;
     114              : }
     115              : 
     116           41 : inline void xigNode::key( const std::string &nkey )
     117              : {
     118           41 :     m_keys.insert( nkey );
     119           41 : }
     120              : 
     121           35 : inline ingr::instNode *xigNode::node()
     122              : {
     123           35 :     return m_node; // b/c of constructor, this can't be null
     124              : }
     125              : 
     126            9 : inline void xigNode::togglePutsOn()
     127              : {
     128            9 :     for( auto &&iput : m_node->inputs() )
     129              :     {
     130              :         //iput.second->enabled(true);
     131            0 :         iput.second->state( ingr::putState::on );
     132              :     }
     133              : 
     134            9 :     for( auto &&oput : m_node->outputs() )
     135              :     {
     136              :         //oput.second->enabled(true);
     137            0 :         oput.second->state( ingr::putState::on );
     138              :     }
     139            9 : }
     140              : 
     141            3 : inline void xigNode::togglePutsOff()
     142              : {
     143            3 :     for( auto &&iput : m_node->inputs() )
     144              :     {
     145              :         //iput.second->enabled(false);
     146            0 :         iput.second->state( ingr::putState::off );
     147              :     }
     148              : 
     149            3 :     for( auto &&oput : m_node->outputs() )
     150              :     {
     151              :         //oput.second->enabled(false);
     152            0 :         oput.second->state( ingr::putState::off );
     153              :     }
     154            3 : }
     155              : 
     156              : #endif // xigNode_hpp
        

Generated by: LCOV version 2.0-1