nsComponentManagerUtils.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
1N/A/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
1N/A/* ***** BEGIN LICENSE BLOCK *****
1N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1
1N/A *
1N/A * The contents of this file are subject to the Mozilla Public License Version
1N/A * 1.1 (the "License"); you may not use this file except in compliance with
1N/A * the License. You may obtain a copy of the License at
1N/A * http://www.mozilla.org/MPL/
1N/A *
1N/A * Software distributed under the License is distributed on an "AS IS" basis,
1N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1N/A * for the specific language governing rights and limitations under the
1N/A * License.
1N/A *
1N/A * The Original Code is mozilla.org code.
1N/A *
1N/A * The Initial Developer of the Original Code is
1N/A * Netscape Communications Corporation.
1N/A * Portions created by the Initial Developer are Copyright (C) 1998
1N/A * the Initial Developer. All Rights Reserved.
1N/A *
1N/A * Contributor(s):
1N/A *
1N/A * Alternatively, the contents of this file may be used under the terms of
1N/A * either of the GNU General Public License Version 2 or later (the "GPL"),
1N/A * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1N/A * in which case the provisions of the GPL or the LGPL are applicable instead
1N/A * of those above. If you wish to allow use of your version of this file only
1N/A * under the terms of either the GPL or the LGPL, and not to allow others to
1N/A * use your version of this file under the terms of the MPL, indicate your
1N/A * decision by deleting the provisions above and replace them with the notice
1N/A * and other provisions required by the GPL or the LGPL. If you do not delete
1N/A * the provisions above, a recipient may use your version of this file under
1N/A * the terms of any one of the MPL, the GPL or the LGPL.
1N/A *
1N/A * ***** END LICENSE BLOCK ***** */
1N/A
1N/A#ifndef nsXPCOM_h__
1N/A#include "nsXPCOM.h"
1N/A#endif
1N/A
1N/A#ifndef nsCOMPtr_h__
1N/A#include "nsCOMPtr.h"
1N/A#endif
1N/A
1N/A#include "nsComponentManagerUtils.h"
1N/A#include "nsIServiceManagerUtils.h"
1N/A
1N/Ansresult
1N/AnsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
1N/A{
1N/A nsCOMPtr<nsIComponentManager> compMgr;
1N/A nsresult status = NS_GetComponentManager(getter_AddRefs(compMgr));
1N/A if (compMgr)
1N/A status = compMgr->CreateInstance(mCID, mOuter, aIID, aInstancePtr);
1N/A else if (NS_SUCCEEDED(status))
1N/A status = NS_ERROR_UNEXPECTED;
1N/A
1N/A if ( NS_FAILED(status) )
1N/A *aInstancePtr = 0;
1N/A
1N/A if ( mErrorPtr )
1N/A *mErrorPtr = status;
1N/A return status;
1N/A}
1N/A
1N/Ansresult
1N/AnsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
1N/A{
1N/A nsresult status;
1N/A if ( mContractID ) {
1N/A nsCOMPtr<nsIComponentManager> compMgr;
1N/A status = NS_GetComponentManager(getter_AddRefs(compMgr));
1N/A if (compMgr)
1N/A status = compMgr->CreateInstanceByContractID(mContractID, mOuter,
1N/A aIID, aInstancePtr);
1N/A else if (NS_SUCCEEDED(status))
1N/A status = NS_ERROR_UNEXPECTED;
}
else
status = NS_ERROR_NULL_POINTER;
if (NS_FAILED(status))
*aInstancePtr = 0;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
nsresult
nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status = NS_ERROR_FAILURE;
if ( mServiceManager ) {
status = mServiceManager->GetService(mCID, aIID, (void**)aInstancePtr);
} else {
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager(getter_AddRefs(mgr));
if (mgr)
status = mgr->GetService(mCID, aIID, (void**)aInstancePtr);
}
if ( NS_FAILED(status) )
*aInstancePtr = 0;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
nsresult
nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status = NS_ERROR_FAILURE;
if ( mServiceManager ) {
status = mServiceManager->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr);
} else {
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager(getter_AddRefs(mgr));
if (mgr)
status = mgr->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr);
}
if ( NS_FAILED(status) )
*aInstancePtr = 0;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}