Mercurial > projects > dstep
diff dstep/foundation/NSConnection.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/NSConnection.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSConnection.d Sun Jan 03 22:06:11 2010 +0100 @@ -12,32 +12,114 @@ import dstep.foundation.NSDictionary; import dstep.foundation.NSDistantObject; import dstep.foundation.NSException; -import dstep.foundation.NSMutableData; +import dstep.foundation.NSInvocation; import dstep.foundation.NSObject; import dstep.foundation.NSPort; import dstep.foundation.NSPortNameServer; import dstep.foundation.NSRunLoop; +import dstep.foundation.NSString; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; import bindings = dstep.foundation.NSConnection_bindings; -const NSString NSConnectionReplyMode; -const NSString NSConnectionDidDieNotification; -const NSString NSFailedAuthenticationException; -const NSString NSConnectionDidInitializeNotification; +private +{ + NSString NSConnectionReplyMode_; + NSString NSConnectionDidDieNotification_; + NSString NSFailedAuthenticationException_; + NSString NSConnectionDidInitializeNotification_; +} + +NSString NSConnectionReplyMode () +{ + if (NSConnectionReplyMode_) + return NSConnectionReplyMode_; + + return NSConnectionReplyMode_ = new NSString(bindings.NSConnectionReplyMode); +} + +NSString NSConnectionDidDieNotification () +{ + if (NSConnectionDidDieNotification_) + return NSConnectionDidDieNotification_; + + return NSConnectionDidDieNotification_ = new NSString(bindings.NSConnectionDidDieNotification); +} + +NSString NSFailedAuthenticationException () +{ + if (NSFailedAuthenticationException_) + return NSFailedAuthenticationException_; + + return NSFailedAuthenticationException_ = new NSString(bindings.NSFailedAuthenticationException); +} + +NSString NSConnectionDidInitializeNotification () +{ + if (NSConnectionDidInitializeNotification_) + return NSConnectionDidInitializeNotification_; + + return NSConnectionDidInitializeNotification_ = new NSString(bindings.NSConnectionDidInitializeNotification); +} + +const TNSDistantObjectRequestMethods = ` -static this () -{ - NSConnectionReplyMode = new NSString(bindings.NSConnectionReplyMode); - NSConnectionDidDieNotification = new NSString(bindings.NSConnectionDidDieNotification); - NSFailedAuthenticationException = new NSString(bindings.NSFailedAuthenticationException); - NSConnectionDidInitializeNotification = new NSString(bindings.NSConnectionDidInitializeNotification); -} + bool connection (NSConnection connection, NSDistantObjectRequest doreq) + { + return invokeObjcSelf!(bool, "connection:handleRequest:", NSConnection, NSDistantObjectRequest)(connection, doreq); + } + + //mixin ObjcBindMethod!(connection, "connection:handleRequest:"); +`; + +const TNSConnectionDelegateMethods = ` + + bool makeNewConnection (NSConnection conn, NSConnection ancestor) + { + return invokeObjcSelf!(bool, "makeNewConnection:sender:")(conn, ancestor); + } + + bool connection (NSConnection ancestor, NSConnection conn) + { + return invokeObjcSelf!(bool, "connection:shouldMakeNewConnection:", NSConnection, NSConnection)(ancestor, conn); + } + + NSData authenticationDataForComponents (NSArray components) + { + return invokeObjcSelf!(NSData, "authenticationDataForComponents:", NSArray)(components); + } + + bool authenticateComponents (NSArray components, NSData signature) + { + return invokeObjcSelf!(bool, "authenticateComponents:withData:")(components, signature); + } + + Object createConversationForConnection (NSConnection conn) + { + return invokeObjcSelf!(Object, "createConversationForConnection:")(conn); + } + + //mixin ObjcBindMethod!(makeNewConnection, "makeNewConnection:sender:"); + //mixin ObjcBindMethod!(connection, "connection:shouldMakeNewConnection:"); + //mixin ObjcBindMethod!(authenticationDataForComponents, "authenticationDataForComponents:"); + //mixin ObjcBindMethod!(authenticateComponents, "authenticateComponents:withData:"); + //mixin ObjcBindMethod!(createConversationForConnection, "createConversationForConnection:"); +`; class NSDistantObjectRequest : NSObject { - mixin ObjcWrap; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } NSInvocation invocation () { @@ -62,7 +144,17 @@ class NSConnection : NSObject { - mixin ObjcWrap; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } NSDictionary statistics () { @@ -71,42 +163,42 @@ static NSArray allConnections () { - return invokeObjcSelfClass!(NSArray, "allConnections"); + return invokeObjcSuperClass!(NSArray, "allConnections"); } static NSConnection defaultConnection () { - return invokeObjcSelfClass!(NSConnection, "defaultConnection"); + return invokeObjcSuperClass!(NSConnection, "defaultConnection"); } static Object connectionWithRegisteredName (NSString name, NSString hostName) { - return invokeObjcSelfClass!(Object, "connectionWithRegisteredName:host:", NSString, NSString)(name, hostName); + return invokeObjcSuperClass!(Object, "connectionWithRegisteredName:host:", NSString, NSString)(name, hostName); } static Object connectionWithRegisteredName (NSString name, NSString hostName, NSPortNameServer server) { - return invokeObjcSelfClass!(Object, "connectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server); + return invokeObjcSuperClass!(Object, "connectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server); } static NSDistantObject rootProxyForConnectionWithRegisteredName (NSString name, NSString hostName) { - return invokeObjcSelfClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:", NSString, NSString)(name, hostName); + return invokeObjcSuperClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:", NSString, NSString)(name, hostName); } static NSDistantObject rootProxyForConnectionWithRegisteredName (NSString name, NSString hostName, NSPortNameServer server) { - return invokeObjcSelfClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server); + return invokeObjcSuperClass!(NSDistantObject, "rootProxyForConnectionWithRegisteredName:host:usingNameServer:", NSString, NSString, NSPortNameServer)(name, hostName, server); } static Object serviceConnectionWithName (NSString name, Object root, NSPortNameServer server) { - return invokeObjcSelfClass!(Object, "serviceConnectionWithName:rootObject:usingNameServer:", NSString, Object, NSPortNameServer)(name, root, server); + return invokeObjcSuperClass!(Object, "serviceConnectionWithName:rootObject:usingNameServer:", NSString, Object, NSPortNameServer)(name, root, server); } static Object serviceConnectionWithName (NSString name, Object root) { - return invokeObjcSelfClass!(Object, "serviceConnectionWithName:rootObject:", NSString, Object)(name, root); + return invokeObjcSuperClass!(Object, "serviceConnectionWithName:rootObject:", NSString, Object)(name, root); } void setRequestTimeout (double ti) @@ -201,12 +293,12 @@ static Object connectionWithReceivePort (NSPort receivePort, NSPort sendPort) { - return invokeObjcSelfClass!(Object, "connectionWithReceivePort:sendPort:", NSPort, NSPort)(receivePort, sendPort); + return invokeObjcSuperClass!(Object, "connectionWithReceivePort:sendPort:", NSPort, NSPort)(receivePort, sendPort); } static Object currentConversation () { - return invokeObjcSelfClass!(Object, "currentConversation"); + return invokeObjcSuperClass!(Object, "currentConversation"); } Object initWithReceivePort (NSPort receivePort, NSPort sendPort) @@ -216,13 +308,7 @@ this (NSPort receivePort, NSPort sendPort) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithReceivePort:sendPort:", NSPort, NSPort)(objcObject, receivePort, sendPort); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithReceivePort(receivePort, sendPort); } NSPort sendPort () @@ -269,19 +355,4 @@ { return invokeObjcSelf!(NSArray, "localObjects"); } -} - -template TNSDistantObjectRequestMethods () -{ - bool connection (NSConnection connection, NSDistantObjectRequest doreq); -} - -template TNSConnectionDelegateMethods () -{ - bool makeNewConnection (NSConnection conn, NSConnection ancestor); - bool connection (NSConnection ancestor, NSConnection conn); - NSData authenticationDataForComponents (NSArray components); - bool authenticateComponents (NSArray components, NSData signature); - Object createConversationForConnection (NSConnection conn); -} - +} \ No newline at end of file