add PdhValidatePath wrapper

This commit is contained in:
Doug MacEachern 2007-03-05 21:24:03 +00:00
parent 98fd0fdbcc
commit c2296865e2
3 changed files with 20 additions and 10 deletions

View File

@ -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) JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhConnectMachine)
(JNIEnv *env, jobject cur, jstring jhost) (JNIEnv *env, jobject cur, jstring jhost)
{ {

View File

@ -243,6 +243,8 @@ public class Pdh extends Win32 {
return pdhGetObjects(); return pdhGetObjects();
} }
public static final native long validate(String path);
private static final native void pdhConnectMachine(String host) private static final native void pdhConnectMachine(String host)
throws Win32Exception; throws Win32Exception;
private static final native long pdhOpenQuery() throws Win32Exception; private static final native long pdhOpenQuery() throws Win32Exception;

View File

@ -58,19 +58,12 @@ public class TestPdh extends SigarTestCase {
if (!trans.equals(path)) { if (!trans.equals(path)) {
traceln(path + "-->" + trans); traceln(path + "-->" + trans);
} }
traceln(path + " validate: " + Pdh.validate(path));
getValue(path); getValue(path);
} }
/* XXX hangs for a while on my XP box
String bogusKey = "\\Does Not\\Exist"; String bogusKey = "\\Does Not\\Exist";
try { assertTrue(Pdh.validate(bogusKey) != 0);
new Pdh().getRawValue(bogusKey);
assertTrue(false);
} catch (Win32Exception e) {
assertTrue(true);
traceln(bogusKey + "=" + e.getMessage());
}
*/
} }
public void testCounterMap() throws Exception { public void testCounterMap() throws Exception {