VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/components/nsComponentManager.h@ 4837

Last change on this file since 4837 was 1, checked in by vboxsync, 54 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
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/
9 *
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.
14 *
15 * The Original Code is mozilla.org code.
16 *
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.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nsComponentManager_h__
39#define nsComponentManager_h__
40
41#include "nsXPCOM.h"
42
43#include "nsIComponentLoader.h"
44#include "xpcom-private.h"
45#include "nsNativeComponentLoader.h"
46#include "nsIComponentManager.h"
47#include "nsIComponentRegistrar.h"
48#include "nsIComponentManagerObsolete.h"
49#include "nsIComponentLoaderManager.h"
50#include "nsCategoryManager.h"
51#include "nsIServiceManager.h"
52#include "nsIFactory.h"
53#include "nsIInterfaceRequestor.h"
54#include "nsIInterfaceRequestorUtils.h"
55#include "pldhash.h"
56#include "prtime.h"
57#include "prmon.h"
58#include "nsCOMPtr.h"
59#include "nsWeakReference.h"
60#include "nsXPIDLString.h"
61#include "nsIFile.h"
62#include "plarena.h"
63
64class nsFactoryEntry;
65class nsDll;
66class nsIServiceManager;
67
68
69// Predefined loader types. Do not change the numbers.
70// NATIVE should be 0 as it is being used as the first array index.
71#define NS_COMPONENT_TYPE_NATIVE 0
72#define NS_COMPONENT_TYPE_FACTORY_ONLY -1
73// this define means that the factory entry only has a ContractID
74// to service mapping and has no cid mapping.
75#define NS_COMPONENT_TYPE_SERVICE_ONLY -2
76
77
78#ifdef DEBUG
79#define XPCOM_CHECK_PENDING_CIDS
80#endif
81////////////////////////////////////////////////////////////////////////////////
82
83// Array of Loaders and their type strings
84struct nsLoaderdata {
85 nsIComponentLoader *loader;
86 const char *type;
87};
88
89class nsComponentManagerImpl
90 : public nsIComponentManager,
91 public nsIServiceManager,
92 public nsIComponentRegistrar,
93 public nsSupportsWeakReference,
94 public nsIInterfaceRequestor,
95 public nsIComponentLoaderManager,
96 public nsIServiceManagerObsolete,
97 public nsIComponentManagerObsolete
98{
99public:
100 NS_DECL_ISUPPORTS
101 NS_DECL_NSIINTERFACEREQUESTOR
102 // Since the nsIComponentManagerObsolete and nsIComponentManager share some of the
103 // same interface function names, we have to manually define the functions here.
104 // The only function that is in nsIComponentManagerObsolete and is in nsIComponentManager
105 // is GetClassObjectContractID.
106 //
107 // nsIComponentManager function not in nsIComponentManagerObsolete:
108 NS_IMETHOD GetClassObjectByContractID(const char *aContractID,
109 const nsIID &aIID,
110 void **_retval);
111
112
113 NS_DECL_NSICOMPONENTMANAGEROBSOLETE
114
115 // Since the nsIComponentManagerObsolete and nsIComponentRegistrar share some of the
116 // same interface function names, we have to manually define the functions here.
117 // the only function that is shared is UnregisterFactory
118 NS_IMETHOD AutoRegister(nsIFile *aSpec);
119 NS_IMETHOD AutoUnregister(nsIFile *aSpec);
120 NS_IMETHOD RegisterFactory(const nsCID & aClass, const char *aClassName, const char *aContractID, nsIFactory *aFactory);
121 // NS_IMETHOD UnregisterFactory(const nsCID & aClass, nsIFactory *aFactory);
122 NS_IMETHOD RegisterFactoryLocation(const nsCID & aClass, const char *aClassName, const char *aContractID, nsIFile *aFile, const char *loaderStr, const char *aType);
123 NS_IMETHOD UnregisterFactoryLocation(const nsCID & aClass, nsIFile *aFile);
124 NS_IMETHOD IsCIDRegistered(const nsCID & aClass, PRBool *_retval);
125 NS_IMETHOD IsContractIDRegistered(const char *aClass, PRBool *_retval);
126 NS_IMETHOD EnumerateCIDs(nsISimpleEnumerator **_retval);
127 NS_IMETHOD EnumerateContractIDs(nsISimpleEnumerator **_retval);
128 NS_IMETHOD CIDToContractID(const nsCID & aClass, char **_retval);
129 NS_IMETHOD ContractIDToCID(const char *aContractID, nsCID * *_retval);
130
131 NS_DECL_NSISERVICEMANAGER
132 NS_DECL_NSISERVICEMANAGEROBSOLETE
133 NS_DECL_NSICOMPONENTLOADERMANAGER
134
135 // nsComponentManagerImpl methods:
136 nsComponentManagerImpl();
137
138 static nsComponentManagerImpl* gComponentManager;
139 nsresult Init(void);
140
141 nsresult WritePersistentRegistry();
142 nsresult ReadPersistentRegistry();
143
144 nsresult Shutdown(void);
145
146 nsresult FreeServices();
147
148 nsresult
149 NS_GetService(const char *aContractID, const nsIID& aIID, PRBool aDontCreate, nsISupports** result);
150
151 nsresult RegisterComponentCommon(const nsCID &aClass,
152 const char *aClassName,
153 const char *aContractID,
154 PRUint32 aContractIDLen,
155 const char *aRegistryName,
156 PRUint32 aRegistryNameLen,
157 PRBool aReplace, PRBool aPersist,
158 const char *aType);
159 nsresult GetLoaderForType(int aType,
160 nsIComponentLoader **aLoader);
161 nsresult FindFactory(const char *contractID, PRUint32 aContractIDLen, nsIFactory **aFactory) ;
162 nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
163
164 nsFactoryEntry *GetFactoryEntry(const char *aContractID,
165 PRUint32 aContractIDLen);
166 nsFactoryEntry *GetFactoryEntry(const nsCID &aClass);
167
168 nsresult SyncComponentsInDir(PRInt32 when, nsIFile *dirSpec);
169 nsresult SelfRegisterDll(nsDll *dll);
170 nsresult SelfUnregisterDll(nsDll *dll);
171 nsresult HashContractID(const char *acontractID, PRUint32 aContractIDLen,
172 nsFactoryEntry *fe_ptr);
173
174 void DeleteContractIDEntriesByCID(const nsCID* aClass, const char*registryName);
175 void DeleteContractIDEntriesByCID(const nsCID* aClass, nsIFactory* factory);
176
177 nsresult UnloadLibraries(nsIServiceManager *servmgr, PRInt32 when);
178
179 // Convert a loader type string into an index into the loader data
180 // array. Empty loader types are converted to NATIVE. Returns -1 if
181 // loader type cannot be determined.
182 int GetLoaderType(const char *typeStr);
183
184 // Add a loader type if not already known. Out the typeIndex
185 // if the loader type is either added or already there;
186 // returns NS_OK or an error on failure.
187 nsresult AddLoaderType(const char *typeStr, int *typeIndex);
188
189 int GetLoaderCount() { return mNLoaderData + 1; }
190
191 // registers only the files in spec's location by loaders other than the
192 // native loader. This is an optimization method only.
193 nsresult AutoRegisterNonNativeComponents(nsIFile* spec);
194
195 nsresult AutoRegisterImpl(PRInt32 when, nsIFile *inDirSpec, PRBool fileIsCompDir=PR_TRUE);
196 nsresult RemoveEntries(nsIFile* file);
197
198 PLDHashTable mFactories;
199 PLDHashTable mContractIDs;
200 PRMonitor* mMon;
201
202 nsNativeComponentLoader *mNativeComponentLoader;
203#ifdef ENABLE_STATIC_COMPONENT_LOADER
204 nsIComponentLoader *mStaticComponentLoader;
205#endif
206 nsCOMPtr<nsIFile> mComponentsDir;
207 PRInt32 mComponentsOffset;
208
209 nsCOMPtr<nsIFile> mGREComponentsDir;
210 PRInt32 mGREComponentsOffset;
211
212 nsCOMPtr<nsIFile> mRegistryFile;
213
214 // Shutdown
215 #define NS_SHUTDOWN_NEVERHAPPENED 0
216 #define NS_SHUTDOWN_INPROGRESS 1
217 #define NS_SHUTDOWN_COMPLETE 2
218 PRUint32 mShuttingDown;
219
220 nsLoaderdata *mLoaderData;
221 int mNLoaderData;
222 int mMaxNLoaderData;
223
224 PRBool mRegistryDirty;
225 nsHashtable mAutoRegEntries;
226 nsCOMPtr<nsCategoryManager> mCategoryManager;
227
228 PLArenaPool mArena;
229
230#ifdef XPCOM_CHECK_PENDING_CIDS
231 nsresult AddPendingCID(const nsCID &aClass);
232 void RemovePendingCID(const nsCID &aClass);
233
234 nsVoidArray mPendingCIDs;
235#endif
236
237private:
238 ~nsComponentManagerImpl();
239};
240
241
242#define NS_MAX_FILENAME_LEN 1024
243
244#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
245
246////////////////////////////////////////////////////////////////////////////////
247/**
248 * Class: nsFactoryEntry()
249 *
250 * There are two types of FactoryEntries.
251 *
252 * 1. {CID, dll} mapping.
253 * Factory is a consequence of the dll. These can be either session
254 * specific or persistent based on whether we write this
255 * to the registry or not.
256 *
257 * 2. {CID, factory} mapping
258 * These are strictly session specific and in memory only.
259 */
260
261class nsFactoryEntry {
262public:
263 nsFactoryEntry(const nsCID &aClass,
264 const char *location, PRUint32 locationlen, int aType, class nsFactoryEntry* parent = nsnull);
265 nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory, class nsFactoryEntry* parent = nsnull);
266 ~nsFactoryEntry();
267
268 nsresult ReInit(const nsCID &aClass, const char *location, int aType);
269
270 nsresult GetFactory(nsIFactory **aFactory,
271 nsComponentManagerImpl * mgr) {
272 if (mFactory) {
273 *aFactory = mFactory.get();
274 NS_ADDREF(*aFactory);
275 return NS_OK;
276 }
277
278 if (mTypeIndex < 0)
279 return NS_ERROR_FAILURE;
280
281 nsresult rv;
282 nsCOMPtr<nsIComponentLoader> loader;
283 rv = mgr->GetLoaderForType(mTypeIndex, getter_AddRefs(loader));
284 if(NS_FAILED(rv))
285 return rv;
286
287 rv = loader->GetFactory(mCid, mLocation, mgr->mLoaderData[mTypeIndex].type, aFactory);
288 if (NS_SUCCEEDED(rv))
289 mFactory = do_QueryInterface(*aFactory);
290 return rv;
291 }
292
293 nsCID mCid;
294 nsCOMPtr<nsIFactory> mFactory;
295 // This is an index into the mLoaderData array that holds the type string and the loader
296 int mTypeIndex;
297 nsCOMPtr<nsISupports> mServiceObject;
298 char* mLocation;
299 class nsFactoryEntry* mParent;
300};
301
302////////////////////////////////////////////////////////////////////////////////
303
304struct nsFactoryTableEntry : public PLDHashEntryHdr {
305 nsFactoryEntry *mFactoryEntry;
306};
307
308struct nsContractIDTableEntry : public PLDHashEntryHdr {
309 char *mContractID;
310 PRUint32 mContractIDLen;
311 nsFactoryEntry *mFactoryEntry;
312};
313
314
315class AutoRegEntry
316{
317public:
318 AutoRegEntry(const nsACString& name, PRInt64* modDate);
319 ~AutoRegEntry();
320
321 const nsDependentCString GetName()
322 { return nsDependentCString(mName, mNameLen); }
323 PRInt64 GetDate() {return mModDate;}
324 void SetDate(PRInt64 *date) { mModDate = *date;}
325 PRBool Modified(PRInt64 *date);
326
327 // this is the optional field line in the compreg.dat.
328 // it must not contain any comma's and it must be null terminated.
329 char* GetOptionalData() {return mData;};
330 void SetOptionalData(const char* data);
331
332private:
333 char* mName;
334 PRUint32 mNameLen;
335 char* mData;
336 PRInt64 mModDate;
337};
338#endif // nsComponentManager_h__
339
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use