mirror of
https://github.com/espressif/openthread.git
synced 2026-08-22 18:39:50 +00:00
[cli] use template Process<Cmd("command")> to simplify handlers (#7412)
This commit updates how the CLI command handlers are defined. A
template `Process<CommandId>()` method is now used to process a CLI
command where the `CommandId` is a `uint64` hash ID derived from
the command string itself.
This model helps simplify the CLI modules. With this change, there is
no need to declare different process methods for every CLI command in
the header files. It also makes the association between a CLI command
and its command string explicit and simple (e.g., `"state"` command
with `Process<Cmd("state")>` method).
This commit is contained in:
+389
-194
File diff suppressed because it is too large
Load Diff
+7
-402
@@ -316,34 +316,15 @@ private:
|
||||
static otError ParseRoute(Arg aArgs[], otExternalRouteConfig &aConfig);
|
||||
#endif
|
||||
|
||||
// Process methods on FTD/MTD/RCP
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
otError ProcessDiag(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessHistory(Arg aArgs[]);
|
||||
otError ProcessReset(Arg aArgs[]);
|
||||
otError ProcessCommand(Arg aArgs[]);
|
||||
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
otError ProcessUserCommands(Arg aArgs[]);
|
||||
otError ProcessVersion(Arg aArgs[]);
|
||||
|
||||
// Process methods only on FTD/MTD
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
otError ProcessCcaThreshold(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessCcm(Arg aArgs[]);
|
||||
otError ProcessThreadVersionCheck(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessBufferInfo(Arg aArgs[]);
|
||||
otError ProcessChannel(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
otError ProcessBorderAgent(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
otError ProcessBorderRouting(Arg aArgs[]);
|
||||
#endif
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
otError ProcessBackboneRouter(Arg aArgs[]);
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
otError ProcessBackboneRouterLocal(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
|
||||
@@ -351,86 +332,18 @@ private:
|
||||
void PrintMulticastListenersTable(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
otError ProcessDomainName(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
otError ProcessDua(Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessChild(Arg aArgs[]);
|
||||
otError ProcessChildIp(Arg aArgs[]);
|
||||
otError ProcessChildMax(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE
|
||||
otError ProcessChildSupervision(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessChildTimeout(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
|
||||
otError ProcessCoap(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
|
||||
otError ProcessCoapSecure(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
otError ProcessCoexMetrics(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessCommissioner(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessContextIdReuseDelay(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessCounters(Arg aArgs[]);
|
||||
otError ProcessCsl(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessDelayTimerMin(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessDiscover(Arg aArgs[]);
|
||||
otError ProcessDns(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
void OutputEidCacheEntry(const otCacheEntryInfo &aEntry);
|
||||
otError ProcessEidCache(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessEui64(Arg aArgs[]);
|
||||
otError ProcessLog(Arg aArgs[]);
|
||||
otError ProcessExtAddress(Arg aArgs[]);
|
||||
otError ProcessExtPanId(Arg aArgs[]);
|
||||
otError ProcessFactoryReset(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessFake(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessFem(Arg aArgs[]);
|
||||
otError ProcessIfconfig(Arg aArgs[]);
|
||||
otError ProcessIpAddr(Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddr(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
otError ProcessJoiner(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessJoinerPort(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessKeySequence(Arg aArgs[]);
|
||||
otError ProcessLeaderData(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPartitionId(Arg aArgs[]);
|
||||
otError ProcessLeaderWeight(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessMlIid(Arg aArgs[]);
|
||||
void OutputEidCacheEntry(const otCacheEntryInfo &aEntry);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
|
||||
otError ProcessLinkMetrics(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsQuery(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsMgmt(Arg aArgs[]);
|
||||
otError ProcessLinkMetricsProbe(Arg aArgs[]);
|
||||
otError ParseLinkMetricsFlags(otLinkMetrics &aLinkMetrics, const Arg &aFlags);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE
|
||||
otError ProcessLocate(Arg aArgs[]);
|
||||
static void HandleLocateResult(void * aContext,
|
||||
otError aError,
|
||||
const otIp6Address *aMeshLocalAddress,
|
||||
@@ -438,8 +351,6 @@ private:
|
||||
void HandleLocateResult(otError aError, const otIp6Address *aMeshLocalAddress, uint16_t aRloc16);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
|
||||
otError ProcessMlr(Arg aArgs[]);
|
||||
|
||||
static void HandleMlrRegResult(void * aContext,
|
||||
otError aError,
|
||||
uint8_t aMlrStatus,
|
||||
@@ -450,108 +361,17 @@ private:
|
||||
const otIp6Address *aFailedAddresses,
|
||||
uint8_t aFailedAddressNum);
|
||||
#endif
|
||||
otError ProcessMode(Arg aArgs[]);
|
||||
otError ProcessMultiRadio(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
void OutputMultiRadioInfo(const otMultiRadioNeighborInfo &aMultiRadioInfo);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNeighbor(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkData(Arg aArgs[]);
|
||||
otError ProcessNetstat(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessService(Arg aArgs[]);
|
||||
otError ProcessServiceList(void);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
otError ProcessNetworkDiagnostic(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessNetworkIdTimeout(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkKey(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
otError ProcessNetworkKeyRef(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessNetworkName(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
otError ProcessNetworkTime(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessParent(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessParentPriority(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
otError ProcessPing(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPollPeriod(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessPrefix(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessPromiscuous(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessPreferRouterId(Arg aArgs[]);
|
||||
otError ProcessPskc(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
otError ProcessPskcRef(Arg aArgs[]);
|
||||
#endif
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE && OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||
otError ProcessRadioFilter(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessRcp(Arg aArgs[]);
|
||||
otError ProcessRegion(Arg aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessReleaseRouterId(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError ProcessRoute(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessRouter(Arg aArgs[]);
|
||||
otError ProcessRouterDowngradeThreshold(Arg aArgs[]);
|
||||
otError ProcessRouterEligible(Arg aArgs[]);
|
||||
otError ProcessRouterSelectionJitter(Arg aArgs[]);
|
||||
otError ProcessRouterUpgradeThreshold(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessRloc16(Arg aArgs[]);
|
||||
otError ProcessScan(Arg aArgs[]);
|
||||
otError ProcessSingleton(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
|
||||
otError ProcessSntp(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE || OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
otError ProcessSrp(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessThread(Arg aArgs[]);
|
||||
otError ProcessDataset(Arg aArgs[]);
|
||||
otError ProcessTxPower(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TCP_ENABLE && OPENTHREAD_CONFIG_CLI_TCP_ENABLE
|
||||
otError ProcessTcp(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessUdp(Arg aArgs[]);
|
||||
otError ProcessUnsecurePort(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
otError ProcessUptime(Arg aArgs[]);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
otError ProcessMacFilter(Arg aArgs[]);
|
||||
void PrintMacFilter(void);
|
||||
otError ProcessMacFilterAddress(Arg aArgs[]);
|
||||
otError ProcessMacFilterRss(Arg aArgs[]);
|
||||
void OutputMacFilterEntry(const otMacFilterEntry &aEntry);
|
||||
static const char *MacFilterAddressModeToString(otMacFilterAddressMode aMode);
|
||||
#endif
|
||||
otError ProcessMac(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
otError ProcessTrel(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
otError ProcessRouterIdRange(Arg *aArgs);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
static void HandlePingReply(const otPingSenderReply *aReply, void *aContext);
|
||||
@@ -646,221 +466,6 @@ private:
|
||||
static void HandleTimer(Timer &aTimer);
|
||||
void HandleTimer(void);
|
||||
|
||||
// Commands supported by radio:
|
||||
// [diag, help, reset, version]
|
||||
static constexpr Command sCommands[] = {
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
{"ba", &Interpreter::ProcessBorderAgent},
|
||||
#endif
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
{"bbr", &Interpreter::ProcessBackboneRouter},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
{"br", &Interpreter::ProcessBorderRouting},
|
||||
#endif
|
||||
{"bufferinfo", &Interpreter::ProcessBufferInfo},
|
||||
{"ccathreshold", &Interpreter::ProcessCcaThreshold},
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
{"ccm", &Interpreter::ProcessCcm},
|
||||
#endif
|
||||
{"channel", &Interpreter::ProcessChannel},
|
||||
#if OPENTHREAD_FTD
|
||||
{"child", &Interpreter::ProcessChild},
|
||||
{"childip", &Interpreter::ProcessChildIp},
|
||||
{"childmax", &Interpreter::ProcessChildMax},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE
|
||||
{"childsupervision", &Interpreter::ProcessChildSupervision},
|
||||
#endif
|
||||
{"childtimeout", &Interpreter::ProcessChildTimeout},
|
||||
#if OPENTHREAD_CONFIG_COAP_API_ENABLE
|
||||
{"coap", &Interpreter::ProcessCoap},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
|
||||
{"coaps", &Interpreter::ProcessCoapSecure},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE
|
||||
{"coex", &Interpreter::ProcessCoexMetrics},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
{"commissioner", &Interpreter::ProcessCommissioner},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
{"contextreusedelay", &Interpreter::ProcessContextIdReuseDelay},
|
||||
#endif
|
||||
{"counters", &Interpreter::ProcessCounters},
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
|
||||
{"csl", &Interpreter::ProcessCsl},
|
||||
#endif
|
||||
{"dataset", &Interpreter::ProcessDataset},
|
||||
#if OPENTHREAD_FTD
|
||||
{"delaytimermin", &Interpreter::ProcessDelayTimerMin},
|
||||
#endif
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_CONFIG_DIAG_ENABLE
|
||||
{"diag", &Interpreter::ProcessDiag},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{"discover", &Interpreter::ProcessDiscover},
|
||||
{"dns", &Interpreter::ProcessDns},
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
{"domainname", &Interpreter::ProcessDomainName},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
{"dua", &Interpreter::ProcessDua},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
{"eidcache", &Interpreter::ProcessEidCache},
|
||||
#endif
|
||||
{"eui64", &Interpreter::ProcessEui64},
|
||||
{"extaddr", &Interpreter::ProcessExtAddress},
|
||||
{"extpanid", &Interpreter::ProcessExtPanId},
|
||||
{"factoryreset", &Interpreter::ProcessFactoryReset},
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
{"fake", &Interpreter::ProcessFake},
|
||||
#endif
|
||||
{"fem", &Interpreter::ProcessFem},
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{"help", &Interpreter::ProcessHelp},
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
|
||||
{"history", &Interpreter::ProcessHistory},
|
||||
#endif
|
||||
{"ifconfig", &Interpreter::ProcessIfconfig},
|
||||
{"ipaddr", &Interpreter::ProcessIpAddr},
|
||||
{"ipmaddr", &Interpreter::ProcessIpMulticastAddr},
|
||||
#if OPENTHREAD_CONFIG_JOINER_ENABLE
|
||||
{"joiner", &Interpreter::ProcessJoiner},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
{"joinerport", &Interpreter::ProcessJoinerPort},
|
||||
#endif
|
||||
{"keysequence", &Interpreter::ProcessKeySequence},
|
||||
{"leaderdata", &Interpreter::ProcessLeaderData},
|
||||
#if OPENTHREAD_FTD
|
||||
{"leaderweight", &Interpreter::ProcessLeaderWeight},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
|
||||
{"linkmetrics", &Interpreter::ProcessLinkMetrics},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_TMF_ANYCAST_LOCATOR_ENABLE
|
||||
{"locate", &Interpreter::ProcessLocate},
|
||||
#endif
|
||||
{"log", &Interpreter::ProcessLog},
|
||||
{"mac", &Interpreter::ProcessMac},
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
{"macfilter", &Interpreter::ProcessMacFilter},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
{"mliid", &Interpreter::ProcessMlIid},
|
||||
#endif
|
||||
#if (OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_MLR_ENABLE) && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
|
||||
{"mlr", &Interpreter::ProcessMlr},
|
||||
#endif
|
||||
{"mode", &Interpreter::ProcessMode},
|
||||
{"multiradio", &Interpreter::ProcessMultiRadio},
|
||||
#if OPENTHREAD_FTD
|
||||
{"neighbor", &Interpreter::ProcessNeighbor},
|
||||
#endif
|
||||
{"netdata", &Interpreter::ProcessNetworkData},
|
||||
{"netstat", &Interpreter::ProcessNetstat},
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
{"networkdiagnostic", &Interpreter::ProcessNetworkDiagnostic},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
{"networkidtimeout", &Interpreter::ProcessNetworkIdTimeout},
|
||||
#endif
|
||||
{"networkkey", &Interpreter::ProcessNetworkKey},
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
{"networkkeyref", &Interpreter::ProcessNetworkKeyRef},
|
||||
#endif
|
||||
{"networkname", &Interpreter::ProcessNetworkName},
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
{"networktime", &Interpreter::ProcessNetworkTime},
|
||||
#endif
|
||||
{"panid", &Interpreter::ProcessPanId},
|
||||
{"parent", &Interpreter::ProcessParent},
|
||||
#if OPENTHREAD_FTD
|
||||
{"parentpriority", &Interpreter::ProcessParentPriority},
|
||||
{"partitionid", &Interpreter::ProcessPartitionId},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_PING_SENDER_ENABLE
|
||||
{"ping", &Interpreter::ProcessPing},
|
||||
#endif
|
||||
{"pollperiod", &Interpreter::ProcessPollPeriod},
|
||||
#if OPENTHREAD_FTD
|
||||
{"preferrouterid", &Interpreter::ProcessPreferRouterId},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
{"prefix", &Interpreter::ProcessPrefix},
|
||||
#endif
|
||||
{"promiscuous", &Interpreter::ProcessPromiscuous},
|
||||
#if OPENTHREAD_FTD
|
||||
{"pskc", &Interpreter::ProcessPskc},
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
|
||||
{"pskcref", &Interpreter::ProcessPskcRef},
|
||||
#endif
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE && OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
|
||||
{"radiofilter", &Interpreter::ProcessRadioFilter},
|
||||
#endif
|
||||
{"rcp", &Interpreter::ProcessRcp},
|
||||
{"region", &Interpreter::ProcessRegion},
|
||||
#if OPENTHREAD_FTD
|
||||
{"releaserouterid", &Interpreter::ProcessReleaseRouterId},
|
||||
#endif
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{"reset", &Interpreter::ProcessReset},
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{"rloc16", &Interpreter::ProcessRloc16},
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
{"route", &Interpreter::ProcessRoute},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
{"router", &Interpreter::ProcessRouter},
|
||||
{"routerdowngradethreshold", &Interpreter::ProcessRouterDowngradeThreshold},
|
||||
{"routereligible", &Interpreter::ProcessRouterEligible},
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
{"routeridrange", &Interpreter::ProcessRouterIdRange},
|
||||
#endif
|
||||
{"routerselectionjitter", &Interpreter::ProcessRouterSelectionJitter},
|
||||
{"routerupgradethreshold", &Interpreter::ProcessRouterUpgradeThreshold},
|
||||
#endif
|
||||
{"scan", &Interpreter::ProcessScan},
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
{"service", &Interpreter::ProcessService},
|
||||
#endif
|
||||
{"singleton", &Interpreter::ProcessSingleton},
|
||||
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
|
||||
{"sntp", &Interpreter::ProcessSntp},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_ENABLE || OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
{"srp", &Interpreter::ProcessSrp},
|
||||
#endif
|
||||
{"state", &Interpreter::ProcessState},
|
||||
#if OPENTHREAD_CONFIG_TCP_ENABLE && OPENTHREAD_CONFIG_CLI_TCP_ENABLE
|
||||
{"tcp", &Interpreter::ProcessTcp},
|
||||
#endif
|
||||
{"thread", &Interpreter::ProcessThread},
|
||||
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
|
||||
{"trel", &Interpreter::ProcessTrel},
|
||||
#endif
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
{"tvcheck", &Interpreter::ProcessThreadVersionCheck},
|
||||
#endif
|
||||
{"txpower", &Interpreter::ProcessTxPower},
|
||||
{"udp", &Interpreter::ProcessUdp},
|
||||
{"unsecureport", &Interpreter::ProcessUnsecurePort},
|
||||
#if OPENTHREAD_CONFIG_UPTIME_ENABLE
|
||||
{"uptime", &Interpreter::ProcessUptime},
|
||||
#endif
|
||||
#endif // OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
{"version", &Interpreter::ProcessVersion},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
|
||||
const otCliCommand *mUserCommands;
|
||||
uint8_t mUserCommandsLength;
|
||||
void * mUserCommandsContext;
|
||||
|
||||
+47
-34
@@ -44,8 +44,6 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr Coap::Command Coap::sCommands[];
|
||||
|
||||
Coap::Coap(Output &aOutput)
|
||||
: OutputWrapper(aOutput)
|
||||
, mUseDefaultRequestTxParameters(true)
|
||||
@@ -144,7 +142,7 @@ void Coap::PrintPayload(otMessage *aMessage)
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessCancel(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("cancel")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -152,19 +150,7 @@ otError Coap::ProcessCancel(Arg aArgs[])
|
||||
}
|
||||
#endif
|
||||
|
||||
otError Coap::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Coap::ProcessResource(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("resource")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -203,7 +189,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessSet(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("set")>(Arg aArgs[])
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otMessage * notificationMessage = nullptr;
|
||||
@@ -264,14 +250,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessStart(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("start")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otCoapStart(GetInstancePtr(), OT_DEFAULT_COAP_PORT);
|
||||
}
|
||||
|
||||
otError Coap::ProcessStop(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("stop")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -284,7 +270,7 @@ otError Coap::ProcessStop(Arg aArgs[])
|
||||
return otCoapStop(GetInstancePtr());
|
||||
}
|
||||
|
||||
otError Coap::ProcessParameters(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("parameters")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool * defaultTxParameters;
|
||||
@@ -342,28 +328,28 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Coap::ProcessGet(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("get")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_GET);
|
||||
}
|
||||
|
||||
otError Coap::ProcessPost(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("post")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_POST);
|
||||
}
|
||||
|
||||
otError Coap::ProcessPut(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("put")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_PUT);
|
||||
}
|
||||
|
||||
otError Coap::ProcessDelete(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("delete")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_DELETE);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError Coap::ProcessObserve(Arg aArgs[])
|
||||
template <> otError Coap::Process<Cmd("observe")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRequest(aArgs, OT_COAP_CODE_GET, /* aCoapObserve */ true);
|
||||
}
|
||||
@@ -577,17 +563,44 @@ exit:
|
||||
|
||||
otError Coap::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &Coap::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
static constexpr Command kCommands[] = {
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
CmdEntry("cancel"),
|
||||
#endif
|
||||
CmdEntry("delete"),
|
||||
CmdEntry("get"),
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
CmdEntry("observe"),
|
||||
#endif
|
||||
CmdEntry("parameters"),
|
||||
CmdEntry("post"),
|
||||
CmdEntry("put"),
|
||||
CmdEntry("resource"),
|
||||
CmdEntry("set"),
|
||||
CmdEntry("start"),
|
||||
CmdEntry("stop"),
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? OT_ERROR_INVALID_ARGS : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
|
||||
+2
-38
@@ -86,6 +86,8 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError CancelResourceSubscription(void);
|
||||
void CancelSubscriber(void);
|
||||
@@ -93,23 +95,6 @@ private:
|
||||
|
||||
void PrintPayload(otMessage *aMessage);
|
||||
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessCancel(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessDelete(Arg aArgs[]);
|
||||
otError ProcessGet(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessObserve(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessParameters(Arg aArgs[]);
|
||||
otError ProcessPost(Arg aArgs[]);
|
||||
otError ProcessPut(Arg aArgs[]);
|
||||
otError ProcessResource(Arg aArgs[]);
|
||||
otError ProcessSet(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
otError ProcessRequest(Arg aArgs[], otCoapCode aCoapCode, bool aCoapObserve = false);
|
||||
#else
|
||||
@@ -161,27 +146,6 @@ private:
|
||||
return mUseDefaultResponseTxParameters ? nullptr : &mResponseTxParameters;
|
||||
}
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
{"cancel", &Coap::ProcessCancel},
|
||||
#endif
|
||||
{"delete", &Coap::ProcessDelete},
|
||||
{"get", &Coap::ProcessGet},
|
||||
{"help", &Coap::ProcessHelp},
|
||||
#if OPENTHREAD_CONFIG_COAP_OBSERVE_API_ENABLE
|
||||
{"observe", &Coap::ProcessObserve},
|
||||
#endif
|
||||
{"parameters", &Coap::ProcessParameters},
|
||||
{"post", &Coap::ProcessPost},
|
||||
{"put", &Coap::ProcessPut},
|
||||
{"resource", &Coap::ProcessResource},
|
||||
{"set", &Coap::ProcessSet},
|
||||
{"start", &Coap::ProcessStart},
|
||||
{"stop", &Coap::ProcessStop},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
|
||||
bool mUseDefaultRequestTxParameters;
|
||||
bool mUseDefaultResponseTxParameters;
|
||||
|
||||
|
||||
@@ -40,21 +40,7 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr Commissioner::Command Commissioner::sCommands[];
|
||||
|
||||
otError Commissioner::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessAnnounce(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("announce")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -73,7 +59,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessEnergy(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("energy")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint32_t mask;
|
||||
@@ -95,7 +81,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessJoiner(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("joiner")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otExtAddress addr;
|
||||
@@ -163,7 +149,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtGet(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("mgmtget")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t tlvs[32];
|
||||
@@ -210,7 +196,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessMgmtSet(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("mgmtset")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otCommissioningDataset dataset;
|
||||
@@ -272,7 +258,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessPanId(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("panid")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
uint16_t panId;
|
||||
@@ -289,14 +275,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessProvisioningUrl(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("provisioningurl")>(Arg aArgs[])
|
||||
{
|
||||
// If aArgs[0] is empty, `GetCString() will return `nullptr`
|
||||
/// which will correctly clear the provisioning URL.
|
||||
return otCommissionerSetProvisioningUrl(GetInstancePtr(), aArgs[0].GetCString());
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessSessionId(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("sessionid")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -305,7 +291,7 @@ otError Commissioner::ProcessSessionId(Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStart(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("start")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -376,14 +362,14 @@ void Commissioner::HandleJoinerEvent(otCommissionerJoinerEvent aEvent,
|
||||
OutputLine("");
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessStop(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("stop")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
return otCommissionerStop(GetInstancePtr());
|
||||
}
|
||||
|
||||
otError Commissioner::ProcessState(Arg aArgs[])
|
||||
template <> otError Commissioner::Process<Cmd("state")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -394,16 +380,32 @@ otError Commissioner::ProcessState(Arg aArgs[])
|
||||
|
||||
otError Commissioner::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &Commissioner::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
CmdEntry("announce"), CmdEntry("energy"), CmdEntry("joiner"),
|
||||
CmdEntry("mgmtget"), CmdEntry("mgmtset"), CmdEntry("panid"),
|
||||
CmdEntry("provisioningurl"), CmdEntry("sessionid"), CmdEntry("start"),
|
||||
CmdEntry("state"), CmdEntry("stop"),
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? error : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
@@ -81,18 +81,7 @@ private:
|
||||
|
||||
using Command = CommandEntry<Commissioner>;
|
||||
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessAnnounce(Arg aArgs[]);
|
||||
otError ProcessEnergy(Arg aArgs[]);
|
||||
otError ProcessJoiner(Arg aArgs[]);
|
||||
otError ProcessMgmtGet(Arg aArgs[]);
|
||||
otError ProcessMgmtSet(Arg aArgs[]);
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessProvisioningUrl(Arg aArgs[]);
|
||||
otError ProcessSessionId(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
static void HandleStateChanged(otCommissionerState aState, void *aContext);
|
||||
void HandleStateChanged(otCommissionerState aState);
|
||||
@@ -115,17 +104,6 @@ private:
|
||||
void HandlePanIdConflict(uint16_t aPanId, uint32_t aChannelMask);
|
||||
|
||||
static const char *StateToString(otCommissionerState aState);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"announce", &Commissioner::ProcessAnnounce}, {"energy", &Commissioner::ProcessEnergy},
|
||||
{"help", &Commissioner::ProcessHelp}, {"joiner", &Commissioner::ProcessJoiner},
|
||||
{"mgmtget", &Commissioner::ProcessMgmtGet}, {"mgmtset", &Commissioner::ProcessMgmtSet},
|
||||
{"panid", &Commissioner::ProcessPanId}, {"provisioningurl", &Commissioner::ProcessProvisioningUrl},
|
||||
{"sessionid", &Commissioner::ProcessSessionId}, {"start", &Commissioner::ProcessStart},
|
||||
{"state", &Commissioner::ProcessState}, {"stop", &Commissioner::ProcessStop},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
};
|
||||
|
||||
} // namespace Cli
|
||||
|
||||
+82
-54
@@ -45,8 +45,7 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr Dataset::Command Dataset::sCommands[];
|
||||
otOperationalDataset Dataset::sDataset;
|
||||
otOperationalDataset Dataset::sDataset;
|
||||
|
||||
otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
{
|
||||
@@ -119,38 +118,7 @@ otError Dataset::Print(otOperationalDataset &aDataset)
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessInit(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("init")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
@@ -183,7 +151,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActive(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("active")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
@@ -206,7 +174,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPending(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("pending")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
@@ -229,7 +197,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessActiveTimestamp(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("activetimestamp")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -250,7 +218,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannel(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("channel")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -271,7 +239,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessChannelMask(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("channelmask")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -292,7 +260,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessClear(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("clear")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -300,7 +268,7 @@ otError Dataset::ProcessClear(Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessCommit(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("commit")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
@@ -316,7 +284,7 @@ otError Dataset::ProcessCommit(Arg aArgs[])
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessDelay(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("delay")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -337,7 +305,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessExtPanId(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("extpanid")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -358,7 +326,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMeshLocalPrefix(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("meshlocalprefix")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -384,7 +352,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessNetworkKey(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("networkkey")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -405,7 +373,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessNetworkName(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("networkname")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -426,7 +394,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPanId(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("panid")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -447,7 +415,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPendingTimestamp(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("pendingtimestamp")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -468,7 +436,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtSetCommand(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("mgmtsetcommand")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDataset dataset;
|
||||
@@ -583,7 +551,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessMgmtGetCommand(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("mgmtgetcommand")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otOperationalDatasetComponents datasetComponents;
|
||||
@@ -676,7 +644,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessPskc(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("pskc")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -839,7 +807,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSecurityPolicy(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("securitypolicy")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -862,7 +830,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Dataset::ProcessSet(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("set")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
MeshCoP::Dataset::Type datasetType;
|
||||
@@ -907,7 +875,7 @@ exit:
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
otError Dataset::ProcessUpdater(Arg aArgs[])
|
||||
template <> otError Dataset::Process<Cmd("updater")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -943,5 +911,65 @@ void Dataset::HandleDatasetUpdater(otError aError)
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
otError Dataset::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &Dataset::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
CmdEntry("active"),
|
||||
CmdEntry("activetimestamp"),
|
||||
CmdEntry("channel"),
|
||||
CmdEntry("channelmask"),
|
||||
CmdEntry("clear"),
|
||||
CmdEntry("commit"),
|
||||
CmdEntry("delay"),
|
||||
CmdEntry("extpanid"),
|
||||
CmdEntry("init"),
|
||||
CmdEntry("meshlocalprefix"),
|
||||
CmdEntry("mgmtgetcommand"),
|
||||
CmdEntry("mgmtsetcommand"),
|
||||
CmdEntry("networkkey"),
|
||||
CmdEntry("networkname"),
|
||||
CmdEntry("panid"),
|
||||
CmdEntry("pending"),
|
||||
CmdEntry("pendingtimestamp"),
|
||||
CmdEntry("pskc"),
|
||||
CmdEntry("securitypolicy"),
|
||||
CmdEntry("set"),
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
CmdEntry("updater"),
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
|
||||
if (aArgs[0] == "help")
|
||||
{
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
+2
-51
@@ -70,29 +70,9 @@ public:
|
||||
private:
|
||||
using Command = CommandEntry<Dataset>;
|
||||
|
||||
otError Print(otOperationalDataset &aDataset);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessActive(Arg aArgs[]);
|
||||
otError ProcessActiveTimestamp(Arg aArgs[]);
|
||||
otError ProcessChannel(Arg aArgs[]);
|
||||
otError ProcessChannelMask(Arg aArgs[]);
|
||||
otError ProcessClear(Arg aArgs[]);
|
||||
otError ProcessCommit(Arg aArgs[]);
|
||||
otError ProcessDelay(Arg aArgs[]);
|
||||
otError ProcessExtPanId(Arg aArgs[]);
|
||||
otError ProcessInit(Arg aArgs[]);
|
||||
otError ProcessMeshLocalPrefix(Arg aArgs[]);
|
||||
otError ProcessNetworkName(Arg aArgs[]);
|
||||
otError ProcessNetworkKey(Arg aArgs[]);
|
||||
otError ProcessPanId(Arg aArgs[]);
|
||||
otError ProcessPending(Arg aArgs[]);
|
||||
otError ProcessPendingTimestamp(Arg aArgs[]);
|
||||
otError ProcessMgmtSetCommand(Arg aArgs[]);
|
||||
otError ProcessMgmtGetCommand(Arg aArgs[]);
|
||||
otError ProcessPskc(Arg aArgs[]);
|
||||
otError ProcessSecurityPolicy(Arg aArgs[]);
|
||||
otError ProcessSet(Arg aArgs[]);
|
||||
otError Print(otOperationalDataset &aDataset);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
otError ProcessUpdater(Arg aArgs[]);
|
||||
@@ -103,35 +83,6 @@ private:
|
||||
void OutputSecurityPolicy(const otSecurityPolicy &aSecurityPolicy);
|
||||
otError ParseSecurityPolicy(otSecurityPolicy &aSecurityPolicy, Arg *&aArgs);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"active", &Dataset::ProcessActive},
|
||||
{"activetimestamp", &Dataset::ProcessActiveTimestamp},
|
||||
{"channel", &Dataset::ProcessChannel},
|
||||
{"channelmask", &Dataset::ProcessChannelMask},
|
||||
{"clear", &Dataset::ProcessClear},
|
||||
{"commit", &Dataset::ProcessCommit},
|
||||
{"delay", &Dataset::ProcessDelay},
|
||||
{"extpanid", &Dataset::ProcessExtPanId},
|
||||
{"help", &Dataset::ProcessHelp},
|
||||
{"init", &Dataset::ProcessInit},
|
||||
{"meshlocalprefix", &Dataset::ProcessMeshLocalPrefix},
|
||||
{"mgmtgetcommand", &Dataset::ProcessMgmtGetCommand},
|
||||
{"mgmtsetcommand", &Dataset::ProcessMgmtSetCommand},
|
||||
{"networkkey", &Dataset::ProcessNetworkKey},
|
||||
{"networkname", &Dataset::ProcessNetworkName},
|
||||
{"panid", &Dataset::ProcessPanId},
|
||||
{"pending", &Dataset::ProcessPending},
|
||||
{"pendingtimestamp", &Dataset::ProcessPendingTimestamp},
|
||||
{"pskc", &Dataset::ProcessPskc},
|
||||
{"securitypolicy", &Dataset::ProcessSecurityPolicy},
|
||||
{"set", &Dataset::ProcessSet},
|
||||
#if OPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE && OPENTHREAD_FTD
|
||||
{"updater", &Dataset::ProcessUpdater},
|
||||
#endif
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
|
||||
static otOperationalDataset sDataset;
|
||||
};
|
||||
|
||||
|
||||
+27
-27
@@ -42,25 +42,11 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr History::Command History::sCommands[];
|
||||
|
||||
static const char *const kSimpleEventStrings[] = {
|
||||
"Added", // (0) OT_HISTORY_TRACKER_{NET_DATA_ENTRY/ADDRESSS_EVENT}_ADDED
|
||||
"Removed" // (1) OT_HISTORY_TRACKER_{NET_DATA_ENTRY/ADDRESS_EVENT}_REMOVED
|
||||
};
|
||||
|
||||
otError History::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError History::ParseArgs(Arg aArgs[], bool &aIsList, uint16_t &aNumEntries) const
|
||||
{
|
||||
if (*aArgs == "list")
|
||||
@@ -85,7 +71,7 @@ otError History::ParseArgs(Arg aArgs[], bool &aIsList, uint16_t &aNumEntries) co
|
||||
return aArgs[0].IsEmpty() ? OT_ERROR_NONE : OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
otError History::ProcessIpAddr(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("ipaddr")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool isList;
|
||||
@@ -146,7 +132,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError History::ProcessIpMulticastAddr(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("ipmaddr")>(Arg aArgs[])
|
||||
{
|
||||
static const char *const kEventStrings[] = {
|
||||
"Subscribed", // (0) OT_HISTORY_TRACKER_ADDRESS_EVENT_ADDED
|
||||
@@ -203,7 +189,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError History::ProcessNeighbor(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("neighbor")>(Arg aArgs[])
|
||||
{
|
||||
static const char *const kEventString[] = {
|
||||
/* (0) OT_HISTORY_TRACKER_NEIGHBOR_EVENT_ADDED -> */ "Added",
|
||||
@@ -268,7 +254,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError History::ProcessNetInfo(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("netinfo")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool isList;
|
||||
@@ -311,17 +297,17 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError History::ProcessRx(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("rx")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRxTxHistory(kRx, aArgs);
|
||||
}
|
||||
|
||||
otError History::ProcessRxTx(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("rxtx")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRxTxHistory(kRxTx, aArgs);
|
||||
}
|
||||
|
||||
otError History::ProcessTx(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("tx")>(Arg aArgs[])
|
||||
{
|
||||
return ProcessRxTxHistory(kTx, aArgs);
|
||||
}
|
||||
@@ -571,7 +557,7 @@ void History::OutputRxTxEntryTableFormat(const otHistoryTrackerMessageInfo &aInf
|
||||
OutputLine("| %20s | dst: %-70s |", "", addrString);
|
||||
}
|
||||
|
||||
otError History::ProcessPrefix(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("prefix")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool isList;
|
||||
@@ -621,7 +607,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError History::ProcessRoute(Arg aArgs[])
|
||||
template <> otError History::Process<Cmd("route")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
bool isList;
|
||||
@@ -673,16 +659,30 @@ exit:
|
||||
|
||||
otError History::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &History::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
CmdEntry("ipaddr"), CmdEntry("ipmaddr"), CmdEntry("neighbor"), CmdEntry("netinfo"), CmdEntry("prefix"),
|
||||
CmdEntry("route"), CmdEntry("rx"), CmdEntry("rxtx"), CmdEntry("tx"),
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? error : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
+1
-25
@@ -88,16 +88,7 @@ private:
|
||||
kRxTx,
|
||||
};
|
||||
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessIpAddr(Arg aArgs[]);
|
||||
otError ProcessIpMulticastAddr(Arg aArgs[]);
|
||||
otError ProcessNetInfo(Arg aArgs[]);
|
||||
otError ProcessNeighbor(Arg aArgs[]);
|
||||
otError ProcessPrefix(Arg aArgs[]);
|
||||
otError ProcessRoute(Arg aArgs[]);
|
||||
otError ProcessRx(Arg aArgs[]);
|
||||
otError ProcessRxTx(Arg aArgs[]);
|
||||
otError ProcessTx(Arg aArgs[]);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
otError ParseArgs(Arg aArgs[], bool &aIsList, uint16_t &aNumEntries) const;
|
||||
otError ProcessRxTxHistory(RxTx aRxTx, Arg aArgs[]);
|
||||
@@ -107,21 +98,6 @@ private:
|
||||
static const char *MessagePriorityToString(uint8_t aPriority);
|
||||
static const char *RadioTypeToString(const otHistoryTrackerMessageInfo &aInfo);
|
||||
static const char *MessageTypeToString(const otHistoryTrackerMessageInfo &aInfo);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"help", &History::ProcessHelp},
|
||||
{"ipaddr", &History::ProcessIpAddr},
|
||||
{"ipmaddr", &History::ProcessIpMulticastAddr},
|
||||
{"neighbor", &History::ProcessNeighbor},
|
||||
{"netinfo", &History::ProcessNetInfo},
|
||||
{"prefix", &History::ProcessPrefix},
|
||||
{"route", &History::ProcessRoute},
|
||||
{"rx", &History::ProcessRx},
|
||||
{"rxtx", &History::ProcessRxTx},
|
||||
{"tx", &History::ProcessTx},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
};
|
||||
|
||||
} // namespace Cli
|
||||
|
||||
+22
-23
@@ -42,9 +42,7 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr Joiner::Command Joiner::sCommands[];
|
||||
|
||||
otError Joiner::ProcessDiscerner(Arg aArgs[])
|
||||
template <> otError Joiner::Process<Cmd("discerner")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
|
||||
@@ -79,19 +77,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessId(Arg aArgs[])
|
||||
template <> otError Joiner::Process<Cmd("id")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -100,7 +86,7 @@ otError Joiner::ProcessId(Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStart(Arg aArgs[])
|
||||
template <> otError Joiner::Process<Cmd("start")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
|
||||
@@ -119,7 +105,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessStop(Arg aArgs[])
|
||||
template <> otError Joiner::Process<Cmd("stop")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -128,7 +114,7 @@ otError Joiner::ProcessStop(Arg aArgs[])
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError Joiner::ProcessState(Arg aArgs[])
|
||||
template <> otError Joiner::Process<Cmd("state")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -139,16 +125,29 @@ otError Joiner::ProcessState(Arg aArgs[])
|
||||
|
||||
otError Joiner::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &Joiner::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
CmdEntry("discerner"), CmdEntry("id"), CmdEntry("start"), CmdEntry("state"), CmdEntry("stop"),
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? error : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
+1
-13
@@ -76,22 +76,10 @@ public:
|
||||
private:
|
||||
using Command = CommandEntry<Joiner>;
|
||||
|
||||
otError ProcessDiscerner(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessId(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
static void HandleCallback(otError aError, void *aContext);
|
||||
void HandleCallback(otError aError);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"discerner", &Joiner::ProcessDiscerner}, {"help", &Joiner::ProcessHelp}, {"id", &Joiner::ProcessId},
|
||||
{"start", &Joiner::ProcessStart}, {"state", &Joiner::ProcessState}, {"stop", &Joiner::ProcessStop},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
};
|
||||
|
||||
} // namespace Cli
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr NetworkData::Command NetworkData::sCommands[];
|
||||
|
||||
void NetworkData::PrefixFlagsToString(const otBorderRouterConfig &aConfig, FlagsString &aString)
|
||||
{
|
||||
char *flagsPtr = &aString[0];
|
||||
@@ -186,20 +184,8 @@ void NetworkData::OutputService(const otServiceConfig &aConfig)
|
||||
OutputLine(" %04x", aConfig.mServerConfig.mRloc16);
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
otError NetworkData::ProcessPublish(Arg aArgs[])
|
||||
template <> otError NetworkData::Process<Cmd("publish")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -261,7 +247,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessUnpublish(Arg aArgs[])
|
||||
template <> otError NetworkData::Process<Cmd("unpublish")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -293,7 +279,7 @@ exit:
|
||||
#endif // OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError NetworkData::ProcessRegister(Arg aArgs[])
|
||||
template <> otError NetworkData::Process<Cmd("register")>(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
@@ -310,7 +296,7 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
otError NetworkData::ProcessSteeringData(Arg aArgs[])
|
||||
template <> otError NetworkData::Process<Cmd("steeringdata")>(Arg aArgs[])
|
||||
{
|
||||
otError error;
|
||||
otExtAddress addr;
|
||||
@@ -466,7 +452,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError NetworkData::ProcessShow(Arg aArgs[])
|
||||
template <> otError NetworkData::Process<Cmd("show")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
bool local = false;
|
||||
@@ -506,16 +492,39 @@ exit:
|
||||
|
||||
otError NetworkData::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &NetworkData::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
CmdEntry("publish"),
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
CmdEntry("register"),
|
||||
#endif
|
||||
CmdEntry("show"),
|
||||
CmdEntry("steeringdata"),
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
CmdEntry("unpublish"),
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef CmdEntry
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? error : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
@@ -138,16 +138,7 @@ public:
|
||||
private:
|
||||
using Command = CommandEntry<NetworkData>;
|
||||
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
otError ProcessPublish(Arg aArgs[]);
|
||||
otError ProcessUnpublish(Arg aArgs[]);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
otError ProcessRegister(Arg aArgs[]);
|
||||
#endif
|
||||
otError ProcessShow(Arg aArgs[]);
|
||||
otError ProcessSteeringData(Arg aArgs[]);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
otError GetNextPrefix(otNetworkDataIterator *aIterator, otBorderRouterConfig *aConfig, bool aLocal);
|
||||
otError GetNextRoute(otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig, bool aLocal);
|
||||
@@ -157,23 +148,6 @@ private:
|
||||
void OutputPrefixes(bool aLocal);
|
||||
void OutputRoutes(bool aLocal);
|
||||
void OutputServices(bool aLocal);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"help", &NetworkData::ProcessHelp},
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
{"publish", &NetworkData::ProcessPublish},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE || OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
{"register", &NetworkData::ProcessRegister},
|
||||
#endif
|
||||
{"show", &NetworkData::ProcessShow},
|
||||
{"steeringdata", &NetworkData::ProcessSteeringData},
|
||||
#if OPENTHREAD_CONFIG_NETDATA_PUBLISHER_ENABLE
|
||||
{"unpublish", &NetworkData::ProcessUnpublish},
|
||||
#endif
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
};
|
||||
|
||||
} // namespace Cli
|
||||
|
||||
+83
-17
@@ -49,6 +49,25 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
/**
|
||||
* This type represents a ID number value associated with a CLI command string.
|
||||
*
|
||||
*/
|
||||
typedef uint64_t CommandId;
|
||||
|
||||
/**
|
||||
* This `constexpr` function converts a CLI command string to its associated `CommandId` value.
|
||||
*
|
||||
* @param[in] aString The CLI command string.
|
||||
*
|
||||
* @returns The associated `CommandId` with @p aString.
|
||||
*
|
||||
*/
|
||||
constexpr static CommandId Cmd(const char *aString)
|
||||
{
|
||||
return (aString[0] == '\0') ? 0 : (static_cast<uint8_t>(aString[0]) + Cmd(aString + 1) * 255u);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is the base class for `Output` and `OutputWrapper` providing common helper methods.
|
||||
*
|
||||
@@ -56,6 +75,48 @@ namespace Cli {
|
||||
class OutputBase
|
||||
{
|
||||
public:
|
||||
typedef Utils::CmdLineParser::Arg Arg; ///< An argument
|
||||
|
||||
/**
|
||||
* This structure represent a CLI command table entry, mapping a command with `aName` to a handler method.
|
||||
*
|
||||
* @tparam Cli The CLI module type.
|
||||
*
|
||||
*/
|
||||
template <typename Cli> struct CommandEntry
|
||||
{
|
||||
typedef otError (Cli::*Handler)(Arg aArgs[]); ///< The handler method pointer type.
|
||||
|
||||
/**
|
||||
* This method compares the entry's name with a given name.
|
||||
*
|
||||
* @param aName The name string to compare with.
|
||||
*
|
||||
* @return zero means perfect match, positive (> 0) indicates @p aName is larger than entry's name, and
|
||||
* negative (< 0) indicates @p aName is smaller than entry's name.
|
||||
*
|
||||
*/
|
||||
int Compare(const char *aName) const { return strcmp(aName, mName); }
|
||||
|
||||
/**
|
||||
* This `constexpr` method compares two entries to check if they are in order.
|
||||
*
|
||||
* @param[in] aFirst The first entry.
|
||||
* @param[in] aSecond The second entry.
|
||||
*
|
||||
* @retval TRUE if @p aFirst and @p aSecond are in order, i.e. `aFirst < aSecond`.
|
||||
* @retval FALSE if @p aFirst and @p aSecond are not in order, i.e. `aFirst >= aSecond`.
|
||||
*
|
||||
*/
|
||||
constexpr static bool AreInOrder(const CommandEntry &aFirst, const CommandEntry &aSecond)
|
||||
{
|
||||
return AreStringsInOrder(aFirst.mName, aSecond.mName);
|
||||
}
|
||||
|
||||
const char *mName; ///< The command name.
|
||||
Handler mHandler; ///< The handler method pointer.
|
||||
};
|
||||
|
||||
static const char kUnknownString[]; // Constant string "unknown".
|
||||
|
||||
/**
|
||||
@@ -82,23 +143,6 @@ public:
|
||||
|
||||
protected:
|
||||
OutputBase(void) = default;
|
||||
|
||||
typedef Utils::CmdLineParser::Arg Arg;
|
||||
|
||||
template <typename Cli> struct CommandEntry
|
||||
{
|
||||
typedef otError (Cli::*Handler)(Arg aArgs[]);
|
||||
|
||||
int Compare(const char *aName) const { return strcmp(aName, mName); }
|
||||
|
||||
constexpr static bool AreInOrder(const CommandEntry &aFirst, const CommandEntry &aSecond)
|
||||
{
|
||||
return AreStringsInOrder(aFirst.mName, aSecond.mName);
|
||||
}
|
||||
|
||||
const char *mName;
|
||||
Handler mHandler;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -363,6 +407,23 @@ public:
|
||||
OutputTableSeparator(kTableNumColumns, &aWidths[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method outputs the list of commands from a given command table.
|
||||
*
|
||||
* @tparam Cli The CLI module type.
|
||||
* @tparam kLength The length of command table array.
|
||||
*
|
||||
* @param[in] aCommandTable The command table array.
|
||||
*
|
||||
*/
|
||||
template <typename Cli, uint16_t kLength> void OutputCommandTable(const CommandEntry<Cli> (&aCommandTable)[kLength])
|
||||
{
|
||||
for (const CommandEntry<Cli> &entry : aCommandTable)
|
||||
{
|
||||
OutputLine("%s", entry.mName);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void OutputFormatV(const char *aFormat, va_list aArguments);
|
||||
|
||||
@@ -463,6 +524,11 @@ protected:
|
||||
mOutput.OutputTableSeparator(aWidths);
|
||||
}
|
||||
|
||||
template <typename Cli, uint16_t kLength> void OutputCommandTable(const CommandEntry<Cli> (&aCommandTable)[kLength])
|
||||
{
|
||||
mOutput.OutputCommandTable(aCommandTable);
|
||||
}
|
||||
|
||||
private:
|
||||
Output &mOutput;
|
||||
};
|
||||
|
||||
+43
-44
@@ -42,8 +42,6 @@
|
||||
namespace ot {
|
||||
namespace Cli {
|
||||
|
||||
constexpr SrpClient::Command SrpClient::sCommands[];
|
||||
|
||||
static otError CopyString(char *aDest, uint16_t aDestSize, const char *aSource)
|
||||
{
|
||||
// Copies a string from `aSource` to `aDestination` (char array),
|
||||
@@ -66,29 +64,9 @@ SrpClient::SrpClient(Output &aOutput)
|
||||
otSrpClientSetCallback(GetInstancePtr(), SrpClient::HandleCallback, this);
|
||||
}
|
||||
|
||||
otError SrpClient::Process(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
{
|
||||
IgnoreError(ProcessHelp(aArgs));
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessAutoStart(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("autostart")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool enable;
|
||||
@@ -116,7 +94,7 @@ exit:
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
|
||||
|
||||
otError SrpClient::ProcessCallback(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("callback")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -132,19 +110,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHelp(Arg aArgs[])
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
OutputLine(command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessHost(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("host")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -265,18 +231,18 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessLeaseInterval(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("leaseinterval")>(Arg aArgs[])
|
||||
{
|
||||
return Interpreter::GetInterpreter().ProcessGetSet(aArgs, otSrpClientGetLeaseInterval, otSrpClientSetLeaseInterval);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessKeyLeaseInterval(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("keyleaseinterval")>(Arg aArgs[])
|
||||
{
|
||||
return Interpreter::GetInterpreter().ProcessGetSet(aArgs, otSrpClientGetKeyLeaseInterval,
|
||||
otSrpClientSetKeyLeaseInterval);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessServer(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("server")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const otSockAddr *serverSockAddr = otSrpClientGetServerAddress(GetInstancePtr());
|
||||
@@ -306,7 +272,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessService(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("service")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool isRemove;
|
||||
@@ -521,7 +487,7 @@ void SrpClient::OutputService(uint8_t aIndentSize, const otSrpClientService &aSe
|
||||
aService.mPort, aService.mPriority, aService.mWeight);
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStart(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("start")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otSockAddr serverSockAddr;
|
||||
@@ -536,7 +502,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessState(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("state")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -548,7 +514,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError SrpClient::ProcessStop(Arg aArgs[])
|
||||
template <> otError SrpClient::Process<Cmd("stop")>(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
@@ -602,6 +568,39 @@ void SrpClient::HandleCallback(otError aError,
|
||||
}
|
||||
}
|
||||
|
||||
otError SrpClient::Process(Arg aArgs[])
|
||||
{
|
||||
#define CmdEntry(aCommandString) \
|
||||
{ \
|
||||
aCommandString, &SrpClient::Process<Cmd(aCommandString)> \
|
||||
}
|
||||
|
||||
static constexpr Command kCommands[] = {
|
||||
CmdEntry("autostart"), CmdEntry("callback"), CmdEntry("host"), CmdEntry("keyleaseinterval"),
|
||||
CmdEntry("leaseinterval"), CmdEntry("server"), CmdEntry("service"), CmdEntry("start"),
|
||||
CmdEntry("state"), CmdEntry("stop"),
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(kCommands), "kCommands is not sorted");
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
const Command *command;
|
||||
|
||||
if (aArgs[0].IsEmpty() || (aArgs[0] == "help"))
|
||||
{
|
||||
OutputCommandTable(kCommands);
|
||||
ExitNow(error = aArgs[0].IsEmpty() ? error : OT_ERROR_NONE);
|
||||
}
|
||||
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), kCommands);
|
||||
VerifyOrExit(command != nullptr);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -81,18 +81,9 @@ private:
|
||||
|
||||
using Command = CommandEntry<SrpClient>;
|
||||
|
||||
otError ProcessAutoStart(Arg aArgs[]);
|
||||
otError ProcessCallback(Arg aArgs[]);
|
||||
otError ProcessHelp(Arg aArgs[]);
|
||||
otError ProcessHost(Arg aArgs[]);
|
||||
otError ProcessLeaseInterval(Arg aArgs[]);
|
||||
otError ProcessKeyLeaseInterval(Arg aArgs[]);
|
||||
otError ProcessServer(Arg aArgs[]);
|
||||
otError ProcessService(Arg aArgs[]);
|
||||
template <CommandId kCommandId> otError Process(Arg aArgs[]);
|
||||
|
||||
otError ProcessServiceAdd(Arg aArgs[]);
|
||||
otError ProcessStart(Arg aArgs[]);
|
||||
otError ProcessState(Arg aArgs[]);
|
||||
otError ProcessStop(Arg aArgs[]);
|
||||
|
||||
void OutputHostInfo(uint8_t aIndentSize, const otSrpClientHostInfo &aHostInfo);
|
||||
void OutputServiceList(uint8_t aIndentSize, const otSrpClientService *aServices);
|
||||
@@ -108,22 +99,6 @@ private:
|
||||
const otSrpClientService * aServices,
|
||||
const otSrpClientService * aRemovedServices);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
{"autostart", &SrpClient::ProcessAutoStart},
|
||||
{"callback", &SrpClient::ProcessCallback},
|
||||
{"help", &SrpClient::ProcessHelp},
|
||||
{"host", &SrpClient::ProcessHost},
|
||||
{"keyleaseinterval", &SrpClient::ProcessKeyLeaseInterval},
|
||||
{"leaseinterval", &SrpClient::ProcessLeaseInterval},
|
||||
{"server", &SrpClient::ProcessServer},
|
||||
{"service", &SrpClient::ProcessService},
|
||||
{"start", &SrpClient::ProcessStart},
|
||||
{"state", &SrpClient::ProcessState},
|
||||
{"stop", &SrpClient::ProcessStop},
|
||||
};
|
||||
|
||||
static_assert(BinarySearch::IsSorted(sCommands), "Command Table is not sorted");
|
||||
|
||||
bool mCallbackEnabled;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user