nsXPComInit.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPCOM.h"
#include "nsXPCOMPrivate.h"
#include "nscore.h"
#include "prlink.h"
#include "nsCOMPtr.h"
#include "nsObserverList.h"
#include "nsObserverService.h"
#include "nsProperties.h"
#include "nsIProperties.h"
#include "nsPersistentProperties.h"
#include "nsScriptableInputStream.h"
#include "nsBinaryStream.h"
#include "nsStorageStream.h"
#include "nsMemoryImpl.h"
#include "nsDebugImpl.h"
#include "nsTraceRefcntImpl.h"
#include "nsErrorService.h"
#include "nsByteBuffer.h"
#include "nsSupportsArray.h"
#include "nsArray.h"
#include "nsSupportsPrimitives.h"
#include "nsConsoleService.h"
#include "nsExceptionService.h"
#include "nsComponentManager.h"
#include "nsCategoryManagerUtils.h"
#include "nsIServiceManager.h"
#include "nsGenericFactory.h"
#include "nsEventQueueService.h"
#include "nsEventQueue.h"
#include "nsIProxyObjectManager.h"
#include "nsProxyEventPrivate.h" // access to the impl of nsProxyObjectManager for the generic factory registration.
#include "xptinfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsTimerImpl.h"
#include "TimerThread.h"
#include "nsThread.h"
#include "nsProcess.h"
#include "nsEnvironment.h"
#include "nsEmptyEnumerator.h"
#include "nsILocalFile.h"
#include "nsLocalFile.h"
#include "nsNativeCharsetUtils.h"
#endif
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsCategoryManager.h"
#include "nsICategoryManager.h"
#include "nsStringStream.h"
#include "nsMultiplexInputStream.h"
#include "nsFastLoadService.h"
#include "nsAtomService.h"
#include "nsAtomTable.h"
#include "nsTraceRefcnt.h"
#include "nsTimelineService.h"
#include "nsVariant.h"
#ifdef GC_LEAK_DETECTOR
#include "nsLeakDetector.h"
#endif
#include "nsRecyclingAllocator.h"
#include "SpecialSystemDirectory.h"
#include "ipcdclient.h"
#include "ipcService.h"
#include "ipcConfig.h"
#include "ipcCID.h"
#include "ipcLockService.h"
#include "ipcLockCID.h"
#include "tmTransactionService.h"
#include "ipcDConnectService.h"
#include <locale.h>
// Registry Factory creation function defined in nsRegistry.cpp
// We hook into this function locally to create and register the registry
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
// does not have a local include file, we are putting this definition
// here rather than in nsIRegistry.h
#ifdef DEBUG
extern void _FreeAutoLockStatics();
#endif
#define NS_ENVIRONMENT_CLASSNAME "Environment Service"
#include "nsXPCOM.h"
#define NS_SUPPORTS_ID_CLASSNAME "Supports ID"
#define NS_SUPPORTS_CSTRING_CLASSNAME "Supports String"
#define NS_SUPPORTS_STRING_CLASSNAME "Supports WString"
#define NS_SUPPORTS_PRBOOL_CLASSNAME "Supports PRBool"
#define NS_SUPPORTS_PRUINT8_CLASSNAME "Supports PRUint8"
#define NS_SUPPORTS_PRUINT16_CLASSNAME "Supports PRUint16"
#define NS_SUPPORTS_PRUINT32_CLASSNAME "Supports PRUint32"
#define NS_SUPPORTS_PRUINT64_CLASSNAME "Supports PRUint64"
#define NS_SUPPORTS_PRTIME_CLASSNAME "Supports PRTime"
#define NS_SUPPORTS_CHAR_CLASSNAME "Supports Char"
#define NS_SUPPORTS_PRINT16_CLASSNAME "Supports PRInt16"
#define NS_SUPPORTS_PRINT32_CLASSNAME "Supports PRInt32"
#define NS_SUPPORTS_PRINT64_CLASSNAME "Supports PRInt64"
#define NS_SUPPORTS_FLOAT_CLASSNAME "Supports float"
#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
#define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
#define NS_SUPPORTS_INTERFACE_POINTER_CLASSNAME "Supports interface pointer"
#ifdef MOZ_TIMELINE
#endif
static NS_METHOD
void* *aInstancePtr)
{
if (!iim) {
return NS_ERROR_FAILURE;
}
}
const nsModuleComponentInfo *info)
{
fact);
return rv;
}
// In order to support the installer, we need
// to be told out of band if we should cause
// an autoregister. If the file ".autoreg" exists in the binary
// directory, we check its timestamp against the timestamp of the
// compreg.dat file. If the .autoreg file is newer, we autoregister.
static PRBool CheckUpdateFile()
{
if (!directoryService)
return PR_FALSE;
NS_WARNING("Getting NS_XPCOM_CURRENT_PROCESS_DIR failed");
return PR_FALSE;
}
if (!exists)
return PR_FALSE;
NS_WARNING("Getting NS_XPCOM_COMPONENT_REGISTRY_FILE failed");
return PR_FALSE;
}
// Don't need to check whether compreg exists; if it doesn't
// we won't even be here.
}
#if 0 /// @todo later
// enable this code to make the IPC DCONNECT service auto-start.
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
//
// add ipcService to the XPCOM startup category
//
if (catman) {
}
return NS_OK;
}
const char *registryLocation,
const nsModuleComponentInfo *info)
{
if (catman)
return NS_OK;
}
#endif
// For each class that wishes to support nsIClassInfo, add a line like this
// NS_DECL_CLASSINFO(nsMyClass)
static const nsModuleComponentInfo components[] = {
#define NS_PROPERTIES_CLASSNAME "Properties"
#ifdef MOZ_TIMELINE
#endif
#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
#define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service"
#if 0 /// @todo later
/*
ipcServiceRegisterProc,
ipcServiceUnregisterProc },
*/
//
// extensions go here:
//
#ifdef BUILD_DCONNECT
#endif
#endif
};
// gMemory will be freed during shutdown.
{
if (!gMemory)
{
(void**)&gMemory);
}
return rv;
}
// gDebug will be freed during shutdown.
{
if (!gDebug)
{
(void**)&gDebug);
}
return rv;
}
#ifdef NS_BUILD_REFCNT_LOGGING
// gTraceRefcnt will be freed during shutdown.
#endif
{
#ifdef NS_BUILD_REFCNT_LOGGING
if (!gTraceRefcnt)
{
(void**)&gTraceRefcnt);
}
return rv;
#else
return NS_ERROR_NOT_INITIALIZED;
#endif
}
{
}
{
// We are not shutting down
#ifdef NS_BUILD_REFCNT_LOGGING
#endif
// Establish the main thread here.
// Startup the memory manager
// If the locale hasn't already been setup by our embedder,
// get us out of the "C" locale and into the system
#endif
// Start the directory service so that the component manager init can use it.
(void**)&gDirectoryService);
return rv;
return rv;
return rv;
{
compMgr = new nsComponentManagerImpl();
return NS_ERROR_OUT_OF_MEMORY;
if (binDirectory)
{
}
}
else {
}
if (xpcomLib) {
}
if (appFileLocationProvider) {
}
{
return rv;
}
if (result) {
}
}
// dougt - these calls will be moved into a new interface when nsIComponentManager is frozen.
#ifdef GC_LEAK_DETECTOR
rv = NS_InitLeakDetector();
#endif
// 2. Register the global services with the component manager so that
// clients can create new objects.
// Category Manager
{
return rv;
PR_TRUE);
}
// what I want to do here is QI for a Component Registration Manager. Since this
// has not been invented yet, QI to the obsolete manager. Kids, don't do this at home.
if (registrar) {
for (int i = 0; i < components_length; i++)
}
#ifdef DEBUG
printf("No Persistent Registry Found.\n");
}
#endif
#if 0 /// @todo later
return rv;
#endif
// if we find no persistent registry, we will try to autoregister
// the default components directory.
// If the application is using a GRE, then,
// auto register components in the GRE directory as well.
//
// The application indicates that it's using an GRE by
// returning a valid nsIFile when queried (via appFileLocProvider)
// for the NS_GRE_DIR atom as shown below
//
if ( appFileLocationProvider ) {
if (greDir) {
#ifdef DEBUG_dougt
printf("start - Registering GRE components\n");
#endif
NS_ERROR("Could not get GRE components directory!");
return rv;
}
// If the GRE contains any loaders, we want to know about it so that we can cause another
// autoregistration of the applications component directory.
#ifdef DEBUG_dougt
printf("end - Registering GRE components\n");
#endif
NS_ERROR("Could not AutoRegister GRE components");
return rv;
}
}
}
//
// If additional component directories have been specified, then
// register them as well.
//
if (dirList) {
if (elem) {
if (dir)
// XXX should we worry about new component loaders being
// XXX defined by this process?
}
}
}
// Make sure the compreg file's mod time is current.
}
// Pay the cost at startup time of starting this singleton.
// Notify observers of xpcom autoregistration start
return NS_OK;
}
static nsVoidArray* gExitRoutines;
static void CallExitRoutines()
{
if (!gExitRoutines)
return;
func();
}
gExitRoutines->Clear();
delete gExitRoutines;
}
{
// priority are not used right now. It will need to be implemented as more
// classes are moved into the glue library --dougt
if (!gExitRoutines) {
gExitRoutines = new nsVoidArray();
if (!gExitRoutines) {
NS_WARNING("Failed to allocate gExitRoutines");
return NS_ERROR_FAILURE;
}
}
}
{
if (!gExitRoutines)
return NS_ERROR_FAILURE;
}
//
// NS_ShutdownXPCOM()
//
// The shutdown sequence for xpcom would be
//
// - Release the Global Service Manager
// - Release all service instances held by the global service manager
// - Release the Global Service Manager itself
// - Release the Component Manager
// - Release all factories cached by the Component Manager
// - Unload Libraries
// - Release Contractid Cache held by Component Manager
// - Release dll abstraction held by Component Manager
// - Release the Registry held by Component Manager
// - Finally, release the component manager itself
//
{
// Notify observers of xpcom shutting down
{
// Block it so that the COMPtr will get deleted before we hit
// servicemanager shutdown
if (NS_SUCCEEDED(rv))
{
if (NS_SUCCEEDED(rv))
{
nsnull);
}
}
}
// grab the event queue so that we can process events one last time before exiting
{
if (eventQService) {
}
}
// XPCOM is officially in shutdown mode NOW
// Set this only after the observers have been notified as this
// will cause servicemanager to become inaccessible.
#ifdef DEBUG_dougt
#endif
#if 0 /// @todo later
IPC_Shutdown();
#endif
// We may have AddRef'd for the caller of NS_InitXPCOM, so release it
// here again:
// Shutdown global servicemanager
}
if (currentQ) {
currentQ = 0;
}
// Release the directory service
// Shutdown nsLocalFile string conversion
#ifdef XP_UNIX
#endif
// Shutdown the timer thread and all timers that might still be alive before
// shutting down the component manager
nsTimerImpl::Shutdown();
// Shutdown xpcom. This will release all loaders and cause others holding
// a refcount to the component manager to release it.
} else
NS_WARNING("Component Manager was never created ...");
// Release our own singletons
// Do this _after_ shutting down the component manager, because the
// JS component loader will use XPConnect to call nsIModule::canUnload,
// and that will spin up the InterfaceInfoManager again -- bad mojo
// Finally, release the component manager last because it unloads the
// libraries:
}
#ifdef DEBUG
#endif
nsMemoryImpl::Shutdown();
#ifdef NS_BUILD_REFCNT_LOGGING
#endif
#ifdef GC_LEAK_DETECTOR
// Shutdown the Leak detector.
#endif
return NS_OK;
}
{
if (!functions)
return NS_ERROR_OUT_OF_MEMORY;
return NS_ERROR_FAILURE;
if (!xpcomLib)
return NS_ERROR_FAILURE;
// these functions were added post 1.4 (need to check size of |functions|)
}
// these functions were added post 1.6 (need to check size of |functions|)
}
end:
return rv;
}