1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 # include "nsCOMPtr.h"
15 #ifdef MOZILLA_INTERNAL_API
16 # include "nsComponentManager.h"
19 #include "nsComponentManagerUtils.h"
20 #include "nsServiceManagerUtils.h"
22 #include "nsIComponentManager.h"
24 #ifndef MOZILLA_INTERNAL_API
26 nsresult
CallGetService(const nsCID
& aCID
, const nsIID
& aIID
, void** aResult
) {
27 nsCOMPtr
<nsIServiceManager
> servMgr
;
28 nsresult status
= NS_GetServiceManager(getter_AddRefs(servMgr
));
30 status
= servMgr
->GetService(aCID
, aIID
, aResult
);
35 nsresult
CallGetService(const char* aContractID
, const nsIID
& aIID
,
37 nsCOMPtr
<nsIServiceManager
> servMgr
;
38 nsresult status
= NS_GetServiceManager(getter_AddRefs(servMgr
));
40 status
= servMgr
->GetServiceByContractID(aContractID
, aIID
, aResult
);
47 nsresult
CallGetService(const nsCID
& aCID
, const nsIID
& aIID
, void** aResult
) {
48 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
50 return NS_ERROR_NOT_INITIALIZED
;
53 return compMgr
->nsComponentManagerImpl::GetService(aCID
, aIID
, aResult
);
56 nsresult
CallGetService(const char* aContractID
, const nsIID
& aIID
,
58 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
60 return NS_ERROR_NOT_INITIALIZED
;
63 return compMgr
->nsComponentManagerImpl::GetServiceByContractID(aContractID
,
69 #ifndef MOZILLA_INTERNAL_API
71 nsresult
CallCreateInstance(const nsCID
& aCID
, const nsIID
& aIID
,
73 nsCOMPtr
<nsIComponentManager
> compMgr
;
74 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
76 status
= compMgr
->CreateInstance(aCID
, aIID
, aResult
);
81 nsresult
CallCreateInstance(const char* aContractID
, const nsIID
& aIID
,
83 nsCOMPtr
<nsIComponentManager
> compMgr
;
84 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
86 status
= compMgr
->CreateInstanceByContractID(aContractID
, aIID
, aResult
);
90 nsresult
CallGetClassObject(const nsCID
& aCID
, const nsIID
& aIID
,
92 nsCOMPtr
<nsIComponentManager
> compMgr
;
93 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
95 status
= compMgr
->GetClassObject(aCID
, aIID
, aResult
);
100 nsresult
CallGetClassObject(const char* aContractID
, const nsIID
& aIID
,
102 nsCOMPtr
<nsIComponentManager
> compMgr
;
103 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
105 status
= compMgr
->GetClassObjectByContractID(aContractID
, aIID
, aResult
);
111 nsresult
CallCreateInstance(const nsCID
& aCID
, const nsIID
& aIID
,
113 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
114 if (NS_WARN_IF(!compMgr
)) {
115 return NS_ERROR_NOT_INITIALIZED
;
118 return compMgr
->nsComponentManagerImpl::CreateInstance(aCID
, aIID
, aResult
);
121 nsresult
CallCreateInstance(const char* aContractID
, const nsIID
& aIID
,
123 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
124 if (NS_WARN_IF(!compMgr
)) {
125 return NS_ERROR_NOT_INITIALIZED
;
128 return compMgr
->nsComponentManagerImpl::CreateInstanceByContractID(
129 aContractID
, aIID
, aResult
);
132 nsresult
CallGetClassObject(const nsCID
& aCID
, const nsIID
& aIID
,
134 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
135 if (NS_WARN_IF(!compMgr
)) {
136 return NS_ERROR_NOT_INITIALIZED
;
139 return compMgr
->nsComponentManagerImpl::GetClassObject(aCID
, aIID
, aResult
);
142 nsresult
CallGetClassObject(const char* aContractID
, const nsIID
& aIID
,
144 nsComponentManagerImpl
* compMgr
= nsComponentManagerImpl::gComponentManager
;
145 if (NS_WARN_IF(!compMgr
)) {
146 return NS_ERROR_NOT_INITIALIZED
;
149 return compMgr
->nsComponentManagerImpl::GetClassObjectByContractID(
150 aContractID
, aIID
, aResult
);
155 nsresult
nsCreateInstanceByCID::operator()(const nsIID
& aIID
,
156 void** aInstancePtr
) const {
157 nsresult status
= CallCreateInstance(mCID
, aIID
, aInstancePtr
);
158 if (NS_FAILED(status
)) {
167 nsresult
nsCreateInstanceByContractID::operator()(const nsIID
& aIID
,
168 void** aInstancePtr
) const {
169 nsresult status
= CallCreateInstance(mContractID
, aIID
, aInstancePtr
);
170 if (NS_FAILED(status
)) {
179 nsresult
nsCreateInstanceFromFactory::operator()(const nsIID
& aIID
,
180 void** aInstancePtr
) const {
181 nsresult status
= mFactory
->CreateInstance(aIID
, aInstancePtr
);
182 if (NS_FAILED(status
)) {
191 nsresult
nsGetClassObjectByCID::operator()(const nsIID
& aIID
,
192 void** aInstancePtr
) const {
193 nsresult status
= CallGetClassObject(mCID
, aIID
, aInstancePtr
);
194 if (NS_FAILED(status
)) {
203 nsresult
nsGetClassObjectByContractID::operator()(const nsIID
& aIID
,
204 void** aInstancePtr
) const {
205 nsresult status
= CallGetClassObject(mContractID
, aIID
, aInstancePtr
);
206 if (NS_FAILED(status
)) {
215 nsresult
nsGetServiceByCID::operator()(const nsIID
& aIID
,
216 void** aInstancePtr
) const {
217 nsresult status
= CallGetService(mCID
, aIID
, aInstancePtr
);
218 if (NS_FAILED(status
)) {
225 nsresult
nsGetServiceByCIDWithError::operator()(const nsIID
& aIID
,
226 void** aInstancePtr
) const {
227 nsresult status
= CallGetService(mCID
, aIID
, aInstancePtr
);
228 if (NS_FAILED(status
)) {
238 nsresult
nsGetServiceByContractID::operator()(const nsIID
& aIID
,
239 void** aInstancePtr
) const {
240 nsresult status
= CallGetService(mContractID
, aIID
, aInstancePtr
);
241 if (NS_FAILED(status
)) {
248 nsresult
nsGetServiceByContractIDWithError::operator()(
249 const nsIID
& aIID
, void** aInstancePtr
) const {
250 nsresult status
= CallGetService(mContractID
, aIID
, aInstancePtr
);
251 if (NS_FAILED(status
)) {