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