summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-20 12:46:06 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-24 21:37:29 -0800
commit2461855494cd045567c15c502ba215caffb37ce3 (patch)
treea27f0d9ca53237d7839d25711bd0a786b00d6415 /src
parent69076057dde9f4336b54fb4da677da8fe5da66bd (diff)
downloadopenocd+libswd-2461855494cd045567c15c502ba215caffb37ce3.tar.gz
openocd+libswd-2461855494cd045567c15c502ba215caffb37ce3.tar.bz2
openocd+libswd-2461855494cd045567c15c502ba215caffb37ce3.tar.xz
openocd+libswd-2461855494cd045567c15c502ba215caffb37ce3.zip
add register_commands for batch registration
The register_commands API takes multiple commands in one call, allowing modules to declare and pass a much simpler (and more explicit) array of command_registration records.
Diffstat (limited to 'src')
-rw-r--r--src/helper/command.c17
-rw-r--r--src/helper/command.h19
2 files changed, 36 insertions, 0 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 3df60b65..51b3f9f5 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -302,6 +302,23 @@ struct command* register_command(struct command_context *context,
return c;
}
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+ const struct command_registration *cmds)
+{
+ unsigned i;
+ for (i = 0; cmds[i].name; i++)
+ {
+ struct command *c = register_command(cmd_ctx, parent, cmds + i);
+ if (NULL != c)
+ continue;
+
+ for (unsigned j = 0; j < i; j++)
+ unregister_command(cmd_ctx, parent, cmds[j].name);
+ return ERROR_FAIL;
+ }
+ return ERROR_OK;
+}
+
int unregister_all_commands(struct command_context *context,
struct command *parent)
{
diff --git a/src/helper/command.h b/src/helper/command.h
index b57ca75d..1afaeeaa 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -201,6 +201,9 @@ struct command_registration {
const char *help;
};
+/// Use this as the last entry in an array of command_registration records.
+#define COMMAND_REGISTRATION_DONE { .name = NULL }
+
/**
* Register a command @c handler that can be called from scripts during
* the execution @c mode specified.
@@ -231,6 +234,22 @@ struct command* register_command(struct command_context *cmd_ctx,
})
/**
+ * Register one or more commands in the specified context, as children
+ * of @c parent (or top-level commends, if NULL).
+ *
+ * @param cmd_ctx The command_context in which to register the command.
+ * @param parent Register this command as a child of this, or NULL to
+ * register a top-level command.
+ * @param cmds Pointer to an array of command_registration records that
+ * contains the desired command parameters. The last record must have
+ * NULL for all fields.
+ * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
+ */
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+ const struct command_registration *cmds);
+
+
+/**
* Unregisters command @c name from the given context, @c cmd_ctx.
* @param cmd_ctx The context of the registered command.
* @param parent The parent of the given command, or NULL.