📄 logformat_trace_inputlog.c
字号:
if ( ierr != 0 ) { fprintf( errfile, "Error: %s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); return NULL; } /* Prepare various arrays for C data */ title_name = (char *) malloc( max_title_name * sizeof(char) ); column_names = (char **) malloc( (ncolumns-1) * sizeof(char *) ); for ( icol = 0; icol < ncolumns-1; icol++ ) column_names[ icol ] = (char *) malloc( max_column_name * sizeof(char) ); coordmap_max = nrows * ncolumns; coordmap_base = (int *) malloc( coordmap_max * sizeof( int ) ); coordmap_sz = 0; coordmap_pos = 0; methods_pos = 0; if ( methods_sz > 0 ) { methods_max = methods_sz; methods_base = (int *) malloc( methods_max * sizeof( int ) ); } else methods_base = NULL; ierr = TRACE_Get_next_ycoordmap( tracefile, title_name, column_names, &coordmap_sz, coordmap_base, &coordmap_pos, coordmap_max, &methods_sz, methods_base, &methods_pos, methods_max ); if ( ierr != 0 ) { fprintf( errfile, "Error: %s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); if ( coordmap_base != NULL ) free( coordmap_base ); if ( title_name != NULL ) free( title_name ); if ( column_names != NULL ) { for ( icol = 0; icol < ncolumns-1; icol++ ) if ( column_names[ icol ] != NULL ) free( column_names[ icol ] ); free( column_names ); } if ( methods_base != NULL ) free( methods_base ); return NULL; } /* Title Label String */ jtitle = (*env)->NewStringUTF( env, title_name ); /* Cache String class as a Global Reference */ if ( cid4String == NULL ) { cid_local = (*env)->FindClass( env, "java/lang/String" ); if ( cid_local != NULL ) { cid4String = (*env)->NewGlobalRef( env, cid_local ); (*env)->DeleteLocalRef( env, cid_local ); /* avoid mem leak */ } } /* Column Label String[ num_column - 1 ] */ jcolnames = (*env)->NewObjectArray( env, ncolumns - 1, cid4String, NULL ); for ( icol = 0; icol < ncolumns-1; icol++ ) { jcolname = (*env)->NewStringUTF( env, column_names[ icol ] ); (*env)->SetObjectArrayElement( env, jcolnames, icol, jcolname ); } /* YCoordMap element: int[] */ if ( coordmap_pos > 0 ) { j_coordmap_elems = (*env)->NewIntArray( env, coordmap_sz ); (*env)->SetIntArrayRegion( env, j_coordmap_elems, 0, coordmap_sz, (jint *) coordmap_base ); } else j_coordmap_elems = NULL; /* MethodID elements: int[] */ if ( methods_base != NULL && methods_pos > 0 ) { jmethods = (*env)->NewIntArray( env, methods_sz ); (*env)->SetIntArrayRegion( env, jmethods, 0, methods_sz, (jint *) methods_base ); } else jmethods = NULL; /* Cache YCoordMap Class's constructor as a Global Reference */ if ( cid4YMap == NULL ) { cid_local = (*env)->FindClass( env, "base/drawable/YCoordMap" ); if ( cid_local != NULL ) { cid4YMap = (*env)->NewGlobalRef( env, cid_local ); (*env)->DeleteLocalRef( env, cid_local ); /* avoid mem leak */ mid4NewYMap = (*env)->GetMethodID( env, cid4YMap, "<init>", "(IILjava/lang/String;[Ljava/lang/String;[I[I)V" ); } } /* Call YCoordMap's constructor */ ycoordmap = (*env)->NewObject( env, cid4YMap, mid4NewYMap, (jint) nrows, (jint) ncolumns, jtitle, jcolnames, j_coordmap_elems, jmethods ); /* Clean up the unused reference and free local memory */ if ( coordmap_pos > 0 ) (*env)->DeleteLocalRef( env, j_coordmap_elems ); if ( coordmap_base != NULL ) free( coordmap_base ); if ( title_name != NULL ) free( title_name ); if ( column_names != NULL ) { for ( icol = 0; icol < ncolumns-1; icol++ ) if ( column_names[ icol ] != NULL ) free( column_names[ icol ] ); free( column_names ); } if ( jmethods != NULL ) (*env)->DeleteLocalRef( env, jmethods ); if ( methods_base != NULL ) free( methods_base ); return ycoordmap;}JNIEXPORT jobject JNICALL Java_logformat_trace_InputLog_getNextPrimitive( JNIEnv *env, jobject this ){ TRACE_file tracefile; jlong filehandle; double starttime, endtime; int type_idx; int tcoord_sz, tcoord_pos, tcoord_max; double *tcoord_base; jdoubleArray j_tcoords; int ycoord_sz, ycoord_pos, ycoord_max; int *ycoord_base; jintArray j_ycoords; int info_sz, info_pos, info_max; char *info_base; jbyteArray j_infos; jclass cid_local; jobject prime; int ierr; double stcoord_base[ADOUBLE_LENGTH]; int sycoord_base[AINT_LENGTH]; char sinfo_base[ACHAR_LENGTH]; filehandle = (*env)->GetLongField( env, this, fid4filehandle ); if ( filehandle == 0 ) { fprintf( errfile, "Java_logformat_trace_InputLog_getNextPrimitive(): " "Inaccessible filehandle in Java side\n" ); return NULL; } tracefile = (TRACE_file) filehandle; tcoord_sz = 0; ycoord_sz = 0; info_sz = 0; ierr = TRACE_Peek_next_primitive( tracefile, &starttime, &endtime, &tcoord_sz, &ycoord_sz, &info_sz ); if ( ierr != 0 || ( tcoord_sz <= 0 || ycoord_sz <= 0 ) ) { fprintf( errfile, "%s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); return NULL; } tcoord_pos = 0; tcoord_max = tcoord_sz; if (tcoord_max > ADOUBLE_LENGTH) tcoord_base = (double *) malloc( tcoord_max * sizeof( double ) ); else tcoord_base = stcoord_base; ycoord_pos = 0; ycoord_max = ycoord_sz; if (ycoord_max > AINT_LENGTH) ycoord_base = (int *) malloc( ycoord_max * sizeof( int ) ); else ycoord_base = sycoord_base; info_pos = 0; info_max = info_sz; if (info_max > AINT_LENGTH) info_base = (char *) malloc( info_max * sizeof( char ) ); else info_base = sinfo_base; ierr = TRACE_Get_next_primitive( tracefile, &type_idx, &tcoord_sz, tcoord_base, &tcoord_pos, tcoord_max, &ycoord_sz, ycoord_base, &ycoord_pos, ycoord_max, &info_sz, info_base, &info_pos, info_max ); if ( ierr != 0 || ( tcoord_pos <= 0 || ycoord_pos <= 0 ) ) { fprintf( errfile, "%s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); if ( tcoord_base != NULL && tcoord_base != stcoord_base ) free( tcoord_base ); if ( ycoord_base != NULL && ycoord_base != sycoord_base ) free( ycoord_base ); if ( info_base != NULL && info_base != sinfo_base ) free( info_base ); return NULL; } /* Obtain primitive array references for calling Dobj's constructor */ if ( tcoord_pos > 0 ) { j_tcoords = (*env)->NewDoubleArray( env, tcoord_sz ); (*env)->SetDoubleArrayRegion( env, j_tcoords, 0, tcoord_sz, tcoord_base ); } else j_tcoords = NULL; if ( ycoord_pos > 0 ) { j_ycoords = (*env)->NewIntArray( env, ycoord_sz ); (*env)->SetIntArrayRegion( env, j_ycoords, 0, ycoord_sz, (jint *) ycoord_base ); } else j_ycoords = NULL; if ( info_pos > 0 ) { j_infos = (*env)->NewByteArray( env, info_sz ); (*env)->SetByteArrayRegion( env, j_infos, 0, info_sz, (jbyte *) info_base ); } else j_infos = NULL; /* Cache Primitive Class's constructor as a Global Reference */ if ( cid4Prime == NULL ) { cid_local = (*env)->FindClass( env, "base/drawable/Primitive" ); if ( cid_local != NULL ) { cid4Prime = (*env)->NewGlobalRef( env, cid_local ); (*env)->DeleteLocalRef( env, cid_local ); /* avoid mem leak */ mid4NewPrime = (*env)->GetMethodID( env, cid4Prime, "<init>", "(IDD[D[I[B)V" ); } } /* Call Primitive's constructor */ prime = (*env)->NewObject( env, cid4Prime, mid4NewPrime, type_idx, starttime, endtime, j_tcoords, j_ycoords, j_infos ); /* Clean up the unused reference and free local memory */ if ( tcoord_pos > 0 ) (*env)->DeleteLocalRef( env, j_tcoords ); if ( tcoord_base != NULL && tcoord_base != stcoord_base ) free( tcoord_base ); if ( ycoord_pos > 0 ) (*env)->DeleteLocalRef( env, j_ycoords ); if ( ycoord_base != NULL && ycoord_base != sycoord_base ) free( ycoord_base ); if ( info_pos > 0 ) (*env)->DeleteLocalRef( env, j_infos ); if ( info_base != NULL && info_base != sinfo_base ) free( info_base ); return prime;}JNIEXPORT jobject JNICALL Java_logformat_trace_InputLog_getNextComposite( JNIEnv *env, jobject this ){ TRACE_file tracefile; jlong filehandle; double cmplx_starttime, cmplx_endtime; int cmplx_type_idx; int n_primitives; int cm_info_sz, cm_info_pos, cm_info_max; char *cm_info_base; jbyteArray j_cm_infos; jobjectArray primes; jobject prime; jobject cmplx; jclass cid_local; int idx, ierr; filehandle = (*env)->GetLongField( env, this, fid4filehandle ); if ( filehandle == 0 ) { fprintf( errfile, "Java_logformat_trace_InputLog_getNextComposite(): " "Inaccessible filehandle in Java side\n" ); return NULL; } tracefile = (TRACE_file) filehandle; cm_info_sz = 0; ierr = TRACE_Peek_next_composite( tracefile, &cmplx_starttime, &cmplx_endtime, &n_primitives, &cm_info_sz ); if ( ierr != 0 ) { fprintf( errfile, "%s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); return NULL; } /* return when there is no primitives */ if ( n_primitives <= 0 ) return NULL; j_cm_infos = NULL; if ( cm_info_sz > 0 ) { cm_info_pos = 0; cm_info_max = cm_info_sz; cm_info_base = (char *) malloc( cm_info_max * sizeof( char ) ); ierr = TRACE_Get_next_composite( tracefile, &cmplx_type_idx, &cm_info_sz, cm_info_base, &cm_info_pos, cm_info_max ); if ( ierr != 0 ) { fprintf( errfile, "%s\n", TRACE_Get_err_string( ierr ) ); fflush( errfile ); return NULL; } if ( cm_info_pos > 0 ) { j_cm_infos = (*env)->NewByteArray( env, cm_info_sz ); (*env)->SetByteArrayRegion( env, j_cm_infos, 0, cm_info_sz, (jbyte *) cm_info_base ); } else j_cm_infos = NULL; } /* Cache Primitive Class's constructor as a Global Reference */ if ( cid4Prime == NULL ) { cid_local = (*env)->FindClass( env, "base/drawable/Primitive" ); if ( cid_local != NULL ) { cid4Prime = (*env)->NewGlobalRef( env, cid_local ); (*env)->DeleteLocalRef( env, cid_local ); /* avoid mem leak */ mid4NewPrime = (*env)->GetMethodID( env, cid4Prime, "<init>", "(IDD[D[I[B)V" ); } } /* Create Primitives[] */ primes = (*env)->NewObjectArray( env, n_primitives, cid4Prime, NULL ); if ( primes == NULL ) return NULL; /* Create the Primitive[] inside the Composite from the TRACE */ for ( idx = 0; idx < n_primitives; idx++ ) { prime = Java_logformat_trace_InputLog_getNextPrimitive( env, this ); (*env)->SetObjectArrayElement( env, primes, idx, prime ); } /* Cache Composite Class's constructor as a Global Reference */ if ( cid4Cmplx == NULL ) { cid_local = (*env)->FindClass( env, "base/drawable/Composite" ); if ( cid_local != NULL ) { cid4Cmplx = (*env)->NewGlobalRef( env, cid_local ); (*env)->DeleteLocalRef( env, cid_local ); /* avoid mem leak */ mid4NewCmplx = (*env)->GetMethodID( env, cid4Cmplx, "<init>", "(IDD[Lbase/drawable/Primitive;[B)V" ); } } /* Invoke the Composite's constructor */ cmplx = (*env)->NewObject( env, cid4Cmplx, mid4NewCmplx, cmplx_type_idx, cmplx_starttime, cmplx_endtime, primes, j_cm_infos ); /* Clean up the unused reference and free local memory */ if ( cm_info_sz > 0 && cm_info_pos > 0 ) (*env)->DeleteLocalRef( env, j_cm_infos ); if ( cm_info_base != NULL ) free( cm_info_base ); return cmplx;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -