Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 events |
| 3 | * |
| 4 | * Copyright 1998 Alexandre Julliard |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
David Luyer | ee517e8 | 1999-02-28 12:27:56 +0000 | [diff] [blame] | 8 | #include <string.h> |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 9 | #include "winerror.h" |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 10 | #include "syslevel.h" |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 11 | #include "server.h" |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 12 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 13 | |
| 14 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 15 | * CreateEventA (KERNEL32.156) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 16 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 17 | HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 18 | BOOL initial_state, LPCSTR name ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 19 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 20 | struct create_event_request *req = get_req_buffer(); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 21 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 22 | req->manual_reset = manual_reset; |
| 23 | req->initial_state = initial_state; |
| 24 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 25 | server_strcpyAtoW( req->name, name ); |
Alexandre Julliard | 3f09ec5 | 1999-02-28 19:25:51 +0000 | [diff] [blame] | 26 | SetLastError(0); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 27 | server_call( REQ_CREATE_EVENT ); |
| 28 | if (req->handle == -1) return 0; |
| 29 | return req->handle; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | |
| 33 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 34 | * CreateEventW (KERNEL32.157) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 35 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 36 | HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 37 | BOOL initial_state, LPCWSTR name ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 38 | { |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 39 | struct create_event_request *req = get_req_buffer(); |
| 40 | |
| 41 | req->manual_reset = manual_reset; |
| 42 | req->initial_state = initial_state; |
| 43 | req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 44 | server_strcpyW( req->name, name ); |
| 45 | SetLastError(0); |
| 46 | server_call( REQ_CREATE_EVENT ); |
| 47 | if (req->handle == -1) return 0; |
| 48 | return req->handle; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 51 | /*********************************************************************** |
| 52 | * WIN16_CreateEvent (KERNEL.457) |
| 53 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 54 | HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state ) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 55 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 56 | return CreateEventA( NULL, manual_reset, initial_state, NULL ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 59 | |
| 60 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 61 | * OpenEventA (KERNEL32.536) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 62 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 63 | HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 64 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 65 | struct open_event_request *req = get_req_buffer(); |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 66 | |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 67 | req->access = access; |
| 68 | req->inherit = inherit; |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 69 | server_strcpyAtoW( req->name, name ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 70 | server_call( REQ_OPEN_EVENT ); |
| 71 | if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ |
| 72 | return req->handle; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 77 | * OpenEventW (KERNEL32.537) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 78 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 79 | HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 80 | { |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 81 | struct open_event_request *req = get_req_buffer(); |
| 82 | |
| 83 | req->access = access; |
| 84 | req->inherit = inherit; |
| 85 | server_strcpyW( req->name, name ); |
| 86 | server_call( REQ_OPEN_EVENT ); |
| 87 | if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */ |
| 88 | return req->handle; |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
| 92 | /*********************************************************************** |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 93 | * EVENT_Operation |
| 94 | * |
| 95 | * Execute an event operation (set,reset,pulse). |
| 96 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 97 | static BOOL EVENT_Operation( HANDLE handle, enum event_op op ) |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 98 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 99 | struct event_op_request *req = get_req_buffer(); |
| 100 | req->handle = handle; |
| 101 | req->op = op; |
| 102 | return !server_call( REQ_EVENT_OP ); |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
| 106 | /*********************************************************************** |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 107 | * PulseEvent (KERNEL32.557) |
| 108 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 109 | BOOL WINAPI PulseEvent( HANDLE handle ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 110 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 111 | return EVENT_Operation( handle, PULSE_EVENT ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | /*********************************************************************** |
| 116 | * SetEvent (KERNEL32.644) |
| 117 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 118 | BOOL WINAPI SetEvent( HANDLE handle ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 119 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 120 | return EVENT_Operation( handle, SET_EVENT ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | /*********************************************************************** |
| 125 | * ResetEvent (KERNEL32.586) |
| 126 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 127 | BOOL WINAPI ResetEvent( HANDLE handle ) |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 128 | { |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 129 | return EVENT_Operation( handle, RESET_EVENT ); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | /*********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 134 | * NOTE: The Win95 VWin32_Event routines given below are really low-level |
| 135 | * routines implemented directly by VWin32. The user-mode libraries |
| 136 | * implement Win32 synchronisation routines on top of these low-level |
| 137 | * primitives. We do it the other way around here :-) |
| 138 | */ |
| 139 | |
| 140 | /*********************************************************************** |
| 141 | * VWin32_EventCreate (KERNEL.442) |
| 142 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 143 | HANDLE WINAPI VWin32_EventCreate(VOID) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 144 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 145 | HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL ); |
Ulrich Weigand | 4a54690 | 1998-10-24 12:00:33 +0000 | [diff] [blame] | 146 | return ConvertToGlobalHandle( hEvent ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /*********************************************************************** |
| 150 | * VWin32_EventDestroy (KERNEL.443) |
| 151 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 152 | VOID WINAPI VWin32_EventDestroy(HANDLE event) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 153 | { |
| 154 | CloseHandle( event ); |
| 155 | } |
| 156 | |
| 157 | /*********************************************************************** |
| 158 | * VWin32_EventWait (KERNEL.450) |
| 159 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 160 | VOID WINAPI VWin32_EventWait(HANDLE event) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 161 | { |
| 162 | SYSLEVEL_ReleaseWin16Lock(); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 163 | WaitForSingleObject( event, INFINITE ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 164 | SYSLEVEL_RestoreWin16Lock(); |
| 165 | } |
| 166 | |
| 167 | /*********************************************************************** |
| 168 | * VWin32_EventSet (KERNEL.451) |
| 169 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 170 | VOID WINAPI VWin32_EventSet(HANDLE event) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 171 | { |
| 172 | SetEvent( event ); |
| 173 | } |
| 174 | |