2014-06-30 08:39:45 -07: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 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07: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-26 18:35:39 -07:00
|
|
|
template<class T, class DestinationType>
|
|
|
|
inline nsresult
|
|
|
|
CallGetInterface(T* aSource, DestinationType** aDestination)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSource, "null parameter");
|
|
|
|
NS_PRECONDITION(aDestination, "null parameter");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-26 18:35:39 -07:00
|
|
|
return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-01-18 12:17:26 -08:00
|
|
|
class MOZ_STACK_CLASS nsGetInterface : public nsCOMPtr_helper
|
2014-06-26 18:35:39 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsGetInterface(nsISupports* aSource, nsresult* aError)
|
|
|
|
: mSource(aSource)
|
|
|
|
, mErrorPtr(aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-15 17:04:42 -08:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const
|
2015-03-21 09:28:04 -07:00
|
|
|
override;
|
2014-06-26 18:35:39 -07:00
|
|
|
|
|
|
|
private:
|
2014-12-23 18:17:50 -08:00
|
|
|
nsISupports* MOZ_NON_OWNING_REF mSource;
|
2014-06-26 18:35:39 -07:00
|
|
|
nsresult* mErrorPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const nsGetInterface
|
|
|
|
do_GetInterface(nsISupports* aSource, nsresult* aError = 0)
|
|
|
|
{
|
|
|
|
return nsGetInterface(aSource, aError);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // __nsInterfaceRequestorUtils_h
|
|
|
|
|