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
This commit is contained in:
Russell Bryant
2008-06-10 14:06:29 +00:00
parent 51602928e3
commit 42c1e3601e
3 changed files with 160 additions and 65 deletions

View File

@@ -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;
}