On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / glue / nsComponentManagerUtils.cpp
blob9ed06a3f962cd05aae227131746f275c421176c2
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
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/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsXPCOM_h__
39 #include "nsXPCOM.h"
40 #endif
42 #ifndef nsCOMPtr_h__
43 #include "nsCOMPtr.h"
44 #endif
46 #include "nsComponentManagerUtils.h"
47 #include "nsServiceManagerUtils.h"
49 #include "nsIComponentManager.h"
51 #ifndef MOZILLA_INTERNAL_API
53 nsresult
54 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
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;
63 nsresult
64 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
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;
73 #else
75 #include "nsComponentManager.h"
77 nsresult
78 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
80 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
81 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
83 return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
86 nsresult
87 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
89 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
90 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
92 return compMgr->
93 nsComponentManagerImpl::GetServiceByContractID(aContractID,
94 aIID, aResult);
97 #endif
99 #ifndef MOZILLA_INTERNAL_API
101 nsresult
102 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
103 const nsIID &aIID, void **aResult)
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;
112 nsresult
113 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
114 const nsIID &aIID, void **aResult)
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;
124 nsresult
125 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
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;
134 nsresult
135 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
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;
145 #else
147 #include "nsComponentManager.h"
149 nsresult
150 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
151 const nsIID &aIID, void **aResult)
153 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
154 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
156 return compMgr->
157 nsComponentManagerImpl::CreateInstance(aCID, aDelegate, aIID, aResult);
160 nsresult
161 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
162 const nsIID &aIID, void **aResult)
164 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
165 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
167 return compMgr->
168 nsComponentManagerImpl::CreateInstanceByContractID(aContractID,
169 aDelegate, aIID,
170 aResult);
173 nsresult
174 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
176 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
177 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
179 return compMgr->
180 nsComponentManagerImpl::GetClassObject(aCID, aIID, aResult);
183 nsresult
184 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
186 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
187 NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
189 return compMgr->
190 nsComponentManagerImpl::GetClassObjectByContractID(aContractID, aIID,
191 aResult);
194 #endif
196 nsresult
197 nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
199 nsresult status = CallCreateInstance(mCID, mOuter, aIID, aInstancePtr);
200 if ( NS_FAILED(status) )
201 *aInstancePtr = 0;
202 if ( mErrorPtr )
203 *mErrorPtr = status;
204 return status;
207 nsresult
208 nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
210 nsresult status = CallCreateInstance(mContractID, mOuter, aIID, aInstancePtr);
211 if (NS_FAILED(status))
212 *aInstancePtr = 0;
213 if ( mErrorPtr )
214 *mErrorPtr = status;
215 return status;
218 nsresult
219 nsCreateInstanceFromFactory::operator()( const nsIID& aIID, void** aInstancePtr ) const
221 nsresult status = mFactory->CreateInstance(mOuter, aIID, aInstancePtr);
222 if ( NS_FAILED(status) )
223 *aInstancePtr = 0;
224 if ( mErrorPtr )
225 *mErrorPtr = status;
226 return status;
230 nsresult
231 nsGetClassObjectByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
233 nsresult status = CallGetClassObject(mCID, aIID, aInstancePtr);
234 if ( NS_FAILED(status) )
235 *aInstancePtr = 0;
236 if ( mErrorPtr )
237 *mErrorPtr = status;
238 return status;
241 nsresult
242 nsGetClassObjectByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
244 nsresult status = CallGetClassObject(mContractID, aIID, aInstancePtr);
245 if ( NS_FAILED(status) )
246 *aInstancePtr = 0;
247 if ( mErrorPtr )
248 *mErrorPtr = status;
249 return status;
253 nsresult
254 nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
256 nsresult status = CallGetService(mCID, aIID, aInstancePtr);
257 if ( NS_FAILED(status) )
258 *aInstancePtr = 0;
260 return status;
263 nsresult
264 nsGetServiceByCIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
266 nsresult status = CallGetService(mCID, aIID, aInstancePtr);
267 if ( NS_FAILED(status) )
268 *aInstancePtr = 0;
270 if ( mErrorPtr )
271 *mErrorPtr = status;
272 return status;
275 nsresult
276 nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
278 nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
279 if ( NS_FAILED(status) )
280 *aInstancePtr = 0;
282 return status;
285 nsresult
286 nsGetServiceByContractIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
288 nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
289 if ( NS_FAILED(status) )
290 *aInstancePtr = 0;
292 if ( mErrorPtr )
293 *mErrorPtr = status;
294 return status;