Skip to content

Commit 85d9fab

Browse files
committedAug 31, 2013
Before trying to add lastSaveHash
1 parent e66e410 commit 85d9fab

5 files changed

+58
-41
lines changed
 

‎SSYDocChildObject.h

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
BkmxDoc* m_document ;
77
}
88

9+
/*
10+
@details It is very important that someone counter this assignment by
11+
sending us a setDocument:nil sometime between the time we find out that the
12+
document is closing and the time that the document deallocs.
13+
*/
914
- (id)initWithDocument:(BkmxDoc*)document ;
1015

1116
// Weak reference, not retained, to avoid retain cycles

‎SSYDocChildObject.m

-26
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ - (void)setDocument:(BkmxDoc *)document {
1616
@synchronized(self) {
1717
m_document = document ;
1818
}
19-
20-
// During document opening, during -viewDidMoveToWindow, this class
21-
// will be sent an -initWithDocument: with argument nil.
22-
// If that were passed to the following method as the object: argument,
23-
// we would get notifications when ^any^ document closed. We only
24-
// want notifications when ^our^ document closes. Thus, the following if()...
25-
if (document != nil) {
26-
[[NSNotificationCenter defaultCenter] addObserver:self
27-
selector:@selector(docWillClose:)
28-
name:SSYUndoManagerDocumentWillCloseNotification
29-
object:document] ;
30-
}
3119
}
3220

3321
- (id)initWithDocument:(BkmxDoc*)document_ {
@@ -40,18 +28,4 @@ - (id)initWithDocument:(BkmxDoc*)document_ {
4028
return self;
4129
}
4230

43-
- (void)dealloc {
44-
45-
[super dealloc] ;
46-
}
47-
48-
- (void)docWillClose:(NSNotification*)note {
49-
[[NSNotificationCenter defaultCenter] removeObserver:self] ;
50-
51-
// To keep from crashing, in particular if I am a Broker, because
52-
// my timers will keep invoking gotHeaders: and other methods
53-
// which send messages to _doc as responses are received.
54-
[self setDocument:nil] ;
55-
}
56-
5731
@end

‎SSYManagedObject.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ extern NSString* const constKeyNewValue ;
118118
owns the receiver's managed object context
119119
120120
@details See +[SSYMOCManager ownerOfManagedObjectContext:] for exact search algorithm
121-
and definition of "owner".  Assuming that the owner must be of a specific type or
122-
conform to a certain formal protocol, it is recommended to override this method in
123-
subclasses.  Just invoke super, but return the required type.
121+
and definition of "owner". If the owner must be of a specific type or
122+
conform to a certain formal protocol, you can re-declare and override this
123+
method in subclasses. The implementation simply returns super's owner.
124124
@result The owner of the receiver
125125
*/
126126
- (id)owner ;
@@ -215,13 +215,17 @@ extern NSString* const constKeyNewValue ;
215215

216216
- (NSUInteger)countOfNonNilValues ;
217217

218+
218219
/*!
219220
@brief A hash representing all relevant current property values of
220221
the receiver
221222
222223
@details The default implementation considers all attribute values to
223224
be relevant, and excludes all relationships. Subclasses may override
224225
to exclude some attributes, or include some relationships, as desired.
226+
227+
I don't use this implementation in BookMacster any more. Instead, I have
228+
tweaked implementations in two subclasses.
225229
*/
226230
- (uint32_t)valuesHash ;
227231

‎SSYOperationQueue.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
6363
id m_scriptResult ;
6464
NSMutableArray* m_errorRetryInvocations ;
6565
NSSet* m_skipOperationsExceptGroups ;
66+
id m_noAppNapActivity ;
6667
}
6768

