comparison dstep/foundation/NSURLProtocol.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.NSURLProtocol; 7 module dstep.foundation.NSURLProtocol;
8 8
9 import dstep.AvailabilityMacros; 9 import dstep.foundation.NSData;
10 import dstep.foundation.NSCachedURLResponse;
11 import dstep.foundation.NSError; 10 import dstep.foundation.NSError;
12 import dstep.foundation.NSMutableURLRequest;
13 import dstep.foundation.NSObject; 11 import dstep.foundation.NSObject;
12 import dstep.foundation.NSString;
14 import dstep.foundation.NSURLAuthenticationChallenge; 13 import dstep.foundation.NSURLAuthenticationChallenge;
15 import dstep.foundation.NSURLCache; 14 import dstep.foundation.NSURLCache;
16 import dstep.foundation.NSURLConnection; 15 import dstep.foundation.NSURLConnection;
17 import dstep.foundation.NSURLProtocolInternal;
18 import dstep.foundation.NSURLRequest; 16 import dstep.foundation.NSURLRequest;
19 import dstep.foundation.NSURLResponse; 17 import dstep.foundation.NSURLResponse;
20 import dstep.objc.bridge.Bridge; 18 import dstep.objc.bridge.Bridge;
21 import dstep.objc.objc : id; 19 import dstep.objc.objc;
22 20
23 class NSURLProtocol : NSObject 21 class NSURLProtocol : NSObject
24 { 22 {
25 mixin ObjcWrap; 23 mixin (ObjcWrap);
24
25 this ()
26 {
27 super(typeof(this).alloc.init.objcObject);
28 }
29
30 typeof(this) init ()
31 {
32 return invokeObjcSelf!(typeof(this), "init");
33 }
26 34
27 Object initWithRequest (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client) 35 Object initWithRequest (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
28 { 36 {
29 return invokeObjcSelf!(Object, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(request, cachedResponse, client); 37 return invokeObjcSelf!(Object, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(request, cachedResponse, client);
30 } 38 }
31 39
32 this (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client) 40 this (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
33 { 41 {
34 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 42 typeof(this).alloc.initWithRequest(request, cachedResponse, client);
35 id result = Bridge.invokeObjcMethod!(id, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(objcObject, request, cachedResponse, client);
36
37 if (result)
38 objcObject = ret;
39
40 dObject = this;
41 } 43 }
42 44
43 INSURLProtocolClient client () 45 INSURLProtocolClient client ()
44 { 46 {
45 return invokeObjcSelf!(INSURLProtocolClient, "client"); 47 return invokeObjcSelf!(INSURLProtocolClient, "client");
55 return invokeObjcSelf!(NSCachedURLResponse, "cachedResponse"); 57 return invokeObjcSelf!(NSCachedURLResponse, "cachedResponse");
56 } 58 }
57 59
58 static bool canInitWithRequest (NSURLRequest request) 60 static bool canInitWithRequest (NSURLRequest request)
59 { 61 {
60 return invokeObjcSelfClass!(bool, "canInitWithRequest:", NSURLRequest)(request); 62 return invokeObjcSuperClass!(bool, "canInitWithRequest:", NSURLRequest)(request);
61 } 63 }
62 64
63 static NSURLRequest canonicalRequestForRequest (NSURLRequest request) 65 static NSURLRequest canonicalRequestForRequest (NSURLRequest request)
64 { 66 {
65 return invokeObjcSelfClass!(NSURLRequest, "canonicalRequestForRequest:", NSURLRequest)(request); 67 return invokeObjcSuperClass!(NSURLRequest, "canonicalRequestForRequest:", NSURLRequest)(request);
66 } 68 }
67 69
68 static bool requestIsCacheEquivalent (NSURLRequest a, NSURLRequest b) 70 static bool requestIsCacheEquivalent (NSURLRequest a, NSURLRequest b)
69 { 71 {
70 return invokeObjcSelfClass!(bool, "requestIsCacheEquivalent:toRequest:", NSURLRequest, NSURLRequest)(a, b); 72 return invokeObjcSuperClass!(bool, "requestIsCacheEquivalent:toRequest:", NSURLRequest, NSURLRequest)(a, b);
71 } 73 }
72 74
73 void startLoading () 75 void startLoading ()
74 { 76 {
75 return invokeObjcSelf!(void, "startLoading"); 77 return invokeObjcSelf!(void, "startLoading");
80 return invokeObjcSelf!(void, "stopLoading"); 82 return invokeObjcSelf!(void, "stopLoading");
81 } 83 }
82 84
83 static Object propertyForKey (NSString key, NSURLRequest request) 85 static Object propertyForKey (NSString key, NSURLRequest request)
84 { 86 {
85 return invokeObjcSelfClass!(Object, "propertyForKey:inRequest:", NSString, NSURLRequest)(key, request); 87 return invokeObjcSuperClass!(Object, "propertyForKey:inRequest:", NSString, NSURLRequest)(key, request);
86 } 88 }
87 89
88 static void setProperty (Object value, NSString key, NSMutableURLRequest request) 90 static void setProperty (Object value, NSString key, NSMutableURLRequest request)
89 { 91 {
90 return invokeObjcSelfClass!(void, "setProperty:forKey:inRequest:", Object, NSString, NSMutableURLRequest)(value, key, request); 92 return invokeObjcSuperClass!(void, "setProperty:forKey:inRequest:", Object, NSString, NSMutableURLRequest)(value, key, request);
91 } 93 }
92 94
93 static void removePropertyForKey (NSString key, NSMutableURLRequest request) 95 static void removePropertyForKey (NSString key, NSMutableURLRequest request)
94 { 96 {
95 return invokeObjcSelfClass!(void, "removePropertyForKey:inRequest:", NSString, NSMutableURLRequest)(key, request); 97 return invokeObjcSuperClass!(void, "removePropertyForKey:inRequest:", NSString, NSMutableURLRequest)(key, request);
96 } 98 }
97 99
98 static bool registerClass (Class protocolClass) 100 static bool registerClass (Class protocolClass)
99 { 101 {
100 return invokeObjcSelfClass!(bool, "registerClass:", Class)(protocolClass); 102 return invokeObjcSuperClass!(bool, "registerClass:", Class)(protocolClass);
101 } 103 }
102 104
103 static void unregisterClass (Class protocolClass) 105 static void unregisterClass (Class protocolClass)
104 { 106 {
105 return invokeObjcSelfClass!(void, "unregisterClass:", Class)(protocolClass); 107 return invokeObjcSuperClass!(void, "unregisterClass:", Class)(protocolClass);
106 } 108 }
107 } 109 }
108 110
109 interface INSURLProtocolClient : INSObject 111 interface INSURLProtocolClient : INSObject
110 { 112 {