summaryrefslogtreecommitdiff
path: root/src/helper/command.h
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-27 16:30:28 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-28 13:00:39 -0800
commit933b4579f06d25e349e6648ec4aff114e634164d (patch)
tree95bf31e87606d3790294cc2b22d5816d44c0e9a3 /src/helper/command.h
parent3b5751a4d4aa4eb980aee6931b7d100a6d37224a (diff)
downloadopenocd+libswd-933b4579f06d25e349e6648ec4aff114e634164d.tar.gz
openocd+libswd-933b4579f06d25e349e6648ec4aff114e634164d.tar.bz2
openocd+libswd-933b4579f06d25e349e6648ec4aff114e634164d.tar.xz
openocd+libswd-933b4579f06d25e349e6648ec4aff114e634164d.zip
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.h')
-rw-r--r--src/helper/command.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/helper/command.h b/src/helper/command.h
index 84bdb71e..2d334846 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -80,6 +80,8 @@ struct command_context
void *output_handler_priv;
};
+struct command;
+
/**
* When run_command is called, a new instance will be created on the
* stack, filled with the proper values, and passed by reference to the
@@ -87,6 +89,7 @@ struct command_context
*/
struct command_invocation {
struct command_context *ctx;
+ struct command *current;
const char *name;
unsigned argc;
const char **argv;
@@ -151,6 +154,16 @@ struct command_invocation {
* rather than accessing the variable directly. It may be moved.
*/
#define CMD_NAME cmd->name
+/**
+ * Use this macro to access the current command being handled,
+ * rather than accessing the variable directly. It may be moved.
+ */
+#define CMD_CURRENT cmd->current
+/**
+ * Use this macro to access the invoked command handler's data pointer,
+ * rather than accessing the variable directly. It may be moved.
+ */
+#define CMD_DATA CMD_CURRENT->jim_handler_data
/// The type signature for commands' handler functions.
@@ -290,6 +303,16 @@ struct command *command_find_in_context(struct command_context *cmd_ctx,
struct command *command_find_in_parent(struct command *parent,
const char *name);
+/**
+ * Update the private command data field for a command and all descendents.
+ * This is used when creating a new heirarchy of commands that depends
+ * on obtaining a dynamically created context. The value will be available
+ * in command handlers by using the CMD_DATA macro.
+ * @param c The command (group) whose data pointer(s) will be updated.
+ * @param p The new data pointer to use for the command or its descendents.
+ */
+void command_set_handler_data(struct command *c, void *p);
+
void command_set_output_handler(struct command_context* context,
command_output_handler_t output_handler, void *priv);