From 5b87277a6f2881f5f78936caa0ae6b23c6109fb9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 26 Jun 2005 01:54:11 +0000 Subject: [PATCH] ServiceConfig.dependencies needs to be String[] --- bindings/java/src/jni/win32/service.cpp | 42 ++++++++++++++++++- .../src/net/hyperic/sigar/win32/Service.java | 5 +++ .../hyperic/sigar/win32/ServiceConfig.java | 9 ++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bindings/java/src/jni/win32/service.cpp b/bindings/java/src/jni/win32/service.cpp index d4eb12c4..68d1c02d 100644 --- a/bindings/java/src/jni/win32/service.cpp +++ b/bindings/java/src/jni/win32/service.cpp @@ -258,6 +258,32 @@ JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames) return listobj; } +/* + * convert: + * "RPCSS\0Tcpip\0IPSec\0\0" + * to: + * ["RPCSS", "Tcpip", "IPSec"] + */ +static int to_array(JNIEnv *env, LPTSTR str, jobjectArray array) +{ + TCHAR *ptr = &str[0]; + int offset=0, i=0; + + while (*ptr != 0) { + int slen = _tcslen(ptr); + if (array) { + jstring jstr = + env->NewString((const jchar *)ptr, slen); + env->SetObjectArrayElement(array, i, jstr); + } + offset += slen + 1; + ptr = &str[offset]; + i++; + } + + return i; +} + JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig) (JNIEnv *env, jclass, jlong handle, jobject obj) { @@ -286,7 +312,21 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig) SERVICE_SetIntField("tagId", config->dwTagId); - SERVICE_SetStringField("dependencies", config->lpDependencies); + if (config->lpDependencies) { + /* first pass just get num for NewObjectArray */ + int num = to_array(env, config->lpDependencies, NULL); + jclass stringclass = + env->FindClass("java/lang/String"); + jobjectArray dependencies = + env->NewObjectArray(num, stringclass, 0); + + to_array(env, config->lpDependencies, dependencies); + + id = env->GetFieldID(cls, "dependencies", + "[" STRING_SIG); + + env->SetObjectField(obj, id, dependencies); + } SERVICE_SetStringField("serviceStartName", config->lpServiceStartName); diff --git a/bindings/java/src/net/hyperic/sigar/win32/Service.java b/bindings/java/src/net/hyperic/sigar/win32/Service.java index 6d3320db..2be38f27 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/Service.java +++ b/bindings/java/src/net/hyperic/sigar/win32/Service.java @@ -1,5 +1,6 @@ package net.hyperic.sigar.win32; +import java.util.Arrays; import java.util.List; public class Service extends Win32 { @@ -355,6 +356,10 @@ public class Service extends Win32 { System.out.println("[" + name + "]" + "=" + "[" + config.getBinaryPathName() + "]"); + String[] deps = config.getDependencies(); + if (deps.length != 0) { + System.out.println(" deps..." + Arrays.asList(deps)); + } } } } diff --git a/bindings/java/src/net/hyperic/sigar/win32/ServiceConfig.java b/bindings/java/src/net/hyperic/sigar/win32/ServiceConfig.java index ec87a471..2a0a941b 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/ServiceConfig.java +++ b/bindings/java/src/net/hyperic/sigar/win32/ServiceConfig.java @@ -78,7 +78,7 @@ public class ServiceConfig { String binaryPathName; String loadOrderGroup; int tagId; - String dependencies; + String[] dependencies = null; String serviceStartName; String displayName; @@ -97,13 +97,16 @@ public class ServiceConfig { /** * @return Returns the dependencies. */ - public String getDependencies() { + public String[] getDependencies() { + if (this.dependencies == null) { + return new String[0]; + } return dependencies; } /** * @param dependencies The dependencies to set. */ - public void setDependencies(String dependencies) { + public void setDependencies(String[] dependencies) { this.dependencies = dependencies; } /**