mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[utils] adding 'LookupTable' class and use it in CLI (#5602)
This commit adds `LookupTable` module which provides helper methods to perform binary search in a generic sorted lookup table for specific entry matching a given name string. It also provides `constexpr` methods to check (at build-time) whether a lookup table array is sorted. This commit also updates CLI modules to use the `LookupTable` methods for command lookup. It also adds a unit test for the lookup table.
This commit is contained in:
committed by
GitHub
parent
946141ed32
commit
4db030c6c9
+8
-34
@@ -44,31 +44,8 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
const Dataset::Command Dataset::sCommands[] = {
|
||||
{"help", &Dataset::ProcessHelp},
|
||||
{"active", &Dataset::ProcessActive},
|
||||
{"activetimestamp", &Dataset::ProcessActiveTimestamp},
|
||||
{"channel", &Dataset::ProcessChannel},
|
||||
{"channelmask", &Dataset::ProcessChannelMask},
|
||||
{"clear", &Dataset::ProcessClear},
|
||||
{"commit", &Dataset::ProcessCommit},
|
||||
{"delay", &Dataset::ProcessDelay},
|
||||
{"extpanid", &Dataset::ProcessExtPanId},
|
||||
{"init", &Dataset::ProcessInit},
|
||||
{"masterkey", &Dataset::ProcessMasterKey},
|
||||
{"meshlocalprefix", &Dataset::ProcessMeshLocalPrefix},
|
||||
{"mgmtgetcommand", &Dataset::ProcessMgmtGetCommand},
|
||||
{"mgmtsetcommand", &Dataset::ProcessMgmtSetCommand},
|
||||
{"networkname", &Dataset::ProcessNetworkName},
|
||||
{"panid", &Dataset::ProcessPanId},
|
||||
{"pending", &Dataset::ProcessPending},
|
||||
{"pendingtimestamp", &Dataset::ProcessPendingTimestamp},
|
||||
{"pskc", &Dataset::ProcessPskc},
|
||||
{"securitypolicy", &Dataset::ProcessSecurityPolicy},
|
||||
{"set", &Dataset::ProcessSet},
|
||||
};
|
||||
|
||||
otOperationalDataset Dataset::sDataset;
|
||||
constexpr Dataset::Command Dataset::sCommands[];
|
||||
otOperationalDataset Dataset::sDataset;
|
||||
|
||||
otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
{
|
||||
@@ -175,21 +152,18 @@ otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
|
||||
otError Dataset::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
{
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*command.mCommand)(aArgsLength - 1, aArgs + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
command = Utils::LookupTable::Find(aArgs[0], sCommands);
|
||||
VerifyOrExit(command != nullptr, OT_NOOP);
|
||||
|
||||
error = (this->*command->mHandler)(aArgsLength - 1, aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user