diff dstep/foundation/NSThread.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 7ff919f595d5
children b9de51448c6b
line wrap: on
line diff
--- a/dstep/foundation/NSThread.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSThread.d	Sun Jan 03 22:06:11 2010 +0100
@@ -8,41 +8,109 @@
 
 import dstep.foundation.NSArray;
 import dstep.foundation.NSDate;
-import dstep.foundation.NSMutableDictionary;
+import dstep.foundation.NSDictionary;
+import dstep.foundation.NSObjCRuntime;
 import dstep.foundation.NSObject;
+import dstep.foundation.NSString;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
+
 
 import bindings = dstep.foundation.NSThread_bindings;
 
-const NSString NSWillBecomeMultiThreadedNotification;
-const NSString NSDidBecomeSingleThreadedNotification;
-const NSString NSThreadWillExitNotification;
+private
+{
+	NSString NSWillBecomeMultiThreadedNotification_;
+	NSString NSDidBecomeSingleThreadedNotification_;
+	NSString NSThreadWillExitNotification_;
+}
+
+NSString NSWillBecomeMultiThreadedNotification ()
+{
+	if (NSWillBecomeMultiThreadedNotification_)
+		return NSWillBecomeMultiThreadedNotification_;
+		
+	return NSWillBecomeMultiThreadedNotification_ = new NSString(bindings.NSWillBecomeMultiThreadedNotification);
+}
+
+NSString NSDidBecomeSingleThreadedNotification ()
+{
+	if (NSDidBecomeSingleThreadedNotification_)
+		return NSDidBecomeSingleThreadedNotification_;
+		
+	return NSDidBecomeSingleThreadedNotification_ = new NSString(bindings.NSDidBecomeSingleThreadedNotification);
+}
+
+NSString NSThreadWillExitNotification ()
+{
+	if (NSThreadWillExitNotification_)
+		return NSThreadWillExitNotification_;
+		
+	return NSThreadWillExitNotification_ = new NSString(bindings.NSThreadWillExitNotification);
+}
+
 
