[svn-commits] dvossel: branch 1.6.0 r204754 - in /branches/1.6.0: ./ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 2 13:07:40 CDT 2009


Author: dvossel
Date: Thu Jul  2 13:07:35 2009
New Revision: 204754

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=204754
Log:
Merged revisions 204710 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r204710 | dvossel | 2009-07-02 11:03:44 -0500 (Thu, 02 Jul 2009) | 21 lines
  
  Merged revisions 204681 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r204681 | dvossel | 2009-07-02 10:05:57 -0500 (Thu, 02 Jul 2009) | 14 lines
    
    Improved mapping of extension states from combined device states.
    
    This fixes a few issues with incorrect extension states and adds
    a cli command, core show device2extenstate, to display all possible
    state mappings.
    
    (closes issue #15413)
    Reported by: legart
    Patches:
          exten_helper.diff uploaded by dvossel (license 671)
    Tested by: dvossel, legart, amilcar
    
    Review: https://reviewboard.asterisk.org/r/301/
  ........
................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/include/asterisk/devicestate.h
    branches/1.6.0/main/devicestate.c
    branches/1.6.0/main/pbx.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/include/asterisk/devicestate.h
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.0/include/asterisk/devicestate.h?view=diff&rev=204754&r1=204753&r2=204754
==============================================================================
--- branches/1.6.0/include/asterisk/devicestate.h (original)
+++ branches/1.6.0/include/asterisk/devicestate.h Thu Jul  2 13:07:35 2009
@@ -56,6 +56,7 @@
 	AST_DEVICE_RINGING,      /*!< Device is ringing */
 	AST_DEVICE_RINGINUSE,    /*!< Device is ringing *and* in use */
 	AST_DEVICE_ONHOLD,       /*!< Device is on hold */
+	AST_DEVICE_TOTAL,        /*/ Total num of device states, used for testing */
 };
 
 /*! \brief Devicestate provider call back */
@@ -175,6 +176,64 @@
  */
 int ast_device_state_changed_literal(const char *device);
 
+/*!
+ * \brief An object to hold state when calculating aggregate device state
+ */
+struct ast_devstate_aggregate;
+
+/*!
+ * \brief Initialize aggregate device state
+ *
+ * \param[in] agg the state object
+ *
+ * \return nothing
+ */
+void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg);
+
+/*!
+ * \brief Add a device state to the aggregate device state
+ *
+ * \param[in] agg the state object
+ * \param[in] state the state to add
+ *
+ * \return nothing
+ */
+void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state);
+
+/*!
+ * \brief Get the aggregate device state result
+ *
+ * \param[in] agg the state object
+ *
+ * \return the aggregate device state after adding some number of device states.
+ */
+enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg);
+
+/*!
+ * \brief Map devstate to an extension state.
+ *
+ * \param[in] device state
+ *
+ * \return the extension state mapping.
+ */
+enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate);
+
+/*!
+ * \brief You shouldn't care about the contents of this struct
+ *
+ * This struct is only here so that it can be easily declared on the stack.
+ */
+struct ast_devstate_aggregate {
+	unsigned int all_unavail:1;
+	unsigned int all_busy:1;
+	unsigned int all_free:1;
+	unsigned int all_unknown:1;
+	unsigned int on_hold:1;
+	unsigned int busy:1;
+	unsigned int in_use:1;
+	unsigned int ring:1;
+};
+
 /*! 
  * \brief Add device state provider 
  *

Modified: branches/1.6.0/main/devicestate.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.0/main/devicestate.c?view=diff&rev=204754&r1=204753&r2=204754
==============================================================================
--- branches/1.6.0/main/devicestate.c (original)
+++ branches/1.6.0/main/devicestate.c Thu Jul  2 13:07:35 2009
@@ -210,6 +210,8 @@
 		break;
 	case AST_DEVICE_ONHOLD:
 		res = "ONHOLD";
+		break;
+	case AST_DEVICE_TOTAL: /* included only for completeness */
 		break;
 	}
 
@@ -533,3 +535,118 @@
 
 	return 0;
 }
