4 * Copyright 1998 Alexandre Julliard
15 #include "server/request.h"
24 /***********************************************************************
25 * CreateEvent32A (KERNEL32.156)
27 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
28 BOOL initial_state, LPCSTR name )
30 struct create_event_request req;
31 struct create_event_reply reply;
32 int len = name ? strlen(name) + 1 : 0;
36 req.manual_reset = manual_reset;
37 req.initial_state = initial_state;
38 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
40 CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, len );
41 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
42 if (reply.handle == -1) return 0;
45 event = (EVENT *)K32OBJ_Create( K32OBJ_EVENT, sizeof(*event), name,
46 reply.handle, EVENT_ALL_ACCESS, sa, &handle );
48 K32OBJ_DecCount( &event->header );
50 if (handle == INVALID_HANDLE_VALUE) handle = 0;
55 /***********************************************************************
56 * CreateEvent32W (KERNEL32.157)
58 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
59 BOOL initial_state, LPCWSTR name )
61 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
62 HANDLE ret = CreateEventA( sa, manual_reset, initial_state, nameA );
63 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
67 /***********************************************************************
68 * WIN16_CreateEvent (KERNEL.457)
70 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
72 return CreateEventA( NULL, manual_reset, initial_state, NULL );
76 /***********************************************************************
77 * OpenEvent32A (KERNEL32.536)
79 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
83 struct open_named_obj_request req;
84 struct open_named_obj_reply reply;
85 int len = name ? strlen(name) + 1 : 0;
87 req.type = OPEN_EVENT;
89 req.inherit = inherit;
90 CLIENT_SendRequest( REQ_OPEN_NAMED_OBJ, -1, 2, &req, sizeof(req), name, len );
91 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
92 if (reply.handle != -1)
95 if ((obj = K32OBJ_FindNameType( name, K32OBJ_EVENT )) != NULL)
97 handle = HANDLE_Alloc( PROCESS_Current(), obj, access, inherit, reply.handle );
98 K32OBJ_DecCount( obj );
99 if (handle == INVALID_HANDLE_VALUE)
100 handle = 0; /* must return 0 on failure, not -1 */
102 else CLIENT_CloseHandle( reply.handle );
109 /***********************************************************************
110 * OpenEvent32W (KERNEL32.537)
112 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
114 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
115 HANDLE ret = OpenEventA( access, inherit, nameA );
116 if (nameA) HeapFree( GetProcessHeap(), 0, nameA );
121 /***********************************************************************
124 * Execute an event operation (set,reset,pulse).
126 static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
128 struct event_op_request req;
130 req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle,
131 K32OBJ_EVENT, EVENT_MODIFY_STATE );
132 if (req.handle == -1) return FALSE;
134 CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
135 return !CLIENT_WaitReply( NULL, NULL, 0 );
139 /***********************************************************************
140 * PulseEvent (KERNEL32.557)
142 BOOL WINAPI PulseEvent( HANDLE handle )
144 return EVENT_Operation( handle, PULSE_EVENT );
148 /***********************************************************************
149 * SetEvent (KERNEL32.644)
151 BOOL WINAPI SetEvent( HANDLE handle )
153 return EVENT_Operation( handle, SET_EVENT );
157 /***********************************************************************
158 * ResetEvent (KERNEL32.586)
160 BOOL WINAPI ResetEvent( HANDLE handle )
162 return EVENT_Operation( handle, RESET_EVENT );
166 /***********************************************************************
167 * NOTE: The Win95 VWin32_Event routines given below are really low-level
168 * routines implemented directly by VWin32. The user-mode libraries
169 * implement Win32 synchronisation routines on top of these low-level
170 * primitives. We do it the other way around here :-)
173 /***********************************************************************
174 * VWin32_EventCreate (KERNEL.442)
176 HANDLE WINAPI VWin32_EventCreate(VOID)
178 HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
179 return ConvertToGlobalHandle( hEvent );
182 /***********************************************************************
183 * VWin32_EventDestroy (KERNEL.443)
185 VOID WINAPI VWin32_EventDestroy(HANDLE event)
187 CloseHandle( event );
190 /***********************************************************************
191 * VWin32_EventWait (KERNEL.450)
193 VOID WINAPI VWin32_EventWait(HANDLE event)
195 SYSLEVEL_ReleaseWin16Lock();
196 WaitForSingleObject( event, INFINITE );
197 SYSLEVEL_RestoreWin16Lock();
200 /***********************************************************************
201 * VWin32_EventSet (KERNEL.451)
203 VOID WINAPI VWin32_EventSet(HANDLE event)