[svn-commits] mmichelson: branch group/CCSS r247900 - /team/group/CCSS/main/ccss.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 19 10:16:11 CST 2010


Author: mmichelson
Date: Fri Feb 19 10:16:08 2010
New Revision: 247900

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247900
Log:
Add CLI command to cancel CC requests.


Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=247900&r1=247899&r2=247900
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Fri Feb 19 10:16:08 2010
@@ -3965,8 +3965,63 @@
 	return CLI_SUCCESS;
 }
 
+static int kill_cores(void *obj, void *arg, int flags)
+{
+	int *core_id = arg;
+	struct cc_core_instance *core_instance = obj;
+
+	if (!core_id || (core_instance->core_id == *core_id)) {
+		ast_cc_failed(core_instance->core_id, "CC transaction canceled administratively\n");
+	}
+	return 0;
+}
+
+static char *handle_cc_kill(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	static const char * const option[] = { "core", "all", NULL };
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "cc cancel";
+		e->usage =
+			"Usage: cc cancel can be used in two ways.\n"
+			"       1. 'cc cancel core [core ID]' will cancel the CC transaction with\n"
+			"          core ID equal to the specified core ID.\n"
+			"       2. 'cc cancel all' will cancel all active CC transacitons.\n";
+		return NULL;
+	case CLI_GENERATE:
+		if (a->pos == 2) {
+			return ast_cli_complete(a->word, option, a->n);
+		}
+		return NULL;
+	}
+
+	if (a->argc == 4) {
+		int core_id;
+		char *endptr;
+		if (strcasecmp(a->argv[2], "core")) {
+			return CLI_SHOWUSAGE;
+		}
+		core_id = strtol(a->argv[3], &endptr, 10);
+		if ((errno != 0 && core_id == 0) || (endptr == a->argv[3])) {
+			return CLI_SHOWUSAGE;
+		}
+		ao2_t_callback(cc_core_instances, OBJ_NODATA, kill_cores, &core_id, "CLI Killing Core Id");
+	} else if (a->argc == 3) {
+		if (strcasecmp(a->argv[2], "all")) {
+			return CLI_SHOWUSAGE;
+		}
+		ao2_t_callback(cc_core_instances, OBJ_NODATA, kill_cores, NULL, "CLI Killing all CC cores");
+	} else {
+		return CLI_SHOWUSAGE;
+	}
+	
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cc_cli[] = {
 	AST_CLI_DEFINE(handle_cc_status, "Reports CC stats"),
+	AST_CLI_DEFINE(handle_cc_kill, "Kill a CC transaction"),
 };
 
 int ast_cc_init(void)




More information about the svn-commits mailing list