Define RPC_FC_RANGE.
[wine.git] / server / event.c
blob3445185aeb5c0656d8c36711e0559680818ad0bb
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"
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 );
44 static int event_signal( struct object *obj, unsigned int access);
46 static const struct object_ops event_ops =
48 sizeof(struct event), /* size */
49 event_dump, /* dump */
50 add_queue, /* add_queue */
51 remove_queue, /* remove_queue */
52 event_signaled, /* signaled */
53 event_satisfied, /* satisfied */
54 event_signal, /* signal */
55 no_get_fd, /* get_fd */
56 no_close_handle, /* close_handle */
57 no_destroy /* destroy */
61 struct event *create_event( const WCHAR *name, size_t len,
62 int manual_reset, int initial_state )
64 struct event *event;
66 if ((event = create_named_object( sync_namespace, &event_ops, name, len )))
68 if (get_error() != STATUS_OBJECT_NAME_COLLISION)
70 /* initialize it if it didn't already exist */
71 event->manual_reset = manual_reset;
72 event->signaled = initial_state;
75 return event;
78 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
80 return (struct event *)get_handle_obj( process, handle, access, &event_ops );
83 void pulse_event( struct event *event )
85 event->signaled = 1;
86 /* wake up all waiters if manual reset, a single one otherwise */
87 wake_up( &event->obj, !event->manual_reset );
88 event->signaled = 0;
91 void set_event( struct event *event )
93 event->signaled = 1;
94 /* wake up all waiters if manual reset, a single one otherwise */
95 wake_up( &event->obj, !event->manual_reset );
98 void reset_event( struct event *event )
100 event->signaled = 0;
103 static void event_dump( struct object *obj, int verbose )
105 struct event *event = (struct event *)obj;
106 assert( obj->ops == &event_ops );
107 fprintf( stderr, "Event manual=%d signaled=%d ",
108 event->manual_reset, event->signaled );
109 dump_object_name( &event->obj );
110 fputc( '\n', stderr );
113 static int event_signaled( struct object *obj, struct thread *thread )
115 struct event *event = (struct event *)obj;
116 assert( obj->ops == &event_ops );
117 return event->signaled;
120 static int event_satisfied( struct object *obj, struct thread *thread )
122 struct event *event = (struct event *)obj;
123 assert( obj->ops == &event_ops );
124 /* Reset if it's an auto-reset event */
125 if (!event->manual_reset) event->signaled = 0;
126 return 0; /* Not abandoned */
129 static int event_signal( struct object *obj, unsigned int access )
131 struct event *event = (struct event *)obj;
132 assert( obj->ops == &event_ops );
134 if (!(access & EVENT_MODIFY_STATE))
136 set_error( STATUS_ACCESS_DENIED );
137 return 0;
139 set_event( event );
140 return 1;
143 /* create an event */
144 DECL_HANDLER(create_event)
146 struct event *event;
148 reply->handle = 0;
149 if ((event = create_event( get_req_data(), get_req_data_size(),
150 req->manual_reset, req->initial_state )))
152 reply->handle = alloc_handle( current->process, event, req->access, req->inherit );
153 release_object( event );
157 /* open a handle to an event */
158 DECL_HANDLER(open_event)
160 reply->handle = open_object( sync_namespace, get_req_data(), get_req_data_size(),
161 &event_ops, req->access, req->inherit );
164 /* do an event operation */
165 DECL_HANDLER(event_op)
167 struct event *event;
169 if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
170 switch(req->op)
172 case PULSE_EVENT:
173 pulse_event( event );
174 break;
175 case SET_EVENT:
176 set_event( event );
177 break;
178 case RESET_EVENT:
179 reset_event( event );
180 break;
181 default:
182 fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
184 release_object( event );