From 3feb988e7ed7d390b0b8b2b6c045ee72a86671b4 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 26 Mar 2008 17:06:54 +0000 Subject: [PATCH] use sigar_services_query --- bindings/java/src/jni/win32/service.cpp | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bindings/java/src/jni/win32/service.cpp b/bindings/java/src/jni/win32/service.cpp index 304b5721..3fe82a1c 100644 --- a/bindings/java/src/jni/win32/service.cpp +++ b/bindings/java/src/jni/win32/service.cpp @@ -218,28 +218,32 @@ SIGAR_JNI(win32_Service_QueryServiceStatus) return result; } +static int jsigar_add_service(sigar_services_walker_t *walker, char *name) +{ + return jsigar_list_add(walker->data, name, -1); +} + JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames) (JNIEnv *env, jclass) { - DWORD i, status; - sigar_services_status_t ss; + DWORD status; jsigar_list_t obj; + sigar_services_walker_t walker; - SIGAR_ZERO(&ss); - status = sigar_services_status_get(&ss, SERVICE_STATE_ALL); - if (status != SIGAR_OK) { - win32_throw_error(env, status); - return NULL; - } + walker.sigar = NULL; + walker.flags = SERVICE_STATE_ALL; + walker.data = &obj; + walker.add_service = jsigar_add_service; jsigar_list_init(env, &obj); - for (i=0; iDeleteLocalRef(obj.obj); + win32_throw_error(env, status); + return NULL; } - sigar_services_status_close(&ss); - return obj.obj; }