annotate dwt/browser/InputStream.d @ 348:9a4d7706df52

Test Update to fix linux XPCOM interface issues
author John Reimer <terminal.node@gmail.com>
date Fri, 31 Oct 2008 21:46:44 -0700
parents 2e591eb01162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
341
942da4b6558a Ongoing fixup for compile
John Reimer <terminal.node@gmail.com>
parents: 298
diff changeset
18 import XPCOM = dwt.internal.mozilla.XPCOM;
346
2e591eb01162 Browser Package now compiles (phase 2 complete)
John Reimer <terminal.node@gmail.com>
parents: 345
diff changeset
19
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
20 import dwt.internal.mozilla.nsID;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
21 import dwt.internal.mozilla.nsIInputStream;
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
22 import dwt.internal.mozilla.nsISupports;
343
96243e3ebcf0 Mozilla.d compiles successfully :)
John Reimer <terminal.node@gmail.com>
parents: 341
diff changeset
23 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
24
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
25 class InputStream : nsIInputStream {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
26 //XPCOMObject inputStream;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
27 int refCount = 0;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
28
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
29 byte[] buffer;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
30 int index = 0;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
31
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
32 this (byte[] buffer) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
33 this.buffer = buffer;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
34 index = 0;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
35 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
36
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
37 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
38 nsrefcnt AddRef () {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
39 refCount++;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
40 return refCount;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
41 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
42
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
43 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
44 nsresult QueryInterface (nsID* riid, void** ppvObject) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
45 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
46 //nsID guid = new nsID ();
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
47 //XPCOM.memmove (guid, riid, nsID.sizeof);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
48
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
49 if (*riid == nsISupports.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
50 *ppvObject = cast(void*)cast(nsISupports)this;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
51 AddRef ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
52 return XPCOM.NS_OK;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
53 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
54 if (*riid == nsIInputStream.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
55 *ppvObject = cast(void*)cast(nsIInputStream)this;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
56 AddRef ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
57 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
58 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
59 *ppvObject = null;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
60 return XPCOM.NS_ERROR_NO_INTERFACE;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
61 }
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
62
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
63 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
64 nsrefcnt Release () {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
65 refCount--;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
66 //if (refCount is 0) disposeCOMInterfaces ();
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
67 return refCount;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
68 }
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
69
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
70 /* nsIInputStream implementation */
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
71
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
72 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
73 nsresult Close () {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
74 buffer = null;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
75 index = 0;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
76 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
77 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
78
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
79 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
80 nsresult Available (PRUint32* _retval) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
81 PRUint32 available = buffer is null ? 0 : buffer.length - index;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
82 *_retval = available;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
83 //XPCOM.memmove (_retval, new int[] {available}, 4);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
84 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
85 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
86
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
87 extern(System)
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
88 nsresult Read(byte* aBuf, PRUint32 aCount, PRUint32* _retval) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
89 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
90 if (aBuf is null)
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
91 assert(0);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
92 if (max > 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
93 //byte[] src = new byte[max];
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
94 //System.arraycopy (buffer, index, src, 0, max);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
95 //XPCOM.memmove (aBuf, src, max);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
96 aBuf[0..max] = buffer[index..$];
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
97 index += max;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
98 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
99 *_retval = max;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
100 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
101 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
102
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
103 extern(System)
343
96243e3ebcf0 Mozilla.d compiles successfully :)
John Reimer <terminal.node@gmail.com>
parents: 341
diff changeset
104 nsresult ReadSegments (nsWriteSegmentFun aWriter, void* aClosure, PRUint32 aCount, PRUint32* _retval) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
105 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
106 PRUint32 cnt = max;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
107 while (cnt > 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
108 PRUint32 aWriteCount;
345
John Reimer <terminal.node@gmail.com>
parents: 343
diff changeset
109 nsresult rc = aWriter (cast(nsIInputStream)this, aClosure, buffer.ptr, index, cnt, &aWriteCount);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
110 if (rc !is XPCOM.NS_OK) break;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
111 index += aWriteCount;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
112 cnt -= aWriteCount;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
113 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
114 //XPCOM.memmove (_retval, new int[] {max - cnt}, 4);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
115 *_retval = (max - cnt);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
116 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
117 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
118
348
9a4d7706df52 Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents: 346
diff changeset
119 extern(System)
346
2e591eb01162 Browser Package now compiles (phase 2 complete)
John Reimer <terminal.node@gmail.com>
parents: 345
diff changeset
120 nsresult IsNonBlocking (PRBool* _retval) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
121 /* blocking */
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
122 *_retval = 0;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
123 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
124 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
125 }