[asterisk-commits] twilson: trunk r358945 - in /trunk: ./ channels/ include/asterisk/ main/ tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 13 15:07:04 CDT 2012
Author: twilson
Date: Tue Mar 13 15:06:57 2012
New Revision: 358945
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=358945
Log:
Make hints for invalid SIP devices return Unavail, not idle
This patch drastically simplifies the device state aggegation code.
The old method was not only overly complex, but also made it impossible
to return AST_DEVICE_INVALID from the aggregation code. The unit test
update is as a result of fixing that bug.
The SIP change stems from a bug introduced by removing a DNS lookup
for hostname-based SIP channels.
(closes issue ASTERISK-16702)
Review: https://reviewboard.asterisk.org/r/1808/
........
Merged revisions 358943 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 358944 from http://svn.asterisk.org/svn/asterisk/branches/10
Modified:
trunk/ (props changed)
trunk/channels/chan_sip.c
trunk/include/asterisk/devicestate.h
trunk/main/devicestate.c
trunk/tests/test_devicestate.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.
Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=358945&r1=358944&r2=358945
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Mar 13 15:06:57 2012
@@ -27507,8 +27507,6 @@
res = AST_DEVICE_UNAVAILABLE;
}
sip_unref_peer(p, "sip_unref_peer, from sip_devicestate, release ref from sip_find_peer");
- } else {
- res = AST_DEVICE_UNKNOWN;
}
return res;
Modified: trunk/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/devicestate.h?view=diff&rev=358945&r1=358944&r2=358945
==============================================================================
--- trunk/include/asterisk/devicestate.h (original)
+++ trunk/include/asterisk/devicestate.h Tue Mar 13 15:06:57 2012
@@ -254,14 +254,9 @@
* This struct is only here so that it can be easily declared on the stack.
*/
struct ast_devstate_aggregate {
- unsigned int all_unknown:1;
- unsigned int all_unavail:1;
- unsigned int all_busy:1;
- unsigned int all_free:1;
- unsigned int on_hold:1;
- unsigned int busy:1;
- unsigned int in_use:1;
- unsigned int ring:1;
+ unsigned int ringing:1;
+ unsigned int inuse:1;
+ enum ast_device_state state;
};
/*!
Modified: trunk/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/devicestate.c?view=diff&rev=358945&r1=358944&r2=358945
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Tue Mar 13 15:06:57 2012
@@ -732,91 +732,39 @@
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;
+ agg->state = AST_DEVICE_INVALID;
}
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;
- }
-}
-
+ static enum ast_device_state state_order[] = {
+ 1, /* AST_DEVICE_UNKNOWN */
+ 3, /* AST_DEVICE_NOT_INUSE */
+ 6, /* AST_DEVICE_INUSE */
+ 7, /* AST_DEVICE_BUSY */
+ 0, /* AST_DEVICE_INVALID */
+ 2, /* AST_DEVICE_UNAVAILABLE */
+ 5, /* AST_DEVICE_RINGING */
+ 8, /* AST_DEVICE_RINGINUSE */
+ 4, /* AST_DEVICE_ONHOLD */
+ };
+
+ if (state == AST_DEVICE_RINGING) {
+ agg->ringing = 1;
+ } else if (state == AST_DEVICE_INUSE || state == AST_DEVICE_ONHOLD || state == AST_DEVICE_BUSY) {
+ agg->inuse = 1;
+ }
+
+ if (agg->ringing && agg->inuse) {
+ agg->state = AST_DEVICE_RINGINUSE;
+ } else if (state_order[state] > state_order[agg->state]) {
+ agg->state = state;
+ }
+}
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;
+ return agg->state;
}
int ast_enable_distributed_devstate(void)
Modified: trunk/tests/test_devicestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_devicestate.c?view=diff&rev=358945&r1=358944&r2=358945
==============================================================================
--- trunk/tests/test_devicestate.c (original)
+++ trunk/tests/test_devicestate.c Tue Mar 13 15:06:57 2012
@@ -83,7 +83,7 @@
AST_DEVICE_NOT_INUSE,
AST_DEVICE_INUSE,
AST_DEVICE_BUSY,
- AST_DEVICE_UNKNOWN,
+ AST_DEVICE_INVALID,
AST_DEVICE_UNAVAILABLE,
AST_DEVICE_RINGING,
AST_DEVICE_RINGINUSE,
@@ -167,7 +167,7 @@
AST_EXTENSION_NOT_INUSE,
AST_EXTENSION_INUSE,
AST_EXTENSION_BUSY,
- AST_EXTENSION_NOT_INUSE,
+ AST_EXTENSION_UNAVAILABLE,
AST_EXTENSION_UNAVAILABLE,
AST_EXTENSION_RINGING,
AST_EXTENSION_INUSE | AST_EXTENSION_RINGING,
More information about the asterisk-commits
mailing list