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 nsXPCOM_h__
39 : #include "nsXPCOM.h"
40 : #endif
41 :
42 : #ifndef nsCOMPtr_h__
43 : #include "nsCOMPtr.h"
44 : #endif
45 :
46 : #include "nsComponentManagerUtils.h"
47 : #include "nsServiceManagerUtils.h"
48 :
49 : #include "nsIComponentManager.h"
50 :
51 : #ifndef MOZILLA_INTERNAL_API
52 :
53 : nsresult
54 : CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
55 : {
56 : nsCOMPtr<nsIServiceManager> servMgr;
57 : nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
58 : if (servMgr)
59 : status = servMgr->GetService(aCID, aIID, aResult);
60 : return status;
61 : }
62 :
63 : nsresult
64 : CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
65 : {
66 : nsCOMPtr<nsIServiceManager> servMgr;
67 : nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
68 : if (servMgr)
69 : status = servMgr->GetServiceByContractID(aContractID, aIID, aResult);
70 : return status;
71 : }
72 :
73 : #else
74 :
75 : #include "nsComponentManager.h"
76 :
77 : nsresult
78 20243 : CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
79 : {
80 20243 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
81 20243 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
82 :
83 20243 : return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
84 : }
85 :
86 : nsresult
87 586896 : CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
88 : {
89 586896 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
90 586896 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
91 :
92 : return compMgr->
93 : nsComponentManagerImpl::GetServiceByContractID(aContractID,
94 586896 : aIID, aResult);
95 : }
96 :
97 : #endif
98 :
99 : #ifndef MOZILLA_INTERNAL_API
100 :
101 : nsresult
102 : CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
103 : const nsIID &aIID, void **aResult)
104 : {
105 : nsCOMPtr<nsIComponentManager> compMgr;
106 : nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
107 : if (compMgr)
108 : status = compMgr->CreateInstance(aCID, aDelegate, aIID, aResult);
109 : return status;
110 : }
111 :
112 : nsresult
113 : CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
114 : const nsIID &aIID, void **aResult)
115 : {
116 : nsCOMPtr<nsIComponentManager> compMgr;
117 : nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
118 : if (compMgr)
119 : status = compMgr->CreateInstanceByContractID(aContractID, aDelegate,
120 : aIID, aResult);
121 : return status;
122 : }
123 :
124 : nsresult
125 : CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
126 : {
127 : nsCOMPtr<nsIComponentManager> compMgr;
128 : nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
129 : if (compMgr)
130 : status = compMgr->GetClassObject(aCID, aIID, aResult);
131 : return status;
132 : }
133 :
134 : nsresult
135 : CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
136 : {
137 : nsCOMPtr<nsIComponentManager> compMgr;
138 : nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
139 : if (compMgr)
140 : status = compMgr->GetClassObjectByContractID(aContractID, aIID,
141 : aResult);
142 : return status;
143 : }
144 :
145 : #else
146 :
147 : #include "nsComponentManager.h"
148 :
149 : nsresult
150 11100 : CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
151 : const nsIID &aIID, void **aResult)
152 : {
153 11100 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
154 11100 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
155 :
156 : return compMgr->
157 11100 : nsComponentManagerImpl::CreateInstance(aCID, aDelegate, aIID, aResult);
158 : }
159 :
160 : nsresult
161 394608 : CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
162 : const nsIID &aIID, void **aResult)
163 : {
164 394608 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
165 394608 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
166 :
167 : return compMgr->
168 : nsComponentManagerImpl::CreateInstanceByContractID(aContractID,
169 : aDelegate, aIID,
170 394608 : aResult);
171 : }
172 :
173 : nsresult
174 1404 : CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
175 : {
176 1404 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
177 1404 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
178 :
179 : return compMgr->
180 1404 : nsComponentManagerImpl::GetClassObject(aCID, aIID, aResult);
181 : }
182 :
183 : nsresult
184 14623 : CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
185 : {
186 14623 : nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
187 14623 : NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
188 :
189 : return compMgr->
190 : nsComponentManagerImpl::GetClassObjectByContractID(aContractID, aIID,
191 14623 : aResult);
192 : }
193 :
194 : #endif
195 :
196 : nsresult
197 11081 : nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
198 : {
199 11081 : nsresult status = CallCreateInstance(mCID, mOuter, aIID, aInstancePtr);
200 11081 : if ( NS_FAILED(status) )
201 0 : *aInstancePtr = 0;
202 11081 : if ( mErrorPtr )
203 11052 : *mErrorPtr = status;
204 11081 : return status;
205 : }
206 :
207 : nsresult
208 389046 : nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
209 : {
210 389046 : nsresult status = CallCreateInstance(mContractID, mOuter, aIID, aInstancePtr);
211 389046 : if (NS_FAILED(status))
212 24 : *aInstancePtr = 0;
213 389046 : if ( mErrorPtr )
214 334436 : *mErrorPtr = status;
215 389046 : return status;
216 : }
217 :
218 : nsresult
219 0 : nsCreateInstanceFromFactory::operator()( const nsIID& aIID, void** aInstancePtr ) const
220 : {
221 0 : nsresult status = mFactory->CreateInstance(mOuter, aIID, aInstancePtr);
222 0 : if ( NS_FAILED(status) )
223 0 : *aInstancePtr = 0;
224 0 : if ( mErrorPtr )
225 0 : *mErrorPtr = status;
226 0 : return status;
227 : }
228 :
229 :
230 : nsresult
231 1404 : nsGetClassObjectByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
232 : {
233 1404 : nsresult status = CallGetClassObject(mCID, aIID, aInstancePtr);
234 1404 : if ( NS_FAILED(status) )
235 0 : *aInstancePtr = 0;
236 1404 : if ( mErrorPtr )
237 1404 : *mErrorPtr = status;
238 1404 : return status;
239 : }
240 :
241 : nsresult
242 14623 : nsGetClassObjectByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
243 : {
244 14623 : nsresult status = CallGetClassObject(mContractID, aIID, aInstancePtr);
245 14623 : if ( NS_FAILED(status) )
246 14623 : *aInstancePtr = 0;
247 14623 : if ( mErrorPtr )
248 0 : *mErrorPtr = status;
249 14623 : return status;
250 : }
251 :
252 :
253 : nsresult
254 2572 : nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
255 : {
256 2572 : nsresult status = CallGetService(mCID, aIID, aInstancePtr);
257 2572 : if ( NS_FAILED(status) )
258 0 : *aInstancePtr = 0;
259 :
260 2572 : return status;
261 : }
262 :
263 : nsresult
264 6065 : nsGetServiceByCIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
265 : {
266 6065 : nsresult status = CallGetService(mCID, aIID, aInstancePtr);
267 6065 : if ( NS_FAILED(status) )
268 281 : *aInstancePtr = 0;
269 :
270 6065 : if ( mErrorPtr )
271 6065 : *mErrorPtr = status;
272 6065 : return status;
273 : }
274 :
275 : nsresult
276 421572 : nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
277 : {
278 421572 : nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
279 421572 : if ( NS_FAILED(status) )
280 120428 : *aInstancePtr = 0;
281 :
282 421572 : return status;
283 : }
284 :
285 : nsresult
286 129750 : nsGetServiceByContractIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
287 : {
288 129750 : nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
289 129750 : if ( NS_FAILED(status) )
290 2838 : *aInstancePtr = 0;
291 :
292 129750 : if ( mErrorPtr )
293 129750 : *mErrorPtr = status;
294 129750 : return status;
295 : }
|