4 * Copyright 1998 Alexandre Julliard
15 #include "server/request.h"
24 /***********************************************************************
25 * CreateEvent32A (KERNEL32.156)
27 HANDLE32 WINAPI
CreateEvent32A( SECURITY_ATTRIBUTES
*sa
, BOOL32 manual_reset
,
28 BOOL32 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_VALUE32
) handle
= 0;
55 /***********************************************************************
56 * CreateEvent32W (KERNEL32.157)
58 HANDLE32 WINAPI
CreateEvent32W( SECURITY_ATTRIBUTES
*sa
, BOOL32 manual_reset
,
59 BOOL32 initial_state
, LPCWSTR name
)
61 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
62 HANDLE32 ret
= CreateEvent32A( sa
, manual_reset
, initial_state
, nameA
);
63 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
67 /***********************************************************************
68 * WIN16_CreateEvent (KERNEL.457)
70 HANDLE32 WINAPI
WIN16_CreateEvent( BOOL32 manual_reset
, BOOL32 initial_state
)
72 return CreateEvent32A( NULL
, manual_reset
, initial_state
, NULL
);
76 /***********************************************************************
77 * OpenEvent32A (KERNEL32.536)
79 HANDLE32 WINAPI
OpenEvent32A( DWORD access
, BOOL32 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_VALUE32
)
100 handle
= 0; /* must return 0 on failure, not -1 */
102 else CLIENT_CloseHandle( reply
.handle
);
109 /***********************************************************************
110 * OpenEvent32W (KERNEL32.537)
112 HANDLE32 WINAPI
OpenEvent32W( DWORD access
, BOOL32 inherit
, LPCWSTR name
)
114 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
115 HANDLE32 ret
= OpenEvent32A( access
, inherit
, nameA
);
116 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
121 /***********************************************************************
124 * Execute an event operation (set,reset,pulse).
126 static BOOL32
EVENT_Operation( HANDLE32 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 BOOL32 WINAPI
PulseEvent( HANDLE32 handle
)
144 return EVENT_Operation( handle
, PULSE_EVENT
);
148 /***********************************************************************
149 * SetEvent (KERNEL32.644)
151 BOOL32 WINAPI
SetEvent( HANDLE32 handle
)
153 return EVENT_Operation( handle
, SET_EVENT
);
157 /***********************************************************************
158 * ResetEvent (KERNEL32.586)
160 BOOL32 WINAPI
ResetEvent( HANDLE32 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 HANDLE32 WINAPI
VWin32_EventCreate(VOID
)
178 HANDLE32 hEvent
= CreateEvent32A( NULL
, FALSE
, 0, NULL
);
179 return ConvertToGlobalHandle( hEvent
);
182 /***********************************************************************
183 * VWin32_EventDestroy (KERNEL.443)
185 VOID WINAPI
VWin32_EventDestroy(HANDLE32 event
)
187 CloseHandle( event
);
190 /***********************************************************************
191 * VWin32_EventWait (KERNEL.450)
193 VOID WINAPI
VWin32_EventWait(HANDLE32 event
)
195 SYSLEVEL_ReleaseWin16Lock();
196 WaitForSingleObject( event
, INFINITE32
);
197 SYSLEVEL_RestoreWin16Lock();
200 /***********************************************************************
201 * VWin32_EventSet (KERNEL.451)
203 VOID WINAPI
VWin32_EventSet(HANDLE32 event
)