|
1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
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/. */ |
|
6 |
|
7 #ifndef __nsInterfaceRequestorUtils_h |
|
8 #define __nsInterfaceRequestorUtils_h |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 |
|
12 // a type-safe shortcut for calling the |GetInterface()| member function |
|
13 // T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous. |
|
14 template <class T, class DestinationType> |
|
15 inline |
|
16 nsresult |
|
17 CallGetInterface( T* aSource, DestinationType** aDestination ) |
|
18 { |
|
19 NS_PRECONDITION(aSource, "null parameter"); |
|
20 NS_PRECONDITION(aDestination, "null parameter"); |
|
21 |
|
22 return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType), |
|
23 reinterpret_cast<void**>(aDestination)); |
|
24 } |
|
25 |
|
26 class NS_COM_GLUE nsGetInterface : public nsCOMPtr_helper |
|
27 { |
|
28 public: |
|
29 nsGetInterface( nsISupports* aSource, nsresult* error ) |
|
30 : mSource(aSource), |
|
31 mErrorPtr(error) |
|
32 { |
|
33 // nothing else to do here |
|
34 } |
|
35 |
|
36 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const; |
|
37 |
|
38 private: |
|
39 nsISupports* mSource; |
|
40 nsresult* mErrorPtr; |
|
41 }; |
|
42 |
|
43 inline |
|
44 const nsGetInterface |
|
45 do_GetInterface( nsISupports* aSource, nsresult* error = 0 ) |
|
46 { |
|
47 return nsGetInterface(aSource, error); |
|
48 } |
|
49 |
|
50 #endif // __nsInterfaceRequestorUtils_h |
|
51 |