void surface_finalize(jobject objectHandle) { AbstractSurface* surface; if (!fieldIdsInitialized) { return; } surface = (AbstractSurface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); if (surface != NULL) { surface->cleanup(surface); surface_dispose(&surface->super); KNI_SetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR], (jlong)0); if (KNI_TRUE == readAndClearMemErrorFlag()) { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } }
static jboolean getLocation(jobject locationInfo, jobject string_obj, ProviderInfo *pInfo) { jint i; jfieldID fid; jboolean ret = KNI_FALSE; if(pInfo != NULL) { if (pInfo->lastLocationTimestamp != 0) { /* Get location parameters */ KNI_SetBooleanField(locationInfo, locationInfoFieldID.isValid, pInfo->lastLocation.isValidCoordinate); KNI_SetDoubleField(locationInfo, locationInfoFieldID.latitude, pInfo->lastLocation.latitude); KNI_SetDoubleField(locationInfo, locationInfoFieldID.longitude, pInfo->lastLocation.longitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.altitude, pInfo->lastLocation.altitude); KNI_SetFloatField(locationInfo, locationInfoFieldID.horizontalAccuracy, pInfo->lastLocation.horizontalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.verticalAccuracy, pInfo->lastLocation.verticalAccuracy); KNI_SetFloatField(locationInfo, locationInfoFieldID.speed, pInfo->lastLocation.speed); KNI_SetFloatField(locationInfo, locationInfoFieldID.course, pInfo->lastLocation.course); KNI_SetIntField(locationInfo, locationInfoFieldID.method, pInfo->lastLocation.method); KNI_SetLongField(locationInfo, locationInfoFieldID.timestamp, pInfo->lastLocationTimestamp); if (pInfo->lastLocation.addressInfoFieldNumber == 0) { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_FALSE); } else { KNI_SetBooleanField(locationInfo, locationInfoFieldID.isAddressInfo, KNI_TRUE); for(i=0; i<pInfo->lastLocation.addressInfoFieldNumber; i++) { midp_jstring_from_pcsl_string(&pInfo->lastAddressInfo[i].data, string_obj); switch(pInfo->lastAddressInfo[i].fieldId) { case JSR179_ADDRESSINFO_EXTENSION: fid = locationInfoFieldID. AddressInfo_EXTENSION; break; case JSR179_ADDRESSINFO_STREET: fid = locationInfoFieldID. AddressInfo_STREET; break; case JSR179_ADDRESSINFO_POSTAL_CODE: fid = locationInfoFieldID. AddressInfo_POSTAL_CODE; break; case JSR179_ADDRESSINFO_CITY: fid = locationInfoFieldID. AddressInfo_CITY; break; case JSR179_ADDRESSINFO_COUNTY: fid = locationInfoFieldID. AddressInfo_COUNTY; break; case JSR179_ADDRESSINFO_STATE: fid = locationInfoFieldID. AddressInfo_STATE; break; case JSR179_ADDRESSINFO_COUNTRY: fid = locationInfoFieldID. AddressInfo_COUNTRY; break; case JSR179_ADDRESSINFO_COUNTRY_CODE: fid = locationInfoFieldID. AddressInfo_COUNTRY_CODE; break; case JSR179_ADDRESSINFO_DISTRICT: fid = locationInfoFieldID. AddressInfo_DISTRICT; break; case JSR179_ADDRESSINFO_BUILDING_NAME: fid = locationInfoFieldID. AddressInfo_BUILDING_NAME; break; case JSR179_ADDRESSINFO_BUILDING_FLOOR: fid = locationInfoFieldID. AddressInfo_BUILDING_FLOOR; break; case JSR179_ADDRESSINFO_BUILDING_ROOM: fid = locationInfoFieldID. AddressInfo_BUILDING_ROOM; break; case JSR179_ADDRESSINFO_BUILDING_ZONE: fid = locationInfoFieldID. AddressInfo_BUILDING_ZONE; break; case JSR179_ADDRESSINFO_CROSSING1: fid = locationInfoFieldID. AddressInfo_CROSSING1; break; case JSR179_ADDRESSINFO_CROSSING2: fid = locationInfoFieldID. AddressInfo_CROSSING2; break; case JSR179_ADDRESSINFO_URL: fid = locationInfoFieldID. AddressInfo_URL; break; case JSR179_ADDRESSINFO_PHONE_NUMBER: fid = locationInfoFieldID. AddressInfo_PHONE_NUMBER; break; default: fid = 0; break; } if(fid != 0) { KNI_SetObjectField(locationInfo, fid, string_obj); } } } if (pInfo->lastLocation.extraInfoSize > 0) { midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[0], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoNMEA, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[1], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoLIF, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[2], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoPlain, string_obj); midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[3], string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOther, string_obj); midp_jstring_from_pcsl_string(&pInfo->otherExtraInfoMimeType, string_obj); KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOtherMIMEType, string_obj); } ret = KNI_TRUE; } } return ret; }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_JavaSurface_initialize() { KNI_StartHandles(1); KNI_DeclareHandle(objectHandle); jint dataType = KNI_GetParameterAsInt(1); jint width = KNI_GetParameterAsInt(2); jint height = KNI_GetParameterAsInt(3); JavaSurface* jSurface; AbstractSurface* surface; KNI_GetThisPointer(objectHandle); if (surface_initialize(objectHandle) && initializeSurfaceFieldIds(objectHandle)) { jSurface = my_malloc(JavaSurface, 1); surface = &jSurface->super; if (surface != NULL) { surface->super.width = width; surface->super.height = height; surface->super.offset = 0; surface->super.scanlineStride = width; surface->super.pixelStride = 1; surface->super.imageType = dataType; surface->acquire = surface_acquire; surface->release = surface_release; surface->cleanup = surface_cleanup; switch(surface->super.imageType){ case TYPE_INT_RGB: case TYPE_INT_ARGB: case TYPE_INT_ARGB_PRE: jSurface->javaArrayFieldID = fieldIds[SURFACE_DATA_INT]; jSurface->javaArrayFieldSize = sizeof(jint); break; case TYPE_USHORT_565_RGB: jSurface->javaArrayFieldID = fieldIds[SURFACE_DATA_SHORT]; jSurface->javaArrayFieldSize = sizeof(jshort); break; case TYPE_BYTE_GRAY: jSurface->javaArrayFieldID = fieldIds[SURFACE_DATA_BYTE]; jSurface->javaArrayFieldSize = sizeof(jbyte); break; default: //errorneous - should never happen jSurface->javaArrayFieldID = NULL; } KNI_SetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR], PointerToJLong(surface)); // KNI_registerCleanup(objectHandle, disposeNativeImpl); } else { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } else { KNI_ThrowNew("java/lang/IllegalStateException", ""); } KNI_EndHandles(); KNI_ReturnVoid(); }