diff 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
line wrap: on
line diff
--- a/dstep/foundation/NSURLConnection.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSURLConnection.d	Sun Jan 03 22:06:11 2010 +0100
@@ -6,32 +6,100 @@
  */
 module dstep.foundation.NSURLConnection;
 
-import dstep.AvailabilityMacros;
-import dstep.foundation.NSCachedURLResponse;
 import dstep.foundation.NSData;
 import dstep.foundation.NSError;
 import dstep.foundation.NSObject;
 import dstep.foundation.NSRunLoop;
+import dstep.foundation.NSString;
 import dstep.foundation.NSURLAuthenticationChallenge;
-import dstep.foundation.NSURLConnectionInternal;
+import dstep.foundation.NSURLCache;
 import dstep.foundation.NSURLRequest;
 import dstep.foundation.NSURLResponse;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
+
+const TNSURLConnectionDelegate = `
+
+	NSURLRequest connection (NSURLConnection connection, NSURLRequest request, NSURLResponse response)
+	{
+		return invokeObjcSelf!(NSURLRequest, "connection:willSendRequest:redirectResponse:", NSURLConnection, NSURLRequest, NSURLResponse)(connection, request, response);
+	}
+	
+	void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge)
+	{
+		return invokeObjcSelf!(void, "connection:didReceiveAuthenticationChallenge:", NSURLConnection, NSURLAuthenticationChallenge)(connection, challenge);
+	}
+	
+	void connection_didCancelAuthenticationChallenge (NSURLConnection connection, NSURLAuthenticationChallenge challenge)
+	{
+		return invokeObjcSelf!(void, "connection:didCancelAuthenticationChallenge:", NSURLConnection, NSURLAuthenticationChallenge)(connection, challenge);
+	}
+	
+	void connection (NSURLConnection connection, NSURLResponse response)
+	{
+		return invokeObjcSelf!(void, "connection:didReceiveResponse:", NSURLConnection, NSURLResponse)(connection, response);
+	}
+	
+	void connection (NSURLConnection connection, NSData data)
+	{
+		return invokeObjcSelf!(void, "connection:didReceiveData:", NSURLConnection, NSData)(connection, data);
+	}
+	
+	void connectionDidFinishLoading (NSURLConnection connection)
+	{
+		return invokeObjcSelf!(void, "connectionDidFinishLoading:", NSURLConnection)(connection);
+	}
+	
+	void connection (NSURLConnection connection, NSError error)
+	{
+		return invokeObjcSelf!(void, "connection:didFailWithError:", NSURLConnection, NSError)(connection, error);
+	}
+	
+	NSCachedURLResponse connection (NSURLConnection connection, NSCachedURLResponse cachedResponse)
+	{
+		return invokeObjcSelf!(NSCachedURLResponse, "connection:willCacheResponse:", NSURLConnection, NSCachedURLResponse)(connection, cachedResponse);
+	}
+	
+	//mixin ObjcBindMethod!(connection, "connection:willSendRequest:redirectResponse:");
+	//mixin ObjcBindMethod!(connection, "replacementObjectForArchiver:");
+	//mixin ObjcBindMethod!(connection_didCancelAuthenticationChallenge, "connection:didReceiveAuthenticationChallenge:");
+	//mixin ObjcBindMethod!(connection, "connection:didReceiveResponse:");
+	//mixin ObjcBindMethod!(connection, "connection:didReceiveData:");
+	//mixin ObjcBindMethod!(connectionDidFinishLoading, "connectionDidFinishLoading:");
+	//mixin ObjcBindMethod!(connection, "connection:didFailWithError:");
+	//mixin ObjcBindMethod!(connection, "connection:willCacheResponse:");
+`;
+
+const TNSURLConnectionSynchronousLoading = `
+
+	static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error)
+	{
+		return invokeObjcSuperClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error);
+	}
+`;
 
 class NSURLConnection : NSObject
 {
-	mixin ObjcWrap;
-	mixin TNSURLConnectionSynchronousLoading;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	static bool canHandleRequest (NSURLRequest request)
 	{
-		return invokeObjcSelfClass!(bool, "canHandleRequest:", NSURLRequest)(request);
+		return invokeObjcSuperClass!(bool, "canHandleRequest:", NSURLRequest)(request);
 	}
 
 	static NSURLConnection connectionWithRequest (NSURLRequest request, Object delegate_)
 	{
-		return invokeObjcSelfClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
+		return invokeObjcSuperClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
 	}
 
 	Object initWithRequest (NSURLRequest request, Object delegate_)
@@ -41,13 +109,7 @@
 
 	this (NSURLRequest request, Object delegate_)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:", NSURLRequest, Object)(objcObject, request, delegate_);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithRequest(request, delegate_);
 	}
 
 	Object initWithRequest (NSURLRequest request, Object delegate_, bool startImmediately)
@@ -57,13 +119,7 @@
 
 	this (NSURLRequest request, Object delegate_, bool startImmediately)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(objcObject, request, delegate_, startImmediately);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithRequest(request, delegate_, startImmediately);
 	}
 
 	void start ()
@@ -85,25 +141,10 @@
 	{
 		return invokeObjcSelf!(void, "unscheduleFromRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode);
 	}
-}
-
-template TNSURLConnectionDelegate ()
-{
-	NSURLRequest connection (NSURLConnection connection, NSURLRequest request, NSURLResponse response);
-	void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge);
-	void connection (NSURLConnection connection, NSURLAuthenticationChallenge challenge);
-	void connection (NSURLConnection connection, NSURLResponse response);
-	void connection (NSURLConnection connection, NSData data);
-	void connectionDidFinishLoading (NSURLConnection connection);
-	void connection (NSURLConnection connection, NSError error);
-	NSCachedURLResponse connection (NSURLConnection connection, NSCachedURLResponse cachedResponse);
-}
-
-template TNSURLConnectionSynchronousLoading ()
-{
+	
+	// TNSURLConnectionSynchronousLoading
 	static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error)
 	{
-		return invokeObjcSelfClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error);
+		return invokeObjcSuperClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error);
 	}
-}
-
+}
\ No newline at end of file