view 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 source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Aug 3, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.foundation.NSURLConnection;

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.NSURLCache;
import dstep.foundation.NSURLRequest;
import dstep.foundation.NSURLResponse;
import dstep.objc.bridge.Bridge;
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);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	static bool canHandleRequest (NSURLRequest request)
	{
		return invokeObjcSuperClass!(bool, "canHandleRequest:", NSURLRequest)(request);
	}

	static NSURLConnection connectionWithRequest (NSURLRequest request, Object delegate_)
	{
		return invokeObjcSuperClass!(NSURLConnection, "connectionWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
	}

	Object initWithRequest (NSURLRequest request, Object delegate_)
	{
		return invokeObjcSelf!(Object, "initWithRequest:delegate:", NSURLRequest, Object)(request, delegate_);
	}

	this (NSURLRequest request, Object delegate_)
	{
		typeof(this).alloc.initWithRequest(request, delegate_);
	}

	Object initWithRequest (NSURLRequest request, Object delegate_, bool startImmediately)
	{
		return invokeObjcSelf!(Object, "initWithRequest:delegate:startImmediately:", NSURLRequest, Object, bool)(request, delegate_, startImmediately);
	}

	this (NSURLRequest request, Object delegate_, bool startImmediately)
	{
		typeof(this).alloc.initWithRequest(request, delegate_, startImmediately);
	}

	void start ()
	{
		return invokeObjcSelf!(void, "start");
	}

	void cancel ()
	{
		return invokeObjcSelf!(void, "cancel");
	}

	void scheduleInRunLoop (NSRunLoop aRunLoop, NSString mode)
	{
		return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode);
	}

	void unscheduleFromRunLoop (NSRunLoop aRunLoop, NSString mode)
	{
		return invokeObjcSelf!(void, "unscheduleFromRunLoop:forMode:", NSRunLoop, NSString)(aRunLoop, mode);
	}
	
	// TNSURLConnectionSynchronousLoading
	static NSData sendSynchronousRequest (NSURLRequest request, NSURLResponse** response, NSError** error)
	{
		return invokeObjcSuperClass!(NSData, "sendSynchronousRequest:returningResponse:error:", NSURLRequest, NSURLResponse**, NSError**)(request, response, error);
	}
}