Skip to content

Commit

Permalink
[shell]:Start CHIP event-loop by default during initialization. (#4185)
Browse files Browse the repository at this point in the history
* Start CHIP event-loop by default during initialization.

* Add CHIP memory init during initialization
  • Loading branch information
yufengwangca authored Dec 12, 2020
1 parent fd1da07 commit 8a75ed7
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions examples/shell/shell_common/cmd_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -925,7 +910,6 @@ static const shell_command_t cmds_device_root = { &cmd_device_dispatch, "device"
/// Subcommands for root command: `device <subcommand>`
static const shell_command_t cmds_device[] = {
{ &cmd_device_help, "help", "Usage: device <subcommand>" },
{ &cmd_device_start, "start", "Start the device layer. Usage: device start" },
{ &cmd_device_get, "get", "Get configuration value. Usage: device get <param_name>" },
{ &cmd_device_config, "config", "Dump entire configuration of device. Usage: device config" },
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
Expand Down Expand Up @@ -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
}

0 comments on commit 8a75ed7

Please sign in to comment.