xpcom/build/nsXPCOM.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/build/nsXPCOM.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,414 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsXPCOM_h__
    1.10 +#define nsXPCOM_h__
    1.11 +
    1.12 +#include "nscore.h"
    1.13 +#include "nsXPCOMCID.h"
    1.14 +
    1.15 +#ifdef __cplusplus
    1.16 +#define DECL_CLASS(c) class c
    1.17 +#define DECL_STRUCT(c) struct c
    1.18 +#else
    1.19 +#define DECL_CLASS(c) typedef struct c c
    1.20 +#define DECL_STRUCT(c) typedef struct c c
    1.21 +#endif
    1.22 +
    1.23 +DECL_CLASS(nsAString);
    1.24 +DECL_CLASS(nsACString);
    1.25 +
    1.26 +DECL_CLASS(nsISupports);
    1.27 +DECL_CLASS(nsIModule);
    1.28 +DECL_CLASS(nsIComponentManager);
    1.29 +DECL_CLASS(nsIComponentRegistrar);
    1.30 +DECL_CLASS(nsIServiceManager);
    1.31 +DECL_CLASS(nsIFile);
    1.32 +DECL_CLASS(nsILocalFile);
    1.33 +DECL_CLASS(nsIDirectoryServiceProvider);
    1.34 +DECL_CLASS(nsIMemory);
    1.35 +DECL_CLASS(nsIDebug);
    1.36 +
    1.37 +#ifdef __cplusplus
    1.38 +namespace mozilla {
    1.39 +struct Module;
    1.40 +}
    1.41 +#endif
    1.42 +
    1.43 +/**
    1.44 + * Initialises XPCOM. You must call one of the NS_InitXPCOM methods
    1.45 + * before proceeding to use xpcom. The one exception is that you may
    1.46 + * call NS_NewLocalFile to create a nsIFile.
    1.47 + * 
    1.48 + * @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE> 
    1.49 + *       to create the file object you supply as the bin directory path in this
    1.50 + *       call. The function may be safely called before the rest of XPCOM or 
    1.51 + *       embedding has been initialised.
    1.52 + *
    1.53 + * @param result           The service manager.  You may pass null.
    1.54 + *
    1.55 + * @param binDirectory     The directory containing the component
    1.56 + *                         registry and runtime libraries;
    1.57 + *                         or use <CODE>nullptr</CODE> to use the working
    1.58 + *                         directory.
    1.59 + *
    1.60 + * @param appFileLocationProvider The object to be used by Gecko that specifies
    1.61 + *                         to Gecko where to find profiles, the component
    1.62 + *                         registry preferences and so on; or use
    1.63 + *                         <CODE>nullptr</CODE> for the default behaviour.
    1.64 + *
    1.65 + * @see NS_NewLocalFile
    1.66 + * @see nsIFile
    1.67 + * @see nsIDirectoryServiceProvider
    1.68 + *
    1.69 + * @return NS_OK for success;
    1.70 + *         NS_ERROR_NOT_INITIALIZED if static globals were not initialized,
    1.71 + *         which can happen if XPCOM is reloaded, but did not completly
    1.72 + *         shutdown. Other error codes indicate a failure during
    1.73 + *         initialisation.
    1.74 + */
    1.75 +XPCOM_API(nsresult)
    1.76 +NS_InitXPCOM2(nsIServiceManager* *result, 
    1.77 +              nsIFile* binDirectory,
    1.78 +              nsIDirectoryServiceProvider* appFileLocationProvider);
    1.79 +
    1.80 +/**
    1.81 + * Shutdown XPCOM. You must call this method after you are finished
    1.82 + * using xpcom. 
    1.83 + *
    1.84 + * @param servMgr           The service manager which was returned by NS_InitXPCOM.
    1.85 + *                          This will release servMgr.  You may pass null.
    1.86 + *
    1.87 + * @return NS_OK for success;
    1.88 + *         other error codes indicate a failure during initialisation.
    1.89 + *
    1.90 + */
    1.91 +XPCOM_API(nsresult)
    1.92 +NS_ShutdownXPCOM(nsIServiceManager* servMgr);
    1.93 +
    1.94 +
    1.95 +/**
    1.96 + * Public Method to access to the service manager.
    1.97 + * 
    1.98 + * @param result Interface pointer to the service manager 
    1.99 + *
   1.100 + * @return NS_OK for success;
   1.101 + *         other error codes indicate a failure during initialisation.
   1.102 + *
   1.103 + */
   1.104 +XPCOM_API(nsresult)
   1.105 +NS_GetServiceManager(nsIServiceManager* *result);
   1.106 +
   1.107 +/**
   1.108 + * Public Method to access to the component manager.
   1.109 + * 
   1.110 + * @param result Interface pointer to the service 
   1.111 + *
   1.112 + * @return NS_OK for success;
   1.113 + *         other error codes indicate a failure during initialisation.
   1.114 + *
   1.115 + */
   1.116 +XPCOM_API(nsresult)
   1.117 +NS_GetComponentManager(nsIComponentManager* *result);
   1.118 +
   1.119 +
   1.120 +/**
   1.121 + * Public Method to access to the component registration manager.
   1.122 + *
   1.123 + * @param result Interface pointer to the service
   1.124 + *
   1.125 + * @return NS_OK for success;
   1.126 + *         other error codes indicate a failure during initialisation.
   1.127 + *
   1.128 + */
   1.129 +XPCOM_API(nsresult)
   1.130 +NS_GetComponentRegistrar(nsIComponentRegistrar* *result);
   1.131 +
   1.132 +/**
   1.133 + * Public Method to access to the memory manager.  See nsIMemory
   1.134 + * 
   1.135 + * @param result Interface pointer to the memory manager 
   1.136 + *
   1.137 + * @return NS_OK for success;
   1.138 + *         other error codes indicate a failure during initialisation.
   1.139 + *
   1.140 + */
   1.141 +XPCOM_API(nsresult)
   1.142 +NS_GetMemoryManager(nsIMemory* *result);
   1.143 +
   1.144 +/**
   1.145 + * Public Method to create an instance of a nsIFile.  This function
   1.146 + * may be called prior to NS_InitXPCOM.
   1.147 + * 
   1.148 + *   @param path       
   1.149 + *       A string which specifies a full file path to a 
   1.150 + *       location.  Relative paths will be treated as an
   1.151 + *       error (NS_ERROR_FILE_UNRECOGNIZED_PATH).       
   1.152 + *       |NS_NewNativeLocalFile|'s path must be in the 
   1.153 + *       filesystem charset.
   1.154 + *   @param followLinks
   1.155 + *       This attribute will determine if the nsLocalFile will auto
   1.156 + *       resolve symbolic links.  By default, this value will be false
   1.157 + *       on all non unix systems.  On unix, this attribute is effectively
   1.158 + *       a noop.  
   1.159 + * @param result Interface pointer to a new instance of an nsIFile 
   1.160 + *
   1.161 + * @return NS_OK for success;
   1.162 + *         other error codes indicate a failure.
   1.163 + */
   1.164 +
   1.165 +#ifdef __cplusplus
   1.166 +
   1.167 +XPCOM_API(nsresult)
   1.168 +NS_NewLocalFile(const nsAString &path, 
   1.169 +                bool followLinks, 
   1.170 +                nsIFile* *result);
   1.171 +
   1.172 +XPCOM_API(nsresult)
   1.173 +NS_NewNativeLocalFile(const nsACString &path, 
   1.174 +                      bool followLinks, 
   1.175 +                      nsIFile* *result);
   1.176 +
   1.177 +#endif
   1.178 +
   1.179 +/**
   1.180 + * Allocates a block of memory of a particular size. If the memory cannot
   1.181 + * be allocated (because of an out-of-memory condition), the process aborts.
   1.182 + *
   1.183 + * @param size   The size of the block to allocate
   1.184 + * @result       The block of memory
   1.185 + * @note         This function is thread-safe.
   1.186 + */
   1.187 +XPCOM_API(void*)
   1.188 +NS_Alloc(size_t size);
   1.189 +
   1.190 +/**
   1.191 + * Reallocates a block of memory to a new size.
   1.192 + *
   1.193 + * @param ptr     The block of memory to reallocate. This block must originally
   1.194 +                  have been allocated by NS_Alloc or NS_Realloc
   1.195 + * @param size    The new size. If 0, frees the block like NS_Free
   1.196 + * @result        The reallocated block of memory
   1.197 + * @note          This function is thread-safe.
   1.198 + *
   1.199 + * If ptr is null, this function behaves like NS_Alloc.
   1.200 + * If s is the size of the block to which ptr points, the first min(s, size)
   1.201 + * bytes of ptr's block are copied to the new block. If the allocation
   1.202 + * succeeds, ptr is freed and a pointer to the new block is returned. If the
   1.203 + * allocation fails, the process aborts.
   1.204 + */
   1.205 +XPCOM_API(void*)
   1.206 +NS_Realloc(void* ptr, size_t size);
   1.207 +
   1.208 +/**
   1.209 + * Frees a block of memory. Null is a permissible value, in which case no
   1.210 + * action is taken.
   1.211 + *
   1.212 + * @param ptr   The block of memory to free. This block must originally have
   1.213 + *              been allocated by NS_Alloc or NS_Realloc
   1.214 + * @note        This function is thread-safe.
   1.215 + */
   1.216 +XPCOM_API(void)
   1.217 +NS_Free(void* ptr);
   1.218 +
   1.219 +/**
   1.220 + * Support for warnings, assertions, and debugging breaks.
   1.221 + */
   1.222 +
   1.223 +enum {
   1.224 +    NS_DEBUG_WARNING = 0,
   1.225 +    NS_DEBUG_ASSERTION = 1,
   1.226 +    NS_DEBUG_BREAK = 2,
   1.227 +    NS_DEBUG_ABORT = 3
   1.228 +};
   1.229 +
   1.230 +/**
   1.231 + * Print a runtime assertion. This function is available in both debug and
   1.232 + * release builds.
   1.233 + * 
   1.234 + * @note Based on the value of aSeverity and the XPCOM_DEBUG_BREAK
   1.235 + * environment variable, this function may cause the application to
   1.236 + * print the warning, print a stacktrace, break into a debugger, or abort
   1.237 + * immediately.
   1.238 + *
   1.239 + * @param aSeverity A NS_DEBUG_* value
   1.240 + * @param aStr   A readable error message (ASCII, may be null)
   1.241 + * @param aExpr  The expression evaluated (may be null)
   1.242 + * @param aFile  The source file containing the assertion (may be null)
   1.243 + * @param aLine  The source file line number (-1 indicates no line number)
   1.244 + */
   1.245 +XPCOM_API(void)
   1.246 +NS_DebugBreak(uint32_t aSeverity,
   1.247 +              const char *aStr, const char *aExpr,
   1.248 +              const char *aFile, int32_t aLine);
   1.249 +
   1.250 +/**
   1.251 + * Perform a stack-walk to a debugging log under various
   1.252 + * circumstances. Used to aid debugging of leaked object graphs.
   1.253 + *
   1.254 + * The NS_Log* functions are available in both debug and release
   1.255 + * builds of XPCOM, but the output will be useless unless binary
   1.256 + * debugging symbols for all modules in the stacktrace are available.
   1.257 + */
   1.258 +
   1.259 +/**
   1.260 + * By default, refcount logging is enabled at NS_InitXPCOM and
   1.261 + * refcount statistics are printed at NS_ShutdownXPCOM. NS_LogInit and
   1.262 + * NS_LogTerm allow applications to enable logging earlier and delay
   1.263 + * printing of logging statistics. They should always be used as a
   1.264 + * matched pair.
   1.265 + */
   1.266 +XPCOM_API(void)
   1.267 +NS_LogInit();
   1.268 +
   1.269 +XPCOM_API(void)
   1.270 +NS_LogTerm();
   1.271 +
   1.272 +/**
   1.273 + * Log construction and destruction of objects. Processing tools can use the
   1.274 + * stacktraces printed by these functions to identify objects that are being
   1.275 + * leaked.
   1.276 + *
   1.277 + * @param aPtr          A pointer to the concrete object.
   1.278 + * @param aTypeName     The class name of the type
   1.279 + * @param aInstanceSize The size of the type
   1.280 + */
   1.281 +
   1.282 +XPCOM_API(void)
   1.283 +NS_LogCtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize);
   1.284 +
   1.285 +XPCOM_API(void)
   1.286 +NS_LogDtor(void *aPtr, const char *aTypeName, uint32_t aInstanceSize);
   1.287 +
   1.288 +/**
   1.289 + * Log a stacktrace when an XPCOM object's refcount is incremented or
   1.290 + * decremented. Processing tools can use the stacktraces printed by these
   1.291 + * functions to identify objects that were leaked due to XPCOM references.
   1.292 + *
   1.293 + * @param aPtr          A pointer to the concrete object
   1.294 + * @param aNewRefCnt    The new reference count.
   1.295 + * @param aTypeName     The class name of the type
   1.296 + * @param aInstanceSize The size of the type
   1.297 + */
   1.298 +XPCOM_API(void)
   1.299 +NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt,
   1.300 +             const char *aTypeName, uint32_t aInstanceSize);
   1.301 +
   1.302 +XPCOM_API(void)
   1.303 +NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName);
   1.304 +
   1.305 +/**
   1.306 + * Log reference counting performed by COMPtrs. Processing tools can
   1.307 + * use the stacktraces printed by these functions to simplify reports
   1.308 + * about leaked objects generated from the data printed by
   1.309 + * NS_LogAddRef/NS_LogRelease.
   1.310 + *
   1.311 + * @param aCOMPtr the address of the COMPtr holding a strong reference
   1.312 + * @param aObject the object being referenced by the COMPtr
   1.313 + */
   1.314 +
   1.315 +XPCOM_API(void)
   1.316 +NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject);
   1.317 +
   1.318 +XPCOM_API(void)
   1.319 +NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject);
   1.320 +
   1.321 +/**
   1.322 + * The XPCOM cycle collector analyzes and breaks reference cycles between
   1.323 + * participating XPCOM objects. All objects in the cycle must implement
   1.324 + * nsCycleCollectionParticipant to break cycles correctly.
   1.325 + */
   1.326 +
   1.327 +#ifdef __cplusplus
   1.328 +
   1.329 +class nsCycleCollectionParticipant;
   1.330 +class nsCycleCollectingAutoRefCnt;
   1.331 +
   1.332 +XPCOM_API(void)
   1.333 +NS_CycleCollectorSuspect3(void *n, nsCycleCollectionParticipant *p,
   1.334 +                          nsCycleCollectingAutoRefCnt *aRefCnt,
   1.335 +                          bool* aShouldDelete);
   1.336 +
   1.337 +#endif
   1.338 +
   1.339 +/**
   1.340 + * Categories (in the category manager service) used by XPCOM:
   1.341 + */
   1.342 +
   1.343 +/**
   1.344 + * A category which is read after component registration but before
   1.345 + * the "xpcom-startup" notifications. Each category entry is treated
   1.346 + * as the contract ID of a service which implements
   1.347 + * nsIDirectoryServiceProvider. Each directory service provider is
   1.348 + * installed in the global directory service.
   1.349 + */
   1.350 +#define XPCOM_DIRECTORY_PROVIDER_CATEGORY "xpcom-directory-providers"
   1.351 +
   1.352 +/**
   1.353 + * A category which is read after component registration but before
   1.354 + * NS_InitXPCOM returns. Each category entry is treated as the contractID of
   1.355 + * a service: each service is instantiated, and if it implements nsIObserver
   1.356 + * the nsIObserver.observe method is called with the "xpcom-startup" topic.
   1.357 + */
   1.358 +#define NS_XPCOM_STARTUP_CATEGORY "xpcom-startup"
   1.359 +
   1.360 +
   1.361 +/**
   1.362 + * Observer topics (in the observer service) used by XPCOM:
   1.363 + */
   1.364 +
   1.365 +/**
   1.366 + * At XPCOM startup after component registration is complete, the
   1.367 + * following topic is notified. In order to receive this notification,
   1.368 + * component must register their contract ID in the category manager,
   1.369 + *
   1.370 + * @see NS_XPCOM_STARTUP_CATEGORY
   1.371 + */
   1.372 +#define NS_XPCOM_STARTUP_OBSERVER_ID "xpcom-startup"
   1.373 +
   1.374 +/**
   1.375 + * At XPCOM shutdown, this topic is notified just before "xpcom-shutdown".
   1.376 + * Components should only use this to mark themselves as 'being destroyed'.
   1.377 + * Nothing should be dispatched to any event loop.
   1.378 + */
   1.379 +#define NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID "xpcom-will-shutdown"
   1.380 +
   1.381 +/**
   1.382 + * At XPCOM shutdown, this topic is notified. All components must
   1.383 + * release any interface references to objects in other modules when
   1.384 + * this topic is notified.
   1.385 + */
   1.386 +#define NS_XPCOM_SHUTDOWN_OBSERVER_ID "xpcom-shutdown"
   1.387 +
   1.388 +/**
   1.389 + * This topic is notified when an entry was added to a category in the
   1.390 + * category manager. The subject of the notification will be the name of
   1.391 + * the added entry as an nsISupportsCString, and the data will be the
   1.392 + * name of the category. The notification will occur on the main thread.
   1.393 + */
   1.394 +#define NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID \
   1.395 +  "xpcom-category-entry-added"
   1.396 +
   1.397 +/**
   1.398 + * This topic is notified when an entry was removed from a category in the
   1.399 + * category manager. The subject of the notification will be the name of
   1.400 + * the removed entry as an nsISupportsCString, and the data will be the
   1.401 + * name of the category. The notification will occur on the main thread.
   1.402 + */
   1.403 +#define NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID \
   1.404 +  "xpcom-category-entry-removed"
   1.405 +
   1.406 +/**
   1.407 + * This topic is notified when an a category was cleared in the category
   1.408 + * manager. The subject of the notification will be the category manager,
   1.409 + * and the data will be the name of the cleared category.
   1.410 + * The notification will occur on the main thread.
   1.411 + */
   1.412 +#define NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID "xpcom-category-cleared"
   1.413 +
   1.414 +XPCOM_API(nsresult)
   1.415 +NS_GetDebug(nsIDebug* *result);
   1.416 +
   1.417 +#endif

mercurial