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:
Zachary T Welch
2009-11-27 16:30:28 -08:00
parent 3b5751a4d4
commit 933b4579f0
2 changed files with 31 additions and 0 deletions

View File

@@ -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) {