Skip to content

Commit

Permalink
use char ptr in xQueueSend
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Oct 9, 2023
1 parent 13f09f4 commit 23b31a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ static CHIP_ERROR OtcliHandler(int argc, char * argv[])
strcat(cli_str.get(), " ");
}

if (cli_transmit_task_post(cli_str) != CHIP_NO_ERROR)
if (cli_transmit_task_post(std::move(cli_str)) != CHIP_NO_ERROR)
{
return CHIP_ERROR_INTERNAL;
}
cli_str.release();
return CHIP_NO_ERROR;
}

Expand Down
17 changes: 10 additions & 7 deletions src/platform/ESP32/OpenthreadLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ static esp_openthread_platform_config_t * s_platform_config = NULL;
static TaskHandle_t cli_transmit_task = NULL;
static QueueHandle_t cli_transmit_task_queue = NULL;

CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> & cli_str)
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> && cli_str)
{
if (!cli_transmit_task_queue || xQueueSend(cli_transmit_task_queue, &cli_str, portMAX_DELAY) != pdTRUE)
char * cmd = cli_str.get();
if (!cli_transmit_task_queue || xQueueSend(cli_transmit_task_queue, &cmd, portMAX_DELAY) != pdTRUE)
{
return CHIP_ERROR_INTERNAL;
}
cli_str.release();
return CHIP_NO_ERROR;
}

Expand All @@ -71,7 +73,7 @@ static void esp_openthread_matter_cli_init(void)

static void cli_transmit_worker(void * context)
{
cli_transmit_task_queue = xQueueCreate(8, sizeof(std::unique_ptr<char[]>));
cli_transmit_task_queue = xQueueCreate(8, sizeof(char *));
if (!cli_transmit_task_queue)
{
vTaskDelete(NULL);
Expand All @@ -80,12 +82,13 @@ static void cli_transmit_worker(void * context)

while (true)
{
std::unique_ptr<char[]> command_line(nullptr);
if (xQueueReceive(cli_transmit_task_queue, &command_line, portMAX_DELAY) == pdTRUE)
char * cmd = NULL;
if (xQueueReceive(cli_transmit_task_queue, &cmd, portMAX_DELAY) == pdTRUE)
{
if (command_line)
if (cmd)
{
esp_openthread_cli_input(command_line.get());
std::unique_ptr<char[]> cmd_ptr(cmd);
esp_openthread_cli_input(cmd_ptr.get());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/OpenthreadLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
esp_err_t set_openthread_platform_config(esp_openthread_platform_config_t * config);
esp_err_t openthread_init_stack(void);
esp_err_t openthread_launch_task(void);
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> & cli_str);
CHIP_ERROR cli_transmit_task_post(std::unique_ptr<char[]> && cli_str);

0 comments on commit 23b31a7

Please sign in to comment.