1 | /***********************************************************
|
---|
2 |
|
---|
3 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
4 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
5 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
6 | AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
---|
7 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
---|
8 | CONNECTION 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 |
|
---|
22 | typedef int *DevPrivateKey;
|
---|
23 | struct _Private;
|
---|
24 | typedef struct _Private PrivateRec;
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * Request pre-allocated private space for your driver/module.
|
---|
28 | * Calling this is not necessary if only a pointer by itself is needed.
|
---|
29 | */
|
---|
30 | extern _X_EXPORT int
|
---|
31 | dixRequestPrivate(const DevPrivateKey key, unsigned size);
|
---|
32 |
|
---|
33 | /*
|
---|
34 | * Allocates a new private and attaches it to an existing object.
|
---|
35 | */
|
---|
36 | extern _X_EXPORT pointer *
|
---|
37 | dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * Look up a private pointer.
|
---|
41 | */
|
---|
42 | extern _X_EXPORT pointer
|
---|
43 | dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
|
---|
44 |
|
---|
45 | /*
|
---|
46 | * Look up the address of a private pointer.
|
---|
47 | */
|
---|
48 | extern _X_EXPORT pointer *
|
---|
49 | dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key);
|
---|
50 |
|
---|
51 | /*
|
---|
52 | * Set a private pointer.
|
---|
53 | */
|
---|
54 | extern _X_EXPORT int
|
---|
55 | dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val);
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * Register callbacks to be called on private allocation/freeing.
|
---|
59 | * The calldata argument to the callbacks is a PrivateCallbackPtr.
|
---|
60 | */
|
---|
61 | typedef struct _PrivateCallback {
|
---|
62 | DevPrivateKey key; /* private registration key */
|
---|
63 | pointer *value; /* address of private pointer */
|
---|
64 | } PrivateCallbackRec;
|
---|
65 |
|
---|
66 | extern _X_EXPORT int
|
---|
67 | dixRegisterPrivateInitFunc(const DevPrivateKey key,
|
---|
68 | CallbackProcPtr callback, pointer userdata);
|
---|
69 |
|
---|
70 | extern _X_EXPORT int
|
---|
71 | dixRegisterPrivateDeleteFunc(const DevPrivateKey key,
|
---|
72 | CallbackProcPtr callback, pointer userdata);
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * Frees private data.
|
---|
76 | */
|
---|
77 | extern _X_EXPORT void
|
---|
78 | dixFreePrivates(PrivateRec *privates);
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * Resets the subsystem, called from the main loop.
|
---|
82 | */
|
---|
83 | extern _X_EXPORT int
|
---|
84 | dixResetPrivates(void);
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * These next two functions are necessary because the position of
|
---|
88 | * the devPrivates field varies by structure and calling code might
|
---|
89 | * only know the resource type, not the structure definition.
|
---|
90 | */
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * Looks up the offset where the devPrivates field is located.
|
---|
94 | * Returns -1 if no offset has been registered for the resource type.
|
---|
95 | */
|
---|
96 | extern _X_EXPORT int
|
---|
97 | dixLookupPrivateOffset(RESTYPE type);
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Specifies the offset where the devPrivates field is located.
|
---|
101 | * A negative value indicates no devPrivates field is available.
|
---|
102 | */
|
---|
103 | extern _X_EXPORT int
|
---|
104 | dixRegisterPrivateOffset(RESTYPE type, int offset);
|
---|
105 |
|
---|
106 | /*
|
---|
107 | * Convenience macro for adding an offset to an object pointer
|
---|
108 | * when making a call to one of the devPrivates functions
|
---|
109 | */
|
---|
110 | #define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
|
---|
111 |
|
---|
112 | #endif /* PRIVATES_H */
|
---|