aboutsummaryrefslogtreecommitdiffstats
path: root/main/devicestate.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-10 14:06:29 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-06-10 14:06:29 +0000
commitdd57dea04e9dc323b31a8917eeb8b0b226825592 (patch)
tree09b6f1c8beeb38a06eabef0e249351347d1e4009 /main/devicestate.c
parent97f03a1be3849874f90db97f7c75bb56d475eb8d (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: http://svn.digium.com/svn/asterisk/trunk@121501 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/devicestate.c')
-rw-r--r--main/devicestate.c88
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;
+}
+