Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv6648

Modified Files:
        channel.c devicestate.c 
Log Message:
various devicestate fixes (issue #5081, take two)


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.239
retrieving revision 1.240
diff -u -d -r1.239 -r1.240
--- channel.c   1 Sep 2005 21:50:49 -0000       1.239
+++ channel.c   1 Sep 2005 22:28:33 -0000       1.240
@@ -2808,34 +2808,25 @@
 
 int ast_setstate(struct ast_channel *chan, int state)
 {
-       if (chan->_state != state) {
-               int oldstate = chan->_state;
-               chan->_state = state;
-               if (oldstate == AST_STATE_DOWN) {
-                       ast_device_state_changed(chan->name);
-                       manager_event(EVENT_FLAG_CALL, "Newchannel",
-                               "Channel: %s\r\n"
-                               "State: %s\r\n"
-                               "CallerID: %s\r\n"
-                               "CallerIDName: %s\r\n"
-                               "Uniqueid: %s\r\n",
-                               chan->name, ast_state2str(chan->_state), 
-                               chan->cid.cid_num ? chan->cid.cid_num : 
"<unknown>", 
-                               chan->cid.cid_name ? chan->cid.cid_name : 
"<unknown>", 
-                               chan->uniqueid);
-               } else {
-                       manager_event(EVENT_FLAG_CALL, "Newstate", 
-                               "Channel: %s\r\n"
-                               "State: %s\r\n"
-                               "CallerID: %s\r\n"
-                               "CallerIDName: %s\r\n"
-                               "Uniqueid: %s\r\n",
-                               chan->name, ast_state2str(chan->_state), 
-                               chan->cid.cid_num ? chan->cid.cid_num : 
"<unknown>", 
-                               chan->cid.cid_name ? chan->cid.cid_name : 
"<unknown>", 
-                               chan->uniqueid);
-               }
-       }
+       int oldstate = chan->_state;
+
+       if (oldstate == state)
+               return 0;
+
+       chan->_state = state;
+       ast_device_state_changed(chan->name);
+       manager_event(EVENT_FLAG_CALL,
+                     (oldstate == AST_STATE_DOWN) ? "Newchannel" : "Newstate",
+                     "Channel: %s\r\n"
+                     "State: %s\r\n"
+                     "CallerID: %s\r\n"
+                     "CallerIDName: %s\r\n"
+                     "Uniqueid: %s\r\n",
+                     chan->name, ast_state2str(chan->_state), 
+                     chan->cid.cid_num ? chan->cid.cid_num : "<unknown>", 
+                     chan->cid.cid_name ? chan->cid.cid_name : "<unknown>", 
+                     chan->uniqueid);
+
        return 0;
 }
 

Index: devicestate.c
===================================================================
RCS file: /usr/cvsroot/asterisk/devicestate.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- devicestate.c       9 Aug 2005 15:37:32 -0000       1.5
+++ devicestate.c       1 Sep 2005 22:28:33 -0000       1.6
@@ -109,9 +109,16 @@
                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)
-                       return ast_parse_device_state(device);
-               else
+               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;
        }
 }

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to