4 * Copyright 1998 Alexandre Julliard
14 #include "server/request.h"
23 /***********************************************************************
24 * CreateEvent32A (KERNEL32.156)
26 HANDLE32 WINAPI CreateEvent32A( SECURITY_ATTRIBUTES *sa, BOOL32 manual_reset,
27 BOOL32 initial_state, LPCSTR name )
29 struct create_event_request req;
30 struct create_event_reply reply;
31 int len = name ? strlen(name) + 1 : 0;
35 req.manual_reset = manual_reset;
36 req.initial_state = initial_state;
37 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
39 CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, len );
40 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
41 if (reply.handle == -1) return 0;
44 event = (EVENT *)K32OBJ_Create( K32OBJ_EVENT, sizeof(*event), name,
45 reply.handle, EVENT_ALL_ACCESS, sa, &handle );
47 K32OBJ_DecCount( &event->header );
49 if (handle == INVALID_HANDLE_VALUE32) handle = 0;
54 /***********************************************************************
55 * CreateEvent32W (KERNEL32.157)
57 HANDLE32 WINAPI CreateEvent32W( SECURITY_ATTRIBUTES *sa, BOOL32 manual_reset,
58 BOOL32 initial_state, LPCWSTR name )
60 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
61 HANDLE32 ret = CreateEvent32A( sa, manual_reset, initial_state, nameA );
62 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
66 /***********************************************************************
67 * WIN16_CreateEvent (KERNEL.457)
69 HANDLE32 WINAPI WIN16_CreateEvent( BOOL32 manual_reset, BOOL32 initial_state )
71 return CreateEvent32A( NULL, manual_reset, initial_state, NULL );
75 /***********************************************************************
76 * OpenEvent32A (KERNEL32.536)
78 HANDLE32 WINAPI OpenEvent32A( DWORD access, BOOL32 inherit, LPCSTR name )
82 struct open_named_obj_request req;
83 struct open_named_obj_reply reply;
84 int len = name ? strlen(name) + 1 : 0;
86 req.type = OPEN_EVENT;
88 req.inherit = inherit;
89 CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len );
90 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
91 if (reply.handle != -1)
94 if ((obj = K32OBJ_FindNameType( name, K32OBJ_EVENT )) != NULL)
96 handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle );
97 K32OBJ_DecCount( obj );
98 if (handle == INVALID_HANDLE_VALUE32)
99 handle = 0; /* must return 0 on failure, not -1 */
101 else CLIENT_CloseHandle( reply.handle );
108 /***********************************************************************
109 * OpenEvent32W (KERNEL32.537)
111 HANDLE32 WINAPI OpenEvent32W( DWORD access, BOOL32 inherit, LPCWSTR name )
113 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
114 HANDLE32 ret = OpenEvent32A( access, inherit, nameA );
115 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
120 /***********************************************************************
123 * Execute an event operation (set,reset,pulse).
125 static BOOL32 EVENT_Operation( HANDLE32 handle, enum event_op op )
127 struct event_op_request req;
129 req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle,
130 K32OBJ_EVENT, EVENT_MODIFY_STATE );
131 if (req.handle == -1) return FALSE;
133 CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
134 return !CLIENT_WaitReply( NULL, NULL, 0 );
138 /***********************************************************************
139 * PulseEvent (KERNEL32.557)
141 BOOL32 WINAPI PulseEvent( HANDLE32 handle )
143 return EVENT_Operation( handle, PULSE_EVENT );
147 /***********************************************************************
148 * SetEvent (KERNEL32.644)
150 BOOL32 WINAPI SetEvent( HANDLE32 handle )
152 return EVENT_Operation( handle, SET_EVENT );
156 /***********************************************************************
157 * ResetEvent (KERNEL32.586)
159 BOOL32 WINAPI ResetEvent( HANDLE32 handle )
161 return EVENT_Operation( handle, RESET_EVENT );
165 /***********************************************************************
166 * NOTE: The Win95 VWin32_Event routines given below are really low-level
167 * routines implemented directly by VWin32. The user-mode libraries
168 * implement Win32 synchronisation routines on top of these low-level
169 * primitives. We do it the other way around here :-)
172 /***********************************************************************
173 * VWin32_EventCreate (KERNEL.442)
175 HANDLE32 WINAPI VWin32_EventCreate(VOID)
177 HANDLE32 hEvent = CreateEvent32A( NULL, FALSE, 0, NULL );
178 return ConvertToGlobalHandle( hEvent );
181 /***********************************************************************
182 * VWin32_EventDestroy (KERNEL.443)
184 VOID WINAPI VWin32_EventDestroy(HANDLE32 event)
186 CloseHandle( event );
189 /***********************************************************************
190 * VWin32_EventWait (KERNEL.450)
192 VOID WINAPI VWin32_EventWait(HANDLE32 event)
194 SYSLEVEL_ReleaseWin16Lock();
195 WaitForSingleObject( event, INFINITE32 );
196 SYSLEVEL_RestoreWin16Lock();
199 /***********************************************************************
200 * VWin32_EventSet (KERNEL.451)
202 VOID WINAPI VWin32_EventSet(HANDLE32 event)