| 50 | | |
|---|
| 51 | | @implementation NSNotificationQueue (NSNotificationQueueAdditions) |
|---|
| 52 | | - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle { |
|---|
| 53 | | if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; |
|---|
| 54 | | [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil]; |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | - (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes { |
|---|
| 58 | | if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; |
|---|
| 59 | | |
|---|
| 60 | | NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:4]; |
|---|
| 61 | | if( notification ) [info setObject:notification forKey:@"notification"]; |
|---|
| 62 | | [info setObject:[NSNumber numberWithUnsignedInt:postingStyle] forKey:@"postingStyle"]; |
|---|
| 63 | | [info setObject:[NSNumber numberWithUnsignedInt:coalesceMask] forKey:@"coalesceMask"]; |
|---|
| 64 | | if( modes ) [info setObject:modes forKey:@"modes"]; |
|---|
| 65 | | |
|---|
| 66 | | [[self class] performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO]; |
|---|
| 67 | | } |
|---|
| 68 | | |
|---|
| 69 | | + (void) _enqueueNotification:(NSDictionary *) info { |
|---|
| 70 | | NSNotification *notification = [info objectForKey:@"notification"]; |
|---|
| 71 | | NSPostingStyle postingStyle = [[info objectForKey:@"postingStyle"] unsignedIntValue]; |
|---|
| 72 | | unsigned coalesceMask = [[info objectForKey:@"coalesceMask"] unsignedIntValue]; |
|---|
| 73 | | NSArray *modes = [info objectForKey:@"modes"]; |
|---|
| 74 | | |
|---|
| 75 | | [[self defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes]; |
|---|
| 76 | | |
|---|
| 77 | | [info release]; |
|---|
| 78 | | } |
|---|
| 79 | | @end |
|---|