2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-10-16 07:35:52 +04:00
|
|
|
|
2004-11-25 01:48:45 +03:00
|
|
|
#ifndef nsServiceManagerUtils_h__
|
|
|
|
#define nsServiceManagerUtils_h__
|
2001-10-16 07:35:52 +04:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2018-07-24 03:41:06 +03:00
|
|
|
#include "nsString.h"
|
2001-10-16 07:35:52 +04:00
|
|
|
|
2004-11-25 01:48:45 +03:00
|
|
|
inline const nsGetServiceByCID do_GetService(const nsCID& aCID) {
|
2014-06-27 05:35:39 +04:00
|
|
|
return nsGetServiceByCID(aCID);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
inline const nsGetServiceByCIDWithError do_GetService(const nsCID& aCID,
|
|
|
|
nsresult* aError) {
|
|
|
|
return nsGetServiceByCIDWithError(aCID, aError);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2004-11-25 01:48:45 +03:00
|
|
|
inline const nsGetServiceByContractID do_GetService(const char* aContractID) {
|
2014-06-27 05:35:39 +04:00
|
|
|
return nsGetServiceByContractID(aContractID);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
inline const nsGetServiceByContractIDWithError do_GetService(
|
|
|
|
const char* aContractID, nsresult* aError) {
|
|
|
|
return nsGetServiceByContractIDWithError(aContractID, aError);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 23:58:15 +03:00
|
|
|
class MOZ_STACK_CLASS nsGetServiceFromCategory final : public nsCOMPtr_helper {
|
2014-06-27 05:35:39 +04:00
|
|
|
public:
|
2018-07-24 03:41:06 +03:00
|
|
|
nsGetServiceFromCategory(const nsACString& aCategory,
|
|
|
|
const nsACString& aEntry, nsresult* aErrorPtr)
|
2014-06-27 05:35:39 +04:00
|
|
|
: mCategory(aCategory), mEntry(aEntry), mErrorPtr(aErrorPtr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-15 19:36:10 +03:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
protected:
|
2018-07-24 03:41:06 +03:00
|
|
|
const nsCString mCategory;
|
|
|
|
const nsCString mEntry;
|
2014-06-27 05:35:39 +04:00
|
|
|
nsresult* mErrorPtr;
|
2001-10-16 07:35:52 +04:00
|
|
|
};
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
inline const nsGetServiceFromCategory do_GetServiceFromCategory(
|
2018-07-24 03:41:06 +03:00
|
|
|
const nsACString& aCategory, const nsACString& aEntry,
|
2014-06-27 05:35:39 +04:00
|
|
|
nsresult* aError = 0) {
|
|
|
|
return nsGetServiceFromCategory(aCategory, aEntry, aError);
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 02:47:27 +04:00
|
|
|
nsresult CallGetService(const nsCID& aClass, const nsIID& aIID, void** aResult);
|
2004-11-25 01:48:45 +03:00
|
|
|
|
2014-08-28 02:47:27 +04:00
|
|
|
nsresult CallGetService(const char* aContractID, const nsIID& aIID,
|
|
|
|
void** aResult);
|
2004-11-25 01:48:45 +03:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
// type-safe shortcuts for calling |GetService|
|
2014-06-27 05:35:39 +04:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallGetService(const nsCID& aClass,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 05:35:39 +04:00
|
|
|
|
|
|
|
return CallGetService(aClass, NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
template <class DestinationType>
|
|
|
|
inline nsresult CallGetService(const char* aContractID,
|
|
|
|
DestinationType** aDestination) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aContractID, "null parameter");
|
|
|
|
MOZ_ASSERT(aDestination, "null parameter");
|
2014-06-27 05:35:39 +04:00
|
|
|
|
|
|
|
return CallGetService(aContractID, NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
2001-10-16 07:35:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|