1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsServiceManagerUtils_h__
8 #define nsServiceManagerUtils_h__
13 inline const nsGetServiceByCID
do_GetService(const nsCID
& aCID
) {
14 return nsGetServiceByCID(aCID
);
17 inline const nsGetServiceByCIDWithError
do_GetService(const nsCID
& aCID
,
19 return nsGetServiceByCIDWithError(aCID
, aError
);
22 inline const nsGetServiceByContractID
do_GetService(const char* aContractID
) {
23 return nsGetServiceByContractID(aContractID
);
26 inline const nsGetServiceByContractIDWithError
do_GetService(
27 const char* aContractID
, nsresult
* aError
) {
28 return nsGetServiceByContractIDWithError(aContractID
, aError
);
31 class MOZ_STACK_CLASS nsGetServiceFromCategory final
: public nsCOMPtr_helper
{
33 nsGetServiceFromCategory(const nsACString
& aCategory
,
34 const nsACString
& aEntry
, nsresult
* aErrorPtr
)
35 : mCategory(aCategory
), mEntry(aEntry
), mErrorPtr(aErrorPtr
) {}
37 virtual nsresult NS_FASTCALL
operator()(const nsIID
&, void**) const override
;
40 const nsCString mCategory
;
41 const nsCString mEntry
;
45 inline const nsGetServiceFromCategory
do_GetServiceFromCategory(
46 const nsACString
& aCategory
, const nsACString
& aEntry
,
47 nsresult
* aError
= 0) {
48 return nsGetServiceFromCategory(aCategory
, aEntry
, aError
);
51 nsresult
CallGetService(const nsCID
& aClass
, const nsIID
& aIID
, void** aResult
);
53 nsresult
CallGetService(const char* aContractID
, const nsIID
& aIID
,
56 // type-safe shortcuts for calling |GetService|
57 template <class DestinationType
>
58 inline nsresult
CallGetService(const nsCID
& aClass
,
59 DestinationType
** aDestination
) {
60 MOZ_ASSERT(aDestination
, "null parameter");
62 return CallGetService(aClass
, NS_GET_TEMPLATE_IID(DestinationType
),
63 reinterpret_cast<void**>(aDestination
));
66 template <class DestinationType
>
67 inline nsresult
CallGetService(const char* aContractID
,
68 DestinationType
** aDestination
) {
69 MOZ_ASSERT(aContractID
, "null parameter");
70 MOZ_ASSERT(aDestination
, "null parameter");
72 return CallGetService(aContractID
, NS_GET_TEMPLATE_IID(DestinationType
),
73 reinterpret_cast<void**>(aDestination
));