Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /*********************************************************** |
2 | ||
3 | Copyright 1987, 1989, 1998 The Open Group | |
4 | ||
5 | Permission to use, copy, modify, distribute, and sell this software and its | |
6 | documentation for any purpose is hereby granted without fee, provided that | |
7 | the above copyright notice appear in all copies and that both that | |
8 | copyright notice and this permission notice appear in supporting | |
9 | documentation. | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |
18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
20 | ||
21 | Except as contained in this notice, the name of The Open Group shall not be | |
22 | used in advertising or otherwise to promote the sale, use or other dealings | |
23 | in this Software without prior written authorization from The Open Group. | |
24 | ||
25 | Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. | |
26 | ||
27 | All Rights Reserved | |
28 | ||
29 | Permission to use, copy, modify, and distribute this software and its | |
30 | documentation for any purpose and without fee is hereby granted, | |
31 | provided that the above copyright notice appear in all copies and that | |
32 | both that copyright notice and this permission notice appear in | |
33 | supporting documentation, and that the name of Digital not be | |
34 | used in advertising or publicity pertaining to distribution of the | |
35 | software without specific, written prior permission. | |
36 | ||
37 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
38 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
39 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |
40 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
41 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
42 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
43 | SOFTWARE. | |
44 | ||
45 | ******************************************************************/ | |
46 | ||
47 | #ifndef RESOURCE_H | |
48 | #define RESOURCE_H 1 | |
49 | #include "misc.h" | |
50 | #include "dixaccess.h" | |
51 | ||
52 | /***************************************************************** | |
53 | * STUFF FOR RESOURCES | |
54 | *****************************************************************/ | |
55 | ||
56 | /* classes for Resource routines */ | |
57 | ||
58 | typedef uint32_t RESTYPE; | |
59 | ||
60 | #define RC_VANILLA ((RESTYPE)0) | |
61 | #define RC_CACHED ((RESTYPE)1<<31) | |
62 | #define RC_DRAWABLE ((RESTYPE)1<<30) | |
63 | /* Use class RC_NEVERRETAIN for resources that should not be retained | |
64 | * regardless of the close down mode when the client dies. (A client's | |
65 | * event selections on objects that it doesn't own are good candidates.) | |
66 | * Extensions can use this too! | |
67 | */ | |
68 | #define RC_NEVERRETAIN ((RESTYPE)1<<29) | |
69 | #define RC_LASTPREDEF RC_NEVERRETAIN | |
70 | #define RC_ANY (~(RESTYPE)0) | |
71 | ||
72 | /* types for Resource routines */ | |
73 | ||
74 | #define RT_WINDOW ((RESTYPE)1|RC_DRAWABLE) | |
75 | #define RT_PIXMAP ((RESTYPE)2|RC_DRAWABLE) | |
76 | #define RT_GC ((RESTYPE)3) | |
77 | #undef RT_FONT | |
78 | #undef RT_CURSOR | |
79 | #define RT_FONT ((RESTYPE)4) | |
80 | #define RT_CURSOR ((RESTYPE)5) | |
81 | #define RT_COLORMAP ((RESTYPE)6) | |
82 | #define RT_CMAPENTRY ((RESTYPE)7) | |
83 | #define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN) | |
84 | #define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN) | |
85 | #define RT_LASTPREDEF ((RESTYPE)9) | |
86 | #define RT_NONE ((RESTYPE)0) | |
87 | ||
88 | /* bits and fields within a resource id */ | |
89 | #define RESOURCE_AND_CLIENT_COUNT 29 /* 29 bits for XIDs */ | |
90 | #if MAXCLIENTS == 64 | |
91 | #define RESOURCE_CLIENT_BITS 6 | |
92 | #endif | |
93 | #if MAXCLIENTS == 128 | |
94 | #define RESOURCE_CLIENT_BITS 7 | |
95 | #endif | |
96 | #if MAXCLIENTS == 256 | |
97 | #define RESOURCE_CLIENT_BITS 8 | |
98 | #endif | |
99 | #if MAXCLIENTS == 512 | |
100 | #define RESOURCE_CLIENT_BITS 9 | |
101 | #endif | |
102 | /* client field offset */ | |
103 | #define CLIENTOFFSET (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS) | |
104 | /* resource field */ | |
105 | #define RESOURCE_ID_MASK ((1 << CLIENTOFFSET) - 1) | |
106 | /* client field */ | |
107 | #define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET) | |
108 | /* extract the client mask from an XID */ | |
109 | #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK) | |
110 | /* extract the client id from an XID */ | |
111 | #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET)) | |
112 | #define SERVER_BIT (Mask)0x40000000 /* use illegal bit */ | |
113 | ||
114 | #ifdef INVALID | |
115 | #undef INVALID /* needed on HP/UX */ | |
116 | #endif | |
117 | ||
118 | /* Invalid resource id */ | |
119 | #define INVALID (0) | |
120 | ||
121 | #define BAD_RESOURCE 0xe0000000 | |
122 | ||
123 | #define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) | |
124 | ||
125 | /* Resource state callback */ | |
126 | extern _X_EXPORT CallbackListPtr ResourceStateCallback; | |
127 | ||
128 | typedef enum { ResourceStateAdding, | |
129 | ResourceStateFreeing | |
130 | } ResourceState; | |
131 | ||
132 | typedef struct { | |
133 | ResourceState state; | |
134 | XID id; | |
135 | RESTYPE type; | |
136 | pointer value; | |
137 | } ResourceStateInfoRec; | |
138 | ||
139 | typedef int (*DeleteType) (pointer /*value */ , | |
140 | XID /*id */ ); | |
141 | ||
142 | typedef void (*FindResType) (pointer /*value */ , | |
143 | XID /*id */ , | |
144 | pointer /*cdata */ ); | |
145 | ||
146 | typedef void (*FindAllRes) (pointer /*value */ , | |
147 | XID /*id */ , | |
148 | RESTYPE /*type */ , | |
149 | pointer /*cdata */ ); | |
150 | ||
151 | typedef Bool (*FindComplexResType) (pointer /*value */ , | |
152 | XID /*id */ , | |
153 | pointer /*cdata */ ); | |
154 | ||
155 | /* Structure for estimating resource memory usage. Memory usage | |
156 | * consists of space allocated for the resource itself and of | |
157 | * references to other resources. Currently the most important use for | |
158 | * this structure is to estimate pixmap usage of different resources | |
159 | * more accurately. */ | |
160 | typedef struct { | |
161 | /* Size of resource itself. Zero if not implemented. */ | |
162 | unsigned long resourceSize; | |
163 | /* Size attributed to pixmap references from the resource. */ | |
164 | unsigned long pixmapRefSize; | |
165 | /* Number of references to this resource; typically 1 */ | |
166 | unsigned long refCnt; | |
167 | } ResourceSizeRec, *ResourceSizePtr; | |
168 | ||
169 | typedef void (*SizeType)(pointer /*value*/, | |
170 | XID /*id*/, | |
171 | ResourceSizePtr /*size*/); | |
172 | ||
173 | extern _X_EXPORT RESTYPE CreateNewResourceType(DeleteType /*deleteFunc */ , | |
174 | const char * /*name */ ); | |
175 | ||
176 | typedef void (*FindTypeSubResources)(pointer /* value */, | |
177 | FindAllRes /* func */, | |
178 | pointer /* cdata */); | |
179 | ||
180 | extern _X_EXPORT SizeType GetResourceTypeSizeFunc( | |
181 | RESTYPE /*type*/); | |
182 | ||
183 | extern _X_EXPORT void SetResourceTypeFindSubResFunc( | |
184 | RESTYPE /*type*/, FindTypeSubResources /*findFunc*/); | |
185 | ||
186 | extern _X_EXPORT void SetResourceTypeSizeFunc( | |
187 | RESTYPE /*type*/, SizeType /*sizeFunc*/); | |
188 | ||
189 | extern _X_EXPORT void SetResourceTypeErrorValue( | |
190 | RESTYPE /*type*/, int /*errorValue*/); | |
191 | ||
192 | extern _X_EXPORT RESTYPE CreateNewResourceClass(void); | |
193 | ||
194 | extern _X_EXPORT Bool InitClientResources(ClientPtr /*client */ ); | |
195 | ||
196 | extern _X_EXPORT XID FakeClientID(int /*client */ ); | |
197 | ||
198 | /* Quartz support on Mac OS X uses the CarbonCore | |
199 | framework whose AddResource function conflicts here. */ | |
200 | #ifdef __APPLE__ | |
201 | #define AddResource Darwin_X_AddResource | |
202 | #endif | |
203 | extern _X_EXPORT Bool AddResource(XID /*id */ , | |
204 | RESTYPE /*type */ , | |
205 | pointer /*value */ ); | |
206 | ||
207 | extern _X_EXPORT void FreeResource(XID /*id */ , | |
208 | RESTYPE /*skipDeleteFuncType */ ); | |
209 | ||
210 | extern _X_EXPORT void FreeResourceByType(XID /*id */ , | |
211 | RESTYPE /*type */ , | |
212 | Bool /*skipFree */ ); | |
213 | ||
214 | extern _X_EXPORT Bool ChangeResourceValue(XID /*id */ , | |
215 | RESTYPE /*rtype */ , | |
216 | pointer /*value */ ); | |
217 | ||
218 | extern _X_EXPORT void FindClientResourcesByType(ClientPtr /*client */ , | |
219 | RESTYPE /*type */ , | |
220 | FindResType /*func */ , | |
221 | pointer /*cdata */ ); | |
222 | ||
223 | extern _X_EXPORT void FindAllClientResources(ClientPtr /*client */ , | |
224 | FindAllRes /*func */ , | |
225 | pointer /*cdata */ ); | |
226 | ||
227 | /** @brief Iterate through all subresources of a resource. | |
228 | ||
229 | @note The XID argument provided to the FindAllRes function | |
230 | may be 0 for subresources that don't have an XID */ | |
231 | extern _X_EXPORT void FindSubResources(pointer /*resource*/, | |
232 | RESTYPE /*type*/, | |
233 | FindAllRes /*func*/, | |
234 | pointer /*cdata*/); | |
235 | ||
236 | extern _X_EXPORT void FreeClientNeverRetainResources(ClientPtr /*client */ ); | |
237 | ||
238 | extern _X_EXPORT void FreeClientResources(ClientPtr /*client */ ); | |
239 | ||
240 | extern _X_EXPORT void FreeAllResources(void); | |
241 | ||
242 | extern _X_EXPORT Bool LegalNewID(XID /*id */ , | |
243 | ClientPtr /*client */ ); | |
244 | ||
245 | extern _X_EXPORT pointer LookupClientResourceComplex(ClientPtr client, | |
246 | RESTYPE type, | |
247 | FindComplexResType func, | |
248 | pointer cdata); | |
249 | ||
250 | extern _X_EXPORT int dixLookupResourceByType(pointer *result, | |
251 | XID id, | |
252 | RESTYPE rtype, | |
253 | ClientPtr client, | |
254 | Mask access_mode); | |
255 | ||
256 | extern _X_EXPORT int dixLookupResourceByClass(pointer *result, | |
257 | XID id, | |
258 | RESTYPE rclass, | |
259 | ClientPtr client, | |
260 | Mask access_mode); | |
261 | ||
262 | extern _X_EXPORT void GetXIDRange(int /*client */ , | |
263 | Bool /*server */ , | |
264 | XID * /*minp */ , | |
265 | XID * /*maxp */ ); | |
266 | ||
267 | extern _X_EXPORT unsigned int GetXIDList(ClientPtr /*client */ , | |
268 | unsigned int /*count */ , | |
269 | XID * /*pids */ ); | |
270 | ||
271 | extern _X_EXPORT RESTYPE lastResourceType; | |
272 | extern _X_EXPORT RESTYPE TypeMask; | |
273 | ||
274 | /** @brief A hashing function to be used for hashing resource IDs | |
275 | ||
276 | @param id The resource ID to hash | |
277 | @param numBits The number of bits in the resulting hash. Must be >=0. | |
278 | ||
279 | @note This function is really only for handling | |
280 | INITHASHSIZE..MAXHASHSIZE bit hashes, but will handle any number | |
281 | of bits by either masking numBits lower bits of the ID or by | |
282 | providing at most MAXHASHSIZE hashes. | |
283 | */ | |
284 | extern _X_EXPORT int HashResourceID(XID id, | |
285 | int numBits); | |
286 | ||
287 | #endif /* RESOURCE_H */ |