~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/server/event.c

Version: ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Server-side event management
  3  *
  4  * Copyright (C) 1998 Alexandre Julliard
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "config.h"
 22 #include "wine/port.h"
 23 
 24 #include <assert.h>
 25 #include <stdio.h>
 26 #include <stdlib.h>
 27 #include <stdarg.h>
 28 
 29 #include "ntstatus.h"
 30 #define WIN32_NO_STATUS
 31 #include "windef.h"
 32 #include "winternl.h"
 33 
 34 #include "handle.h"
 35 #include "thread.h"
 36 #include "request.h"
 37 #include "security.h"
 38 
 39 struct event
 40 {
 41     struct object  obj;             /* object header */
 42     int            manual_reset;    /* is it a manual reset event? */
 43     int            signaled;        /* event has been signaled */
 44 };
 45 
 46 static void event_dump( struct object *obj, int verbose );
 47 static struct object_type *event_get_type( struct object *obj );
 48 static int event_signaled( struct object *obj, struct thread *thread );
 49 static int event_satisfied( struct object *obj, struct thread *thread );
 50 static unsigned int event_map_access( struct object *obj, unsigned int access );
 51 static int event_signal( struct object *obj, unsigned int access);
 52 
 53 static const struct object_ops event_ops =
 54 {
 55     sizeof(struct event),      /* size */
 56     event_dump,                /* dump */
 57     event_get_type,            /* get_type */
 58     add_queue,                 /* add_queue */
 59     remove_queue,              /* remove_queue */
 60     event_signaled,            /* signaled */
 61     event_satisfied,           /* satisfied */
 62     event_signal,              /* signal */
 63     no_get_fd,                 /* get_fd */
 64     event_map_access,          /* map_access */
 65     default_get_sd,            /* get_sd */
 66     default_set_sd,            /* set_sd */
 67     no_lookup_name,            /* lookup_name */
 68     no_open_file,              /* open_file */
 69     no_close_handle,           /* close_handle */
 70     no_destroy                 /* destroy */
 71 };
 72 
 73 
 74 struct event *create_event( struct directory *root, const struct unicode_str *name,
 75                             unsigned int attr, int manual_reset, int initial_state,
 76                             const struct security_descriptor *sd )
 77 {
 78     struct event *event;
 79 
 80     if ((event = create_named_object_dir( root, name, attr, &event_ops )))
 81     {
 82         if (get_error() != STATUS_OBJECT_NAME_EXISTS)
 83         {
 84             /* initialize it if it didn't already exist */
 85             event->manual_reset = manual_reset;
 86             event->signaled     = initial_state;
 87             if (sd) default_set_sd( &event->obj, sd, OWNER_SECURITY_INFORMATION|
 88                                                      GROUP_SECURITY_INFORMATION|
 89                                                      DACL_SECURITY_INFORMATION|
 90                                                      SACL_SECURITY_INFORMATION );
 91         }
 92     }
 93     return event;
 94 }
 95 
 96 struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access )
 97 {
 98     return (struct event *)get_handle_obj( process, handle, access, &event_ops );
 99 }
