summaryrefslogtreecommitdiff
path: root/src/helper/command.h
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-20 11:23:34 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-24 21:37:29 -0800
commit69076057dde9f4336b54fb4da677da8fe5da66bd (patch)
tree839cc6881d7a8ed26c82635b640ebc9fe93c98ad /src/helper/command.h
parent833e7f5248778bcb31b4db1a1b91160995415203 (diff)
downloadopenocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.gz
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.bz2
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.xz
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.zip
add struct command_registration
Add a structure to encapsulate command registration information, rather than passing them all as parameters. Enables further API changes that require additional required or optional parameters. Updates the register_command API and COMMAND_REGISTER macro to use it, along with their documentation.
Diffstat (limited to 'src/helper/command.h')
-rw-r--r--src/helper/command.h51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/helper/command.h b/src/helper/command.h
index 25c05011..b57ca75d 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -177,13 +177,9 @@ struct command
*/
char *command_name(struct command *c, char delim);
-/**
- * Register a command @c handler that can be called from scripts during
- * the execution @c mode specified.
- *
- * If @c parent is non-NULL, the new command will be registered as a
- * sub-command under it; otherwise, it will be available as a top-level
- * command.
+/*
+ * Commands should be registered by filling in one or more of these
+ * structures and passing them to register_command().
*
* A conventioal format should be used for help strings, to provide both
* usage and basic information:
@@ -191,25 +187,48 @@ char *command_name(struct command *c, char delim);
* "@<options@> ... - some explanation text"
* @endcode
*
- * @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 name The name of the command to register, which must not have
- * been registered previously.
+ * been registered previously in the intended context.
* @param handler The callback function that will be called. If NULL,
* then the command serves as a placeholder for its children or a script.
* @param mode The command mode(s) in which this command may be run.
* @param help The help text that will be displayed to the user.
+ */
+struct command_registration {
+ const char *name;
+ command_handler_t handler;
+ enum command_mode mode;
+ const char *help;
+};
+
+/**
+ * Register a command @c handler that can be called from scripts during
+ * the execution @c mode specified.
+ *
+ * If @c parent is non-NULL, the new command will be registered as a
+ * sub-command under it; otherwise, it will be available as a top-level
+ * command.
+ *
+ * @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 rec A command_registration record that contains the desired
+ * command parameters.
* @returns The new command, if successful; otherwise, NULL.
*/
struct command* register_command(struct command_context *cmd_ctx,
- struct command *parent, const char *name,
- command_handler_t handler, enum command_mode mode,
- const char *help);
+ struct command *parent, const struct command_registration *rec);
-// provide a simple shim, for now; allows parameters to be migrated
#define COMMAND_REGISTER(_cmd_ctx, _parent, _name, _handler, _mode, _help) \
- register_command(_cmd_ctx, _parent, _name, _handler, _mode, _help)
+ ({ \
+ struct command_registration cr = { \
+ .name = _name, \
+ .handler = _handler, \
+ .mode = _mode, \
+ .help = _help, \
+ }; \
+ register_command(_cmd_ctx, _parent, &cr); \
+ })
/**
* Unregisters command @c name from the given context, @c cmd_ctx.