1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/glue/nsServiceManagerUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsServiceManagerUtils_h__ 1.10 +#define nsServiceManagerUtils_h__ 1.11 + 1.12 +#include "nsIServiceManager.h" 1.13 +#include "nsCOMPtr.h" 1.14 + 1.15 +inline 1.16 +const nsGetServiceByCID 1.17 +do_GetService(const nsCID& aCID) 1.18 +{ 1.19 + return nsGetServiceByCID(aCID); 1.20 +} 1.21 + 1.22 +inline 1.23 +const nsGetServiceByCIDWithError 1.24 +do_GetService(const nsCID& aCID, nsresult* error) 1.25 +{ 1.26 + return nsGetServiceByCIDWithError(aCID, error); 1.27 +} 1.28 + 1.29 +inline 1.30 +const nsGetServiceByContractID 1.31 +do_GetService(const char* aContractID) 1.32 +{ 1.33 + return nsGetServiceByContractID(aContractID); 1.34 +} 1.35 + 1.36 +inline 1.37 +const nsGetServiceByContractIDWithError 1.38 +do_GetService( const char* aContractID, nsresult* error) 1.39 +{ 1.40 + return nsGetServiceByContractIDWithError(aContractID, error); 1.41 +} 1.42 + 1.43 +class nsGetServiceFromCategory : public nsCOMPtr_helper 1.44 +{ 1.45 + public: 1.46 + nsGetServiceFromCategory(const char* aCategory, const char* aEntry, 1.47 + nsresult* aErrorPtr) 1.48 + : mCategory(aCategory), 1.49 + mEntry(aEntry), 1.50 + mErrorPtr(aErrorPtr) 1.51 + { 1.52 + // nothing else to do 1.53 + } 1.54 + 1.55 + virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const; 1.56 + protected: 1.57 + const char* mCategory; 1.58 + const char* mEntry; 1.59 + nsresult* mErrorPtr; 1.60 +}; 1.61 + 1.62 +inline 1.63 +const nsGetServiceFromCategory 1.64 +do_GetServiceFromCategory( const char* category, const char* entry, 1.65 + nsresult* error = 0) 1.66 +{ 1.67 + return nsGetServiceFromCategory(category, entry, error); 1.68 +} 1.69 + 1.70 +NS_COM_GLUE nsresult 1.71 +CallGetService(const nsCID &aClass, const nsIID &aIID, void **aResult); 1.72 + 1.73 +NS_COM_GLUE nsresult 1.74 +CallGetService(const char *aContractID, const nsIID &aIID, void **aResult); 1.75 + 1.76 +// type-safe shortcuts for calling |GetService| 1.77 +template <class DestinationType> 1.78 +inline 1.79 +nsresult 1.80 +CallGetService( const nsCID &aClass, 1.81 + DestinationType** aDestination) 1.82 +{ 1.83 + NS_PRECONDITION(aDestination, "null parameter"); 1.84 + 1.85 + return CallGetService(aClass, 1.86 + NS_GET_TEMPLATE_IID(DestinationType), 1.87 + reinterpret_cast<void**>(aDestination)); 1.88 +} 1.89 + 1.90 +template <class DestinationType> 1.91 +inline 1.92 +nsresult 1.93 +CallGetService( const char *aContractID, 1.94 + DestinationType** aDestination) 1.95 +{ 1.96 + NS_PRECONDITION(aContractID, "null parameter"); 1.97 + NS_PRECONDITION(aDestination, "null parameter"); 1.98 + 1.99 + return CallGetService(aContractID, 1.100 + NS_GET_TEMPLATE_IID(DestinationType), 1.101 + reinterpret_cast<void**>(aDestination)); 1.102 +} 1.103 + 1.104 +#endif