blob: 0e23b18c3d01fe81468093626833b3d4186fe497 [file] [log] [blame]
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001/*
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>
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000015#include "server.h"
Alexandre Julliard767e6f61998-08-09 12:47:43 +000016
Alexandre Julliard1bdd1541999-06-04 19:47:04 +000017#define DEBUG_OBJECTS
18
Alexandre Julliard767e6f61998-08-09 12:47:43 +000019/* kernel objects */
20
21struct object;
22struct object_name;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000023struct thread;
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +000024struct process;
Alexandre Julliarda8b8d9c1999-01-01 16:59:27 +000025struct file;
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000026struct wait_queue_entry;
Alexandre Julliard767e6f61998-08-09 12:47:43 +000027
Alexandre Julliard05625391999-01-03 11:55:56 +000028/* operations valid on all objects */
Alexandre Julliard767e6f61998-08-09 12:47:43 +000029struct object_ops
30{
Alexandre Julliard5bc78081999-06-22 17:26:53 +000031 /* size of this object type */
32 size_t size;
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000033 /* dump the object (for debugging) */
34 void (*dump)(struct object *,int);
35 /* add a thread to the object wait queue */
Alexandre Julliarda8b8d9c1999-01-01 16:59:27 +000036 int (*add_queue)(struct object *,struct wait_queue_entry *);
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000037 /* 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 *);
Alexandre Julliardaa0ebd01998-12-30 12:06:45 +000043 /* 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 */
Alexandre Julliard05625391999-01-03 11:55:56 +000048 int (*flush)(struct object *);
49 /* get file information */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000050 int (*get_file_info)(struct object *,struct get_file_info_request *);
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000051 /* destroy on refcount == 0 */
52 void (*destroy)(struct object *);
Alexandre Julliard767e6f61998-08-09 12:47:43 +000053};
54
55struct object
56{
57 unsigned int refcount;
58 const struct object_ops *ops;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000059 struct wait_queue_entry *head;
60 struct wait_queue_entry *tail;
Alexandre Julliard767e6f61998-08-09 12:47:43 +000061 struct object_name *name;
Alexandre Julliard1bdd1541999-06-04 19:47:04 +000062#ifdef DEBUG_OBJECTS
63 struct object *prev;
64 struct object *next;
65#endif
Alexandre Julliard767e6f61998-08-09 12:47:43 +000066};
67
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000068extern void *mem_alloc( size_t size ); /* malloc wrapper */
Alexandre Julliard5bc78081999-06-22 17:26:53 +000069extern char *mem_strdup( const char *str );
70extern void *alloc_object( const struct object_ops *ops );
Alexandre Julliard05625391999-01-03 11:55:56 +000071extern const char *get_object_name( struct object *obj );
Alexandre Julliard5bc78081999-06-22 17:26:53 +000072extern void *create_named_object( const struct object_ops *ops, const char *name, size_t len );
Alexandre Julliard767e6f61998-08-09 12:47:43 +000073/* grab/release_object can take any pointer, but you better make sure */
74/* that the thing pointed to starts with a struct object... */
75extern struct object *grab_object( void *obj );
76extern void release_object( void *obj );
Alexandre Julliard5bc78081999-06-22 17:26:53 +000077extern struct object *find_object( const char *name, size_t len );
Alexandre Julliarda8b8d9c1999-01-01 16:59:27 +000078extern int no_add_queue( struct object *obj, struct wait_queue_entry *entry );
Alexandre Julliardaa0ebd01998-12-30 12:06:45 +000079extern int no_satisfied( struct object *obj, struct thread *thread );
80extern int no_read_fd( struct object *obj );
81extern int no_write_fd( struct object *obj );
82extern int no_flush( struct object *obj );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000083extern int no_get_file_info( struct object *obj, struct get_file_info_request *info );
Alexandre Julliard5bc78081999-06-22 17:26:53 +000084extern void no_destroy( struct object *obj );
Alexandre Julliard88de35c1999-05-16 16:57:49 +000085extern void default_select_event( int event, void *private );
Alexandre Julliard1bdd1541999-06-04 19:47:04 +000086#ifdef DEBUG_OBJECTS
87extern void dump_objects(void);
88#endif
Alexandre Julliard767e6f61998-08-09 12:47:43 +000089
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000090/* select functions */
91
92#define READ_EVENT 1
93#define WRITE_EVENT 2
94
Alexandre Julliard88de35c1999-05-16 16:57:49 +000095struct select_user
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +000096{
Alexandre Julliard88de35c1999-05-16 16:57:49 +000097 int fd; /* user fd */
98 void (*func)(int event, void *private); /* callback function */
99 void *private; /* callback private data */
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +0000100};
101
Alexandre Julliard88de35c1999-05-16 16:57:49 +0000102extern void register_select_user( struct select_user *user );
103extern void unregister_select_user( struct select_user *user );
104extern void set_select_events( struct select_user *user, int events );
105extern int check_select_events( struct select_user *user, int events );
Alexandre Julliardc6e45ed1998-12-27 08:35:39 +0000106extern void select_loop(void);
107
Alexandre Julliard88de35c1999-05-16 16:57:49 +0000108/* timeout functions */
109
110struct timeout_user;
111
112typedef void (*timeout_callback)( void *private );
113
114extern struct timeout_user *add_timeout_user( struct timeval *when,
115 timeout_callback func, void *private );
116extern void remove_timeout_user( struct timeout_user *user );
117extern void make_timeout( struct timeval *when, int timeout );
118
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000119/* socket functions */
120
Alexandre Julliard88de35c1999-05-16 16:57:49 +0000121struct client;
122
123extern struct client *add_client( int client_fd, struct thread *self );
124extern void remove_client( struct client *client, int exit_code );
Alexandre Julliard5bc78081999-06-22 17:26:53 +0000125extern void client_pass_fd( struct client *client, int pass_fd );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000126extern void client_reply( struct client *client, unsigned int res );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000127
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000128/* mutex functions */
129
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000130extern void abandon_mutexes( struct thread *thread );
131
Alexandre Julliard338e7571998-12-27 15:28:54 +0000132/* file functions */
133
Alexandre Julliarda8b8d9c1999-01-01 16:59:27 +0000134extern struct file *get_file_obj( struct process *process, int handle,
135 unsigned int access );
136extern int file_get_mmap_fd( struct file *file );
Alexandre Julliardcb28bdc1999-02-28 10:13:59 +0000137extern int grow_file( struct file *file, int size_high, int size_low );
Alexandre Julliard5bc78081999-06-22 17:26:53 +0000138extern int create_anonymous_file(void);
Alexandre Julliardcb28bdc1999-02-28 10:13:59 +0000139extern struct file *create_temp_file( int access );
Alexandre Julliardaa0ebd01998-12-30 12:06:45 +0000140extern void file_set_error(void);
141
Alexandre Julliardaa0ebd01998-12-30 12:06:45 +0000142/* console functions */
143
Alexandre Julliard039aa421999-06-11 18:31:22 +0000144extern int alloc_console( struct process *process );
145extern int free_console( struct process *process );
Alexandre Julliardfdc92ba1999-02-14 18:03:15 +0000146
Alexandre Julliarde712e071999-05-23 19:53:30 +0000147/* debugger functions */
148
149extern int debugger_attach( struct process *process, struct thread *debugger );
150extern void debug_exit_thread( struct thread *thread, int exit_code );
151
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000152extern int debug_level;
153
154#endif /* __WINE_SERVER_OBJECT_H */