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 |
|
---|
36 |
|
---|
37 | #ifndef nsISupportsObsolete_h__
|
---|
38 | #define nsISupportsObsolete_h__
|
---|
39 |
|
---|
40 | #include "prcmon.h"
|
---|
41 |
|
---|
42 | ///////////////////////////////////////////////////////////////////////////////
|
---|
43 |
|
---|
44 |
|
---|
45 | #define NS_INIT_REFCNT() NS_INIT_ISUPPORTS()
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Macro to free an array of pointers to nsISupports (or classes
|
---|
49 | * derived from it). A convenience wrapper around
|
---|
50 | * NS_FREE_XPCOM_POINTER_ARRAY.
|
---|
51 | *
|
---|
52 | * Note that if you know that none of your nsISupports pointers are
|
---|
53 | * going to be 0, you can gain a bit of speed by calling
|
---|
54 | * NS_FREE_XPCOM_POINTER_ARRAY directly and using NS_RELEASE as your
|
---|
55 | * free function.
|
---|
56 | *
|
---|
57 | * @param size Number of elements in the array. If not a constant, this
|
---|
58 | * should be a PRInt32. Note that this means this macro
|
---|
59 | * will not work if size >= 2^31.
|
---|
60 | * @param array The array to be freed.
|
---|
61 | */
|
---|
62 | #define NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(size, array) \
|
---|
63 | NS_FREE_XPCOM_POINTER_ARRAY((size), (array), NS_IF_RELEASE)
|
---|
64 |
|
---|
65 |
|
---|
66 | ///////////////////////////////////////////////////////////////////////////////
|
---|
67 |
|
---|
68 | /* use these functions to associate get/set methods with a
|
---|
69 | C++ member variable
|
---|
70 | */
|
---|
71 |
|
---|
72 | #define NS_METHOD_GETTER(_method, _type, _member) \
|
---|
73 | _method(_type* aResult) \
|
---|
74 | {\
|
---|
75 | if (!aResult) return NS_ERROR_NULL_POINTER; \
|
---|
76 | *aResult = _member; \
|
---|
77 | return NS_OK; \
|
---|
78 | }
|
---|
79 |
|
---|
80 | #define NS_METHOD_SETTER(_method, _type, _member) \
|
---|
81 | _method(_type aResult) \
|
---|
82 | { \
|
---|
83 | _member = aResult; \
|
---|
84 | return NS_OK; \
|
---|
85 | }
|
---|
86 |
|
---|
87 | /*
|
---|
88 | * special for strings to get/set char* strings
|
---|
89 | * using PL_strdup and PR_FREEIF
|
---|
90 | */
|
---|
91 | #define NS_METHOD_GETTER_STR(_method,_member) \
|
---|
92 | _method(char* *aString) \
|
---|
93 | { \
|
---|
94 | if (!aString) return NS_ERROR_NULL_POINTER; \
|
---|
95 | if (!(*aString = PL_strdup(_member))) \
|
---|
96 | return NS_ERROR_OUT_OF_MEMORY; \
|
---|
97 | return NS_OK; \
|
---|
98 | }
|
---|
99 |
|
---|
100 | #define NS_METHOD_SETTER_STR(_method, _member) \
|
---|
101 | _method(const char *aString) \
|
---|
102 | { \
|
---|
103 | if (_member) PR_Free(_member); \
|
---|
104 | if (!aString) \
|
---|
105 | _member = nsnull; \
|
---|
106 | else if (!(_member = PL_strdup(aString))) \
|
---|
107 | return NS_ERROR_OUT_OF_MEMORY; \
|
---|
108 | return NS_OK; \
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* Getter/Setter macros.
|
---|
112 | Usage:
|
---|
113 | NS_IMPL_[CLASS_]GETTER[_<type>](method, [type,] member);
|
---|
114 | NS_IMPL_[CLASS_]SETTER[_<type>](method, [type,] member);
|
---|
115 | NS_IMPL_[CLASS_]GETSET[_<type>]([class, ]postfix, [type,] member);
|
---|
116 |
|
---|
117 | where:
|
---|
118 | CLASS_ - implementation is inside a class definition
|
---|
119 | (otherwise the class name is needed)
|
---|
120 | Do NOT use in publicly exported header files, because
|
---|
121 | the implementation may be included many times over.
|
---|
122 | Instead, use the non-CLASS_ version.
|
---|
123 | _<type> - For more complex (STR, IFACE) data types
|
---|
124 | (otherwise the simple data type is needed)
|
---|
125 | method - name of the method, such as GetWidth or SetColor
|
---|
126 | type - simple data type if required
|
---|
127 | member - class member variable such as m_width or mColor
|
---|
128 | class - the class name, such as Window or MyObject
|
---|
129 | postfix - Method part after Get/Set such as "Width" for "GetWidth"
|
---|
130 |
|
---|
131 | Example:
|
---|
132 | class Window {
|
---|
133 | public:
|
---|
134 | NS_IMPL_CLASS_GETSET(Width, int, m_width);
|
---|
135 | NS_IMPL_CLASS_GETTER_STR(GetColor, m_color);
|
---|
136 | NS_IMETHOD SetColor(char *color);
|
---|
137 |
|
---|
138 | private:
|
---|
139 | int m_width; // read/write
|
---|
140 | char *m_color; // readonly
|
---|
141 | };
|
---|
142 |
|
---|
143 | // defined outside of class
|
---|
144 | NS_IMPL_SETTER_STR(Window::GetColor, m_color);
|
---|
145 |
|
---|
146 | Questions/Comments to [email protected]
|
---|
147 | */
|
---|
148 |
|
---|
149 |
|
---|
150 | /*
|
---|
151 | * Getter/Setter implementation within a class definition
|
---|
152 | */
|
---|
153 |
|
---|
154 | /* simple data types */
|
---|
155 | #define NS_IMPL_CLASS_GETTER(_method, _type, _member) \
|
---|
156 | NS_IMETHOD NS_METHOD_GETTER(_method, _type, _member)
|
---|
157 |
|
---|
158 | #define NS_IMPL_CLASS_SETTER(_method, _type, _member) \
|
---|
159 | NS_IMETHOD NS_METHOD_SETTER(_method, _type, _member)
|
---|
160 |
|
---|
161 | #define NS_IMPL_CLASS_GETSET(_postfix, _type, _member) \
|
---|
162 | NS_IMPL_CLASS_GETTER(Get##_postfix, _type, _member) \
|
---|
163 | NS_IMPL_CLASS_SETTER(Set##_postfix, _type, _member)
|
---|
164 |
|
---|
165 | /* strings */
|
---|
166 | #define NS_IMPL_CLASS_GETTER_STR(_method, _member) \
|
---|
167 | NS_IMETHOD NS_METHOD_GETTER_STR(_method, _member)
|
---|
168 |
|
---|
169 | #define NS_IMPL_CLASS_SETTER_STR(_method, _member) \
|
---|
170 | NS_IMETHOD NS_METHOD_SETTER_STR(_method, _member)
|
---|
171 |
|
---|
172 | #define NS_IMPL_CLASS_GETSET_STR(_postfix, _member) \
|
---|
173 | NS_IMPL_CLASS_GETTER_STR(Get##_postfix, _member) \
|
---|
174 | NS_IMPL_CLASS_SETTER_STR(Set##_postfix, _member)
|
---|
175 |
|
---|
176 | /* Getter/Setter implementation outside of a class definition */
|
---|
177 |
|
---|
178 | /* simple data types */
|
---|
179 | #define NS_IMPL_GETTER(_method, _type, _member) \
|
---|
180 | NS_IMETHODIMP NS_METHOD_GETTER(_method, _type, _member)
|
---|
181 |
|
---|
182 | #define NS_IMPL_SETTER(_method, _type, _member) \
|
---|
183 | NS_IMETHODIMP NS_METHOD_SETTER(_method, _type, _member)
|
---|
184 |
|
---|
185 | #define NS_IMPL_GETSET(_class, _postfix, _type, _member) \
|
---|
186 | NS_IMPL_GETTER(_class::Get##_postfix, _type, _member) \
|
---|
187 | NS_IMPL_SETTER(_class::Set##_postfix, _type, _member)
|
---|
188 |
|
---|
189 | /* strings */
|
---|
190 | #define NS_IMPL_GETTER_STR(_method, _member) \
|
---|
191 | NS_IMETHODIMP NS_METHOD_GETTER_STR(_method, _member)
|
---|
192 |
|
---|
193 | #define NS_IMPL_SETTER_STR(_method, _member) \
|
---|
194 | NS_IMETHODIMP NS_METHOD_SETTER_STR(_method, _member)
|
---|
195 |
|
---|
196 | #define NS_IMPL_GETSET_STR(_class, _postfix, _member) \
|
---|
197 | NS_IMPL_GETTER_STR(_class::Get##_postfix, _member) \
|
---|
198 | NS_IMPL_SETTER_STR(_class::Set##_postfix, _member)
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * IID for the nsIsThreadsafe interface
|
---|
202 | * {88210890-47a6-11d2-bec3-00805f8a66dc}
|
---|
203 | *
|
---|
204 | * This interface is *only* used for debugging purposes to determine if
|
---|
205 | * a given component is threadsafe.
|
---|
206 | */
|
---|
207 | #define NS_ISTHREADSAFE_IID \
|
---|
208 | { 0x88210890, 0x47a6, 0x11d2, \
|
---|
209 | {0xbe, 0xc3, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
---|
210 |
|
---|
211 | #define NS_LOCK_INSTANCE() \
|
---|
212 | PR_CEnterMonitor((void*)this)
|
---|
213 | #define NS_UNLOCK_INSTANCE() \
|
---|
214 | PR_CExitMonitor((void*)this)
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * This implements query interface with two assumptions: First, the
|
---|
218 | * class in question implements nsISupports and its own interface and
|
---|
219 | * nothing else. Second, the implementation of the class's primary
|
---|
220 | * inheritance chain leads to its own interface.
|
---|
221 | *
|
---|
222 | * @param _class The name of the class implementing the method
|
---|
223 | * @param _classiiddef The name of the #define symbol that defines the IID
|
---|
224 | * for the class (e.g. NS_ISUPPORTS_IID)
|
---|
225 | */
|
---|
226 | #if defined(NS_DEBUG)
|
---|
227 | #define NS_VERIFY_THREADSAFE_INTERFACE(_iface) \
|
---|
228 | if (NULL != (_iface)) { \
|
---|
229 | nsISupports* tmp; \
|
---|
230 | static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID); \
|
---|
231 | NS_PRECONDITION((NS_OK == _iface->QueryInterface(kIsThreadsafeIID, \
|
---|
232 | (void**)&tmp)), \
|
---|
233 | "Interface is not threadsafe"); \
|
---|
234 | }
|
---|
235 | #else
|
---|
236 | #define NS_VERIFY_THREADSAFE_INTERFACE(_iface)
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | ////////////////////////////////////////////////////////////////////////////////
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 | #endif
|
---|