use sigar_services_query

This commit is contained in:
Doug MacEachern 2008-03-26 17:06:54 +00:00
parent 7a3b9a8fe6
commit 3feb988e7e
1 changed files with 16 additions and 12 deletions

View File

@ -218,28 +218,32 @@ SIGAR_JNI(win32_Service_QueryServiceStatus)
return result; 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) JNIEXPORT jobject SIGAR_JNI(win32_Service_getServiceNames)
(JNIEnv *env, jclass) (JNIEnv *env, jclass)
{ {
DWORD i, status; DWORD status;
sigar_services_status_t ss;
jsigar_list_t obj; jsigar_list_t obj;
sigar_services_walker_t walker;
SIGAR_ZERO(&ss); walker.sigar = NULL;
status = sigar_services_status_get(&ss, SERVICE_STATE_ALL); walker.flags = SERVICE_STATE_ALL;
if (status != SIGAR_OK) { walker.data = &obj;
win32_throw_error(env, status); walker.add_service = jsigar_add_service;
return NULL;
}
jsigar_list_init(env, &obj); jsigar_list_init(env, &obj);
for (i=0; i<ss.count; i++) { status = sigar_services_query(NULL, NULL, &walker);
jsigar_list_add(&obj, (char *)ss.services[i].lpServiceName, -1); if (status != SIGAR_OK) {
env->DeleteLocalRef(obj.obj);
win32_throw_error(env, status);
return NULL;
} }
sigar_services_status_close(&ss);
return obj.obj; return obj.obj;
} }