100 
101 void pulse_event( struct event *event )
102 {
103     event->signaled = 1;
104     /* wake up all waiters if manual reset, a single one otherwise */
105     wake_up( &event->obj, !event->manual_reset );
106     event->signaled = 0;
107 }
108 
109 void set_event( struct event *event )
110 {
111     event->signaled = 1;
112     /* wake up all waiters if manual reset, a single one otherwise */
113     wake_up( &event->obj, !event->manual_reset );
114 }
115 
116 void reset_event( struct event *event )
117 {
118     event->signaled = 0;
119 }
120 
121 static void event_dump( struct object *obj, int verbose )
122 {
123     struct event *event = (struct event *)obj;
124     assert( obj->ops == &event_ops );
125     fprintf( stderr, "Event manual=%d signaled=%d ",
126              event->manual_reset, event->signaled );
127     dump_object_name( &event->obj );
128     fputc( '\n', stderr );
129 }
130 
131 static struct object_type *event_get_type( struct object *obj )
132 {
133     static const WCHAR name[] = {'E','v','e','n','t'};
134     static const struct unicode_str str = { name, sizeof(name) };
135     return get_object_type( &str );
136 }
137 
138 static int event_signaled( struct object *obj, struct thread *thread )
139 {
140     struct event *event = (struct event *)obj;
141     assert( obj->ops == &event_ops );
142     return event->signaled;
143 }
144 
145 static int event_satisfied( struct object *obj, struct thread *thread )
146 {
147     struct event *event = (struct event *)obj;
148     assert( obj->ops == &event_ops );
149     /* Reset if it's an auto-reset event */
150     if (!event->manual_reset) event->signaled = 0;
151     return 0;  /* Not abandoned */
152 }
153 
154 static unsigned int event_map_access( struct object *obj, unsigned int access )
155 {
156     if (access & GENERIC_READ)    access |= STANDARD_RIGHTS_READ | SYNCHRONIZE | EVENT_QUERY_STATE;
157     if (access & GENERIC_WRITE)   access |= STANDARD_RIGHTS_WRITE;
158     if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
159     if (access & GENERIC_ALL)     access |= STANDARD_RIGHTS_ALL | EVENT_ALL_ACCESS;
160     return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
161 }
162 
163 static int event_signal( struct object *obj, unsigned int access )
164 {
165     struct event *event = (struct event *)obj;
166     assert( obj->ops == &event_ops );
167 
168     if (!(access & EVENT_MODIFY_STATE))
169     {
170         set_error( STATUS_ACCESS_DENIED );
171         return 0;
172     }
173     set_event( event );
174     return 1;
175 }
176 
177 /* create an event */
178 DECL_HANDLER(create_event)
179 {
180     struct event *event;
181     struct unicode_str name;
182     struct directory *root = NULL;
183     const struct object_attributes *objattr = get_req_data();
184     const struct security_descriptor *sd;
185 
186     reply->handle = 0;
187 
188     if (!objattr_is_valid( objattr, get_req_data_size() ))
189         return;
190 
191     sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
192     objattr_get_name( objattr, &name );
193 
194     if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 )))
195         return;
196 
197     if ((event = create_event( root, &name, req->attributes, req->manual_reset, req->initial_state, sd )))
198     {
199         if (get_error() == STATUS_OBJECT_NAME_EXISTS)
200             reply->handle = alloc_handle( current->process, event, req->access, req->attributes );
201         else
202             reply->handle = alloc_handle_no_access_check( current->process, event, req->access, req->attributes );
203         release_object( event );
204     }
205 
206     if (root) release_object( root );
207 }
208 
209 /* open a handle to an event */
210 DECL_HANDLER(open_event)
211 {
212     struct unicode_str name;
213     struct directory *root = NULL;
214     struct event *event;
215 
216     get_req_unicode_str( &name );
217     if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
218         return;
219 
220     if ((event = open_object_dir( root, &name, req->attributes, &event_ops )))
221     {
222         reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
223         release_object( event );
224     }
225 
226     if (root) release_object( root );
227 }
228 
229 /* do an event operation */
230 DECL_HANDLER(event_op)
231 {
232     struct event *event;
233 
234     if (!(event = get_event_obj( current->process, req->handle, EVENT_MODIFY_STATE ))) return;
235     switch(req->op)
236     {
237     case PULSE_EVENT:
238         pulse_event( event );
239         break;
240     case SET_EVENT:
241         set_event( event );
242         break;
243     case RESET_EVENT:
244         reset_event( event );
245         break;
246     default:
247         set_error( STATUS_INVALID_PARAMETER );
248         break;
249     }
250     release_object( event );
251 }
252 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.