From: zy.jiang <ja...@gm...> - 2008-03-21 11:50:53
|
Hi all: i have a function like this: int *request_computer_list* (struct computer **computer, uint16_t who); i want to access the "*struct computer ***" with "*computer[]*" in java , so i make some typemaps : *%typemap(jni) struct computer** "jobjectArray" %typemap(javain) struct computer** "$javainput" %typemap(jtype) struct computer** "computer[]" %typemap(jstype) struct computer** "computer[]" %typemap(javaout) struct computer** { return $jnicall; } %typemap(in) struct computer **computer (struct computer *computer) { $1 = &computer; } %typemap(argout) struct computer** { int i; jclass clazz = (*jenv)->FindClass(jenv,"lib/computer"); jobject temp_obj; jmethodID cid=(*jenv)->GetMethodID(jenv,clazz, "<init>", "()V"); if(cid==NULL) return 0; for (i=0; i<result; i++) { temp_obj = (*jenv)->NewObject(jenv,clazz,cid,(jobject*)*arg1); (*jenv)->SetObjectArrayElement(jenv,jarg1, i,temp_obj); } } and the XX_wrap.c like this: SWIGEXPORT jint JNICALL Java_lib_drqueueJNI_request_1computer_1list(JNIEnv *jenv, jclass jcls, jobjectArray jarg1, jint jarg2) { jint jresult = 0 ; struct computer **arg1 = (struct computer **) 0 ; uint16_t arg2 ; int result; struct computer *computer1 ; (void)jenv; (void)jcls; { arg1 = &computer1; } arg2 = (uint16_t)jarg2; result = (int)request_computer_list(arg1,arg2); jresult = (jint)result; { int i; jclass clazz = (*jenv)->FindClass(jenv,"lib/computer"); jobject temp_obj; jmethodID cid=(*jenv)->GetMethodID(jenv,clazz, "<init>", "()V"); if(cid==NULL) return 0; for (i=0; i<result; i++) { temp_obj = (*jenv)->NewObject(jenv,clazz,cid,(jobject*)*arg1); arg1++; (*jenv)->SetObjectArrayElement(jenv,jarg1, i,temp_obj); } } return jresult; } *but when i use the out parameter "*struct computer **computer*" in java ,i cann't get right results from the "computer[]". so ,anybody can tell me what's wrong with it? also if you know about the good way to wrap pointer to pointer for java,please email to me! thanks in advance! |