Mercurial > projects > dwt-mac
comparison dwt/internal/cocoa/NSStream.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 8b48be5454ce |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * | |
11 * Port to the D Programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
13 *******************************************************************************/ | |
14 module dwt.internal.cocoa.NSStream; | |
15 | |
16 import dwt.internal.cocoa.id; | |
17 import dwt.internal.cocoa.NSError; | |
18 import dwt.internal.cocoa.NSHost; | |
19 import dwt.internal.cocoa.NSInteger; | |
20 import dwt.internal.cocoa.NSObject; | |
21 import dwt.internal.cocoa.NSRunLoop; | |
22 import dwt.internal.cocoa.NSString; | |
23 import dwt.internal.cocoa.OS; | |
24 import objc = dwt.internal.objc.runtime; | |
25 | |
26 | |
27 | |
28 enum NSStreamEvent : NSUInteger | |
29 { | |
30 NSStreamEventNone = 0, | |
31 NSStreamEventOpenCompleted = 1 << 0, | |
32 NSStreamEventHasBytesAvailable = 1 << 1, | |
33 NSStreamEventHasSpaceAvailable = 1 << 2, | |
34 NSStreamEventErrorOccurred = 1 << 3, | |
35 NSStreamEventEndEncountered = 1 << 4 | |
36 } | |
37 | |
38 alias NSStreamEvent.NSStreamEventNone NSStreamEventNone; | |
39 alias NSStreamEvent.NSStreamEventOpenCompleted NSStreamEventOpenCompleted; | |
40 alias NSStreamEvent.NSStreamEventHasBytesAvailable NSStreamEventHasBytesAvailable; | |
41 alias NSStreamEvent.NSStreamEventHasSpaceAvailable NSStreamEventHasSpaceAvailable; | |
42 alias NSStreamEvent.NSStreamEventErrorOccurred NSStreamEventErrorOccurred; | |
43 alias NSStreamEvent.NSStreamEventEndEncountered NSStreamEventEndEncountered; | |
44 | |
45 | |
46 | |
47 enum NSStreamStatus : NSUInteger | |
48 { | |
49 NSStreamStatusNotOpen = 0, | |
50 NSStreamStatusOpening = 1, | |
51 NSStreamStatusOpen = 2, | |
52 NSStreamStatusReading = 3, | |
53 NSStreamStatusWriting = 4, | |
54 NSStreamStatusAtEnd = 5, | |
55 NSStreamStatusClosed = 6, | |
56 NSStreamStatusError = 7 | |
57 } | |
58 | |
59 alias NSStreamStatus.NSStreamStatusNotOpen NSStreamStatusNotOpen; | |
60 alias NSStreamStatus.NSStreamStatusOpening NSStreamStatusOpening; | |
61 alias NSStreamStatus.NSStreamStatusOpen NSStreamStatusOpen; | |
62 alias NSStreamStatus.NSStreamStatusReading NSStreamStatusReading; | |
63 alias NSStreamStatus.NSStreamStatusWriting NSStreamStatusWriting; | |
64 alias NSStreamStatus.NSStreamStatusAtEnd NSStreamStatusAtEnd; | |
65 alias NSStreamStatus.NSStreamStatusClosed NSStreamStatusClosed; | |
66 alias NSStreamStatus.NSStreamStatusError NSStreamStatusError; | |
67 | |
68 | |
69 | |
70 public class NSStream : NSObject | |
71 { | |
72 | |
73 public this () | |
74 { | |
75 super(); | |
76 } | |
77 | |
78 public this (objc.id id) | |
79 { | |
80 super(id); | |
81 } | |
82 | |
83 public void close () | |
84 { | |
85 OS.objc_msgSend(this.id, OS.sel_close); | |
86 } | |
87 | |
88 public id delegatee () | |
89 { | |
90 objc.id result = OS.objc_msgSend(this.id, OS.sel_delegate); | |
91 return result !is null ? new id(result) : null; | |
92 } | |
93 | |
94 public static void getStreamsToHost (NSHost host, NSInteger port, /*NSInputStream** */objc.id** inputStream, | |
95 /*NSOutputStream** */objc.id** outputStream) | |
96 { | |
97 OS.objc_msgSend(OS.class_NSStream, OS.sel_getStreamsToHost_1port_1inputStream_1outputStream_1, host !is null ? host.id : null, port, | |
98 inputStream, outputStream); | |
99 } | |
100 | |
101 public void open () | |
102 { | |
103 OS.objc_msgSend(this.id, OS.sel_open); | |
104 } | |
105 | |
106 public id propertyForKey (NSString key) | |
107 { | |
108 objc.id result = OS.objc_msgSend(this.id, OS.sel_propertyForKey_1, key !is null ? key.id : null); | |
109 return result !is null ? new id(result) : null; | |
110 } | |
111 | |
112 public void removeFromRunLoop (NSRunLoop aRunLoop, NSString mode) | |
113 { | |
114 OS.objc_msgSend(this.id, OS.sel_removeFromRunLoop_1forMode_1, aRunLoop !is null ? aRunLoop.id : null, mode !is null ? mode.id : null); | |
115 } | |
116 | |
117 public void scheduleInRunLoop (NSRunLoop aRunLoop, NSString mode) | |
118 { | |
119 OS.objc_msgSend(this.id, OS.sel_scheduleInRunLoop_1forMode_1, aRunLoop !is null ? aRunLoop.id : null, mode !is null ? mode.id : null); | |
120 } | |
121 | |
122 public void setDelegate (id delegatee) | |
123 { | |
124 OS.objc_msgSend(this.id, OS.sel_setDelegate_1, delegatee !is null ? delegatee.id : null); | |
125 } | |
126 | |
127 public bool setProperty (id property, NSString key) | |
128 { | |
129 return OS.objc_msgSend(this.id, OS.sel_setProperty_1forKey_1, property !is null ? property.id : null, key !is null ? key.id : null) !is null; | |
130 } | |
131 | |
132 public NSError streamError () | |
133 { | |
134 objc.id result = OS.objc_msgSend(this.id, OS.sel_streamError); | |
135 return result !is null ? new NSError(result) : null; | |
136 } | |
137 | |
138 public NSStreamStatus streamStatus () | |
139 { | |
140 return cast(NSStreamStatus) OS.objc_msgSend(this.id, OS.sel_streamStatus); | |
141 } | |
142 | |
143 } |