/** * boolean loadRomizedImage(IamgeData imageData, int imageDataArrayPtr, * int imageDataArrayLength); */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_javax_microedition_lcdui_ImageDataFactory_loadRomizedImage() { int status = KNI_FALSE; int imageDataArrayPtr = KNI_GetParameterAsInt(2); int imageDataArrayLength = KNI_GetParameterAsInt(3); int imgWidth, imgHeight; img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; /* pointer to native image structure */ gxpport_image_native_handle newImagePtr; KNI_StartHandles(1); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(1, imageData); do { unsigned char* buffer = (unsigned char*)imageDataArrayPtr; gxpport_loadimmutable_from_platformbuffer( buffer, imageDataArrayLength, KNI_TRUE, &imgWidth, &imgHeight, &newImagePtr, &creationError); if (IMG_NATIVE_IMAGE_NO_ERROR == creationError) { java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData); dstImageDataPtr->width = (jint)imgWidth; dstImageDataPtr->height = (jint)imgHeight; dstImageDataPtr->nativeImageData = (jint)newImagePtr; status = KNI_TRUE; break; } else if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } else if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for immutable image"); break; } else { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } while (0); KNI_EndHandles(); KNI_ReturnBoolean(status); }
/** * Compare two strings using locale- and level-specific rules. * <p> * Java declaration: * <pre> * compare0(Ljava/lang/String;Ljava/lang/String;II)I * </pre> * * @param locale_index the locale index in supported locales list * @param hstr1 first string to compare * @param hstr2 second string to compare * @param level the collation level to use * @return negative if <code>s1</code> belongs before <code>s2</code>, * zero if the strings are equal, positive if <code>s1</code> belongs * after <code>s2</code> */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_j2me_global_StringComparatorImpl_compare0() { jint locale_index = KNI_GetParameterAsInt(1); jint level = KNI_GetParameterAsInt(4); jchar *s1, *s2; jsize s1_len, s2_len; jint res, compare_result = 0; KNI_StartHandles(2); KNI_DeclareHandle(hstr1); KNI_DeclareHandle(hstr2); KNI_GetParameterAsObject(2, hstr1); KNI_GetParameterAsObject(3, hstr2); s1_len = KNI_GetStringLength(hstr1); if (s1_len == -1){ KNI_ThrowNew(midpNullPointerException, NULL); } else { s1 = (jchar *)midpMalloc(s1_len * sizeof(jchar)); if (NULL == s1) { KNI_ThrowNew(midpOutOfMemoryError, "Cannot allocate string for collation"); } else { s2_len = KNI_GetStringLength(hstr2); if (s2_len == -1){ KNI_ThrowNew(midpNullPointerException, NULL); } else { s2 = (jchar *)midpMalloc(s2_len * sizeof(jchar)); if (NULL == s2) { KNI_ThrowNew(midpOutOfMemoryError, "Cannot allocate string for collation"); } else { KNI_GetStringRegion(hstr1, 0, s1_len, s1); KNI_GetStringRegion(hstr2, 0, s2_len, s2); res = jsr238_compare_strings(locale_index, s1, s1_len, s2, s2_len, level, &compare_result); if (res < 0){ KNI_ThrowNew(midpRuntimeException,"Error comparing strings"); } midpFree(s2); } } midpFree(s1); } } KNI_EndHandles(); KNI_ReturnInt(compare_result); }
/** * java call: * private native String getValues0(String callerId, int searchBy); */ KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_content_RegistryStore_getValues0(void) { jsr211_field searchBy; pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER; JSR211_RESULT_STRARRAY result = _JSR211_RESULT_INITIALIZER_; KNI_StartHandles(1); KNI_DeclareHandle(strObj); // String object do { KNI_GetParameterAsObject(1, strObj); // callerId if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(strObj, &callerId)) { KNI_ThrowNew(midpOutOfMemoryError, "RegistryStore_getValues0 no memory for string arguments"); break; } searchBy = (jsr211_field) KNI_GetParameterAsInt(2); jsr211_get_all(&callerId, searchBy, &result); } while (0); pcsl_string_free(&callerId); result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, strObj); KNI_EndHandlesAndReturnObject(strObj); }
/* * Returns the number of bytes available to be read from the connection * without blocking. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPConnectionImpl</code> object. * * @return the number of available bytes * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_available0) { javacall_handle handle; int count = -1; char* pError; REPORT_INFO(LC_PROTOCOL, "btspp::available"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); switch (javacall_bt_rfcomm_get_available(handle, &count)) { case JAVACALL_OK: REPORT_INFO(LC_PROTOCOL, "btspp::available done!"); break; case JAVACALL_FAIL: javacall_bt_rfcomm_get_error(handle, &pError); JAVAME_SNPRINTF(gBtBuffer, BT_BUFFER_SIZE, "IO error during btspp::::available (%s)", pError); REPORT_ERROR(LC_PROTOCOL, gBtBuffer); KNI_ThrowNew(jsropIOException, EXCEPTION_MSG(gBtBuffer)); break; default: /* illegal argument */ REPORT_ERROR(LC_PROTOCOL, "Internal error in btspp::available"); } KNI_EndHandles(); KNI_ReturnInt(count); }
/** * Gets the total advance width of the given <tt>String</tt> in this * <tt>Font</tt>. * <p> * Java declaration: * <pre> * stringWidth(Ljava/lang/String;)I * </pre> * * @param str the <tt>String</tt> to be measured * * @return the total advance width of the <tt>String</tt> in pixels */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_Font_stringWidth) { int strLen; jint result = 0; KNI_StartHandles(2); KNI_DeclareHandle(str); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(1, str); KNI_GetParameterAsObject(0, thisObject); if ((strLen = KNI_GetStringLength(str)) == -1) { KNI_ThrowNew(midpNullPointerException, NULL); } else { int face, style, size; _JavaString *jstr; DECLARE_FONT_PARAMS(thisObject); SNI_BEGIN_RAW_POINTERS; jstr = GET_STRING_PTR(str); result = gx_get_charswidth(face, style, size, jstr->value->elements + jstr->offset, strLen); SNI_END_RAW_POINTERS; } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Adds a connection to the push registry. * <p> * Java declaration: * <pre> * add0([B)I * </pre> * * @param connection The connection to add to the push registry * * @return <tt>0</tt> upon successfully adding the connection, otherwise * <tt>-1</tt> if connection already exists */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_add0) { char *szConn = NULL; int connLen; int ret = -1; KNI_StartHandles(1); KNI_DeclareHandle(conn); KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); szConn = midpMalloc(connLen); if (szConn != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); ret = pushadd(szConn); midpFree(szConn); } if ((szConn == NULL) || (ret == -2)) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnInt(ret); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_j2me_location_PlatformLocationProvider_resetImpl() { MidpReentryData *info = NULL; ProviderInfo *pInfo = NULL; jint provider = KNI_GetParameterAsInt(1); jsr179_result res; info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* reset provider */ res = jsr179_update_cancel((jsr179_handle)provider); switch (res) { case JSR179_STATUSCODE_OK: case JSR179_STATUSCODE_FAIL: break; case JSR179_STATUSCODE_INVALID_ARGUMENT: /* wrong provider name */ KNI_ThrowNew(midpIllegalArgumentException, "wrong provider"); break; case JSR179_STATUSCODE_WOULD_BLOCK: /* wait for javanotify */ pInfo = getProviderInfo(provider); if(pInfo != NULL) { pInfo->locked = KNI_FALSE; } lock_thread(JSR179_EVENT_UPDATE_ONCE, provider); break; default: break; } } KNI_ReturnVoid(); }
/* * 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); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_openLandmarkList) { javacall_handle hndl = 0; javacall_result res; KNI_StartHandles(2); GET_PARAMETER_AS_UTF16_STRING(1, storeName) GET_PARAMETER_AS_UTF16_STRING(2, categoryName) res = javacall_landmarkstore_landmarklist_open(storeName, categoryName, &hndl); switch (res) { case JAVACALL_OK: /* Category list open successfully */ break; case JAVACALL_INVALID_ARGUMENT: /* wrong category name */ break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } RELEASE_UTF16_STRING_PARAMETER RELEASE_UTF16_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnInt((jint)hndl); }
/** * 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(); }
/** * Perform a platform-defined procedure for obtaining random bytes and * store the obtained bytes into b, starting from index 0. * (see IETF RFC 1750, Randomness Recommendations for Security, * http://www.ietf.org/rfc/rfc1750.txt) * @param b array that receives random bytes * @param nbytes the number of random bytes to receive, must not be less than size of b * @return the number of actually obtained random bytes, -1 in case of an error */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(com_sun_midp_crypto_PRand_getRandomBytes) { jint size; jboolean res = KNI_FALSE; unsigned char* buffer; KNI_StartHandles(1); KNI_DeclareHandle(hBytes); KNI_GetParameterAsObject(1, hBytes); size = KNI_GetParameterAsInt(2); buffer = pcsl_mem_malloc(size); if (0 == buffer) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { int i; res = get_random_bytes_port(buffer, size); for(i=0; i<size; i++) { KNI_SetByteArrayElement(hBytes,i,(jbyte)buffer[i]); } pcsl_mem_free(buffer); } KNI_EndHandles(); KNI_ReturnBoolean(res); }
/** * Gets the length of a specific converted string as an array of * Unicode characters. * <p> * Java declaration: * <pre> * sizeOfUnicodeInByte(I[CII)I * </pre> * * @param handler handle returned from getHandler * @param c buffer of characters to be converted * @param offset offset into the provided buffer * @param length length of data to be processed * * @return length of the converted string, or zero if the * arguments were not valid */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_sizeOfUnicodeInByte() { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); int id = KNI_GetParameterAsInt(1); jchar *buf; jint result = 0; KNI_StartHandles(1); KNI_DeclareHandle(c); KNI_GetParameterAsObject(2, c); /* 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. */ buf = (jchar*)midpMalloc(length<<1); if (buf == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetRawArrayRegion(c, offset<<1, length<<1, (jbyte*)buf); result = lcConv[id] ? lcConv[id]->sizeOfUnicodeInByte((const jchar *)buf, offset, length) : 0; midpFree(buf); } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Gets the length of a specific converted string as an array of * Unicode bytes. * <p> * Java declaration: * <pre> * sizeOfByteInUnicode(I[BII)I * </pre> * * @param handler handle returned from getHandler * @param b buffer of bytes to be converted * @param offset offset into the provided buffer * @param length length of data to be processed * * @return length of the converted string, or zero if the * arguments were not valid */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_sizeOfByteInUnicode() { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); int id = KNI_GetParameterAsInt(1); char *buf; jint result = 0; KNI_StartHandles(1); KNI_DeclareHandle(b); KNI_GetParameterAsObject(2, b); buf = (char*)midpMalloc(length); if (buf == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetRawArrayRegion(b, offset, length, (jbyte*)buf); result = lcConv[id] ? lcConv[id]->sizeOfByteInUnicode((const unsigned char *)buf, offset, length) : 0; midpFree(buf); } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * 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); }
/** * java call: * private native String getHandler0(String callerId, String id, int mode); */ KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_content_RegistryStore_getHandler0(void) { int mode; pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER; pcsl_string id = PCSL_STRING_NULL_INITIALIZER; JSR211_RESULT_CH handler = _JSR211_RESULT_INITIALIZER_; KNI_StartHandles(2); KNI_DeclareHandle(callerObj); KNI_DeclareHandle(handlerObj); do { KNI_GetParameterAsObject(1, callerObj); KNI_GetParameterAsObject(2, handlerObj); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(callerObj, &callerId) || PCSL_STRING_OK != midp_jstring_to_pcsl_string(handlerObj, &id)) { KNI_ThrowNew(midpOutOfMemoryError, "RegistryStore_getHandler0 no memory for string arguments"); break; } mode = KNI_GetParameterAsInt(3); jsr211_get_handler(&callerId, &id, mode, &handler); } while (0); pcsl_string_free(&callerId); pcsl_string_free(&id); result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&handler, handlerObj); KNI_EndHandlesAndReturnObject(handlerObj); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_openCategoryList) { javacall_handle pHandle; jint hndl = 0; javacall_result res; KNI_StartHandles(1); GET_PARAMETER_AS_UTF16_STRING(1, storeName) /* call provider_open to get provider handler */ res = javacall_landmarkstore_categorylist_open(storeName, &pHandle); switch (res) { case JAVACALL_OK: /* Category list open successfully */ hndl = (jint)pHandle; break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } RELEASE_UTF16_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnInt(hndl); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_j2me_location_LocationPersistentStorage_deleteLandmarkFromCategoryImpl) { jint landmarkID; javacall_result res; KNI_StartHandles(2); GET_PARAMETER_AS_UTF16_STRING(1, storeName) landmarkID = KNI_GetParameterAsInt(2); GET_PARAMETER_AS_UTF16_STRING(3, categoryName) res = javacall_landmarkstore_landmark_delete_from_category(storeName, (javacall_handle)landmarkID, categoryName); switch (res) { case JAVACALL_OK: /* Category added successfully */ break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } RELEASE_UTF16_STRING_PARAMETER RELEASE_UTF16_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnVoid(); }
/** * KNI function that sets new content on the native resource corresponding to * the current StringItem. * * Class: javax.microedition.lcdui.StringLFImpl * Java prototype: * private native int setContent0(int nativeId, Image image, altText, * appearanceMode) * * INTERFACE (operand stack manipulation): * parameters: nativeId pointer to the native resource of the StringItem * text the new string set in the StringItem * appearanceMode the appearance mode of the passed in text * returns: <nothing> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_javax_microedition_lcdui_StringItemLFImpl_setContent0() { MidpError err = KNI_OK; MidpItem *itemPtr = (MidpItem *)KNI_GetParameterAsInt(1); int appearanceMode = KNI_GetParameterAsInt(3); pcsl_string text; pcsl_string_status rc; KNI_StartHandles(1); KNI_DeclareHandle(textJString); KNI_GetParameterAsObject(2, textJString); rc = midp_kjstring_to_pcsl_string(textJString, &text); KNI_EndHandles(); if (PCSL_STRING_OK != rc) { err = KNI_ENOMEM; } else { err = lfpport_stringitem_set_content(itemPtr, &text, appearanceMode); } pcsl_string_free(&text); if (err == KNI_ENOMEM) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnVoid(); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_landmarkStoreGetNext) { javacall_handle hndl; javacall_result res; javacall_utf16_string storeName; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); hndl = (javacall_handle)KNI_GetParameterAsInt(1); res = javacall_landmarkstore_list_next(hndl, &storeName); switch (res) { case JAVACALL_OK: /* LandmarkStore name returned successfully */ if (storeName != NULL) { jsrop_jstring_from_utf16_string(KNIPASSARGS storeName, stringObj); } else { /* Category name returned successfully */ KNI_ReleaseHandle(stringObj); } break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } KNI_EndHandlesAndReturnObject(stringObj); }
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); }
/** * Gets the value of the specified property key in the internal * property set. If the key is not found in the internal property * set, the application property set is then searched. * <p> * Java declaration: * <pre> * getProperty0(Ljava.lang.String;)Ljava.lang.String; * <pre> * * @param key The key to search for * * @return The value associated with <tt>key<tt> if found, otherwise * <tt>null<tt> */ KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_midp_main_Configuration_getProperty0) { jchar* uStr; const char* key; const char* value; int strLen; KNI_StartHandles(2); KNI_DeclareHandle(str); KNI_DeclareHandle(result); KNI_GetParameterAsObject(1, str); strLen = KNI_GetStringLength(str); if (strLen <= 0 || (uStr = (jchar*) midpMalloc(strLen * sizeof(jchar))) == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetStringRegion(str, 0, strLen, uStr); key = UnicodeToCString(uStr, strLen); midpFree(uStr); /* Look up the property value */ value = getInternalProperty(key); midpFree((void *)key); if (value != NULL) { KNI_NewStringUTF(value, result); } else { KNI_ReleaseHandle(result); } } KNI_EndHandlesAndReturnObject(result); }
/** * 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); }
/** * Updates the parameters of the invocation in the native store. * The ID, URL, Type, arguments, and data are stored again in native. * The key into the native store is the TID; * * @param invoc the InvocationImpl to update the native params * @see StoredInvoc * @see #invocQueue */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_content_InvocationStore_setParams0(void) { StoredLink* link; StoredInvoc* invoc; int tid; KNI_StartHandles(3); KNI_DeclareHandle(invocObj); KNI_DeclareHandle(obj1); KNI_DeclareHandle(obj2); KNI_GetParameterAsObject(1, invocObj); init(invocObj, obj1); /* Find the matching entry in the queue */ tid = KNI_GetIntField(invocObj, tidFid); link = invocFindTid(tid); if (link != NULL) { invoc = link->invoc; if (KNI_TRUE != setParamsFromObj(invoc, invocObj, obj1, obj2)) { KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c: setParam0() allocation failed"); } } else { #if REPORT_LEVEL <= LOG_CRITICAL REPORT_CRIT(LC_NONE, "invocStore.c: setParam0() no entry for tid"); #endif } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * private native void init0(int sender, int receiver); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_init0(void) { int sender; int receiver; rendezvous *rp; KNI_StartHandles(1); KNI_DeclareHandle(thisObj); sender = KNI_GetParameterAsInt(1); receiver = KNI_GetParameterAsInt(2); KNI_GetThisPointer(thisObj); rp = rp_create(sender, receiver); if (rp == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { setNativePointer(thisObj, rp); rp_incref(rp); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Adds an entry to the alarm registry. * <p> * Java declaration: * <pre> * addalarm0([BJ)J * </pre> * * @param midlet The entry to add to the alarm registry * @param time The time the alarm will be go off * * @return <tt>0</tt> if this is the first alarm registered with * the given <tt>midlet</tt>, otherwise the time of the * previosly registered alarm. */ KNIEXPORT KNI_RETURNTYPE_LONG KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_addAlarm0) { char *szConn = NULL; int connLen; jlong alarm = 0; jlong lastalarm = 0; int ret = 0; alarm = KNI_GetParameterAsLong(2); KNI_StartHandles(1); KNI_DeclareHandle(conn); KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); szConn = midpMalloc(connLen); if (szConn != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); ret = alarmadd(szConn, alarm, &lastalarm); midpFree(szConn); } if ((szConn == NULL) || (ret == -2)) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnLong(lastalarm); }
/** * KNI function that makes native form visible. * Java Prototype: void showNativeResource0(int nativeId, * int modelVersion, * int w, int h) * CLASS: javax.microedition.lcdui.FormLFImpl * Param: nativeId Id of previously created Form native resource * Param: modelVersion version id of the data passed in from Java * Param: w width of all form content * Param: h height of all form content */ KNIEXPORT KNI_RETURNTYPE_VOID Java_javax_microedition_lcdui_FormLFImpl_showNativeResource0() { int w, h; MidpError err; MidpDisplayable *formPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); /* Initialize data model version for this new visible period */ formPtr->frame.component.modelVersion = KNI_GetParameterAsInt(2); w = KNI_GetParameterAsInt(3); h = KNI_GetParameterAsInt(4); /* Set form window virtual size */ err = lfpport_form_set_content_size(formPtr, w, h); if (err != KNI_OK) goto cleanup; if (MidpCurrentScreen != &formPtr->frame) { /* Becomes the new current screen that receives events */ MidpCurrentScreen = &formPtr->frame; /* * NOTE: MidpCurrentScreen is needed before it is shown because * on show its children may want to notify their appearance. */ /* Show Form window */ err = formPtr->frame.show(&formPtr->frame); } cleanup: if (err != KNI_OK) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnVoid(); }
/* * Closes client connection. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object. * * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_close0) { javacall_handle handle; REPORT_INFO(LC_PROTOCOL, "btspp::close"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); if (handle != JAVACALL_BT_INVALID_HANDLE) { if (javacall_bt_rfcomm_close(handle) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "RFCOMM connection closing failed in btspp::close"); KNI_ThrowNew(jsropIOException, EXCEPTION_MSG("RFCOMM connection closing failed")); } else { // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, connHandleID, (jint)JAVACALL_BT_INVALID_HANDLE); } REPORT_INFO(LC_PROTOCOL, "btspp::close done!"); KNI_EndHandles(); KNI_ReturnVoid(); }
/* private native int _eglCopyBuffers ( int display , int surface , Graphics target ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglCopyBuffers() { EGLDisplay display = (EGLDisplay) KNI_GetParameterAsInt(1); EGLSurface surface = (EGLSurface) KNI_GetParameterAsInt(2); jint width = KNI_GetParameterAsInt(4); jint height = KNI_GetParameterAsInt(5); jint flip = 0; JSR239_Pixmap *pixmap = (JSR239_Pixmap *) 0; EGLBoolean returnValue = EGL_FALSE; KNI_StartHandles(1); KNI_DeclareHandle(graphicsHandle); KNI_GetParameterAsObject(3, graphicsHandle); returnValue = (jint)eglCopyBuffers((EGLDisplay) display, (EGLSurface) surface, (NativePixmapType) pixmap); #ifdef DEBUG printf("eglCopyBuffers(0x%x, 0x%x, 0x%x) = %d\n", display, surface, pixmap, returnValue); #endif /* Workaround - use glReadPixels if eglCopyBuffers fails. */ if (returnValue == EGL_FALSE) { pixmap = JSR239_getImagePixmap(graphicsHandle, width, height, 4, 8, 8, 8, 8); if (!pixmap) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglCopyBuffers"); goto exit; } // Enforce RGBA order of glReadPixels pixmap->aOffset = 24; pixmap->bOffset = 16; pixmap->gOffset = 8; pixmap->rOffset = 0; returnValue = eglCopyBuffersWorkaround((EGLDisplay) display, (EGLSurface) surface, pixmap); flip = 1; } if (returnValue == EGL_TRUE) { JSR239_putWindowContents(graphicsHandle, pixmap, flip); } if (pixmap) { JSR239_destroyPixmap(pixmap); } exit: KNI_EndHandles(); KNI_ReturnInt((jint)returnValue); }
KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_amms_DirectSoundSource3D_nCheckSupported) { KNIPlayerInfo* pKniInfo = (KNIPlayerInfo*)KNI_GetParameterAsInt(1); javacall_handle player = (javacall_handle)(pKniInfo->pNativeHandle); javacall_result result = JAVACALL_FAIL; javacall_media_format_type format; const javacall_media_format_type* supported; int num; if (JAVACALL_OK == javacall_media_get_format(player, &format) && NULL != (supported = javacall_audio3d_get_supported_soundsource3d_player_types(&num))) { int i; for (i = 0; i < num; i++) { if (javautil_string_equals(format, supported[i])) { result = JAVACALL_OK; break; } } } if (JAVACALL_OK != result) { KNI_ThrowNew("javax/microedition/media/MediaException", "\nThe Player cannot be added to SoundSource3D\n" ); } KNI_ReturnVoid(); }
/** * Force Bluetooth stack to listen for incoming client connections. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object. * * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_listen0(void) { javacall_handle handle = BT_INVALID_HANDLE; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::listen"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); if (KNI_GetIntField(thisHandle, pushHandleID) == BT_INVALID_PUSH_HANDLE) { handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); /* force listening */ if (javacall_bt_l2cap_listen(handle) == JAVACALL_FAIL) { javacall_bt_l2cap_close(handle); REPORT_ERROR(LC_PROTOCOL, "L2CAP notifier listen failed in btl2cap_notif::listen"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("L2CAP notifier listen failed")); } else { REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::listen done!"); } } KNI_EndHandles(); KNI_ReturnVoid(); }