diff --git a/bindings/java/src/jni/win32/service.cpp b/bindings/java/src/jni/win32/service.cpp index 3fe82a1c..516ba704 100644 --- a/bindings/java/src/jni/win32/service.cpp +++ b/bindings/java/src/jni/win32/service.cpp @@ -224,20 +224,37 @@ static int jsigar_add_service(sigar_services_walker_t *walker, char *name) } JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames) -(JNIEnv *env, jclass) +(JNIEnv *env, jclass, jobject sigar_obj, jstring jptql) { DWORD status; jsigar_list_t obj; + sigar_t *sigar = NULL; + char *ptql = NULL; sigar_services_walker_t walker; + jboolean is_copy; - walker.sigar = NULL; + if (sigar_obj) { + if (!(sigar = jsigar_get_sigar(env, sigar_obj))) { + return NULL; + } + } + if (jptql) { + ptql = (char *)env->GetStringUTFChars(jptql, &is_copy); + } + + walker.sigar = sigar; walker.flags = SERVICE_STATE_ALL; walker.data = &obj; walker.add_service = jsigar_add_service; jsigar_list_init(env, &obj); - status = sigar_services_query(NULL, NULL, &walker); + status = sigar_services_query(ptql, NULL, &walker); + + if (ptql && is_copy) { + env->ReleaseStringUTFChars(jptql, ptql); + } + if (status != SIGAR_OK) { env->DeleteLocalRef(obj.obj); win32_throw_error(env, status); diff --git a/bindings/java/src/org/hyperic/sigar/win32/Service.java b/bindings/java/src/org/hyperic/sigar/win32/Service.java index 724ef622..0c1d9975 100644 --- a/bindings/java/src/org/hyperic/sigar/win32/Service.java +++ b/bindings/java/src/org/hyperic/sigar/win32/Service.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.List; +import org.hyperic.sigar.Sigar; + public class Service extends Win32 { // Service State public static final int SERVICE_STOPPED = 0x00000001; @@ -103,7 +105,12 @@ public class Service extends Win32 { this.manager = OpenSCManager("", SC_MANAGER_ALL_ACCESS); } - public static native List getServiceNames() throws Win32Exception; + public static native List getServiceNames(Sigar sigar, String ptql) + throws Win32Exception; + + public static List getServiceNames() throws Win32Exception { + return getServiceNames(null, null); + } private static class ExeFilter implements FileFilter { private String name; @@ -422,6 +429,14 @@ public class Service extends Win32 { } return; } + else if ((args.length == 1) && (args[0].startsWith("Service."))) { + Sigar sigar = new Sigar(); + try { + services = Service.getServiceNames(sigar, args[0]); + } finally { + sigar.close(); + } + } else { services = Arrays.asList(args); }