diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-11-27 16:30:28 -0800 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-28 13:00:39 -0800 |
commit | 933b4579f06d25e349e6648ec4aff114e634164d (patch) | |
tree | 95bf31e87606d3790294cc2b22d5816d44c0e9a3 /src/helper/command.c | |
parent | 3b5751a4d4aa4eb980aee6931b7d100a6d37224a (diff) | |
download | riscv-openocd-933b4579f06d25e349e6648ec4aff114e634164d.zip riscv-openocd-933b4579f06d25e349e6648ec4aff114e634164d.tar.gz riscv-openocd-933b4579f06d25e349e6648ec4aff114e634164d.tar.bz2 |
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.
Diffstat (limited to 'src/helper/command.c')
-rw-r--r-- | src/helper/command.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 61a791d..b2aa76b 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -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) { |