diff options
author | Russell Bryant <russell@russellbryant.com> | 2008-06-10 14:06:29 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2008-06-10 14:06:29 +0000 |
commit | 42c1e3601e58474efbd7081c6bfaafc0ea370a4f (patch) | |
tree | 09b6f1c8beeb38a06eabef0e249351347d1e4009 /main/devicestate.c | |
parent | 51602928e3069889a0b9bcbe492b52bd969b772b (diff) |
Merge another change from team/russell/events
This commit breaks out some logic from pbx.c into a simple API. The hint
processing code had logic for taking the state from multiple devices and
turning that into the state for a single extension. So, I broke this out
and made an API that lets you take multiple device states and determine
the aggregate device state. I needed this for some core device state changes
to support distributed device state.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121501 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/devicestate.c')
-rw-r--r-- | main/devicestate.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/main/devicestate.c b/main/devicestate.c index bd9261306..85ac6492e 100644 --- a/main/devicestate.c +++ b/main/devicestate.c @@ -551,3 +551,91 @@ int ast_device_state_engine_init(void) return 0; } + +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_busy = 0; + agg->all_unavail = 0; + agg->all_free = 0; + agg->all_on_hold = 0; + break; + case AST_DEVICE_RINGING: + agg->ring = 1; + agg->all_busy = 0; + 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_busy = 0; + 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; +} + |