Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / embedding / componentlib / nsMetaModule.cpp.in
blob3e608981102e67517d4dbbf4dec5f2f3f8075ff7
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1998
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Christopher Seawood <cls@seawood.org>
23 * Doug Turner <dougt@netscape.com>
24 * Chris Waterson <waterson@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #line 27 "nsMetaModule.cpp.in"
41 #include "nsError.h"
42 #include "nsIModule.h"
43 #include "nsIFile.h"
44 #include "nsIGenericFactory.h"
45 #include "prmem.h"
47 %DECLARE_SUBMODULE_INFOS%
48 #line 35 "nsMetaModule.cpp.in"
50 static nsModuleInfo* gSubModules[] = {
51 %SUBMODULE_INFOS%
52 #line 39 "nsMetaModule.cpp.in"
55 #define NUM_SUB_MODULES (sizeof(gSubModules) / sizeof(gSubModules[0]))
57 static nsModuleComponentInfo* gComponentInfo;
58 static PRBool gInitialized = PR_FALSE;
60 PR_STATIC_CALLBACK(nsresult)
61 Initialize(nsIModule *self)
63 if (! gInitialized) {
64 // Run the ctor for each sub-module
65 gInitialized = PR_TRUE;
67 nsModuleInfo** module = gSubModules;
68 nsModuleInfo** limit = module + NUM_SUB_MODULES;
69 for ( ; module < limit; ++module) {
70 if ((*module)->mCtor)
71 ((*module)->mCtor)(self);
75 return NS_OK;
78 PR_STATIC_CALLBACK(void)
79 Shutdown(nsIModule *self)
81 if (gInitialized) {
82 // Run the dtor for each sub-module
83 gInitialized = PR_FALSE;
85 nsModuleInfo** module = gSubModules;
86 nsModuleInfo** limit = module + NUM_SUB_MODULES;
87 for ( ; module < limit; ++module) {
88 if ((*module)->mDtor)
89 ((*module)->mDtor)(self);
94 extern "C" NS_EXPORT nsresult
95 nsMetaModule_nsGetModule(nsIComponentManager *servMgr,
96 nsIFile *location,
97 nsIModule **result)
99 // Count the number of components contained in all of the
100 // sub-modules
101 nsModuleInfo** info = gSubModules;
102 nsModuleInfo** limit = info + NUM_SUB_MODULES;
103 PRUint32 count = 0;
104 for ( ; info < limit; ++info)
105 count += (*info)->mCount;
107 // Allocate an nsModuleComponentInfo array large enough to contain
108 // all of them. This will be permanently leaked.
109 gComponentInfo = new nsModuleComponentInfo[count];
110 if (! gComponentInfo)
111 return NS_ERROR_OUT_OF_MEMORY;
113 // Copy the module component info into the contiguous array
114 nsModuleComponentInfo *comps = gComponentInfo;
115 for (info = gSubModules; info < limit; ++info) {
116 PRUint32 n = (*info)->mCount;
117 ::memcpy(comps, (*info)->mComponents, sizeof(nsModuleComponentInfo) * n);
118 comps += n;
121 // Dummy up an nsModuleInfo struct to register us as a generic
122 // module that contains all our sub-module's components.
123 nsModuleInfo metainfo;
124 memset(&metainfo, 0, sizeof(metainfo));
125 metainfo.mVersion = NS_MODULEINFO_VERSION;
126 metainfo.mModuleName = META_MODULE " meta module";
127 metainfo.mComponents = gComponentInfo;
128 metainfo.mCount = count;
129 metainfo.mCtor = Initialize;
130 metainfo.mDtor = Shutdown;
132 return NS_NewGenericModule2(&metainfo, result);