Changeset 3108
- Timestamp:
- 01/01/06 23:22:55 (3 years ago)
- Files:
-
- trunk/Additions/NSNotificationAdditions.h (modified) (1 diff)
- trunk/Additions/NSNotificationAdditions.m (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Additions/NSNotificationAdditions.h
r3088 r3108 2 2 - (void) postNotificationOnMainThread:(NSNotification *) notification; 3 3 - (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait; 4 5 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object;6 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo;7 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait;8 4 @end 9 5 trunk/Additions/NSNotificationAdditions.m
r3091 r3108 1 1 #import "NSNotificationAdditions.h" 2 #import <pthread.h>3 2 4 3 @implementation NSNotificationCenter (NSNotificationCenterAdditions) 5 4 - (void) postNotificationOnMainThread:(NSNotification *) notification { 6 if( pthread_main_np() ) return [self postNotification:notification];7 5 [self postNotificationOnMainThread:notification waitUntilDone:NO]; 8 6 } 9 7 10 8 - (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait { 11 if( pthread_main_np() ) return [self postNotification:notification]; 12 [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait]; 13 } 14 15 + (void) _postNotification:(NSNotification *) notification { 16 [[self defaultCenter] postNotification:notification]; 17 } 18 19 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object { 20 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil]; 21 [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO]; 22 } 23 24 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo { 25 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 26 [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO]; 27 } 28 29 - (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait { 30 if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; 31 32 NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init]; 33 [info setObject:name forKey:@"name"]; 34 if( object ) [info setObject:object forKey:@"object"]; 35 if( userInfo ) [info setObject:userInfo forKey:@"userInfo"]; 36 37 [[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait]; 38 [info release]; 39 } 40 41 + (void) _postNotificationName:(NSDictionary *) info { 42 NSString *name = [info objectForKey:@"name"]; 43 id object = [info objectForKey:@"object"]; 44 NSDictionary *userInfo = [info objectForKey:@"userInfo"]; 45 46 [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; 9 [self performSelectorOnMainThread:@selector( postNotification: ) withObject:notification waitUntilDone:wait]; 47 10 } 48 11 @end … … 50 13 @implementation NSNotificationQueue (NSNotificationQueueAdditions) 51 14 - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle { 52 if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil];53 15 [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; 54 16 } 55 17 56 18 - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes { 57 if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];58 59 19 NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init]; 60 20 [info setObject:notification forKey:@"notification"]; … … 63 23 if( modes ) [info setObject:modes forKey:@"modes"]; 64 24 65 [ [self class]performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO];25 [self performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO]; 66 26 [info release]; 67 27 } 68 28 69 +(void) _enqueueNotification:(NSDictionary *) info {29 - (void) _enqueueNotification:(NSDictionary *) info { 70 30 NSNotification *notification = [info objectForKey:@"notification"]; 71 31 NSPostingStyle postingStyle = [[info objectForKey:@"postingStyle"] unsignedIntValue]; … … 73 33 NSArray *modes = [info objectForKey:@"modes"]; 74 34 75 [[ selfdefaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];35 [[[self class] defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; 76 36 } 77 37 @end
