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
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.
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 ***** */
46 #include "nsComponentManagerUtils.h"
47 #include "nsServiceManagerUtils.h"
49 #include "nsIComponentManager.h"
51 #ifndef MOZILLA_INTERNAL_API
54 CallGetService(const nsCID
&aCID
, const nsIID
&aIID
, void **aResult
)
56 nsCOMPtr
<nsIServiceManager
> servMgr
;
57 nsresult status
= NS_GetServiceManager(getter_AddRefs(servMgr
));
59 status
= servMgr
->GetService(aCID
, aIID
, aResult
);
64 CallGetService(const char *aContractID
, const nsIID
&aIID
, void **aResult
)
66 nsCOMPtr
<nsIServiceManager
> servMgr
;
67 nsresult status
= NS_GetServiceManager(getter_AddRefs(servMgr
));
69 status
= servMgr
->GetServiceByContractID(aContractID
, aIID
, aResult
);
75 #include "nsComponentManager.h"
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
);
87 CallGetService(const char *aContractID
, const nsIID
&aIID
, void **aResult
)
89 nsComponentManagerImpl
*compMgr
= nsComponentManagerImpl::gComponentManager
;
90 NS_ENSURE_TRUE(compMgr
, NS_ERROR_NOT_INITIALIZED
);
93 nsComponentManagerImpl::GetServiceByContractID(aContractID
,
99 #ifndef MOZILLA_INTERNAL_API
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
));
108 status
= compMgr
->CreateInstance(aCID
, aDelegate
, aIID
, aResult
);
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
));
119 status
= compMgr
->CreateInstanceByContractID(aContractID
, aDelegate
,
125 CallGetClassObject(const nsCID
&aCID
, const nsIID
&aIID
, void **aResult
)
127 nsCOMPtr
<nsIComponentManager
> compMgr
;
128 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
130 status
= compMgr
->GetClassObject(aCID
, aIID
, aResult
);
135 CallGetClassObject(const char *aContractID
, const nsIID
&aIID
, void **aResult
)
137 nsCOMPtr
<nsIComponentManager
> compMgr
;
138 nsresult status
= NS_GetComponentManager(getter_AddRefs(compMgr
));
140 status
= compMgr
->GetClassObjectByContractID(aContractID
, aIID
,
147 #include "nsComponentManager.h"
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
);
157 nsComponentManagerImpl::CreateInstance(aCID
, aDelegate
, aIID
, aResult
);
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
);
168 nsComponentManagerImpl::CreateInstanceByContractID(aContractID
,
174 CallGetClassObject(const nsCID
&aCID
, const nsIID
&aIID
, void **aResult
)
176 nsComponentManagerImpl
*compMgr
= nsComponentManagerImpl::gComponentManager
;
177 NS_ENSURE_TRUE(compMgr
, NS_ERROR_NOT_INITIALIZED
);
180 nsComponentManagerImpl::GetClassObject(aCID
, aIID
, aResult
);
184 CallGetClassObject(const char *aContractID
, const nsIID
&aIID
, void **aResult
)
186 nsComponentManagerImpl
*compMgr
= nsComponentManagerImpl::gComponentManager
;
187 NS_ENSURE_TRUE(compMgr
, NS_ERROR_NOT_INITIALIZED
);
190 nsComponentManagerImpl::GetClassObjectByContractID(aContractID
, aIID
,
197 nsCreateInstanceByCID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
199 nsresult status
= CallCreateInstance(mCID
, mOuter
, aIID
, aInstancePtr
);
200 if ( NS_FAILED(status
) )
208 nsCreateInstanceByContractID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
210 nsresult status
= CallCreateInstance(mContractID
, mOuter
, aIID
, aInstancePtr
);
211 if (NS_FAILED(status
))
219 nsCreateInstanceFromFactory::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
221 nsresult status
= mFactory
->CreateInstance(mOuter
, aIID
, aInstancePtr
);
222 if ( NS_FAILED(status
) )
231 nsGetClassObjectByCID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
233 nsresult status
= CallGetClassObject(mCID
, aIID
, aInstancePtr
);
234 if ( NS_FAILED(status
) )
242 nsGetClassObjectByContractID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
244 nsresult status
= CallGetClassObject(mContractID
, aIID
, aInstancePtr
);
245 if ( NS_FAILED(status
) )
254 nsGetServiceByCID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
256 nsresult status
= CallGetService(mCID
, aIID
, aInstancePtr
);
257 if ( NS_FAILED(status
) )
264 nsGetServiceByCIDWithError::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
266 nsresult status
= CallGetService(mCID
, aIID
, aInstancePtr
);
267 if ( NS_FAILED(status
) )
276 nsGetServiceByContractID::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
278 nsresult status
= CallGetService(mContractID
, aIID
, aInstancePtr
);
279 if ( NS_FAILED(status
) )
286 nsGetServiceByContractIDWithError::operator()( const nsIID
& aIID
, void** aInstancePtr
) const
288 nsresult status
= CallGetService(mContractID
, aIID
, aInstancePtr
);
289 if ( NS_FAILED(status
) )