Skip to content

Commit

Permalink
Added com.sun.jna.platform.win32.Kernel32.ResetEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
manithree authored and dblock committed Dec 11, 2013
1 parent c94c3b9 commit 35c743d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Features
* [#271](https://github.com/twall/jna/pull/271): Added `com.sun.jna.platform.win32.OpenGL32`, `OpenGL32Util` and `WinOpenGL` - [@kc7bfi](https://github.com/kc7bfi).
* [#250](https://github.com/twall/jna/pull/250): Added `com.sun.jna.platform.win32.Kernel32.GetPrivateProfileSection`, `GetPrivateProfileSectionNames` and `WritePrivateProfileSection` and corresponding `Kernel32Util` helpers - [@quipsy-karg](https://github.com/quipsy-karg).
* [#287](https://github.com/twall/jna/pull/287): Added `DBTF_MEDIA` and `DBTF_NET` to `com.sun.jna.platform.win32.DBT` - [@daifei4321](https://github.com/daifei4321).
* [#295](https://github.com/twall/jna/pull/295): Added `com.sun.jna.platform.win32.Kernel32.ResetEvent` - [@manithree](https://github.com/manithree).

Bug Fixes
---------
Expand Down
14 changes: 13 additions & 1 deletion contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,18 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes,
*/
boolean SetEvent(HANDLE hEvent);

/**
* Resets (to non-signaled state) the specified event object.
*
* @param hEvent
* A handle to the event object
*
* @return If the function succeeds, the return value is nonzero.
* If the function fails the return value is zero. To get
* extended error information, call GetLastError.
*/
boolean ResetEvent(HANDLE hEvent);

/**
* Sets the specified event object to the signaled state and then resets it
* to the nonsignaled state after releasing the appropriate number of
Expand Down Expand Up @@ -2042,4 +2054,4 @@ boolean WritePrivateProfileString(String lpAppName, String lpKeyName,
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
*/
boolean WritePrivateProfileSection(String lpAppName, String lpString, String lpFileName);
}
}
21 changes: 21 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ public void testWaitForSingleObject() {
Kernel32.INSTANCE.CloseHandle(handle);
}

public void testResetEvent() {
HANDLE handle = Kernel32.INSTANCE.CreateEvent(null, true, false, null);

// set the event to the signaled state
Kernel32.INSTANCE.SetEvent(handle);

// This should return successfully
assertEquals(WinBase.WAIT_OBJECT_0, Kernel32.INSTANCE.WaitForSingleObject(
handle, 1000));

// now reset it to not signaled
Kernel32.INSTANCE.ResetEvent(handle);

// handle runs into timeout since it is not triggered
// WAIT_TIMEOUT = 0x00000102
assertEquals(WinError.WAIT_TIMEOUT, Kernel32.INSTANCE.WaitForSingleObject(
handle, 1000));

Kernel32.INSTANCE.CloseHandle(handle);
}

public void testWaitForMultipleObjects(){
HANDLE[] handles = new HANDLE[2];

Expand Down

0 comments on commit 35c743d

Please sign in to comment.