From f5287d4e79ae6a5b21cb6807a1aece48be098f82 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 2 Feb 2015 10:38:44 +0000 Subject: [PATCH] add some debug git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@38320 72102866-910b-0410-8b05-ffd578937521 --- EcAlarmDestination.h | 7 +++++ EcAlarmDestination.m | 74 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/EcAlarmDestination.h b/EcAlarmDestination.h index eef504e..0682d9e 100644 --- a/EcAlarmDestination.h +++ b/EcAlarmDestination.h @@ -97,6 +97,7 @@ NSString *_name; id _destination; NSArray *_backups; + BOOL _debug; } /** Passes an alarm to the destination by adding it to a queue of alarm @@ -172,6 +173,12 @@ */ - (BOOL) setCoalesce: (BOOL)coalesce; +/** Sets debug on/off. When debugging is on, we generate logs of + * forwarding to the destination and of coalescing of alams.
+ * Returns the previous value of the setting. + */ +- (BOOL) setDebug: (BOOL)debug; + /** Sets the destination to which alarms should be forwarded.
* If nil this turns off forwarding until it is re-set to a non-nil * destination.
diff --git a/EcAlarmDestination.m b/EcAlarmDestination.m index 0d619bf..e95c4cb 100644 --- a/EcAlarmDestination.m +++ b/EcAlarmDestination.m @@ -84,19 +84,34 @@ [_alarmQueue addObject: event]; if (NSNotFound != index) { - event = [_alarmQueue objectAtIndex: index]; - if ([event perceivedSeverity] == EcAlarmSeverityCleared) + EcAlarm *old = [_alarmQueue objectAtIndex: index]; + + if ([old perceivedSeverity] == EcAlarmSeverityCleared) { + if (YES == _debug) + { + NSLog(@"Coalesce %@ by removing %@", event, old); + } [_alarmQueue removeObjectAtIndex: index]; } } } else { - [event retain]; - [_alarmQueue removeObject: event]; + NSUInteger index; + + index = [_alarmQueue indexOfObject: event]; [_alarmQueue addObject: event]; - [event release]; + if (NSNotFound != index) + { + EcAlarm *old = [_alarmQueue objectAtIndex: index]; + + if (YES == _debug) + { + NSLog(@"Coalesce %@ by removing %@", event, old); + } + [_alarmQueue removeObjectAtIndex: index]; + } } [_alarmLock unlock]; } @@ -206,8 +221,17 @@ } else { - [_alarmQueue removeObject: event]; - [_alarmQueue addObject: event]; + NSUInteger index = [_alarmQueue indexOfObject: event]; + + [_alarmQueue addObject: event]; + if (NSNotFound != index) + { + if (YES == _debug) + { + NSLog(@"Coalesce %@", event); + } + [_alarmQueue removeObjectAtIndex: index]; + } } [_alarmLock unlock]; } @@ -292,6 +316,17 @@ return old; } +- (BOOL) setDebug: (BOOL)debug +{ + BOOL old; + + [_alarmLock lock]; + old = _debug; + _debug = (YES == debug) ? YES : NO; + [_alarmLock unlock]; + return old; +} + - (id) setDestination: (id)destination { id old; @@ -372,8 +407,17 @@ } else { - [_alarmQueue removeObject: event]; - [_alarmQueue addObject: event]; + NSUInteger index = [_alarmQueue indexOfObject: event]; + + [_alarmQueue addObject: event]; + if (NSNotFound != index) + { + if (YES == _debug) + { + NSLog(@"Coalesce %@", event); + } + [_alarmQueue removeObjectAtIndex: index]; + } } [_alarmLock unlock]; } @@ -664,6 +708,10 @@ } NS_DURING [[self _connect] alarm: event]; + if (YES == _debug) + { + NSLog(@"%@ %@", NSStringFromSelector(_cmd), event); + } NS_DURING [[self backups] makeObjectsPerformSelector: @selector(alarm:) withObject: event]; @@ -688,6 +736,10 @@ } NS_DURING [[self _connect] domanage: managedObject]; + if (YES == _debug) + { + NSLog(@"%@ %@", NSStringFromSelector(_cmd), managedObject); + } NS_DURING [[self backups] makeObjectsPerformSelector: @selector(domanage:) withObject: managedObject]; @@ -712,6 +764,10 @@ } NS_DURING [[self _connect] unmanage: managedObject]; + if (YES == _debug) + { + NSLog(@"%@ %@", NSStringFromSelector(_cmd), managedObject); + } NS_DURING [[self backups] makeObjectsPerformSelector: @selector(unmanage:) withObject: managedObject];