add command private data setter/accessor
Presently, commands registration taks a static handler data pointer. This patch adds support for commands that require a dynamic pointer, such as those registered in a dynamic context (e.g. subcommands for a user-created 'foo.cpu' command). The command_set_handler_data will update a command (group) to use a new context pointer, while the CMD_DATA macro allows command handlers to access the value. Jim handlers should find this value in interp->cmdPrivData.
This commit is contained in:
@@ -439,6 +439,14 @@ int unregister_command(struct command_context *context,
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
void command_set_handler_data(struct command *c, void *p)
|
||||
{
|
||||
if (NULL != c->handler || NULL != c->jim_handler)
|
||||
c->jim_handler_data = p;
|
||||
for (struct command *cc = c->children; NULL != cc; cc = cc->next)
|
||||
command_set_handler_data(cc, p);
|
||||
}
|
||||
|
||||
void command_output_text(struct command_context *context, const char *data)
|
||||
{
|
||||
if (context && context->output_handler && data) {
|
||||
|
||||
Reference in New Issue
Block a user