Made all 16<->32 HWND conversions use explicit functions instead of
[wine/multimedia.git] / server / event.c
blobb7652fb8616048dc9de51b7367c6538bfb0c228c
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_get_fd, /* get_fd */
39 no_flush, /* flush */
40 no_get_file_info, /* get_file_info */
41 no_destroy /* destroy */
45 struct event *create_event( const WCHAR *name, size_t len,
46 int manual_reset, int initial_state )
48 struct event *event;
50 if ((event = create_named_object( &event_ops, name, len )))
52 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
54 /* initialize it if it didn't already exist */
55 event->manual_reset = manual_reset;
56 event->signaled = initial_state;
59 return event;
62 struct event *get_event_obj( struct process *process, handle_t handle, unsigned int access )
64 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
67 void pulse_event( struct event *event )
69 event->signaled = 1;
70 /* wake up all waiters if manual reset, a single one otherwise */
71 wake_up( &event->obj, !event->manual_reset );
72 event->signaled = 0;
75 void set_event( struct event *event )
77 event->signaled = 1;
78 /* wake up all waiters if manual reset, a single one otherwise */
79 wake_up( &event->obj, !event->manual_reset );
82 void reset_event( struct event *event )
84 event->signaled = 0;
87 static void event_dump( struct object *obj, int verbose )
89 struct event *event = (struct event *)obj;
90 assert( obj->ops == &event_ops );
91 fprintf( stderr, "Event manual=%d signaled=%d ",
92 event->manual_reset, event->signaled );
93 dump_object_name( &event->obj );
94 fputc( '\n', stderr );
97 static int event_signaled( struct object *obj, struct thread *thread )
99 struct event *event = (struct event *)obj;
100 assert( obj->ops == &event_ops );
101 return event->signaled;
104 static int event_satisfied( struct object *obj, struct thread *thread )
106 struct event *event = (struct event *)obj;
107 assert( obj->ops == &event_ops );
108 /* Reset if it's an auto-reset event */
109 if (!event->manual_reset) event->signaled = 0;
110 return 0; /* Not abandoned */
113 /* create an event */
114 DECL_HANDLER(create_event)
116 struct event *event;
118 req->handle = 0;
119 if ((event = create_event( get_req_data(req), get_req_data_size(req),
120 req->manual_reset, req->initial_state )))
122 req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
123 release_object( event );
127 /* open a handle to an event */
128 DECL_HANDLER(open_event)
130 req->handle = open_object( get_req_data(req), get_req_data_size(req),
131 &event_ops, req->access, req->inherit );
134 /* do an event operation */
135 DECL_HANDLER(event_op)
137 struct event *event;
139 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
140 switch(req->op)
142 case PULSE_EVENT:
143 pulse_event( event );
144 break;
145 case SET_EVENT:
146 set_event( event );
147 break;
148 case RESET_EVENT:
149 reset_event( event );
150 break;
151 default:
152 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
154 release_object( event );