KNI_RETURNTYPE_BYTE KNIDECL(com_sun_midp_security_Permissions_getMaxValue) { int str_len; jbyte value; jchar jbuff[64]; char domain_name[64], group_name[64]; KNI_StartHandles(2); KNI_DeclareHandle(domain); KNI_DeclareHandle(group); value = 0; KNI_GetParameterAsObject(1, domain); KNI_GetParameterAsObject(2, group); if (!KNI_IsNullHandle(domain) && !KNI_IsNullHandle(group)) { str_len = KNI_GetStringLength(domain); KNI_GetStringRegion(domain, 0, str_len, jbuff); jchar_to_char(jbuff, domain_name, str_len); str_len = KNI_GetStringLength(group); KNI_GetStringRegion(group, 0, str_len, jbuff); jchar_to_char(jbuff, group_name, str_len); value = (jbyte)permissions_get_max_value(domain_name, group_name); } KNI_EndHandles(); KNI_ReturnByte(value); }
/* * Retrieves service record from the service search result. * * @param recHandle native handle of the service record * @param array byte array which will receive the data, * or null for size query * @return size of the data read/required */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_jsr082_bluetooth_SDPTransaction_getServiceRecord0) { jint retval = 0; javacall_handle id = 0; javacall_uint8 *data = NULL; javacall_uint16 size = 0; KNI_StartHandles(1); KNI_DeclareHandle(dataHandle); KNI_GetParameterAsObject(2, dataHandle); id = (javacall_handle)KNI_GetParameterAsInt(1); if (!KNI_IsNullHandle(dataHandle)) size = KNI_GetArrayLength(dataHandle); data = JAVAME_MALLOC(size); if (data == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, "Out of memory inside SDDB.readRecord()"); } else { if (javacall_bt_sdp_get_service(id, data, &size) == JAVACALL_OK) { retval = size; if (!KNI_IsNullHandle(dataHandle)) { KNI_SetRawArrayRegion(dataHandle, 0, size, data); } } else { retval = 0; } JAVAME_FREE(data); } KNI_EndHandles(); KNI_ReturnInt(retval); }
/** * Gets a handle to specific character encoding conversion routine. * <p> * Java declaration: * <pre> * getHandler(Ljava/lang/String;)I * </pre> * * @param encoding character encoding * * @return identifier for requested handler, or <tt>-1</tt> if * the encoding was not supported. */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_getHandler() { jint result = 0; KNI_StartHandles(1); KNI_DeclareHandle(str); KNI_GetParameterAsObject(1, str); if (!KNI_IsNullHandle(str)) { int strLen = KNI_GetStringLength(str); jchar* strBuf; /* Instead of always multiplying the length by sizeof(jchar), * we shift left by 1. This can be done because jchar has a * size of 2 bytes. */ strBuf = (jchar*)midpMalloc(strLen<<1); if (strBuf != NULL) { KNI_GetStringRegion(str, 0, strLen, strBuf); result = getLcConvMethodsID(strBuf, strLen); midpFree(strBuf); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Fetch a KNI String array object into the string array. * * @param arrObj KNI Java String object handle * @param arrPtr the String array pointer for values storing * @return number of retrieved strings * <BR>KNI_ENOMEM - indicates memory allocation error */ static int getStringArray(jobjectArray arrObj, pcsl_string** arrPtr) { int i, n = 0; pcsl_string* arr; KNI_StartHandles(1); KNI_DeclareHandle(strObj); n = KNI_IsNullHandle(arrObj)? 0: (int)KNI_GetArrayLength(arrObj); while (n > 0) { arr = alloc_pcsl_string_list(n); if (arr == NULL) { n = KNI_ENOMEM; break; } *arrPtr = arr; for (i = 0; i < n; i++, arr++) { KNI_GetObjectArrayElement(arrObj, i, strObj); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(strObj, arr)) { free_pcsl_string_list(*arrPtr, n); *arrPtr = NULL; n = KNI_ENOMEM; break; } } break; } KNI_EndHandles(); return n; }
/** * Sets the content buffer. All paints are done to that buffer. * When paint is processed snapshot of the buffer is flushed to * the native resource content area. * Native implementation of Java function: * private static native int setContentBuffer0 ( int nativeId, Image img ); * @param nativeId native resource is for this CustomItem * @param img mutable image that serves as an offscreen buffer */ KNIEXPORT KNI_RETURNTYPE_VOID Java_javax_microedition_lcdui_CustomItemLFImpl_setContentBuffer0() { MidpError err = KNI_OK; unsigned char* imgPtr = NULL; MidpItem *ciPtr = (MidpItem *)KNI_GetParameterAsInt(1); KNI_StartHandles(1); KNI_DeclareHandle(image); KNI_GetParameterAsObject(2, image); if (KNI_IsNullHandle(image) != KNI_TRUE) { imgPtr = gxp_get_imagedata(image); } KNI_EndHandles(); err = lfpport_customitem_set_content_buffer(ciPtr, imgPtr); if (err != KNI_OK) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnVoid(); }
/* private native int _eglInitialize ( int display , int [ ] major_minor ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglInitialize() { jint display = KNI_GetParameterAsInt(1); EGLint major, minor; jint returnValue; KNI_StartHandles(1); KNI_DeclareHandle(major_minorHandle); KNI_GetParameterAsObject(2, major_minorHandle); returnValue = (jint) eglInitialize((EGLDisplay)display, &major, &minor); #ifdef DEBUG printf("eglInitialize(0x%x, major<-%d, minor<-%d) = %d\n", display, major, minor, returnValue); #endif if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(major_minorHandle)) { KNI_SetIntArrayElement(major_minorHandle, 0, major); KNI_SetIntArrayElement(major_minorHandle, 1, minor); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/** * Get index of supported locales for collation by its name. * <p> * Java declaration: * <pre> * getDevLocaleIndex(Ljava/lang/String)I * </pre> * * @param locale name * @return internal index of locale or -1 if locale is not supported */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_j2me_global_CollationAbstractionLayerImpl_getCollationLocaleIndex() { jint result =-1, index = 0; jsize len = 0; int error = 0; jchar* locale_name; KNI_StartHandles(1); KNI_DeclareHandle(hstr1); KNI_GetParameterAsObject(1, hstr1); if (KNI_IsNullHandle(hstr1)) { locale_name = NULL; } else { len = KNI_GetStringLength(hstr1); locale_name = (jchar *)midpMalloc((len + 1) * sizeof(jchar)); if (NULL == locale_name) { KNI_ThrowNew(midpOutOfMemoryError, "Out of memory"); error = 1; } else { KNI_GetStringRegion(hstr1, 0, len, locale_name); locale_name[len]=0; } } if (!error){ result = jsr238_get_collation_locale_index(locale_name, &index); if (result < 0) index =-1; midpFree(locale_name); } KNI_EndHandles(); KNI_ReturnInt(index); }
KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_midp_security_Permissions_loadGroupList) { int lines, i1; void* array; KNI_StartHandles(2); KNI_DeclareHandle(groups); KNI_DeclareHandle(tmpString); lines = permissions_load_group_list(&array); if (lines > 0) { char** list = (char**)array; SNI_NewArray(SNI_STRING_ARRAY, lines, groups); if (KNI_IsNullHandle(groups)) KNI_ThrowNew(midpOutOfMemoryError, NULL); else for (i1 = 0; i1 < lines; i1++) { KNI_NewStringUTF(list[i1], tmpString); KNI_SetObjectArrayElement(groups, (jint)i1, tmpString); } permissions_dealloc(array); } else KNI_ReleaseHandle(groups); /* set object to NULL */ KNI_EndHandlesAndReturnObject(groups); }
/** * Get index of supported locales for device resources by its name. * <p> * Java declaration: * <pre> * getDevLocaleIndex(Ljava/lang/String)I * </pre> * * @param locale name * @return internal index of locale or -1 if locale is not supported */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_global_DevResourceManagerFactory_getDevLocaleIndex) { jint result =-1, index = 0; jsize len = 0; int error = 0; jchar* locale_name; KNI_StartHandles(1); KNI_DeclareHandle(hstr1); KNI_GetParameterAsObject(1, hstr1); if (KNI_IsNullHandle(hstr1)) { locale_name = NULL; } else { len = KNI_GetStringLength(hstr1); locale_name = (jchar *)JAVAME_MALLOC((len + 1) * sizeof(jchar)); if (NULL == locale_name) { KNI_ThrowNew(jsropOutOfMemoryError, "Out of memory"); error = 1; } else { KNI_GetStringRegion(hstr1, 0, len, locale_name); locale_name[len]=0; } } if (!error){ result = jsr238_get_resource_locale_index(locale_name, &index); if (result < 0) index =-1; JAVAME_FREE(locale_name); } KNI_EndHandles(); KNI_ReturnInt(index); }
/* private native int _eglQueryContext ( int display , int ctx , int attribute , int [ ] value ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglQueryContext() { jint display = KNI_GetParameterAsInt(1); jint ctx = KNI_GetParameterAsInt(2); jint attribute = KNI_GetParameterAsInt(3); EGLint value; jint returnValue = EGL_FALSE; KNI_StartHandles(1); KNI_DeclareHandle(valueHandle); KNI_GetParameterAsObject(4, valueHandle); returnValue = (jint)eglQueryContext((EGLDisplay)display, (EGLContext)ctx, attribute, &value); #ifdef DEBUG printf("eglQueryContext(0x%x, 0x%x, %d, value<-%d) = %d\n", display, ctx, attribute, value, returnValue); #endif if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(valueHandle)) { KNI_SetIntArrayElement(valueHandle, 0, value); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/** * Retrieves service record from the SDDB. * * @param handle handle of the service record to be retrieved * @param data byte array which will receive the data, * or null for size query * @return size of the data read/required */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_kvem_jsr082_bluetooth_SDDB_readRecord(void) { jint retval; bt_record_t record; KNI_StartHandles(1); KNI_DeclareHandle(dataHandle); KNI_GetParameterAsObject(2, dataHandle); record.id = (bt_sddbid_t)KNI_GetParameterAsInt(1); if (KNI_IsNullHandle(dataHandle)) { record.data = NULL; record.size = 0; } else { record.data = JavaByteArray(dataHandle); record.size = KNI_GetArrayLength(dataHandle); } if (javacall_bt_sddb_read_record(record.id, &record.classes, record.data, &record.size) == JAVACALL_OK) { retval = record.size; } else { retval = 0; } KNI_EndHandles(); KNI_ReturnInt(retval); }
/** * KNI function that creates new native resource for the current ImageItem. * * Class: javax.microedition.lcdui.ImageItemLFImpl * Java prototype: * private native int createNativeResource0(int ownerId, String label, * int layout, * Image img, String altText, * int appearanceMode) * * INTERFACE (operand stack manipulation): * parameters: ownerId pointer to the owner's native resource * label ImageItem's label * layout ImageItem's layout * img ImageItem's image * altText ImageItem's attText * appearanceMode the appearanceMode of ImageItem * return pointer to the created native resource */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_ImageItemLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr; MidpItem *itemPtr = NULL; pcsl_string label, altText; pcsl_string_status rc1,rc2; unsigned char* imgPtr = NULL; int appearanceMode, layout; KNI_StartHandles(3); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(image); KNI_DeclareHandle(altTextJString); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelJString); layout = KNI_GetParameterAsInt(3); KNI_GetParameterAsObject(4, image); KNI_GetParameterAsObject(5, altTextJString); if (KNI_IsNullHandle(image) != KNI_TRUE) { imgPtr = gxp_get_imagedata(image); } appearanceMode = KNI_GetParameterAsInt(6); rc1 = midp_jstring_to_pcsl_string(labelJString, &label); rc2 = midp_jstring_to_pcsl_string(altTextJString, &altText); KNI_EndHandles(); /* NULL and empty strings are acceptable. */ if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2 ) { err = KNI_ENOMEM; goto cleanup; } itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_IMAGE_ITEM_TYPE+appearanceMode); if (itemPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } err = lfpport_imageitem_create(itemPtr, ownerPtr, &label, layout, imgPtr, &altText, appearanceMode); cleanup: pcsl_string_free(&altText); pcsl_string_free(&label); if (err != KNI_OK) { MidpDeleteItem(itemPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(itemPtr); }
/** * Retrieves a pointer to the raw image data. * * @param imgData a handle to the <tt>ImageData</tt> Java object that contains * the raw image data * * @return A pointer to the raw data associated with the given * <tt>ImageData</tt> object. Otherwise NULL. */ gxpport_image_native_handle gxp_get_imagedata(jobject imgData) { if (KNI_IsNullHandle(imgData)) { return NULL; } else { return (gxpport_image_native_handle)IMGAPI_GET_IMAGEDATA_PTR(imgData)->nativeImageData; } }
/** * Fills <code>MidpString</code> arrays for locales and action_maps from * <code>ActionMap</code> objects. * <BR>Length of <code>actionnames</code> array must be the same as in * <code>act_num</code> parameter for each element of <code>ActionMap</code> * array. * * @param o <code>ActionMap[]</code> object * @param handler pointer on <code>JSR211_content_handler</code> structure * being filled up * @return KNI_OK - if successfully get all fields, * KNI_ERR or KNI_ENOMEM - otherwise */ static int fillActionMap(jobject o, JSR211_content_handler* handler) { int ret = KNI_OK; // returned result int len; // number of locales len = KNI_IsNullHandle(o)? 0: (int)KNI_GetArrayLength(o); if (len > 0) { int i, j; int n = handler->act_num; // number of actions pcsl_string *locs = NULL; // fetched locales pcsl_string *nams = NULL; // fetched action names KNI_StartHandles(3); KNI_DeclareHandle(map); // current ANMap object KNI_DeclareHandle(str); // the ANMap's locale|name String object KNI_DeclareHandle(arr); // the ANMap's array of names object do { // allocate buffers handler->locales = alloc_pcsl_string_list(len); if (handler->locales == NULL) { ret = KNI_ENOMEM; break; } handler->locale_num = len; handler->action_map = alloc_pcsl_string_list(len * n); if (handler->action_map == NULL) { ret = KNI_ENOMEM; break; } // iterate array elements locs = handler->locales; nams = handler->action_map; for (i = 0; i < len && ret == KNI_OK; i++) { KNI_GetObjectArrayElement(o, i, map); KNI_GetObjectField(map, anMapLocale, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, locs++)) { ret = KNI_ENOMEM; break; } KNI_GetObjectField(map, anMapActionnames, arr); for (j = 0; j < n; j++) { KNI_GetObjectArrayElement(arr, j, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, nams++)) { ret = KNI_ENOMEM; break; } } } } while (0); KNI_EndHandles(); } return ret; }
/** * Decodes the given byte array into the <tt>ImageData</tt>. * <p> * Java declaration: * <pre> * loadJPG(Ljavax/microedition/lcdui/ImageData;[BII)V * </pre> * * @param imageData the ImageData to load to * @param imageBytes A byte array containing the encoded JPEG image data * @param imageOffset The start of the image data within the byte array * @param imageLength The length of the image data in the byte array */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadJPEG) { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); unsigned char* srcBuffer = NULL; gxj_screen_buffer image; java_imagedata * midpImageData = NULL; /* variable to hold error codes */ gxutl_native_image_error_codes creationError = GXUTL_NATIVE_IMAGE_NO_ERROR; KNI_StartHandles(3); /* KNI_DeclareHandle(alphaData); */ KNI_DeclareHandle(pixelData); KNI_DeclareHandle(jpegData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, jpegData); KNI_GetParameterAsObject(1, imageData); midpImageData = GXAPI_GET_IMAGEDATA_PTR(imageData); /* assert * (KNI_IsNullHandle(jpegData)) */ srcBuffer = (unsigned char *)JavaByteArray(jpegData); /* * JAVA_TRACE("loadJPEG jpegData length=%d %x\n", * JavaByteArray(jpegData)->length, srcBuffer); */ image.width = midpImageData->width; image.height = midpImageData->height; unhand(jbyte_array, pixelData) = midpImageData->pixelData; if (!KNI_IsNullHandle(pixelData)) { image.pixelData = (gxj_pixel_type *)JavaByteArray(pixelData); /* * JAVA_TRACE("loadJPEG pixelData length=%d\n", * JavaByteArray(pixelData)->length); */ } /* assert * (imagedata.pixelData != NULL) */ decode_jpeg((srcBuffer + offset), length, &image, &creationError); if (GXUTL_NATIVE_IMAGE_NO_ERROR != creationError) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * (Internal) Fill addressInfo Field. */ static jboolean fill_adressInfoField(jobject landmarkObj, jfieldID fieldID, jobject stringObj, javacall_location_addressinfo_fieldinfo *fieldInfo, javacall_location_addressinfo_field addressInfoFieldId) { KNI_GetObjectField(landmarkObj, fieldID, stringObj); if (!KNI_IsNullHandle(stringObj)) { fieldInfo->fieldId = addressInfoFieldId; return jsr179_jstring_to_utf16(stringObj, fieldInfo->data, JAVACALL_LOCATION_MAX_ADDRESSINFO_FIELD); } return KNI_FALSE; }
KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_midp_security_Permissions_loadGroupPermissions) { int lines, i1; unsigned int str_len; void *array; jchar jbuff[64]; char group_name[64]; KNI_StartHandles(3); KNI_DeclareHandle(members); KNI_DeclareHandle(tmpString); KNI_DeclareHandle(group); KNI_GetParameterAsObject(1, group); if (!KNI_IsNullHandle(group)) { str_len = KNI_GetStringLength(group); if (str_len <= sizeof(group_name)-1) { KNI_GetStringRegion(group, 0, str_len, jbuff); jchar_to_char(jbuff, group_name, str_len); lines = permissions_load_group_permissions(&array, group_name); if (lines > 0) { char **list = (char**)array; SNI_NewArray(SNI_STRING_ARRAY, lines, members); if (KNI_IsNullHandle(members)) KNI_ThrowNew(midpOutOfMemoryError, NULL); else for (i1 = 0; i1 < lines; i1++) { KNI_NewStringUTF(list[i1], tmpString); KNI_SetObjectArrayElement(members, (jint)i1, tmpString); } permissions_dealloc(array); } else KNI_ReleaseHandle(members); /* set object to NULL */ } } else KNI_ThrowNew(midpNullPointerException, "null group parameter"); KNI_EndHandlesAndReturnObject(members); }
/** * Draws the specified image by using the anchor point. * The image can be drawn in different positions relative to * the anchor point by passing the appropriate position constants. * See <a href="#anchor">anchor points</a>. * * <p>If the source image contains transparent pixels, the corresponding * pixels in the destination image must be left untouched. If the source * image contains partially transparent pixels, a compositing operation * must be performed with the destination pixels, leaving all pixels of * the destination image fully opaque.</p> * * <p>If <code>img</code> is the same as the destination of this Graphics * object, the result is undefined. For copying areas within an * <code>Image</code>, {@link #copyArea copyArea} should be used instead. * </p> * * @param g the specified Graphics to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the image * @throws IllegalArgumentException if <code>anchor</code> * is not a legal value * @throws NullPointerException if <code>g</code> is <code>null</code> * @see Image */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(javax_microedition_lcdui_Image_render) { jboolean success = KNI_TRUE; int anchor = KNI_GetParameterAsInt(4); int y = KNI_GetParameterAsInt(3); int x = KNI_GetParameterAsInt(2); KNI_StartHandles(3); KNI_DeclareHandle(img); KNI_DeclareHandle(g); KNI_DeclareHandle(gImg); KNI_GetParameterAsObject(1, g); KNI_GetThisPointer(img); if (GRAPHICS_OP_IS_ALLOWED(g)) { /* null checking is handled by the Java layer, but test just in case */ if (KNI_IsNullHandle(img)) { success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL); } else { const java_imagedata * srcImageDataPtr = GET_IMAGE_PTR(img)->imageData; GET_IMAGE_PTR(gImg) = (struct Java_javax_microedition_lcdui_Image *) (GXAPI_GET_GRAPHICS_PTR(g)->img); if (KNI_IsSameObject(gImg, img) || !gxutl_check_anchor(anchor,0)) { success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL); } else if (!gxutl_normalize_anchor(&x, &y, srcImageDataPtr->width, srcImageDataPtr->height, anchor)) { success = KNI_FALSE;//KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ const java_imagedata * dstMutableImageDataPtr = GXAPI_GET_IMAGEDATA_PTR_FROM_GRAPHICS(g); GXAPI_TRANSLATE(g, x, y); GXAPI_GET_CLIP(g, clip); gx_render_image(srcImageDataPtr, dstMutableImageDataPtr, clip, x, y); } } } KNI_EndHandles(); KNI_ReturnBoolean(success); }
/* private native int _eglCreateContext ( int display , int config , int share_context , int [ ] attrib_list ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglCreateContext() { jint display = KNI_GetParameterAsInt(1); jint config = KNI_GetParameterAsInt(2); jint share_context = KNI_GetParameterAsInt(3); EGLint *attrib_list = (EGLint *)0; jint returnValue = 0; KNI_StartHandles(1); KNI_DeclareHandle(attrib_listHandle); KNI_GetParameterAsObject(4, attrib_listHandle); /* Construct attrib_list as a copy of attrib_listHandle */ if (!KNI_IsNullHandle(attrib_listHandle)) { jint attrib_list_length, attrib_list_size; attrib_list_length = KNI_GetArrayLength(attrib_listHandle); attrib_list_size = attrib_list_length*sizeof(jint); attrib_list = (EGLint *)JSR239_malloc(attrib_list_size); if (!attrib_list) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglCreateContext"); goto exit; } KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size, (jbyte *)attrib_list); } returnValue = (jint)eglCreateContext((EGLDisplay) display, (EGLConfig) config, (EGLConfig) share_context, attrib_list); #ifdef DEBUG if (returnValue > 0) { ++contexts; } printf("eglCreateContext(0x%x, 0x%x, 0x%x, attrib_list) = %d, contexts = %d\n", display, config, share_context, returnValue, contexts); #endif exit: if (attrib_list) { JSR239_free(attrib_list); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/* * IMPL_NOTE: this function is the same as midpGetJarEntry() in midpJar.c, * but it uses only CLDC stuff */ jboolean midp_readJarEntry(const pcsl_string* jarName, const pcsl_string* entryName, jobject* entry) { JvmPathChar* platformJarName; int i; jboolean noerror = KNI_TRUE; GET_PCSL_STRING_DATA_AND_LENGTH(jarName) /* Entry names in JARs are UTF-8. */ const jbyte * const platformEntryName = pcsl_string_get_utf8_data(entryName); do { if (platformEntryName == NULL) { noerror = KNI_FALSE; break; } /* * JvmPathChars can be either 16 bits or 8 bits so we can't * assume either. */ /* * Conversion to JvmPathChars is only temporary, we should change the VM * should take a jchar array and a length and pass that to * PCSL which will then perform * a platform specific conversion (DBCS on Win32 or UTF8 on Linux) */ platformJarName = midpMalloc((jarName_len + 1) * sizeof (JvmPathChar)); if (platformJarName == NULL) { noerror = KNI_FALSE; break; } for (i = 0; i < jarName_len; i++) { platformJarName[i] = (JvmPathChar)jarName_data[i]; } platformJarName[i] = 0; Jvm_read_jar_entry(platformJarName, (char*)platformEntryName, (jobject)*entry); midpFree(platformJarName); } while(0); pcsl_string_release_utf8_data(platformEntryName, entryName); RELEASE_PCSL_STRING_DATA_AND_LENGTH if (noerror) { return (KNI_IsNullHandle((jobject)*entry) == KNI_TRUE) ? KNI_FALSE : KNI_TRUE; } else { return KNI_FALSE; } }
/* private native int _eglCreatePixmapSurface ( int display , int config , int pixmap , int [ ] attrib_list ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglCreatePixmapSurface() { jint display = KNI_GetParameterAsInt(1); jint config = KNI_GetParameterAsInt(2); jint pixmap = KNI_GetParameterAsInt(3); EGLint *attrib_list = (EGLint *)0; jint returnValue = (jint)EGL_NO_SURFACE; KNI_StartHandles(1); KNI_DeclareHandle(attrib_listHandle); KNI_GetParameterAsObject(4, attrib_listHandle); /* Construct attrib_list as a copy of attrib_listHandle if non-null */ if (!KNI_IsNullHandle(attrib_listHandle)) { jint attrib_list_length, attrib_list_size; attrib_list_length = KNI_GetArrayLength(attrib_listHandle); attrib_list_size = attrib_list_length*sizeof(jint); attrib_list = (EGLint *)JSR239_malloc(attrib_list_size); if (!attrib_list) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglCreatePixmapSurface"); goto exit; } KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size, (jbyte *) attrib_list); } returnValue = (jint)eglCreatePixmapSurface((EGLDisplay)display, (EGLConfig)config, (NativePixmapType)pixmap, (EGLint const *) attrib_list); #ifdef DEBUG printf("eglCreatePixmapSurface(%d, %d, 0x%x, attrib_list) = %d\n", display, config, pixmap, returnValue); #endif exit: if (attrib_list) { JSR239_free(attrib_list); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
static jboolean jsr179_jstring_to_utf16(jobject stringObj, javacall_utf16 *string, jint len) { if (!KNI_IsNullHandle(stringObj)) { if (KNI_GetStringLength(stringObj) > 0) { if (JAVACALL_OK != jsrop_jstring_to_utf16(stringObj, string, len)) { return KNI_FALSE; } } else { string[0] = (javacall_utf16)0x0000; string[1] = (javacall_utf16)0x0000; } } else { string[0] = (javacall_utf16)0x0000; string[1] = (javacall_utf16)0xFFFF; } return KNI_TRUE; }
/* This is called by the last active TextFieldLFImpl to retrieve * the contents of the native editor, which was saved by * MIDPWindow.disableAndSyncNativeEditor() into a malloc'ed buffer above. * See disableAndSyncNativeEditor above for more info. */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(javax_microedition_lcdui_TextFieldLFImpl_mallocToJavaChars) { int strLen = KNI_GetParameterAsInt(2); jchar *tmp = (jchar*)KNI_GetParameterAsInt(1); KNI_StartHandles(1); KNI_DeclareHandle(chars); #if 0 SNI_NewArray(SNI_CHAR_ARRAY, strLen, chars); if (!KNI_IsNullHandle(chars)) { memcpy(JavaCharArray(chars), tmp, strLen*sizeof(jchar)); } #endif midpFree((void*)tmp); KNI_EndHandlesAndReturnObject(chars); }
/** * Retrieves handles of all service records in the SDDB. * * @param handles array to receive handles, or null for count query * @return number of entries read/available */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_kvem_jsr082_bluetooth_SDDB_getRecords(void) { jint retval; KNI_StartHandles(1); KNI_DeclareHandle(arrayHandle); KNI_GetParameterAsObject(1, arrayHandle); if (KNI_IsNullHandle(arrayHandle)) { retval = javacall_bt_sddb_get_records(NULL, 0); } else { retval = javacall_bt_sddb_get_records((bt_sddbid_t *)JavaIntArray(arrayHandle), KNI_GetArrayLength(arrayHandle)); } KNI_EndHandles(); KNI_ReturnInt(retval); }
/* * Checks refId for validity, gets its handle value, and stores it * into obj. An error message incorporating msg is emitted if refId is * invalid or if the handle returns is null. */ static void getReference(int refId, char *msg, jobject obj) { if (refId == INVALID_REFERENCE_ID) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "invalid reference ID in %s", msg); REPORT_CRIT(LC_CORE, gKNIBuffer); KNI_ReleaseHandle(obj); } else { SNI_GetReference(refId, obj); if (KNI_IsNullHandle(obj)) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "null reference from SNI_GetReference in %s", msg); REPORT_CRIT(LC_CORE, gKNIBuffer); } } }
/* * Retrieves native connection handle from temporary storage * inside <code>RFCOMMNotifierImpl</code> instance * and sets it to this <code>RFCOMMConnectionImpl</code> instance. * * Note: the method sets native connection handle directly to * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object. * * @param notif reference to corresponding <code>RFCOMMNotifierImpl</code> * instance storing native peer handle */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_setThisConnHandle0) { REPORT_INFO(LC_PROTOCOL, "btspp::setThisConnHandle"); KNI_StartHandles(2); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(notifHandle); KNI_GetThisPointer(thisHandle); KNI_GetParameterAsObject(1, notifHandle); if (KNI_IsNullHandle(notifHandle)) { REPORT_ERROR(LC_PROTOCOL, "Notifier handle is null in btspp::setThisConnHandle"); } else { jfieldID peerHandleID = GetRFCOMMPeerHandleID(); if (peerHandleID == NULL) { REPORT_ERROR(LC_PROTOCOL, "Peer handle ID is not initialized" "in btspp::setThisConnHandle"); } else { javacall_handle handle = (javacall_handle)KNI_GetIntField(notifHandle, peerHandleID); if (handle != JAVACALL_BT_INVALID_HANDLE) { /* store native connection handle to Java */ KNI_SetIntField(thisHandle, connHandleID, (jint)handle); /* reset temporary storing field */ KNI_SetIntField(notifHandle, peerHandleID, (jint)JAVACALL_BT_INVALID_HANDLE); REPORT_INFO(LC_PROTOCOL, "btspp::setThisConnHandle done!"); } else { REPORT_ERROR(LC_PROTOCOL, "Peer handle is invalid in btspp::setThisConnHandle"); } } } KNI_EndHandles(); KNI_ReturnVoid(); }
/* 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); }
/** * Performs reset of the device. * <p>Java declaration: * <pre> * private native int reset0(byte[] atr); * </pre> * @param atr ATR bytes * @return Length of ATR in case of success, else -1 */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_cardreader_PlatformCardDevice_reset0) { jint retcode; javacall_int32 atr_length; char *atr_buffer; MidpReentryData* info; void *context = NULL; javacall_result status_code; KNI_StartHandles(1); KNI_DeclareHandle(atr_handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); KNI_GetParameterAsObject(1, atr_handle); if (KNI_IsNullHandle(atr_handle)) { atr_buffer = NULL; atr_length = 0; } else { atr_length = KNI_GetArrayLength(atr_handle); atr_buffer = SNI_GetRawArrayPointer(atr_handle); } if (info == NULL) { status_code = javacall_carddevice_reset_start(atr_buffer, &atr_length, &context); } else { context = info->pResult; status_code = javacall_carddevice_reset_finish(atr_buffer, &atr_length, context); } if (status_code == JAVACALL_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_RESET, context); goto end; } if (status_code != JAVACALL_OK) { retcode = -1; } else { retcode = atr_length; } end: KNI_EndHandles(); KNI_ReturnInt(retcode); }
/* Return the content of the editor in a Java string. */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(javax_microedition_lcdui_TextFieldLFImpl_getNativeEditorContent) { KNI_StartHandles(1); KNI_DeclareHandle(chars); #if 0 if (editBoxShown) { int strLen = GetWindowTextLength(hwndTextActive); jchar *tmp = (jchar*)midpMalloc((strLen + 1) * sizeof(jchar)); if (tmp) { GetWindowText(hwndTextActive, (LPTSTR)tmp, strLen+1); /* 0-terminated */ SNI_NewArray(SNI_CHAR_ARRAY, strLen, chars); if (!KNI_IsNullHandle(chars)) { memcpy(JavaCharArray(chars), tmp, strLen*sizeof(jchar)); } midpFree((void*)tmp); } } #endif KNI_EndHandlesAndReturnObject(chars); }
/** * Set a jobject field from Java native functions. * * Always use KNI to set an object field instead of setting it directly * using SNI access, since there is more to setting a object in a field * than just moving a reference, there is a flag to tell the the garbage * collector that the field is set to an object and if this flag is not * set then the collector not count the field as a reference which can * lead to premature collection of the object the field is referencing * and then a crash since the field will reference will not be null, it * will be unchanged and invalid. * * @param obj a handle to Java object whose field will be set * @param fieldName field name * @param fieldSignature field signature string * @param newValue a handle to the new Java value of the field */ void midp_set_jobject_field(KNIDECLARGS jobject obj, const char *fieldName, const char *fieldSignature, jobject newValue) { if (KNI_IsNullHandle(obj)) { return; } KNI_StartHandles(1); KNI_DeclareHandle(clazz); KNI_GetObjectClass(obj, clazz); KNI_SetObjectField(obj, midp_get_field_id(KNIPASSARGS clazz, fieldName, fieldSignature), newValue); KNI_EndHandles(); }