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 * Christopher Seawood <cls@seawood.org>
24 * Doug Turner <dougt@netscape.com>
25 * Chris Waterson <waterson@netscape.com>
26 * Benjamin Smedberg <benjamin@smedbergs.us>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include "nsIGenericFactory.h"
44 #include "nsIModule.h"
46 #include "nsCOMArray.h"
48 #include "nsAutoPtr.h"
50 #include "module_list.h"
52 #define NSGETMODULE(_name) _name##_NSGetModule
54 #define MODULE(_name) \
55 NSGETMODULE_ENTRY_POINT(_name) (nsIComponentManager*, nsIFile*, nsIModule**);
61 #define MODULE(_name) NSGETMODULE(_name),
63 static const nsGetModuleProc kGetModules
[] = {
69 class MetaModule
: public nsIModule
76 nsresult
Init(nsIComponentManager
*, nsIFile
*);
81 nsCOMArray
<nsIModule
> mModules
;
84 NS_IMPL_THREADSAFE_ISUPPORTS1(MetaModule
, nsIModule
)
87 MetaModule::Init(nsIComponentManager
* aCompMgr
, nsIFile
* aLocation
)
89 if (!mModules
.SetCapacity(NS_ARRAY_LENGTH(kGetModules
)))
90 return NS_ERROR_OUT_OF_MEMORY
;
93 nsGetModuleProc
const *end
= kGetModules
+ NS_ARRAY_LENGTH(kGetModules
);
95 nsCOMPtr
<nsIModule
> module
;
96 for (nsGetModuleProc
const *cur
= kGetModules
; cur
< end
; ++cur
) {
97 nsresult rv
= (*cur
)(aCompMgr
, aLocation
, getter_AddRefs(module
));
99 mModules
.AppendObject(module
);
106 MetaModule::GetClassObject(nsIComponentManager
* aCompMgr
, REFNSCID aCID
,
107 REFNSIID aIID
, void **aResult
)
109 for (PRInt32 i
= mModules
.Count() - 1; i
>= 0; --i
) {
110 nsresult rv
= mModules
[i
]->GetClassObject(aCompMgr
, aCID
,
112 if (NS_SUCCEEDED(rv
))
116 return NS_ERROR_FAILURE
;
120 MetaModule::RegisterSelf(nsIComponentManager
* aCompMgr
, nsIFile
* aLocation
,
121 const char *aStr
, const char *aType
)
123 for (PRInt32 i
= mModules
.Count() - 1; i
>= 0; --i
) {
124 mModules
[i
]->RegisterSelf(aCompMgr
, aLocation
, aStr
, aType
);
130 MetaModule::UnregisterSelf(nsIComponentManager
* aCompMgr
, nsIFile
* aLocation
,
133 for (PRInt32 i
= mModules
.Count() - 1; i
>= 0; --i
) {
134 mModules
[i
]->UnregisterSelf(aCompMgr
, aLocation
, aStr
);
140 MetaModule::CanUnload(nsIComponentManager
* aCompMgr
, PRBool
*aResult
)
142 for (PRInt32 i
= mModules
.Count() - 1; i
>= 0; --i
) {
143 nsresult rv
= mModules
[i
]->CanUnload(aCompMgr
, aResult
);
147 // Any submodule may veto unloading
155 extern "C" NS_EXPORT nsresult
156 NSGetModule(nsIComponentManager
*servMgr
,
160 nsRefPtr
<MetaModule
> mmodule
= new MetaModule();
161 nsresult rv
= mmodule
->Init(servMgr
, location
);
165 NS_ADDREF(*result
= mmodule
);