blob: 4183b75a2b84d8d2379184c4813397fbdeb4f5fa [file] [log] [blame]
Alexandre Julliardf727b431999-01-19 16:31:32 +00001/*
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
Michael Vekslerf935c591999-02-09 15:49:39 +000019#include "winbase.h"
Alexandre Julliard43c190e1999-05-15 10:48:19 +000020
21#include "handle.h"
22#include "thread.h"
Alexandre Julliard5bc78081999-06-22 17:26:53 +000023#include "request.h"
Alexandre Julliardf727b431999-01-19 16:31:32 +000024
25struct device
26{
27 struct object obj; /* object header */
28 int id; /* client identifier */
29};
30
31static void device_dump( struct object *obj, int verbose );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000032static int device_get_info( struct object *obj, struct get_file_info_request *req );
Alexandre Julliardf727b431999-01-19 16:31:32 +000033
34static const struct object_ops device_ops =
35{
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000036 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 */
Alexandre Julliard1ab243b2000-12-19 02:12:45 +000044 no_get_fd, /* get_fd */
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000045 no_flush, /* flush */
46 device_get_info, /* get_file_info */
47 no_destroy /* destroy */
Alexandre Julliardf727b431999-01-19 16:31:32 +000048};
49
Alexandre Julliard5bc78081999-06-22 17:26:53 +000050static struct device *create_device( int id )
Alexandre Julliardf727b431999-01-19 16:31:32 +000051{
52 struct device *dev;
Alexandre Julliard1dca5e22000-01-01 00:56:27 +000053 if ((dev = alloc_object( &device_ops, -1 )))
Alexandre Julliard5bc78081999-06-22 17:26:53 +000054 {
55 dev->id = id;
56 }
57 return dev;
Alexandre Julliardf727b431999-01-19 16:31:32 +000058}
59
60static void device_dump( struct object *obj, int verbose )
61{
62 struct device *dev = (struct device *)obj;
63 assert( obj->ops == &device_ops );
64 fprintf( stderr, "Device id=%08x\n", dev->id );
65}
66
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000067static int device_get_info( struct object *obj, struct get_file_info_request *req )
Alexandre Julliardf727b431999-01-19 16:31:32 +000068{
69 struct device *dev = (struct device *)obj;
70 assert( obj->ops == &device_ops );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000071 req->type = FILE_TYPE_UNKNOWN;
72 req->attr = dev->id; /* hack! */
73 req->access_time = 0;
74 req->write_time = 0;
75 req->size_high = 0;
76 req->size_low = 0;
77 req->links = 0;
78 req->index_high = 0;
79 req->index_low = 0;
80 req->serial = 0;
Alexandre Julliardf727b431999-01-19 16:31:32 +000081 return 1;
82}
83
Alexandre Julliard43c190e1999-05-15 10:48:19 +000084/* create a device */
85DECL_HANDLER(create_device)
86{
Alexandre Julliard5bc78081999-06-22 17:26:53 +000087 struct device *dev;
Alexandre Julliard43c190e1999-05-15 10:48:19 +000088
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000089 req->handle = -1;
Alexandre Julliard5bc78081999-06-22 17:26:53 +000090 if ((dev = create_device( req->id )))
Alexandre Julliard43c190e1999-05-15 10:48:19 +000091 {
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000092 req->handle = alloc_handle( current->process, dev, req->access, req->inherit );
Alexandre Julliard5bc78081999-06-22 17:26:53 +000093 release_object( dev );
Alexandre Julliard43c190e1999-05-15 10:48:19 +000094 }
Alexandre Julliard43c190e1999-05-15 10:48:19 +000095}