From 933b4579f06d25e349e6648ec4aff114e634164d Mon Sep 17 00:00:00 2001 From: Zachary T Welch Date: Fri, 27 Nov 2009 16:30:28 -0800 Subject: 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. --- src/helper/command.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/helper/command.c') diff --git a/src/helper/command.c b/src/helper/command.c index 61a791dc..b2aa76b0 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) { -- cgit v1.2.3