[asterisk-commits] russell: branch russell/events r103655 - in /team/russell/events: include/ast...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Feb 13 08:51:58 CST 2008
Author: russell
Date: Wed Feb 13 08:51:57 2008
New Revision: 103655
URL: http://svn.digium.com/view/asterisk?view=rev&rev=103655
Log:
When device state changes on one server, calculate the new aggregate device state.
This logic pretty much already existed in pbx.c for calculating extension state when
a hint was mapped to multiple devices. So, I took the logic and broke it out into
API calls so that it could be used elsewhere without being replicated.
Modified:
team/russell/events/include/asterisk/devicestate.h
team/russell/events/main/devicestate.c
team/russell/events/main/pbx.c
Modified: team/russell/events/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/devicestate.h?view=diff&rev=103655&r1=103654&r2=103655
==============================================================================
--- team/russell/events/include/asterisk/devicestate.h (original)
+++ team/russell/events/include/asterisk/devicestate.h Wed Feb 13 08:51:57 2008
@@ -196,6 +196,25 @@
*/
int ast_devstate_prov_del(const char *label);
+struct ast_devstate_aggregate;
+
+void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg);
+
+void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state);
+
+enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg);
+
+/*! \brief You shouldn't care about the contents of this struct */
+struct ast_devstate_aggregate {
+ unsigned int all_unavail:1;
+ unsigned int all_busy:1;
+ unsigned int all_free:1;
+ unsigned int all_on_hold:1;
+ unsigned int busy:1;
+ unsigned int in_use:1;
+ unsigned int ring:1;
+};
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/russell/events/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/devicestate.c?view=diff&rev=103655&r1=103654&r2=103655
==============================================================================
--- team/russell/events/main/devicestate.c (original)
+++ team/russell/events/main/devicestate.c Wed Feb 13 08:51:57 2008
@@ -593,8 +593,103 @@
collection->num_states++;
}
+void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
+{
+ memset(agg, 0, sizeof(*agg));
+
+ agg->all_unavail = 1;
+ agg->all_busy = 1;
+ agg->all_free = 1;
+ agg->all_on_hold = 1;
+}
+
+void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
+{
+ switch (state) {
+ case AST_DEVICE_NOT_INUSE:
+ agg->all_unavail = 0;
+ agg->all_busy = 0;
+ agg->all_on_hold = 0;
+ break;
+ case AST_DEVICE_INUSE:
+ agg->in_use = 1;
+ agg->all_unavail = 0;
+ agg->all_free = 0;
+ agg->all_on_hold = 0;
+ break;
+ case AST_DEVICE_RINGING:
+ agg->ring = 1;
+ agg->all_unavail = 0;
+ agg->all_free = 0;
+ agg->all_on_hold = 0;
+ break;
+ case AST_DEVICE_RINGINUSE:
+ agg->in_use = 1;
+ agg->ring = 1;
+ agg->all_unavail = 0;
+ agg->all_free = 0;
+ agg->all_on_hold = 0;
+ break;
+ case AST_DEVICE_ONHOLD:
+ agg->all_unavail = 0;
+ agg->all_free = 0;
+ break;
+ case AST_DEVICE_BUSY:
+ agg->all_unavail = 0;
+ agg->all_free = 0;
+ agg->all_on_hold = 0;
+ agg->busy = 1;
+ break;
+ case AST_DEVICE_UNAVAILABLE:
+ case AST_DEVICE_INVALID:
+ agg->all_busy = 0;
+ agg->all_free = 0;
+ agg->all_on_hold = 0;
+ break;
+ case AST_DEVICE_UNKNOWN:
+ break;
+ }
+}
+
+enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
+{
+ if (agg->all_free)
+ return AST_DEVICE_NOT_INUSE;
+
+ if (agg->all_on_hold)
+ return AST_DEVICE_ONHOLD;
+
+ if (agg->all_busy)
+ return AST_DEVICE_BUSY;
+
+ if (agg->all_unavail)
+ return AST_DEVICE_UNAVAILABLE;
+
+ if (agg->ring)
+ return agg->in_use ? AST_DEVICE_RINGINUSE : AST_DEVICE_RINGING;
+
+ if (agg->in_use)
+ return AST_DEVICE_INUSE;
+
+ if (agg->busy)
+ return AST_DEVICE_BUSY;
+
+ return AST_DEVICE_NOT_INUSE;
+}
+
static void process_collection(struct change_collection *collection)
{
+ int i;
+ struct ast_devstate_aggregate agg;
+ enum ast_device_state state;
+
+ ast_devstate_aggregate_init(&agg);
+
+ for (i = 0; i < collection->num_states; i++)
+ ast_devstate_aggregate_add(&agg, collection->states[i].state);
+
+ state = ast_devstate_aggregate_result(&agg);
+
/* XXX */
}
Modified: team/russell/events/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/pbx.c?view=diff&rev=103655&r1=103654&r2=103655
==============================================================================
--- team/russell/events/main/pbx.c (original)
+++ team/russell/events/main/pbx.c Wed Feb 13 08:51:57 2008
@@ -2745,82 +2745,41 @@
{
char hint[AST_MAX_EXTENSION];
char *cur, *rest;
- int allunavailable = 1, allbusy = 1, allfree = 1, allonhold = 1;
- int busy = 0, inuse = 0, ring = 0;
+ struct ast_devstate_aggregate agg;
+ enum ast_device_state state;
if (!e)
return -1;
+ ast_devstate_aggregate_init(&agg);
+
ast_copy_string(hint, ast_get_extension_app(e), sizeof(hint));
rest = hint; /* One or more devices separated with a & character */
- while ( (cur = strsep(&rest, "&")) ) {
- int res = ast_device_state(cur);
- switch (res) {
- case AST_DEVICE_NOT_INUSE:
- allunavailable = 0;
- allbusy = 0;
- allonhold = 0;
- break;
- case AST_DEVICE_INUSE:
- inuse = 1;
- allunavailable = 0;
- allfree = 0;
- allonhold = 0;
- break;
- case AST_DEVICE_RINGING:
- ring = 1;
- allunavailable = 0;
- allfree = 0;
- allonhold = 0;
- break;
- case AST_DEVICE_RINGINUSE:
- inuse = 1;
- ring = 1;
- allunavailable = 0;
- allfree = 0;
- allonhold = 0;
- break;
- case AST_DEVICE_ONHOLD:
- allunavailable = 0;
- allfree = 0;
- break;
- case AST_DEVICE_BUSY:
- allunavailable = 0;
- allfree = 0;
- allonhold = 0;
- busy = 1;
- break;
- case AST_DEVICE_UNAVAILABLE:
- case AST_DEVICE_INVALID:
- allbusy = 0;
- allfree = 0;
- allonhold = 0;
- break;
- default:
- allunavailable = 0;
- allbusy = 0;
- allfree = 0;
- allonhold = 0;
- }
- }
-
- if (!inuse && ring)
+
+ while ( (cur = strsep(&rest, "&")) )
+ 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:
+ return AST_EXTENSION_UNAVAILABLE;
+ case AST_DEVICE_RINGINUSE:
+ return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
+ case AST_DEVICE_RINGING:
return AST_EXTENSION_RINGING;
- if (inuse && ring)
- return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
- if (inuse)
+ case AST_DEVICE_INUSE:
return AST_EXTENSION_INUSE;
- if (allfree)
+ case AST_DEVICE_UNKNOWN:
+ case AST_DEVICE_INVALID:
+ case AST_DEVICE_NOT_INUSE:
return AST_EXTENSION_NOT_INUSE;
- if (allonhold)
- return AST_EXTENSION_ONHOLD;
- if (allbusy)
- return AST_EXTENSION_BUSY;
- if (allunavailable)
- return AST_EXTENSION_UNAVAILABLE;
- if (busy)
- return AST_EXTENSION_INUSE;
+ }
return AST_EXTENSION_NOT_INUSE;
}
More information about the asterisk-commits
mailing list