nsIPrefBranch2.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * DO NOT EDIT. THIS FILE IS GENERATED FROM c:/mozilla/modules/libpref/public/nsIPrefBranch2.idl
  3. */
  4. #ifndef __gen_nsIPrefBranch2_h__
  5. #define __gen_nsIPrefBranch2_h__
  6. #ifndef __gen_nsIPrefBranch_h__
  7. #include "nsIPrefBranch.h"
  8. #endif
  9. /* For IDL files that don't want to include root IDL files. */
  10. #ifndef NS_NO_VTABLE
  11. #define NS_NO_VTABLE
  12. #endif
  13. class nsIObserver; /* forward declaration */
  14. /* starting interface: nsIPrefBranch2 */
  15. #define NS_IPREFBRANCH2_IID_STR "74567534-eb94-4b1c-8f45-389643bfc555"
  16. #define NS_IPREFBRANCH2_IID \
  17. {0x74567534, 0xeb94, 0x4b1c, \
  18. { 0x8f, 0x45, 0x38, 0x96, 0x43, 0xbf, 0xc5, 0x55 }}
  19. /**
  20. * nsIPrefBranch2 allows clients to observe changes to pref values.
  21. *
  22. * @status FROZEN
  23. * @see nsIPrefBranch
  24. */
  25. class NS_NO_VTABLE nsIPrefBranch2 : public nsIPrefBranch {
  26. public:
  27. NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPREFBRANCH2_IID)
  28. /**
  29. * Add a preference change observer. On preference changes, the following
  30. * arguments will be passed to the nsIObserver.observe() method:
  31. * aSubject - The nsIPrefBranch object (this)
  32. * aTopic - The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
  33. * aData - The preference which has changed
  34. *
  35. * @param aDomain The preference on which to listen for changes. This can
  36. * be the name of an entire branch to observe.
  37. * e.g. Holding the "root" prefbranch and calling
  38. * addObserver("foo.bar.", ...) will observe changes to
  39. * foo.bar.baz and foo.bar.bzip
  40. * @param aObserver The object to be notified if the preference changes.
  41. * @param aHoldWeak true Hold a weak reference to |aObserver|. The object
  42. * must implement the nsISupportsWeakReference
  43. * interface or this will fail.
  44. * false Hold a strong reference to |aObserver|.
  45. *
  46. * @note
  47. * Registering as a preference observer can open an object to potential
  48. * cyclical references which will cause memory leaks. These cycles generally
  49. * occur because an object both registers itself as an observer (causing the
  50. * branch to hold a reference to the observer) and holds a reference to the
  51. * branch object for the purpose of getting/setting preference values. There
  52. * are 3 approaches which have been implemented in an attempt to avoid these
  53. * situations.
  54. * 1) The nsPrefBranch object supports nsISupportsWeakReference. Any consumer
  55. * may hold a weak reference to it instead of a strong one.
  56. * 2) The nsPrefBranch object listens for xpcom-shutdown and frees all of the
  57. * objects currently in its observer list. This insures that long lived
  58. * objects (services for example) will be freed correctly.
  59. * 3) The observer can request to be held as a weak reference when it is
  60. * registered. This insures that shorter lived objects (say one tied to an
  61. * open window) will not fall into the cyclical reference trap.
  62. *
  63. * @see nsIObserver
  64. * @see removeObserver
  65. */
  66. /* void addObserver (in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak); */
  67. NS_IMETHOD AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak) = 0;
  68. /**
  69. * Remove a preference change observer.
  70. *
  71. * @param aDomain The preference which is being observed for changes.
  72. * @param aObserver An observer previously registered with addObserver().
  73. *
  74. * @see nsIObserver
  75. * @see addObserver
  76. */
  77. /* void removeObserver (in string aDomain, in nsIObserver aObserver); */
  78. NS_IMETHOD RemoveObserver(const char *aDomain, nsIObserver *aObserver) = 0;
  79. };
  80. /* Use this macro when declaring classes that implement this interface. */
  81. #define NS_DECL_NSIPREFBRANCH2 \
  82. NS_IMETHOD AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak); \
  83. NS_IMETHOD RemoveObserver(const char *aDomain, nsIObserver *aObserver);
  84. /* Use this macro to declare functions that forward the behavior of this interface to another object. */
  85. #define NS_FORWARD_NSIPREFBRANCH2(_to) \
  86. NS_IMETHOD AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak) { return _to AddObserver(aDomain, aObserver, aHoldWeak); } \
  87. NS_IMETHOD RemoveObserver(const char *aDomain, nsIObserver *aObserver) { return _to RemoveObserver(aDomain, aObserver); }
  88. /* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
  89. #define NS_FORWARD_SAFE_NSIPREFBRANCH2(_to) \
  90. NS_IMETHOD AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aDomain, aObserver, aHoldWeak); } \
  91. NS_IMETHOD RemoveObserver(const char *aDomain, nsIObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aDomain, aObserver); }
  92. #if 0
  93. /* Use the code below as a template for the implementation class for this interface. */
  94. /* Header file */
  95. class nsPrefBranch2 : public nsIPrefBranch2
  96. {
  97. public:
  98. NS_DECL_ISUPPORTS
  99. NS_DECL_NSIPREFBRANCH2
  100. nsPrefBranch2();
  101. private:
  102. ~nsPrefBranch2();
  103. protected:
  104. /* additional members */
  105. };
  106. /* Implementation file */
  107. NS_IMPL_ISUPPORTS1(nsPrefBranch2, nsIPrefBranch2)
  108. nsPrefBranch2::nsPrefBranch2()
  109. {
  110. /* member initializers and constructor code */
  111. }
  112. nsPrefBranch2::~nsPrefBranch2()
  113. {
  114. /* destructor code */
  115. }
  116. /* void addObserver (in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak); */
  117. NS_IMETHODIMP nsPrefBranch2::AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak)
  118. {
  119. return NS_ERROR_NOT_IMPLEMENTED;
  120. }
  121. /* void removeObserver (in string aDomain, in nsIObserver aObserver); */
  122. NS_IMETHODIMP nsPrefBranch2::RemoveObserver(const char *aDomain, nsIObserver *aObserver)
  123. {
  124. return NS_ERROR_NOT_IMPLEMENTED;
  125. }
  126. /* End of implementation class template. */
  127. #endif
  128. /**
  129. * Notification sent when a preference changes.
  130. */
  131. #define NS_PREFBRANCH_PREFCHANGE_TOPIC_ID "nsPref:changed"
  132. #endif /* __gen_nsIPrefBranch2_h__ */