Skip to content

Commit df60b23

Browse files
committed
res_alarmsystem: Add ALARMSYSTEM_STATE function.
Add a function that can be used to retrieve the current state of the alarm system as a whole, rather than an individual sensor. This allows us to determine from the dialplan if the system is actively "in alarm" - just because a sensor is triggered doesn't mean the system is, as the system may be in the temporarily disarmed mode (e.g. to allow egress). This allows dialplan logic to do certain things when an alarm is actively going off.
1 parent a8f60e0 commit df60b23

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

res/res_alarmsystem.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ struct alarm_client {
597597

598598
static AST_RWLIST_HEAD_STATIC(clients, alarm_client);
599599

600+
static const char *state2str(enum alarm_state state)
601+
{
602+
switch (state) {
603+
case ALARM_STATE_OK: return "OK";
604+
case ALARM_STATE_TRIGGERED: return "TRIGGERED";
605+
case ALARM_STATE_BREACH: return "BREACH";
606+
}
607+
__builtin_unreachable();
608+
}
609+
600610
static const char *state2text(int state)
601611
{
602612
switch (state) {
@@ -2614,6 +2624,32 @@ static struct ast_custom_function acf_sensortriggered = {
26142624
.read = sensor_triggered_read,
26152625
};
26162626

2627+
static int alarm_state_read(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
2628+
{
2629+
struct alarm_client *c;
2630+
2631+
if (ast_strlen_zero(parse)) {
2632+
ast_log(LOG_ERROR, "Must specify client-name\n");
2633+
return -1;
2634+
}
2635+
2636+
AST_RWLIST_RDLOCK(&clients);
2637+
c = find_client_locked(parse);
2638+
if (!c) {
2639+
ast_log(LOG_ERROR, "Client '%s' not found in configuration\n", parse);
2640+
AST_RWLIST_UNLOCK(&clients);
2641+
return -1;
2642+
}
2643+
ast_copy_string(buffer, state2str(c->state), buflen);
2644+
AST_RWLIST_UNLOCK(&clients);
2645+
return 0;
2646+
}
2647+
2648+
static struct ast_custom_function acf_state = {
2649+
.name = "ALARMSYSTEM_STATE",
2650+
.read = alarm_state_read,
2651+
};
2652+
26172653
static char *handle_show_sensors(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
26182654
{
26192655
#define FORMAT "%-12s %-20s %s\n"
@@ -2771,6 +2807,7 @@ static int unload_module(void)
27712807

27722808
ast_cli_unregister_multiple(alarmsystem_cli, ARRAY_LEN(alarmsystem_cli));
27732809
ast_custom_function_unregister(&acf_sensortriggered);
2810+
ast_custom_function_unregister(&acf_state);
27742811
ast_unregister_application("AlarmSensor");
27752812
ast_unregister_application("AlarmEventReceiver");
27762813
ast_unregister_application("AlarmKeypad");
@@ -2825,6 +2862,7 @@ static int load_module(void)
28252862
}
28262863

28272864
ast_custom_function_register(&acf_sensortriggered);
2865+
ast_custom_function_register(&acf_state);
28282866
ast_cli_register_multiple(alarmsystem_cli, ARRAY_LEN(alarmsystem_cli));
28292867
return 0;
28302868
}

0 commit comments

Comments
 (0)