Mercurial > projects > dwt-linux
annotate dwt/browser/InputStream.d @ 345:5abc6f7f7a95
Fixups
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Tue, 28 Oct 2008 22:07:01 -0700 |
parents | 96243e3ebcf0 |
children | 2e591eb01162 |
rev | line source |
---|---|
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2003, 2007 IBM Corporation and others. |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
7 * |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
10 * Port to the D programming language: |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
11 * John Reimer <terminal.node@gmail.com> |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
12 *******************************************************************************/ |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
13 module dwt.browser.InputStream; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
14 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
15 import Math = tango.math.Math; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
16 import dwt.dwthelper.utils; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
17 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
18 //import dwt.internal.C; |
341
942da4b6558a
Ongoing fixup for compile
John Reimer <terminal.node@gmail.com>
parents:
298
diff
changeset
|
19 import XPCOM = dwt.internal.mozilla.XPCOM; |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
20 //import dwt.internal.mozilla.XPCOMObject; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
21 import dwt.internal.mozilla.nsID; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
22 import dwt.internal.mozilla.nsIInputStream; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
23 import dwt.internal.mozilla.nsISupports; |
343
96243e3ebcf0
Mozilla.d compiles successfully :)
John Reimer <terminal.node@gmail.com>
parents:
341
diff
changeset
|
24 import dwt.internal.mozilla.Common; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
25 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
26 class InputStream : nsIInputStream { |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
27 //XPCOMObject inputStream; |
286 | 28 int refCount = 0; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
29 |
286 | 30 byte[] buffer; |
31 int index = 0; | |
32 | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
33 this (byte[] buffer) { |
286 | 34 this.buffer = buffer; |
35 index = 0; | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
36 //createCOMInterfaces (); |
286 | 37 } |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
38 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
39 nsrefcnt AddRef () { |
286 | 40 refCount++; |
41 return refCount; | |
42 } | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
43 /+ |
286 | 44 void createCOMInterfaces () { |
45 /* Create each of the interfaces that this object implements */ | |
46 inputStream = new XPCOMObject (new int[] {2, 0, 0, 0, 1, 3, 4, 1}) { | |
47 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
48 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
49 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
50 public int /*long*/ method3 (int /*long*/[] args) {return Close ();} | |
51 public int /*long*/ method4 (int /*long*/[] args) {return Available (args[0]);} | |
52 public int /*long*/ method5 (int /*long*/[] args) {return Read (args[0], (int)/*64*/args[1], args[2]);} | |
53 public int /*long*/ method6 (int /*long*/[] args) {return ReadSegments (args[0], args[1], (int)/*64*/args[2], args[3]);} | |
54 public int /*long*/ method7 (int /*long*/[] args) {return IsNonBlocking (args[0]);} | |
55 }; | |
56 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
57 |
286 | 58 void disposeCOMInterfaces () { |
59 if (inputStream !is null) { | |
60 inputStream.dispose (); | |
61 inputStream = null; | |
62 } | |
63 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
64 |
286 | 65 int /*long*/ getAddress () { |
66 return inputStream.getAddress (); | |
67 } | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
68 +/ |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
69 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
70 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
71 //nsID guid = new nsID (); |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
72 //XPCOM.memmove (guid, riid, nsID.sizeof); |
286 | 73 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
74 if (*riid == nsISupports.IID) { |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
75 *ppvObject = cast(void*)cast(nsISupports)this; |
286 | 76 AddRef (); |
77 return XPCOM.NS_OK; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
78 } |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
79 if (*riid == nsIInputStream.IID) { |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
80 *ppvObject = cast(void*)cast(nsIInputStream)this; |
286 | 81 AddRef (); |
82 return XPCOM.NS_OK; | |
83 } | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
84 *ppvObject = null; |
286 | 85 return XPCOM.NS_ERROR_NO_INTERFACE; |
86 } | |
87 | |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
88 nsrefcnt Release () { |
286 | 89 refCount--; |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
90 //if (refCount is 0) disposeCOMInterfaces (); |
286 | 91 return refCount; |
92 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
93 |
286 | 94 /* nsIInputStream implementation */ |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
95 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
96 nsresult Close () { |
286 | 97 buffer = null; |
98 index = 0; | |
99 return XPCOM.NS_OK; | |
100 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
101 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
102 nsresult Available (PRUint32* _retval) { |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
103 PRUint32 available = buffer is null ? 0 : buffer.length - index; |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
104 *_retval = available; |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
105 //XPCOM.memmove (_retval, new int[] {available}, 4); |
286 | 106 return XPCOM.NS_OK; |
107 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
108 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
109 nsresult Read(byte* aBuf, PRUint32 aCount, PRUint32* _retval) { |
286 | 110 int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
111 if (aBuf is null) |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
112 assert(0); |
286 | 113 if (max > 0) { |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
114 //byte[] src = new byte[max]; |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
115 //System.arraycopy (buffer, index, src, 0, max); |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
116 //XPCOM.memmove (aBuf, src, max); |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
117 aBuf[0..max] = buffer[index..$]; |
286 | 118 index += max; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
119 } |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
120 *_retval = max; |
286 | 121 return XPCOM.NS_OK; |
122 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
123 |
343
96243e3ebcf0
Mozilla.d compiles successfully :)
John Reimer <terminal.node@gmail.com>
parents:
341
diff
changeset
|
124 nsresult ReadSegments (nsWriteSegmentFun aWriter, void* aClosure, PRUint32 aCount, PRUint32* _retval) { |
286 | 125 int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
126 PRUint32 cnt = max; |
286 | 127 while (cnt > 0) { |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
128 PRUint32 aWriteCount; |
345 | 129 nsresult rc = aWriter (cast(nsIInputStream)this, aClosure, buffer.ptr, index, cnt, &aWriteCount); |
286 | 130 if (rc !is XPCOM.NS_OK) break; |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
131 index += aWriteCount; |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
132 cnt -= aWriteCount; |
286 | 133 } |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
134 //XPCOM.memmove (_retval, new int[] {max - cnt}, 4); |
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
135 *_retval = (max - cnt); |
286 | 136 return XPCOM.NS_OK; |
137 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
138 |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
139 nsresult IsNonBlocking (PRUint32* _retval) { |
286 | 140 /* blocking */ |
298
eec6ddb07873
More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents:
286
diff
changeset
|
141 *_retval = 0; |
286 | 142 return XPCOM.NS_OK; |
143 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
144 } |