Added DebugBreak.
[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 "winerror.h"
20 #include "winbase.h"
21
22 #include "handle.h"
23 #include "thread.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 static void device_destroy( struct object *obj );
34
35 static const struct object_ops device_ops =
36 {
37     device_dump,
38     no_add_queue,
39     NULL,  /* should never get called */
40     NULL,  /* should never get called */
41     NULL,  /* should never get called */
42     no_read_fd,
43     no_write_fd,
44     no_flush,
45     device_get_info,
46     device_destroy
47 };
48
49 static struct object *create_device( int id )
50 {
51     struct device *dev;
52
53     if (!(dev = mem_alloc(sizeof(*dev)))) return NULL;
54     init_object( &dev->obj, &device_ops, NULL );
55     dev->id = id;
56     return &dev->obj;
57 }
58
59 static void device_dump( struct object *obj, int verbose )
60 {
61     struct device *dev = (struct device *)obj;
62     assert( obj->ops == &device_ops );
63     fprintf( stderr, "Device id=%08x\n", dev->id );
64 }
65
66 static int device_get_info( struct object *obj, struct get_file_info_reply *reply )
67 {
68     struct device *dev = (struct device *)obj;
69     assert( obj->ops == &device_ops );
70     memset( reply, 0, sizeof(*reply) );
71     reply->type = FILE_TYPE_UNKNOWN;
72     reply->attr = dev->id;  /* hack! */
73     return 1;
74 }
75
76 static void device_destroy( struct object *obj )
77 {
78     struct device *dev = (struct device *)obj;
79     assert( obj->ops == &device_ops );
80     free( dev );
81 }
82
83 /* create a device */
84 DECL_HANDLER(create_device)
85 {
86     struct object *obj;
87     struct create_device_reply reply = { -1 };
88
89     if ((obj = create_device( req->id )))
90     {
91         reply.handle = alloc_handle( current->process, obj,
92                                      req->access, req->inherit );
93         release_object( obj );
94     }
95     send_reply( current, -1, 1, &reply, sizeof(reply) );
96 }