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: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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-09-06 02:52:43 +04:00
|
|
|
|
|
|
|
#ifndef __nsInterfaceRequestorUtils_h
|
|
|
|
#define __nsInterfaceRequestorUtils_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
// a type-safe shortcut for calling the |GetInterface()| member function
|
|
|
|
// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
|
2014-06-27 05:35:39 +04:00
|
|
|
template<class T, class DestinationType>
|
|
|
|
inline nsresult
|
|
|
|
CallGetInterface(T* aSource, DestinationType** aDestination)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSource, "null parameter");
|
|
|
|
NS_PRECONDITION(aDestination, "null parameter");
|
2001-09-06 02:52:43 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
|
|
|
}
|
2001-09-06 02:52:43 +04:00
|
|
|
|
2015-04-20 23:58:15 +03:00
|
|
|
class MOZ_STACK_CLASS nsGetInterface final : public nsCOMPtr_helper
|
2014-06-27 05:35:39 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsGetInterface(nsISupports* aSource, nsresult* aError)
|
|
|
|
: mSource(aSource)
|
|
|
|
, mErrorPtr(aError)
|
2001-09-06 02:52:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-16 04:04:42 +03:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const
|
2015-03-21 19:28:04 +03:00
|
|
|
override;
|
2014-06-27 05:35:39 +04:00
|
|
|
|
|
|
|
private:
|
2014-12-24 05:17:50 +03:00
|
|
|
nsISupports* MOZ_NON_OWNING_REF mSource;
|
2014-06-27 05:35:39 +04:00
|
|
|
nsresult* mErrorPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const nsGetInterface
|
|
|
|
do_GetInterface(nsISupports* aSource, nsresult* aError = 0)
|
|
|
|
{
|
|
|
|
return nsGetInterface(aSource, aError);
|
|
|
|
}
|
|
|
|
|
2001-09-06 02:52:43 +04:00
|
|
|
#endif // __nsInterfaceRequestorUtils_h
|
|
|
|
|