bring back ServiceConfig.argv

This commit is contained in:
Doug MacEachern 2008-03-27 21:06:19 +00:00
parent 0b876faf31
commit 7579374e47
2 changed files with 33 additions and 9 deletions

View File

@ -7,12 +7,14 @@
#include "sigar.h"
#include "sigar_private.h"
#include "sigar_os.h"
#include <shellapi.h>
#ifdef __cplusplus
extern "C" {
#endif
#define STRING_SIG "Ljava/lang/String;"
#define ASTRING_SIG "[" STRING_SIG
#define SERVICE_SetStringField(field, str) \
id = env->GetFieldID(cls, field, STRING_SIG); \
@ -307,6 +309,10 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
jclass cls = env->GetObjectClass(obj);
jstring value;
HINSTANCE lib;
LPWSTR *argv;
int argc;
jclass stringclass =
env->FindClass("java/lang/String");
if (!QueryServiceConfig((SC_HANDLE)handle, config,
sizeof(buffer), &bytes))
@ -323,12 +329,22 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
SERVICE_SetStringField("path", config->lpBinaryPathName);
SIGAR_W2A(config->lpBinaryPathName, exe, sizeof(exe));
ptr = sigar_service_exe_get(NULL, exe, 0);
if ((argv = CommandLineToArgvW(config->lpBinaryPathName, &argc))) {
int i;
jobjectArray jargv =
env->NewObjectArray(argc, stringclass, 0);
env->SetObjectField(obj,
env->GetFieldID(cls, "exe", STRING_SIG),
env->NewStringUTF(ptr));
for (i=0; i<argc; i++) {
jstring jstr =
env->NewString((const jchar *)argv[i], lstrlen(argv[i]));
env->SetObjectArrayElement(jargv, i, jstr);
}
id = env->GetFieldID(cls, "argv", ASTRING_SIG);
env->SetObjectField(obj, id, jargv);
LocalFree(argv);
}
SERVICE_SetStringField("loadOrderGroup", config->lpLoadOrderGroup);
@ -337,15 +353,12 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
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);
id = env->GetFieldID(cls, "dependencies", ASTRING_SIG);
env->SetObjectField(obj, id, dependencies);
}

View File

@ -108,6 +108,7 @@ public class ServiceConfig {
int errorControl;
String path;
String exe;
String[] argv;
String loadOrderGroup;
int tagId;
String[] dependencies;
@ -143,7 +144,17 @@ public class ServiceConfig {
this.path = path;
}
public String[] getArgv() {
return this.argv;
}
public String getExe() {
if (this.exe == null) {
String[] argv = getArgv();
if ((argv != null) && (argv.length != 0)) {
this.exe = argv[0];
}
}
return this.exe;
}