Reimplemented multi-byte and wide-chars functions to not depend on
[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 char *mem_strdup( const char *str );
70 extern void *alloc_object( const struct object_ops *ops );
71 extern const char *get_object_name( struct object *obj );
72 extern void *create_named_object( const struct object_ops *ops, const char *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 char *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
95 struct select_user
96 {
97     int    fd;                              /* user fd */
98     void (*func)(int event, void *private); /* callback function */
99     void  *private;                         /* callback private data */
100 };
101
102 extern void register_select_user( struct select_user *user );
103 extern void unregister_select_user( struct select_user *user );
104 extern void set_select_events( struct select_user *user, int events );
105 extern int check_select_events( struct select_user *user, int events );
106 extern void select_loop(void);
107
108 /* timeout functions */
109
110 struct timeout_user;
111
112 typedef void (*timeout_callback)( void *private );
113
114 extern struct timeout_user *add_timeout_user( struct timeval *when,
115                                               timeout_callback func, void *private );
116 extern void remove_timeout_user( struct timeout_user *user );
117 extern void make_timeout( struct timeval *when, int timeout );
118
119 /* socket functions */
120
121 struct client;
122
123 extern struct client *add_client( int client_fd, struct thread *self );
124 extern void remove_client( struct client *client, int exit_code );
125 extern void client_pass_fd( struct client *client, int pass_fd );
126 extern void client_reply( struct client *client, unsigned int res );
127
128 /* mutex functions */
129
130 extern void abandon_mutexes( struct thread *thread );
131
132 /* file functions */
133
134 extern struct file *get_file_obj( struct process *process, int handle,
135                                   unsigned int access );
136 extern int file_get_mmap_fd( struct file *file );
137 extern int grow_file( struct file *file, int size_high, int size_low );
138 extern int create_anonymous_file(void);
139 extern struct file *create_temp_file( int access );
140 extern void file_set_error(void);
141
142 /* console functions */
143
144 extern int alloc_console( struct process *process );
145 extern int free_console( struct process *process );
146
147 /* debugger functions */
148
149 extern int debugger_attach( struct process *process, struct thread *debugger );
150 extern void debug_exit_thread( struct thread *thread, int exit_code );
151
152 extern int debug_level;
153
154 #endif  /* __WINE_SERVER_OBJECT_H */