comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *
11 * Port to the D Programming language:
12 * Jacob Carlborg <jacob.carlborg@gmail.com>
13 *******************************************************************************/
14 module dwt.internal.cocoa.NSThread;
15
16 import dwt.internal.cocoa.id;
17 import dwt.internal.cocoa.NSArray;
18 import dwt.internal.cocoa.NSDate;
19 import dwt.internal.cocoa.NSInteger;
20 import dwt.internal.cocoa.NSMutableDictionary;
21 import dwt.internal.cocoa.NSObject;
22 import dwt.internal.cocoa.NSString;
23 import dwt.internal.cocoa.OS;
24 import objc = dwt.internal.objc.runtime;
25
26 public class NSThread : NSObject
27 {
28
29 public this ()
30 {
31 super();
32 }
33
34 public this (objc.id id)
35 {
36 super(id);
37 }
38
39 public static NSArray callStackReturnAddresses ()
40 {
41 objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_callStackReturnAddresses);
42 return result !is null ? new NSArray(result) : null;
43 }
44
45 public void cancel ()
46 {
47 OS.objc_msgSend(this.id, OS.sel_cancel);
48 }
49
50 public static NSThread currentThread ()
51 {
52 objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_currentThread);
53 return result !is null ? new NSThread(result) : null;
54 }
55
56 public static void detachNewThreadSelector (objc.SEL selector, id target, id argument)
57 {
58 OS.objc_msgSend(OS.class_NSThread, OS.sel_detachNewThreadSelector_1toTarget_1withObject_1, selector, target !is null ? target.id : null,
59 argument !is null ? argument.id : null);
60 }
61
62 public static void exit ()
63 {
64 OS.objc_msgSend(OS.class_NSThread, OS.sel_exit);
65 }
66
67 public id initWithTarget (id target, objc.SEL selector, id argument)
68 {
69 objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithTarget_1selector_1object_1, target !is null ? target.id : null, selector,
70 argument !is null ? argument.id : null);
71 return result !is null ? new id(result) : null;
72 }
73
74 public bool isCancelled ()
75 {
76 return OS.objc_msgSend(this.id, OS.sel_isCancelled) !is null;
77 }
78
79 public bool isExecuting ()
80 {
81 return OS.objc_msgSend(this.id, OS.sel_isExecuting) !is null;
82 }
83
84 public bool isFinished ()
85 {
86 return OS.objc_msgSend(this.id, OS.sel_isFinished) !is null;
87 }
88
89 public static bool static_isMainThread ()
90 {
91 return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMainThread) !is null;
92 }
93
94 public bool isMainThread ()
95 {
96 return OS.objc_msgSend(this.id, OS.sel_isMainThread) !is null;
97 }
98
99 public static bool isMultiThreaded ()
100 {
101 return OS.objc_msgSend(OS.class_NSThread, OS.sel_isMultiThreaded) !is null;
102 }
103
104 public void main ()
105 {
106 OS.objc_msgSend(this.id, OS.sel_main);
107 }
108
109 public static NSThread mainThread ()
110 {
111 objc.id result = OS.objc_msgSend(OS.class_NSThread, OS.sel_mainThread);
112 return result !is null ? new NSThread(result) : null;
113 }
114
115 public NSString name ()
116 {
117 objc.id result = OS.objc_msgSend(this.id, OS.sel_name);
118 return result !is null ? new NSString(result) : null;
119 }
120
121 public void setName (NSString n)
122 {
123 OS.objc_msgSend(this.id, OS.sel_setName_1, n !is null ? n.id : null);
124 }
125
126 public void setStackSize (NSUInteger s)
127 {
128 OS.objc_msgSend(this.id, OS.sel_setStackSize_1, s);
129 }
130
131 public static bool setThreadPriority (double p)
132 {
133 return OS.objc_msgSend(OS.class_NSThread, OS.sel_setThreadPriority_1, p) !is null;
134 }
135
136 public static void sleepForTimeInterval (NSTimeInterval ti)
137 {
138 OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepForTimeInterval_1, ti);
139 }
140
141 public static void sleepUntilDate (NSDate date)
142 {
143 OS.objc_msgSend(OS.class_NSThread, OS.sel_sleepUntilDate_1, date !is null ? date.id : null);
144 }
145
146 public NSUInteger stackSize ()
147 {
148 return cast(NSUInteger) OS.objc_msgSend(this.id, OS.sel_stackSize);
149 }
150
151 public void start ()
152 {
153 OS.objc_msgSend(this.id, OS.sel_start);
154 }
155
156 public NSMutableDictionary threadDictionary ()
157 {
158 objc.id result = OS.objc_msgSend(this.id, OS.sel_threadDictionary);
159 return result !is null ? new NSMutableDictionary(result) : null;
160 }
161
162 public static double threadPriority ()
163 {
164 return OS.objc_msgSend_fpret(OS.class_NSThread, OS.sel_threadPriority);
165 }
166
167 }