14
|
1 /**
|
|
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Aug 3, 2009
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module dstep.foundation.NSConnection;
|
|
8
|
|
9 import dstep.foundation.NSArray;
|
|
10 import dstep.foundation.NSData;
|
|
11 import dstep.foundation.NSDate;
|
|
12 import dstep.foundation.NSDictionary;
|
|
13 import dstep.foundation.NSDistantObject;
|
|
14 import dstep.foundation.NSException;
|
|
15 import dstep.foundation.NSMutableData;
|
|
16 import dstep.foundation.NSObject;
|
|
17 import dstep.foundation.NSPort;
|
|
18 import dstep.foundation.NSPortNameServer;
|
|
19 import dstep.foundation.NSRunLoop;
|
|
20 import dstep.objc.bridge.Bridge;
|
|
21 import dstep.objc.objc : id;
|
|
22
|
|
23 import bindings = dstep.foundation.NSConnection_bindings;
|
|
24
|
|
25 const NSString NSConnectionReplyMode;
|
|
26 const NSString NSConnectionDidDieNotification;
|
|
27 const NSString NSFailedAuthenticationException;
|
|
28 const NSString NSConnectionDidInitializeNotification;
|
|
29
|
|
30 static this ()
|
|
31 {
|
|
32 NSConnectionReplyMode = new NSString(bindings.NSConnectionReplyMode);
|
|
33 NSConnectionDidDieNotification = new NSString(bindings.NSConnectionDidDieNotification);
|
|
34 NSFailedAuthenticationException = new NSString(bindings.NSFailedAuthenticationException);
|
|
35 NSConnectionDidInitializeNotification = new NSString(bindings.NSConnectionDidInitializeNotification);
|
|
36 }
|
|
37
|
|
38 class NSDistantObjectRequest : NSObject
|
|
39 {
|
|
40 mixin ObjcWrap;
|
|
41
|
|
42 NSInvocation invocation ()
|
|
43 {
|
|
44 return invokeObjcSelf!(NSInvocation, "invocation");
|
|
45 }
|
|
46
|
|
47 NSConnection connection ()
|
|
48 {
|
|
49 return invokeObjcSelf!(NSConnection, "connection");
|
|
50 }
|
|
51
|
|
52 Object conversation ()
|
|
53 {
|
|
54 return invokeObjcSelf!(Object, "conversation");
|
|
55 }
|
|
56
|
|
57 void replyWithException (NSException exception)
|
|
58 {
|
|
59 return invokeObjcSelf!(void, "replyWithException:", NSException)(exception);
|
|
60 }
|
|
61 }
|
|
62
|
|
63 class NSConnection : NSObject
|
|
64 {
|
|
65 mixin ObjcWrap;
|
|
66
|
|
67 NSDictionary statistics ()
|
|
68 {
|
|
69 return invokeObjcSelf!(NSDictionary, "statistics");
|
|
70 }
|
|
71
|
|
72 static NSArray allConnections ()
|
|
73 {
|
|
74 return invokeObjcSelfClass!(NSArray, "allConnections");
|
|
75 }
|
|
76
|
|
77 static NSConnection defaultConnection ()
|
|
78 {
|
|
79 return invokeObjcSelfClass!(NSConnection, "defaultConnection"return result is this.objcObject ? this : (result !is null ? new NSConnection(result) : null); }
|
|
80
|
|
81 static Object connectionWithRegisteredName (NSString name, NSString hostName)
|
|
82 {
|
|
83 return invokeObjcSelfClass!(Object, "connectionWithRegisteredName:host:", NSString, NSString)(name, hostName);
|
|
84 }
|
|
85
|
|
86 static Object connectionWithRegisteredName (NSString name, NSString hostName, NSPortNameServer server)
|
|
87 {
|
|
88 return invokeObjcSelfClass!(Object, "connectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server);
|
|
89 }
|
|
90
|
|
91 static NSDistantObject rootProxyForConnectionWithRegisteredName (NSString name, NSString hostName)
|
|
92 {
|
|
93 return invokeObjcSelfClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:", NSString, NSString)(name, hostName);
|
|
94 }
|
|
95
|
|
96 static NSDistantObject rootProxyForConnectionWithRegisteredName (NSString name, NSString hostName, NSPortNameServer server)
|
|
97 {
|
|
98 return invokeObjcSelfClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server);
|
|
99 }
|
|
100
|
|
101 static Object serviceConnectionWithName (NSString name, Object root, NSPortNameServer server)
|
|
102 {
|
|
103 return invokeObjcSelfClass!(Object, "serviceConnectionWithName:rootObject:usingNameServer:", NSString, Object, NSPortNameServer)(name, root, server);
|
|
104 }
|
|
105
|
|
106 static Object serviceConnectionWithName (NSString name, Object root)
|
|
107 {
|
|
108 return invokeObjcSelfClass!(Object, "serviceConnectionWithName:rootObject:", NSString, Object)(name, root);
|
|
109 }
|
|
110
|
|
111 void setRequestTimeout (double ti)
|
|
112 {
|
|
113 return invokeObjcSelf!(void, "setRequestTimeout:", double)(ti);
|
|
114 }
|
|
115
|
|
116 double requestTimeout ()
|
|
117 {
|
|
118 return invokeObjcSelf!(double, "requestTimeout");
|
|
119 }
|
|
120
|
|
121 void setReplyTimeout (double ti)
|
|
122 {
|
|
123 return invokeObjcSelf!(void, "setReplyTimeout:", double)(ti);
|
|
124 }
|
|
125
|
|
126 double replyTimeout ()
|
|
127 {
|
|
128 return invokeObjcSelf!(double, "replyTimeout");
|
|
129 }
|
|
130
|
|
131 void setRootObject (Object anObject)
|
|
132 {
|
|
133 return invokeObjcSelf!(void, "setRootObject:", Object)(anObject);
|
|
134 }
|
|
135
|
|
136 Object rootObject ()
|
|
137 {
|
|
138 return invokeObjcSelf!(Object, "rootObject");
|
|
139 }
|
|
140
|
|
141 NSDistantObject rootProxy ()
|
|
142 {
|
|
143 return invokeObjcSelf!(NSDistantObject, "rootProxy");
|
|
144 }
|
|
145
|
|
146 void setDelegate (Object anObject)
|
|
147 {
|
|
148 return invokeObjcSelf!(void, "setDelegate:", Object)(anObject);
|
|
149 }
|
|
150
|
|
151 Object delegate_ ()
|
|
152 {
|
|
153 return invokeObjcSelf!(Object, "delegate");
|
|
154 }
|
|
155
|
|
156 void setIndependentConversationQueueing (bool yorn)
|
|
157 {
|
|
158 return invokeObjcSelf!(void, "setIndependentConversationQueueing:", bool)(yorn);
|
|
159 }
|
|
160
|
|
161 bool independentConversationQueueing ()
|
|
162 {
|
|
163 return invokeObjcSelf!(bool, "independentConversationQueueing");
|
|
164 }
|
|
165
|
|
166 bool isValid ()
|
|
167 {
|
|
168 return invokeObjcSelf!(bool, "isValid");
|
|
169 }
|
|
170
|
|
171 void invalidate ()
|
|
172 {
|
|
173 return invokeObjcSelf!(void, "invalidate");
|
|
174 }
|
|
175
|
|
176 void addRequestMode (NSString rmode)
|
|
177 {
|
|
178 return invokeObjcSelf!(void, "addRequestMode:", NSString)(rmode);
|
|
179 }
|
|
180
|
|
181 void removeRequestMode (NSString rmode)
|
|
182 {
|
|
183 return invokeObjcSelf!(void, "removeRequestMode:", NSString)(rmode);
|
|
184 }
|
|
185
|
|
186 NSArray requestModes ()
|
|
187 {
|
|
188 return invokeObjcSelf!(NSArray, "requestModes");
|
|
189 }
|
|
190
|
|
191 bool registerName (NSString name)
|
|
192 {
|
|
193 return invokeObjcSelf!(bool, "registerName:", NSString)(name);
|
|
194 }
|
|
195
|
|
196 bool registerName (NSString name, NSPortNameServer server)
|
|
197 {
|
|
198 return invokeObjcSelf!(bool, "registerName:withNameServer:", NSString, NSPortNameServer)(name, server);
|
|
199 }
|
|
200
|
|
201 static Object connectionWithReceivePort (NSPort receivePort, NSPort sendPort)
|
|
202 {
|
|
203 return invokeObjcSelfClass!(Object, "connectionWithReceivePort:sendPort:", NSPort, NSPort)(receivePort, sendPort);
|
|
204 }
|
|
205
|
|
206 static Object currentConversation ()
|
|
207 {
|
|
208 return invokeObjcSelfClass!(Object, "currentConversation");
|
|
209 }
|
|
210
|
|
211 Object initWithReceivePort (NSPort receivePort, NSPort sendPort)
|
|
212 {
|
|
213 return invokeObjcSelf!(Object, "initWithReceivePort:sendPort:", NSPort, NSPort)(receivePort, sendPort);
|
|
214 }
|
|
215
|
|
216 this (NSPort receivePort, NSPort sendPort)
|
|
217 {
|
|
218 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
219 id result = Bridge.invokeObjcMethod!(id, "initWithReceivePort:sendPort:", NSPort, NSPort)(objcObject, receivePort, sendPort);
|
|
220
|
|
221 if (result)
|
|
222 objcObject = ret;
|
|
223
|
|
224 dObject = this;
|
|
225 }
|
|
226
|
|
227 NSPort sendPort ()
|
|
228 {
|
|
229 return invokeObjcSelf!(NSPort, "sendPort");
|
|
230 }
|
|
231
|
|
232 NSPort receivePort ()
|
|
233 {
|
|
234 return invokeObjcSelf!(NSPort, "receivePort");
|
|
235 }
|
|
236
|
|
237 void enableMultipleThreads ()
|
|
238 {
|
|
239 return invokeObjcSelf!(void, "enableMultipleThreads");
|
|
240 }
|
|
241
|
|
242 bool multipleThreadsEnabled ()
|
|
243 {
|
|
244 return invokeObjcSelf!(bool, "multipleThreadsEnabled");
|
|
245 }
|
|
246
|
|
247 void addRunLoop (NSRunLoop runloop)
|
|
248 {
|
|
249 return invokeObjcSelf!(void, "addRunLoop:", NSRunLoop)(runloop);
|
|
250 }
|
|
251
|
|
252 void removeRunLoop (NSRunLoop runloop)
|
|
253 {
|
|
254 return invokeObjcSelf!(void, "removeRunLoop:", NSRunLoop)(runloop);
|
|
255 }
|
|
256
|
|
257 void runInNewThread ()
|
|
258 {
|
|
259 return invokeObjcSelf!(void, "runInNewThread");
|
|
260 }
|
|
261
|
|
262 NSArray remoteObjects ()
|
|
263 {
|
|
264 return invokeObjcSelf!(NSArray, "remoteObjects");
|
|
265 }
|
|
266
|
|
267 NSArray localObjects ()
|
|
268 {
|
|
269 return invokeObjcSelf!(NSArray, "localObjects");
|
|
270 }
|
|
271 }
|
|
272
|
|
273 template TNSDistantObjectRequestMethods ()
|
|
274 {
|
|
275 bool connection (NSConnection connection, NSDistantObjectRequest doreq);
|
|
276 }
|
|
277
|
|
278 template TNSConnectionDelegateMethods ()
|
|
279 {
|
|
280 bool makeNewConnection (NSConnection conn, NSConnection ancestor);
|
|
281 bool connection (NSConnection ancestor, NSConnection conn);
|
|
282 NSData authenticationDataForComponents (NSArray components);
|
|
283 bool authenticateComponents (NSArray components, NSData signature);
|
|
284 Object createConversationForConnection (NSConnection conn);
|
|
285 }
|
|
286
|