Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsISupportsObsolete_h__ |
michael@0 | 7 | #define nsISupportsObsolete_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "prcmon.h" |
michael@0 | 10 | |
michael@0 | 11 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | #define NS_INIT_REFCNT() NS_INIT_ISUPPORTS() |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * Macro to free an array of pointers to nsISupports (or classes |
michael@0 | 18 | * derived from it). A convenience wrapper around |
michael@0 | 19 | * NS_FREE_XPCOM_POINTER_ARRAY. |
michael@0 | 20 | * |
michael@0 | 21 | * Note that if you know that none of your nsISupports pointers are |
michael@0 | 22 | * going to be 0, you can gain a bit of speed by calling |
michael@0 | 23 | * NS_FREE_XPCOM_POINTER_ARRAY directly and using NS_RELEASE as your |
michael@0 | 24 | * free function. |
michael@0 | 25 | * |
michael@0 | 26 | * @param size Number of elements in the array. If not a constant, this |
michael@0 | 27 | * should be a int32_t. Note that this means this macro |
michael@0 | 28 | * will not work if size >= 2^31. |
michael@0 | 29 | * @param array The array to be freed. |
michael@0 | 30 | */ |
michael@0 | 31 | #define NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(size, array) \ |
michael@0 | 32 | NS_FREE_XPCOM_POINTER_ARRAY((size), (array), NS_IF_RELEASE) |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 36 | |
michael@0 | 37 | /* use these functions to associate get/set methods with a |
michael@0 | 38 | C++ member variable |
michael@0 | 39 | */ |
michael@0 | 40 | |
michael@0 | 41 | #define NS_METHOD_GETTER(_method, _type, _member) \ |
michael@0 | 42 | _method(_type* aResult) \ |
michael@0 | 43 | {\ |
michael@0 | 44 | if (!aResult) return NS_ERROR_NULL_POINTER; \ |
michael@0 | 45 | *aResult = _member; \ |
michael@0 | 46 | return NS_OK; \ |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | #define NS_METHOD_SETTER(_method, _type, _member) \ |
michael@0 | 50 | _method(_type aResult) \ |
michael@0 | 51 | { \ |
michael@0 | 52 | _member = aResult; \ |
michael@0 | 53 | return NS_OK; \ |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * special for strings to get/set char* strings |
michael@0 | 58 | * using PL_strdup and PR_FREEIF |
michael@0 | 59 | */ |
michael@0 | 60 | #define NS_METHOD_GETTER_STR(_method,_member) \ |
michael@0 | 61 | _method(char* *aString) \ |
michael@0 | 62 | { \ |
michael@0 | 63 | if (!aString) return NS_ERROR_NULL_POINTER; \ |
michael@0 | 64 | if (!(*aString = PL_strdup(_member))) \ |
michael@0 | 65 | return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 66 | return NS_OK; \ |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | #define NS_METHOD_SETTER_STR(_method, _member) \ |
michael@0 | 70 | _method(const char *aString) \ |
michael@0 | 71 | { \ |
michael@0 | 72 | if (_member) PR_Free(_member); \ |
michael@0 | 73 | if (!aString) \ |
michael@0 | 74 | _member = nullptr; \ |
michael@0 | 75 | else if (!(_member = PL_strdup(aString))) \ |
michael@0 | 76 | return NS_ERROR_OUT_OF_MEMORY; \ |
michael@0 | 77 | return NS_OK; \ |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /* Getter/Setter macros. |
michael@0 | 81 | Usage: |
michael@0 | 82 | NS_IMPL_[CLASS_]GETTER[_<type>](method, [type,] member); |
michael@0 | 83 | NS_IMPL_[CLASS_]SETTER[_<type>](method, [type,] member); |
michael@0 | 84 | NS_IMPL_[CLASS_]GETSET[_<type>]([class, ]postfix, [type,] member); |
michael@0 | 85 | |
michael@0 | 86 | where: |
michael@0 | 87 | CLASS_ - implementation is inside a class definition |
michael@0 | 88 | (otherwise the class name is needed) |
michael@0 | 89 | Do NOT use in publicly exported header files, because |
michael@0 | 90 | the implementation may be included many times over. |
michael@0 | 91 | Instead, use the non-CLASS_ version. |
michael@0 | 92 | _<type> - For more complex (STR, IFACE) data types |
michael@0 | 93 | (otherwise the simple data type is needed) |
michael@0 | 94 | method - name of the method, such as GetWidth or SetColor |
michael@0 | 95 | type - simple data type if required |
michael@0 | 96 | member - class member variable such as m_width or mColor |
michael@0 | 97 | class - the class name, such as Window or MyObject |
michael@0 | 98 | postfix - Method part after Get/Set such as "Width" for "GetWidth" |
michael@0 | 99 | |
michael@0 | 100 | Example: |
michael@0 | 101 | class Window { |
michael@0 | 102 | public: |
michael@0 | 103 | NS_IMPL_CLASS_GETSET(Width, int, m_width); |
michael@0 | 104 | NS_IMPL_CLASS_GETTER_STR(GetColor, m_color); |
michael@0 | 105 | NS_IMETHOD SetColor(char *color); |
michael@0 | 106 | |
michael@0 | 107 | private: |
michael@0 | 108 | int m_width; // read/write |
michael@0 | 109 | char *m_color; // readonly |
michael@0 | 110 | }; |
michael@0 | 111 | |
michael@0 | 112 | // defined outside of class |
michael@0 | 113 | NS_IMPL_SETTER_STR(Window::GetColor, m_color); |
michael@0 | 114 | |
michael@0 | 115 | Questions/Comments to alecf@netscape.com |
michael@0 | 116 | */ |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | /* |
michael@0 | 120 | * Getter/Setter implementation within a class definition |
michael@0 | 121 | */ |
michael@0 | 122 | |
michael@0 | 123 | /* simple data types */ |
michael@0 | 124 | #define NS_IMPL_CLASS_GETTER(_method, _type, _member) \ |
michael@0 | 125 | NS_IMETHOD NS_METHOD_GETTER(_method, _type, _member) |
michael@0 | 126 | |
michael@0 | 127 | #define NS_IMPL_CLASS_SETTER(_method, _type, _member) \ |
michael@0 | 128 | NS_IMETHOD NS_METHOD_SETTER(_method, _type, _member) |
michael@0 | 129 | |
michael@0 | 130 | #define NS_IMPL_CLASS_GETSET(_postfix, _type, _member) \ |
michael@0 | 131 | NS_IMPL_CLASS_GETTER(Get##_postfix, _type, _member) \ |
michael@0 | 132 | NS_IMPL_CLASS_SETTER(Set##_postfix, _type, _member) |
michael@0 | 133 | |
michael@0 | 134 | /* strings */ |
michael@0 | 135 | #define NS_IMPL_CLASS_GETTER_STR(_method, _member) \ |
michael@0 | 136 | NS_IMETHOD NS_METHOD_GETTER_STR(_method, _member) |
michael@0 | 137 | |
michael@0 | 138 | #define NS_IMPL_CLASS_SETTER_STR(_method, _member) \ |
michael@0 | 139 | NS_IMETHOD NS_METHOD_SETTER_STR(_method, _member) |
michael@0 | 140 | |
michael@0 | 141 | #define NS_IMPL_CLASS_GETSET_STR(_postfix, _member) \ |
michael@0 | 142 | NS_IMPL_CLASS_GETTER_STR(Get##_postfix, _member) \ |
michael@0 | 143 | NS_IMPL_CLASS_SETTER_STR(Set##_postfix, _member) |
michael@0 | 144 | |
michael@0 | 145 | /* Getter/Setter implementation outside of a class definition */ |
michael@0 | 146 | |
michael@0 | 147 | /* simple data types */ |
michael@0 | 148 | #define NS_IMPL_GETTER(_method, _type, _member) \ |
michael@0 | 149 | NS_IMETHODIMP NS_METHOD_GETTER(_method, _type, _member) |
michael@0 | 150 | |
michael@0 | 151 | #define NS_IMPL_SETTER(_method, _type, _member) \ |
michael@0 | 152 | NS_IMETHODIMP NS_METHOD_SETTER(_method, _type, _member) |
michael@0 | 153 | |
michael@0 | 154 | #define NS_IMPL_GETSET(_class, _postfix, _type, _member) \ |
michael@0 | 155 | NS_IMPL_GETTER(_class::Get##_postfix, _type, _member) \ |
michael@0 | 156 | NS_IMPL_SETTER(_class::Set##_postfix, _type, _member) |
michael@0 | 157 | |
michael@0 | 158 | /* strings */ |
michael@0 | 159 | #define NS_IMPL_GETTER_STR(_method, _member) \ |
michael@0 | 160 | NS_IMETHODIMP NS_METHOD_GETTER_STR(_method, _member) |
michael@0 | 161 | |
michael@0 | 162 | #define NS_IMPL_SETTER_STR(_method, _member) \ |
michael@0 | 163 | NS_IMETHODIMP NS_METHOD_SETTER_STR(_method, _member) |
michael@0 | 164 | |
michael@0 | 165 | #define NS_IMPL_GETSET_STR(_class, _postfix, _member) \ |
michael@0 | 166 | NS_IMPL_GETTER_STR(_class::Get##_postfix, _member) \ |
michael@0 | 167 | NS_IMPL_SETTER_STR(_class::Set##_postfix, _member) |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * IID for the nsIsThreadsafe interface |
michael@0 | 171 | * {88210890-47a6-11d2-bec3-00805f8a66dc} |
michael@0 | 172 | * |
michael@0 | 173 | * This interface is *only* used for debugging purposes to determine if |
michael@0 | 174 | * a given component is threadsafe. |
michael@0 | 175 | */ |
michael@0 | 176 | #define NS_ISTHREADSAFE_IID \ |
michael@0 | 177 | { 0x88210890, 0x47a6, 0x11d2, \ |
michael@0 | 178 | {0xbe, 0xc3, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} } |
michael@0 | 179 | |
michael@0 | 180 | #define NS_LOCK_INSTANCE() \ |
michael@0 | 181 | PR_CEnterMonitor((void*)this) |
michael@0 | 182 | #define NS_UNLOCK_INSTANCE() \ |
michael@0 | 183 | PR_CExitMonitor((void*)this) |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * This implements query interface with two assumptions: First, the |
michael@0 | 187 | * class in question implements nsISupports and its own interface and |
michael@0 | 188 | * nothing else. Second, the implementation of the class's primary |
michael@0 | 189 | * inheritance chain leads to its own interface. |
michael@0 | 190 | * |
michael@0 | 191 | * @param _class The name of the class implementing the method |
michael@0 | 192 | * @param _classiiddef The name of the #define symbol that defines the IID |
michael@0 | 193 | * for the class (e.g. NS_ISUPPORTS_IID) |
michael@0 | 194 | */ |
michael@0 | 195 | #if defined(DEBUG) |
michael@0 | 196 | #define NS_VERIFY_THREADSAFE_INTERFACE(_iface) \ |
michael@0 | 197 | if (nullptr != (_iface)) { \ |
michael@0 | 198 | nsISupports* tmp; \ |
michael@0 | 199 | static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID); \ |
michael@0 | 200 | NS_PRECONDITION((NS_OK == _iface->QueryInterface(kIsThreadsafeIID, \ |
michael@0 | 201 | (void**)&tmp)), \ |
michael@0 | 202 | "Interface is not threadsafe"); \ |
michael@0 | 203 | } |
michael@0 | 204 | #else |
michael@0 | 205 | #define NS_VERIFY_THREADSAFE_INTERFACE(_iface) |
michael@0 | 206 | #endif |
michael@0 | 207 | |
michael@0 | 208 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 209 | |
michael@0 | 210 | |
michael@0 | 211 | |
michael@0 | 212 | #endif |