From c2296865e23211ccdab6d6b4a211b90b34bf675f Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 5 Mar 2007 21:24:03 +0000 Subject: [PATCH] add PdhValidatePath wrapper --- bindings/java/src/jni/win32/pdh.c | 15 +++++++++++++++ .../java/src/org/hyperic/sigar/win32/Pdh.java | 2 ++ .../src/org/hyperic/sigar/win32/test/TestPdh.java | 13 +++---------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bindings/java/src/jni/win32/pdh.c b/bindings/java/src/jni/win32/pdh.c index 405220ab..5ecfb79f 100644 --- a/bindings/java/src/jni/win32/pdh.c +++ b/bindings/java/src/jni/win32/pdh.c @@ -70,6 +70,21 @@ static char *get_error_message(PDH_STATUS status) { } } +JNIEXPORT jlong SIGAR_JNI(win32_Pdh_validate) +(JNIEnv *env, jclass cur, jstring jpath) +{ + PDH_STATUS status; + jboolean is_copy; + LPCTSTR path = JENV->GetStringChars(env, jpath, &is_copy); + + status = PdhValidatePath(path); + if (is_copy) { + JENV->ReleaseStringChars(env, jpath, path); + } + + return status; +} + JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhConnectMachine) (JNIEnv *env, jobject cur, jstring jhost) { diff --git a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java index 5ef6d356..4d823944 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Pdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Pdh.java @@ -243,6 +243,8 @@ public class Pdh extends Win32 { return pdhGetObjects(); } + public static final native long validate(String path); + private static final native void pdhConnectMachine(String host) throws Win32Exception; private static final native long pdhOpenQuery() throws Win32Exception; diff --git a/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java b/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java index 767ff3f3..a9bc2972 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java +++ b/bindings/java/src/org/hyperic/sigar/win32/test/TestPdh.java @@ -58,19 +58,12 @@ public class TestPdh extends SigarTestCase { if (!trans.equals(path)) { traceln(path + "-->" + trans); } - + traceln(path + " validate: " + Pdh.validate(path)); getValue(path); } - /* XXX hangs for a while on my XP box + String bogusKey = "\\Does Not\\Exist"; - try { - new Pdh().getRawValue(bogusKey); - assertTrue(false); - } catch (Win32Exception e) { - assertTrue(true); - traceln(bogusKey + "=" + e.getMessage()); - } - */ + assertTrue(Pdh.validate(bogusKey) != 0); } public void testCounterMap() throws Exception {