-static this ()
-{
-	NSWillBecomeMultiThreadedNotification = new NSString(bindings.NSWillBecomeMultiThreadedNotification);
-	NSDidBecomeSingleThreadedNotification = new NSString(bindings.NSDidBecomeSingleThreadedNotification);
-	NSThreadWillExitNotification = new NSString(bindings.NSThreadWillExitNotification);
-}
+const TNSThreadPerformAdditions = `
+
+	void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait, NSArray array)
+	{
+		return invokeObjcSelf!(void, "performSelectorOnMainThread:withObject:waitUntilDone:modes", SEL, Object, bool, NSArray)(aSelector, arg, wait, array);
+	}
+	
+	void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait)
+	{
+		return invokeObjcSelf!(void, "performSelectorOnMainThread:withObject:waitUntilDone:", SEL, Object, bool)(aSelector, arg, wait);
+	}
+	
+	void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait, NSArray array)
+	{
+		return invokeObjcSelf!(void, "performSelector:onThread:withObject:waitUntilDone:modes:", SEL, NSThread, Object, bool, NSArray)(aSelector, thr, arg, wait, array);
+	}
+	
+	void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait)
+	{
+		return invokeObjcSelf!(void, "performSelector:onThread:withObject:waitUntilDone:", SEL, NSThread, Object, bool)(aSelector, thr, arg, wait);
+	}
+	
+	void performSelectorInBackground (SEL aSelector, Object arg)
+	{
+		return invokeObjcSelf!(void, "performSelectorInBackground:withObject:", SEL, Object)(aSelector, arg);
+	}
+	
+	//mixin ObjcBindMethod!(performSelectorOnMainThread, void, "performSelectorOnMainThread:withObject:waitUntilDone:modes:", SEL, Object, bool, NSArray);
+	//mixin ObjcBindMethod!(performSelectorOnMainThread, void, "performSelectorOnMainThread:withObject:waitUntilDone:", SEL, Object, bool);
+	//mixin ObjcBindMethod!(performSelector, void, "performSelector:onThread:withObject:waitUntilDone:modes:", SEL, NSThread, Object, bool, NSArray);
+	//mixin ObjcBindMethod!(performSelector, void, "performSelector:onThread:withObject:waitUntilDone:", SEL, NSThread, Object, bool);
+	//mixin ObjcBindMethod!(performSelectorInBackground, void, "performSelectorInBackground:withObject:", SEL, Object);
+`;
 
 class NSThread : NSObject
 {
-	mixin ObjcWrap;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	static NSThread currentThread ()
 	{
-		return invokeObjcSelfClass!(NSThread, "currentThread");
+		return invokeObjcSuperClass!(NSThread, "currentThread");
 	}
 
 	static void detachNewThreadSelector (SEL selector, Object target, Object argument)
 	{
-		return invokeObjcSelfClass!(void, "detachNewThreadSelector:toTarget:withObject:", SEL, Object, Object)(selector, target, argument);
+		return invokeObjcSuperClass!(void, "detachNewThreadSelector:toTarget:withObject:", SEL, Object, Object)(selector, target, argument);
 	}
 
 	static bool isMultiThreaded ()
 	{
-		return invokeObjcSelfClass!(bool, "isMultiThreaded");
+		return invokeObjcSuperClass!(bool, "isMultiThreaded");
 	}
 
 	NSMutableDictionary threadDictionary ()
@@ -52,32 +120,32 @@
 
 	static void sleepUntilDate (NSDate date)
 	{
-		return invokeObjcSelfClass!(void, "sleepUntilDate:", NSDate)(date);
+		return invokeObjcSuperClass!(void, "sleepUntilDate:", NSDate)(date);
 	}
 
 	static void sleepForTimeInterval (double ti)
 	{
-		return invokeObjcSelfClass!(void, "sleepForTimeInterval:", double)(ti);
+		return invokeObjcSuperClass!(void, "sleepForTimeInterval:", double)(ti);
 	}
 
 	static void exit ()
 	{
-		return invokeObjcSelfClass!(void, "exit");
+		return invokeObjcSuperClass!(void, "exit");
 	}
 
 	static double threadPriority ()
 	{
-		return invokeObjcSelfClass!(double, "threadPriority");
+		return invokeObjcSuperClass!(double, "threadPriority");
 	}
 
 	static bool setThreadPriority (double p)
 	{
-		return invokeObjcSelfClass!(bool, "setThreadPriority:", double)(p);
+		return invokeObjcSuperClass!(bool, "setThreadPriority:", double)(p);
 	}
 
 	static NSArray callStackReturnAddresses ()
 	{
-		return invokeObjcSelfClass!(NSArray, "callStackReturnAddresses");
+		return invokeObjcSuperClass!(NSArray, "callStackReturnAddresses");
 	}
 
 	void setName (NSString n)
@@ -105,30 +173,14 @@
 		return invokeObjcSelf!(bool, "isMainThread");
 	}
 
-	static bool isMainThread ()
+	static bool isMainThread_static ()
 	{
-		return invokeObjcSelfClass!(bool, "isMainThread");
+		return invokeObjcSuperClass!(bool, "isMainThread");
 	}
 
 	static NSThread mainThread ()
 	{
-		return invokeObjcSelfClass!(NSThread, "mainThread");
-	}
-
-	Object init ()
-	{
-		return invokeObjcSelf!(Object, "init");
-	}
-
-	this ()
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "init")(objcObject);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		return invokeObjcSuperClass!(NSThread, "mainThread");
 	}
 
 	Object initWithTarget (Object target, SEL selector, Object argument)
@@ -138,13 +190,7 @@
 
 	this (Object target, SEL selector, Object argument)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithTarget:selector:object:", Object, SEL, Object)(objcObject, target, selector, argument);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithTarget(target, selector, argument);
 	}
 
 	bool isExecuting ()
@@ -176,14 +222,4 @@
 	{
 		return invokeObjcSelf!(void, "main");
 	}
-}
-
-template TNSThreadPerformAdditions ()
-{
-	void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait, NSArray array);
-	void performSelectorOnMainThread (SEL aSelector, Object arg, bool wait);
-	void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait, NSArray array);
-	void performSelector (SEL aSelector, NSThread thr, Object arg, bool wait);
-	void performSelectorInBackground (SEL aSelector, Object arg);
-}
-
+}
\ No newline at end of file