From 5cd9bfd25ee3e09fc448104430f92ba420e2c9cd Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 26 Jun 2005 00:50:08 +0000 Subject: [PATCH] move GetLastError and GetErrorMessage to base class --- bindings/java/src/jni/win32/service.cpp | 23 ------------------- bindings/java/src/jni/win32/util.c | 23 +++++++++++++++++++ .../src/net/hyperic/sigar/win32/Service.java | 4 ---- .../src/net/hyperic/sigar/win32/Win32.java | 5 ++++ 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/bindings/java/src/jni/win32/service.cpp b/bindings/java/src/jni/win32/service.cpp index c7a3cc16..ed5308d1 100644 --- a/bindings/java/src/jni/win32/service.cpp +++ b/bindings/java/src/jni/win32/service.cpp @@ -262,29 +262,6 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_DeleteService) return DeleteService((SC_HANDLE)handle); } -JNIEXPORT jstring SIGAR_JNI(win32_Service_GetErrorMessage) -(JNIEnv *env, jclass, jint error) -{ - LPTSTR lpMsg; - - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| - FORMAT_MESSAGE_IGNORE_INSERTS| - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error, - MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), - (LPTSTR)&lpMsg, 0, NULL); - return env->NewString((const jchar *)lpMsg, lstrlen(lpMsg)); -} - -/** - * XXX: this should probablly be moved into a util class - */ -JNIEXPORT jint SIGAR_JNI(win32_Service_GetLastError) -(JNIEnv *, jclass) -{ - return GetLastError(); -} - JNIEXPORT jlong SIGAR_JNI(win32_Service_OpenSCManager) (JNIEnv *env, jclass, jstring machine, jint access) { diff --git a/bindings/java/src/jni/win32/util.c b/bindings/java/src/jni/win32/util.c index d4f5625b..3f52a575 100644 --- a/bindings/java/src/jni/win32/util.c +++ b/bindings/java/src/jni/win32/util.c @@ -1,4 +1,7 @@ #ifdef WIN32 +#define UNICODE +#define _UNICODE + #include #include @@ -19,6 +22,26 @@ void win32_throw_exception(JNIEnv *env, char *msg) JENV->ThrowNew(env, exceptionClass, msg); } +JNIEXPORT jint SIGAR_JNI(win32_Win32_GetLastError) +(JNIEnv *env, jclass cls) +{ + return GetLastError(); +} + +JNIEXPORT jstring SIGAR_JNI(win32_Win32_GetErrorMessage) +(JNIEnv *env, jclass cls, jint error) +{ + LPTSTR msg; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| + FORMAT_MESSAGE_IGNORE_INSERTS| + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, error, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + (LPTSTR)&msg, 0, NULL); + return JENV->NewString(env, (const jchar *)msg, lstrlen(msg)); +} + #ifdef __cplusplus } #endif diff --git a/bindings/java/src/net/hyperic/sigar/win32/Service.java b/bindings/java/src/net/hyperic/sigar/win32/Service.java index bdb45492..6d3320db 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/Service.java +++ b/bindings/java/src/net/hyperic/sigar/win32/Service.java @@ -330,10 +330,6 @@ public class Service extends Win32 { private static native boolean DeleteService(long handle); - private static native String GetErrorMessage(int error); - - private static native int GetLastError(); - private static native long OpenSCManager(String machine, int access); diff --git a/bindings/java/src/net/hyperic/sigar/win32/Win32.java b/bindings/java/src/net/hyperic/sigar/win32/Win32.java index f27a194e..157c4b75 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/Win32.java +++ b/bindings/java/src/net/hyperic/sigar/win32/Win32.java @@ -12,4 +12,9 @@ abstract class Win32 { } } + + static native String GetErrorMessage(int error); + + static native int GetLastError(); + }