From 4b4fc881a8a5d56d9f5b79a784b50ed02a98b734 Mon Sep 17 00:00:00 2001 From: dbwiddis Date: Sun, 29 Nov 2015 15:34:30 -0800 Subject: [PATCH] Add GetSystemTimes() to Kernel32 --- CHANGES.md | 1 + .../com/sun/jna/platform/win32/Kernel32.java | 26 +++++++++++++++++++ .../sun/jna/platform/win32/Kernel32Test.java | 16 ++++++++++++ 3 files changed, 43 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 96ae9d6079..7ea4ae7b45 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Features * [#535](https://github.com/java-native-access/jna/pull/535): Added `SHEmptyRecycleBin`, `ShellExecuteEx` to `com.sun.jna.platform.win32.Shell32` - [@mlfreeman2](https://github.com/mlfreeman2). * [#535](https://github.com/java-native-access/jna/pull/535): Added `GetDesktopWindow` to `com.sun.jna.platform.win32.User32` - [@mlfreeman2](https://github.com/mlfreeman2). * [#543](https://github.com/java-native-access/jna/pull/543): Added `ProcessIdToSessionId`, `LoadLibraryEx`, `FreeLibrary` and `Find/Load/Lock/SizeofResource` to `com.sun.jna.platform.win32.Kernel32` - [@mlfreeman2](https://github.com/mlfreeman2). +* [#547](https://github.com/java-native-access/jna/pull/547): Added `GetSystemTimes` to `com.sun.jna.platform.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis). Bug Fixes --------- diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java index ee663a264b..1bb7868359 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java @@ -181,6 +181,32 @@ boolean ReadFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToRead, */ boolean SetLocalTime(SYSTEMTIME lpSystemTime); + /** + * Retrieves system timing information. On a multiprocessor system, the + * values returned are the sum of the designated times across all + * processors. + * + * @param lpIdleTime + * A pointer to a {@link WinBase.FILETIME} structure that + * receives the amount of time that the system has been idle. + * @param lpKernelTime + * A pointer to a {@link WinBase.FILETIME} structure that + * receives the amount of time that the system has spent + * executing in Kernel mode (including all threads in all + * processes, on all processors). This time value also includes + * the amount of time the system has been idle. + * @param lpUserTime + * A pointer to a {@link WinBase.FILETIME} structure that + * receives the amount of time that the system has spent + * executing in User mode (including all threads in all + * processes, on all processors). + * @return {@code true} if the function succeeds, {@code false} otherwise. + * If the function fails, call {@link #GetLastError()} to get extended error + * information. + * @see GetSystemTimes documentation + */ + boolean GetSystemTimes(WinBase.FILETIME lpIdleTime, WinBase.FILETIME lpKernelTime, WinBase.FILETIME lpUserTime); + /** * The GetTickCount function retrieves the number of milliseconds that have * elapsed since the system was started, up to 49.7 days. diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java index b0661574ce..436a1050b5 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java @@ -384,6 +384,22 @@ public void testGetSystemInfo() { assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0); } + public void testGetSystemTimes() { + Kernel32 kernel = Kernel32.INSTANCE; + WinBase.FILETIME lpIdleTime = new WinBase.FILETIME(); + WinBase.FILETIME lpKernelTime = new WinBase.FILETIME(); + WinBase.FILETIME lpUserTime = new WinBase.FILETIME(); + boolean succ = kernel.GetSystemTimes(lpIdleTime, lpKernelTime, lpUserTime); + assertTrue(succ); + long idleTime = WinBase.FILETIME.dateToFileTime(lpIdleTime.toDate()); + long kernelTime = WinBase.FILETIME.dateToFileTime(lpKernelTime.toDate()); + long userTime = WinBase.FILETIME.dateToFileTime(lpUserTime.toDate()); + // All should be >= 0. kernel includes idle. + assertTrue(idleTime >= 0); + assertTrue(kernelTime >= idleTime); + assertTrue(userTime >= 0); + } + public void testIsWow64Process() { try { IntByReference isWow64 = new IntByReference(42);