[39738] branches/gsoc08-framework/MacPorts_Framework_Release
armahg at macports.org
armahg at macports.org
Mon Sep 1 23:42:19 PDT 2008
Revision: 39738
http://trac.macosforge.org/projects/macports/changeset/39738
Author: armahg at macports.org
Date: 2008-09-01 23:42:18 -0700 (Mon, 01 Sep 2008)
Log Message:
-----------
Adding Notification+ThreadAdditions categories to enable posting NSNotifications to main thread. Thanks to TH from CocoaDev for sample code
Modified Paths:
--------------
branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj
Added Paths:
-----------
branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.h
branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.m
Modified: branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj 2008-09-02 03:00:08 UTC (rev 39737)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/MacPorts.Framework.xcodeproj/project.pbxproj 2008-09-02 06:42:18 UTC (rev 39738)
@@ -40,6 +40,8 @@
48E9939F0C82CEB000219DDF /* init.tcl in Resources */ = {isa = PBXBuildFile; fileRef = 48E9939E0C82CEB000219DDF /* init.tcl */; };
6E270D090E158CED00BAE687 /* MPNotifications.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E270D070E158CED00BAE687 /* MPNotifications.h */; settings = {ATTRIBUTES = (Public, ); }; };
6E270D0A0E158CED00BAE687 /* MPNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E270D080E158CED00BAE687 /* MPNotifications.m */; };
+ 6E31A02D0E6CFB51002804D0 /* Notification+ThreadAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E31A02B0E6CFB51002804D0 /* Notification+ThreadAdditions.h */; };
+ 6E31A02E0E6CFB51002804D0 /* Notification+ThreadAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E31A02C0E6CFB51002804D0 /* Notification+ThreadAdditions.m */; };
6E3345350E54AF14008A2F6C /* MPPortManipulationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E3345340E54AF14008A2F6C /* MPPortManipulationTest.m */; };
6E44A00D0E2DAD66007DE8EC /* ToDo.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6E44A00C0E2DAD66007DE8EC /* ToDo.txt */; };
6E49F37B0DFFAB0B0030C3AF /* MPInterpreterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 489DD92E0C94674B00595506 /* MPInterpreterTest.m */; };
@@ -143,6 +145,8 @@
48F811BF0CE4638C009630DE /* MPRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPRegistry.m; sourceTree = "<group>"; };
6E270D070E158CED00BAE687 /* MPNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNotifications.h; sourceTree = "<group>"; };
6E270D080E158CED00BAE687 /* MPNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNotifications.m; sourceTree = "<group>"; };
+ 6E31A02B0E6CFB51002804D0 /* Notification+ThreadAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Notification+ThreadAdditions.h"; sourceTree = "<group>"; };
+ 6E31A02C0E6CFB51002804D0 /* Notification+ThreadAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Notification+ThreadAdditions.m"; sourceTree = "<group>"; };
6E3345330E54AF14008A2F6C /* MPPortManipulationTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPortManipulationTest.h; sourceTree = "<group>"; };
6E3345340E54AF14008A2F6C /* MPPortManipulationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPortManipulationTest.m; sourceTree = "<group>"; };
6E44A00C0E2DAD66007DE8EC /* ToDo.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ToDo.txt; sourceTree = "<group>"; };
@@ -371,6 +375,8 @@
6E270D080E158CED00BAE687 /* MPNotifications.m */,
6EE6DDCC0E6276AA00FB2115 /* MPNotifications+IPCAdditions.h */,
6EE6DDCD0E6276AA00FB2115 /* MPNotifications+IPCAdditions.m */,
+ 6E31A02B0E6CFB51002804D0 /* Notification+ThreadAdditions.h */,
+ 6E31A02C0E6CFB51002804D0 /* Notification+ThreadAdditions.m */,
);
name = "Tcl Notifications ";
sourceTree = "<group>";
@@ -428,6 +434,7 @@
6E8563B90E5DDF7000C1D73C /* MPHelperNotificationsCommon.h in Headers */,
6E8563BA0E5DDF7000C1D73C /* MPHelperNotificationsProtocol.h in Headers */,
6EE6DDCE0E6276AA00FB2115 /* MPNotifications+IPCAdditions.h in Headers */,
+ 6E31A02D0E6CFB51002804D0 /* Notification+ThreadAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -681,6 +688,7 @@
6EC2609A0E4272D20013BC48 /* MPHelperCommon.c in Sources */,
6E8563B80E5DDF7000C1D73C /* MPHelperNotificationsCommon.c in Sources */,
6EE6DDCF0E6276AA00FB2115 /* MPNotifications+IPCAdditions.m in Sources */,
+ 6E31A02E0E6CFB51002804D0 /* Notification+ThreadAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.h
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.h (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.h 2008-09-02 06:42:18 UTC (rev 39738)
@@ -0,0 +1,27 @@
+//
+// Notification+ThreadAdditions.h
+// MacPorts.Framework
+//
+// Created by George Armah on 9/1/08.
+// Copyright 2008 Lafayette College. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+// Using code from CococaDev to post Notifications to main thread
+// http://www.cocoadev.com/index.pl?NotificationsAcrossThreads
+
+ at interface NSNotificationCenter (NSNotificationCenterAdditions)
+- (void) postNotificationOnMainThread:(NSNotification *) notification;
+- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait;
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object;
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo;
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait;
+ at end
+
+ at interface NSNotificationQueue (NSNotificationQueueAdditions)
+- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle;
+- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes;
+ at end
\ No newline at end of file
Property changes on: branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.h
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.m
===================================================================
--- branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.m (rev 0)
+++ branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.m 2008-09-02 06:42:18 UTC (rev 39738)
@@ -0,0 +1,86 @@
+//
+// Notification+ThreadAdditions.m
+// MacPorts.Framework
+//
+// Created by George Armah on 9/1/08.
+// Copyright 2008 Lafayette College. All rights reserved.
+//
+
+#import "Notification+ThreadAdditions.h"
+#import <pthread.h>
+
+
+ at implementation NSNotificationCenter (NSNotificationCenterAdditions)
+- (void) postNotificationOnMainThread:(NSNotification *) notification {
+ if( pthread_main_np() ) return [self postNotification:notification];
+ [self postNotificationOnMainThread:notification waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait {
+ if( pthread_main_np() ) return [self postNotification:notification];
+ [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait];
+}
+
++ (void) _postNotification:(NSNotification *) notification {
+ [[self defaultCenter] postNotification:notification];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil];
+ [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
+ [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
+}
+
+- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait {
+ if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo];
+
+ NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init];
+ [info setObject:name forKey:@"name"];
+ if( object ) [info setObject:object forKey:@"object"];
+ if( userInfo ) [info setObject:userInfo forKey:@"userInfo"];
+
+ [[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait];
+ [info release];
+}
+
++ (void) _postNotificationName:(NSDictionary *) info {
+ NSString *name = [info objectForKey:@"name"];
+ id object = [info objectForKey:@"object"];
+ NSDictionary *userInfo = [info objectForKey:@"userInfo"];
+
+ [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo];
+}
+ at end
+
+ at implementation NSNotificationQueue (NSNotificationQueueAdditions)
+- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle {
+ if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil];
+ [self enqueueNotificationOnMainThread:notification postingStyle:postingStyle coalesceMask:( NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender ) forModes:nil];
+}
+
+- (void) enqueueNotificationOnMainThread:(NSNotification *) notification postingStyle:(NSPostingStyle) postingStyle coalesceMask:(unsigned) coalesceMask forModes:(NSArray *) modes {
+ if( pthread_main_np() ) return [self enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];
+
+ NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] init];
+ [info setObject:notification forKey:@"notification"];
+ [info setObject:[NSNumber numberWithUnsignedInt:postingStyle] forKey:@"postingStyle"];
+ [info setObject:[NSNumber numberWithUnsignedInt:coalesceMask] forKey:@"coalesceMask"];
+ if( modes ) [info setObject:modes forKey:@"modes"];
+
+ [[self class] performSelectorOnMainThread:@selector( _enqueueNotification: ) withObject:info waitUntilDone:NO];
+ [info release];
+}
+
++ (void) _enqueueNotification:(NSDictionary *) info {
+ NSNotification *notification = [info objectForKey:@"notification"];
+ NSPostingStyle postingStyle = [[info objectForKey:@"postingStyle"] unsignedIntValue];
+ unsigned coalesceMask = [[info objectForKey:@"coalesceMask"] unsignedIntValue];
+ NSArray *modes = [info objectForKey:@"modes"];
+
+ [[self defaultQueue] enqueueNotification:notification postingStyle:postingStyle coalesceMask:coalesceMask forModes:modes];
+}
+ at end
\ No newline at end of file
Property changes on: branches/gsoc08-framework/MacPorts_Framework_Release/Notification+ThreadAdditions.m
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080901/f4e47b3e/attachment.html
More information about the macports-changes
mailing list