[asterisk-commits] file: trunk r53113 - /trunk/main/devicestate.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 1 17:58:09 MST 2007


Author: file
Date: Thu Feb  1 18:58:09 2007
New Revision: 53113

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53113
Log:
Clean up ast_device_state. It's pretty now!

Modified:
    trunk/main/devicestate.c

Modified: trunk/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/trunk/main/devicestate.c?view=diff&rev=53113&r1=53112&r2=53113
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Thu Feb  1 18:58:09 2007
@@ -226,10 +226,8 @@
 	
 	buf = ast_strdupa(device);
 	tech = strsep(&buf, "/");
-	number = buf;
-	if (!number) {
-		provider = strsep(&tech, ":");
-		if (!provider)
+	if (!(number = buf)) {
+		if (!(provider = strsep(&tech, ":")))
 			return AST_DEVICE_INVALID;
 		/* We have a provider */
 		number = tech;
@@ -241,29 +239,27 @@
 			ast_log(LOG_DEBUG, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
 		return getproviderstate(provider, number);
 	}
+
 	if (option_debug > 3)
 		ast_log(LOG_DEBUG, "No provider found, checking channel drivers for %s - %s\n", tech, number);
 
-	chan_tech = ast_get_channel_tech(tech);
-	if (!chan_tech)
+	if (!(chan_tech = ast_get_channel_tech(tech)))
 		return AST_DEVICE_INVALID;
 
-	if (!chan_tech->devicestate) 	/* Does the channel driver support device state notification? */
-		return ast_parse_device_state(device);	/* No, try the generic function */
-	else {
-		res = chan_tech->devicestate(number);	/* Ask the channel driver for device state */
-		if (res == AST_DEVICE_UNKNOWN) {
-			res = ast_parse_device_state(device);
-			/* at this point we know the device exists, but the channel driver
-			   could not give us a state; if there is no channel state available,
-			   it must be 'not in use'
-			*/
-			if (res == AST_DEVICE_UNKNOWN)
-				res = AST_DEVICE_NOT_INUSE;
-			return res;
-		} else
-			return res;
-	}
+	if (!(chan_tech->devicestate)) /* Does the channel driver support device state notification? */
+		return ast_parse_device_state(device); /* No, try the generic function */
+
+	res = chan_tech->devicestate(number);
+
+	if (res != AST_DEVICE_UNKNOWN)
+		return res;
+
+	res = ast_parse_device_state(device);
+
+	if (res == AST_DEVICE_UNKNOWN)
+		return AST_DEVICE_NOT_INUSE;
+
+	return res;
 }
 
 /*! \brief Add device state provider */
@@ -388,8 +384,6 @@
 	device = buf;
 	if ((tmp = strrchr(device, '-')))
 		*tmp = '\0';
-
-	
 
 	if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
 		/* we could not allocate a change struct, or */



More information about the asterisk-commits mailing list