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) \
14 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
19 _InstanceClass * inst; \
22 if (nullptr != aOuter) { \
23 rv = NS_ERROR_NO_AGGREGATION; \
27 inst = new _InstanceClass(); \
28 if (nullptr == inst) { \
29 rv = NS_ERROR_OUT_OF_MEMORY; \
33 rv = inst->QueryInterface(aIID, aResult); \
39 #define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
41 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
46 _InstanceClass * inst; \
49 if (nullptr != aOuter) { \
50 rv = NS_ERROR_NO_AGGREGATION; \
54 inst = new _InstanceClass(); \
55 if (nullptr == inst) { \
56 rv = NS_ERROR_OUT_OF_MEMORY; \
60 rv = inst->_InitMethod(); \
61 if(NS_SUCCEEDED(rv)) { \
62 rv = inst->QueryInterface(aIID, aResult); \
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) \
73 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
78 _InstanceClass * inst; \
81 if (nullptr != aOuter) { \
82 rv = NS_ERROR_NO_AGGREGATION; \
86 inst = already_AddRefed<_InstanceClass>(_GetterProc()).take(); \
87 if (nullptr == inst) { \
88 rv = NS_ERROR_OUT_OF_MEMORY; \
91 /* NS_ADDREF(inst); */ \
92 rv = inst->QueryInterface(aIID, aResult); \
98 #ifndef MOZILLA_INTERNAL_API
100 #include "nsIModule.h"
101 #include "nsISupportsUtils.h"
105 class GenericModule MOZ_FINAL
: public nsIModule
110 explicit GenericModule(const mozilla::Module
* aData
) : mData(aData
) {}
112 NS_DECL_THREADSAFE_ISUPPORTS
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); \
134 #endif // mozilla_GenericModule_h