1 /* $XConsortium: resource.h /main/23 1996/10/30 11:18:23 rws $ */ 2 /*********************************************************** 3 4 Copyright (c) 1987, 1989 X Consortium 5 6 Permission is hereby granted, free of charge, to any person obtaining a copy 7 of this software and associated documentation files (the "Software"), to deal 8 in the Software without restriction, including without limitation the rights 9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 copies of the Software, and to permit persons to whom the Software is 11 furnished to do so, subject to the following conditions: 12 13 The above copyright notice and this permission notice shall be included in 14 all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23 Except as contained in this notice, the name of the X Consortium shall not be 24 used in advertising or otherwise to promote the sale, use or other dealings 25 in this Software without prior written authorization from the X Consortium. 26 27 28 Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 29 30 All Rights Reserved 31 32 Permission to use, copy, modify, and distribute this software and its 33 documentation for any purpose and without fee is hereby granted, 34 provided that the above copyright notice appear in all copies and that 35 both that copyright notice and this permission notice appear in 36 supporting documentation, and that the name of Digital not be 37 used in advertising or publicity pertaining to distribution of the 38 software without specific, written prior permission. 39 40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 46 SOFTWARE. 47 48 ******************************************************************/ 49 #ifndef RESOURCE_H 50 #define RESOURCE_H 1 51 #include "misc.h" 52 53 /***************************************************************** 54 * STUFF FOR RESOURCES 55 *****************************************************************/ 56 57 /* classes for Resource routines */ 58 59 typedef 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_CACHED|RC_DRAWABLE) 76 #define RT_PIXMAP ((RESTYPE)2|RC_CACHED|RC_DRAWABLE) 77 #define RT_GC ((RESTYPE)3|RC_CACHED) 78 #define RT_FONT ((RESTYPE)4) 79 #define RT_CURSOR ((RESTYPE)5) 80 #define RT_COLORMAP ((RESTYPE)6) 81 #define RT_CMAPENTRY ((RESTYPE)7) 82 #define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN) 83 #define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN) 84 #define RT_LASTPREDEF ((RESTYPE)9) 85 #define RT_NONE ((RESTYPE)0) 86 87 /* bits and fields within a resource id */ 88 #define CLIENTOFFSET 22 /* client field */ 89 #define RESOURCE_ID_MASK 0x3FFFFF /* low 22 bits */ 90 #define CLIENT_BITS(id) ((id) & 0x1fc00000) /* hi 7 bits */ 91 #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET)) 92 #define SERVER_BIT 0x20000000 /* use illegal bit */ 93 94 #ifdef INVALID 95 #undef INVALID /* needed on HP/UX */ 96 #endif 97 98 /* Invalid resource id */ 99 #define INVALID (0) 100 101 #define BAD_RESOURCE 0xe0000000 102 103 typedef int (*DeleteType)( 104 #if NeedNestedPrototypes 105 pointer /*value*/, 106 XID /*id*/ 107 #endif 108 ); 109 110 typedef void (*FindResType)( 111 #if NeedNestedPrototypes 112 pointer /*value*/, 113 XID /*id*/, 114 pointer /*cdata*/ 115 #endif 116 ); 117 118 extern RESTYPE CreateNewResourceType( 119 #if NeedFunctionPrototypes 120 DeleteType /*deleteFunc*/ 121 #endif 122 ); 123 124 extern RESTYPE CreateNewResourceClass( 125 #if NeedFunctionPrototypes 126 void 127 #endif 128 ); 129 130 extern Bool InitClientResources( 131 #if NeedFunctionPrototypes 132 ClientPtr /*client*/ 133 #endif 134 ); 135 136 extern XID FakeClientID( 137 #if NeedFunctionPrototypes 138 int /*client*/ 139 #endif 140 ); 141 142 extern Bool AddResource( 143 #if NeedFunctionPrototypes 144 XID /*id*/, 145 RESTYPE /*type*/, 146 pointer /*value*/ 147 #endif 148 ); 149 150 extern void FreeResource( 151 #if NeedFunctionPrototypes 152 XID /*id*/, 153 RESTYPE /*skipDeleteFuncType*/ 154 #endif 155 ); 156 157 extern void FreeResourceByType( 158 #if NeedFunctionPrototypes 159 XID /*id*/, 160 RESTYPE /*type*/, 161 Bool /*skipFree*/ 162 #endif 163 ); 164 165 extern Bool ChangeResourceValue( 166 #if NeedFunctionPrototypes 167 XID /*id*/, 168 RESTYPE /*rtype*/, 169 pointer /*value*/ 170 #endif 171 ); 172 173 extern void FindClientResourcesByType( 174 #if NeedFunctionPrototypes 175 ClientPtr /*client*/, 176 RESTYPE /*type*/, 177 FindResType /*func*/, 178 pointer /*cdata*/ 179 #endif 180 ); 181 182 extern void FreeClientNeverRetainResources( 183 #if NeedFunctionPrototypes 184 ClientPtr /*client*/ 185 #endif 186 ); 187 188 extern void FreeClientResources( 189 #if NeedFunctionPrototypes 190 ClientPtr /*client*/ 191 #endif 192 ); 193 194 extern void FreeAllResources( 195 #if NeedFunctionPrototypes 196 void 197 #endif 198 ); 199 200 extern Bool LegalNewID( 201 #if NeedFunctionPrototypes 202 XID /*id*/, 203 ClientPtr /*client*/ 204 #endif 205 ); 206 207 extern pointer LookupIDByType( 208 #if NeedFunctionPrototypes 209 XID /*id*/, 210 RESTYPE /*rtype*/ 211 #endif 212 ); 213 214 extern pointer LookupIDByClass( 215 #if NeedFunctionPrototypes 216 XID /*id*/, 217 RESTYPE /*classes*/ 218 #endif 219 ); 220 221 /* These are the access modes that can be passed in the last parameter 222 * to SecurityLookupIDByType/Class. The Security extension doesn't 223 * currently make much use of these; they're mainly provided as an 224 * example of what you might need for discretionary access control. 225 * You can or these values together to indicate multiple modes 226 * simultaneously. 227 */ 228 229 #define SecurityUnknownAccess 0 /* don't know intentions */ 230 #define SecurityReadAccess (1<<0) /* inspecting the object */ 231 #define SecurityWriteAccess (1<<1) /* changing the object */ 232 #define SecurityDestroyAccess (1<<2) /* destroying the object */ 233 234 #ifdef XCSECURITY 235 236 extern pointer SecurityLookupIDByType( 237 #if NeedFunctionPrototypes 238 ClientPtr /*client*/, 239 XID /*id*/, 240 RESTYPE /*rtype*/, 241 Mask /*access_mode*/ 242 #endif 243 ); 244 245 extern pointer SecurityLookupIDByClass( 246 #if NeedFunctionPrototypes 247 ClientPtr /*client*/, 248 XID /*id*/, 249 RESTYPE /*classes*/, 250 Mask /*access_mode*/ 251 #endif 252 ); 253 254 #else /* not XCSECURITY */ 255 256 #define SecurityLookupIDByType(client, id, rtype, access_mode) \ 257 LookupIDByType(id, rtype) 258 259 #define SecurityLookupIDByClass(client, id, classes, access_mode) \ 260 LookupIDByClass(id, classes) 261 262 #endif /* XCSECURITY */ 263 264 extern void GetXIDRange( 265 #if NeedFunctionPrototypes 266 int /*client*/, 267 Bool /*server*/, 268 XID * /*minp*/, 269 XID * /*maxp*/ 270 #endif 271 ); 272 273 extern unsigned int GetXIDList( 274 #if NeedFunctionPrototypes 275 ClientPtr /*client*/, 276 unsigned int /*count*/, 277 XID * /*pids*/ 278 #endif 279 ); 280 281 #endif /* RESOURCE_H */ 282 283