From 8a75ed7075a901d2f774a23718d4dd2695aceb9b Mon Sep 17 00:00:00 2001 From: Yufeng Wang <44623591+yufengwangca@users.noreply.github.com> Date: Fri, 11 Dec 2020 16:17:05 -0800 Subject: [PATCH] [shell]:Start CHIP event-loop by default during initialization. (#4185) * Start CHIP event-loop by default during initialization. * Add CHIP memory init during initialization --- examples/shell/shell_common/cmd_device.cpp | 35 ++++++++-------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/examples/shell/shell_common/cmd_device.cpp b/examples/shell/shell_common/cmd_device.cpp index 5699366db65d37..c6e425fc54eafd 100644 --- a/examples/shell/shell_common/cmd_device.cpp +++ b/examples/shell/shell_common/cmd_device.cpp @@ -53,21 +53,6 @@ int cmd_device_help(int argc, char ** argv) return 0; } -int cmd_device_start(int argc, char ** argv) -{ - CHIP_ERROR error = CHIP_NO_ERROR; - streamer_t * sout = streamer_get(); - - VerifyOrExit(argc == 0, error = CHIP_ERROR_INVALID_ARGUMENT); - - streamer_printf(sout, "Starting Platform Manager Event Loop\r\n"); - error = PlatformMgr().StartEventLoopTask(); - SuccessOrExit(error); - -exit: - return error; -} - static CHIP_ERROR ConfigGetDone(streamer_t * sout, CHIP_ERROR error) { if (error) @@ -925,7 +910,6 @@ static const shell_command_t cmds_device_root = { &cmd_device_dispatch, "device" /// Subcommands for root command: `device ` static const shell_command_t cmds_device[] = { { &cmd_device_help, "help", "Usage: device " }, - { &cmd_device_start, "start", "Start the device layer. Usage: device start" }, { &cmd_device_get, "get", "Get configuration value. Usage: device get " }, { &cmd_device_config, "config", "Dump entire configuration of device. Usage: device config" }, #if CHIP_DEVICE_CONFIG_ENABLE_THREAD @@ -953,20 +937,25 @@ void cmd_device_init() streamer_t * sout = streamer_get(); + error = chip::Platform::MemoryInit(); + VerifyOrExit(error == CHIP_NO_ERROR, + streamer_printf(sout, "Failed to init CHIP platform memory with error: %s\r\n", ErrorStr(error))); + streamer_printf(sout, "Init CHIP Stack\r\n"); error = PlatformMgr().InitChipStack(); - - if (error != CHIP_NO_ERROR) - streamer_printf(sout, "Failed to init CHIP Stack with error: %s\r\n", ErrorStr(error)); + VerifyOrExit(error == CHIP_NO_ERROR, streamer_printf(sout, "Failed to init CHIP Stack with error: %s\r\n", ErrorStr(error))); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD streamer_printf(sout, "Init Thread stack\r\n"); error = ThreadStackMgr().InitThreadStack(); - if (error != CHIP_NO_ERROR) - { - streamer_printf(sout, "ThreadStackMgr().InitThreadStack() failed\r\n"); - } + VerifyOrExit(error == CHIP_NO_ERROR, streamer_printf(sout, "ThreadStackMgr().InitThreadStack() failed\r\n")); #endif + // Starting Platform Manager Event Loop; + error = PlatformMgr().StartEventLoopTask(); + VerifyOrExit(error == CHIP_NO_ERROR, streamer_printf(sout, "Failed to start platform event loop\r\n")); + +exit: + return; #endif // CONFIG_DEVICE_LAYER }