|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsServiceManagerUtils_h__ |
|
7 #define nsServiceManagerUtils_h__ |
|
8 |
|
9 #include "nsIServiceManager.h" |
|
10 #include "nsCOMPtr.h" |
|
11 |
|
12 inline |
|
13 const nsGetServiceByCID |
|
14 do_GetService(const nsCID& aCID) |
|
15 { |
|
16 return nsGetServiceByCID(aCID); |
|
17 } |
|
18 |
|
19 inline |
|
20 const nsGetServiceByCIDWithError |
|
21 do_GetService(const nsCID& aCID, nsresult* error) |
|
22 { |
|
23 return nsGetServiceByCIDWithError(aCID, error); |
|
24 } |
|
25 |
|
26 inline |
|
27 const nsGetServiceByContractID |
|
28 do_GetService(const char* aContractID) |
|
29 { |
|
30 return nsGetServiceByContractID(aContractID); |
|
31 } |
|
32 |
|
33 inline |
|
34 const nsGetServiceByContractIDWithError |
|
35 do_GetService( const char* aContractID, nsresult* error) |
|
36 { |
|
37 return nsGetServiceByContractIDWithError(aContractID, error); |
|
38 } |
|
39 |
|
40 class nsGetServiceFromCategory : public nsCOMPtr_helper |
|
41 { |
|
42 public: |
|
43 nsGetServiceFromCategory(const char* aCategory, const char* aEntry, |
|
44 nsresult* aErrorPtr) |
|
45 : mCategory(aCategory), |
|
46 mEntry(aEntry), |
|
47 mErrorPtr(aErrorPtr) |
|
48 { |
|
49 // nothing else to do |
|
50 } |
|
51 |
|
52 virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const; |
|
53 protected: |
|
54 const char* mCategory; |
|
55 const char* mEntry; |
|
56 nsresult* mErrorPtr; |
|
57 }; |
|
58 |
|
59 inline |
|
60 const nsGetServiceFromCategory |
|
61 do_GetServiceFromCategory( const char* category, const char* entry, |
|
62 nsresult* error = 0) |
|
63 { |
|
64 return nsGetServiceFromCategory(category, entry, error); |
|
65 } |
|
66 |
|
67 NS_COM_GLUE nsresult |
|
68 CallGetService(const nsCID &aClass, const nsIID &aIID, void **aResult); |
|
69 |
|
70 NS_COM_GLUE nsresult |
|
71 CallGetService(const char *aContractID, const nsIID &aIID, void **aResult); |
|
72 |
|
73 // type-safe shortcuts for calling |GetService| |
|
74 template <class DestinationType> |
|
75 inline |
|
76 nsresult |
|
77 CallGetService( const nsCID &aClass, |
|
78 DestinationType** aDestination) |
|
79 { |
|
80 NS_PRECONDITION(aDestination, "null parameter"); |
|
81 |
|
82 return CallGetService(aClass, |
|
83 NS_GET_TEMPLATE_IID(DestinationType), |
|
84 reinterpret_cast<void**>(aDestination)); |
|
85 } |
|
86 |
|
87 template <class DestinationType> |
|
88 inline |
|
89 nsresult |
|
90 CallGetService( const char *aContractID, |
|
91 DestinationType** aDestination) |
|
92 { |
|
93 NS_PRECONDITION(aContractID, "null parameter"); |
|
94 NS_PRECONDITION(aDestination, "null parameter"); |
|
95 |
|
96 return CallGetService(aContractID, |
|
97 NS_GET_TEMPLATE_IID(DestinationType), |
|
98 reinterpret_cast<void**>(aDestination)); |
|
99 } |
|
100 |
|
101 #endif |