[svn-commits] russell: trunk r105461 - in /trunk: CHANGES funcs/func_devstate.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 29 18:53:26 CST 2008


Author: russell
Date: Fri Feb 29 18:53:25 2008
New Revision: 105461

URL: http://svn.digium.com/view/asterisk?view=rev&rev=105461
Log:
Add a "devstate change" CLI command to control custom device states.  Also,
do some additional code cleanup and improvement in passing.

(closes issue #12106)
Reported by: nizon
Patches:
      devstate-patch.txt uploaded by nizon (license 415)
        -- Updated to trunk, and tab completion added by me

Modified:
    trunk/CHANGES
    trunk/funcs/func_devstate.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=105461&r1=105460&r2=105461
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri Feb 29 18:53:25 2008
@@ -97,6 +97,9 @@
   * New CLI command: "core set chanvar" to set a channel variable from the CLI.
   * Added an easy way to execute Asterisk CLI commands at startup.  Any commands
     listed in the startup_commands section of cli.conf will get executed.
+  * Added a CLI command, "devstate change", which allows you to set custom device
+     states from the func_devstate module that provides the DEVICE_STATE() function
+     and handling of the "Custom:" devices.
 
 SIP changes
 -----------
@@ -166,7 +169,7 @@
   * Proper codec support in chan_skinny.
   * Added settings for IP and Ethernet QoS requests
 
-MGCP changes
+
 ------------
   * Added separate settings for media QoS in mgcp.conf
 

Modified: trunk/funcs/func_devstate.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_devstate.c?view=diff&rev=105461&r1=105460&r2=105461
==============================================================================
--- trunk/funcs/func_devstate.c (original)
+++ trunk/funcs/func_devstate.c Fri Feb 29 18:53:25 2008
@@ -54,6 +54,7 @@
 static int devstate_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
 	size_t len = strlen("Custom:");
+	enum ast_device_state state_val;
 
 	if (strncasecmp(data, "Custom:", len)) {
 		ast_log(LOG_WARNING, "The DEVICE_STATE function can only be used to set 'Custom:' device state!\n");
@@ -65,9 +66,16 @@
 		return -1;
 	}
 
+	state_val = ast_devstate_val(value);
+
+	if (state_val == AST_DEVICE_UNKNOWN) {
+		ast_log(LOG_ERROR, "DEVICE_STATE function given invalid state value '%s'\n", value);
+		return -1;
+	}
+
 	ast_db_put(astdb_family, data, value);
 
-	ast_devstate_changed(ast_devstate_val(value), "Custom:%s", data);
+	ast_devstate_changed(state_val, "Custom:%s", data);
 
 	return 0;
 }
@@ -215,9 +223,73 @@
 	return CLI_SUCCESS;
 }
 
+static char *handle_cli_devstate_change(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+    size_t len;
+	const char *dev, *state;
+	enum ast_device_state state_val;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "devstate change";
+		e->usage =
+			"Usage: devstate change <device> <state>\n"
+			"       Change a custom device to a new state.\n"
+			"       The possible values for the state are:\n"
+			"UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING\n"
+			"RINGINUSE | ONHOLD\n",
+			"\n"
+			"Examples:\n"
+			"       devstate change Custom:mystate1 INUSE\n"
+			"       devstate change Custom:mystate1 NOT_INUSE\n"
+			"       \n";
+		return NULL;
+	case CLI_GENERATE:
+	{
+		static char * const cmds[] = { "UNKNOWN", "NOT_INUSE", "INUSE", "BUSY",
+			"UNAVAILALBE", "RINGING", "RINGINUSE", "ONHOLD", NULL };
+
+		if (a->pos == e->args + 1)
+			return ast_cli_complete(a->word, cmds, a->n);
+
+		return NULL;
+	}
+	}
+
+	if (a->argc != e->args + 2)
+		return CLI_SHOWUSAGE;
+
+	len = strlen("Custom:");
+	dev = a->argv[e->args];
+	state = a->argv[e->args + 1];
+
+	if (strncasecmp(dev, "Custom:", len)) {
+		ast_cli(a->fd, "The devstate command can only be used to set 'Custom:' device state!\n");
+		return CLI_FAILURE;
+	}
+
+	dev += len;
+	if (ast_strlen_zero(dev))
+		return CLI_SHOWUSAGE;
+
+	state_val = ast_devstate_val(state);
+
+	if (state_val == AST_DEVICE_UNKNOWN)
+		return CLI_SHOWUSAGE;
+
+	ast_cli(a->fd, "Changing %s to %s\n", dev, state);
+
+	ast_db_put(astdb_family, dev, state);
+
+	ast_devstate_changed(state_val, "Custom:%s", dev);
+
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cli_funcdevstate_list_deprecated = AST_CLI_DEFINE(handle_cli_funcdevstate_list, "List currently known custom device states");
 static struct ast_cli_entry cli_funcdevstate[] = {
 	AST_CLI_DEFINE(handle_cli_devstate_list, "List currently known custom device states", .deprecate_cmd = &cli_funcdevstate_list_deprecated),
+	AST_CLI_DEFINE(handle_cli_devstate_change, "Change a custom device state"),
 };
 
 static struct ast_custom_function devstate_function = {




More information about the svn-commits mailing list