/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_j2me_location_PlatformLocationProvider_getStateImpl() { jsr179_state state = JSR179_OUT_OF_SERVICE; jint provider = KNI_GetParameterAsInt(1); jint ret=0; /* out of service */ if (stateValue.filled == KNI_FALSE) { KNI_StartHandles(1); KNI_DeclareHandle(clazz); KNI_FindClass("javax/microedition/location/LocationProvider", clazz); if(!KNI_IsNullHandle(clazz)) { stateValue.available = KNI_GetStaticIntField(clazz, KNI_GetStaticFieldID(clazz, "AVAILABLE", "I")); stateValue.temporarilyUnavailable = KNI_GetStaticIntField(clazz, KNI_GetStaticFieldID(clazz, "TEMPORARILY_UNAVAILABLE", "I")); stateValue.outOfService = KNI_GetStaticIntField(clazz, KNI_GetStaticFieldID(clazz, "OUT_OF_SERVICE", "I")); stateValue.filled = KNI_TRUE; } KNI_EndHandles(); } if (stateValue.filled == KNI_TRUE) { jsr179_provider_state((jsr179_handle)provider, &state); switch(state) { case JSR179_AVAILABLE: ret = stateValue.available; break; case JSR179_TEMPORARILY_UNAVAILABLE: ret = stateValue.temporarilyUnavailable; break; case JSR179_OUT_OF_SERVICE: default: ret = stateValue.outOfService; break; } } KNI_ReturnInt(ret); }
/** * Stores the romized byte array in corresponding Java array * @param the required resource (initialFont or defaultFont) * */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_perseus_platform_ResourceHandler_getRomizedResource() { jbyte *font_data; int font_type = -1; int buflen = -1; int size = -1; KNI_StartHandles(2); KNI_DeclareHandle(clazz); KNI_DeclareHandle(bufHandle); KNI_GetClassPointer(clazz); font_type = KNI_GetParameterAsInt(1); if (font_type == DEFAULT_FONT) { KNI_GetStaticObjectField(clazz, KNI_GetStaticFieldID(clazz, "defaultFont", "[B"), bufHandle); size = sizeof(defaultFont); font_data = defaultFont; } else { KNI_GetStaticObjectField(clazz, KNI_GetStaticFieldID(clazz, "initialFont", "[B"), bufHandle); size = sizeof(initialFont); font_data = initialFont; } if (KNI_IsNullHandle(bufHandle)) { KNI_ThrowNew(midpNullPointerException, 0); } else { buflen = KNI_GetArrayLength(bufHandle); if (buflen < size) { //REPORT_ERROR(LC_HIGHUI, "java array too small"); KNI_ThrowNew(midpArrayIndexOutOfBoundsException, 0); } else { KNI_SetRawArrayRegion(bufHandle, 0, size, (jbyte*)font_data); } } KNI_EndHandles(); KNI_ReturnVoid(); }
KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(KNITest_testGetSetStaticDoubleField) { jdouble x = KNI_GetParameterAsDouble(1); jdouble y; jfieldID typeFieldID; KNI_StartHandles(1); KNI_DeclareHandle(clazz); KNI_GetClassPointer(clazz); typeFieldID = KNI_GetStaticFieldID(clazz, "d", "D"); y = KNI_GetStaticDoubleField(clazz, typeFieldID); KNI_SetStaticDoubleField(clazz, typeFieldID, x*y); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Gets the KNI field ID for a static field of a class and checks it for * validity. See KNI_GetStaticFieldID for further information. * * @param classHandle the handle to the containing class * @param name the field's name * @param signature the field's type */ jfieldID midp_get_static_field_id(KNIDECLARGS jclass classHandle, const char* name, const char* signature) { jfieldID id = KNI_GetStaticFieldID(classHandle, name, signature); if (id == NULL) { REPORT_CRIT3(LC_CORE, "midp_get_static_field_id: " "can't find field, clazz=0x%x name=%s sig=%s", (unsigned int)classHandle, name, signature); } return id; }
jboolean initializeStaticFieldIds(jfieldID* dest, jclass classHandle, const FieldDesc* fields) { jboolean retVal = KNI_TRUE; while (fields->name != NULL) { *dest = KNI_GetStaticFieldID(classHandle, fields->name, fields->signature); if (*dest == NULL) { retVal = KNI_FALSE; break; } ++fields; ++dest; } return retVal; }
KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_beginReadingSkinFile) { const unsigned char* skin_description = lfj_get_skin_description(); if (skin_description != NULL) { gsSkinFileDataStart = gsSkinFileDataPos = (unsigned char*)skin_description; gsSkinFileDataEnd = gsSkinFileDataStart + lfj_get_skin_description_size(); } else { char* errorStr = NULL; int fileHandle = -1; int fileSize; int bytesRead; jfieldID fid; KNI_StartHandles(2); KNI_DeclareHandle(classHandle); KNI_GetClassPointer(classHandle); fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_USASCII", "B"); STRING_ENCODING_USASCII = (unsigned char) KNI_GetStaticByteField(classHandle, fid); fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_UTF8", "B"); STRING_ENCODING_UTF8 = (unsigned char) KNI_GetStaticByteField(classHandle, fid); GET_PARAMETER_AS_PCSL_STRING(1, fileName); do { /* * Open skin file */ fileHandle = storage_open(&errorStr, &fileName, OPEN_READ); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); break; } /* * Obtain file size */ fileSize = storageSizeOf(&errorStr, fileHandle); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); break; } /* * Read whole file into heap memory */ gsSkinFileDataStart = (unsigned char*)midpMalloc(fileSize); if (gsSkinFileDataStart == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } bytesRead = storageRead(&errorStr, fileHandle, (char*)gsSkinFileDataStart, fileSize); if (errorStr != NULL) { KNI_ThrowNew(midpIOException, errorStr); storageFreeError(errorStr); midpFree(gsSkinFileDataStart); gsSkinFileDataStart = NULL; break; } if (bytesRead != fileSize) { KNI_ThrowNew(midpIOException, "Failed to read whole file"); midpFree(gsSkinFileDataStart); gsSkinFileDataStart = NULL; break; } gsSkinFileDataPos = gsSkinFileDataStart; gsSkinFileDataEnd = gsSkinFileDataStart + fileSize; } while (0); RELEASE_PCSL_STRING_PARAMETER; /* * Close skin file */ if (fileHandle != -1) { storageClose(&errorStr, fileHandle); } KNI_EndHandles(); } KNI_ReturnVoid(); }