Mercurial > projects > dwt-linux
annotate dwt/browser/InputStream.d @ 286:44258e0b6687
More fixes for xpcom
author | John Reimer<terminal.node@gmail.com> |
---|---|
date | Tue, 05 Aug 2008 10:11:58 -0700 |
parents | 93409d9838c5 |
children | eec6ddb07873 |
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 |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
10 *******************************************************************************/ |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
11 module dwt.browser.InputStream; |
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 import dwt.dwthelper.utils; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
14 |
286 | 15 import dwt.internal.C; |
16 import dwt.internal.mozilla.XPCOM; | |
17 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
|
18 import dwt.internal.mozilla.nsID; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
19 import dwt.internal.mozilla.nsIInputStream; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
20 import dwt.internal.mozilla.nsISupports; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
21 |
286 | 22 class InputStream { |
23 XPCOMObject inputStream; | |
24 int refCount = 0; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
25 |
286 | 26 byte[] buffer; |
27 int index = 0; | |
28 | |
29 InputStream (byte[] buffer) { | |
30 this.buffer = buffer; | |
31 index = 0; | |
32 createCOMInterfaces (); | |
33 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
34 |
286 | 35 int AddRef () { |
36 refCount++; | |
37 return refCount; | |
38 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
39 |
286 | 40 void createCOMInterfaces () { |
41 /* Create each of the interfaces that this object implements */ | |
42 inputStream = new XPCOMObject (new int[] {2, 0, 0, 0, 1, 3, 4, 1}) { | |
43 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
44 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
45 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
46 public int /*long*/ method3 (int /*long*/[] args) {return Close ();} | |
47 public int /*long*/ method4 (int /*long*/[] args) {return Available (args[0]);} | |
48 public int /*long*/ method5 (int /*long*/[] args) {return Read (args[0], (int)/*64*/args[1], args[2]);} | |
49 public int /*long*/ method6 (int /*long*/[] args) {return ReadSegments (args[0], args[1], (int)/*64*/args[2], args[3]);} | |
50 public int /*long*/ method7 (int /*long*/[] args) {return IsNonBlocking (args[0]);} | |
51 }; | |
52 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
53 |
286 | 54 void disposeCOMInterfaces () { |
55 if (inputStream !is null) { | |
56 inputStream.dispose (); | |
57 inputStream = null; | |
58 } | |
59 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
60 |
286 | 61 int /*long*/ getAddress () { |
62 return inputStream.getAddress (); | |
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 QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { |
66 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
67 nsID guid = new nsID (); | |
68 XPCOM.memmove (guid, riid, nsID.sizeof); | |
69 | |
70 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
71 XPCOM.memmove (ppvObject, new int /*long*/[] {inputStream.getAddress ()}, C.PTR_SIZEOF); | |
72 AddRef (); | |
73 return XPCOM.NS_OK; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
74 } |
286 | 75 if (guid.Equals (nsIInputStream.NS_IINPUTSTREAM_IID)) { |
76 XPCOM.memmove (ppvObject, new int /*long*/[] {inputStream.getAddress ()}, C.PTR_SIZEOF); | |
77 AddRef (); | |
78 return XPCOM.NS_OK; | |
79 } | |
80 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
81 return XPCOM.NS_ERROR_NO_INTERFACE; | |
82 } | |
83 | |
84 int Release () { | |
85 refCount--; | |
86 if (refCount is 0) disposeCOMInterfaces (); | |
87 return refCount; | |
88 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
89 |
286 | 90 /* nsIInputStream implementation */ |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
91 |
286 | 92 int Close () { |
93 buffer = null; | |
94 index = 0; | |
95 return XPCOM.NS_OK; | |
96 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
97 |
286 | 98 int Available (int /*long*/ _retval) { |
99 int available = buffer is null ? 0 : buffer.length - index; | |
100 XPCOM.memmove (_retval, new int[] {available}, 4); | |
101 return XPCOM.NS_OK; | |
102 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
103 |
286 | 104 int Read(int /*long*/ aBuf, int aCount, int /*long*/ _retval) { |
105 int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); | |
106 if (max > 0) { | |
107 byte[] src = new byte[max]; | |
108 System.arraycopy (buffer, index, src, 0, max); | |
109 XPCOM.memmove (aBuf, src, max); | |
110 index += max; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
111 } |
286 | 112 XPCOM.memmove(_retval, new int[] {max}, 4); |
113 return XPCOM.NS_OK; | |
114 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
115 |
286 | 116 int ReadSegments (int /*long*/ aWriter, int /*long*/ aClosure, int aCount, int /*long*/ _retval) { |
117 int max = Math.min (aCount, buffer is null ? 0 : buffer.length - index); | |
118 int cnt = max; | |
119 while (cnt > 0) { | |
120 int[] aWriteCount = new int[1]; | |
121 int /*long*/ rc = XPCOM.Call (aWriter, getAddress (), aClosure, buffer, index, cnt, aWriteCount); | |
122 if (rc !is XPCOM.NS_OK) break; | |
123 index += aWriteCount[0]; | |
124 cnt -= aWriteCount[0]; | |
125 } | |
126 XPCOM.memmove (_retval, new int[] {max - cnt}, 4); | |
127 return XPCOM.NS_OK; | |
128 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
129 |
286 | 130 int IsNonBlocking (int /*long*/ _retval) { |
131 /* blocking */ | |
132 XPCOM.memmove (_retval, new int[] {0}, 4); | |
133 return XPCOM.NS_OK; | |
134 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
135 } |