Mercurial > projects > dstep
diff dstep/foundation/NSPort.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/NSPort.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSPort.d Sun Jan 03 22:06:11 2010 +0100 @@ -6,21 +6,32 @@ */ module dstep.foundation.NSPort; +import dstep.foundation.NSArray; +import dstep.foundation.NSCoder; import dstep.foundation.NSConnection; import dstep.foundation.NSData; import dstep.foundation.NSDate; -import dstep.foundation.NSMutableArray; +import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; import dstep.foundation.NSPortMessage; import dstep.foundation.NSRunLoop; +import dstep.foundation.NSString; +import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; - +import dstep.objc.objc; import bindings = dstep.foundation.NSPort_bindings; alias int NSSocketNativeHandle; -const NSString NSPortDidBecomeInvalidNotification; +private NSString NSPortDidBecomeInvalidNotification_; + +NSString NSPortDidBecomeInvalidNotification () +{ + if (NSPortDidBecomeInvalidNotification_) + return NSPortDidBecomeInvalidNotification_; + + return NSPortDidBecomeInvalidNotification_ = new NSString(bindings.NSPortDidBecomeInvalidNotification); +} enum { @@ -29,23 +40,48 @@ NSMachPortDeallocateReceiveRight = (1 << 1) } -static this () -{ - NSPortDidBecomeInvalidNotification = new NSString(bindings.NSPortDidBecomeInvalidNotification); -} +const TNSMachPortDelegateMethods = ` + + void handleMachMessage (void* msg) + { + return invokeObjcSelf!(void, "handleMachMessage:", void*)(msg); + } + + //mixin ObjcBindMethod!(handleMachMessage, "handleMachMessage:"); +`; + +const TNSPortDelegateMethods = ` + + void handlePortMessage (NSPortMessage message) + { + return invokeObjcSelf!(void, "handlePortMessage:", NSPortMessage)(message); + } + + //mixin ObjcBindMethod!(handlePortMessage, "handlePortMessage:"); +`; class NSPort : NSObject, INSCopying, INSCoding { - mixin ObjcWrap; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } static Object allocWithZone (NSZone* zone) { - return invokeObjcSelfClass!(Object, "allocWithZone:", NSZone*)(zone); + return invokeObjcSuperClass!(Object, "allocWithZone:", NSZone*)(zone); } static NSPort port () { - return invokeObjcSelfClass!(NSPort, "port"); + return invokeObjcSuperClass!(NSPort, "port"); } void invalidate () @@ -120,34 +156,22 @@ this (NSCoder aDecoder) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithCoder(aDecoder); } } class NSSocketPort : NSPort { - mixin ObjcWrap; - - Object init () - { - return invokeObjcSelf!(Object, "init"); - } - + mixin (ObjcWrap); + this () { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); - - if (result) - objcObject = ret; - - dObject = this; + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); } Object initWithTCPPort (ushort port) @@ -157,13 +181,7 @@ this (ushort port) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithTCPPort:", ushort)(objcObject, port); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithTCPPort(port); } Object initWithProtocolFamily (int family, int type, int protocol, NSData address) @@ -173,13 +191,7 @@ this (int family, int type, int protocol, NSData address) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithProtocolFamily(family, type, protocol, address); } Object initWithProtocolFamily (int family, int type, int protocol, int sock) @@ -189,13 +201,7 @@ this (int family, int type, int protocol, int sock) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(objcObject, family, type, protocol, sock); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithProtocolFamily(family, type, protocol, sock); } Object initRemoteWithTCPPort (ushort port, NSString hostName) @@ -205,13 +211,7 @@ this (ushort port, NSString hostName) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initRemoteWithTCPPort:host:", ushort, NSString)(objcObject, port, hostName); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initRemoteWithTCPPort(port, hostName); } Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address) @@ -219,17 +219,6 @@ return invokeObjcSelf!(Object, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(family, type, protocol, address); } - this (int family, int type, int protocol, NSData address) - { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initRemoteWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address); - - if (result) - objcObject = ret; - - dObject = this; - } - int protocolFamily () { return invokeObjcSelf!(int, "protocolFamily"); @@ -258,11 +247,21 @@ class NSMachPort : NSPort { - mixin ObjcWrap; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } static NSPort portWithMachPort (uint machPort) { - return invokeObjcSelfClass!(NSPort, "portWithMachPort:", uint)(machPort); + return invokeObjcSuperClass!(NSPort, "portWithMachPort:", uint)(machPort); } Object initWithMachPort (uint machPort) @@ -272,18 +271,12 @@ this (uint machPort) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:", uint)(objcObject, machPort); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithMachPort(machPort); } static NSPort portWithMachPort (uint machPort, NSUInteger f) { - return invokeObjcSelfClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); + return invokeObjcSuperClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); } Object initWithMachPort (uint machPort, NSUInteger f) @@ -293,13 +286,7 @@ this (uint machPort, NSUInteger f) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:options:", uint, NSUInteger)(objcObject, machPort, f); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithMachPort(machPort, f); } uint machPort () @@ -316,15 +303,4 @@ { return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); } -} - -template TNSMachPortDelegateMethods () -{ - void handleMachMessage (void* msg); -} - -template TNSPortDelegateMethods () -{ - void handlePortMessage (NSPortMessage message); -} - +} \ No newline at end of file