Mercurial > projects > dwt-linux
comparison dwt/browser/DownloadFactory.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 | 942da4b6558a |
comparison
equal
deleted
inserted
replaced
280:e72345914350 | 286:44258e0b6687 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * John Reimer <terminal.node@gmail.com> | |
12 *******************************************************************************/ | 10 *******************************************************************************/ |
13 module dwt.browser.DownloadFactory; | 11 module dwt.browser.DownloadFactory; |
14 | 12 |
15 import dwt.dwthelper.utils; | 13 import dwt.dwthelper.utils; |
16 | 14 |
17 import dwt.browser.Download; | 15 import dwt.internal.C; |
18 | 16 import dwt.internal.mozilla.XPCOM; |
17 import dwt.internal.mozilla.XPCOMObject; | |
19 import dwt.internal.mozilla.nsID; | 18 import dwt.internal.mozilla.nsID; |
20 import dwt.internal.mozilla.nsIFactory; | 19 import dwt.internal.mozilla.nsIFactory; |
21 import dwt.internal.mozilla.nsISupports; | 20 import dwt.internal.mozilla.nsISupports; |
22 | 21 |
23 class DownloadFactory : nsIFactory | 22 class DownloadFactory { |
24 { | 23 XPCOMObject supports; |
25 int _refCount = 0; | 24 XPCOMObject factory; |
25 int refCount = 0; | |
26 | 26 |
27 nsrefcnt AddRef () | 27 DownloadFactory () { |
28 { | 28 createCOMInterfaces (); |
29 _refCount++; | 29 } |
30 return _refCount; | 30 |
31 int AddRef () { | |
32 refCount++; | |
33 return refCount; | |
34 } | |
35 | |
36 void createCOMInterfaces () { | |
37 /* Create each of the interfaces that this object implements */ | |
38 supports = new XPCOMObject (new int[] {2, 0, 0}) { | |
39 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
40 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
41 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
42 }; | |
43 | |
44 factory = new XPCOMObject (new int[] {2, 0, 0, 3, 1}) { | |
45 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
46 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
47 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
48 public int /*long*/ method3 (int /*long*/[] args) {return CreateInstance (args[0], args[1], args[2]);} | |
49 public int /*long*/ method4 (int /*long*/[] args) {return LockFactory ((int)/*64*/args[0]);} | |
50 }; | |
51 } | |
52 | |
53 void disposeCOMInterfaces () { | |
54 if (supports !is null) { | |
55 supports.dispose (); | |
56 supports = null; | |
57 } | |
58 if (factory !is null) { | |
59 factory.dispose (); | |
60 factory = null; | |
31 } | 61 } |
62 } | |
32 | 63 |
33 int QueryInterface ( ref nsIID riid, void** ppvObject) | 64 int /*long*/ getAddress () { |
34 { | 65 return factory.getAddress (); |
35 if (riid is null || ppvObject is null) | 66 } |
36 return NS_ERROR_NO_INTERFACE; | |
37 | |
38 if ( riid == nsISupports.IID) | |
39 { | |
40 *ppvObject = cast(void*)cast(nsISupports)this; | |
41 AddRef (); | |
42 return NS_OK; | |
43 } | |
44 | 67 |
45 if ( riid == nsIFactory.IID) | 68 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { |
46 { | 69 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; |
47 *ppvObject = cast(void*)cast(nsIFactory)this; | 70 nsID guid = new nsID (); |
48 AddRef (); | 71 XPCOM.memmove (guid, riid, nsID.sizeof); |
49 return NS_OK; | |
50 } | |
51 | 72 |
52 *ppvObject = null; | 73 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { |
53 return NS_ERROR_NO_INTERFACE; | 74 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); |
75 AddRef (); | |
76 return XPCOM.NS_OK; | |
54 } | 77 } |
78 if (guid.Equals (nsIFactory.NS_IFACTORY_IID)) { | |
79 XPCOM.memmove (ppvObject, new int /*long*/[] {factory.getAddress ()}, C.PTR_SIZEOF); | |
80 AddRef (); | |
81 return XPCOM.NS_OK; | |
82 } | |
83 | |
84 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
85 return XPCOM.NS_ERROR_NO_INTERFACE; | |
86 } | |
55 | 87 |
56 nsrefcnt Release () | 88 int Release () { |
57 { | 89 refCount--; |
58 _refCount--; | 90 if (refCount is 0) disposeCOMInterfaces (); |
59 if (_refCount is 0) | 91 return refCount; |
60 _refCount = 0; | 92 } |
61 return _refCount; | |
62 } | |
63 | 93 |
64 /* nsIFactory */ | 94 /* nsIFactory */ |
65 | 95 |
66 nsresult CreateInstance ( nsISupports aOuter, nsIID* iid, void** result) | 96 int CreateInstance (int /*long*/ aOuter, int /*long*/ iid, int /*long*/ result) { |
67 { | 97 Download download = new Download (); |
68 Download download = new Download (); | 98 download.AddRef (); |
69 download.AddRef (); | 99 XPCOM.memmove (result, new int /*long*/[] {download.getAddress ()}, C.PTR_SIZEOF); |
70 nsresult rv = download.QueryInterface( iid, result ); | 100 return XPCOM.NS_OK; |
71 return rv; | 101 } |
72 } | |
73 | 102 |
74 nsresult LockFactory (int lock) | 103 int LockFactory (int lock) { |
75 { | 104 return XPCOM.NS_OK; |
76 return NS_OK; | |
77 } | |
78 } | 105 } |
106 } |