VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/1.5/xorg/privates.h@ 9233

Last change on this file since 9233 was 9233, checked in by vboxsync, 17 years ago

Additions/x11: added header files for X.org server 1.5

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.8 KB
Line 
1/***********************************************************
2
3THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
7AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
10******************************************************************/
11
12#ifndef PRIVATES_H
13#define PRIVATES_H 1
14
15#include "dix.h"
16#include "resource.h"
17
18/*****************************************************************
19 * STUFF FOR PRIVATES
20 *****************************************************************/
21
22typedef void *DevPrivateKey;
23
24typedef struct _Private {
25 DevPrivateKey key;
26 pointer value;
27 struct _Private *next;
28} PrivateRec;
29
30/*
31 * Request pre-allocated private space for your driver/module.
32 * Calling this is not necessary if only a pointer by itself is needed.
33 */
34extern int
35dixRequestPrivate(const DevPrivateKey key, unsigned size);
36
37/*
38 * Allocates a new private and attaches it to an existing object.
39 */
40extern pointer *
41dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
42
43/*
44 * Look up a private pointer.
45 */
46static _X_INLINE pointer
47dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
48{
49 PrivateRec *rec = *privates;
50 pointer *ptr;
51
52 while (rec) {
53 if (rec->key == key)
54 return rec->value;
55 rec = rec->next;
56 }
57
58 ptr = dixAllocatePrivate(privates, key);
59 return ptr ? *ptr : NULL;
60}
61
62/*
63 * Look up the address of a private pointer.
64 */
65static _X_INLINE pointer *
66dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
67{
68 PrivateRec *rec = *privates;
69
70 while (rec) {
71 if (rec->key == key)
72 return &rec->value;
73 rec = rec->next;
74 }
75
76 return dixAllocatePrivate(privates, key);
77}
78
79/*
80 * Set a private pointer.
81 */
82static _X_INLINE int
83dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
84{
85 PrivateRec *rec;
86
87 top:
88 rec = *privates;
89 while (rec) {
90 if (rec->key == key) {
91 rec->value = val;
92 return TRUE;
93 }
94 rec = rec->next;
95 }
96
97 if (!dixAllocatePrivate(privates, key))
98 return FALSE;
99 goto top;
100}
101
102/*
103 * Register callbacks to be called on private allocation/freeing.
104 * The calldata argument to the callbacks is a PrivateCallbackPtr.
105 */
106typedef struct _PrivateCallback {
107 DevPrivateKey key; /* private registration key */
108 pointer *value; /* address of private pointer */
109} PrivateCallbackRec;
110
111extern int
112dixRegisterPrivateInitFunc(const DevPrivateKey key,
113 CallbackProcPtr callback, pointer userdata);
114
115extern int
116dixRegisterPrivateDeleteFunc(const DevPrivateKey key,
117 CallbackProcPtr callback, pointer userdata);
118
119/*
120 * Frees private data.
121 */
122extern void
123dixFreePrivates(PrivateRec *privates);
124
125/*
126 * Resets the subsystem, called from the main loop.
127 */
128extern int
129dixResetPrivates(void);
130
131/*
132 * These next two functions are necessary because the position of
133 * the devPrivates field varies by structure and calling code might
134 * only know the resource type, not the structure definition.
135 */
136
137/*
138 * Looks up the offset where the devPrivates field is located.
139 * Returns -1 if no offset has been registered for the resource type.
140 */
141extern int
142dixLookupPrivateOffset(RESTYPE type);
143
144/*
145 * Specifies the offset where the devPrivates field is located.
146 * A negative value indicates no devPrivates field is available.
147 */
148extern int
149dixRegisterPrivateOffset(RESTYPE type, int offset);
150
151/*
152 * Convenience macro for adding an offset to an object pointer
153 * when making a call to one of the devPrivates functions
154 */
155#define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
156
157#endif /* PRIVATES_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette