- ANSI SCSI revision is a hex number.
[wine.git] / server / event.c
blob2778f0fd0636af04e969d8b1b59c076ef69ec1dd
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 "windef.h"
29 #include "winternl.h"
31 #include "handle.h"
32 #include "thread.h"
33 #include "request.h"
35 struct event
37 struct object obj; /* object header */
38 int manual_reset; /* is it a manual reset event? */
39 int signaled; /* event has been signaled */
42 static void event_dump( struct object *obj, int verbose );
43 static int event_signaled( struct object *obj, struct thread *thread );
44 static int event_satisfied( struct object *obj, struct thread *thread );
45 static int event_signal( struct object *obj, unsigned int access);
47 static const struct object_ops event_ops =
49 sizeof(struct event), /* size */
50 event_dump, /* dump */
51 add_queue, /* add_queue */
52 remove_queue, /* remove_queue */
53 event_signaled, /* signaled */
54 event_satisfied, /* satisfied */
55 event_signal, /* signal */
56 no_get_fd, /* get_fd */
57 no_close_handle, /* close_handle */
58 no_destroy /* destroy */
62 struct event *create_event( const struct unicode_str *name, unsigned int attr,
63 int manual_reset, int initial_state )
65 struct event *event;
67 if ((event = create_named_object( sync_namespace, &event_ops, name, attr )))
69 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
71 /* initialize it if it didn't already exist */
72 event->manual_reset = manual_reset;
73 event->signaled = initial_state;
76 return event;
79 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
81 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
84 void pulse_event( struct event *event )
86 event->signaled = 1;
87 /* wake up all waiters if manual reset, a single one otherwise */
88 wake_up( &event->obj, !event->manual_reset );
89 event->signaled = 0;
92 void set_event( struct event *event )
94 event->signaled = 1;
95 /* wake up all waiters if manual reset, a single one otherwise */
96 wake_up( &event->obj, !event->manual_reset );
99 void reset_event( struct event *event )
101 event->signaled = 0;
104 static void event_dump( struct object *obj, int verbose )
106 struct event *event = (struct event *)obj;
107 assert( obj->ops == &event_ops );
108 fprintf( stderr, "Event manual=%d signaled=%d ",
109 event->manual_reset, event->signaled );
110 dump_object_name( &event->obj );
111 fputc( '\n', stderr );
114 static int event_signaled( struct object *obj, struct thread *thread )
116 struct event *event = (struct event *)obj;
117 assert( obj->ops == &event_ops );
118 return event->signaled;
121 static int event_satisfied( struct object *obj, struct thread *thread )
123 struct event *event = (struct event *)obj;
124 assert( obj->ops == &event_ops );
125 /* Reset if it's an auto-reset event */
126 if (!event->manual_reset) event->signaled = 0;
127 return 0; /* Not abandoned */
130 static int event_signal( struct object *obj, unsigned int access )
132 struct event *event = (struct event *)obj;
133 assert( obj->ops == &event_ops );
135 if (!(access & EVENT_MODIFY_STATE))
137 set_error( STATUS_ACCESS_DENIED );
138 return 0;
140 set_event( event );
141 return 1;
144 /* create an event */
145 DECL_HANDLER(create_event)
147 struct event *event;
148 struct unicode_str name;
150 reply->handle = 0;
151 get_req_unicode_str( &name );
152 if ((event = create_event( &name, req->attributes, req->manual_reset, req->initial_state )))
154 reply->handle = alloc_handle( current->process, event, req->access,
155 req->attributes & OBJ_INHERIT );
156 release_object( event );
160 /* open a handle to an event */
161 DECL_HANDLER(open_event)
163 struct unicode_str name;
165 get_req_unicode_str( &name );
166 reply->handle = open_object( sync_namespace, &name, &event_ops, req->access, req->attributes );
169 /* do an event operation */
170 DECL_HANDLER(event_op)
172 struct event *event;
174 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
175 switch(req->op)
177 case PULSE_EVENT:
178 pulse_event( event );
179 break;
180 case SET_EVENT:
181 set_event( event );
182 break;
183 case RESET_EVENT:
184 reset_event( event );
185 break;
186 default:
187 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
189 release_object( event );