Mercurial > projects > dwt-mac
diff dwt/internal/cocoa/NSThread.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 8b48be5454ce |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/cocoa/NSThread.d Sat Aug 09 17:00:02 2008 +0200 @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * + * Port to the D Programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> + *******************************************************************************/ +module dwt.internal.cocoa.NSThread; + +import dwt.internal.cocoa.id; +import dwt.internal.cocoa.NSArray; +import dwt.internal.cocoa.NSDate; +import dwt.internal.cocoa.NSInteger; +import dwt.internal.cocoa.NSMutableDictionary; +import dwt.internal.cocoa.NSObject; +import dwt.internal.cocoa.NSString; +import dwt.internal.cocoa.OS; +import objc = dwt.internal.objc.runtime; + +public class NSThread : NSObject +{ + + public this () + { + super(); + } + + public this (objc.id id) + { + super(id); + } + + public static NSArray callStackReturnAddresses () + { + objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_callStackReturnAddresses); + return result !is null ? new NSArray(result) : null; + } + + public void cancel () + { + OS.objc_msgSend(this.id, OS.sel_cancel); + } + + public static NSThread currentThread () + { + objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_currentThread); + return result !is null ? new NSThread(result) : null; + } + + public static void detachNewThreadSelector (objc.SEL selector, id target, id argument) + { + OS.objc_msgSend(OS.class_NSThread, OS.sel_detachNewThreadSelector_1toTarget_1withObject_1, selector, target !is null ? target.id : null, + argument !is null ? argument.id : null); + } + + public static void exit () + { + OS.objc_msgSend(OS.class_NSThread, OS.sel_exit); + } + + public id initWithTarget (id target, objc.SEL selector, id argument) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithTarget_1selector_1object_1, target !is null ? target.id : null, selector, + argument !is null ? argument.id : null); + return result !is null ? new id(result) : null; + } + + public bool isCancelled () + { + return OS.objc_msgSend(this.id, OS.sel_isCancelled) !is null; + } + + public bool isExecuting () + { + return OS.objc_msgSend(this.id, OS.sel_isExecuting) !is null; + } + + public bool isFinished () + { + return OS.objc_msgSend(this.id, OS.sel_isFinished) !is null; + } + + public static bool static_isMainThread () + { + return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMainThread) !is null; + } + + public bool isMainThread () + { + return OS.objc_msgSend(this.id, OS.sel_isMainThread) !is null; + } + + public static bool isMultiThreaded () + { + return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMultiThreaded) !is null; + } + + public void main () + { + OS.objc_msgSend(this.id, OS.sel_main); + } + + public static NSThread mainThread () + { + objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_mainThread); + return result !is null ? new NSThread(result) : null; + } + + public NSString name () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_name); + return result !is null ? new NSString(result) : null; + } + + public void setName (NSString n) + { + OS.objc_msgSend(this.id, OS.sel_setName_1, n !is null ? n.id : null); + } + + public void setStackSize (NSUInteger s) + { + OS.objc_msgSend(this.id, OS.sel_setStackSize_1, s); + } + + public static bool setThreadPriority (double p) + { + return OS.objc_msgSend(OS.class_NSThread, OS.sel_setThreadPriority_1, p) !is null; + } + + public static void sleepForTimeInterval (NSTimeInterval ti) + { + OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepForTimeInterval_1, ti); + } + + public static void sleepUntilDate (NSDate date) + { + OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepUntilDate_1, date !is null ? date.id : null); + } + + public NSUInteger stackSize () + { + return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_stackSize); + } + + public void start () + { + OS.objc_msgSend(this.id, OS.sel_start); + } + + public NSMutableDictionary threadDictionary () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_threadDictionary); + return result !is null ? new NSMutableDictionary(result) : null; + } + + public static double threadPriority () + { + return OS.objc_msgSend_fpret(OS.class_NSThread, OS.sel_threadPriority); + } + +}