Files
Upsilon/ion/src/device/bench/command_handler.cpp
Romain Goyet 9e3c052830 [ion] Move the bench test in ion
Change-Id: I54b99678df969e6e3e86c2d3858d04088a40f047
2017-03-16 14:20:46 +01:00

45 lines
819 B
C++

#include "command_handler.h"
#include <string.h>
namespace Ion {
namespace Device {
namespace Bench {
bool CommandHandler::valid() const {
return (m_name != nullptr && m_function != nullptr);
}
bool CommandHandler::handle(const char * command) const {
if (matches(command)) {
size_t nameLength = strlen(m_name);
if (command[nameLength] == '=') {
m_function(command+nameLength+1); // Skip the "Equal character"
} else {
m_function(nullptr);
}
return true;
}
return false;
}
bool CommandHandler::matches(const char * command) const {
const char * c = command;
const char * n = m_name;
while (true) {
if (*n == NULL) {
if (*c == NULL || *c == '=') {
return true;
}
}
if (*c != *n) {
return false;
}
c++;
n++;
}
}
}
}
}