6869
/*!
@@ -265,9 +266,9 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
265266
recovery option, you make the adjustments and, to repeat the operations,
266267
simply invoke the invocations in the array returned by this method.
267268
However, you must grab this array during your isDoneSelector, because after
268-
your isDoneSelector returns, the array you get will be empty, as explained below.
269-
Typically, after grabbing this array you process the contents into a single
270-
invocation of invocations, and add the resulting "errorRetryInvocation"
269+
your isDoneSelector returns, the array you get will be empty, as explained
270+
below. Typically, after grabbing this array you process the contents into a
271+
single invocation of invocations, and add the resulting "errorRetryInvocation"
271272
to the -userInfo of your error object.
272273
273274
After invoking your isDoneSelector, unless you passed keepWithNext:YES,

‎SSYOperationQueue.m

+42-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#import "NSError+InfoAccess.h"
55
#import "NSInvocation+Quick.h"
66
#import "NSInvocation+Nesting.h"
7-
7+
#import "NSDate+NiceFormats.h"
88

99
NSString* const SSYOperationQueueDidEndWorkNotification = @"SSYOperationQueueDidEndWorkNotification" ;
1010
NSString* const SSYOperationQueueDidBeginWorkNotification = @"SSYOperationQueueDidBeginWorkNotification" ;
@@ -17,23 +17,19 @@
1717
NSString* const constKeySSYOperationQueueKeepWithNext = @"SSYOperationQueueKeepWithNext" ;
1818
NSString* const constKeySSYOperationGroup = @"SSYOperationGroup" ;
1919

20+
@interface SSYOperationQueue ()
2021

21-
// No longer needed since override of -[SSYOperationQueue setError:] does this. @implementation NSError (SSYOperationQueueExtras)
22-
23-
// No longer needed since override of -[SSYOperationQueue setError:] does this. - (NSError*)errorByAddingOperationGroupFromInfo:(NSDictionary*)info {
24-
// No longer needed since override of -[SSYOperationQueue setError:] does this. return [self errorByAddingUserInfoObject:[info objectForKey:constKeySSYOperationGroup]
25-
// No longer needed since override of -[SSYOperationQueue setError:] does this. forKey:constKeySSYOperationGroup] ;
26-
// No longer needed since override of -[SSYOperationQueue setError:] does this. }
27-
28-
// No longer needed since override of -[SSYOperationQueue setError:] does this. @end
22+
@property (retain) id noAppNapActivity ;
2923

24+
@end
3025

3126

3227
@implementation SSYOperationQueue
3328

3429
@synthesize scriptCommand = m_scriptCommand ;
3530
@synthesize scriptResult = m_scriptResult ;
3631
@synthesize skipOperationsExceptGroups = m_skipOperationsExceptGroups ;
32+
@synthesize noAppNapActivity = m_noAppNapActivity ;
3733

3834
- (BOOL)shouldSkipOperationsInGroup:(NSString*)group {
3935
NSSet* skipOperationsExceptGroups = [self skipOperationsExceptGroups] ;
@@ -132,6 +128,7 @@ - (void)dealloc {
132128
[m_scriptResult release] ;
133129
[m_errorRetryInvocations release] ;
134130
[m_skipOperationsExceptGroups release] ;
131+
[m_noAppNapActivity release] ;
135132

136133
[super dealloc] ;
137134
}
@@ -231,6 +228,15 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
231228
else {
232229
owner = self ;
233230
}
231+
232+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
233+
// Being built with Mac OS X 10.9 or later SDK
234+
id activity = [self noAppNapActivity] ;
235+
if (activity) {
236+
[[NSProcessInfo processInfo] endActivity:activity];
237+
/*SSYDBL*/ NSLog(@"Ended no-app-nap activity=%@", activity) ;
238+
}
239+
#endif
234240

235241
// It is stated in the documentation of NSOperationQueue (in the
236242
// introduction, not in -operations) that KVO notifications
@@ -252,6 +258,33 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
252258
// when the count jumps from 0 to, say, 5. Apparently,
253259
// KVO notifications are coalesced.
254260

261+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
262+
#warning "Built for 10.9"
263+
// Being built with Mac OS X 10.9 or later SDK
264+
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)]) {
265+
// Running in Mac OS X 10.9 or later
266+
NSString* groupName = nil ;
267+
if ([[self operations] count] > 0) {
268+
SSYOperation* firstOperation = [[self operations] objectAtIndex:0] ;
269+
if ([firstOperation respondsToSelector:@selector(info)]) {
270+
NSDictionary* info = [firstOperation info] ;
271+
groupName = [info objectForKey:constKeySSYOperationGroup] ;
272+
}
273+
}
274+
if (!groupName) {
275+
groupName = @"?**?" ;
276+
}
277+
NSString* reason = [NSString stringWithFormat:
278+
@"SSYOperations beginning with group %@ at %@",
279+
groupName,
280+
[[NSDate date] geekDateTimeString]] ;
281+
id activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityAutomaticTerminationDisabled
282+
reason:reason] ;
283+
/*SSYDBL*/ NSLog(@"Suspended app nap with activity=%@ for reason: %@", activity, reason) ;
284+
[self setNoAppNapActivity:activity] ;
285+
}
286+
#endif
287+
255288
NSOperation <SSYOwnee> * operation = [[self operations] objectAtIndex:0] ;
256289
id owner ;
257290
if ([operation respondsToSelector:@selector(owner)]) {

0 commit comments

Comments
 (0)
Please sign in to comment.