Added some getters to the Node<> class

This commit is contained in:
Pavel Kirienko 2015-09-25 01:45:40 +03:00
parent 335cd6622a
commit 14cdbc0594
3 changed files with 15 additions and 9 deletions

View File

@ -150,10 +150,11 @@ public:
int start(const TransferPriority node_status_transfer_priority = TransferPriority::Default);
/**
* Sets the node name, e.g. "com.example.product_name". The node name can be set only once.
* Must be executed before the node is started, otherwise the node will refuse to start up.
* Gets/sets the node name, e.g. "com.example.product_name". The node name can be set only once.
* The name must be set before the node is started, otherwise the node will refuse to start up.
*/
void setName(const char* name) { proto_nsp_.setName(name); }
const NodeStatusProvider::NodeName& getName() const { return proto_nsp_.getName(); }
void setName(const NodeStatusProvider::NodeName& name) { proto_nsp_.setName(name); }
/**
* Node health code helpers.
@ -187,11 +188,14 @@ public:
}
/**
* Sets the node version information.
* Gets/sets the node version information.
*/
void setSoftwareVersion(const protocol::SoftwareVersion& version) { proto_nsp_.setSoftwareVersion(version); }
void setHardwareVersion(const protocol::HardwareVersion& version) { proto_nsp_.setHardwareVersion(version); }
const protocol::SoftwareVersion& getSoftwareVersion() const { return proto_nsp_.getSoftwareVersion(); }
const protocol::HardwareVersion& getHardwareVersion() const { return proto_nsp_.getHardwareVersion(); }
NodeStatusProvider& getNodeStatusProvider() { return proto_nsp_; }
#if !UAVCAN_TINY

View File

@ -51,6 +51,8 @@ public:
typedef typename StorageType<typename protocol::NodeStatus::FieldTypes::vendor_specific_status_code>::Type
VendorSpecificStatusCode;
typedef typename StorageType<typename protocol::GetNodeInfo::Response::FieldTypes::name>::Type NodeName;
explicit NodeStatusProvider(INode& node)
: TimerBase(node)
, creation_timestamp_(node.getMonotonicTime())
@ -119,8 +121,8 @@ public:
* Can be set only once before the provider is started.
* The provider will refuse to start if the node name is not set.
*/
const typename protocol::GetNodeInfo::Response::FieldTypes::name& getName() const { return node_info_.name; }
void setName(const char* name);
const NodeName& getName() const { return node_info_.name; }
void setName(const NodeName& name);
/**
* Node version information.

View File

@ -124,11 +124,11 @@ void NodeStatusProvider::setVendorSpecificStatusCode(VendorSpecificStatusCode co
node_info_.status.vendor_specific_status_code = code;
}
void NodeStatusProvider::setName(const char* name)
void NodeStatusProvider::setName(const NodeName& name)
{
if ((name != NULL) && (*name != '\0') && (node_info_.name.empty()))
if (node_info_.name.empty())
{
node_info_.name = name; // The string contents will be copied, not just pointer.
node_info_.name = name;
}
}