Remove TreeInfo (bug 525371, r=lw).
[mozilla-central.git] / modules / staticmod / nsMetaModule.cpp
blob6f2fd85c7dd186929a2c404775e683e519fc3576
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
13 * License.
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.
22 * Contributor(s):
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"
43 #include "nsXPCOM.h"
44 #include "nsIModule.h"
45 #include "nsCOMPtr.h"
46 #include "nsCOMArray.h"
47 #include "nsMemory.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**);
57 MODULES
59 #undef MODULE
61 #define MODULE(_name) NSGETMODULE(_name),
63 static const nsGetModuleProc kGetModules[] = {
64 MODULES
67 #undef MODULE
69 class MetaModule : public nsIModule
71 public:
72 NS_DECL_ISUPPORTS
73 NS_DECL_NSIMODULE
75 MetaModule() { }
76 nsresult Init(nsIComponentManager*, nsIFile*);
78 private:
79 ~MetaModule() { }
81 nsCOMArray<nsIModule> mModules;
84 NS_IMPL_THREADSAFE_ISUPPORTS1(MetaModule, nsIModule)
86 nsresult
87 MetaModule::Init(nsIComponentManager* aCompMgr, nsIFile* aLocation)
89 if (!mModules.SetCapacity(NS_ARRAY_LENGTH(kGetModules)))
90 return NS_ERROR_OUT_OF_MEMORY;
92 // eat all errors
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));
98 if (NS_SUCCEEDED(rv))
99 mModules.AppendObject(module);
102 return NS_OK;
105 NS_IMETHODIMP
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,
111 aIID, aResult);
112 if (NS_SUCCEEDED(rv))
113 return rv;
116 return NS_ERROR_FAILURE;
119 NS_IMETHODIMP
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);
126 return NS_OK;
129 NS_IMETHODIMP
130 MetaModule::UnregisterSelf(nsIComponentManager* aCompMgr, nsIFile* aLocation,
131 const char *aStr)
133 for (PRInt32 i = mModules.Count() - 1; i >= 0; --i) {
134 mModules[i]->UnregisterSelf(aCompMgr, aLocation, aStr);
136 return NS_OK;
139 NS_IMETHODIMP
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);
144 if (NS_FAILED(rv))
145 return rv;
147 // Any submodule may veto unloading
148 if (!*aResult)
149 return NS_OK;
152 return NS_OK;
155 extern "C" NS_EXPORT nsresult
156 NSGetModule(nsIComponentManager *servMgr,
157 nsIFile *location,
158 nsIModule **result)
160 nsRefPtr<MetaModule> mmodule = new MetaModule();
161 nsresult rv = mmodule->Init(servMgr, location);
162 if (NS_FAILED(rv))
163 return rv;
165 NS_ADDREF(*result = mmodule);
166 return NS_OK;