]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 204710 via svnmerge from
authorDavid Vossel <dvossel@digium.com>
Thu, 2 Jul 2009 16:28:29 +0000 (16:28 +0000)
committerDavid Vossel <dvossel@digium.com>
Thu, 2 Jul 2009 16:28:29 +0000 (16:28 +0000)
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/
  ........
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@204736 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/devicestate.h
main/devicestate.c
main/pbx.c

index dbd513fecfb140f927f7469cd5558eba7a2756fb..a88546ff9cfa316f87fa534273b9306840e2cbac 100644 (file)
@@ -58,6 +58,7 @@ enum ast_device_state {
        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 */
@@ -246,6 +247,15 @@ void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_dev
  */
 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
  *
index 4013d0d7f4e28430aef23890d2cd065bf484a13f..097ee714f99714e2a9ac138ecc2e3f505d4e853d 100644 (file)
@@ -254,6 +254,8 @@ const char *ast_devstate_str(enum ast_device_state state)
        case AST_DEVICE_ONHOLD:
                res = "ONHOLD";
                break;
+       case AST_DEVICE_TOTAL:
+               break;
        }
 
        return res;
@@ -774,14 +776,12 @@ void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_dev
                break;
        case AST_DEVICE_INUSE:
                agg->in_use = 1;
-               agg->all_busy = 0;
                agg->all_unavail = 0;
                agg->all_free = 0;
                agg->all_unknown = 0;
                break;
        case AST_DEVICE_RINGING:
                agg->ring = 1;
-               agg->all_busy = 0;
                agg->all_unavail = 0;
                agg->all_free = 0;
                agg->all_unknown = 0;
@@ -789,7 +789,6 @@ void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_dev
        case AST_DEVICE_RINGINUSE:
                agg->in_use = 1;
                agg->ring = 1;
-               agg->all_busy = 0;
                agg->all_unavail = 0;
                agg->all_free = 0;
                agg->all_unknown = 0;
@@ -814,43 +813,60 @@ void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_dev
                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_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
+enum ast_extension_states ast_devstate_to_extenstate(enum ast_device_state devstate)
 {
-       if (agg->all_unknown) {
-               return AST_DEVICE_UNKNOWN;
+       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;
        }
 
-       if (agg->all_free) {
-               return AST_DEVICE_NOT_INUSE;
-       }
+       return AST_EXTENSION_NOT_INUSE;
+}
 
-       if ((agg->in_use || agg->on_hold) && agg->ring) {
+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->all_busy) {
+       if (agg->ring)
+               return AST_DEVICE_RINGING;
+       if (agg->busy)
                return AST_DEVICE_BUSY;
-       }
-
-       if (agg->in_use) {
+       if (agg->in_use)
                return AST_DEVICE_INUSE;
-       }
-
-       if (agg->ring) {
-               return AST_DEVICE_RINGING;
-       }
-
-       if (agg->on_hold) {
+       if (agg->on_hold)
                return AST_DEVICE_ONHOLD;
-       }
-
-       if (agg->all_unavail) {
+       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;
 }
index 5734241f1c1a0c916eb1625af121c9d90b0abddd..45a999645fc6f33c23ecebd8a07f3a92999f30da 100644 (file)
@@ -22,7 +22,6 @@
  *
  * \author Mark Spencer <markster@digium.com>
  */
-
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -3263,7 +3262,6 @@ static int ast_extension_state2(struct ast_exten *e)
        char hint[AST_MAX_EXTENSION] = "";
        char *cur, *rest;
        struct ast_devstate_aggregate agg;
-       enum ast_device_state state;
 
        if (!e)
                return -1;
@@ -3278,28 +3276,7 @@ static int ast_extension_state2(struct ast_exten *e)
                ast_devstate_aggregate_add(&agg, ast_device_state(cur));
        }
 
-       state = ast_devstate_aggregate_result(&agg);
-
-       switch (state) {
-       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;
-       }
-
-       return AST_EXTENSION_NOT_INUSE;
+       return ast_devstate_to_extenstate(ast_devstate_aggregate_result(&agg));
 }
 
 /*! \brief Return extension_state as string */
@@ -5586,6 +5563,36 @@ static char *handle_show_globals_deprecated(struct ast_cli_entry *e, int cmd, st
        return res;
 }
 
+#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
+
 /*! \brief CLI support for listing chanvar's variables in a parseable way */
 static char *handle_show_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -5766,6 +5773,9 @@ static struct ast_cli_entry pbx_cli[] = {
        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", .deprecate_cmd = &cli_show_globals_deprecated),
+#ifdef AST_DEVMODE
+       AST_CLI_DEFINE(handle_show_device2extenstate, "Show expected exten state from multiple device states"),
+#endif
        AST_CLI_DEFINE(handle_show_chanvar, "Show channel variables"),
        AST_CLI_DEFINE(handle_show_function, "Describe a specific dialplan function"),
        AST_CLI_DEFINE(handle_show_application, "Describe a specific dialplan application"),