diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 1cc1f7a..4d885a8 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -24,6 +24,7 @@ Notable enhancements and changes are: nosetests with pytest, transition from pep8 to pycodestyle and upgrading tools and libraries to more modern versions. * :issue:`124` - Implemented :func:`pywincffi.kernel32.file.GetTempPath` + * :issue:`123` - Implemented :func:`pywincffi.kernel32.event.SetEvent` 0.4.0 ~~~~~ diff --git a/pywincffi/core/cdefs/headers/functions.h b/pywincffi/core/cdefs/headers/functions.h index b62cecd..4c5bcfc 100644 --- a/pywincffi/core/cdefs/headers/functions.h +++ b/pywincffi/core/cdefs/headers/functions.h @@ -216,6 +216,11 @@ BOOL WINAPI ResetEvent( _In_ HANDLE hEvent ); +// https://msdn.microsoft.com/en-us/library/ms686211 +BOOL WINAPI SetEvent( + _In_ HANDLE hEvent +); + /////////////////////// // Communications /////////////////////// diff --git a/pywincffi/kernel32/__init__.py b/pywincffi/kernel32/__init__.py index 2013e7a..d1621ba 100644 --- a/pywincffi/kernel32/__init__.py +++ b/pywincffi/kernel32/__init__.py @@ -20,7 +20,8 @@ from pywincffi.kernel32.process import ( GetProcessId, GetCurrentProcess, OpenProcess, GetExitCodeProcess, TerminateProcess, CreateToolhelp32Snapshot, CreateProcess, pid_exists) -from pywincffi.kernel32.events import CreateEvent, OpenEvent, ResetEvent +from pywincffi.kernel32.events import ( + CreateEvent, OpenEvent, ResetEvent, SetEvent) from pywincffi.kernel32.comms import ClearCommError from pywincffi.kernel32.synchronization import WaitForSingleObject from pywincffi.kernel32.overlapped import GetOverlappedResult diff --git a/pywincffi/kernel32/events.py b/pywincffi/kernel32/events.py index b513cfe..c6209c9 100644 --- a/pywincffi/kernel32/events.py +++ b/pywincffi/kernel32/events.py @@ -125,3 +125,22 @@ def ResetEvent(hEvent): _, library = dist.load() code = library.ResetEvent(wintype_to_cdata(hEvent)) error_check("ResetEvent", code=code, expected=NON_ZERO) + + +def SetEvent(hEvent): + """ + Sets the specified event object to the signaled state. + + .. seealso:: + + https://msdn.microsoft.com/en-us/library/ms686211 + + :param pywincffi.wintypes.HANDLE hEvent: + A handle to the event object. The handle must have the + ``EVENT_MODIFY_STATE`` access right. + """ + input_check("hEvent", hEvent, HANDLE) + + _, library = dist.load() + code = library.SetEvent(wintype_to_cdata(hEvent)) + error_check("SetEvent", code=code, expected=NON_ZERO) diff --git a/tests/test_kernel32/test_events.py b/tests/test_kernel32/test_events.py index 516344b..a6c801e 100644 --- a/tests/test_kernel32/test_events.py +++ b/tests/test_kernel32/test_events.py @@ -7,7 +7,8 @@ from pywincffi.exceptions import WindowsAPIError, InputError from pywincffi.kernel32 import events # used by mocks from pywincffi.kernel32 import ( - CloseHandle, CreateEvent, OpenEvent, ResetEvent, WaitForSingleObject) + CloseHandle, CreateEvent, OpenEvent, ResetEvent, WaitForSingleObject, + SetEvent) # These tests cause TestPidExists and others to fail under Python 3.4 so for @@ -108,3 +109,23 @@ def test_resets_event(self): _, library = dist.load() self.assertEqual(WaitForSingleObject(handle, 0), library.WAIT_TIMEOUT) + + +class TestSetEvent(TestCase): + """ + Tests for :func:`pywincffi.kernel32.SetEvent` + """ + def test_signaled(self): + handle = CreateEvent(True, False) + self.addCleanup(CloseHandle, handle) + _, library = dist.load() + SetEvent(handle) + self.assertEqual( + WaitForSingleObject(handle, 0), library.WAIT_OBJECT_0) + + def test_not_signaled(self): + handle = CreateEvent(True, False) + self.addCleanup(CloseHandle, handle) + _, library = dist.load() + self.assertEqual( + WaitForSingleObject(handle, 0), library.WAIT_TIMEOUT)