Implemented waitable timers.
[wine] / server / object.h
1 /*
2  * Wine server objects
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_SERVER_OBJECT_H
8 #define __WINE_SERVER_OBJECT_H
9
10 #ifndef __WINE_SERVER__
11 #error This file can only be used in the Wine server
12 #endif
13
14 #include <sys/time.h>
15 #include "server.h"
16
17 #define DEBUG_OBJECTS
18
19 /* kernel objects */
20
21 struct object;
22 struct object_name;
23 struct thread;
24 struct process;
25 struct file;
26 struct wait_queue_entry;
27
28 /* operations valid on all objects */
29 struct object_ops
30 {
31     /* size of this object type */
32     size_t size;
33     /* dump the object (for debugging) */
34     void (*dump)(struct object *,int);
35     /* add a thread to the object wait queue */
36     int  (*add_queue)(struct object *,struct wait_queue_entry *);
37     /* remove a thread from the object wait queue */
38     void (*remove_queue)(struct object *,struct wait_queue_entry *);
39     /* is object signaled? */
40     int  (*signaled)(struct object *,struct thread *);
41     /* wait satisfied; return 1 if abandoned */
42     int  (*satisfied)(struct object *,struct thread *);
43     /* return a Unix fd that can be used to read from the object */
44     int  (*get_read_fd)(struct object *);
45     /* return a Unix fd that can be used to write to the object */
46     int  (*get_write_fd)(struct object *);
47     /* flush the object buffers */
48     int  (*flush)(struct object *);
49     /* get file information */
50     int  (*get_file_info)(struct object *,struct get_file_info_request *);
51     /* destroy on refcount == 0 */
52     void (*destroy)(struct object *);
53 };
54
55 struct object
56 {
57     unsigned int              refcount;
58     const struct object_ops  *ops;
59     struct wait_queue_entry  *head;
60     struct wait_queue_entry  *tail;
61     struct object_name       *name;
62 #ifdef DEBUG_OBJECTS
63     struct object            *prev;
64     struct object            *next;
65 #endif
66 };
67
68 extern void *mem_alloc( size_t size );  /* malloc wrapper */
69 extern void *memdup( const void *data, size_t len );
70 extern void *alloc_object( const struct object_ops *ops );
71 extern void dump_object_name( struct object *obj );
72 extern void *create_named_object( const struct object_ops *ops, const WCHAR *name, size_t len );
73 /* grab/release_object can take any pointer, but you better make sure */
74 /* that the thing pointed to starts with a struct object... */
75 extern struct object *grab_object( void *obj );
76 extern void release_object( void *obj );
77 extern struct object *find_object( const WCHAR *name, size_t len );
78 extern int no_add_queue( struct object *obj, struct wait_queue_entry *entry );
79 extern int no_satisfied( struct object *obj, struct thread *thread );
80 extern int no_read_fd( struct object *obj );
81 extern int no_write_fd( struct object *obj );
82 extern int no_flush( struct object *obj );
83 extern int no_get_file_info( struct object *obj, struct get_file_info_request *info );
84 extern void no_destroy( struct object *obj );
85 extern void default_select_event( int event, void *private );
86 #ifdef DEBUG_OBJECTS
87 extern void dump_objects(void);
88 #endif
89
90 /* select functions */
91
92 #define READ_EVENT    1
93 #define WRITE_EVENT   2
94 #define EXCEPT_EVENT  4
95
96 struct select_user
97 {
98     int    fd;                              /* user fd */
99     void (*func)(int event, void *private); /* callback function */
100     void  *private;                         /* callback private data */
101 };
102
103 extern void register_select_user( struct select_user *user );
104 extern void unregister_select_user( struct select_user *user );
105 extern void set_select_events( struct select_user *user, int events );
106 extern int check_select_events( struct select_user *user, int events );
107 extern void select_loop(void);
108
109 /* timeout functions */
110
111 struct timeout_user;
112
113 typedef void (*timeout_callback)( void *private );
114
115 extern struct timeout_user *add_timeout_user( struct timeval *when,
116                                               timeout_callback func, void *private );
117 extern void remove_timeout_user( struct timeout_user *user );
118 extern void make_timeout( struct timeval *when, int timeout );
119
120 /* socket functions */
121
122 struct client;
123
124 extern struct client *add_client( int client_fd, struct thread *self );
125 extern void remove_client( struct client *client, int exit_code );
126 extern void client_pass_fd( struct client *client, int pass_fd );
127 extern void client_reply( struct client *client, unsigned int res );
128
129 /* event functions */
130
131 struct event;
132
133 extern struct event *get_event_obj( struct process *process, int handle, unsigned int access );
134 extern void pulse_event( struct event *event );
135 extern void set_event( struct event *event );
136 extern void reset_event( struct event *event );
137
138 /* mutex functions */
139
140 extern void abandon_mutexes( struct thread *thread );
141
142 /* file functions */
143
144 extern struct file *get_file_obj( struct process *process, int handle,
145                                   unsigned int access );
146 extern int file_get_mmap_fd( struct file *file );
147 extern int grow_file( struct file *file, int size_high, int size_low );
148 extern int create_anonymous_file(void);
149 extern struct file *create_temp_file( int access );
150 extern void file_set_error(void);
151
152 /* console functions */
153
154 extern int alloc_console( struct process *process );
155 extern int free_console( struct process *process );
156
157 /* debugger functions */
158
159 extern int debugger_attach( struct process *process, struct thread *debugger );
160 extern void debug_exit_thread( struct thread *thread, int exit_code );
161
162 /* mapping functions */
163
164 extern int get_page_size(void);
165
166 /* registry functions */
167
168 extern void close_registry(void);
169
170 extern int debug_level;
171
172 #endif  /* __WINE_SERVER_OBJECT_H */