mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-03 19:41:55 +02:00
feat(console): add command user context support
Current implementation implicitly forces the developer to use global variables to enter its context during the command invocation, this change enables each module to register a context for command to find without the need to manage global variables. No API breakage. Fields added: esp_console_cmd_t::func_w_context - (*)(int argc, char **argv, void *context) Functions added: esp_err_t esp_console_cmd_set_context(const char *cmd, void *context) Usage: esp_console_cmd_register(&cmd)); esp_console_cmd_set_context(cmd.command, (void *)"context")); Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
This commit is contained in:
committed by
Jakob Hasse
parent
142218c2eb
commit
bccb2873bd
@@ -147,7 +147,12 @@ For each command, application provides the following information (in the form of
|
||||
- Command name (string without spaces)
|
||||
- Help text explaining what the command does
|
||||
- Optional hint text listing the arguments of the command. If application uses Argtable3 for argument parsing, hint text can be generated automatically by providing a pointer to argtable argument definitions structure instead.
|
||||
- The command handler function.
|
||||
- Command handler function (without context), or
|
||||
- Command handler function (with context). If this function is given, an additional call to :cpp:func:`esp_console_cmd_set_context` must follow *before* the command may be called to initialize the context.
|
||||
|
||||
.. note::
|
||||
|
||||
You can either use a command handler function which takes a context or a command handler function which does not take a context, not both. If you use the command handler function which takes a context, you MUST call :cpp:func:`esp_console_cmd_set_context` to initialize its context, otherwise the function may access the uninitialized context.
|
||||
|
||||
A few other functions are provided by the command registration module:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user