comparison dstep/foundation/NSURLRequest.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 89f3c3ef1fd2
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.NSURLRequest; 7 module dstep.foundation.NSURLRequest;
8 8
9 import dstep.AvailabilityMacros; 9 import dstep.foundation.NSCoder;
10 import dstep.foundation.NSData; 10 import dstep.foundation.NSData;
11 import dstep.foundation.NSDate; 11 import dstep.foundation.NSDate;
12 import dstep.foundation.NSDictionary; 12 import dstep.foundation.NSDictionary;
13 import dstep.foundation.NSInputStream; 13 import dstep.foundation.NSObjCRuntime;
14 import dstep.foundation.NSObject; 14 import dstep.foundation.NSObject;
15 import dstep.foundation.NSStream;
15 import dstep.foundation.NSString; 16 import dstep.foundation.NSString;
16 import dstep.foundation.NSURL; 17 import dstep.foundation.NSURL;
17 import dstep.foundation.NSURLRequestInternal; 18 import dstep.foundation.NSZone;
18 import dstep.objc.bridge.Bridge; 19 import dstep.objc.bridge.Bridge;
19 import dstep.objc.objc : id; 20 import dstep.objc.objc;
20 21
21 alias NSUInteger NSURLRequestCachePolicy; 22 alias NSUInteger NSURLRequestCachePolicy;
22 23
23 enum 24 enum
24 { 25 {
29 NSURLRequestReturnCacheDataElseLoad = 2, 30 NSURLRequestReturnCacheDataElseLoad = 2,
30 NSURLRequestReturnCacheDataDontLoad = 3, 31 NSURLRequestReturnCacheDataDontLoad = 3,
31 NSURLRequestReloadRevalidatingCacheData = 5 32 NSURLRequestReloadRevalidatingCacheData = 5
32 } 33 }
33 34
35 const TNSHTTPURLRequest = `
36
37 NSString HTTPMethod ()
38 {
39 return invokeObjcSelf!(NSString, "HTTPMethod");
40 }
41
42 NSDictionary allHTTPHeaderFields ()
43 {
44 return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields");
45 }
46
47 NSString valueForHTTPHeaderField (NSString field)
48 {
49 return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field);
50 }
51
52 NSData HTTPBody ()
53 {
54 return invokeObjcSelf!(NSData, "HTTPBody");
55 }
56
57 NSInputStream HTTPBodyStream ()
58 {
59 return invokeObjcSelf!(NSInputStream, "HTTPBodyStream");
60 }
61
62 bool HTTPShouldHandleCookies ()
63 {
64 return invokeObjcSelf!(bool, "HTTPShouldHandleCookies");
65 }
66 `;
67
68 const TNSMutableHTTPURLRequest = `
69
70 void setHTTPMethod (NSString method)
71 {
72 return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method);
73 }
74
75 void setAllHTTPHeaderFields (NSDictionary headerFields)
76 {
77 return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields);
78 }
79
80 void setValue (NSString value, NSString field)
81 {
82 return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field);
83 }
84
85 void addValue (NSString value, NSString field)
86 {
87 return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field);
88 }
89
90 void setHTTPBody (NSData data)
91 {
92 return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data);
93 }
94
95 void setHTTPBodyStream (NSInputStream inputStream)
96 {
97 return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream);
98 }
99
100 void setHTTPShouldHandleCookies (bool should)
101 {
102 return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should);
103 }
104 `;
105
34 class NSURLRequest : NSObject, INSCoding, INSCopying, INSMutableCopying 106 class NSURLRequest : NSObject, INSCoding, INSCopying, INSMutableCopying
35 { 107 {
36 mixin ObjcWrap; 108 mixin (ObjcWrap);
37 mixin TNSHTTPURLRequest; 109
110 this ()
111 {
112 super(typeof(this).alloc.init.objcObject);
113 }
114
115 typeof(this) init ()
116 {
117 return invokeObjcSelf!(typeof(this), "init");
118 }
38 119
39 static Object requestWithURL (NSURL URL) 120 static Object requestWithURL (NSURL URL)
40 { 121 {
41 return invokeObjcSelfClass!(Object, "requestWithURL:", NSURL)(URL); 122 return invokeObjcSuperClass!(Object, "requestWithURL:", NSURL)(URL);
42 } 123 }
43 124
44 static Object requestWithURL (NSURL URL, uint cachePolicy, double timeoutInterval) 125 static Object requestWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
45 { 126 {
46 return invokeObjcSelfClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval); 127 return invokeObjcSuperClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
47 } 128 }
48 129
49 Object initWithURL (NSURL URL) 130 Object initWithURL (NSURL URL)
50 { 131 {
51 return invokeObjcSelf!(Object, "initWithURL:", NSURL)(URL); 132 return invokeObjcSelf!(Object, "initWithURL:", NSURL)(URL);
52 } 133 }
53 134
54 this (NSURL URL) 135 this (NSURL URL)
55 { 136 {
56 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 137 typeof(this).alloc.initWithURL(URL);
57 id result = Bridge.invokeObjcMethod!(id, "initWithURL:", NSURL)(objcObject, URL);
58
59 if (result)
60 objcObject = ret;
61
62 dObject = this;
63 } 138 }
64 139
65 Object initWithURL (NSURL URL, uint cachePolicy, double timeoutInterval) 140 Object initWithURL (NSURL URL, uint cachePolicy, double timeoutInterval)
66 { 141 {
67 return invokeObjcSelf!(Object, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval); 142 return invokeObjcSelf!(Object, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval);
68 } 143 }
69 144
70 this (NSURL URL, uint cachePolicy, double timeoutInterval) 145 this (NSURL URL, uint cachePolicy, double timeoutInterval)
71 { 146 {
72 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 147 typeof(this).alloc.initWithURL(URL, cachePolicy, timeoutInterval);
73 id result = Bridge.invokeObjcMethod!(id, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(objcObject, URL, cachePolicy, timeoutInterval);
74
75 if (result)
76 objcObject = ret;
77
78 dObject = this;
79 } 148 }
80 149
81 NSURL URL () 150 NSURL URL ()
82 { 151 {
83 return invokeObjcSelf!(NSURL, "URL"); 152 return invokeObjcSelf!(NSURL, "URL");
108 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); 177 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
109 } 178 }
110 179
111 this (NSCoder aDecoder) 180 this (NSCoder aDecoder)
112 { 181 {
113 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 182 typeof(this).alloc.initWithCoder(aDecoder);
114 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
115
116 if (result)
117 objcObject = ret;
118
119 dObject = this;
120 } 183 }
121 184
122 Object copyWithZone (NSZone* zone) 185 Object copyWithZone (NSZone* zone)
123 { 186 {
124 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); 187 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
125 } 188 }
126 189
127 Object mutableCopyWithZone (NSZone* zone) 190 Object mutableCopyWithZone (NSZone* zone)
128 { 191 {
129 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); 192 return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
193 }
194
195 // TNSHTTPURLRequest
196 NSString HTTPMethod ()
197 {
198 return invokeObjcSelf!(NSString, "HTTPMethod");
199 }
200
201 NSDictionary allHTTPHeaderFields ()
202 {
203 return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields");
204 }
205
206 NSString valueForHTTPHeaderField (NSString field)
207 {
208 return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field);
209 }
210
211 NSData HTTPBody ()
212 {
213 return invokeObjcSelf!(NSData, "HTTPBody");
214 }
215
216 NSInputStream HTTPBodyStream ()
217 {
218 return invokeObjcSelf!(NSInputStream, "HTTPBodyStream");
219 }
220
221 bool HTTPShouldHandleCookies ()
222 {
223 return invokeObjcSelf!(bool, "HTTPShouldHandleCookies");
130 } 224 }
131 } 225 }
132 226
133 class NSMutableURLRequest : NSURLRequest 227 class NSMutableURLRequest : NSURLRequest
134 { 228 {
135 mixin ObjcWrap; 229 mixin (ObjcWrap);
136 mixin TNSMutableHTTPURLRequest; 230
231 this ()
232 {
233 super(typeof(this).alloc.init.objcObject);
234 }
235
236 typeof(this) init ()
237 {
238 return invokeObjcSelf!(typeof(this), "init");
239 }
137 240
138 void setURL (NSURL URL) 241 void setURL (NSURL URL)
139 { 242 {
140 return invokeObjcSelf!(void, "setURL:", NSURL)(URL); 243 return invokeObjcSelf!(void, "setURL:", NSURL)(URL);
141 } 244 }
152 255
153 void setMainDocumentURL (NSURL URL) 256 void setMainDocumentURL (NSURL URL)
154 { 257 {
155 return invokeObjcSelf!(void, "setMainDocumentURL:", NSURL)(URL); 258 return invokeObjcSelf!(void, "setMainDocumentURL:", NSURL)(URL);
156 } 259 }
260
261 // TNSMutableHTTPURLRequest
262 void setHTTPMethod (NSString method)
263 {
264 return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method);
265 }
266
267 void setAllHTTPHeaderFields (NSDictionary headerFields)
268 {
269 return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields);
270 }
271
272 void setValue (NSString value, NSString field)
273 {
274 return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field);
275 }
276
277 void addValue (NSString value, NSString field)
278 {
279 return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field);
280 }
281
282 void setHTTPBody (NSData data)
283 {
284 return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data);
285 }
286
287 void setHTTPBodyStream (NSInputStream inputStream)
288 {
289 return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream);
290 }
291
292 void setHTTPShouldHandleCookies (bool should)
293 {
294 return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should);
295 }
157 } 296 }
158
159 template TNSHTTPURLRequest ()
160 {
161 NSString HTTPMethod ()
162 {
163 return invokeObjcSelf!(NSString, "HTTPMethod");
164 }
165
166 NSDictionary allHTTPHeaderFields ()
167 {
168 return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields");
169 }
170
171 NSString valueForHTTPHeaderField (NSString field)
172 {
173 return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field);
174 }
175
176 NSData HTTPBody ()
177 {
178 return invokeObjcSelf!(NSData, "HTTPBody");
179 }
180
181 NSInputStream HTTPBodyStream ()
182 {
183 return invokeObjcSelf!(NSInputStream, "HTTPBodyStream");
184 }
185
186 bool HTTPShouldHandleCookies ()
187 {
188 return invokeObjcSelf!(bool, "HTTPShouldHandleCookies");
189 }
190 }
191
192 template TNSMutableHTTPURLRequest ()
193 {
194 void setHTTPMethod (NSString method)
195 {
196 return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method);
197 }
198
199 void setAllHTTPHeaderFields (NSDictionary headerFields)
200 {
201 return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields);
202 }
203
204 void setValue (NSString value, NSString field)
205 {
206 return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field);
207 }
208
209 void addValue (NSString value, NSString field)
210 {
211 return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field);
212 }
213
214 void setHTTPBody (NSData data)
215 {
216 return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data);
217 }
218
219 void setHTTPBodyStream (NSInputStream inputStream)
220 {
221 return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream);
222 }
223
224 void setHTTPShouldHandleCookies (bool should)
225 {
226 return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should);
227 }
228 }
229