Mercurial > projects > dstep
comparison dstep/foundation/NSURLConnection.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 |
comparison
equal
deleted
inserted
replaced
15:7ff919f595d5 | 16:19885b43130e |
---|---|
4 * Version: Initial created: Aug 3, 2009 | 4 * Version: Initial created: Aug 3, 2009 |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module dstep.foundation.NSURLConnection; | 7 module dstep.foundation.NSURLConnection; |
8 | 8 |
9 import dstep.AvailabilityMacros; | |
10 import dstep.foundation.NSCachedURLResponse; | |
11 import dstep.foundation.NSData; | 9 import dstep.foundation.NSData; |
12 import dstep.foundation.NSError; | 10 import dstep.foundation.NSError; |
13 import dstep.foundation.NSObject; | 11 import dstep.foundation.NSObject; |
14 import dstep.foundation.NSRunLoop; | 12 import dstep.foundation.NSRunLoop; |
13 import dstep.foundation.NSString; | |
15 import dstep.foundation.NSURLAuthenticationChallenge; | 14 import dstep.foundation.NSURLAuthenticationChallenge; |
16 import dstep.foundation.NSURLConnectionInternal; | 15 import dstep.foundation.NSURLCache; |
17 import dstep.foundation.NSURLRequest; | 16 import dstep.foundation.NSURLRequest; |
18 import dstep.foundation.NSURLResponse; | 17 import dstep.foundation.NSURLResponse; |
19 import dstep.objc.bridge.Bridge; | 18 import dstep.objc.bridge.Bridge; |
20 import dstep.objc.objc : id; | 19 import dstep.objc.objc; |
20 | |
21 const TNSURLConnectionDelegate = ` | |
22 | |
23 NSURLRequest connection (NSURLConnection connection, NSURLRequest request, NSURLResponse response) | |
24 { | |
25 return invokeObjcSelf!(NSURLRequest, "connection:willSendRequest:redirectResponse:", NSURLConnection, NSURLRequest, NSURLResponse)(connection, request, response); | |
26 } | |
27 | |
28 void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge) | |
29 { | |
30 return invokeObjcSelf!(void, "connection:didReceiveAuthenticationChallenge:", NSURLConnection, NSURLAuthenticationChallenge)(connection, challenge); | |
31 } | |
32 | |
33 void connection_didCancelAuthenticationChallenge (NSURLConnection connection, NSURLAuthenticationChallenge challenge) | |
34 { | |
35 return invokeObjcSelf!(void, "connection:didCancelAuthenticationChallenge:", NSURLConnection, NSURLAuthenticationChallenge)(connection, challenge); | |
36 } | |
37 | |
38 void connection (NSURLConnection connection, NSURLResponse response) | |
39 { | |
40 return invokeObjcSelf!(void, "connection:didReceiveResponse:", NSURLConnection, NSURLResponse)(connection, response); | |
41 } | |
42 | |
43 void connection (NSURLConnection connection, NSData data) | |
44 { | |
45 return invokeObjcSelf!(void, "connection:didReceiveData:", NSURLConnection, NSData)(connection, data); | |
46 } | |
47 | |
48 void connectionDidFinishLoading (NSURLConnection connection) | |
49 { | |
50 return invokeObjcSelf!(void, "connectionDidFinishLoading:", NSURLConnection)(connection); | |
51 } | |
52 | |
53 void connection (NSURLConnection connection, NSError error) | |
54 { | |
55 return invokeObjcSelf!(void, "connection:didFailWithError:", NSURLConnection, NSError)(connection, error); | |
56 } | |
57 | |
58 NSCachedURLResponse connection (NSURLConnection connection, NSCachedURLResponse cachedResponse) | |
59 { | |
60 return invokeObjcSelf!(NSCachedURLResponse, "connection:willCacheResponse:", NSURLConnection, NSCachedURLResponse)(connection, cachedResponse); | |
61 } | |
62 | |
63 //mixin ObjcBindMethod!(connection, "connection:willSendRequest:redirectResponse:"); | |
64 //mixin ObjcBindMethod!(connection, "replacementObjectForArchiver:"); | |
65 //mixin ObjcBindMethod!(connection_didCancelAuthenticationChallenge, "connection:didReceiveAuthenticationChallenge:"); | |
66 //mixin ObjcBindMethod!(connection, "connection:didReceiveResponse:"); | |
67 //mixin ObjcBindMethod!(connection, "connection:didReceiveData:"); | |
68 //mixin ObjcBindMethod!(connectionDidFinishLoading, "connectionDidFinishLoading:"); | |
69 //mixin ObjcBindMethod!(connection, "connection:didFailWithError:"); | |
70 //mixin ObjcBindMethod!(connection, "connection:willCacheResponse:"); | |
71 `; | |
72 | |
73 const TNSURLConnectionSynchronousLoading = ` | |
74 | |
75 static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error) | |
76 { | |
77 return invokeObjcSuperClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error); | |
78 } | |
79 `; | |
21 | 80 |
22 class NSURLConnection : NSObject | 81 class NSURLConnection : NSObject |
23 { | 82 { |
24 mixin ObjcWrap; | 83 mixin (ObjcWrap); |
25 mixin TNSURLConnectionSynchronousLoading; | 84 |
85 this () | |
86 { | |
87 super(typeof(this).alloc.init.objcObject); | |
88 } | |
89 | |
90 typeof(this) init () | |
91 { | |
92 return invokeObjcSelf!(typeof(this), "init"); | |
93 } | |
26 | 94 |
27 static bool canHandleRequest (NSURLRequest request) | 95 static bool canHandleRequest (NSURLRequest request) |
28 { | 96 { |
29 return invokeObjcSelfClass!(bool, "canHandleRequest:", NSURLRequest)(request); | 97 return invokeObjcSuperClass!(bool, "canHandleRequest:", NSURLRequest)(request); |
30 } | 98 } |
31 | 99 |
32 static NSURLConnection connectionWithRequest (NSURLRequest request, Object delegate_) | 100 static NSURLConnection connectionWithRequest (NSURLRequest request, Object delegate_) |
33 { | 101 { |
34 return invokeObjcSelfClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); | 102 return invokeObjcSuperClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); |
35 } | 103 } |
36 | 104 |
37 Object initWithRequest (NSURLRequest request, Object delegate_) | 105 Object initWithRequest (NSURLRequest request, Object delegate_) |
38 { | 106 { |
39 return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); | 107 return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_); |
40 } | 108 } |
41 | 109 |
42 this (NSURLRequest request, Object delegate_) | 110 this (NSURLRequest request, Object delegate_) |
43 { | 111 { |
44 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 112 typeof(this).alloc.initWithRequest(request, delegate_); |
45 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:", NSURLRequest, Object)(objcObject, request, delegate_); | |
46 | |
47 if (result) | |
48 objcObject = ret; | |
49 | |
50 dObject = this; | |
51 } | 113 } |
52 | 114 |
53 Object initWithRequest (NSURLRequest request, Object delegate_, bool startImmediately) | 115 Object initWithRequest (NSURLRequest request, Object delegate_, bool startImmediately) |
54 { | 116 { |
55 return invokeObjcSelf!(Object, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(request, delegate_, startImmediately); | 117 return invokeObjcSelf!(Object, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(request, delegate_, startImmediately); |
56 } | 118 } |
57 | 119 |
58 this (NSURLRequest request, Object delegate_, bool startImmediately) | 120 this (NSURLRequest request, Object delegate_, bool startImmediately) |
59 { | 121 { |
60 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | 122 typeof(this).alloc.initWithRequest(request, delegate_, startImmediately); |
61 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(objcObject, request, delegate_, startImmediately); | |
62 | |
63 if (result) | |
64 objcObject = ret; | |
65 | |
66 dObject = this; | |
67 } | 123 } |
68 | 124 |
69 void start () | 125 void start () |
70 { | 126 { |
71 return invokeObjcSelf!(void, "start"); | 127 return invokeObjcSelf!(void, "start"); |
83 | 139 |
84 void unscheduleFromRunLoop (NSRunLoop aRunLoop, NSString mode) | 140 void unscheduleFromRunLoop (NSRunLoop aRunLoop, NSString mode) |
85 { | 141 { |
86 return invokeObjcSelf!(void, "unscheduleFromRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode); | 142 return invokeObjcSelf!(void, "unscheduleFromRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode); |
87 } | 143 } |
88 } | 144 |
89 | 145 // TNSURLConnectionSynchronousLoading |
90 template TNSURLConnectionDelegate () | |
91 { | |
92 NSURLRequest connection (NSURLConnection connection, NSURLRequest request, NSURLResponse response); | |
93 void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge); | |
94 void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge); | |
95 void connection (NSURLConnection connection, NSURLResponse response); | |
96 void connection (NSURLConnection connection, NSData data); | |
97 void connectionDidFinishLoading (NSURLConnection connection); | |
98 void connection (NSURLConnection connection, NSError error); | |
99 NSCachedURLResponse connection (NSURLConnection connection, NSCachedURLResponse cachedResponse); | |
100 } | |
101 | |
102 template TNSURLConnectionSynchronousLoading () | |
103 { | |
104 static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error) | 146 static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error) |
105 { | 147 { |
106 return invokeObjcSelfClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error); | 148 return invokeObjcSuperClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error); |
107 } | 149 } |
108 } | 150 } |
109 |