[svn-commits] twilson: branch 1.8 r358943 - in /branches/1.8: channels/ include/asterisk/ m...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 13 14:51:28 CDT 2012
Author: twilson
Date: Tue Mar 13 14:51:23 2012
New Revision: 358943
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=358943
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/
Modified:
branches/1.8/channels/chan_sip.c
branches/1.8/include/asterisk/devicestate.h
branches/1.8/main/devicestate.c
branches/1.8/tests/test_devicestate.c
Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=358943&r1=358942&r2=358943
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Tue Mar 13 14:51:23 2012
@@ -26396,8 +26396,6 @@
res = AST_DEVICE_UNAVAILABLE;
}
unref_peer(p, "unref_peer, from sip_devicestate, release ref from find_peer");
- } else {
- res = AST_DEVICE_UNKNOWN;
}
return res;
Modified: branches/1.8/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/devicestate.h?view=diff&rev=358943&r1=358942&r2=358943
==============================================================================
--- branches/1.8/include/asterisk/devicestate.h (original)
+++ branches/1.8/include/asterisk/devicestate.h Tue Mar 13 14:51:23 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: branches/1.8/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/devicestate.c?view=diff&rev=358943&r1=358942&r2=358943
==============================================================================
--- branches/1.8/main/devicestate.c (original)
+++ branches/1.8/main/devicestate.c Tue Mar 13 14:51:23 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: branches/1.8/tests/test_devicestate.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/tests/test_devicestate.c?view=diff&rev=358943&r1=358942&r2=358943
==============================================================================
--- branches/1.8/tests/test_devicestate.c (original)
+++ branches/1.8/tests/test_devicestate.c Tue Mar 13 14:51:23 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 svn-commits
mailing list