Convenience method IParamManager::isParamValueEmpty()

This commit is contained in:
Pavel Kirienko
2015-03-23 18:34:19 +03:00
parent 6598b15d88
commit 0affb0eaec
2 changed files with 13 additions and 12 deletions
@@ -64,6 +64,17 @@ public:
* @return Negative if failed.
*/
virtual int eraseAllParams() = 0;
/**
* Convenience method that can be used to check if a param value is empty.
*/
static bool isParamValueEmpty(const ParamValue& val)
{
return val.value_bool.empty() &&
val.value_int.empty() &&
val.value_float.empty() &&
val.value_string.empty();
}
};
/**
@@ -83,8 +94,6 @@ class UAVCAN_EXPORT ParamServer
ServiceServer<protocol::param::ExecuteOpcode, ExecuteOpcodeCallback> save_erase_srv_;
IParamManager* manager_;
static bool isValueNonEmpty(const protocol::param::Value& value);
void handleGetSet(const protocol::param::GetSet::Request& request, protocol::param::GetSet::Response& response);
void handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& request,
+2 -10
View File
@@ -10,14 +10,6 @@
namespace uavcan
{
bool ParamServer::isValueNonEmpty(const protocol::param::Value& value)
{
return !value.value_bool.empty() ||
!value.value_int.empty() ||
!value.value_float.empty() ||
!value.value_string.empty();
}
void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, protocol::param::GetSet::Response& out)
{
UAVCAN_ASSERT(manager_ != NULL);
@@ -40,14 +32,14 @@ void ParamServer::handleGetSet(const protocol::param::GetSet::Request& in, proto
}
// Assign if needed, read back
if (isValueNonEmpty(in.value))
if (!IParamManager::isParamValueEmpty(in.value))
{
manager_->assignParamValue(out.name, in.value);
}
manager_->readParamValue(out.name, out.value);
// Check if the value is OK, otherwise reset the name to indicate that we have no idea what is it all about
if (isValueNonEmpty(out.value))
if (!IParamManager::isParamValueEmpty(out.value))
{
manager_->readParamDefaultMaxMin(out.name, out.default_value, out.max_value, out.min_value);
}