Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / xpcom / components / ModuleUtils.h
blob6291c97f0fe1ee3b77d54fa8dcce9a3f074fe0b8
1 /* -*- Mode: C++; tab-width: 4; 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/. */
6 #ifndef mozilla_GenericModule_h
7 #define mozilla_GenericModule_h
9 #include "mozilla/Attributes.h"
10 #include "mozilla/Module.h"
12 #define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
13 static nsresult \
14 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
15 void **aResult) \
16 { \
17 nsresult rv; \
19 _InstanceClass * inst; \
21 *aResult = nullptr; \
22 if (nullptr != aOuter) { \
23 rv = NS_ERROR_NO_AGGREGATION; \
24 return rv; \
25 } \
27 inst = new _InstanceClass(); \
28 if (nullptr == inst) { \
29 rv = NS_ERROR_OUT_OF_MEMORY; \
30 return rv; \
31 } \
32 NS_ADDREF(inst); \
33 rv = inst->QueryInterface(aIID, aResult); \
34 NS_RELEASE(inst); \
36 return rv; \
39 #define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
40 static nsresult \
41 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
42 void **aResult) \
43 { \
44 nsresult rv; \
46 _InstanceClass * inst; \
48 *aResult = nullptr; \
49 if (nullptr != aOuter) { \
50 rv = NS_ERROR_NO_AGGREGATION; \
51 return rv; \
52 } \
54 inst = new _InstanceClass(); \
55 if (nullptr == inst) { \
56 rv = NS_ERROR_OUT_OF_MEMORY; \
57 return rv; \
58 } \
59 NS_ADDREF(inst); \
60 rv = inst->_InitMethod(); \
61 if(NS_SUCCEEDED(rv)) { \
62 rv = inst->QueryInterface(aIID, aResult); \
63 } \
64 NS_RELEASE(inst); \
66 return rv; \
69 // 'Constructor' that uses an existing getter function that gets a singleton.
70 // NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
71 #define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
72 static nsresult \
73 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
74 void **aResult) \
75 { \
76 nsresult rv; \
78 _InstanceClass * inst; \
80 *aResult = nullptr; \
81 if (nullptr != aOuter) { \
82 rv = NS_ERROR_NO_AGGREGATION; \
83 return rv; \
84 } \
86 inst = already_AddRefed<_InstanceClass>(_GetterProc()).take(); \
87 if (nullptr == inst) { \
88 rv = NS_ERROR_OUT_OF_MEMORY; \
89 return rv; \
90 } \
91 /* NS_ADDREF(inst); */ \
92 rv = inst->QueryInterface(aIID, aResult); \
93 NS_RELEASE(inst); \
95 return rv; \
98 #ifndef MOZILLA_INTERNAL_API
100 #include "nsIModule.h"
101 #include "nsISupportsUtils.h"
103 namespace mozilla {
105 class GenericModule MOZ_FINAL : public nsIModule
107 ~GenericModule() {}
109 public:
110 explicit GenericModule(const mozilla::Module* aData) : mData(aData) {}
112 NS_DECL_THREADSAFE_ISUPPORTS
113 NS_DECL_NSIMODULE
115 private:
116 const mozilla::Module* mData;
119 } // namespace mozilla
121 #define NS_IMPL_MOZILLA192_NSGETMODULE(module) \
122 extern "C" NS_EXPORT nsresult \
123 NSGetModule(nsIComponentManager* aCompMgr, \
124 nsIFile* aLocation, \
125 nsIModule** aResult) \
127 *aResult = new mozilla::GenericModule(module); \
128 NS_ADDREF(*aResult); \
129 return NS_OK; \
132 #endif
134 #endif // mozilla_GenericModule_h