From 2896feb9831654b952b3499343d0eb8bd0c9974b Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 14 Aug 2004 00:40:37 +0000 Subject: [PATCH] move getServicePid to the Sigar class so we get caching via SigarProxy --- bindings/java/src/jni/javasigar.c | 10 ++++------ bindings/java/src/net/hyperic/sigar/Sigar.java | 8 ++++++++ bindings/java/src/net/hyperic/sigar/SigarProxy.java | 2 ++ .../net/hyperic/sigar/ptql/WindowsServiceQuery.java | 6 ++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bindings/java/src/jni/javasigar.c b/bindings/java/src/jni/javasigar.c index 2da5a03c..307f0710 100644 --- a/bindings/java/src/jni/javasigar.c +++ b/bindings/java/src/jni/javasigar.c @@ -1054,8 +1054,8 @@ typedef BOOL (CALLBACK *QueryServiceStatusExFunc)(SC_HANDLE, LPDWORD); #endif -JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid) -(JNIEnv *env, jclass classinstance, jstring jname) +JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid) +(JNIEnv *env, jobject sigar_obj, jstring jname) { #ifdef WIN32 const char *name; @@ -1063,6 +1063,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid) jlong pid = 0; DWORD err = ERROR_SUCCESS; SC_HANDLE mgr; + dSIGAR(0); name = JENV->GetStringUTFChars(env, jname, &is_copy); @@ -1118,10 +1119,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid) } if (err != ERROR_SUCCESS) { - /* XXX need sigar for sigar_strerror */ - char msg[256]; - sprintf(msg, "error=%d", err); - sigar_throw_exception(env, msg); + sigar_throw_error(env, sigar, err); } return pid; diff --git a/bindings/java/src/net/hyperic/sigar/Sigar.java b/bindings/java/src/net/hyperic/sigar/Sigar.java index d9f70e1f..56073440 100644 --- a/bindings/java/src/net/hyperic/sigar/Sigar.java +++ b/bindings/java/src/net/hyperic/sigar/Sigar.java @@ -125,6 +125,14 @@ public class Sigar implements SigarProxy { */ public native long getPid(); + + /** + * Get pid for the Windows service with the given name. + * This method is implemented on Windows only as a helper + * for PTQL. + */ + public native long getServicePid(String name); + /** * Send a signal to a process. * diff --git a/bindings/java/src/net/hyperic/sigar/SigarProxy.java b/bindings/java/src/net/hyperic/sigar/SigarProxy.java index 7f5e3bb4..278655b7 100644 --- a/bindings/java/src/net/hyperic/sigar/SigarProxy.java +++ b/bindings/java/src/net/hyperic/sigar/SigarProxy.java @@ -13,6 +13,8 @@ public interface SigarProxy { public long getPid(); + public long getServicePid(String name); + public Mem getMem() throws SigarException; public Swap getSwap() throws SigarException; diff --git a/bindings/java/src/net/hyperic/sigar/ptql/WindowsServiceQuery.java b/bindings/java/src/net/hyperic/sigar/ptql/WindowsServiceQuery.java index b2909569..e3fb2a31 100644 --- a/bindings/java/src/net/hyperic/sigar/ptql/WindowsServiceQuery.java +++ b/bindings/java/src/net/hyperic/sigar/ptql/WindowsServiceQuery.java @@ -8,8 +8,6 @@ public class WindowsServiceQuery implements ProcessQuery { private String name; - public static native long getServicePid(String name); - public WindowsServiceQuery(String name) { this.name = name; } @@ -17,11 +15,11 @@ public class WindowsServiceQuery implements ProcessQuery { public boolean match(SigarProxy sigar, long pid) throws SigarException { - return pid == getServicePid(this.name); + return pid == sigar.getServicePid(this.name); } public static void main(String[] args) throws Exception { Sigar sigar = new Sigar(); //load the .dll - System.out.println(getServicePid(args[0])); + System.out.println(sigar.getServicePid(args[0])); } }