mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 08:40:06 +00:00
[posix] allow disabling CLI for daemon (#9357)
The CLI interface for the posix daemon ise useful for testing and debugging but may not be useful for release/user builds. on size sensitive plaforms such as Android, disabling the daemon CLI will reduce the ot-daemon binary size by around 150 KB. So this commit defines config "OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE" to make the daemon CLI interface optional.
This commit is contained in:
@@ -381,7 +381,10 @@ int main(int argc, char *argv[])
|
||||
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||
otAppCliInit(instance);
|
||||
#endif
|
||||
|
||||
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE || OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
IgnoreError(otCliSetUserCommands(kCommands, OT_ARRAY_LENGTH(kCommands), instance));
|
||||
#endif
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -72,6 +72,18 @@ void GetFilename(Filename &aFilename, const char *aPattern)
|
||||
|
||||
} // namespace
|
||||
|
||||
int Daemon::OutputFormat(const char *aFormat, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, aFormat);
|
||||
ret = OutputFormatV(aFormat, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Daemon::OutputFormatV(const char *aFormat, va_list aArguments)
|
||||
{
|
||||
static constexpr char truncatedMsg[] = "(truncated ...)";
|
||||
@@ -244,12 +256,14 @@ void Daemon::SetUp(void)
|
||||
DieNowWithMessage("listen", OT_EXIT_ERROR_ERRNO);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
otCliInit(
|
||||
gInstance,
|
||||
[](void *aContext, const char *aFormat, va_list aArguments) -> int {
|
||||
return static_cast<Daemon *>(aContext)->OutputFormatV(aFormat, aArguments);
|
||||
},
|
||||
this);
|
||||
#endif
|
||||
|
||||
Mainloop::Manager::Get().Add(*this);
|
||||
|
||||
@@ -349,7 +363,11 @@ void Daemon::Process(const otSysMainloopContext &aContext)
|
||||
if (rval > 0)
|
||||
{
|
||||
buffer[rval] = '\0';
|
||||
#if OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
otCliInputLine(reinterpret_cast<char *>(buffer));
|
||||
#else
|
||||
OutputFormat("Error: CLI is disabled!\n");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
void Process(const otSysMainloopContext &aContext) override;
|
||||
|
||||
private:
|
||||
int OutputFormat(const char *aFormat, ...);
|
||||
int OutputFormatV(const char *aFormat, va_list aArguments);
|
||||
void InitializeSessionSocket(void);
|
||||
|
||||
|
||||
@@ -75,6 +75,16 @@
|
||||
#define OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
*
|
||||
* Define to 1 to enable CLI for the posix daemon.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
#define OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RCP bus UART.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user