Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 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 | |
Michael Veksler | f935c59 | 1999-02-09 15:49:39 +0000 | [diff] [blame] | 19 | #include "winbase.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 20 | |
| 21 | #include "handle.h" |
| 22 | #include "thread.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 23 | #include "request.h" |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 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 ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 32 | static int device_get_info( struct object *obj, struct get_file_info_request *req ); |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 33 | |
| 34 | static const struct object_ops device_ops = |
| 35 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 44 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 45 | no_flush, /* flush */ |
| 46 | device_get_info, /* get_file_info */ |
| 47 | no_destroy /* destroy */ |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 50 | static struct device *create_device( int id ) |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 51 | { |
| 52 | struct device *dev; |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 53 | if ((dev = alloc_object( &device_ops, -1 ))) |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 54 | { |
| 55 | dev->id = id; |
| 56 | } |
| 57 | return dev; |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static 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 Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 67 | static int device_get_info( struct object *obj, struct get_file_info_request *req ) |
Alexandre Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 68 | { |
| 69 | struct device *dev = (struct device *)obj; |
| 70 | assert( obj->ops == &device_ops ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 71 | 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 Julliard | f727b43 | 1999-01-19 16:31:32 +0000 | [diff] [blame] | 81 | return 1; |
| 82 | } |
| 83 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 84 | /* create a device */ |
| 85 | DECL_HANDLER(create_device) |
| 86 | { |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 87 | struct device *dev; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 88 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 89 | req->handle = -1; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 90 | if ((dev = create_device( req->id ))) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 91 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 92 | req->handle = alloc_handle( current->process, dev, req->access, req->inherit ); |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 93 | release_object( dev ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 94 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 95 | } |