PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/nsXPCOM.h

http://firefox-mac-pdf.googlecode.com/
C Header | 556 lines | 137 code | 53 blank | 366 comment | 0 complexity | a87eddad666cbbcdbc55e248f024ae74 MD5 | raw file
  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. * Benjamin Smedberg <benjamin@smedbergs.us>
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either of the GNU General Public License Version 2 or later (the "GPL"),
  27. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. #ifndef nsXPCOM_h__
  39. #define nsXPCOM_h__
  40. /* Map frozen functions to private symbol names if not using strict API. */
  41. #ifdef MOZILLA_INTERNAL_API
  42. # define NS_InitXPCOM2 NS_InitXPCOM2_P
  43. # define NS_InitXPCOM3 NS_InitXPCOM3_P
  44. # define NS_ShutdownXPCOM NS_ShutdownXPCOM_P
  45. # define NS_GetServiceManager NS_GetServiceManager_P
  46. # define NS_GetComponentManager NS_GetComponentManager_P
  47. # define NS_GetComponentRegistrar NS_GetComponentRegistrar_P
  48. # define NS_GetMemoryManager NS_GetMemoryManager_P
  49. # define NS_NewLocalFile NS_NewLocalFile_P
  50. # define NS_NewNativeLocalFile NS_NewNativeLocalFile_P
  51. # define NS_GetDebug NS_GetDebug_P
  52. # define NS_GetTraceRefcnt NS_GetTraceRefcnt_P
  53. # define NS_Alloc NS_Alloc_P
  54. # define NS_Realloc NS_Realloc_P
  55. # define NS_Free NS_Free_P
  56. # define NS_DebugBreak NS_DebugBreak_P
  57. # define NS_LogInit NS_LogInit_P
  58. # define NS_LogTerm NS_LogTerm_P
  59. # define NS_LogAddRef NS_LogAddRef_P
  60. # define NS_LogRelease NS_LogRelease_P
  61. # define NS_LogCtor NS_LogCtor_P
  62. # define NS_LogDtor NS_LogDtor_P
  63. # define NS_LogCOMPtrAddRef NS_LogCOMPtrAddRef_P
  64. # define NS_LogCOMPtrRelease NS_LogCOMPtrRelease_P
  65. # define NS_CycleCollectorSuspect NS_CycleCollectorSuspect_P
  66. # define NS_CycleCollectorForget NS_CycleCollectorForget_P
  67. #endif
  68. #include "nscore.h"
  69. #include "nsXPCOMCID.h"
  70. #ifdef __cplusplus
  71. #define DECL_CLASS(c) class c
  72. #else
  73. #define DECL_CLASS(c) typedef struct c c
  74. #endif
  75. DECL_CLASS(nsAString);
  76. DECL_CLASS(nsACString);
  77. DECL_CLASS(nsISupports);
  78. DECL_CLASS(nsIModule);
  79. DECL_CLASS(nsIComponentManager);
  80. DECL_CLASS(nsIComponentRegistrar);
  81. DECL_CLASS(nsIServiceManager);
  82. DECL_CLASS(nsIFile);
  83. DECL_CLASS(nsILocalFile);
  84. DECL_CLASS(nsIDirectoryServiceProvider);
  85. DECL_CLASS(nsIMemory);
  86. DECL_CLASS(nsIDebug);
  87. DECL_CLASS(nsITraceRefcnt);
  88. /**
  89. * Every XPCOM component implements this function signature, which is the
  90. * only entrypoint XPCOM uses to the function.
  91. *
  92. * @status FROZEN
  93. */
  94. typedef nsresult (PR_CALLBACK *nsGetModuleProc)(nsIComponentManager *aCompMgr,
  95. nsIFile* location,
  96. nsIModule** return_cobj);
  97. /**
  98. * Initialises XPCOM. You must call one of the NS_InitXPCOM methods
  99. * before proceeding to use xpcom. The one exception is that you may
  100. * call NS_NewLocalFile to create a nsIFile.
  101. *
  102. * @status FROZEN
  103. *
  104. * @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE>
  105. * to create the file object you supply as the bin directory path in this
  106. * call. The function may be safely called before the rest of XPCOM or
  107. * embedding has been initialised.
  108. *
  109. * @param result The service manager. You may pass null.
  110. *
  111. * @param binDirectory The directory containing the component
  112. * registry and runtime libraries;
  113. * or use <CODE>nsnull</CODE> to use the working
  114. * directory.
  115. *
  116. * @param appFileLocationProvider The object to be used by Gecko that specifies
  117. * to Gecko where to find profiles, the component
  118. * registry preferences and so on; or use
  119. * <CODE>nsnull</CODE> for the default behaviour.
  120. *
  121. * @see NS_NewLocalFile
  122. * @see nsILocalFile
  123. * @see nsIDirectoryServiceProvider
  124. *
  125. * @return NS_OK for success;
  126. * NS_ERROR_NOT_INITIALIZED if static globals were not initialized,
  127. * which can happen if XPCOM is reloaded, but did not completly
  128. * shutdown. Other error codes indicate a failure during
  129. * initialisation.
  130. */
  131. XPCOM_API(nsresult)
  132. NS_InitXPCOM2(nsIServiceManager* *result,
  133. nsIFile* binDirectory,
  134. nsIDirectoryServiceProvider* appFileLocationProvider);
  135. /**
  136. * Some clients of XPCOM have statically linked components (not dynamically
  137. * loaded component DLLs), which can be passed to NS_InitXPCOM3 using this
  138. * structure.
  139. *
  140. * @status FROZEN
  141. */
  142. typedef struct nsStaticModuleInfo {
  143. const char *name;
  144. nsGetModuleProc getModule;
  145. } nsStaticModuleInfo;
  146. /**
  147. * Initialises XPCOM with static components. You must call one of the
  148. * NS_InitXPCOM methods before proceeding to use xpcom. The one
  149. * exception is that you may call NS_NewLocalFile to create a nsIFile.
  150. *
  151. * @status FROZEN
  152. *
  153. * @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE>
  154. * to create the file object you supply as the bin directory path in this
  155. * call. The function may be safely called before the rest of XPCOM or
  156. * embedding has been initialised.
  157. *
  158. * @param result The service manager. You may pass null.
  159. *
  160. * @param binDirectory The directory containing the component
  161. * registry and runtime libraries;
  162. * or use <CODE>nsnull</CODE> to use the working
  163. * directory.
  164. *
  165. * @param appFileLocationProvider The object to be used by Gecko that specifies
  166. * to Gecko where to find profiles, the component
  167. * registry preferences and so on; or use
  168. * <CODE>nsnull</CODE> for the default behaviour.
  169. *
  170. * @param staticComponents An array of static components. Passing null causes
  171. * default (builtin) components to be registered, if
  172. * present.
  173. * @param componentCount Number of elements in staticComponents
  174. *
  175. * @see NS_NewLocalFile
  176. * @see nsILocalFile
  177. * @see nsIDirectoryServiceProvider
  178. * @see XRE_GetStaticComponents
  179. *
  180. * @return NS_OK for success;
  181. * NS_ERROR_NOT_INITIALIZED if static globals were not initialized,
  182. * which can happen if XPCOM is reloaded, but did not completly
  183. * shutdown. Other error codes indicate a failure during
  184. * initialisation.
  185. */
  186. XPCOM_API(nsresult)
  187. NS_InitXPCOM3(nsIServiceManager* *result,
  188. nsIFile* binDirectory,
  189. nsIDirectoryServiceProvider* appFileLocationProvider,
  190. nsStaticModuleInfo const *staticComponents,
  191. PRUint32 componentCount);
  192. /**
  193. * Shutdown XPCOM. You must call this method after you are finished
  194. * using xpcom.
  195. *
  196. * @status FROZEN
  197. *
  198. * @param servMgr The service manager which was returned by NS_InitXPCOM.
  199. * This will release servMgr. You may pass null.
  200. *
  201. * @return NS_OK for success;
  202. * other error codes indicate a failure during initialisation.
  203. *
  204. */
  205. XPCOM_API(nsresult)
  206. NS_ShutdownXPCOM(nsIServiceManager* servMgr);
  207. /**
  208. * Public Method to access to the service manager.
  209. *
  210. * @status FROZEN
  211. * @param result Interface pointer to the service manager
  212. *
  213. * @return NS_OK for success;
  214. * other error codes indicate a failure during initialisation.
  215. *
  216. */
  217. XPCOM_API(nsresult)
  218. NS_GetServiceManager(nsIServiceManager* *result);
  219. /**
  220. * Public Method to access to the component manager.
  221. *
  222. * @status FROZEN
  223. * @param result Interface pointer to the service
  224. *
  225. * @return NS_OK for success;
  226. * other error codes indicate a failure during initialisation.
  227. *
  228. */
  229. XPCOM_API(nsresult)
  230. NS_GetComponentManager(nsIComponentManager* *result);
  231. /**
  232. * Public Method to access to the component registration manager.
  233. *
  234. * @status FROZEN
  235. * @param result Interface pointer to the service
  236. *
  237. * @return NS_OK for success;
  238. * other error codes indicate a failure during initialisation.
  239. *
  240. */
  241. XPCOM_API(nsresult)
  242. NS_GetComponentRegistrar(nsIComponentRegistrar* *result);
  243. /**
  244. * Public Method to access to the memory manager. See nsIMemory
  245. *
  246. * @status FROZEN
  247. * @param result Interface pointer to the memory manager
  248. *
  249. * @return NS_OK for success;
  250. * other error codes indicate a failure during initialisation.
  251. *
  252. */
  253. XPCOM_API(nsresult)
  254. NS_GetMemoryManager(nsIMemory* *result);
  255. /**
  256. * Public Method to create an instance of a nsILocalFile. This function
  257. * may be called prior to NS_InitXPCOM.
  258. *
  259. * @status FROZEN
  260. *
  261. * @param path
  262. * A string which specifies a full file path to a
  263. * location. Relative paths will be treated as an
  264. * error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
  265. * |NS_NewNativeLocalFile|'s path must be in the
  266. * filesystem charset.
  267. * @param followLinks
  268. * This attribute will determine if the nsLocalFile will auto
  269. * resolve symbolic links. By default, this value will be false
  270. * on all non unix systems. On unix, this attribute is effectively
  271. * a noop.
  272. * @param result Interface pointer to a new instance of an nsILocalFile
  273. *
  274. * @return NS_OK for success;
  275. * other error codes indicate a failure.
  276. */
  277. #ifdef __cplusplus
  278. XPCOM_API(nsresult)
  279. NS_NewLocalFile(const nsAString &path,
  280. PRBool followLinks,
  281. nsILocalFile* *result);
  282. XPCOM_API(nsresult)
  283. NS_NewNativeLocalFile(const nsACString &path,
  284. PRBool followLinks,
  285. nsILocalFile* *result);
  286. #endif
  287. /**
  288. * Allocates a block of memory of a particular size. If the memory cannot
  289. * be allocated (because of an out-of-memory condition), null is returned.
  290. *
  291. * @status FROZEN
  292. *
  293. * @param size The size of the block to allocate
  294. * @result The block of memory
  295. * @note This function is thread-safe.
  296. */
  297. XPCOM_API(void*)
  298. NS_Alloc(PRSize size);
  299. /**
  300. * Reallocates a block of memory to a new size.
  301. *
  302. * @status FROZEN
  303. *
  304. * @param ptr The block of memory to reallocate. This block must originally
  305. have been allocated by NS_Alloc or NS_Realloc
  306. * @param size The new size. If 0, frees the block like NS_Free
  307. * @result The reallocated block of memory
  308. * @note This function is thread-safe.
  309. *
  310. * If ptr is null, this function behaves like NS_Alloc.
  311. * If s is the size of the block to which ptr points, the first min(s, size)
  312. * bytes of ptr's block are copied to the new block. If the allocation
  313. * succeeds, ptr is freed and a pointer to the new block is returned. If the
  314. * allocation fails, ptr is not freed and null is returned. The returned
  315. * value may be the same as ptr.
  316. */
  317. XPCOM_API(void*)
  318. NS_Realloc(void* ptr, PRSize size);
  319. /**
  320. * Frees a block of memory. Null is a permissible value, in which case no
  321. * action is taken.
  322. *
  323. * @status FROZEN
  324. *
  325. * @param ptr The block of memory to free. This block must originally have
  326. * been allocated by NS_Alloc or NS_Realloc
  327. * @note This function is thread-safe.
  328. */
  329. XPCOM_API(void)
  330. NS_Free(void* ptr);
  331. /**
  332. * Support for warnings, assertions, and debugging breaks.
  333. */
  334. enum {
  335. NS_DEBUG_WARNING = 0,
  336. NS_DEBUG_ASSERTION = 1,
  337. NS_DEBUG_BREAK = 2,
  338. NS_DEBUG_ABORT = 3
  339. };
  340. /**
  341. * Print a runtime assertion. This function is available in both debug and
  342. * release builds.
  343. *
  344. * @note Based on the value of aSeverity and the XPCOM_DEBUG_BREAK
  345. * environment variable, this function may cause the application to
  346. * print the warning, print a stacktrace, break into a debugger, or abort
  347. * immediately.
  348. *
  349. * @param aSeverity A NS_DEBUG_* value
  350. * @param aStr A readable error message (ASCII, may be null)
  351. * @param aExpr The expression evaluated (may be null)
  352. * @param aFile The source file containing the assertion (may be null)
  353. * @param aLine The source file line number (-1 indicates no line number)
  354. */
  355. XPCOM_API(void)
  356. NS_DebugBreak(PRUint32 aSeverity,
  357. const char *aStr, const char *aExpr,
  358. const char *aFile, PRInt32 aLine);
  359. /**
  360. * Perform a stack-walk to a debugging log under various
  361. * circumstances. Used to aid debugging of leaked object graphs.
  362. *
  363. * The NS_Log* functions are available in both debug and release
  364. * builds of XPCOM, but the output will be useless unless binary
  365. * debugging symbols for all modules in the stacktrace are available.
  366. */
  367. /**
  368. * By default, refcount logging is enabled at NS_InitXPCOM and
  369. * refcount statistics are printed at NS_ShutdownXPCOM. NS_LogInit and
  370. * NS_LogTerm allow applications to enable logging earlier and delay
  371. * printing of logging statistics. They should always be used as a
  372. * matched pair.
  373. */
  374. XPCOM_API(void)
  375. NS_LogInit();
  376. XPCOM_API(void)
  377. NS_LogTerm();
  378. /**
  379. * Log construction and destruction of objects. Processing tools can use the
  380. * stacktraces printed by these functions to identify objects that are being
  381. * leaked.
  382. *
  383. * @param aPtr A pointer to the concrete object.
  384. * @param aTypeName The class name of the type
  385. * @param aInstanceSize The size of the type
  386. */
  387. XPCOM_API(void)
  388. NS_LogCtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize);
  389. XPCOM_API(void)
  390. NS_LogDtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize);
  391. /**
  392. * Log a stacktrace when an XPCOM object's refcount is incremented or
  393. * decremented. Processing tools can use the stacktraces printed by these
  394. * functions to identify objects that were leaked due to XPCOM references.
  395. *
  396. * @param aPtr A pointer to the concrete object
  397. * @param aNewRefCnt The new reference count.
  398. * @param aTypeName The class name of the type
  399. * @param aInstanceSize The size of the type
  400. */
  401. XPCOM_API(void)
  402. NS_LogAddRef(void *aPtr, nsrefcnt aNewRefCnt,
  403. const char *aTypeName, PRUint32 aInstanceSize);
  404. XPCOM_API(void)
  405. NS_LogRelease(void *aPtr, nsrefcnt aNewRefCnt, const char *aTypeName);
  406. /**
  407. * Log reference counting performed by COMPtrs. Processing tools can
  408. * use the stacktraces printed by these functions to simplify reports
  409. * about leaked objects generated from the data printed by
  410. * NS_LogAddRef/NS_LogRelease.
  411. *
  412. * @param aCOMPtr the address of the COMPtr holding a strong reference
  413. * @param aObject the object being referenced by the COMPtr
  414. */
  415. XPCOM_API(void)
  416. NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports *aObject);
  417. XPCOM_API(void)
  418. NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports *aObject);
  419. /**
  420. * The XPCOM cycle collector analyzes and breaks reference cycles between
  421. * participating XPCOM objects. All objects in the cycle must implement
  422. * nsCycleCollectionParticipant to break cycles correctly.
  423. */
  424. XPCOM_API(PRBool)
  425. NS_CycleCollectorSuspect(nsISupports *n);
  426. XPCOM_API(PRBool)
  427. NS_CycleCollectorForget(nsISupports *n);
  428. /**
  429. * Categories (in the category manager service) used by XPCOM:
  430. */
  431. /**
  432. * A category which is read after component registration but before
  433. * the "xpcom-startup" notifications. Each category entry is treated
  434. * as the contract ID of a service which implements
  435. * nsIDirectoryServiceProvider. Each directory service provider is
  436. * installed in the global directory service.
  437. *
  438. * @status FROZEN
  439. */
  440. #define XPCOM_DIRECTORY_PROVIDER_CATEGORY "xpcom-directory-providers"
  441. /**
  442. * A category which is read after component registration but before
  443. * NS_InitXPCOM returns. Each category entry is treated as the contractID of
  444. * a service: each service is instantiated, and if it implements nsIObserver
  445. * the nsIObserver.observe method is called with the "xpcom-startup" topic.
  446. *
  447. * @status FROZEN
  448. */
  449. #define NS_XPCOM_STARTUP_CATEGORY "xpcom-startup"
  450. /**
  451. * Observer topics (in the observer service) used by XPCOM:
  452. */
  453. /**
  454. * At XPCOM startup after component registration is complete, the
  455. * following topic is notified. In order to receive this notification,
  456. * component must register their contract ID in the category manager,
  457. *
  458. * @see NS_XPCOM_STARTUP_CATEGORY
  459. * @status FROZEN
  460. */
  461. #define NS_XPCOM_STARTUP_OBSERVER_ID "xpcom-startup"
  462. /**
  463. * At XPCOM shutdown, this topic is notified. All components must
  464. * release any interface references to objects in other modules when
  465. * this topic is notified.
  466. *
  467. * @status FROZEN
  468. */
  469. #define NS_XPCOM_SHUTDOWN_OBSERVER_ID "xpcom-shutdown"
  470. /**
  471. * This topic is notified when an entry was added to a category in the
  472. * category manager. The subject of the notification will be the name of
  473. * the added entry as an nsISupportsCString, and the data will be the
  474. * name of the category. The notification will occur on the main thread.
  475. *
  476. * @status FROZEN
  477. */
  478. #define NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID \
  479. "xpcom-category-entry-added"
  480. /**
  481. * This topic is notified when an entry was removed from a category in the
  482. * category manager. The subject of the notification will be the name of
  483. * the removed entry as an nsISupportsCString, and the data will be the
  484. * name of the category. The notification will occur on the main thread.
  485. *
  486. * @status FROZEN
  487. */
  488. #define NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID \
  489. "xpcom-category-entry-removed"
  490. /**
  491. * This topic is notified when an a category was cleared in the category
  492. * manager. The subject of the notification will be the category manager,
  493. * and the data will be the name of the cleared category.
  494. * The notification will occur on the main thread.
  495. *
  496. * @status FROZEN
  497. */
  498. #define NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID "xpcom-category-cleared"
  499. XPCOM_API(nsresult)
  500. NS_GetDebug(nsIDebug* *result);
  501. XPCOM_API(nsresult)
  502. NS_GetTraceRefcnt(nsITraceRefcnt* *result);
  503. #endif