Make alarm handling easier

This commit is contained in:
Richard Frith-Macdonald 2018-02-20 12:37:12 +00:00
parent a732e99ee4
commit b2c31b8261
3 changed files with 32 additions and 7 deletions

View file

@ -1,3 +1,11 @@
2018-02-20 Richard Frith-Macdonald <rfm@gnu.org>
EcAlerter.h:
EcAlerter.m:
New type 'Raise' to match only an alarm being raised. Behavior of
'Alarm' changed to match both 'Raise' and 'Clear' (and reminders as
long as ReminderInterval matches).
2018-01-05 Richard Frith-Macdonald <rfm@gnu.org>
EcProcess.h:

View file

@ -66,10 +66,13 @@
* </desc>
* <term>Type</term>
* <desc>The type of message ... <em>Error</em>, <em>Alert</em>,
* <em>Alarm</em> or <em>Clear</em>.<br />
* <em>Alarm</em>, <em>Raise</em> or <em>Clear</em>.<br />
* If this is not specified, messages of any type may match.<br />
* NB. Alarm reminders have a type of <em>Alarm</em> while alarm
* clears have a type of <em>Clear</em>.
* NB. Alarm reminders have one of three types. The type <em>Raise</em>
* matches only the initial raising of an alarm while <em>Clear</em>
* matches only the final clearing of the alarm. The type <em>Alarm</em>
* will match raising, clearing, and also (if ReminderInterval is set)
* reminders about the alarm.
* </desc>
* <term>DurationAbove</term>
* <desc>For [EcAlarm] messages, this may be used to match any message

View file

@ -783,13 +783,19 @@ replaceFields(NSDictionary *fields, NSString *template)
s = [d objectForKey: @"Type"];
if (s != nil && [s isEqualToString: event->type] == NO)
{
continue; // Not a match.
/* For alarms only, the type 'Alarm' matches all three types
* of alarm event (raise, reminder, and clear).
*/
if (NO == event->isAlarm || [s isEqualToString: @"Alarm"] == NO)
{
continue; // Not a match.
}
}
/* The next set are performed only for alarms,
* since a non-alarm can never match them.
*/
if (event->reminder >= 0)
if (YES == event->isAlarm)
{
if (event->reminder > 0 && NO == event->isClear)
{
@ -1186,6 +1192,7 @@ replaceFields(NSDictionary *fields, NSString *template)
event->severityText = @"";
event->isAlarm = NO;
event->isClear = NO;
event->reminder = -1;
if (nil != identifier)
{
event->type = @"Alert";
@ -1201,6 +1208,7 @@ replaceFields(NSDictionary *fields, NSString *template)
ASSIGN(event->severityText,
[EcAlarm stringFromSeverity: event->severity]);
event->isAlarm = YES;
event->reminder = reminder;
if ([@"Clear" isEqual: [alarm extra]])
{
event->isClear = YES;
@ -1209,10 +1217,16 @@ replaceFields(NSDictionary *fields, NSString *template)
else
{
event->isClear = NO;
event->type = @"Alarm";
if (0 == event->reminder)
{
event->type = @"Raise";
}
else
{
event->type = @"Alarm";
}
}
}
event->reminder = reminder;
event->duration = (0.0 - [timestamp timeIntervalSinceNow]) / 60.0;
m = event->m = [[NSMutableDictionary alloc] initWithCapacity: 20];