Save the registry before exiting on a SIGTERM.
[wine] / server / device.c
1 /*
2  * Server-side device management
3  *
4  * Copyright (C) 1999 Alexandre Julliard
5  */
6
7 /*
8  * FIXME:
9  * all this stuff is a simple hack to avoid breaking
10  * client-side device support.
11  */
12
13 #include <assert.h>
14 #include <fcntl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include "winbase.h"
20
21 #include "handle.h"
22 #include "thread.h"
23 #include "request.h"
24
25 struct device
26 {
27     struct object  obj;             /* object header */
28     int            id;              /* client identifier */
29 };
30
31 static void device_dump( struct object *obj, int verbose );
32 static int device_get_info( struct object *obj, struct get_file_info_reply *reply );
33
34 static const struct object_ops device_ops =
35 {
36     sizeof(struct device),    /* size */
37     device_dump,              /* dump */
38     no_add_queue,             /* add_queue */
39     NULL,                     /* remove_queue */
40     NULL,                     /* signaled */
41     NULL,                     /* satisfied */
42     NULL,                     /* get_poll_events */
43     NULL,                     /* poll_event */
44     no_get_fd,                /* get_fd */
45     no_flush,                 /* flush */
46     device_get_info,          /* get_file_info */
47     NULL,                     /* queue_async */
48     no_destroy                /* destroy */
49 };
50
51 static struct device *create_device( int id )
52 {
53     struct device *dev;
54     if ((dev = alloc_object( &device_ops, -1 )))
55     {
56         dev->id = id;
57     }
58     return dev;
59 }
60
61 static void device_dump( struct object *obj, int verbose )
62 {
63     struct device *dev = (struct device *)obj;
64     assert( obj->ops == &device_ops );
65     fprintf( stderr, "Device id=%08x\n", dev->id );
66 }
67
68 static int device_get_info( struct object *obj, struct get_file_info_reply *reply )
69 {
70     struct device *dev = (struct device *)obj;
71     assert( obj->ops == &device_ops );
72
73     if (reply)
74     {
75         reply->type        = FILE_TYPE_UNKNOWN;
76         reply->attr        = dev->id;  /* hack! */
77         reply->access_time = 0;
78         reply->write_time  = 0;
79         reply->size_high   = 0;
80         reply->size_low    = 0;
81         reply->links       = 0;
82         reply->index_high  = 0;
83         reply->index_low   = 0;
84         reply->serial      = 0;
85     }
86     return FD_TYPE_DEFAULT;
87 }
88
89 /* create a device */
90 DECL_HANDLER(create_device)
91 {
92     struct device *dev;
93
94     reply->handle = 0;
95     if ((dev = create_device( req->id )))
96     {
97         reply->handle = alloc_handle( current->process, dev, req->access, req->inherit );
98         release_object( dev );
99     }
100 }