Added support for AZERTY keyboard layout.
[wine/hacks.git] / server / event.c
blobf259b9096971407241a87246593379a983a2be6b
1 /*
2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include "winnt.h"
13 #include "handle.h"
14 #include "thread.h"
15 #include "request.h"
17 struct event
19 struct object obj; /* object header */
20 int manual_reset; /* is it a manual reset event? */
21 int signaled; /* event has been signaled */
24 static void event_dump( struct object *obj, int verbose );
25 static int event_signaled( struct object *obj, struct thread *thread );
26 static int event_satisfied( struct object *obj, struct thread *thread );
28 static const struct object_ops event_ops =
30 sizeof(struct event), /* size */
31 event_dump, /* dump */
32 add_queue, /* add_queue */
33 remove_queue, /* remove_queue */
34 event_signaled, /* signaled */
35 event_satisfied, /* satisfied */
36 NULL, /* get_poll_events */
37 NULL, /* poll_event */
38 no_read_fd, /* get_read_fd */
39 no_write_fd, /* get_write_fd */
40 no_flush, /* flush */
41 no_get_file_info, /* get_file_info */
42 no_destroy /* destroy */
46 struct event *create_event( const WCHAR *name, size_t len,
47 int manual_reset, int initial_state )
49 struct event *event;
51 if ((event = create_named_object( &event_ops, name, len )))
53 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
55 /* initialize it if it didn't already exist */
56 event->manual_reset = manual_reset;
57 event->signaled = initial_state;
60 return event;
63 struct event *get_event_obj( struct process *process, int handle, unsigned int access )
65 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
68 void pulse_event( struct event *event )
70 event->signaled = 1;
71 /* wake up all waiters if manual reset, a single one otherwise */
72 wake_up( &event->obj, !event->manual_reset );
73 event->signaled = 0;
76 void set_event( struct event *event )
78 event->signaled = 1;
79 /* wake up all waiters if manual reset, a single one otherwise */
80 wake_up( &event->obj, !event->manual_reset );
83 void reset_event( struct event *event )
85 event->signaled = 0;
88 static void event_dump( struct object *obj, int verbose )
90 struct event *event = (struct event *)obj;
91 assert( obj->ops == &event_ops );
92 fprintf( stderr, "Event manual=%d signaled=%d ",
93 event->manual_reset, event->signaled );
94 dump_object_name( &event->obj );
95 fputc( '\n', stderr );
98 static int event_signaled( struct object *obj, struct thread *thread )
100 struct event *event = (struct event *)obj;
101 assert( obj->ops == &event_ops );
102 return event->signaled;
105 static int event_satisfied( struct object *obj, struct thread *thread )
107 struct event *event = (struct event *)obj;
108 assert( obj->ops == &event_ops );
109 /* Reset if it's an auto-reset event */
110 if (!event->manual_reset) event->signaled = 0;
111 return 0; /* Not abandoned */
114 /* create an event */
115 DECL_HANDLER(create_event)
117 struct event *event;
119 req->handle = -1;
120 if ((event = create_event( get_req_data(req), get_req_data_size(req),
121 req->manual_reset, req->initial_state )))
123 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
124 release_object( event );
128 /* open a handle to an event */
129 DECL_HANDLER(open_event)
131 req->handle = open_object( get_req_data(req), get_req_data_size(req),
132 &event_ops, req->access, req->inherit );
135 /* do an event operation */
136 DECL_HANDLER(event_op)
138 struct event *event;
140 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
141 switch(req->op)
143 case PULSE_EVENT:
144 pulse_event( event );
145 break;
146 case SET_EVENT:
147 set_event( event );
148 break;
149 case RESET_EVENT:
150 reset_event( event );
151 break;
152 default:
153 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
155 release_object( event );