mirror of
https://github.com/espressif/openthread.git
synced 2026-08-31 06:19:54 +00:00
[posix] add otSysCliInitUsingDaemon API (#9897)
This is to initialize CLI for daemon instance. With this API, user can redirect the Vendor server CLI output when needed, and then reset back using this API when the CLI output should be restored.
This commit is contained in:
@@ -285,12 +285,7 @@ void Daemon::SetUp(void)
|
||||
}
|
||||
|
||||
#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);
|
||||
otSysCliInitUsingDaemon(gInstance);
|
||||
#endif
|
||||
|
||||
Mainloop::Manager::Get().Add(*this);
|
||||
|
||||
@@ -45,10 +45,10 @@ public:
|
||||
void TearDown(void);
|
||||
void Update(otSysMainloopContext &aContext) override;
|
||||
void Process(const otSysMainloopContext &aContext) override;
|
||||
int OutputFormatV(const char *aFormat, va_list aArguments);
|
||||
|
||||
private:
|
||||
int OutputFormat(const char *aFormat, ...);
|
||||
int OutputFormatV(const char *aFormat, va_list aArguments);
|
||||
void createListenSocketOrDie(void);
|
||||
void InitializeSessionSocket(void);
|
||||
|
||||
|
||||
@@ -254,6 +254,19 @@ void otSysSetInfraNetif(const char *aInfraNetifName, int aIcmp6Socket);
|
||||
*/
|
||||
bool otSysInfraIfIsRunning(void);
|
||||
|
||||
/**
|
||||
* Initializes the CLI module using the daemon.
|
||||
*
|
||||
* This function initializes the CLI module, and assigns the daemon to handle
|
||||
* the CLI output. This function can be invoked multiple times. The typical use case
|
||||
* is that, after OTBR/vendor_server's CLI output redirection, it uses this API to
|
||||
* restore the original daemon's CLI output.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void otSysCliInitUsingDaemon(otInstance *aInstance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
#endif
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/border_router.h>
|
||||
#include <openthread/cli.h>
|
||||
#include <openthread/heap.h>
|
||||
#include <openthread/tasklet.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
@@ -401,3 +402,15 @@ void otSysMainloopProcess(otInstance *aInstance, const otSysMainloopContext *aMa
|
||||
}
|
||||
|
||||
bool IsSystemDryRun(void) { return gDryRun; }
|
||||
|
||||
#if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE && OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE
|
||||
void otSysCliInitUsingDaemon(otInstance *aInstance)
|
||||
{
|
||||
otCliInit(
|
||||
aInstance,
|
||||
[](void *aContext, const char *aFormat, va_list aArguments) -> int {
|
||||
return static_cast<ot::Posix::Daemon *>(aContext)->OutputFormatV(aFormat, aArguments);
|
||||
},
|
||||
&ot::Posix::Daemon::Get());
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user