add pdhConnectMachine
This commit is contained in:
parent
02f67cbd73
commit
15053e98ac
@ -9,6 +9,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef PDH_ACCESS_DENIED
|
||||
#define PDH_ACCESS_DENIED ((DWORD)0xC0000BDBL)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Hack around not being able to format error codes using
|
||||
* FORMAT_MESSAGE_FROM_HMODULE. We only define the error
|
||||
@ -38,11 +42,27 @@ static char *get_error_message(PDH_STATUS status) {
|
||||
case PDH_FUNCTION_NOT_FOUND:
|
||||
return "The calculation function for this counter could not "
|
||||
"be determined";
|
||||
case PDH_ACCESS_DENIED:
|
||||
return "Access denied";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhConnectMachine)
|
||||
(JNIEnv *env, jobject cur, jstring jhost)
|
||||
{
|
||||
PDH_STATUS status;
|
||||
LPCTSTR host = JENV->GetStringUTFChars(env, jhost, NULL);
|
||||
|
||||
status = PdhConnectMachine(host);
|
||||
JENV->ReleaseStringUTFChars(env, jhost, host);
|
||||
|
||||
if (status != ERROR_SUCCESS) {
|
||||
win32_throw_exception(env, get_error_message(status));
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL SIGAR_JNI(win32_Pdh_pdhOpenQuery)
|
||||
(JNIEnv *env, jobject cur)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||
public class Pdh extends Win32Bindings {
|
||||
|
||||
private long h_query; // Handle to the query
|
||||
private String hostname; // Not yet supported
|
||||
private String hostname = null;
|
||||
|
||||
private String counterPath;
|
||||
private long h_counter = -1l; // Handle to the counter
|
||||
@ -41,6 +41,9 @@ public class Pdh extends Win32Bindings {
|
||||
}
|
||||
|
||||
public double getSingleValue(String cp) throws Win32Exception {
|
||||
if (this.hostname != null) {
|
||||
pdhConnectMachine(this.hostname);
|
||||
}
|
||||
setCounterPath(cp);
|
||||
return getSingleValue();
|
||||
}
|
||||
@ -76,6 +79,8 @@ public class Pdh extends Win32Bindings {
|
||||
this.counterPath = cp;
|
||||
}
|
||||
|
||||
private static final native void pdhConnectMachine(String host)
|
||||
throws Win32Exception;
|
||||
private static final native long pdhOpenQuery() throws Win32Exception;
|
||||
private static final native void pdhCloseQuery(long query)
|
||||
throws Win32Exception;
|
||||
|
Loading…
Reference in New Issue
Block a user