annotate dwt/browser/InputStream.d @ 346:2e591eb01162

Browser Package now compiles (phase 2 complete)
author John Reimer <terminal.node@gmail.com>
date Wed, 29 Oct 2008 20:06:08 -0700
parents 5abc6f7f7a95
children 9a4d7706df52
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;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
35 //createCOMInterfaces ();
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
36 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
37
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 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
42 /+
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
43 void createCOMInterfaces () {
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
44 /* Create each of the interfaces that this object implements */
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
45 inputStream = new XPCOMObject (new int[] {2, 0, 0, 0, 1, 3, 4, 1}) {
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
46 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
47 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
48 public int /*long*/ method2 (int /*long*/[] args) {return Release ();}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
49 public int /*long*/ method3 (int /*long*/[] args) {return Close ();}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
50 public int /*long*/ method4 (int /*long*/[] args) {return Available (args[0]);}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
51 public int /*long*/ method5 (int /*long*/[] args) {return Read (args[0], (int)/*64*/args[1], args[2]);}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
52 public int /*long*/ method6 (int /*long*/[] args) {return ReadSegments (args[0], args[1], (int)/*64*/args[2], args[3]);}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
53 public int /*long*/ method7 (int /*long*/[] args) {return IsNonBlocking (args[0]);}
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
54 };
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
55 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
56
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
57 void disposeCOMInterfaces () {
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
58 if (inputStream !is null) {
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
59 inputStream.dispose ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
60 inputStream = null;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
61 }
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
62 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
63
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
64 int /*long*/ getAddress () {
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
65 return inputStream.getAddress ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
66 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
67 +/
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
68 nsresult QueryInterface (nsID* riid, void** ppvObject) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
69 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
70 //nsID guid = new nsID ();
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
71 //XPCOM.memmove (guid, riid, nsID.sizeof);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
72
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
73 if (*riid == nsISupports.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
74 *ppvObject = cast(void*)cast(nsISupports)this;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
75 AddRef ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
76 return XPCOM.NS_OK;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
77 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
78 if (*riid == nsIInputStream.IID) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
79 *ppvObject = cast(void*)cast(nsIInputStream)this;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
80 AddRef ();
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
81 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
82 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
83 *ppvObject = null;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
84 return XPCOM.NS_ERROR_NO_INTERFACE;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
85 }
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
86
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
87 nsrefcnt Release () {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
88 refCount--;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
89 //if (refCount is 0) disposeCOMInterfaces ();
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
90 return refCount;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
91 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
92
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
93 /* nsIInputStream implementation */
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
94
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
95 nsresult Close () {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
96 buffer = null;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
97 index = 0;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
98 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
99 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
100
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
101 nsresult Available (PRUint32* _retval) {
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
102 PRUint32 available = buffer is null ? 0 : buffer.length - index;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
103 *_retval = available;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
104 //XPCOM.memmove (_retval, new int[] {available}, 4);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
105 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
106 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
107
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
108 nsresult Read(byte* aBuf, PRUint32 aCount, PRUint32* _retval) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
109 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
110 if (aBuf is null)
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
111 assert(0);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
112 if (max > 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
113 //byte[] src = new byte[max];
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
114 //System.arraycopy (buffer, index, src, 0, max);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
115 //XPCOM.memmove (aBuf, src, max);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
116 aBuf[0..max] = buffer[index..$];
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
117 index += max;
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
118 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
119 *_retval = max;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
120 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
121 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
122
343
96243e3ebcf0 Mozilla.d compiles successfully :)
John Reimer <terminal.node@gmail.com>
parents: 341
diff changeset
123 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
124 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
125 PRUint32 cnt = max;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
126 while (cnt > 0) {
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
127 PRUint32 aWriteCount;
345
John Reimer <terminal.node@gmail.com>
parents: 343
diff changeset
128 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
129 if (rc !is XPCOM.NS_OK) break;
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
130 index += aWriteCount;
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
131 cnt -= aWriteCount;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
132 }
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
133 //XPCOM.memmove (_retval, new int[] {max - cnt}, 4);
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
134 *_retval = (max - cnt);
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
135 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
136 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
137
346
2e591eb01162 Browser Package now compiles (phase 2 complete)
John Reimer <terminal.node@gmail.com>
parents: 345
diff changeset
138 nsresult IsNonBlocking (PRBool* _retval) {
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
139 /* blocking */
298
eec6ddb07873 More xpcom/mozilla port
John Reimer<terminal.node@gmail.com>
parents: 286
diff changeset
140 *_retval = 0;
286
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
141 return XPCOM.NS_OK;
44258e0b6687 More fixes for xpcom
John Reimer<terminal.node@gmail.com>
parents: 278
diff changeset
142 }
278
93409d9838c5 Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff changeset
143 }