Mercurial > projects > dstep
diff dstep/foundation/NSPort.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 7ff919f595d5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/foundation/NSPort.d Mon Aug 03 15:23:15 2009 +0200 @@ -0,0 +1,329 @@ +/** + * 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.NSPort; + +import dstep.foundation.NSConnection; +import dstep.foundation.NSData; +import dstep.foundation.NSDate; +import dstep.foundation.NSMutableArray; +import dstep.foundation.NSObject; +import dstep.foundation.NSPortMessage; +import dstep.foundation.NSRunLoop; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc : id; + +import bindings = dstep.foundation.NSPort_bindings; + +alias int NSSocketNativeHandle; + +const NSString NSPortDidBecomeInvalidNotification; + +enum +{ + NSMachPortDeallocateNone = 0, + NSMachPortDeallocateSendRight = (1 << 0), + NSMachPortDeallocateReceiveRight = (1 << 1) +} + +static this () +{ + NSPortDidBecomeInvalidNotification = new NSString(bindings.NSPortDidBecomeInvalidNotification); +} + +class NSPort : NSObject, INSCopying, INSCoding +{ + mixin ObjcWrap; + + static Object allocWithZone (NSZone* zone) + { + return invokeObjcSelfClass!(Object, "allocWithZone:", NSZone*)(zone); + } + + static NSPort port () + { + return invokeObjcSelfClass!(NSPort, "port"return result is this.objcObject ? this : (result !is null ? new NSPort(result) : null); } + + void invalidate () + { + return invokeObjcSelf!(void, "invalidate"); + } + + bool isValid () + { + return invokeObjcSelf!(bool, "isValid"); + } + + void setDelegate (Object anId) + { + return invokeObjcSelf!(void, "setDelegate:", Object)(anId); + } + + Object delegate_ () + { + return invokeObjcSelf!(Object, "delegate"); + } + + void scheduleInRunLoop (NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); + } + + void removeFromRunLoop (NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); + } + + NSUInteger reservedSpaceLength () + { + return invokeObjcSelf!(NSUInteger, "reservedSpaceLength"); + } + + bool sendBeforeDate (NSDate limitDate, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved) + { + return invokeObjcSelf!(bool, "sendBeforeDate:components:from:reserved:", NSDate, NSMutableArray, NSPort, NSUInteger)(limitDate, components, receivePort, headerSpaceReserved); + } + + bool sendBeforeDate (NSDate limitDate, NSUInteger msgID, NSMutableArray components, NSPort receivePort, NSUInteger headerSpaceReserved) + { + return invokeObjcSelf!(bool, "sendBeforeDate:msgid:components:from:reserved:", NSDate, NSUInteger, NSMutableArray, NSPort, NSUInteger)(limitDate, msgID, components, receivePort, headerSpaceReserved); + } + + void addConnection (NSConnection conn, NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "addConnection:toRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode); + } + + void removeConnection (NSConnection conn, NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "removeConnection:fromRunLoop:forMode:", NSConnection, NSRunLoop, NSString)(conn, runLoop, mode); + } + + Object copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); + } + + void encodeWithCoder (NSCoder aCoder) + { + return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); + } + + Object initWithCoder (NSCoder aDecoder) + { + return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); + } + + this (NSCoder aDecoder) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); + + if (result) + objcObject = ret; + + dObject = this; + } +} + +class NSSocketPort : NSPort +{ + mixin ObjcWrap; + + Object init () + { + return invokeObjcSelf!(Object, "init"); + } + + this () + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithTCPPort (ushort port) + { + return invokeObjcSelf!(Object, "initWithTCPPort:", ushort)(port); + } + + this (ushort port) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithTCPPort:", ushort)(objcObject, port); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithProtocolFamily (int family, int type, int protocol, NSData address) + { + return invokeObjcSelf!(Object, "initWithProtocolFamily: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, "initWithProtocolFamily:socketType:protocol:address:", int, int, int, NSData)(objcObject, family, type, protocol, address); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithProtocolFamily (int family, int type, int protocol, int sock) + { + return invokeObjcSelf!(Object, "initWithProtocolFamily:socketType:protocol:socket:", int, int, int, int)(family, type, protocol, sock); + } + + 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; + } + + Object initRemoteWithTCPPort (ushort port, NSString hostName) + { + return invokeObjcSelf!(Object, "initRemoteWithTCPPort:host:", ushort, NSString)(port, hostName); + } + + 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; + } + + Object initRemoteWithProtocolFamily (int family, int type, int protocol, NSData address) + { + 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"); + } + + int socketType () + { + return invokeObjcSelf!(int, "socketType"); + } + + int protocol () + { + return invokeObjcSelf!(int, "protocol"); + } + + NSData address () + { + return invokeObjcSelf!(NSData, "address"); + } + + int socket () + { + return invokeObjcSelf!(int, "socket"); + } +} + +class NSMachPort : NSPort +{ + mixin ObjcWrap; + + static NSPort portWithMachPort (uint machPort) + { + return invokeObjcSelfClass!(NSPort, "portWithMachPort:", uint)(machPort); + } + + Object initWithMachPort (uint machPort) + { + return invokeObjcSelf!(Object, "initWithMachPort:", uint)(machPort); + } + + this (uint machPort) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithMachPort:", uint)(objcObject, machPort); + + if (result) + objcObject = ret; + + dObject = this; + } + + static NSPort portWithMachPort (uint machPort, NSUInteger f) + { + return invokeObjcSelfClass!(NSPort, "portWithMachPort:options:", uint, NSUInteger)(machPort, f); + } + + Object initWithMachPort (uint machPort, NSUInteger f) + { + return invokeObjcSelf!(Object, "initWithMachPort:options:", uint, NSUInteger)(machPort, f); + } + + 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; + } + + uint machPort () + { + return invokeObjcSelf!(uint, "machPort"); + } + + void scheduleInRunLoop (NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "scheduleInRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); + } + + void removeFromRunLoop (NSRunLoop runLoop, NSString mode) + { + return invokeObjcSelf!(void, "removeFromRunLoop:forMode:", NSRunLoop, NSString)(runLoop, mode); + } +} + +template TNSMachPortDelegateMethods () +{ + void handleMachMessage (void* msg); +} + +template TNSPortDelegateMethods () +{ + void handlePortMessage (NSPortMessage message); +} +