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.NSURLConnection;
|
|
8
|
|
9 import dstep.AvailabilityMacros;
|
|
10 import dstep.foundation.NSCachedURLResponse;
|
|
11 import dstep.foundation.NSData;
|
|
12 import dstep.foundation.NSError;
|
|
13 import dstep.foundation.NSObject;
|
|
14 import dstep.foundation.NSRunLoop;
|
|
15 import dstep.foundation.NSURLAuthenticationChallenge;
|
|
16 import dstep.foundation.NSURLConnectionInternal;
|
|
17 import dstep.foundation.NSURLRequest;
|
|
18 import dstep.foundation.NSURLResponse;
|
|
19 import dstep.objc.bridge.Bridge;
|
|
20 import dstep.objc.objc : id;
|
|
21
|
|
22 class NSURLConnection : NSObject
|
|
23 {
|
|
24 mixin ObjcWrap;
|
|
25 mixin TNSURLConnectionSynchronousLoading;
|
|
26
|
|
27 static bool canHandleRequest (NSURLRequest request)
|
|
28 {
|
|
29 return invokeObjcSelfClass!(bool, "canHandleRequest:", NSURLRequest)(request);
|
|
30 }
|
|
31
|
|
32 static NSURLConnection connectionWithRequest (NSURLRequest request, Object delegate_)
|
|
33 {
|
|
34 return invokeObjcSelfClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_return result is this.objcObject ? this : (result !is null ? new NSURLConnection(result) : null); }
|
|
35
|
|
36 Object initWithRequest (NSURLRequest request, Object delegate_)
|
|
37 {
|
|
38 return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
|
|
39 }
|
|
40
|
|
41 this (NSURLRequest request, Object delegate_)
|
|
42 {
|
|
43 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
44 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:", NSURLRequest, Object)(objcObject, request, delegate_);
|
|
45
|
|
46 if (result)
|
|
47 objcObject = ret;
|
|
48
|
|
49 dObject = this;
|
|
50 }
|
|
51
|
|
52 Object initWithRequest (NSURLRequest request, Object delegate_, bool startImmediately)
|
|
53 {
|
|
54 return invokeObjcSelf!(Object, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(request, delegate_, startImmediately);
|
|
55 }
|
|
56
|
|
57 this (NSURLRequest request, Object delegate_, bool startImmediately)
|
|
58 {
|
|
59 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
60 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(objcObject, request, delegate_, startImmediately);
|
|
61
|
|
62 if (result)
|
|
63 objcObject = ret;
|
|
64
|
|
65 dObject = this;
|
|
66 }
|
|
67
|
|
68 void start ()
|
|
69 {
|
|
70 return invokeObjcSelf!(void, "start");
|
|
71 }
|
|
72
|
|
73 void cancel ()
|
|
74 {
|
|
75 return invokeObjcSelf!(void, "cancel");
|
|
76 }
|
|
77
|
|
78 void scheduleInRunLoop (NSRunLoop aRunLoop, NSString mode)
|
|
79 {
|
|
80 return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode);
|
|
81 }
|
|
82
|
|
83 void unscheduleFromRunLoop (NSRunLoop aRunLoop, NSString mode)
|
|
84 {
|
|
85 return invokeObjcSelf!(void, "unscheduleFromRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode);
|
|
86 }
|
|
87 }
|
|
88
|
|
89 template TNSURLConnectionDelegate ()
|
|
90 {
|
|
91 NSURLRequest connection (NSURLConnection connection, NSURLRequest request, NSURLResponse response);
|
|
92 void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge);
|
|
93 void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge);
|
|
94 void connection (NSURLConnection connection, NSURLResponse response);
|
|
95 void connection (NSURLConnection connection, NSData data);
|
|
96 void connectionDidFinishLoading (NSURLConnection connection);
|
|
97 void connection (NSURLConnection connection, NSError error);
|
|
98 NSCachedURLResponse connection (NSURLConnection connection, NSCachedURLResponse cachedResponse);
|
|
99 }
|
|
100
|
|
101 template TNSURLConnectionSynchronousLoading ()
|
|
102 {
|
|
103 static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error)
|
|
104 {
|
|
105 return invokeObjcSelfClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error);
|
|
106 }
|
|
107 }
|
|
108
|