int register_commands(struct command_context *cmd_ctx, struct command *parent,
	const struct command_registration *cmds)
{
	int retval = ERROR_OK;
	unsigned i;
	for (i = 0; cmds[i].name || cmds[i].chain; i++) {
		const struct command_registration *cr = cmds + i;

		struct command *c = NULL;
		if (NULL != cr->name) {
			c = register_command(cmd_ctx, parent, cr);
			if (NULL == c) {
				retval = ERROR_FAIL;
				break;
			}
		}
		if (NULL != cr->chain) {
			struct command *p = c ? : parent;
			retval = register_commands(cmd_ctx, p, cr->chain);
			if (ERROR_OK != retval)
				break;
		}
	}
	if (ERROR_OK != retval) {
		for (unsigned j = 0; j < i; j++)
			unregister_command(cmd_ctx, parent, cmds[j].name);
	}
	return retval;
}
struct command *register_command(struct command_context *context,
	struct command *parent, const struct command_registration *cr)
{
	if (!context || !cr->name)
		return NULL;

	const char *name = cr->name;
	struct command **head = command_list_for_parent(context, parent);
	struct command *c = command_find(*head, name);
	if (NULL != c) {
		/* TODO: originally we treated attempting to register a cmd twice as an error
		 * Sometimes we need this behaviour, such as with flash banks.
		 * http://www.mail-archive.com/[email protected]/msg11152.html */
		LOG_DEBUG("command '%s' is already registered in '%s' context",
			name, parent ? parent->name : "<global>");
		return c;
	}

	c = command_new(context, parent, cr);
	if (NULL == c)
		return NULL;

	int retval = ERROR_OK;
	if (NULL != cr->jim_handler && NULL == parent) {
		retval = Jim_CreateCommand(context->interp, cr->name,
				cr->jim_handler, cr->jim_handler_data, NULL);
	} else if (NULL != cr->handler || NULL != parent)
		retval = register_command_handler(context, command_root(c));

	if (ERROR_OK != retval) {
		unregister_command(context, parent, name);
		c = NULL;
	}
	return c;
}
Exemple #3
0
static __exit void cd_cmd_exit(void)
{
	unregister_command(&cmd_cd);
}
Exemple #4
0
static __exit void reboot_cmd_exit(void)
{
	unregister_command(&cmd_reboot);
}
Exemple #5
0
static __exit void memtest_cmd_exit(void)
{
	unregister_command(&cmd_memtest);
}
Exemple #6
0
static __exit void sync_cmd_exit(void)
{
	unregister_command(&cmd_sync);
}
Exemple #7
0
static __exit void rm_cmd_exit(void)
{
	unregister_command(&cmd_rm);
}
Exemple #8
0
static __exit void maskrom_cmd_exit(void)
{
	unregister_command(&cmd_maskrom);
}
Exemple #9
0
static __exit void fileram_cmd_exit(void)
{
	unregister_command(&cmd_fileram);
}
Exemple #10
0
static __exit void poweroff_cmd_exit(void)
{
	unregister_command(&cmd_poweroff);
}
Exemple #11
0
static __exit void echo_cmd_exit(void)
{
	unregister_command(&cmd_echo);
}
Exemple #12
0
static __exit void write_cmd_exit(void)
{
	unregister_command(&cmd_write);
}
Exemple #13
0
static __exit void go_cmd_exit(void)
{
	unregister_command(&cmd_go);
}
Exemple #14
0
static __exit void delay_cmd_exit(void)
{
	unregister_command(&cmd_delay);
}
Exemple #15
0
static __exit void mw_cmd_exit(void)
{
	unregister_command(&cmd_mw);
}