resource.h revision 4642e01f
105b261ecSmrg/***********************************************************
205b261ecSmrg
305b261ecSmrgCopyright 1987, 1989, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included in
1205b261ecSmrgall copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2005b261ecSmrg
2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be
2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings
2305b261ecSmrgin this Software without prior written authorization from The Open Group.
2405b261ecSmrg
2505b261ecSmrg
2605b261ecSmrgCopyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
2705b261ecSmrg
2805b261ecSmrg                        All Rights Reserved
2905b261ecSmrg
3005b261ecSmrgPermission to use, copy, modify, and distribute this software and its
3105b261ecSmrgdocumentation for any purpose and without fee is hereby granted,
3205b261ecSmrgprovided that the above copyright notice appear in all copies and that
3305b261ecSmrgboth that copyright notice and this permission notice appear in
3405b261ecSmrgsupporting documentation, and that the name of Digital not be
3505b261ecSmrgused in advertising or publicity pertaining to distribution of the
3605b261ecSmrgsoftware without specific, written prior permission.
3705b261ecSmrg
3805b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
3905b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
4005b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
4105b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
4205b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
4305b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
4405b261ecSmrgSOFTWARE.
4505b261ecSmrg
4605b261ecSmrg******************************************************************/
4705b261ecSmrg
4805b261ecSmrg#ifndef RESOURCE_H
4905b261ecSmrg#define RESOURCE_H 1
5005b261ecSmrg#include "misc.h"
514642e01fSmrg#include "dixaccess.h"
5205b261ecSmrg
5305b261ecSmrg/*****************************************************************
5405b261ecSmrg * STUFF FOR RESOURCES
5505b261ecSmrg *****************************************************************/
5605b261ecSmrg
5705b261ecSmrg/* classes for Resource routines */
5805b261ecSmrg
5905b261ecSmrgtypedef unsigned long RESTYPE;
6005b261ecSmrg
6105b261ecSmrg#define RC_VANILLA	((RESTYPE)0)
6205b261ecSmrg#define RC_CACHED	((RESTYPE)1<<31)
6305b261ecSmrg#define RC_DRAWABLE	((RESTYPE)1<<30)
6405b261ecSmrg/*  Use class RC_NEVERRETAIN for resources that should not be retained
6505b261ecSmrg *  regardless of the close down mode when the client dies.  (A client's
6605b261ecSmrg *  event selections on objects that it doesn't own are good candidates.)
6705b261ecSmrg *  Extensions can use this too!
6805b261ecSmrg */
6905b261ecSmrg#define RC_NEVERRETAIN	((RESTYPE)1<<29)
7005b261ecSmrg#define RC_LASTPREDEF	RC_NEVERRETAIN
7105b261ecSmrg#define RC_ANY		(~(RESTYPE)0)
7205b261ecSmrg
7305b261ecSmrg/* types for Resource routines */
7405b261ecSmrg
754642e01fSmrg#define RT_WINDOW	((RESTYPE)1|RC_DRAWABLE)
764642e01fSmrg#define RT_PIXMAP	((RESTYPE)2|RC_DRAWABLE)
774642e01fSmrg#define RT_GC		((RESTYPE)3)
7805b261ecSmrg#undef RT_FONT
7905b261ecSmrg#undef RT_CURSOR
8005b261ecSmrg#define RT_FONT		((RESTYPE)4)
8105b261ecSmrg#define RT_CURSOR	((RESTYPE)5)
8205b261ecSmrg#define RT_COLORMAP	((RESTYPE)6)
8305b261ecSmrg#define RT_CMAPENTRY	((RESTYPE)7)
8405b261ecSmrg#define RT_OTHERCLIENT	((RESTYPE)8|RC_NEVERRETAIN)
8505b261ecSmrg#define RT_PASSIVEGRAB	((RESTYPE)9|RC_NEVERRETAIN)
8605b261ecSmrg#define RT_LASTPREDEF	((RESTYPE)9)
8705b261ecSmrg#define RT_NONE		((RESTYPE)0)
8805b261ecSmrg
8905b261ecSmrg/* bits and fields within a resource id */
9005b261ecSmrg#define RESOURCE_AND_CLIENT_COUNT   29			/* 29 bits for XIDs */
9105b261ecSmrg#if MAXCLIENTS == 64
9205b261ecSmrg#define RESOURCE_CLIENT_BITS	6
9305b261ecSmrg#endif
9405b261ecSmrg#if MAXCLIENTS == 128
9505b261ecSmrg#define RESOURCE_CLIENT_BITS	7
9605b261ecSmrg#endif
9705b261ecSmrg#if MAXCLIENTS == 256
9805b261ecSmrg#define RESOURCE_CLIENT_BITS	8
9905b261ecSmrg#endif
10005b261ecSmrg#if MAXCLIENTS == 512
10105b261ecSmrg#define RESOURCE_CLIENT_BITS	9
10205b261ecSmrg#endif
10305b261ecSmrg/* client field offset */
10405b261ecSmrg#define CLIENTOFFSET	    (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS)
10505b261ecSmrg/* resource field */
10605b261ecSmrg#define RESOURCE_ID_MASK	((1 << CLIENTOFFSET) - 1)
10705b261ecSmrg/* client field */
10805b261ecSmrg#define RESOURCE_CLIENT_MASK	(((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET)
10905b261ecSmrg/* extract the client mask from an XID */
11005b261ecSmrg#define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
11105b261ecSmrg/* extract the client id from an XID */
11205b261ecSmrg#define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
11305b261ecSmrg#define SERVER_BIT		(Mask)0x40000000	/* use illegal bit */
11405b261ecSmrg
11505b261ecSmrg#ifdef INVALID
11605b261ecSmrg#undef INVALID	/* needed on HP/UX */
11705b261ecSmrg#endif
11805b261ecSmrg
11905b261ecSmrg/* Invalid resource id */
12005b261ecSmrg#define INVALID	(0)
12105b261ecSmrg
12205b261ecSmrg#define BAD_RESOURCE 0xe0000000
12305b261ecSmrg
1244642e01fSmrg/* Resource state callback */
1254642e01fSmrgextern CallbackListPtr ResourceStateCallback;
1264642e01fSmrg
1274642e01fSmrgtypedef enum {ResourceStateAdding,
1284642e01fSmrg	      ResourceStateFreeing} ResourceState;
1294642e01fSmrg
1304642e01fSmrgtypedef struct {
1314642e01fSmrg    ResourceState state;
1324642e01fSmrg    XID id;
1334642e01fSmrg    RESTYPE type;
1344642e01fSmrg    pointer value;
1354642e01fSmrg} ResourceStateInfoRec;
1364642e01fSmrg
13705b261ecSmrgtypedef int (*DeleteType)(
13805b261ecSmrg    pointer /*value*/,
13905b261ecSmrg    XID /*id*/);
14005b261ecSmrg
14105b261ecSmrgtypedef void (*FindResType)(
14205b261ecSmrg    pointer /*value*/,
14305b261ecSmrg    XID /*id*/,
14405b261ecSmrg    pointer /*cdata*/);
14505b261ecSmrg
14605b261ecSmrgtypedef void (*FindAllRes)(
14705b261ecSmrg    pointer /*value*/,
14805b261ecSmrg    XID /*id*/,
14905b261ecSmrg    RESTYPE /*type*/,
15005b261ecSmrg    pointer /*cdata*/);
15105b261ecSmrg
15205b261ecSmrgtypedef Bool (*FindComplexResType)(
15305b261ecSmrg    pointer /*value*/,
15405b261ecSmrg    XID /*id*/,
15505b261ecSmrg    pointer /*cdata*/);
15605b261ecSmrg
15705b261ecSmrgextern RESTYPE CreateNewResourceType(
15805b261ecSmrg    DeleteType /*deleteFunc*/);
15905b261ecSmrg
16005b261ecSmrgextern RESTYPE CreateNewResourceClass(void);
16105b261ecSmrg
16205b261ecSmrgextern Bool InitClientResources(
16305b261ecSmrg    ClientPtr /*client*/);
16405b261ecSmrg
16505b261ecSmrgextern XID FakeClientID(
16605b261ecSmrg    int /*client*/);
16705b261ecSmrg
16805b261ecSmrg/* Quartz support on Mac OS X uses the CarbonCore
16905b261ecSmrg   framework whose AddResource function conflicts here. */
1704642e01fSmrg#ifdef __APPLE__
17105b261ecSmrg#define AddResource Darwin_X_AddResource
17205b261ecSmrg#endif
17305b261ecSmrgextern Bool AddResource(
17405b261ecSmrg    XID /*id*/,
17505b261ecSmrg    RESTYPE /*type*/,
17605b261ecSmrg    pointer /*value*/);
17705b261ecSmrg
17805b261ecSmrgextern void FreeResource(
17905b261ecSmrg    XID /*id*/,
18005b261ecSmrg    RESTYPE /*skipDeleteFuncType*/);
18105b261ecSmrg
18205b261ecSmrgextern void FreeResourceByType(
18305b261ecSmrg    XID /*id*/,
18405b261ecSmrg    RESTYPE /*type*/,
18505b261ecSmrg    Bool /*skipFree*/);
18605b261ecSmrg
18705b261ecSmrgextern Bool ChangeResourceValue(
18805b261ecSmrg    XID /*id*/,
18905b261ecSmrg    RESTYPE /*rtype*/,
19005b261ecSmrg    pointer /*value*/);
19105b261ecSmrg
19205b261ecSmrgextern void FindClientResourcesByType(
19305b261ecSmrg    ClientPtr /*client*/,
19405b261ecSmrg    RESTYPE /*type*/,
19505b261ecSmrg    FindResType /*func*/,
19605b261ecSmrg    pointer /*cdata*/);
19705b261ecSmrg
19805b261ecSmrgextern void FindAllClientResources(
19905b261ecSmrg    ClientPtr /*client*/,
20005b261ecSmrg    FindAllRes /*func*/,
20105b261ecSmrg    pointer /*cdata*/);
20205b261ecSmrg
20305b261ecSmrgextern void FreeClientNeverRetainResources(
20405b261ecSmrg    ClientPtr /*client*/);
20505b261ecSmrg
20605b261ecSmrgextern void FreeClientResources(
20705b261ecSmrg    ClientPtr /*client*/);
20805b261ecSmrg
20905b261ecSmrgextern void FreeAllResources(void);
21005b261ecSmrg
21105b261ecSmrgextern Bool LegalNewID(
21205b261ecSmrg    XID /*id*/,
21305b261ecSmrg    ClientPtr /*client*/);
21405b261ecSmrg
21505b261ecSmrgextern pointer LookupClientResourceComplex(
21605b261ecSmrg    ClientPtr client,
21705b261ecSmrg    RESTYPE type,
21805b261ecSmrg    FindComplexResType func,
21905b261ecSmrg    pointer cdata);
22005b261ecSmrg
2214642e01fSmrgextern int dixLookupResource(
2224642e01fSmrg    pointer *result,
2234642e01fSmrg    XID id,
2244642e01fSmrg    RESTYPE rtype,
2254642e01fSmrg    ClientPtr client,
2264642e01fSmrg    Mask access_mode);
22705b261ecSmrg
22805b261ecSmrgextern void GetXIDRange(
22905b261ecSmrg    int /*client*/,
23005b261ecSmrg    Bool /*server*/,
23105b261ecSmrg    XID * /*minp*/,
23205b261ecSmrg    XID * /*maxp*/);
23305b261ecSmrg
23405b261ecSmrgextern unsigned int GetXIDList(
23505b261ecSmrg    ClientPtr /*client*/,
23605b261ecSmrg    unsigned int /*count*/,
23705b261ecSmrg    XID * /*pids*/);
23805b261ecSmrg
23905b261ecSmrgextern RESTYPE lastResourceType;
24005b261ecSmrgextern RESTYPE TypeMask;
24105b261ecSmrg
2424642e01fSmrg/*
2434642e01fSmrg * These are deprecated compatibility functions and will be removed soon!
2444642e01fSmrg * Please use the noted replacements instead.
2454642e01fSmrg */
2464642e01fSmrg
2474642e01fSmrg/* replaced by dixLookupResource */
2484642e01fSmrgextern pointer SecurityLookupIDByType(
2494642e01fSmrg    ClientPtr client,
2504642e01fSmrg    XID id,
2514642e01fSmrg    RESTYPE rtype,
2524642e01fSmrg    Mask access_mode);
2534642e01fSmrg
2544642e01fSmrg/* replaced by dixLookupResource */
2554642e01fSmrgextern pointer SecurityLookupIDByClass(
2564642e01fSmrg    ClientPtr client,
2574642e01fSmrg    XID id,
2584642e01fSmrg    RESTYPE classes,
2594642e01fSmrg    Mask access_mode);
2604642e01fSmrg
2614642e01fSmrg/* replaced by dixLookupResource */
2624642e01fSmrgextern pointer LookupIDByType(
2634642e01fSmrg    XID id,
2644642e01fSmrg    RESTYPE rtype);
2654642e01fSmrg
2664642e01fSmrg/* replaced by dixLookupResource */
2674642e01fSmrgextern pointer LookupIDByClass(
2684642e01fSmrg    XID id,
2694642e01fSmrg    RESTYPE classes);
27005b261ecSmrg
27105b261ecSmrg#endif /* RESOURCE_H */
27205b261ecSmrg
273