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; }