diff dstep/foundation/NSThread.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 7ff919f595d5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSThread.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,187 @@
+/**
+ * Copyright: Copyright (c) 2009 Jacob Carlborg.
+ * Authors: Jacob Carlborg
+ * Version: Initial created: Aug 3, 2009 
+ * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
+ */
+module dstep.foundation.NSThread;
+
+import dstep.foundation.NSArray;
+import dstep.foundation.NSDate;
+import dstep.foundation.NSMutableDictionary;
+import dstep.foundation.NSObject;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+import bindings = dstep.foundation.NSThread_bindings;
+
+const NSString NSWillBecomeMultiThreadedNotification;
+const NSString NSDidBecomeSingleThreadedNotification;
+const NSString NSThreadWillExitNotification;
+
+static this ()
+{
+	NSWillBecomeMultiThreadedNotification = new NSString(bindings.NSWillBecomeMultiThreadedNotification);
+	NSDidBecomeSingleThreadedNotification = new NSString(bindings.NSDidBecomeSingleThreadedNotification);
+	NSThreadWillExitNotification = new NSString(bindings.NSThreadWillExitNotification);
+}
+
+class NSThread : NSObject
+{
+	mixin ObjcWrap;
+
+	static NSThread currentThread ()
+	{
+		return invokeObjcSelfClass!(NSThread, "currentThread"return result is this.objcObject ? this : (result !is null ? new NSThread(result) : null);	}
+
+	static void detachNewThreadSelector (SEL selector, Object target, Object argument)
+	{
+		return invokeObjcSelfClass!(void, "detachNewThreadSelector:toTarget:withObject:", SEL, Object, Object)(selector, target, argument);
+	}
+
+	static bool isMultiThreaded ()
+	{
+		return invokeObjcSelfClass!(bool, "isMultiThreaded");
+	}
+
+	NSMutableDictionary threadDictionary ()
+	{
+		return invokeObjcSelf!(NSMutableDictionary, "threadDictionary");
+	}
+
+	static void sleepUntilDate (NSDate date)
+	{
+		return invokeObjcSelfClass!(void, "sleepUntilDate:", NSDate)(date);
+	}
+
+	static void sleepForTimeInterval (double ti)
+	{
+		return invokeObjcSelfClass!(void, "sleepForTimeInterval:", double)(ti);
+	}
+
+	static void exit ()
+	{
+		return invokeObjcSelfClass!(void, "exit");
+	}
+
+	static double threadPriority ()
+	{
+		return invokeObjcSelfClass!(double, "threadPriority");
+	}
+
+	static bool setThreadPriority (double p)
+	{
+		return invokeObjcSelfClass!(bool, "setThreadPriority:", double)(p);
+	}
+
+	static NSArray callStackReturnAddresses ()
+	{
+		return invokeObjcSelfClass!(NSArray, "callStackReturnAddresses");
+	}
+
+	void setName (NSString n)
+	{
+		return invokeObjcSelf!(void, "setName:", NSString)(n);
+	}
+
+	NSString name ()
+	{
+		return invokeObjcSelf!(NSString, "name");
+	}
+
+	NSUInteger stackSize ()
+	{
+		return invokeObjcSelf!(NSUInteger, "stackSize");
+	}
+
+	void setStackSize (NSUInteger s)
+	{
+		return invokeObjcSelf!(void, "setStackSize:", NSUInteger)(s);
+	}
+
+	bool isMainThread ()
+	{
+		return invokeObjcSelf!(bool, "isMainThread");
+	}
+
+	static bool isMainThread ()
+	{
+		return invokeObjcSelfClass!(bool, "isMainThread");
+	}
+
+	static NSThread mainThread ()
+	{
+		return invokeObjcSelfClass!(NSThread, "mainThread"return result is this.objcObject ? this : (result !is null ? new NSThread(result) : null);	}
+
+	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;
+	}
+
+	Object initWithTarget (Object target, SEL selector, Object argument)
+	{
+		return invokeObjcSelf!(Object, "initWithTarget:selector:object:", Object, SEL, Object)(target, selector, argument);
+	}
+
+	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;
+	}
+
+	bool isExecuting ()
+	{
+		return invokeObjcSelf!(bool, "isExecuting");
+	}
+
+	bool isFinished ()
+	{
+		return invokeObjcSelf!(bool, "isFinished");
+	}
+
+	bool isCancelled ()
+	{
+		return invokeObjcSelf!(bool, "isCancelled");
+	}
+
+	void cancel ()
+	{
+		return invokeObjcSelf!(void, "cancel");
+	}
+
+	void start ()
+	{
+		return invokeObjcSelf!(void, "start");
+	}
+
+	void main ()
+	{
+		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);
+}
+