use jsigar_list

This commit is contained in:
Doug MacEachern 2008-03-26 16:49:25 +00:00
parent 4b77f0f1f4
commit d98b62dc9e

View File

@ -774,57 +774,27 @@ JNIEXPORT jstring SIGAR_JNI(ProcEnv_getValue)
return get.val; return get.val;
} }
typedef struct {
JNIEnv *env;
jobject listobj;
jmethodID id;
} jni_proc_module_t;
static int jni_proc_module_get(void *data,
char *name, int len)
{
jni_proc_module_t *module = (jni_proc_module_t *)data;
JNIEnv *env = module->env;
JENV->CallBooleanMethod(env, module->listobj, module->id,
JENV->NewStringUTF(env, name));
return SIGAR_OK;
}
JNIEXPORT jobject SIGAR_JNIx(getProcModulesNative) JNIEXPORT jobject SIGAR_JNIx(getProcModulesNative)
(JNIEnv *env, jobject sigar_obj, jlong pid) (JNIEnv *env, jobject sigar_obj, jlong pid)
{ {
int status; int status;
sigar_proc_modules_t procmods; sigar_proc_modules_t procmods;
jobject listobj; jsigar_list_t obj;
jni_proc_module_t module;
jclass listclass =
JENV->FindClass(env, "java/util/ArrayList");
jmethodID listid =
JENV->GetMethodID(env, listclass, "<init>", "()V");
jmethodID addid =
JENV->GetMethodID(env, listclass, "add",
"(Ljava/lang/Object;)"
"Z");
dSIGAR(NULL); dSIGAR(NULL);
listobj = JENV->NewObject(env, listclass, listid); jsigar_list_init(env, &obj);
module.env = env; procmods.module_getter = jsigar_list_add;
module.id = addid; procmods.data = &obj;
module.listobj = listobj;
procmods.module_getter = jni_proc_module_get;
procmods.data = &module;
if ((status = sigar_proc_modules_get(sigar, pid, &procmods)) != SIGAR_OK) { if ((status = sigar_proc_modules_get(sigar, pid, &procmods)) != SIGAR_OK) {
JENV->DeleteLocalRef(env, listobj); JENV->DeleteLocalRef(env, obj.obj);
sigar_throw_error(env, jsigar, status); sigar_throw_error(env, jsigar, status);
return NULL; return NULL;
} }
return listobj; return obj.obj;
} }
JNIEXPORT jdoubleArray SIGAR_JNIx(getLoadAverage) JNIEXPORT jdoubleArray SIGAR_JNIx(getLoadAverage)