support clearing of multiple alarms on one line

This commit is contained in:
Richard Frith-Macdonald 2020-07-16 13:36:48 +01:00
parent 25826e9236
commit 518f015c35

View file

@ -870,14 +870,18 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
else if (comp(wd, @"clear") >= 0) else if (comp(wd, @"clear") >= 0)
{ {
NSArray *a = [sink alarms]; NSArray *a = [sink alarms];
unsigned index = 1;
wd = cmdWord(cmd, 1); m = @"";
if ([wd length] > 0 && [wd intValue] > 0) while ([(wd = cmdWord(cmd, index++)) length] > 0)
{ {
EcAlarm *alarm = nil; EcAlarm *alarm = nil;
int n = [wd intValue]; int n = [wd intValue];
int i = [a count]; int i = [a count];
if (n <= 0)
{
}
while (i-- > 0) while (i-- > 0)
{ {
alarm = [a objectAtIndex: i]; alarm = [a objectAtIndex: i];
@ -889,16 +893,18 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
} }
if (nil == alarm) if (nil == alarm)
{ {
m = @"No alarm found with that notificationID\n"; m = [NSString stringWithFormat:
@"%@No alarm found with ID %@\n", m, wd];
} }
else else
{ {
m = [NSString stringWithFormat: @"Clearing %@\n", alarm]; m = [NSString stringWithFormat:
@"%@Clearing %@\n", m, alarm];
alarm = [alarm clear]; alarm = [alarm clear];
[self alarm: alarm]; [self alarm: alarm];
} }
} }
else if (0 == [m length])
{ {
m = @"The 'clear' command requires an alarm notificationID\n" m = @"The 'clear' command requires an alarm notificationID\n"
@"This is the unique identifier used for working with\n" @"This is the unique identifier used for working with\n"
@ -1013,9 +1019,9 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
{ {
m = @"Clear\n\n" m = @"Clear\n\n"
@"Instructs the Control server to clear " @"Instructs the Control server to clear "
@"an alarm (identified by numeric\n" @"one or more alarms (identified by numeric\n"
@"notificationID).\n\n" @"notificationIDs).\n\n"
@"NB. This command clears the alarm in the " @"NB. This command clears the alarm(s) in the "
@"central records of the Control server,\n" @"central records of the Control server,\n"
@"NOT in the originating process.\n" @"NOT in the originating process.\n"
@"This feature means that you can clear " @"This feature means that you can clear "
@ -1029,7 +1035,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
@"the central system.\n" @"the central system.\n"
@"To reset things so the alarm may be " @"To reset things so the alarm may be "
@"raised again you must issue a 'clear'\n" @"raised again you must issue a 'clear'\n"
@"command directly to the originatig process itsself.\n"; @"command directly to the originating process itsself.\n";
} }
else if (comp(wd, @"Config") >= 0) else if (comp(wd, @"Config") >= 0)
{ {
@ -1286,6 +1292,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
wd = cmdWord(cmd, 1); wd = cmdWord(cmd, 1);
if ([wd length] > 0 && comp(wd, @"self") == 0) if ([wd length] > 0 && comp(wd, @"self") == 0)
{ {
[sink setMonitor: nil];
[alerter shutdown]; [alerter shutdown];
DESTROY(alerter); DESTROY(alerter);
exit(0); exit(0);
@ -1605,6 +1612,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
- (void) dealloc - (void) dealloc
{ {
[sink setMonitor: nil];
[alerter shutdown]; [alerter shutdown];
DESTROY(alerter); DESTROY(alerter);
[self cmdLogEnd: logname]; [self cmdLogEnd: logname];
@ -3112,6 +3120,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
} }
else if ([alerter class] != alerterClass) else if ([alerter class] != alerterClass)
{ {
[sink setMonitor: nil];
[alerter shutdown]; [alerter shutdown];
DESTROY(alerter); DESTROY(alerter);
} }
@ -3120,6 +3129,14 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
alerter = [alerterClass new]; alerter = [alerterClass new];
} }
/* An alerter which confrms t the correct protocol is assumed to
* want to monitor alarms.
*/
if ([alerter conformsToProtocol: @protocol(EcAlarmMonitor)])
{
[sink setMonitor: (id<EcAlarmMonitor>)alerter];
}
dict = [NSMutableDictionary dictionaryWithCapacity: 3]; dict = [NSMutableDictionary dictionaryWithCapacity: 3];
/* /*