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