Move the name directive from the .spec file to the Makefile.
[wine/gsoc_dplay.git] / server / event.c
blob020c70ca535634632cd9594973455d8b0225829a
1 /*
2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include "winnt.h"
30 #include "handle.h"
31 #include "thread.h"
32 #include "request.h"
34 struct event
36 struct object obj; /* object header */
37 int manual_reset; /* is it a manual reset event? */
38 int signaled; /* event has been signaled */
41 static void event_dump( struct object *obj, int verbose );
42 static int event_signaled( struct object *obj, struct thread *thread );
43 static int event_satisfied( struct object *obj, struct thread *thread );
45 static const struct object_ops event_ops =
47 sizeof(struct event), /* size */
48 event_dump, /* dump */
49 add_queue, /* add_queue */
50 remove_queue, /* remove_queue */
51 event_signaled, /* signaled */
52 event_satisfied, /* satisfied */
53 NULL, /* get_poll_events */
54 NULL, /* poll_event */
55 no_get_fd, /* get_fd */
56 no_flush, /* flush */
57 no_get_file_info, /* get_file_info */
58 NULL, /* queue_async */
59 no_destroy /* destroy */
63 struct event *create_event( const WCHAR *name, size_t len,
64 int manual_reset, int initial_state )
66 struct event *event;
68 if ((event = create_named_object( &event_ops, name, len )))
70 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
72 /* initialize it if it didn't already exist */
73 event->manual_reset = manual_reset;
74 event->signaled = initial_state;
77 return event;
80 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
82 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
85 void pulse_event( struct event *event )
87 event->signaled = 1;
88 /* wake up all waiters if manual reset, a single one otherwise */
89 wake_up( &event->obj, !event->manual_reset );
90 event->signaled = 0;
93 void set_event( struct event *event )
95 event->signaled = 1;
96 /* wake up all waiters if manual reset, a single one otherwise */
97 wake_up( &event->obj, !event->manual_reset );
100 void reset_event( struct event *event )
102 event->signaled = 0;
105 static void event_dump( struct object *obj, int verbose )
107 struct event *event = (struct event *)obj;
108 assert( obj->ops == &event_ops );
109 fprintf( stderr, "Event manual=%d signaled=%d ",
110 event->manual_reset, event->signaled );
111 dump_object_name( &event->obj );
112 fputc( '\n', stderr );
115 static int event_signaled( struct object *obj, struct thread *thread )
117 struct event *event = (struct event *)obj;
118 assert( obj->ops == &event_ops );
119 return event->signaled;
122 static int event_satisfied( struct object *obj, struct thread *thread )
124 struct event *event = (struct event *)obj;
125 assert( obj->ops == &event_ops );
126 /* Reset if it's an auto-reset event */
127 if (!event->manual_reset) event->signaled = 0;
128 return 0; /* Not abandoned */
131 /* create an event */
132 DECL_HANDLER(create_event)
134 struct event *event;
136 reply->handle = 0;
137 if ((event = create_event( get_req_data(), get_req_data_size(),
138 req->manual_reset, req->initial_state )))
140 reply->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
141 release_object( event );
145 /* open a handle to an event */
146 DECL_HANDLER(open_event)
148 reply->handle = open_object( get_req_data(), get_req_data_size(),
149 &event_ops, req->access, req->inherit );
152 /* do an event operation */
153 DECL_HANDLER(event_op)
155 struct event *event;
157 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
158 switch(req->op)
160 case PULSE_EVENT:
161 pulse_event( event );
162 break;
163 case SET_EVENT:
164 set_event( event );
165 break;
166 case RESET_EVENT:
167 reset_event( event );
168 break;
169 default:
170 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
172 release_object( event );