Back to index

lightning-sunbird  0.9+nobinonly
nsComponentManagerUtils.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsXPCOM_h__
00039 #include "nsXPCOM.h"
00040 #endif
00041 
00042 #ifndef nsCOMPtr_h__
00043 #include "nsCOMPtr.h"
00044 #endif
00045 
00046 #include "nsComponentManagerUtils.h"
00047 #include "nsServiceManagerUtils.h"
00048 
00049 #include "nsIComponentManager.h"
00050 
00051 #ifndef MOZILLA_INTERNAL_API
00052 
00053 nsresult
00054 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
00055 {
00056     nsCOMPtr<nsIServiceManager> servMgr;
00057     nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
00058     if (servMgr)
00059         status = servMgr->GetService(aCID, aIID, aResult);
00060     return status;
00061 }
00062 
00063 nsresult
00064 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
00065 {
00066     nsCOMPtr<nsIServiceManager> servMgr;
00067     nsresult status = NS_GetServiceManager(getter_AddRefs(servMgr));
00068     if (servMgr)
00069         status = servMgr->GetServiceByContractID(aContractID, aIID, aResult);
00070     return status;
00071 }
00072 
00073 #else
00074 
00075 #include "nsComponentManager.h"
00076 
00077 nsresult
00078 CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
00079 {
00080     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00081     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00082 
00083     return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
00084 }
00085 
00086 nsresult
00087 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
00088 {
00089     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00090     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00091 
00092     return compMgr->
00093         nsComponentManagerImpl::GetServiceByContractID(aContractID,
00094                                                        aIID, aResult);
00095 }
00096 
00097 #endif
00098 
00099 #ifndef MOZILLA_INTERNAL_API
00100 
00101 nsresult
00102 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
00103                    const nsIID &aIID, void **aResult)
00104 {
00105     nsCOMPtr<nsIComponentManager> compMgr;
00106     nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
00107     if (compMgr)
00108         status = compMgr->CreateInstance(aCID, aDelegate, aIID, aResult);
00109     return status;
00110 }
00111 
00112 nsresult
00113 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
00114                    const nsIID &aIID, void **aResult)
00115 {
00116     nsCOMPtr<nsIComponentManager> compMgr;
00117     nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
00118     if (compMgr)
00119         status = compMgr->CreateInstanceByContractID(aContractID, aDelegate,
00120                                                      aIID, aResult);
00121     return status;
00122 }
00123 
00124 nsresult
00125 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
00126 {
00127     nsCOMPtr<nsIComponentManager> compMgr;
00128     nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
00129     if (compMgr)
00130         status = compMgr->GetClassObject(aCID, aIID, aResult);
00131     return status;
00132 }
00133 
00134 nsresult
00135 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
00136 {
00137     nsCOMPtr<nsIComponentManager> compMgr;
00138     nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
00139     if (compMgr)
00140         status = compMgr->GetClassObjectByContractID(aContractID, aIID,
00141                                                      aResult);
00142     return status;
00143 }
00144 
00145 #else
00146 
00147 #include "nsComponentManager.h"
00148 
00149 nsresult
00150 CallCreateInstance(const nsCID &aCID, nsISupports *aDelegate,
00151                    const nsIID &aIID, void **aResult)
00152 {
00153     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00154     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00155 
00156     return compMgr->
00157         nsComponentManagerImpl::CreateInstance(aCID, aDelegate, aIID, aResult);
00158 }
00159 
00160 nsresult
00161 CallCreateInstance(const char *aContractID, nsISupports *aDelegate,
00162                    const nsIID &aIID, void **aResult)
00163 {
00164     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00165     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00166 
00167     return compMgr->
00168         nsComponentManagerImpl::CreateInstanceByContractID(aContractID,
00169                                                            aDelegate, aIID,
00170                                                            aResult);
00171 }
00172 
00173 nsresult
00174 CallGetClassObject(const nsCID &aCID, const nsIID &aIID, void **aResult)
00175 {
00176     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00177     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00178 
00179     return compMgr->
00180         nsComponentManagerImpl::GetClassObject(aCID, aIID, aResult);
00181 }
00182 
00183 nsresult
00184 CallGetClassObject(const char *aContractID, const nsIID &aIID, void **aResult)
00185 {
00186     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
00187     NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
00188 
00189     return compMgr->
00190         nsComponentManagerImpl::GetClassObjectByContractID(aContractID, aIID,
00191                                                            aResult);
00192 }
00193 
00194 #endif
00195 
00196 nsresult
00197 nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00198 {
00199     nsresult status = CallCreateInstance(mCID, mOuter, aIID, aInstancePtr);
00200     if ( NS_FAILED(status) )
00201         *aInstancePtr = 0;
00202     if ( mErrorPtr )
00203         *mErrorPtr = status;
00204     return status;
00205 }
00206 
00207 nsresult
00208 nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00209 {
00210     nsresult status = CallCreateInstance(mContractID, mOuter, aIID, aInstancePtr);
00211     if (NS_FAILED(status))
00212         *aInstancePtr = 0;
00213     if ( mErrorPtr )
00214         *mErrorPtr = status;
00215     return status;
00216 }
00217 
00218 nsresult
00219 nsCreateInstanceFromFactory::operator()( const nsIID& aIID, void** aInstancePtr ) const
00220 {
00221     nsresult status = mFactory->CreateInstance(mOuter, aIID, aInstancePtr);
00222     if ( NS_FAILED(status) )
00223         *aInstancePtr = 0;
00224     if ( mErrorPtr )
00225         *mErrorPtr = status;
00226     return status;
00227 }
00228 
00229 
00230 nsresult
00231 nsGetClassObjectByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00232 {
00233     nsresult status = CallGetClassObject(mCID, aIID, aInstancePtr);
00234     if ( NS_FAILED(status) )
00235         *aInstancePtr = 0;
00236     if ( mErrorPtr )
00237         *mErrorPtr = status;
00238     return status;
00239 }
00240 
00241 nsresult
00242 nsGetClassObjectByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00243 {
00244     nsresult status = CallGetClassObject(mContractID, aIID, aInstancePtr);
00245     if ( NS_FAILED(status) )
00246         *aInstancePtr = 0;
00247     if ( mErrorPtr )
00248         *mErrorPtr = status;
00249     return status;
00250 }
00251 
00252 
00253 nsresult
00254 nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00255 {
00256     nsresult status = CallGetService(mCID, aIID, aInstancePtr);
00257     if ( NS_FAILED(status) )
00258         *aInstancePtr = 0;
00259 
00260     return status;
00261 }
00262 
00263 nsresult
00264 nsGetServiceByCIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
00265 {
00266     nsresult status = CallGetService(mCID, aIID, aInstancePtr);
00267     if ( NS_FAILED(status) )
00268         *aInstancePtr = 0;
00269 
00270     if ( mErrorPtr )
00271         *mErrorPtr = status;
00272     return status;
00273 }
00274 
00275 nsresult
00276 nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
00277 {
00278     nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
00279     if ( NS_FAILED(status) )
00280         *aInstancePtr = 0;
00281     
00282     return status;
00283 }
00284 
00285 nsresult
00286 nsGetServiceByContractIDWithError::operator()( const nsIID& aIID, void** aInstancePtr ) const
00287 {
00288     nsresult status = CallGetService(mContractID, aIID, aInstancePtr);
00289     if ( NS_FAILED(status) )
00290         *aInstancePtr = 0;
00291     
00292     if ( mErrorPtr )
00293         *mErrorPtr = status;
00294     return status;
00295 }