nsISupportsImpl.h 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is XPCOM.
  15. *
  16. * The Initial Developer of the Original Code is Netscape Communications Corp.
  17. * Portions created by the Initial Developer are Copyright (C) 2001
  18. * the Initial Developer. All Rights Reserved.
  19. *
  20. * Contributor(s):
  21. *
  22. * Alternatively, the contents of this file may be used under the terms of
  23. * either the GNU General Public License Version 2 or later (the "GPL"), or
  24. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  25. * in which case the provisions of the GPL or the LGPL are applicable instead
  26. * of those above. If you wish to allow use of your version of this file only
  27. * under the terms of either the GPL or the LGPL, and not to allow others to
  28. * use your version of this file under the terms of the MPL, indicate your
  29. * decision by deleting the provisions above and replace them with the notice
  30. * and other provisions required by the GPL or the LGPL. If you do not delete
  31. * the provisions above, a recipient may use your version of this file under
  32. * the terms of any one of the MPL, the GPL or the LGPL.
  33. *
  34. * ***** END LICENSE BLOCK ***** */
  35. #ifndef nsISupportsImpl_h__
  36. #define nsISupportsImpl_h__
  37. #ifndef nscore_h___
  38. #include "nscore.h"
  39. #endif
  40. #ifndef nsISupportsBase_h__
  41. #include "nsISupportsBase.h"
  42. #endif
  43. #if defined(XPCOM_GLUE) && !defined(XPCOM_GLUE_USE_NSPR)
  44. // If we're being linked as standalone glue, we don't want a dynamic dependency
  45. // on NSPR libs, so we skip the debug thread-safety checks, and we cannot use
  46. // the THREADSAFE_ISUPPORTS macros.
  47. #define XPCOM_GLUE_AVOID_NSPR
  48. #endif
  49. #if !defined(XPCOM_GLUE_AVOID_NSPR)
  50. #include "prthread.h" /* needed for thread-safety checks */
  51. #include "pratom.h" /* needed for PR_AtomicIncrement and PR_AtomicDecrement */
  52. #endif
  53. #include "nsDebug.h"
  54. #include "nsTraceRefcnt.h"
  55. ////////////////////////////////////////////////////////////////////////////////
  56. // Macros to help detect thread-safety:
  57. #if defined(NS_DEBUG) && !defined(XPCOM_GLUE_AVOID_NSPR)
  58. class nsAutoOwningThread {
  59. public:
  60. nsAutoOwningThread() { mThread = PR_GetCurrentThread(); }
  61. void *GetThread() const { return mThread; }
  62. private:
  63. void *mThread;
  64. };
  65. #define NS_DECL_OWNINGTHREAD nsAutoOwningThread _mOwningThread;
  66. #define NS_ASSERT_OWNINGTHREAD(_class) \
  67. NS_CheckThreadSafe(_mOwningThread.GetThread(), #_class " not thread-safe")
  68. #else // !NS_DEBUG
  69. #define NS_DECL_OWNINGTHREAD /* nothing */
  70. #define NS_ASSERT_OWNINGTHREAD(_class) ((void)0)
  71. #endif // NS_DEBUG
  72. class nsAutoRefCnt {
  73. public:
  74. nsAutoRefCnt() : mValue(0) {}
  75. nsAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {}
  76. // only support prefix increment/decrement
  77. nsrefcnt operator++() { return ++mValue; }
  78. nsrefcnt operator--() { return --mValue; }
  79. nsrefcnt operator=(nsrefcnt aValue) { return (mValue = aValue); }
  80. operator nsrefcnt() const { return mValue; }
  81. nsrefcnt get() const { return mValue; }
  82. private:
  83. // do not define these to enforce the faster prefix notation
  84. nsrefcnt operator++(int);
  85. nsrefcnt operator--(int);
  86. nsrefcnt mValue;
  87. };
  88. ///////////////////////////////////////////////////////////////////////////////
  89. /**
  90. * Declare the reference count variable and the implementations of the
  91. * AddRef and QueryInterface methods.
  92. */
  93. #define NS_DECL_ISUPPORTS \
  94. public: \
  95. NS_IMETHOD QueryInterface(REFNSIID aIID, \
  96. void** aInstancePtr); \
  97. NS_IMETHOD_(nsrefcnt) AddRef(void); \
  98. NS_IMETHOD_(nsrefcnt) Release(void); \
  99. protected: \
  100. nsAutoRefCnt mRefCnt; \
  101. NS_DECL_OWNINGTHREAD \
  102. public:
  103. ///////////////////////////////////////////////////////////////////////////////
  104. /**
  105. * Previously used to initialize the reference count, but no longer needed.
  106. *
  107. * DEPRECATED.
  108. */
  109. #define NS_INIT_ISUPPORTS() ((void)0)
  110. /**
  111. * Use this macro to implement the AddRef method for a given <i>_class</i>
  112. * @param _class The name of the class implementing the method
  113. */
  114. #define NS_IMPL_ADDREF(_class) \
  115. NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
  116. { \
  117. NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
  118. NS_ASSERT_OWNINGTHREAD(_class); \
  119. ++mRefCnt; \
  120. NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this)); \
  121. return mRefCnt; \
  122. }
  123. /**
  124. * Use this macro to implement the AddRef method for a given <i>_class</i>
  125. * implemented as a wholly owned aggregated object intended to implement
  126. * interface(s) for its owner
  127. * @param _class The name of the class implementing the method
  128. * @param _aggregator the owning/containing object
  129. */
  130. #define NS_IMPL_ADDREF_USING_AGGREGATOR(_class, _aggregator) \
  131. NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
  132. { \
  133. NS_PRECONDITION(_aggregator, "null aggregator"); \
  134. return (_aggregator)->AddRef(); \
  135. }
  136. /**
  137. * Use this macro to implement the Release method for a given
  138. * <i>_class</i>.
  139. * @param _class The name of the class implementing the method
  140. * @param _destroy A statement that is executed when the object's
  141. * refcount drops to zero.
  142. *
  143. * For example,
  144. *
  145. * NS_IMPL_RELEASE_WITH_DESTROY(Foo, Destroy(this))
  146. *
  147. * will cause
  148. *
  149. * Destroy(this);
  150. *
  151. * to be invoked when the object's refcount drops to zero. This
  152. * allows for arbitrary teardown activity to occur (e.g., deallocation
  153. * of object allocated with placement new).
  154. */
  155. #define NS_IMPL_RELEASE_WITH_DESTROY(_class, _destroy) \
  156. NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
  157. { \
  158. NS_PRECONDITION(0 != mRefCnt, "dup release"); \
  159. NS_ASSERT_OWNINGTHREAD(_class); \
  160. --mRefCnt; \
  161. NS_LOG_RELEASE(this, mRefCnt, #_class); \
  162. if (mRefCnt == 0) { \
  163. mRefCnt = 1; /* stabilize */ \
  164. _destroy; \
  165. return 0; \
  166. } \
  167. return mRefCnt; \
  168. }
  169. /**
  170. * Use this macro to implement the Release method for a given <i>_class</i>
  171. * @param _class The name of the class implementing the method
  172. *
  173. * A note on the 'stabilization' of the refcnt to one. At that point,
  174. * the object's refcount will have gone to zero. The object's
  175. * destructor may trigger code that attempts to QueryInterface() and
  176. * Release() 'this' again. Doing so will temporarily increment and
  177. * decrement the refcount. (Only a logic error would make one try to
  178. * keep a permanent hold on 'this'.) To prevent re-entering the
  179. * destructor, we make sure that no balanced refcounting can return
  180. * the refcount to |0|.
  181. */
  182. #define NS_IMPL_RELEASE(_class) \
  183. NS_IMPL_RELEASE_WITH_DESTROY(_class, NS_DELETEXPCOM(this))
  184. /**
  185. * Use this macro to implement the Release method for a given <i>_class</i>
  186. * implemented as a wholly owned aggregated object intended to implement
  187. * interface(s) for its owner
  188. * @param _class The name of the class implementing the method
  189. * @param _aggregator the owning/containing object
  190. */
  191. #define NS_IMPL_RELEASE_USING_AGGREGATOR(_class, _aggregator) \
  192. NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
  193. { \
  194. NS_PRECONDITION(_aggregator, "null aggregator"); \
  195. return (_aggregator)->Release(); \
  196. }
  197. ///////////////////////////////////////////////////////////////////////////////
  198. /*
  199. * Some convenience macros for implementing QueryInterface
  200. */
  201. /**
  202. * This implements query interface with two assumptions: First, the
  203. * class in question implements nsISupports and its own interface and
  204. * nothing else. Second, the implementation of the class's primary
  205. * inheritance chain leads to its own interface.
  206. *
  207. * @param _class The name of the class implementing the method
  208. * @param _classiiddef The name of the #define symbol that defines the IID
  209. * for the class (e.g. NS_ISUPPORTS_IID)
  210. */
  211. #define NS_IMPL_QUERY_HEAD(_class) \
  212. NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
  213. { \
  214. NS_ASSERTION(aInstancePtr, \
  215. "QueryInterface requires a non-NULL destination!"); \
  216. nsISupports* foundInterface;
  217. #define NS_IMPL_QUERY_BODY(_interface) \
  218. if ( aIID.Equals(NS_GET_IID(_interface)) ) \
  219. foundInterface = NS_STATIC_CAST(_interface*, this); \
  220. else
  221. #define NS_IMPL_QUERY_BODY_CONDITIONAL(_interface, condition) \
  222. if ( (condition) && aIID.Equals(NS_GET_IID(_interface))) \
  223. foundInterface = NS_STATIC_CAST(_interface*, this); \
  224. else
  225. #define NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass) \
  226. if ( aIID.Equals(NS_GET_IID(_interface)) ) \
  227. foundInterface = NS_STATIC_CAST(_interface*, \
  228. NS_STATIC_CAST(_implClass*, this)); \
  229. else
  230. #define NS_IMPL_QUERY_BODY_AGGREGATED(_interface, _aggregate) \
  231. if ( aIID.Equals(NS_GET_IID(_interface)) ) \
  232. foundInterface = NS_STATIC_CAST(_interface*, _aggregate); \
  233. else
  234. #define NS_IMPL_QUERY_TAIL_GUTS \
  235. foundInterface = 0; \
  236. nsresult status; \
  237. if ( !foundInterface ) \
  238. status = NS_NOINTERFACE; \
  239. else \
  240. { \
  241. NS_ADDREF(foundInterface); \
  242. status = NS_OK; \
  243. } \
  244. *aInstancePtr = foundInterface; \
  245. return status; \
  246. }
  247. #define NS_IMPL_QUERY_TAIL_INHERITING(_baseclass) \
  248. foundInterface = 0; \
  249. nsresult status; \
  250. if ( !foundInterface ) \
  251. status = _baseclass::QueryInterface(aIID, (void**)&foundInterface); \
  252. else \
  253. { \
  254. NS_ADDREF(foundInterface); \
  255. status = NS_OK; \
  256. } \
  257. *aInstancePtr = foundInterface; \
  258. return status; \
  259. }
  260. #define NS_IMPL_QUERY_TAIL_USING_AGGREGATOR(_aggregator) \
  261. foundInterface = 0; \
  262. nsresult status; \
  263. if ( !foundInterface ) { \
  264. NS_ASSERTION(_aggregator, "null aggregator"); \
  265. status = _aggregator->QueryInterface(aIID, (void**)&foundInterface); \
  266. } else \
  267. { \
  268. NS_ADDREF(foundInterface); \
  269. status = NS_OK; \
  270. } \
  271. *aInstancePtr = foundInterface; \
  272. return status; \
  273. }
  274. #define NS_IMPL_QUERY_TAIL(_supports_interface) \
  275. NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface) \
  276. NS_IMPL_QUERY_TAIL_GUTS
  277. /*
  278. This is the new scheme. Using this notation now will allow us to switch to
  279. a table driven mechanism when it's ready. Note the difference between this
  280. and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism. You must
  281. explicitly mention |nsISupports| when using the interface maps.
  282. */
  283. #define NS_INTERFACE_MAP_BEGIN(_implClass) NS_IMPL_QUERY_HEAD(_implClass)
  284. #define NS_INTERFACE_MAP_ENTRY(_interface) NS_IMPL_QUERY_BODY(_interface)
  285. #define NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, condition) \
  286. NS_IMPL_QUERY_BODY_CONDITIONAL(_interface, condition)
  287. #define NS_INTERFACE_MAP_ENTRY_AGGREGATED(_interface,_aggregate) \
  288. NS_IMPL_QUERY_BODY_AGGREGATED(_interface,_aggregate)
  289. #define NS_INTERFACE_MAP_END NS_IMPL_QUERY_TAIL_GUTS
  290. #define NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(_interface, _implClass) \
  291. NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass)
  292. #define NS_INTERFACE_MAP_END_INHERITING(_baseClass) \
  293. NS_IMPL_QUERY_TAIL_INHERITING(_baseClass)
  294. #define NS_INTERFACE_MAP_END_AGGREGATED(_aggregator) \
  295. NS_IMPL_QUERY_TAIL_USING_AGGREGATOR(_aggregator)
  296. #define NS_IMPL_QUERY_INTERFACE0(_class) \
  297. NS_INTERFACE_MAP_BEGIN(_class) \
  298. NS_INTERFACE_MAP_ENTRY(nsISupports) \
  299. NS_INTERFACE_MAP_END
  300. #define NS_IMPL_QUERY_INTERFACE1(_class, _i1) \
  301. NS_INTERFACE_MAP_BEGIN(_class) \
  302. NS_INTERFACE_MAP_ENTRY(_i1) \
  303. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  304. NS_INTERFACE_MAP_END
  305. #define NS_IMPL_QUERY_INTERFACE2(_class, _i1, _i2) \
  306. NS_INTERFACE_MAP_BEGIN(_class) \
  307. NS_INTERFACE_MAP_ENTRY(_i1) \
  308. NS_INTERFACE_MAP_ENTRY(_i2) \
  309. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  310. NS_INTERFACE_MAP_END
  311. #define NS_IMPL_QUERY_INTERFACE3(_class, _i1, _i2, _i3) \
  312. NS_INTERFACE_MAP_BEGIN(_class) \
  313. NS_INTERFACE_MAP_ENTRY(_i1) \
  314. NS_INTERFACE_MAP_ENTRY(_i2) \
  315. NS_INTERFACE_MAP_ENTRY(_i3) \
  316. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  317. NS_INTERFACE_MAP_END
  318. #define NS_IMPL_QUERY_INTERFACE4(_class, _i1, _i2, _i3, _i4) \
  319. NS_INTERFACE_MAP_BEGIN(_class) \
  320. NS_INTERFACE_MAP_ENTRY(_i1) \
  321. NS_INTERFACE_MAP_ENTRY(_i2) \
  322. NS_INTERFACE_MAP_ENTRY(_i3) \
  323. NS_INTERFACE_MAP_ENTRY(_i4) \
  324. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  325. NS_INTERFACE_MAP_END
  326. #define NS_IMPL_QUERY_INTERFACE5(_class, _i1, _i2, _i3, _i4, _i5) \
  327. NS_INTERFACE_MAP_BEGIN(_class) \
  328. NS_INTERFACE_MAP_ENTRY(_i1) \
  329. NS_INTERFACE_MAP_ENTRY(_i2) \
  330. NS_INTERFACE_MAP_ENTRY(_i3) \
  331. NS_INTERFACE_MAP_ENTRY(_i4) \
  332. NS_INTERFACE_MAP_ENTRY(_i5) \
  333. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  334. NS_INTERFACE_MAP_END
  335. #define NS_IMPL_QUERY_INTERFACE6(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  336. NS_INTERFACE_MAP_BEGIN(_class) \
  337. NS_INTERFACE_MAP_ENTRY(_i1) \
  338. NS_INTERFACE_MAP_ENTRY(_i2) \
  339. NS_INTERFACE_MAP_ENTRY(_i3) \
  340. NS_INTERFACE_MAP_ENTRY(_i4) \
  341. NS_INTERFACE_MAP_ENTRY(_i5) \
  342. NS_INTERFACE_MAP_ENTRY(_i6) \
  343. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  344. NS_INTERFACE_MAP_END
  345. #define NS_IMPL_QUERY_INTERFACE7(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7) \
  346. NS_INTERFACE_MAP_BEGIN(_class) \
  347. NS_INTERFACE_MAP_ENTRY(_i1) \
  348. NS_INTERFACE_MAP_ENTRY(_i2) \
  349. NS_INTERFACE_MAP_ENTRY(_i3) \
  350. NS_INTERFACE_MAP_ENTRY(_i4) \
  351. NS_INTERFACE_MAP_ENTRY(_i5) \
  352. NS_INTERFACE_MAP_ENTRY(_i6) \
  353. NS_INTERFACE_MAP_ENTRY(_i7) \
  354. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  355. NS_INTERFACE_MAP_END
  356. #define NS_IMPL_QUERY_INTERFACE8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  357. _i7, _i8) \
  358. NS_INTERFACE_MAP_BEGIN(_class) \
  359. NS_INTERFACE_MAP_ENTRY(_i1) \
  360. NS_INTERFACE_MAP_ENTRY(_i2) \
  361. NS_INTERFACE_MAP_ENTRY(_i3) \
  362. NS_INTERFACE_MAP_ENTRY(_i4) \
  363. NS_INTERFACE_MAP_ENTRY(_i5) \
  364. NS_INTERFACE_MAP_ENTRY(_i6) \
  365. NS_INTERFACE_MAP_ENTRY(_i7) \
  366. NS_INTERFACE_MAP_ENTRY(_i8) \
  367. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  368. NS_INTERFACE_MAP_END
  369. #define NS_IMPL_QUERY_INTERFACE9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  370. _i7, _i8, _i9) \
  371. NS_INTERFACE_MAP_BEGIN(_class) \
  372. NS_INTERFACE_MAP_ENTRY(_i1) \
  373. NS_INTERFACE_MAP_ENTRY(_i2) \
  374. NS_INTERFACE_MAP_ENTRY(_i3) \
  375. NS_INTERFACE_MAP_ENTRY(_i4) \
  376. NS_INTERFACE_MAP_ENTRY(_i5) \
  377. NS_INTERFACE_MAP_ENTRY(_i6) \
  378. NS_INTERFACE_MAP_ENTRY(_i7) \
  379. NS_INTERFACE_MAP_ENTRY(_i8) \
  380. NS_INTERFACE_MAP_ENTRY(_i9) \
  381. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  382. NS_INTERFACE_MAP_END
  383. #define NS_IMPL_QUERY_INTERFACE10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  384. _i7, _i8, _i9, _i10) \
  385. NS_INTERFACE_MAP_BEGIN(_class) \
  386. NS_INTERFACE_MAP_ENTRY(_i1) \
  387. NS_INTERFACE_MAP_ENTRY(_i2) \
  388. NS_INTERFACE_MAP_ENTRY(_i3) \
  389. NS_INTERFACE_MAP_ENTRY(_i4) \
  390. NS_INTERFACE_MAP_ENTRY(_i5) \
  391. NS_INTERFACE_MAP_ENTRY(_i6) \
  392. NS_INTERFACE_MAP_ENTRY(_i7) \
  393. NS_INTERFACE_MAP_ENTRY(_i8) \
  394. NS_INTERFACE_MAP_ENTRY(_i9) \
  395. NS_INTERFACE_MAP_ENTRY(_i10) \
  396. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  397. NS_INTERFACE_MAP_END
  398. #define NS_IMPL_QUERY_INTERFACE11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  399. _i7, _i8, _i9, _i10, _i11) \
  400. NS_INTERFACE_MAP_BEGIN(_class) \
  401. NS_INTERFACE_MAP_ENTRY(_i1) \
  402. NS_INTERFACE_MAP_ENTRY(_i2) \
  403. NS_INTERFACE_MAP_ENTRY(_i3) \
  404. NS_INTERFACE_MAP_ENTRY(_i4) \
  405. NS_INTERFACE_MAP_ENTRY(_i5) \
  406. NS_INTERFACE_MAP_ENTRY(_i6) \
  407. NS_INTERFACE_MAP_ENTRY(_i7) \
  408. NS_INTERFACE_MAP_ENTRY(_i8) \
  409. NS_INTERFACE_MAP_ENTRY(_i9) \
  410. NS_INTERFACE_MAP_ENTRY(_i10) \
  411. NS_INTERFACE_MAP_ENTRY(_i11) \
  412. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  413. NS_INTERFACE_MAP_END
  414. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE0 NS_IMPL_QUERY_INTERFACE0
  415. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE1 NS_IMPL_QUERY_INTERFACE1
  416. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE2 NS_IMPL_QUERY_INTERFACE2
  417. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE3 NS_IMPL_QUERY_INTERFACE3
  418. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE4 NS_IMPL_QUERY_INTERFACE4
  419. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE5 NS_IMPL_QUERY_INTERFACE5
  420. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE6 NS_IMPL_QUERY_INTERFACE6
  421. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE7 NS_IMPL_QUERY_INTERFACE7
  422. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE8 NS_IMPL_QUERY_INTERFACE8
  423. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE9 NS_IMPL_QUERY_INTERFACE9
  424. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE10 NS_IMPL_QUERY_INTERFACE10
  425. #define NS_IMPL_THREADSAFE_QUERY_INTERFACE11 NS_IMPL_QUERY_INTERFACE11
  426. /**
  427. * Declare that you're going to inherit from something that already
  428. * implements nsISupports, but also implements an additional interface, thus
  429. * causing an ambiguity. In this case you don't need another mRefCnt, you
  430. * just need to forward the definitions to the appropriate superclass. E.g.
  431. *
  432. * class Bar : public Foo, public nsIBar { // both provide nsISupports
  433. * public:
  434. * NS_DECL_ISUPPORTS_INHERITED
  435. * ...other nsIBar and Bar methods...
  436. * };
  437. */
  438. #define NS_DECL_ISUPPORTS_INHERITED \
  439. public: \
  440. NS_IMETHOD QueryInterface(REFNSIID aIID, \
  441. void** aInstancePtr); \
  442. NS_IMETHOD_(nsrefcnt) AddRef(void); \
  443. NS_IMETHOD_(nsrefcnt) Release(void); \
  444. /**
  445. * These macros can be used in conjunction with NS_DECL_ISUPPORTS_INHERITED
  446. * to implement the nsISupports methods, forwarding the invocations to a
  447. * superclass that already implements nsISupports.
  448. *
  449. * Note that I didn't make these inlined because they're virtual methods.
  450. */
  451. #define NS_IMPL_ADDREF_INHERITED(Class, Super) \
  452. NS_IMETHODIMP_(nsrefcnt) Class::AddRef(void) \
  453. { \
  454. return Super::AddRef(); \
  455. } \
  456. #define NS_IMPL_RELEASE_INHERITED(Class, Super) \
  457. NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \
  458. { \
  459. return Super::Release(); \
  460. } \
  461. #define NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \
  462. NS_IMPL_QUERY_HEAD(Class) \
  463. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  464. #define NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \
  465. NS_IMPL_QUERY_HEAD(Class) \
  466. NS_IMPL_QUERY_BODY(i1) \
  467. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  468. #define NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \
  469. NS_IMPL_QUERY_HEAD(Class) \
  470. NS_IMPL_QUERY_BODY(i1) \
  471. NS_IMPL_QUERY_BODY(i2) \
  472. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  473. #define NS_IMPL_QUERY_INTERFACE_INHERITED3(Class, Super, i1, i2, i3) \
  474. NS_IMPL_QUERY_HEAD(Class) \
  475. NS_IMPL_QUERY_BODY(i1) \
  476. NS_IMPL_QUERY_BODY(i2) \
  477. NS_IMPL_QUERY_BODY(i3) \
  478. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  479. #define NS_IMPL_QUERY_INTERFACE_INHERITED4(Class, Super, i1, i2, i3, i4) \
  480. NS_IMPL_QUERY_HEAD(Class) \
  481. NS_IMPL_QUERY_BODY(i1) \
  482. NS_IMPL_QUERY_BODY(i2) \
  483. NS_IMPL_QUERY_BODY(i3) \
  484. NS_IMPL_QUERY_BODY(i4) \
  485. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  486. #define NS_IMPL_QUERY_INTERFACE_INHERITED5(Class,Super,i1,i2,i3,i4,i5) \
  487. NS_IMPL_QUERY_HEAD(Class) \
  488. NS_IMPL_QUERY_BODY(i1) \
  489. NS_IMPL_QUERY_BODY(i2) \
  490. NS_IMPL_QUERY_BODY(i3) \
  491. NS_IMPL_QUERY_BODY(i4) \
  492. NS_IMPL_QUERY_BODY(i5) \
  493. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  494. #define NS_IMPL_QUERY_INTERFACE_INHERITED6(Class,Super,i1,i2,i3,i4,i5,i6) \
  495. NS_IMPL_QUERY_HEAD(Class) \
  496. NS_IMPL_QUERY_BODY(i1) \
  497. NS_IMPL_QUERY_BODY(i2) \
  498. NS_IMPL_QUERY_BODY(i3) \
  499. NS_IMPL_QUERY_BODY(i4) \
  500. NS_IMPL_QUERY_BODY(i5) \
  501. NS_IMPL_QUERY_BODY(i6) \
  502. NS_IMPL_QUERY_TAIL_INHERITING(Super) \
  503. /**
  504. * Convenience macros for implementing all nsISupports methods for
  505. * a simple class.
  506. * @param _class The name of the class implementing the method
  507. * @param _classiiddef The name of the #define symbol that defines the IID
  508. * for the class (e.g. NS_ISUPPORTS_IID)
  509. */
  510. #define NS_IMPL_ISUPPORTS0(_class) \
  511. NS_IMPL_ADDREF(_class) \
  512. NS_IMPL_RELEASE(_class) \
  513. NS_IMPL_QUERY_INTERFACE0(_class)
  514. #define NS_IMPL_ISUPPORTS1(_class, _interface) \
  515. NS_IMPL_ADDREF(_class) \
  516. NS_IMPL_RELEASE(_class) \
  517. NS_IMPL_QUERY_INTERFACE1(_class, _interface)
  518. #define NS_IMPL_ISUPPORTS2(_class, _i1, _i2) \
  519. NS_IMPL_ADDREF(_class) \
  520. NS_IMPL_RELEASE(_class) \
  521. NS_IMPL_QUERY_INTERFACE2(_class, _i1, _i2)
  522. #define NS_IMPL_ISUPPORTS3(_class, _i1, _i2, _i3) \
  523. NS_IMPL_ADDREF(_class) \
  524. NS_IMPL_RELEASE(_class) \
  525. NS_IMPL_QUERY_INTERFACE3(_class, _i1, _i2, _i3)
  526. #define NS_IMPL_ISUPPORTS4(_class, _i1, _i2, _i3, _i4) \
  527. NS_IMPL_ADDREF(_class) \
  528. NS_IMPL_RELEASE(_class) \
  529. NS_IMPL_QUERY_INTERFACE4(_class, _i1, _i2, _i3, _i4)
  530. #define NS_IMPL_ISUPPORTS5(_class, _i1, _i2, _i3, _i4, _i5) \
  531. NS_IMPL_ADDREF(_class) \
  532. NS_IMPL_RELEASE(_class) \
  533. NS_IMPL_QUERY_INTERFACE5(_class, _i1, _i2, _i3, _i4, _i5)
  534. #define NS_IMPL_ISUPPORTS6(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  535. NS_IMPL_ADDREF(_class) \
  536. NS_IMPL_RELEASE(_class) \
  537. NS_IMPL_QUERY_INTERFACE6(_class, _i1, _i2, _i3, _i4, _i5, _i6)
  538. #define NS_IMPL_ISUPPORTS7(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7) \
  539. NS_IMPL_ADDREF(_class) \
  540. NS_IMPL_RELEASE(_class) \
  541. NS_IMPL_QUERY_INTERFACE7(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7)
  542. #define NS_IMPL_ISUPPORTS8(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8) \
  543. NS_IMPL_ADDREF(_class) \
  544. NS_IMPL_RELEASE(_class) \
  545. NS_IMPL_QUERY_INTERFACE8(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8)
  546. #define NS_IMPL_ISUPPORTS9(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, \
  547. _i9) \
  548. NS_IMPL_ADDREF(_class) \
  549. NS_IMPL_RELEASE(_class) \
  550. NS_IMPL_QUERY_INTERFACE9(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9)
  551. #define NS_IMPL_ISUPPORTS10(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, \
  552. _i9, _i10) \
  553. NS_IMPL_ADDREF(_class) \
  554. NS_IMPL_RELEASE(_class) \
  555. NS_IMPL_QUERY_INTERFACE10(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, \
  556. _i9, _i10)
  557. #define NS_IMPL_ISUPPORTS11(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, \
  558. _i9, _i10, _i11) \
  559. NS_IMPL_ADDREF(_class) \
  560. NS_IMPL_RELEASE(_class) \
  561. NS_IMPL_QUERY_INTERFACE11(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, \
  562. _i9, _i10, _i11)
  563. #define NS_IMPL_ISUPPORTS_INHERITED0(Class, Super) \
  564. NS_IMPL_QUERY_INTERFACE_INHERITED0(Class, Super) \
  565. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  566. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  567. #define NS_IMPL_ISUPPORTS_INHERITED1(Class, Super, i1) \
  568. NS_IMPL_QUERY_INTERFACE_INHERITED1(Class, Super, i1) \
  569. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  570. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  571. #define NS_IMPL_ISUPPORTS_INHERITED2(Class, Super, i1, i2) \
  572. NS_IMPL_QUERY_INTERFACE_INHERITED2(Class, Super, i1, i2) \
  573. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  574. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  575. #define NS_IMPL_ISUPPORTS_INHERITED3(Class, Super, i1, i2, i3) \
  576. NS_IMPL_QUERY_INTERFACE_INHERITED3(Class, Super, i1, i2, i3) \
  577. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  578. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  579. #define NS_IMPL_ISUPPORTS_INHERITED4(Class, Super, i1, i2, i3, i4) \
  580. NS_IMPL_QUERY_INTERFACE_INHERITED4(Class, Super, i1, i2, i3, i4) \
  581. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  582. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  583. #define NS_IMPL_ISUPPORTS_INHERITED5(Class, Super, i1, i2, i3, i4, i5) \
  584. NS_IMPL_QUERY_INTERFACE_INHERITED5(Class, Super, i1, i2, i3, i4, i5) \
  585. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  586. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  587. #define NS_IMPL_ISUPPORTS_INHERITED6(Class, Super, i1, i2, i3, i4, i5, i6) \
  588. NS_IMPL_QUERY_INTERFACE_INHERITED6(Class, Super, i1, i2, i3, i4, i5, i6) \
  589. NS_IMPL_ADDREF_INHERITED(Class, Super) \
  590. NS_IMPL_RELEASE_INHERITED(Class, Super) \
  591. ///////////////////////////////////////////////////////////////////////////////
  592. /**
  593. *
  594. * Threadsafe implementations of the ISupports convenience macros.
  595. *
  596. * @note These are not available when linking against the standalone glue,
  597. * because the implementation requires PR_ symbols.
  598. */
  599. #if !defined(XPCOM_GLUE_AVOID_NSPR)
  600. /**
  601. * Use this macro to implement the AddRef method for a given <i>_class</i>
  602. * @param _class The name of the class implementing the method
  603. */
  604. #define NS_IMPL_THREADSAFE_ADDREF(_class) \
  605. NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
  606. { \
  607. NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
  608. nsrefcnt count; \
  609. count = PR_AtomicIncrement((PRInt32*)&mRefCnt); \
  610. NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \
  611. return count; \
  612. }
  613. /**
  614. * Use this macro to implement the Release method for a given <i>_class</i>
  615. * @param _class The name of the class implementing the method
  616. */
  617. #define NS_IMPL_THREADSAFE_RELEASE(_class) \
  618. NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
  619. { \
  620. nsrefcnt count; \
  621. NS_PRECONDITION(0 != mRefCnt, "dup release"); \
  622. count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); \
  623. NS_LOG_RELEASE(this, count, #_class); \
  624. if (0 == count) { \
  625. mRefCnt = 1; /* stabilize */ \
  626. /* enable this to find non-threadsafe destructors: */ \
  627. /* NS_ASSERT_OWNINGTHREAD(_class); */ \
  628. NS_DELETEXPCOM(this); \
  629. return 0; \
  630. } \
  631. return count; \
  632. }
  633. #else // XPCOM_GLUE_AVOID_NSPR
  634. #define NS_IMPL_THREADSAFE_ADDREF(_class) \
  635. THREADSAFE_ISUPPORTS_NOT_AVAILABLE_IN_STANDALONE_GLUE;
  636. #define NS_IMPL_THREADSAFE_RELEASE(_class) \
  637. THREADSAFE_ISUPPORTS_NOT_AVAILABLE_IN_STANDALONE_GLUE;
  638. #endif
  639. #define NS_IMPL_THREADSAFE_ISUPPORTS0(_class) \
  640. NS_IMPL_THREADSAFE_ADDREF(_class) \
  641. NS_IMPL_THREADSAFE_RELEASE(_class) \
  642. NS_IMPL_THREADSAFE_QUERY_INTERFACE0(_class)
  643. #define NS_IMPL_THREADSAFE_ISUPPORTS1(_class, _interface) \
  644. NS_IMPL_THREADSAFE_ADDREF(_class) \
  645. NS_IMPL_THREADSAFE_RELEASE(_class) \
  646. NS_IMPL_THREADSAFE_QUERY_INTERFACE1(_class, _interface)
  647. #define NS_IMPL_THREADSAFE_ISUPPORTS2(_class, _i1, _i2) \
  648. NS_IMPL_THREADSAFE_ADDREF(_class) \
  649. NS_IMPL_THREADSAFE_RELEASE(_class) \
  650. NS_IMPL_THREADSAFE_QUERY_INTERFACE2(_class, _i1, _i2)
  651. #define NS_IMPL_THREADSAFE_ISUPPORTS3(_class, _i1, _i2, _i3) \
  652. NS_IMPL_THREADSAFE_ADDREF(_class) \
  653. NS_IMPL_THREADSAFE_RELEASE(_class) \
  654. NS_IMPL_THREADSAFE_QUERY_INTERFACE3(_class, _i1, _i2, _i3)
  655. #define NS_IMPL_THREADSAFE_ISUPPORTS4(_class, _i1, _i2, _i3, _i4) \
  656. NS_IMPL_THREADSAFE_ADDREF(_class) \
  657. NS_IMPL_THREADSAFE_RELEASE(_class) \
  658. NS_IMPL_THREADSAFE_QUERY_INTERFACE4(_class, _i1, _i2, _i3, _i4)
  659. #define NS_IMPL_THREADSAFE_ISUPPORTS5(_class, _i1, _i2, _i3, _i4, _i5) \
  660. NS_IMPL_THREADSAFE_ADDREF(_class) \
  661. NS_IMPL_THREADSAFE_RELEASE(_class) \
  662. NS_IMPL_THREADSAFE_QUERY_INTERFACE5(_class, _i1, _i2, _i3, _i4, _i5)
  663. #define NS_IMPL_THREADSAFE_ISUPPORTS6(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  664. NS_IMPL_THREADSAFE_ADDREF(_class) \
  665. NS_IMPL_THREADSAFE_RELEASE(_class) \
  666. NS_IMPL_THREADSAFE_QUERY_INTERFACE6(_class, _i1, _i2, _i3, _i4, _i5, _i6)
  667. #define NS_IMPL_THREADSAFE_ISUPPORTS7(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  668. _i7) \
  669. NS_IMPL_THREADSAFE_ADDREF(_class) \
  670. NS_IMPL_THREADSAFE_RELEASE(_class) \
  671. NS_IMPL_THREADSAFE_QUERY_INTERFACE7(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  672. _i7)
  673. #define NS_IMPL_THREADSAFE_ISUPPORTS8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  674. _i7, _i8) \
  675. NS_IMPL_THREADSAFE_ADDREF(_class) \
  676. NS_IMPL_THREADSAFE_RELEASE(_class) \
  677. NS_IMPL_THREADSAFE_QUERY_INTERFACE8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  678. _i7, _i8)
  679. #define NS_IMPL_THREADSAFE_ISUPPORTS9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  680. _i7, _i8, _i9) \
  681. NS_IMPL_THREADSAFE_ADDREF(_class) \
  682. NS_IMPL_THREADSAFE_RELEASE(_class) \
  683. NS_IMPL_THREADSAFE_QUERY_INTERFACE9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  684. _i7, _i8, _i9)
  685. #define NS_IMPL_THREADSAFE_ISUPPORTS10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  686. _i7, _i8, _i9, _i10) \
  687. NS_IMPL_THREADSAFE_ADDREF(_class) \
  688. NS_IMPL_THREADSAFE_RELEASE(_class) \
  689. NS_IMPL_THREADSAFE_QUERY_INTERFACE10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  690. _i7, _i8, _i9, _i10)
  691. #define NS_IMPL_THREADSAFE_ISUPPORTS11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  692. _i7, _i8, _i9, _i10, _i11) \
  693. NS_IMPL_THREADSAFE_ADDREF(_class) \
  694. NS_IMPL_THREADSAFE_RELEASE(_class) \
  695. NS_IMPL_THREADSAFE_QUERY_INTERFACE11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  696. _i7, _i8, _i9, _i10, _i11)
  697. ///////////////////////////////////////////////////////////////////////////////
  698. // Macros for implementing nsIClassInfo-related stuff.
  699. ///////////////////////////////////////////////////////////////////////////////
  700. // include here instead of at the top because it requires the nsISupport decl
  701. #include "nsIClassInfo.h"
  702. #define NS_CLASSINFO_NAME(_class) _class##_classInfoGlobal
  703. #define NS_CI_INTERFACE_GETTER_NAME(_class) _class##_GetInterfacesHelper
  704. #define NS_DECL_CI_INTERFACE_GETTER(_class) \
  705. extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *, \
  706. nsIID ***);
  707. #define NS_DECL_CLASSINFO(_class) \
  708. NS_DECL_CI_INTERFACE_GETTER(_class) \
  709. nsIClassInfo *NS_CLASSINFO_NAME(_class);
  710. #define NS_IMPL_QUERY_CLASSINFO(_class) \
  711. if ( aIID.Equals(NS_GET_IID(nsIClassInfo)) ) { \
  712. extern nsIClassInfo *NS_CLASSINFO_NAME(_class); \
  713. foundInterface = NS_STATIC_CAST(nsIClassInfo*, NS_CLASSINFO_NAME(_class));\
  714. } else
  715. #define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \
  716. NS_IMETHODIMP \
  717. NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *count, nsIID ***array) \
  718. { \
  719. *count = _c; \
  720. *array = (nsIID **)nsMemory::Alloc(sizeof (nsIID *) * _c);
  721. #define NS_CLASSINFO_HELPER_ENTRY(_i, _interface) \
  722. (*array)[_i] = (nsIID *)nsMemory::Clone(&NS_GET_IID(_interface), \
  723. sizeof(nsIID));
  724. #define NS_CLASSINFO_HELPER_END \
  725. return NS_OK; \
  726. }
  727. #define NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface) \
  728. NS_CLASSINFO_HELPER_BEGIN(_class, 1) \
  729. NS_CLASSINFO_HELPER_ENTRY(0, _interface) \
  730. NS_CLASSINFO_HELPER_END
  731. #define NS_IMPL_QUERY_INTERFACE1_CI(_class, _i1) \
  732. NS_INTERFACE_MAP_BEGIN(_class) \
  733. NS_INTERFACE_MAP_ENTRY(_i1) \
  734. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  735. NS_IMPL_QUERY_CLASSINFO(_class) \
  736. NS_INTERFACE_MAP_END
  737. #define NS_IMPL_ISUPPORTS1_CI(_class, _interface) \
  738. NS_IMPL_ADDREF(_class) \
  739. NS_IMPL_RELEASE(_class) \
  740. NS_IMPL_QUERY_INTERFACE1_CI(_class, _interface) \
  741. NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface)
  742. #define NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2) \
  743. NS_CLASSINFO_HELPER_BEGIN(_class, 2) \
  744. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  745. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  746. NS_CLASSINFO_HELPER_END
  747. #define NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
  748. NS_INTERFACE_MAP_BEGIN(_class) \
  749. NS_INTERFACE_MAP_ENTRY(_i1) \
  750. NS_INTERFACE_MAP_ENTRY(_i2) \
  751. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  752. NS_IMPL_QUERY_CLASSINFO(_class) \
  753. NS_INTERFACE_MAP_END
  754. #define NS_IMPL_ISUPPORTS2_CI(_class, _i1, _i2) \
  755. NS_IMPL_ADDREF(_class) \
  756. NS_IMPL_RELEASE(_class) \
  757. NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
  758. NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2)
  759. #define NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3) \
  760. NS_CLASSINFO_HELPER_BEGIN(_class, 3) \
  761. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  762. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  763. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  764. NS_CLASSINFO_HELPER_END
  765. #define NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
  766. NS_INTERFACE_MAP_BEGIN(_class) \
  767. NS_INTERFACE_MAP_ENTRY(_i1) \
  768. NS_INTERFACE_MAP_ENTRY(_i2) \
  769. NS_INTERFACE_MAP_ENTRY(_i3) \
  770. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  771. NS_IMPL_QUERY_CLASSINFO(_class) \
  772. NS_INTERFACE_MAP_END
  773. #define NS_IMPL_ISUPPORTS3_CI(_class, _i1, _i2, _i3) \
  774. NS_IMPL_ADDREF(_class) \
  775. NS_IMPL_RELEASE(_class) \
  776. NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
  777. NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3)
  778. #define NS_IMPL_CI_INTERFACE_GETTER4(_class, _i1, _i2, _i3, _i4) \
  779. NS_CLASSINFO_HELPER_BEGIN(_class, 4) \
  780. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  781. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  782. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  783. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  784. NS_CLASSINFO_HELPER_END
  785. #define NS_IMPL_QUERY_INTERFACE4_CI(_class, _i1, _i2, _i3, _i4) \
  786. NS_INTERFACE_MAP_BEGIN(_class) \
  787. NS_INTERFACE_MAP_ENTRY(_i1) \
  788. NS_INTERFACE_MAP_ENTRY(_i2) \
  789. NS_INTERFACE_MAP_ENTRY(_i3) \
  790. NS_INTERFACE_MAP_ENTRY(_i4) \
  791. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  792. NS_IMPL_QUERY_CLASSINFO(_class) \
  793. NS_INTERFACE_MAP_END
  794. #define NS_IMPL_ISUPPORTS4_CI(_class, _i1, _i2, _i3, _i4) \
  795. NS_IMPL_ADDREF(_class) \
  796. NS_IMPL_RELEASE(_class) \
  797. NS_IMPL_QUERY_INTERFACE4_CI(_class, _i1, _i2, _i3, _i4) \
  798. NS_IMPL_CI_INTERFACE_GETTER4(_class, _i1, _i2, _i3, _i4)
  799. #define NS_IMPL_CI_INTERFACE_GETTER5(_class, _i1, _i2, _i3, _i4, _i5) \
  800. NS_CLASSINFO_HELPER_BEGIN(_class, 5) \
  801. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  802. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  803. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  804. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  805. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  806. NS_CLASSINFO_HELPER_END
  807. #define NS_IMPL_QUERY_INTERFACE5_CI(_class, _i1, _i2, _i3, _i4, _i5) \
  808. NS_INTERFACE_MAP_BEGIN(_class) \
  809. NS_INTERFACE_MAP_ENTRY(_i1) \
  810. NS_INTERFACE_MAP_ENTRY(_i2) \
  811. NS_INTERFACE_MAP_ENTRY(_i3) \
  812. NS_INTERFACE_MAP_ENTRY(_i4) \
  813. NS_INTERFACE_MAP_ENTRY(_i5) \
  814. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  815. NS_IMPL_QUERY_CLASSINFO(_class) \
  816. NS_INTERFACE_MAP_END
  817. #define NS_IMPL_ISUPPORTS5_CI(_class, _i1, _i2, _i3, _i4, _i5) \
  818. NS_IMPL_ADDREF(_class) \
  819. NS_IMPL_RELEASE(_class) \
  820. NS_IMPL_QUERY_INTERFACE5_CI(_class, _i1, _i2, _i3, _i4, _i5) \
  821. NS_IMPL_CI_INTERFACE_GETTER5(_class, _i1, _i2, _i3, _i4, _i5)
  822. #define NS_IMPL_CI_INTERFACE_GETTER6(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  823. NS_CLASSINFO_HELPER_BEGIN(_class, 6) \
  824. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  825. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  826. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  827. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  828. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  829. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  830. NS_CLASSINFO_HELPER_END
  831. #define NS_IMPL_QUERY_INTERFACE6_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  832. NS_INTERFACE_MAP_BEGIN(_class) \
  833. NS_INTERFACE_MAP_ENTRY(_i1) \
  834. NS_INTERFACE_MAP_ENTRY(_i2) \
  835. NS_INTERFACE_MAP_ENTRY(_i3) \
  836. NS_INTERFACE_MAP_ENTRY(_i4) \
  837. NS_INTERFACE_MAP_ENTRY(_i5) \
  838. NS_INTERFACE_MAP_ENTRY(_i6) \
  839. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  840. NS_IMPL_QUERY_CLASSINFO(_class) \
  841. NS_INTERFACE_MAP_END
  842. #define NS_IMPL_ISUPPORTS6_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  843. NS_IMPL_ADDREF(_class) \
  844. NS_IMPL_RELEASE(_class) \
  845. NS_IMPL_QUERY_INTERFACE6_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6) \
  846. NS_IMPL_CI_INTERFACE_GETTER6(_class, _i1, _i2, _i3, _i4, _i5, _i6)
  847. #define NS_IMPL_CI_INTERFACE_GETTER7(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  848. _i7) \
  849. NS_CLASSINFO_HELPER_BEGIN(_class, 7) \
  850. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  851. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  852. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  853. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  854. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  855. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  856. NS_CLASSINFO_HELPER_ENTRY(6, _i7) \
  857. NS_CLASSINFO_HELPER_END
  858. #define NS_IMPL_QUERY_INTERFACE7_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  859. _i7) \
  860. NS_INTERFACE_MAP_BEGIN(_class) \
  861. NS_INTERFACE_MAP_ENTRY(_i1) \
  862. NS_INTERFACE_MAP_ENTRY(_i2) \
  863. NS_INTERFACE_MAP_ENTRY(_i3) \
  864. NS_INTERFACE_MAP_ENTRY(_i4) \
  865. NS_INTERFACE_MAP_ENTRY(_i5) \
  866. NS_INTERFACE_MAP_ENTRY(_i6) \
  867. NS_INTERFACE_MAP_ENTRY(_i7) \
  868. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  869. NS_IMPL_QUERY_CLASSINFO(_class) \
  870. NS_INTERFACE_MAP_END
  871. #define NS_IMPL_ISUPPORTS7_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7) \
  872. NS_IMPL_ADDREF(_class) \
  873. NS_IMPL_RELEASE(_class) \
  874. NS_IMPL_QUERY_INTERFACE7_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7) \
  875. NS_IMPL_CI_INTERFACE_GETTER7(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7)
  876. #define NS_IMPL_CI_INTERFACE_GETTER8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  877. _i7, _i8) \
  878. NS_CLASSINFO_HELPER_BEGIN(_class, 8) \
  879. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  880. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  881. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  882. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  883. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  884. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  885. NS_CLASSINFO_HELPER_ENTRY(6, _i7) \
  886. NS_CLASSINFO_HELPER_ENTRY(7, _i8) \
  887. NS_CLASSINFO_HELPER_END
  888. #define NS_IMPL_QUERY_INTERFACE8_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  889. _i7, _i8) \
  890. NS_INTERFACE_MAP_BEGIN(_class) \
  891. NS_INTERFACE_MAP_ENTRY(_i1) \
  892. NS_INTERFACE_MAP_ENTRY(_i2) \
  893. NS_INTERFACE_MAP_ENTRY(_i3) \
  894. NS_INTERFACE_MAP_ENTRY(_i4) \
  895. NS_INTERFACE_MAP_ENTRY(_i5) \
  896. NS_INTERFACE_MAP_ENTRY(_i6) \
  897. NS_INTERFACE_MAP_ENTRY(_i7) \
  898. NS_INTERFACE_MAP_ENTRY(_i8) \
  899. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  900. NS_IMPL_QUERY_CLASSINFO(_class) \
  901. NS_INTERFACE_MAP_END
  902. #define NS_IMPL_ISUPPORTS8_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8) \
  903. NS_IMPL_ADDREF(_class) \
  904. NS_IMPL_RELEASE(_class) \
  905. NS_IMPL_QUERY_INTERFACE8_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8) \
  906. NS_IMPL_CI_INTERFACE_GETTER8(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8)
  907. #define NS_IMPL_CI_INTERFACE_GETTER9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  908. _i7, _i8, _i9) \
  909. NS_CLASSINFO_HELPER_BEGIN(_class, 9) \
  910. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  911. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  912. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  913. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  914. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  915. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  916. NS_CLASSINFO_HELPER_ENTRY(6, _i7) \
  917. NS_CLASSINFO_HELPER_ENTRY(7, _i8) \
  918. NS_CLASSINFO_HELPER_ENTRY(8, _i9) \
  919. NS_CLASSINFO_HELPER_END
  920. #define NS_IMPL_QUERY_INTERFACE9_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  921. _i7, _i8, _i9) \
  922. NS_INTERFACE_MAP_BEGIN(_class) \
  923. NS_INTERFACE_MAP_ENTRY(_i1) \
  924. NS_INTERFACE_MAP_ENTRY(_i2) \
  925. NS_INTERFACE_MAP_ENTRY(_i3) \
  926. NS_INTERFACE_MAP_ENTRY(_i4) \
  927. NS_INTERFACE_MAP_ENTRY(_i5) \
  928. NS_INTERFACE_MAP_ENTRY(_i6) \
  929. NS_INTERFACE_MAP_ENTRY(_i7) \
  930. NS_INTERFACE_MAP_ENTRY(_i8) \
  931. NS_INTERFACE_MAP_ENTRY(_i9) \
  932. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  933. NS_IMPL_QUERY_CLASSINFO(_class) \
  934. NS_INTERFACE_MAP_END
  935. #define NS_IMPL_ISUPPORTS9_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  936. _i8, _i9) \
  937. NS_IMPL_ADDREF(_class) \
  938. NS_IMPL_RELEASE(_class) \
  939. NS_IMPL_QUERY_INTERFACE9_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  940. _i8, _i9) \
  941. NS_IMPL_CI_INTERFACE_GETTER9(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  942. _i8, _i9)
  943. #define NS_IMPL_CI_INTERFACE_GETTER10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  944. _i7, _i8, _i9, _i10) \
  945. NS_CLASSINFO_HELPER_BEGIN(_class, 10) \
  946. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  947. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  948. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  949. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  950. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  951. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  952. NS_CLASSINFO_HELPER_ENTRY(6, _i7) \
  953. NS_CLASSINFO_HELPER_ENTRY(7, _i8) \
  954. NS_CLASSINFO_HELPER_ENTRY(8, _i9) \
  955. NS_CLASSINFO_HELPER_ENTRY(9, _i10) \
  956. NS_CLASSINFO_HELPER_END
  957. #define NS_IMPL_CI_INTERFACE_GETTER11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  958. _i7, _i8, _i9, _i10, _i11) \
  959. NS_CLASSINFO_HELPER_BEGIN(_class, 11) \
  960. NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
  961. NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
  962. NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
  963. NS_CLASSINFO_HELPER_ENTRY(3, _i4) \
  964. NS_CLASSINFO_HELPER_ENTRY(4, _i5) \
  965. NS_CLASSINFO_HELPER_ENTRY(5, _i6) \
  966. NS_CLASSINFO_HELPER_ENTRY(6, _i7) \
  967. NS_CLASSINFO_HELPER_ENTRY(7, _i8) \
  968. NS_CLASSINFO_HELPER_ENTRY(8, _i9) \
  969. NS_CLASSINFO_HELPER_ENTRY(9, _i10) \
  970. NS_CLASSINFO_HELPER_ENTRY(10, _i11) \
  971. NS_CLASSINFO_HELPER_END
  972. #define NS_IMPL_QUERY_INTERFACE10_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  973. _i7, _i8, _i9, _i10) \
  974. NS_INTERFACE_MAP_BEGIN(_class) \
  975. NS_INTERFACE_MAP_ENTRY(_i1) \
  976. NS_INTERFACE_MAP_ENTRY(_i2) \
  977. NS_INTERFACE_MAP_ENTRY(_i3) \
  978. NS_INTERFACE_MAP_ENTRY(_i4) \
  979. NS_INTERFACE_MAP_ENTRY(_i5) \
  980. NS_INTERFACE_MAP_ENTRY(_i6) \
  981. NS_INTERFACE_MAP_ENTRY(_i7) \
  982. NS_INTERFACE_MAP_ENTRY(_i8) \
  983. NS_INTERFACE_MAP_ENTRY(_i9) \
  984. NS_INTERFACE_MAP_ENTRY(_i10) \
  985. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  986. NS_IMPL_QUERY_CLASSINFO(_class) \
  987. NS_INTERFACE_MAP_END
  988. #define NS_IMPL_QUERY_INTERFACE11_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, \
  989. _i7, _i8, _i9, _i10, _i11) \
  990. NS_INTERFACE_MAP_BEGIN(_class) \
  991. NS_INTERFACE_MAP_ENTRY(_i1) \
  992. NS_INTERFACE_MAP_ENTRY(_i2) \
  993. NS_INTERFACE_MAP_ENTRY(_i3) \
  994. NS_INTERFACE_MAP_ENTRY(_i4) \
  995. NS_INTERFACE_MAP_ENTRY(_i5) \
  996. NS_INTERFACE_MAP_ENTRY(_i6) \
  997. NS_INTERFACE_MAP_ENTRY(_i7) \
  998. NS_INTERFACE_MAP_ENTRY(_i8) \
  999. NS_INTERFACE_MAP_ENTRY(_i9) \
  1000. NS_INTERFACE_MAP_ENTRY(_i10) \
  1001. NS_INTERFACE_MAP_ENTRY(_i11) \
  1002. NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
  1003. NS_IMPL_QUERY_CLASSINFO(_class) \
  1004. NS_INTERFACE_MAP_END
  1005. #define NS_IMPL_ISUPPORTS10_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1006. _i8, _i9, _i10) \
  1007. NS_IMPL_ADDREF(_class) \
  1008. NS_IMPL_RELEASE(_class) \
  1009. NS_IMPL_QUERY_INTERFACE10_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1010. _i8, _i9, _i10) \
  1011. NS_IMPL_CI_INTERFACE_GETTER10(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1012. _i8, _i9, _i10)
  1013. #define NS_IMPL_ISUPPORTS11_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1014. _i8, _i9, _i10, _i11) \
  1015. NS_IMPL_ADDREF(_class) \
  1016. NS_IMPL_RELEASE(_class) \
  1017. NS_IMPL_QUERY_INTERFACE11_CI(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1018. _i8, _i9, _i10, _i11) \
  1019. NS_IMPL_CI_INTERFACE_GETTER11(_class, _i1, _i2, _i3, _i4, _i5, _i6, _i7, \
  1020. _i8, _i9, _i10, _i11)
  1021. #define NS_INTERFACE_MAP_END_THREADSAFE NS_IMPL_QUERY_TAIL_GUTS
  1022. #endif