Implemented NtQueueApcThread, and changed the server APC interface to
[wine] / server / device.c
1 /*
2  * Server-side device management
3  *
4  * Copyright (C) 1999 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 /*
22  * FIXME:
23  * all this stuff is a simple hack to avoid breaking
24  * client-side device support.
25  */
26
27 #include <assert.h>
28 #include <fcntl.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "winbase.h"
34
35 #include "handle.h"
36 #include "thread.h"
37 #include "request.h"
38
39 struct device
40 {
41     struct object  obj;             /* object header */
42     int            id;              /* client identifier */
43 };
44
45 static void device_dump( struct object *obj, int verbose );
46
47 static const struct object_ops device_ops =
48 {
49     sizeof(struct device),    /* size */
50     device_dump,              /* dump */
51     no_add_queue,             /* add_queue */
52     NULL,                     /* remove_queue */
53     NULL,                     /* signaled */
54     NULL,                     /* satisfied */
55     no_get_fd,                /* get_fd */
56     no_destroy                /* destroy */
57 };
58
59 static struct device *create_device( int id )
60 {
61     struct device *dev;
62     if ((dev = alloc_object( &device_ops )))
63     {
64         dev->id = id;
65     }
66     return dev;
67 }
68
69 static void device_dump( struct object *obj, int verbose )
70 {
71     struct device *dev = (struct device *)obj;
72     assert( obj->ops == &device_ops );
73     fprintf( stderr, "Device id=%08x\n", dev->id );
74 }
75
76 /* create a device */
77 DECL_HANDLER(create_device)
78 {
79     struct device *dev;
80
81     reply->handle = 0;
82     if ((dev = create_device( req->id )))
83     {
84         reply->handle = alloc_handle( current->process, dev, req->access, req->inherit );
85         release_object( dev );
86     }
87 }
88
89
90 /* Retrieve the client private id for a device */
91 DECL_HANDLER(get_device_id)
92 {
93     struct device *dev;
94
95     if ((dev = (struct device *)get_handle_obj( current->process, req->handle, 0, &device_ops )))
96     {
97         reply->id = dev->id;
98         release_object( dev );
99     }
100 }