michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsServiceManagerUtils_h__ michael@0: #define nsServiceManagerUtils_h__ michael@0: michael@0: #include "nsIServiceManager.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: inline michael@0: const nsGetServiceByCID michael@0: do_GetService(const nsCID& aCID) michael@0: { michael@0: return nsGetServiceByCID(aCID); michael@0: } michael@0: michael@0: inline michael@0: const nsGetServiceByCIDWithError michael@0: do_GetService(const nsCID& aCID, nsresult* error) michael@0: { michael@0: return nsGetServiceByCIDWithError(aCID, error); michael@0: } michael@0: michael@0: inline michael@0: const nsGetServiceByContractID michael@0: do_GetService(const char* aContractID) michael@0: { michael@0: return nsGetServiceByContractID(aContractID); michael@0: } michael@0: michael@0: inline michael@0: const nsGetServiceByContractIDWithError michael@0: do_GetService( const char* aContractID, nsresult* error) michael@0: { michael@0: return nsGetServiceByContractIDWithError(aContractID, error); michael@0: } michael@0: michael@0: class nsGetServiceFromCategory : public nsCOMPtr_helper michael@0: { michael@0: public: michael@0: nsGetServiceFromCategory(const char* aCategory, const char* aEntry, michael@0: nsresult* aErrorPtr) michael@0: : mCategory(aCategory), michael@0: mEntry(aEntry), michael@0: mErrorPtr(aErrorPtr) michael@0: { michael@0: // nothing else to do michael@0: } michael@0: michael@0: virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const; michael@0: protected: michael@0: const char* mCategory; michael@0: const char* mEntry; michael@0: nsresult* mErrorPtr; michael@0: }; michael@0: michael@0: inline michael@0: const nsGetServiceFromCategory michael@0: do_GetServiceFromCategory( const char* category, const char* entry, michael@0: nsresult* error = 0) michael@0: { michael@0: return nsGetServiceFromCategory(category, entry, error); michael@0: } michael@0: michael@0: NS_COM_GLUE nsresult michael@0: CallGetService(const nsCID &aClass, const nsIID &aIID, void **aResult); michael@0: michael@0: NS_COM_GLUE nsresult michael@0: CallGetService(const char *aContractID, const nsIID &aIID, void **aResult); michael@0: michael@0: // type-safe shortcuts for calling |GetService| michael@0: template michael@0: inline michael@0: nsresult michael@0: CallGetService( const nsCID &aClass, michael@0: DestinationType** aDestination) michael@0: { michael@0: NS_PRECONDITION(aDestination, "null parameter"); michael@0: michael@0: return CallGetService(aClass, michael@0: NS_GET_TEMPLATE_IID(DestinationType), michael@0: reinterpret_cast(aDestination)); michael@0: } michael@0: michael@0: template michael@0: inline michael@0: nsresult michael@0: CallGetService( const char *aContractID, michael@0: DestinationType** aDestination) michael@0: { michael@0: NS_PRECONDITION(aContractID, "null parameter"); michael@0: NS_PRECONDITION(aDestination, "null parameter"); michael@0: michael@0: return CallGetService(aContractID, michael@0: NS_GET_TEMPLATE_IID(DestinationType), michael@0: reinterpret_cast(aDestination)); michael@0: } michael@0: michael@0: #endif