зеркало из https://github.com/mozilla/gecko-dev.git
Add CallGetInterface. b=92602 r=jag sr=scc
This commit is contained in:
Родитель
6181cc4a50
Коммит
a2213222f4
|
@ -54,6 +54,20 @@ interface nsIInterfaceRequestor : nsISupports
|
|||
#include "nsCOMPtr.h"
|
||||
#endif
|
||||
|
||||
// a type-safe shortcut for calling the |GetInterface()| member function
|
||||
// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
|
||||
template <class T, class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetInterface( T* aSource, DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->GetInterface(NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
class NS_EXPORT nsGetInterface : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
|
||||
#define NS_ITESTSERVICE_IID \
|
||||
{0x127b5253, 0x37b1, 0x43c7, \
|
||||
|
@ -101,5 +102,10 @@ int main()
|
|||
CallGetService(NS_TEST_SERVICE_CONTRACTID, myShutdownListener,
|
||||
&myITestService);
|
||||
|
||||
/* Test CallGetInterface */
|
||||
nsIInterfaceRequestor *myInterfaceRequestor =
|
||||
NS_STATIC_CAST(nsIInterfaceRequestor*, mySupportsPtr);
|
||||
CallGetInterface(myInterfaceRequestor, &myITestService);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче