libcyberradio  22.01.24
RadioComponent.cpp
1 /***************************************************************************
2  * \file RadioComponent.cpp
3  * \brief Defines the basic component interface for an NDR-class radio.
4  * \author DA
5  * \author NH
6  * \author MN
7  * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
8  *
9  ***************************************************************************/
10 
11 #include "LibCyberRadio/Driver/RadioHandler.h"
12 #include "LibCyberRadio/Driver/RadioComponent.h"
13 
14 
15 namespace LibCyberRadio
16 {
17  namespace Driver
18  {
19 
20  RadioComponent::RadioComponent(const std::string& name,
21  int index,
22  RadioHandler* parent,
23  bool debug) :
24  Configurable(name, debug),
25  _index(index),
26  _parent(parent),
27  _enabled(false)
28  {
30  }
31 
33  {
34  }
35 
37  Configurable(other),
38  _index(other._index),
39  _parent(other._parent),
40  _enabled(other._enabled)
41  {
42  }
43 
45  {
47  if ( this != &other )
48  {
49  _index = other._index;
50  _parent = other._parent;
51  _enabled = other._enabled;
52  }
53  return *this;
54  }
55 
57  {
58  return _index;
59  }
60 
61  void RadioComponent::setIndex(int index)
62  {
63  _index = index;
64  }
65 
67  {
68  return _parent;
69  }
70 
72  {
73  _parent = parent;
74  }
75 
77  {
78  return enable(false);
79  }
80 
81  bool RadioComponent::enable(bool enabled)
82  {
83  _enabled = enabled;
85  return true;
86  }
87 
89  {
90  return _enabled;
91  }
92 
94  {
95  //this->debug("[RadioComponent::setConfiguration] Called\n");
96  // Call the base-class version to modify the configuration dictionary
97  bool ret = Configurable::setConfiguration(cfg);
98  // Use the keys provided in the *incoming* dictionary to determine
99  // what needs to be changed.
100  if ( cfg.hasKey("enable") && _config.hasKey("enable") )
101  {
102  ret = enable( _config["enable"].asBool() );
103  }
104  //this->debug("[RadioComponent::setConfiguration] Returning\n");
105  return ret;
106  }
107 
109  {
110  //this->debug("[RadioComponent::queryConfiguration] Called\n");
111  // Replace this with hardware queries to determine values
112  //this->debug("[RadioComponent::queryConfiguration] Returning\n");
113  }
114 
116  {
117  //this->debug("[RadioComponent::initConfigurationDict] Called\n");
118  _config["enable"] = _enabled;
119  //this->debug("[RadioComponent::initConfigurationDict] Returning\n");
120  }
121 
123  {
124  //this->debug("[RadioComponent::updateConfigurationDict] Called\n");
125  if ( _config.hasKey("enable") )
126  this->setConfigurationValueToBool("enable", _enabled);
127  //this->debug("[RadioComponent::updateConfigurationDict] Returning\n");
128  }
129 
130  } // namespace Driver
131 
132 } // namespace LibCyberRadio
133 
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
RadioComponent(const std::string &name="<unknown>", int index=0, RadioHandler *parent=NULL, bool debug=false)
Constructs a RadioComponent object.
Base hardware component class.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual bool setConfigurationValueToBool(const std::string &key, const bool value)
Sets a named configuration value to a Boolean.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
virtual bool isEnabled() const
Gets whether or not the component is enabled.
virtual void setIndex(int index)
Sets the index number of the component.
virtual bool enable(bool enabled=true)
Enables this component.
Generic radio handler class.
Definition: RadioHandler.h:54
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
A configuration dictionary.
Definition: Configurable.h:51
virtual bool disable()
Disables this component.
virtual RadioHandler * getParent() const
Gets the "parent" radio handler for this component.
virtual int getIndex() const
Gets the index number of the component.
virtual Configurable & operator=(const Configurable &other)
Assignment operator for Configurable objects.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
Base configurable object class.
Definition: Configurable.h:79
virtual void setParent(RadioHandler *parent)
Sets the "parent" radio handler for this component.
virtual ~RadioComponent()
Destroys a RadioComponent object.