+
+void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
+{
+	memset(agg, 0, sizeof(*agg));
+
+	agg->all_unknown = 1;
+	agg->all_unavail = 1;
+	agg->all_busy = 1;
+	agg->all_free = 1;
+}
+
+void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
+{
+	switch (state) {
+	case AST_DEVICE_NOT_INUSE:
+		agg->all_unknown = 0;
+		agg->all_unavail = 0;
+		agg->all_busy = 0;
+		break;
+	case AST_DEVICE_INUSE:
+		agg->in_use = 1;
+		agg->all_unavail = 0;
+		agg->all_free = 0;
+		agg->all_unknown = 0;
+		break;
+	case AST_DEVICE_RINGING:
+		agg->ring = 1;
+		agg->all_unavail = 0;
+		agg->all_free = 0;
+		agg->all_unknown = 0;
+		break;
+	case AST_DEVICE_RINGINUSE:
+		agg->in_use = 1;
+		agg->ring = 1;
+		agg->all_unavail = 0;
+		agg->all_free = 0;
+		agg->all_unknown = 0;
+		break;
+	case AST_DEVICE_ONHOLD:
+		agg->all_unknown = 0;
+		agg->all_unavail = 0;
+		agg->all_free = 0;
+		agg->on_hold = 1;
+		break;
+	case AST_DEVICE_BUSY:
+		agg->all_unknown = 0;
+		agg->all_unavail = 0;
+		agg->all_free = 0;
+		agg->busy = 1;
+		agg->in_use = 1;
+		break;
+	case AST_DEVICE_UNAVAILABLE:
+		agg->all_unknown = 0;
+	case AST_DEVICE_INVALID:
+		agg->all_busy = 0;
+		agg->all_free = 0;
+		break;
+	case AST_DEVICE_UNKNOWN:
+		agg->all_busy = 0;
+		agg->all_free = 0;
+		break;
+	case AST_DEVICE_TOTAL: /* not a device state, included for completeness. */
+		break;
+	}
+}
+
+enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate)
+{
+	switch (devstate) {
+	case AST_DEVICE_ONHOLD:
+		return AST_EXTENSION_ONHOLD;
+	case AST_DEVICE_BUSY:
+		return AST_EXTENSION_BUSY;
+	case AST_DEVICE_UNAVAILABLE:
+	case AST_DEVICE_UNKNOWN:
+	case AST_DEVICE_INVALID:
+		return AST_EXTENSION_UNAVAILABLE;
+	case AST_DEVICE_RINGINUSE:
+		return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
+	case AST_DEVICE_RINGING:
+		return AST_EXTENSION_RINGING;
+	case AST_DEVICE_INUSE:
+		return AST_EXTENSION_INUSE;
+	case AST_DEVICE_NOT_INUSE:
+		return AST_EXTENSION_NOT_INUSE;
+	case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
+		break;
+	}
+
+	return AST_EXTENSION_NOT_INUSE;
+}
+
+enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
+{
+	if (agg->all_free)
+		return AST_DEVICE_NOT_INUSE;
+	if ((agg->in_use || agg->on_hold) && agg->ring)
+		return AST_DEVICE_RINGINUSE;
+	if (agg->ring)
+		return AST_DEVICE_RINGING;
+	if (agg->busy)
+		return AST_DEVICE_BUSY;
+	if (agg->in_use)
+		return AST_DEVICE_INUSE;
+	if (agg->on_hold)
+		return AST_DEVICE_ONHOLD;
+	if (agg->all_busy)
+		return AST_DEVICE_BUSY;
+	if (agg->all_unknown)
+		return AST_DEVICE_UNKNOWN;
+	if (agg->all_unavail)
+		return AST_DEVICE_UNAVAILABLE;
+
+	return AST_DEVICE_NOT_INUSE;
+}

