Asterisk:1.4:app page.c

From My Notepad
Jump to: navigation, search

The following code adds the device state checks for the page application from 1.6 and adds the ability to still page devices that don't present a device state (where device state returns UNKNOWN).

--- apps/app_page.c.original    2008-03-11 11:05:17.000000000 -0500
+++ apps/app_page.c     2008-03-11 12:49:47.000000000 -0500
@@ -64,18 +64,21 @@
 "destroyed when the original caller leaves.  Valid options are:\n"
 "        d - full duplex audio\n"
 "        q - quiet, do not play beep to caller\n"
-"        r - record the page into a file (see 'r' for app_meetme)\n";
+"        r - record the page into a file (see 'r' for app_meetme)\n"
+"        s - only dial channel if devicestate says it is not in use\n";

 enum {
        PAGE_DUPLEX = (1 << 0),
        PAGE_QUIET = (1 << 1),
        PAGE_RECORD = (1 << 2),
+        PAGE_SKIP = (1 << 3),
 } page_opt_flags;

 AST_APP_OPTIONS(page_opts, {
        AST_APP_OPTION('d', PAGE_DUPLEX),
        AST_APP_OPTION('q', PAGE_QUIET),
        AST_APP_OPTION('r', PAGE_RECORD),
+        AST_APP_OPTION('s', PAGE_SKIP),
 });

 #define MAX_DIALS 128
@@ -119,6 +122,7 @@

        /* Go through parsing/calling each device */
        while ((tech = strsep(&tmp, "&"))) {
+               int state = 0;
                struct ast_dial *dial = NULL;

                /* don't call the originating device */
@@ -131,6 +135,17 @@
                        continue;
                }

+                /* Ensure device is not in use if skip option is enabled */
+                if (ast_test_flag(&flags, PAGE_SKIP)) {
+                       state = ast_device_state(tech);
+                       if (state == AST_DEVICE_UNKNOWN) {
+                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, devstate2str(state));
+                       } else if (state != AST_DEVICE_NOT_INUSE) {
+                               ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Not paging.\n", tech, devstate2str(state));
+                               continue;
+                       }
+                }
+
                *resource++ = '\0';

                /* Create a dialing structure */