shell: Add warning about not initialized backend

Shell will display a warning message if there was a request to print
a message on the not initialized shell backend.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordisemi.no>
This commit is contained in:
Jakub Rzeszutko 2020-08-03 15:12:17 +02:00 committed by Anas Nashif
commit dac8728856
3 changed files with 20 additions and 1 deletions

View file

@ -25,6 +25,8 @@
#endif
#define SHELL_MSG_CMD_NOT_FOUND ": command not found"
#define SHELL_MSG_BACKEND_NOT_ACTIVE \
"WARNING: A print request was detected on not active shell backend.\n"
#define SHELL_INIT_OPTION_PRINTER (NULL)
@ -85,6 +87,11 @@ static void state_set(const struct shell *shell, enum shell_state state)
if (state == SHELL_STATE_ACTIVE) {
cmd_buffer_clear(shell);
if (flag_print_noinit_get(shell)) {
shell_internal_fprintf(shell, SHELL_WARNING, "%s",
SHELL_MSG_BACKEND_NOT_ACTIVE);
flag_print_noinit_set(shell, false);
}
shell_print_prompt_and_cmd(shell);
}
}
@ -1354,6 +1361,7 @@ void shell_vfprintf(const struct shell *shell, enum shell_vt100_color color,
/* Sending a message to a non-active shell leads to a dead lock. */
if (shell->ctx->state != SHELL_STATE_ACTIVE) {
flag_print_noinit_set(shell, true);
return;
}

View file

@ -151,6 +151,16 @@ static inline void flag_last_nl_set(const struct shell *shell, uint8_t val)
shell->ctx->internal.flags.last_nl = val;
}
static inline bool flag_print_noinit_get(const struct shell *shell)
{
return shell->ctx->internal.flags.print_noinit == 1 ? true : false;
}
static inline void flag_print_noinit_set(const struct shell *shell, bool val)
{
shell->ctx->internal.flags.print_noinit = val ? 1 : 0;
}
void shell_op_cursor_vert_move(const struct shell *shell, int32_t delta);
void shell_op_cursor_horiz_move(const struct shell *shell, int32_t delta);