michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsXPCOM_h__ michael@0: #define nsXPCOM_h__ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsXPCOMCID.h" michael@0: michael@0: #ifdef __cplusplus michael@0: #define DECL_CLASS(c) class c michael@0: #define DECL_STRUCT(c) struct c michael@0: #else michael@0: #define DECL_CLASS(c) typedef struct c c michael@0: #define DECL_STRUCT(c) typedef struct c c michael@0: #endif michael@0: michael@0: DECL_CLASS(nsAString); michael@0: DECL_CLASS(nsACString); michael@0: michael@0: DECL_CLASS(nsISupports); michael@0: DECL_CLASS(nsIModule); michael@0: DECL_CLASS(nsIComponentManager); michael@0: DECL_CLASS(nsIComponentRegistrar); michael@0: DECL_CLASS(nsIServiceManager); michael@0: DECL_CLASS(nsIFile); michael@0: DECL_CLASS(nsILocalFile); michael@0: DECL_CLASS(nsIDirectoryServiceProvider); michael@0: DECL_CLASS(nsIMemory); michael@0: DECL_CLASS(nsIDebug); michael@0: michael@0: #ifdef __cplusplus michael@0: namespace mozilla { michael@0: struct Module; michael@0: } michael@0: #endif michael@0: michael@0: /** michael@0: * Initialises XPCOM. You must call one of the NS_InitXPCOM methods michael@0: * before proceeding to use xpcom. The one exception is that you may michael@0: * call NS_NewLocalFile to create a nsIFile. michael@0: * michael@0: * @note Use NS_NewLocalFile or NS_NewNativeLocalFile michael@0: * to create the file object you supply as the bin directory path in this michael@0: * call. The function may be safely called before the rest of XPCOM or michael@0: * embedding has been initialised. michael@0: * michael@0: * @param result The service manager. You may pass null. michael@0: * michael@0: * @param binDirectory The directory containing the component michael@0: * registry and runtime libraries; michael@0: * or use nullptr to use the working michael@0: * directory. michael@0: * michael@0: * @param appFileLocationProvider The object to be used by Gecko that specifies michael@0: * to Gecko where to find profiles, the component michael@0: * registry preferences and so on; or use michael@0: * nullptr for the default behaviour. michael@0: * michael@0: * @see NS_NewLocalFile michael@0: * @see nsIFile michael@0: * @see nsIDirectoryServiceProvider michael@0: * michael@0: * @return NS_OK for success; michael@0: * NS_ERROR_NOT_INITIALIZED if static globals were not initialized, michael@0: * which can happen if XPCOM is reloaded, but did not completly michael@0: * shutdown. Other error codes indicate a failure during michael@0: * initialisation. michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_InitXPCOM2(nsIServiceManager* *result, michael@0: nsIFile* binDirectory, michael@0: nsIDirectoryServiceProvider* appFileLocationProvider); michael@0: michael@0: /** michael@0: * Shutdown XPCOM. You must call this method after you are finished michael@0: * using xpcom. michael@0: * michael@0: * @param servMgr The service manager which was returned by NS_InitXPCOM. michael@0: * This will release servMgr. You may pass null. michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure during initialisation. michael@0: * michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_ShutdownXPCOM(nsIServiceManager* servMgr); michael@0: michael@0: michael@0: /** michael@0: * Public Method to access to the service manager. michael@0: * michael@0: * @param result Interface pointer to the service manager michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure during initialisation. michael@0: * michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_GetServiceManager(nsIServiceManager* *result); michael@0: michael@0: /** michael@0: * Public Method to access to the component manager. michael@0: * michael@0: * @param result Interface pointer to the service michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure during initialisation. michael@0: * michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_GetComponentManager(nsIComponentManager* *result); michael@0: michael@0: michael@0: /** michael@0: * Public Method to access to the component registration manager. michael@0: * michael@0: * @param result Interface pointer to the service michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure during initialisation. michael@0: * michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_GetComponentRegistrar(nsIComponentRegistrar* *result); michael@0: michael@0: /** michael@0: * Public Method to access to the memory manager. See nsIMemory michael@0: * michael@0: * @param result Interface pointer to the memory manager michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure during initialisation. michael@0: * michael@0: */ michael@0: XPCOM_API(nsresult) michael@0: NS_GetMemoryManager(nsIMemory* *result); michael@0: michael@0: /** michael@0: * Public Method to create an instance of a nsIFile. This function michael@0: * may be called prior to NS_InitXPCOM. michael@0: * michael@0: * @param path michael@0: * A string which specifies a full file path to a michael@0: * location. Relative paths will be treated as an michael@0: * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). michael@0: * |NS_NewNativeLocalFile|'s path must be in the michael@0: * filesystem charset. michael@0: * @param followLinks michael@0: * This attribute will determine if the nsLocalFile will auto michael@0: * resolve symbolic links. By default, this value will be false michael@0: * on all non unix systems. On unix, this attribute is effectively michael@0: * a noop. michael@0: * @param result Interface pointer to a new instance of an nsIFile michael@0: * michael@0: * @return NS_OK for success; michael@0: * other error codes indicate a failure. michael@0: */ michael@0: michael@0: #ifdef __cplusplus michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_NewLocalFile(const nsAString &path, michael@0: bool followLinks, michael@0: nsIFile* *result); michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_NewNativeLocalFile(const nsACString &path, michael@0: bool followLinks, michael@0: nsIFile* *result); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Allocates a block of memory of a particular size. If the memory cannot michael@0: * be allocated (because of an out-of-memory condition), the process aborts. michael@0: * michael@0: * @param size The size of the block to allocate michael@0: * @result The block of memory michael@0: * @note This function is thread-safe. michael@0: */ michael@0: XPCOM_API(void*) michael@0: NS_Alloc(size_t size); michael@0: michael@0: /** michael@0: * Reallocates a block of memory to a new size. michael@0: * michael@0: * @param ptr The block of memory to reallocate. This block must originally michael@0: have been allocated by NS_Alloc or NS_Realloc michael@0: * @param size The new size. If 0, frees the block like NS_Free michael@0: * @result The reallocated block of memory michael@0: * @note This function is thread-safe. michael@0: * michael@0: * If ptr is null, this function behaves like NS_Alloc. michael@0: * If s is the size of the block to which ptr points, the first min(s, size) michael@0: * bytes of ptr's block are copied to the new block. If the allocation michael@0: * succeeds, ptr is freed and a pointer to the new block is returned. If the michael@0: * allocation fails, the process aborts. michael@0: */ michael@0: XPCOM_API(void*) michael@0: NS_Realloc(void* ptr, size_t size); michael@0: michael@0: /** michael@0: * Frees a block of memory. Null is a permissible value, in which case no michael@0: * action is taken. michael@0: * michael@0: * @param ptr The block of memory to free. This block must originally have michael@0: * been allocated by NS_Alloc or NS_Realloc michael@0: * @note This function is thread-safe. michael@0: */ michael@0: XPCOM_API(void) michael@0: NS_Free(void* ptr); michael@0: michael@0: /** michael@0: * Support for warnings, assertions, and debugging breaks. michael@0: */ michael@0: michael@0: enum { michael@0: NS_DEBUG_WARNING = 0, michael@0: NS_DEBUG_ASSERTION = 1, michael@0: NS_DEBUG_BREAK = 2, michael@0: NS_DEBUG_ABORT = 3 michael@0: }; michael@0: michael@0: /** michael@0: * Print a runtime assertion. This function is available in both debug and michael@0: * release builds. michael@0: * michael@0: * @note Based on the value of aSeverity and the XPCOM_DEBUG_BREAK michael@0: * environment variable, this function may cause the application to michael@0: * print the warning, print a stacktrace, break into a debugger, or abort michael@0: * immediately. michael@0: * michael@0: * @param aSeverity A NS_DEBUG_* value michael@0: * @param aStr A readable error message (ASCII, may be null) michael@0: * @param aExpr The expression evaluated (may be null) michael@0: * @param aFile The source file containing the assertion (may be null) michael@0: * @param aLine The source file line number (-1 indicates no line number) michael@0: */ michael@0: XPCOM_API(void) michael@0: NS_DebugBreak(uint32_t aSeverity, michael@0: const char *aStr, const char *aExpr, michael@0: const char *aFile, int32_t aLine); michael@0: michael@0: /** michael@0: * Perform a stack-walk to a debugging log under various michael@0: * circumstances. Used to aid debugging of leaked object graphs. michael@0: * michael@0: * The NS_Log* functions are available in both debug and release michael@0: * builds of XPCOM, but the output will be useless unless binary michael@0: * debugging symbols for all modules in the stacktrace are available. michael@0: */ michael@0: michael@0: /** michael@0: * By default, refcount logging is enabled at NS_InitXPCOM and michael@0: * refcount statistics are printed at NS_ShutdownXPCOM. NS_LogInit and michael@0: * NS_LogTerm allow applications to enable logging earlier and delay michael@0: * printing of logging statistics. They should always be used as a michael@0: * matched pair. michael@0: */ michael@0: XPCOM_API(void) michael@0: NS_LogInit(); michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogTerm(); michael@0: michael@0: /** michael@0: * Log construction and destruction of objects. Processing tools can use the michael@0: * stacktraces printed by these functions to identify objects that are being michael@0: * leaked. michael@0: * michael@0: * @param aPtr A pointer to the concrete object. michael@0: * @param aTypeName The class name of the type michael@0: * @param aInstanceSize The size of the type michael@0: */ michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize); michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogDtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize); michael@0: michael@0: /** michael@0: * Log a stacktrace when an XPCOM object's refcount is incremented or michael@0: * decremented. Processing tools can use the stacktraces printed by these michael@0: * functions to identify objects that were leaked due to XPCOM references. michael@0: * michael@0: * @param aPtr A pointer to the concrete object michael@0: * @param aNewRefCnt The new reference count. michael@0: * @param aTypeName The class name of the type michael@0: * @param aInstanceSize The size of the type michael@0: */ michael@0: XPCOM_API(void) michael@0: NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt, michael@0: const char *aTypeName, uint32_t aInstanceSize); michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName); michael@0: michael@0: /** michael@0: * Log reference counting performed by COMPtrs. Processing tools can michael@0: * use the stacktraces printed by these functions to simplify reports michael@0: * about leaked objects generated from the data printed by michael@0: * NS_LogAddRef/NS_LogRelease. michael@0: * michael@0: * @param aCOMPtr the address of the COMPtr holding a strong reference michael@0: * @param aObject the object being referenced by the COMPtr michael@0: */ michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject); michael@0: michael@0: XPCOM_API(void) michael@0: NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject); michael@0: michael@0: /** michael@0: * The XPCOM cycle collector analyzes and breaks reference cycles between michael@0: * participating XPCOM objects. All objects in the cycle must implement michael@0: * nsCycleCollectionParticipant to break cycles correctly. michael@0: */ michael@0: michael@0: #ifdef __cplusplus michael@0: michael@0: class nsCycleCollectionParticipant; michael@0: class nsCycleCollectingAutoRefCnt; michael@0: michael@0: XPCOM_API(void) michael@0: NS_CycleCollectorSuspect3(void *n, nsCycleCollectionParticipant *p, michael@0: nsCycleCollectingAutoRefCnt *aRefCnt, michael@0: bool* aShouldDelete); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Categories (in the category manager service) used by XPCOM: michael@0: */ michael@0: michael@0: /** michael@0: * A category which is read after component registration but before michael@0: * the "xpcom-startup" notifications. Each category entry is treated michael@0: * as the contract ID of a service which implements michael@0: * nsIDirectoryServiceProvider. Each directory service provider is michael@0: * installed in the global directory service. michael@0: */ michael@0: #define XPCOM_DIRECTORY_PROVIDER_CATEGORY "xpcom-directory-providers" michael@0: michael@0: /** michael@0: * A category which is read after component registration but before michael@0: * NS_InitXPCOM returns. Each category entry is treated as the contractID of michael@0: * a service: each service is instantiated, and if it implements nsIObserver michael@0: * the nsIObserver.observe method is called with the "xpcom-startup" topic. michael@0: */ michael@0: #define NS_XPCOM_STARTUP_CATEGORY "xpcom-startup" michael@0: michael@0: michael@0: /** michael@0: * Observer topics (in the observer service) used by XPCOM: michael@0: */ michael@0: michael@0: /** michael@0: * At XPCOM startup after component registration is complete, the michael@0: * following topic is notified. In order to receive this notification, michael@0: * component must register their contract ID in the category manager, michael@0: * michael@0: * @see NS_XPCOM_STARTUP_CATEGORY michael@0: */ michael@0: #define NS_XPCOM_STARTUP_OBSERVER_ID "xpcom-startup" michael@0: michael@0: /** michael@0: * At XPCOM shutdown, this topic is notified just before "xpcom-shutdown". michael@0: * Components should only use this to mark themselves as 'being destroyed'. michael@0: * Nothing should be dispatched to any event loop. michael@0: */ michael@0: #define NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID "xpcom-will-shutdown" michael@0: michael@0: /** michael@0: * At XPCOM shutdown, this topic is notified. All components must michael@0: * release any interface references to objects in other modules when michael@0: * this topic is notified. michael@0: */ michael@0: #define NS_XPCOM_SHUTDOWN_OBSERVER_ID "xpcom-shutdown" michael@0: michael@0: /** michael@0: * This topic is notified when an entry was added to a category in the michael@0: * category manager. The subject of the notification will be the name of michael@0: * the added entry as an nsISupportsCString, and the data will be the michael@0: * name of the category. The notification will occur on the main thread. michael@0: */ michael@0: #define NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID \ michael@0: "xpcom-category-entry-added" michael@0: michael@0: /** michael@0: * This topic is notified when an entry was removed from a category in the michael@0: * category manager. The subject of the notification will be the name of michael@0: * the removed entry as an nsISupportsCString, and the data will be the michael@0: * name of the category. The notification will occur on the main thread. michael@0: */ michael@0: #define NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID \ michael@0: "xpcom-category-entry-removed" michael@0: michael@0: /** michael@0: * This topic is notified when an a category was cleared in the category michael@0: * manager. The subject of the notification will be the category manager, michael@0: * and the data will be the name of the cleared category. michael@0: * The notification will occur on the main thread. michael@0: */ michael@0: #define NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID "xpcom-category-cleared" michael@0: michael@0: XPCOM_API(nsresult) michael@0: NS_GetDebug(nsIDebug* *result); michael@0: michael@0: #endif