Modified: branches/1.6.0/main/pbx.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.0/main/pbx.c?view=diff&rev=204754&r1=204753&r2=204754
==============================================================================
--- branches/1.6.0/main/pbx.c (original)
+++ branches/1.6.0/main/pbx.c Thu Jul  2 13:07:35 2009
@@ -3177,8 +3177,7 @@
 {
 	char hint[AST_MAX_EXTENSION];
 	char *cur, *rest;
-	int allunavailable = 1, allbusy = 1, allfree = 1;
-	int busy = 0, inuse = 0, ring = 0, onhold = 0;
+	struct ast_devstate_aggregate agg;
 
 	if (!e)
 		return -1;
@@ -3187,67 +3186,10 @@
 
 	rest = hint;	/* One or more devices separated with a & character */
 	while ( (cur = strsep(&rest, "&")) ) {
-		int res = ast_device_state(cur);
-		switch (res) {
-		case AST_DEVICE_NOT_INUSE:
-			allunavailable = 0;
-			allbusy = 0;
-			break;
-		case AST_DEVICE_INUSE:
-			inuse = 1;
-			allunavailable = 0;
-			allfree = 0;
-			break;
-		case AST_DEVICE_RINGING:
-			ring = 1;
-			allunavailable = 0;
-			allfree = 0;
-			break;
-		case AST_DEVICE_RINGINUSE:
-			inuse = 1;
-			ring = 1;
-			allunavailable = 0;
-			allfree = 0;
-			break;
-		case AST_DEVICE_ONHOLD:
-			allunavailable = 0;
-			allfree = 0;
-			onhold = 1;
-			break;
-		case AST_DEVICE_BUSY:
-			allunavailable = 0;
-			allfree = 0;
-			busy = 1;
-			inuse = 1;
-			break;
-		case AST_DEVICE_UNAVAILABLE:
-		case AST_DEVICE_INVALID:
-			allbusy = 0;
-			allfree = 0;
-			break;
-		default:
-			allunavailable = 0;
-			allbusy = 0;
-			allfree = 0;
-		}
-	}
-
-	if (allfree)
-		return AST_EXTENSION_NOT_INUSE;
-	if ((inuse || onhold) && ring)
-		return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
-	if (allbusy)
-		return AST_EXTENSION_BUSY;
-	if (inuse)
-		return AST_EXTENSION_INUSE;
-	if (ring)
-		return AST_EXTENSION_RINGING;
-	if (onhold)
-		return AST_EXTENSION_ONHOLD;
-	if (allunavailable)
-		return AST_EXTENSION_UNAVAILABLE;
-
-	return AST_EXTENSION_NOT_INUSE;
+		ast_devstate_aggregate_add(&agg, ast_device_state(cur));
+	}
+
+	return ast_devstate_to_extenstate(ast_devstate_aggregate_result(&agg));
 }
 
 /*! \brief Return extension_state as string */
@@ -5420,6 +5362,36 @@
 	return CLI_SUCCESS;
 }
 
+#ifdef AST_DEVMODE
+static char *handle_show_device2extenstate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_devstate_aggregate agg;
+	int i, j, exten, combined;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "core show device2extenstate";
+		e->usage =
+			"Usage: core show device2extenstate\n"
+			"       Lists device state to extension state combinations.\n";
+	case CLI_GENERATE:
+		return NULL;
+	}
+	for (i = 0; i < AST_DEVICE_TOTAL; i++) {
+		for (j = 0; j < AST_DEVICE_TOTAL; j++) {
+			ast_devstate_aggregate_init(&agg);
+			ast_devstate_aggregate_add(&agg, i);
+			ast_devstate_aggregate_add(&agg, j);
+			combined = ast_devstate_aggregate_result(&agg);
+			exten = ast_devstate_to_extenstate(combined);
+			ast_cli(a->fd, "\n Exten:%14s  CombinedDevice:%12s  Dev1:%12s  Dev2:%12s", ast_extension_state2str(exten), ast_devstate_str(combined), ast_devstate_str(j), ast_devstate_str(i));
+		}
+	}
+	ast_cli(a->fd, "\n");
+	return CLI_SUCCESS;
+}
+#endif
+
 static char *handle_set_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_channel *chan;
@@ -5524,6 +5496,9 @@
 	AST_CLI_DEFINE(handle_show_hints, "Show dialplan hints"),
 	AST_CLI_DEFINE(handle_show_hint, "Show dialplan hint"),
 	AST_CLI_DEFINE(handle_show_globals, "Show global dialplan variables"),
+#ifdef AST_DEVMODE
+	AST_CLI_DEFINE(handle_show_device2extenstate, "Show expected exten state from multiple device states"),
+#endif
 	AST_CLI_DEFINE(handle_show_function, "Describe a specific dialplan function"),
 	AST_CLI_DEFINE(handle_show_application, "Describe a specific dialplan application"),
 	AST_CLI_DEFINE(handle_set_global, "Set global dialplan variable"),




More information about the svn-commits mailing list