Allow lookup for a recent match of an alarm

This commit is contained in:
Richard Frith-Macdonald 2021-12-19 11:02:02 +00:00
parent 4f1029ec5c
commit c49f244ca2
3 changed files with 48 additions and 0 deletions

View file

@ -1,3 +1,10 @@
2021-12-19 Richard Frith-Macdonald <rfm@gnu.org>
* EcAlarmDestination.h:
* EcAlarmDestination.m:
Add (-latest:) method to find the most recent match for an alarm
in the queue/active/cleared data structures.
2021-12-16 Richard Frith-Macdonald <rfm@gnu.org>
* EcCommand.m:

View file

@ -184,6 +184,14 @@
*/
- (BOOL) isRunning;
/** Finds and returns the most recent alarm in the system which matches
* (is equal to) toFind. This searches the queue of alarms to be processed,
* the set of active alarms, and the set of cleared alarms (in that order)
* returning the first match found. If no match is found the method
* returns nil.
*/
- (EcAlarm*) latest: (EcAlarm*)toFind;
/** Returns an array containing the known managed objects.
*/
- (NSArray*) managed;

View file

@ -374,6 +374,39 @@
return result;
}
- (EcAlarm*) latest: (EcAlarm*)toFind
{
EcAlarm *found = nil;
NSUInteger index;
[_alarmLock lock];
/* First try to find the most recent match in the queue
*/
index = [_alarmQueue count];
while (index-- > 0)
{
EcAlarm *a = [_alarmQueue objectAtIndex: index];
if ([a isEqual: toFind])
{
found = RETAIN(a);
break;
}
}
if (nil == found)
{
/* Not in queue ... try active alarms or clears
*/
found = RETAIN([_alarmsActive member: toFind]);
if (nil == found)
{
found = RETAIN([_alarmsCleared member: toFind]);
}
}
[_alarmLock unlock];
return AUTORELEASE(found);
}
- (NSArray*) managed
{
NSArray *a;