1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Benjamin Smedberg <benjamin@smedbergs.us>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef mozilla_GenericModule_h
40 #define mozilla_GenericModule_h
42 #include "mozilla/Module.h"
44 #define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
46 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
51 _InstanceClass * inst; \
54 if (NULL != aOuter) { \
55 rv = NS_ERROR_NO_AGGREGATION; \
59 inst = new _InstanceClass(); \
61 rv = NS_ERROR_OUT_OF_MEMORY; \
65 rv = inst->QueryInterface(aIID, aResult); \
71 #define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
73 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
78 _InstanceClass * inst; \
81 if (NULL != aOuter) { \
82 rv = NS_ERROR_NO_AGGREGATION; \
86 inst = new _InstanceClass(); \
88 rv = NS_ERROR_OUT_OF_MEMORY; \
92 rv = inst->_InitMethod(); \
93 if(NS_SUCCEEDED(rv)) { \
94 rv = inst->QueryInterface(aIID, aResult); \
101 // 'Constructor' that uses an existing getter function that gets a singleton.
102 // NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
103 #define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
105 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
110 _InstanceClass * inst; \
113 if (NULL != aOuter) { \
114 rv = NS_ERROR_NO_AGGREGATION; \
118 inst = already_AddRefed<_InstanceClass>(_GetterProc()).get(); \
119 if (NULL == inst) { \
120 rv = NS_ERROR_OUT_OF_MEMORY; \
123 /* NS_ADDREF(inst); */ \
124 rv = inst->QueryInterface(aIID, aResult); \
130 #ifndef MOZILLA_INTERNAL_API
132 #include "nsIModule.h"
133 #include "nsISupportsUtils.h"
137 class GenericModule
: public nsIModule
140 GenericModule(const mozilla::Module
* aData
)
149 const mozilla::Module
* mData
;
152 } // namespace mozilla
154 #define NS_IMPL_MOZILLA192_NSGETMODULE(module) \
155 extern "C" NS_EXPORT nsresult \
156 NSGetModule(nsIComponentManager* aCompMgr, \
157 nsIFile* aLocation, \
158 nsIModule** aResult) \
160 *aResult = new mozilla::GenericModule(module); \
161 NS_ADDREF(*aResult); \
167 #endif // mozilla_GenericModule_h