ServiceConfig.dependencies needs to be String[]
This commit is contained in:
parent
5c9c3c6cf2
commit
5b87277a6f
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue