1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is mozilla.org Code.
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
26 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef nsComponentManagerUtils_h__
|
---|
39 | #define nsComponentManagerUtils_h__
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * Do not include this file directly. Instead,
|
---|
43 | * |#include "nsIComponentManager.h"|.
|
---|
44 | */
|
---|
45 |
|
---|
46 | #ifndef nsCOMPtr_h__
|
---|
47 | #include "nsCOMPtr.h"
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #ifndef nsComponentManagerObsolete_h___
|
---|
51 | #include "nsComponentManagerObsolete.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #define NS_COMPONENTMANAGER_CID \
|
---|
55 | { /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
---|
56 | 0x91775d60, \
|
---|
57 | 0xd5dc, \
|
---|
58 | 0x11d2, \
|
---|
59 | {0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
---|
60 | }
|
---|
61 |
|
---|
62 | class NS_COM nsCreateInstanceByCID : public nsCOMPtr_helper
|
---|
63 | {
|
---|
64 | public:
|
---|
65 | nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
|
---|
66 | : mCID(aCID),
|
---|
67 | mOuter(aOuter),
|
---|
68 | mErrorPtr(aErrorPtr)
|
---|
69 | {
|
---|
70 | // nothing else to do here
|
---|
71 | }
|
---|
72 |
|
---|
73 | virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
---|
74 |
|
---|
75 | private:
|
---|
76 | const nsCID& mCID;
|
---|
77 | nsISupports* mOuter;
|
---|
78 | nsresult* mErrorPtr;
|
---|
79 | };
|
---|
80 |
|
---|
81 | class NS_COM nsCreateInstanceByContractID : public nsCOMPtr_helper
|
---|
82 | {
|
---|
83 | public:
|
---|
84 | nsCreateInstanceByContractID( const char* aContractID, nsISupports* aOuter, nsresult* aErrorPtr )
|
---|
85 | : mContractID(aContractID),
|
---|
86 | mOuter(aOuter),
|
---|
87 | mErrorPtr(aErrorPtr)
|
---|
88 | {
|
---|
89 | // nothing else to do here
|
---|
90 | }
|
---|
91 |
|
---|
92 | virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
---|
93 |
|
---|
94 | private:
|
---|
95 | const char* mContractID;
|
---|
96 | nsISupports* mOuter;
|
---|
97 | nsresult* mErrorPtr;
|
---|
98 | };
|
---|
99 |
|
---|
100 | inline
|
---|
101 | const nsCreateInstanceByCID
|
---|
102 | do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
|
---|
103 | {
|
---|
104 | return nsCreateInstanceByCID(aCID, 0, error);
|
---|
105 | }
|
---|
106 |
|
---|
107 | inline
|
---|
108 | const nsCreateInstanceByCID
|
---|
109 | do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
|
---|
110 | {
|
---|
111 | return nsCreateInstanceByCID(aCID, aOuter, error);
|
---|
112 | }
|
---|
113 |
|
---|
114 | inline
|
---|
115 | const nsCreateInstanceByContractID
|
---|
116 | do_CreateInstance( const char* aContractID, nsresult* error = 0 )
|
---|
117 | {
|
---|
118 | return nsCreateInstanceByContractID(aContractID, 0, error);
|
---|
119 | }
|
---|
120 |
|
---|
121 | inline
|
---|
122 | const nsCreateInstanceByContractID
|
---|
123 | do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error = 0 )
|
---|
124 | {
|
---|
125 | return nsCreateInstanceByContractID(aContractID, aOuter, error);
|
---|
126 | }
|
---|
127 |
|
---|
128 | // type-safe shortcuts for calling |CreateInstance|
|
---|
129 | template <class DestinationType>
|
---|
130 | inline
|
---|
131 | nsresult
|
---|
132 | CallCreateInstance( const nsCID &aClass,
|
---|
133 | nsISupports *aDelegate,
|
---|
134 | DestinationType** aDestination )
|
---|
135 | {
|
---|
136 | NS_PRECONDITION(aDestination, "null parameter");
|
---|
137 |
|
---|
138 | return nsComponentManager::CreateInstance(aClass, aDelegate,
|
---|
139 | NS_GET_IID(DestinationType),
|
---|
140 | NS_REINTERPRET_CAST(void**, aDestination));
|
---|
141 | }
|
---|
142 |
|
---|
143 | template <class DestinationType>
|
---|
144 | inline
|
---|
145 | nsresult
|
---|
146 | CallCreateInstance( const nsCID &aClass,
|
---|
147 | DestinationType** aDestination )
|
---|
148 | {
|
---|
149 | NS_PRECONDITION(aDestination, "null parameter");
|
---|
150 |
|
---|
151 | return nsComponentManager::CreateInstance(aClass, nsnull,
|
---|
152 | NS_GET_IID(DestinationType),
|
---|
153 | NS_REINTERPRET_CAST(void**, aDestination));
|
---|
154 | }
|
---|
155 |
|
---|
156 | template <class DestinationType>
|
---|
157 | inline
|
---|
158 | nsresult
|
---|
159 | CallCreateInstance( const char *aContractID,
|
---|
160 | nsISupports *aDelegate,
|
---|
161 | DestinationType** aDestination )
|
---|
162 | {
|
---|
163 | NS_PRECONDITION(aContractID, "null parameter");
|
---|
164 | NS_PRECONDITION(aDestination, "null parameter");
|
---|
165 |
|
---|
166 | return nsComponentManager::CreateInstance(aContractID,
|
---|
167 | aDelegate,
|
---|
168 | NS_GET_IID(DestinationType),
|
---|
169 | NS_REINTERPRET_CAST(void**, aDestination));
|
---|
170 | }
|
---|
171 |
|
---|
172 | template <class DestinationType>
|
---|
173 | inline
|
---|
174 | nsresult
|
---|
175 | CallCreateInstance( const char *aContractID,
|
---|
176 | DestinationType** aDestination )
|
---|
177 | {
|
---|
178 | NS_PRECONDITION(aContractID, "null parameter");
|
---|
179 | NS_PRECONDITION(aDestination, "null parameter");
|
---|
180 |
|
---|
181 | return nsComponentManager::CreateInstance(aContractID, nsnull,
|
---|
182 | NS_GET_IID(DestinationType),
|
---|
183 | NS_REINTERPRET_CAST(void**, aDestination));
|
---|
184 | }
|
---|
185 |
|
---|
186 | /* keys for registry use */
|
---|
187 | extern const char xpcomKeyName[];
|
---|
188 | extern const char xpcomComponentsKeyName[];
|
---|
189 | extern const char lastModValueName[];
|
---|
190 | extern const char fileSizeValueName[];
|
---|
191 | extern const char nativeComponentType[];
|
---|
192 | extern const char staticComponentType[];
|
---|
193 |
|
---|
194 | #endif /* nsComponentManagerUtils_h__ */
|
---|
195 |
|
---|
196 |
|
---|