update for HEAD-2003091401
[reactos.git] / lib / kernel32 / synch / event.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS system libraries
5  * FILE:            lib/kernel32/synch/event.c
6  * PURPOSE:         Local string functions
7  * PROGRAMMER:      Ariadne ( ariadne@xs4all.nl)
8  * UPDATE HISTORY:
9  *                  Created 01/11/98
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <k32.h>
15
16 #define NDEBUG
17 #include <kernel32/kernel32.h>
18
19 /* FUNCTIONS ****************************************************************/
20
21 /*
22  * @implemented
23  */
24 HANDLE STDCALL
25 CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
26              WINBOOL bManualReset,
27              WINBOOL bInitialState,
28              LPCSTR lpName)
29 {
30    UNICODE_STRING EventNameU;
31    ANSI_STRING EventName;
32    HANDLE EventHandle;
33
34    RtlInitUnicodeString (&EventNameU, NULL);
35
36    if (lpName)
37      {
38         RtlInitAnsiString(&EventName,
39                           (LPSTR)lpName);
40         RtlAnsiStringToUnicodeString(&EventNameU,
41                                      &EventName,
42                                      TRUE);
43      }
44
45    EventHandle = CreateEventW(lpEventAttributes,
46                               bManualReset,
47                               bInitialState,
48                               EventNameU.Buffer);
49
50    if (lpName)
51      {
52         RtlFreeUnicodeString(&EventNameU);
53      }
54
55    return EventHandle;
56 }
57
58
59 /*
60  * @implemented
61  */
62 HANDLE STDCALL
63 CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,
64              WINBOOL bManualReset,
65              WINBOOL bInitialState,
66              LPCWSTR lpName)
67 {
68    NTSTATUS Status;
69    HANDLE hEvent;
70    UNICODE_STRING EventNameString;
71    OBJECT_ATTRIBUTES ObjectAttributes;
72
73    ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
74    ObjectAttributes.RootDirectory = hBaseDir;
75    ObjectAttributes.ObjectName = NULL;
76    ObjectAttributes.Attributes = 0;
77    ObjectAttributes.SecurityDescriptor = NULL;
78    ObjectAttributes.SecurityQualityOfService = NULL;
79
80    if (lpName != NULL)
81      {
82         RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
83         ObjectAttributes.ObjectName = &EventNameString;
84      }
85
86    Status = NtCreateEvent(&hEvent,
87                           STANDARD_RIGHTS_ALL|EVENT_READ_ACCESS|EVENT_WRITE_ACCESS,
88                           &ObjectAttributes,
89                           bManualReset,
90                           bInitialState);
91    DPRINT( "Called\n" );
92    if (!NT_SUCCESS(Status))
93      {
94         SetLastErrorByStatus(Status);
95         return NULL;
96      }
97
98    return hEvent;
99 }
100
101
102 /*
103  * @implemented
104  */
105 HANDLE STDCALL
106 OpenEventA(DWORD dwDesiredAccess,
107            WINBOOL bInheritHandle,
108            LPCSTR lpName)
109 {
110    UNICODE_STRING EventNameU;
111    ANSI_STRING EventName;
112    HANDLE EventHandle;
113
114    RtlInitUnicodeString(&EventNameU,
115                         NULL);
116
117    if (lpName)
118      {
119         RtlInitAnsiString(&EventName,
120                           (LPSTR)lpName);
121         RtlAnsiStringToUnicodeString(&EventNameU,
122                                      &EventName,
123                                      TRUE);
124     }
125
126    EventHandle = OpenEventW(dwDesiredAccess,
127                             bInheritHandle,
128                             EventNameU.Buffer);
129
130    if (lpName)
131      {
132         RtlFreeUnicodeString(&EventNameU);
133      }
134
135    return EventHandle;
136 }
137
138
139 /*
140  * @implemented
141  */
142 HANDLE STDCALL
143 OpenEventW(DWORD dwDesiredAccess,
144            WINBOOL bInheritHandle,
145            LPCWSTR lpName)
146 {
147    OBJECT_ATTRIBUTES ObjectAttributes;
148    UNICODE_STRING EventNameString;
149    NTSTATUS Status;
150    HANDLE hEvent = NULL;
151
152    if (lpName == NULL)
153      {
154         SetLastError(ERROR_INVALID_PARAMETER);
155         return NULL;
156      }
157
158    RtlInitUnicodeString(&EventNameString, (LPWSTR)lpName);
159
160    ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
161    ObjectAttributes.RootDirectory = hBaseDir;
162    ObjectAttributes.ObjectName = &EventNameString;
163    ObjectAttributes.Attributes = 0;
164    ObjectAttributes.SecurityDescriptor = NULL;
165    ObjectAttributes.SecurityQualityOfService = NULL;
166    if (bInheritHandle == TRUE)
167      {
168         ObjectAttributes.Attributes |= OBJ_INHERIT;
169      }
170
171    Status = NtOpenEvent(&hEvent,
172                         dwDesiredAccess,
173                         &ObjectAttributes);
174    if (!NT_SUCCESS(Status))
175      {
176         SetLastErrorByStatus(Status);
177         return NULL;
178      }
179
180    return hEvent;
181 }
182
183
184 /*
185  * @implemented
186  */
187 WINBOOL STDCALL
188 PulseEvent(HANDLE hEvent)
189 {
190    ULONG Count;
191    NTSTATUS Status;
192
193    Status = NtPulseEvent(hEvent,
194                          &Count);
195    if (!NT_SUCCESS(Status))
196      {
197         SetLastErrorByStatus (Status);
198         return FALSE;
199      }
200
201    return TRUE;
202 }
203
204
205 /*
206  * @implemented
207  */
208 WINBOOL STDCALL
209 ResetEvent(HANDLE hEvent)
210 {
211    NTSTATUS Status;
212    ULONG Count;
213
214    Status = NtResetEvent(hEvent,
215                          &Count);
216    if (!NT_SUCCESS(Status))
217      {
218         SetLastErrorByStatus(Status);
219         return FALSE;
220      }
221
222    return TRUE;
223 }
224
225
226 /*
227  * @implemented
228  */
229 WINBOOL STDCALL
230 SetEvent(HANDLE hEvent)
231 {
232    NTSTATUS Status;
233    ULONG Count;
234
235    Status = NtSetEvent(hEvent,
236                        &Count);
237    if (!NT_SUCCESS(Status))
238      {
239         SetLastErrorByStatus(Status);
240         return FALSE;
241      }
242
243    return TRUE;
244 }
245
246 /* EOF */