/** * private static native void getLinks0(Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_getLinks0(void) { int targetIsolate; jsize len; int i; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = JVM_CurrentIsolateID(); KNI_GetParameterAsObject(1, linkArray); len = KNI_GetArrayLength(linkArray); if (portals != NULL) { if (portals[targetIsolate].count > 0) { rendezvous **rpp = portals[targetIsolate].rppa; for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); setNativePointer(linkObj, rpp[i]); rp_incref(rpp[i]); } } portal_free(&portals[targetIsolate]); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Creates or updates service record in the SDDB. * * @param handle handle of the service record to be updated; * if equals to 0, a new record will be created * @param classes device service classes associated with the record * @param data binary data containing attribute-value pairs in the format * identical to the one used in the AttributeList parameter of * the SDP_ServiceAttributeResponse PDU * @return service record handle, or 0 if the operation fails */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_kvem_jsr082_bluetooth_SDDB_updateRecord(void) { bt_sddbid_t retval; bt_record_t record; bt_sddbid_t old_id = (bt_sddbid_t)KNI_GetParameterAsInt(1); KNI_StartHandles(1); KNI_DeclareHandle(dataHandle); record.id = old_id; record.classes = KNI_GetParameterAsInt(2); KNI_GetParameterAsObject(3, dataHandle); record.data = JavaByteArray(dataHandle); record.size = KNI_GetArrayLength(dataHandle); if (javacall_bt_sddb_update_record(&record.id, record.classes, record.data, record.size) == JAVACALL_OK) { retval = record.id; if (old_id != BT_INVALID_SDDB_HANDLE) { bt_push_update_record(old_id, &record); } javacall_bt_stack_set_service_classes(javacall_bt_sddb_get_service_classes(0)); } else { retval = BT_INVALID_SDDB_HANDLE; } KNI_EndHandles(); KNI_ReturnInt(retval); }
/* * 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); }
/** * 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; }
/** * 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); }
/** * 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); }
KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_midp_jsr82emul_ConnectionEmul_getOutData() { int myHandle = (int)KNI_GetParameterAsInt(1); connection_info_t *info = &emul_data.handled_info[myHandle].conn; jboolean ret = KNI_TRUE; int buflen; LOG1("ConnectionEmul_getOutData(%d)", myHandle); if (info->flags & IN_USE) { KNI_StartHandles(1); KNI_DeclareHandle(buf); KNI_GetParameterAsObject(2, buf); buflen = KNI_GetArrayLength(buf); if (info->out_len < buflen) { LOG1("ConnectionEmul_getOutData(%d) requests too much data", myHandle); ret = KNI_FALSE; } else { memcpy(JavaByteArray(buf), info->out, buflen); info->out_len -= buflen; memmove(info->out, &info->out[buflen], info->out_len); info->out = midpRealloc(info->out, info->out_len); if (info->out_len == 0) { info->out = NULL; } } KNI_EndHandles(); } else { ret = KNI_FALSE; } KNI_ReturnBoolean(ret); }
/** * 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); }
/** * 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; }
/** * Get pointer to internal buffer of Java byte array and * check that expected offset/length can be applied to the buffer * * @param byteArray Java byte array object to get buffer from * @param offset offset of the data needed in the buffer * @param length length of the data needed in the buffer * starting from the offset * @return pointer to the buffer, or NULL if offset/length are * are not applicable. */ static unsigned char *gx_get_java_byte_buffer(KNIDECLARGS kjobject byteArray, int offset, int length) { unsigned char *buffer = (unsigned char *)JavaByteArray(byteArray); int byteArrayLength = KNI_GetArrayLength(byteArray); if (offset < 0 || length < 0 || offset + length > byteArrayLength ) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); return NULL; } return buffer; }
/** * Deletes an entry from the push registry. * <p> * Java declaration: * <pre> * del0([B[B)I * </pre> * * @param connection The connection to remove from the push registry * @param storage The storage name of the current MIDlet suite * * @return <tt>0</tt> if the connection was successfully deleted. * <tt>-1</tt> if the connection was not found. <tt>-2</tt> * if connection was found, but, it belongs to another * MIDlet suite. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_del0) { char *szConn = NULL; int connLen; char *szStore = NULL; int storeLen; int ret = -1; KNI_StartHandles(2); KNI_DeclareHandle(conn); KNI_DeclareHandle(storage); /* Get the connection string. */ KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); if ((szConn = midpMalloc(connLen)) != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); /* Get the storage name string. */ KNI_GetParameterAsObject(2, storage); storeLen = KNI_GetArrayLength(storage); if ((szStore = midpMalloc(storeLen)) != NULL) { KNI_GetRawArrayRegion(storage, 0, storeLen, (jbyte*)szStore); /* Perform the delete operation. */ ret = pushdel(szConn, szStore); midpFree(szStore); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } midpFree(szConn); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); KNI_ReturnInt(ret); }
/* 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); }
/* 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); }
/** * 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); }
/** * Gets the MIDlet name for the given registered push connection. * <p> * Java declaration: * <pre> * getEntry0([B[BI)I * </pre> * * @param connection The connection to add to the push registry * @param midlet A byte array to store the MIDlet name * @param midletsize The size of <tt>midlet</tt> * * @return <tt>0</tt> if successful, otherwise <tt>-1</tt> * * @throw IOException if the registry entry is too long. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_getEntry0) { int midletsize; char *regentry; int regsize ; int ret = -1; int connLen; char *szConn = NULL; midletsize = KNI_GetParameterAsInt(3); KNI_StartHandles(2); KNI_DeclareHandle(conn); KNI_DeclareHandle(regObject); KNI_GetParameterAsObject(1, conn); connLen = KNI_GetArrayLength(conn); ret = -1; if ((szConn = midpMalloc(connLen)) != NULL) { KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn); KNI_GetParameterAsObject(2, regObject); regentry = pushfindconn(szConn); if (NULL != regentry) { regsize = strlen(regentry) + 1; if (regsize < midletsize) { KNI_SetRawArrayRegion(regObject, 0, regsize, (jbyte*)regentry); ret = 0; } else { KNI_ThrowNew(midpIOException, "registration too long"); } } midpFree(szConn); } else { KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_EndHandles(); 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); }
/** * Gets all registered push connections associated with the given MIDlet * suite. * <p> * Java declaration: * <pre> * list0([BZ[BI)I * </pre> * * @param midlet The MIDlet suite to get push registry entries * @param available Which connections to return. If <tt>true</tt>, * only return the connections with available input. * Otherwise, return all connection. * @param connectionlist A comma separated string of connections stored * as a byte array. * @param listsz The maximum length of the byte array that will be * accepted for <tt>connectionlist</tt> * * @return <tt>0</tt> if successful, otherwise <tt>-1</tt> * * @throw IllegalArgumentException If the length <tt>midlet</tt> is * too long. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_list0) { char *midletName = NULL; int available; int connsize; int nameLength; char *conn; int ret = -1; available = KNI_GetParameterAsBoolean(2); connsize = KNI_GetParameterAsInt(4); KNI_StartHandles(2); KNI_DeclareHandle(name); KNI_DeclareHandle(connections); KNI_GetParameterAsObject(1, name); KNI_GetParameterAsObject(3, connections); nameLength = KNI_GetArrayLength(name); midletName = (char*)midpMalloc(nameLength); if (midletName == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetRawArrayRegion(name, 0, nameLength, (jbyte*)midletName); conn = pushfindsuite(midletName, available); if (conn != NULL) { KNI_SetRawArrayRegion(connections, 0, strlen(conn), (jbyte*)conn); midpFree(conn); ret = 0; } midpFree(midletName); } KNI_EndHandles(); KNI_ReturnInt(ret); }
/** * Gets the combined advance width of multiple characters, starting at * the specified offset and for the specified number of characters using * this <tt>Font</tt>. * <p> * Java declaration: * <pre> * charsWidth([CII)I * </pre> * * @param ch the array of characters to be measured * @param offset the index of the first character to measure * @param length the number of characters to measure * * @return the total width of the character range in pixels */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_Font_charsWidth) { int length = (int)KNI_GetParameterAsInt(3); int offset = (int)KNI_GetParameterAsInt(2); int chLen; jint result = 0; KNI_StartHandles(2); KNI_DeclareHandle(ch); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(1, ch); KNI_GetParameterAsObject(0, thisObject); if ((chLen = KNI_GetArrayLength(ch)) == -1) { KNI_ThrowNew(midpNullPointerException, NULL); } else if ( (offset < 0) || (offset > chLen) || (length < 0) || (length > chLen) || ((offset + length) < 0) || ((offset + length) > chLen)) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); } else if (length != 0) { int face, style, size; DECLARE_FONT_PARAMS(thisObject); SNI_BEGIN_RAW_POINTERS; result = gx_get_charswidth(face, style, size, &(JavaCharArray(ch)[offset]), length); SNI_END_RAW_POINTERS; } KNI_EndHandles(); KNI_ReturnInt(result); }
/** * Loads the <tt>ImageData</tt> with the given ARGB integer * array. The array consists of values in the form of 0xAARRGGBB. * <p> * Java declaration: * <pre> * loadRGB(Ljavax/microedition/lcdui/ImageData;[I)V * </pre> * * @param rgbData The array of argb image data */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadRGB) { /* jboolean processAlpha = KNI_GetParameterAsBoolean(2); */ int height; int width; int *rgbBuffer; gxj_screen_buffer sbuf; KNI_StartHandles(2); KNI_DeclareHandle(rgbData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, rgbData); KNI_GetParameterAsObject(1, imageData); width = (int)GXAPI_GET_IMAGEDATA_PTR(imageData)->width; height = (int)GXAPI_GET_IMAGEDATA_PTR(imageData)->height; rgbBuffer = JavaIntArray(rgbData); if (getImageScreenBuffer(imageData, &sbuf) != NULL) { int i; int len = KNI_GetArrayLength(rgbData); int data_length = width * height; if (len > data_length) { len = data_length; } /* if (len != width*height) { * JAVA_TRACE("len mismatch %d != %d\n", len, width*height); * } */ if (sbuf.alphaData != NULL) { for (i = 0; i < len; i++) { sbuf.pixelData[i] = GXJ_RGB24TOPIXEL(rgbBuffer[i]); sbuf.alphaData[i] = (rgbBuffer[i] >> 24) & 0x00ff; } } else { for (i = 0; i < len; i++) {
/** * Retrieves resource data for the given ID and locale. * <p> * Java declaration: * <pre> * getRawResourceData0(I,I,[B)Z * </pre> * * @param hdata byte array to store resource data * @param resource_id resource identifier * @param locale_index index of locale in array of supported locales * @param offset offset of resource to start with * @param length length in bytes to copy * @return length in bytes of copied data */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_global_DevResourceBundleReader_getRawResourceData0) { jint locale_index = KNI_GetParameterAsInt(1); jint resource_id = KNI_GetParameterAsInt(2); jint offset = KNI_GetParameterAsInt(4); jint length = KNI_GetParameterAsInt(5); jint array_len; jbyte* buffer; KNI_StartHandles(1); KNI_DeclareHandle(hdata); KNI_GetParameterAsObject(3, hdata); array_len = KNI_GetArrayLength(hdata); if (array_len < length){ length = 0; KNI_ThrowNew(jsropIllegalArgumentException, "Error! Array size is too few!"); } else { buffer = JAVAME_MALLOC(array_len); if (NULL == buffer) { length = 0; KNI_ThrowNew(jsropOutOfMemoryError, "Cannot allocate buffer for device resource"); } else { if (JSR238_STATUSCODE_OK != jsr238_get_resource(locale_index,resource_id, buffer, offset, &length)) { length = 0; } else { KNI_SetRawArrayRegion(hdata, 0, length, buffer); } JAVAME_FREE(buffer); } } KNI_EndHandles(); KNI_ReturnInt(length); }
/** * 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(); }
/* private native int _eglCreatePbufferSurface ( int display , int config , int [ ] attrib_list ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglCreatePbufferSurface() { jint display = KNI_GetParameterAsInt(1); jint config = KNI_GetParameterAsInt(2); EGLint *attrib_list = (EGLint *)0; jint returnValue = (jint)EGL_NO_SURFACE; KNI_StartHandles(2); KNI_DeclareHandle(attrib_listHandle); KNI_DeclareHandle(thisHandle); KNI_GetParameterAsObject(3, attrib_listHandle); KNI_GetThisPointer(thisHandle); /* 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", "eglCreatePbufferSurface"); goto exit; } KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size, (jbyte *) attrib_list); } #ifdef DEBUG { int idx = 0; int attr; #ifdef DEBUG printf("In eglCreatePbufferSurface:\n"); #endif if (!attrib_list) { #ifdef DEBUG printf("attrib_list is null!\n"); #endif } else { while (1) { attr = attrib_list[idx++]; #ifdef DEBUG printf("attr[%d] = 0x%x\n", idx, attr); #endif if (attr == EGL_NONE) { break; } } } } #endif returnValue = (jint)eglCreatePbufferSurface((EGLDisplay)display, (EGLConfig)config, (EGLint const *) attrib_list); #ifdef DEBUG if (returnValue > 0) { ++surfaces; } printf("eglCreatePbufferSurface(0x%x, 0x%x, attrib_list) = %d, surfaces = %d\n", display, config, returnValue, surfaces); { EGLint error; /* debugging */ error = eglGetError(); if (error != EGL_SUCCESS) { printf("egl error = 0x%x\n", error); } } #endif exit: if (attrib_list) { JSR239_free(attrib_list); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/** * Decodes the given byte array into the <tt>ImageData</tt>. * <p> * Java declaration: * <pre> * loadNative(Ljavax/microedition/lcdui/ImageDataFactory;[BII)Z * </pre> * * @param imageData the ImageData to load to * @param imageBytes A byte array containing the encoded PNG image data * @param offset The start of the image data within the byte array * @param length The length of the image data in the byte array * * @return true if able to decode */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadNative) { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); int status = KNI_TRUE; unsigned char* srcBuffer = NULL; PIXEL* imgPixelData = NULL; ALPHA* imgAlphaData = NULL; java_imagedata* midpImageData = NULL; TBool generateMask = EFalse; KNI_StartHandles(4); KNI_DeclareHandle(pixelData); KNI_DeclareHandle(alphaData); KNI_DeclareHandle(inData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, inData); KNI_GetParameterAsObject(1, imageData); midpImageData = IMGAPI_GET_IMAGEDATA_PTR(imageData); srcBuffer = (unsigned char *)JavaByteArray(inData); int byteArrayLength = KNI_GetArrayLength(inData); if (offset >= 0 && length >= 0 && offset + length <= byteArrayLength) { TPtrC8 sourceData(srcBuffer + offset, length); TInt width; TInt height; if (static_cast<MApplication*>(Dll::Tls())->InitializeDecoder(sourceData, width, height, generateMask) == KErrNone) { midpImageData->width = width; midpImageData->height = height; SNI_NewArray(SNI_BYTE_ARRAY, midpImageData->width * midpImageData->height * 2, pixelData); if (generateMask) { SNI_NewArray(SNI_BYTE_ARRAY, midpImageData->width * midpImageData->height, alphaData); } if (!KNI_IsNullHandle(pixelData) && (!KNI_IsNullHandle(alphaData) || !generateMask)) { if (generateMask) { imgAlphaData = (ALPHA*)JavaByteArray(alphaData); } midp_set_jobject_field(KNIPASSARGS imageData, "pixelData", "[B", pixelData); imgPixelData = (PIXEL*)JavaByteArray(pixelData); if (static_cast<MApplication*>(Dll::Tls())->DecodeImage((char*)imgPixelData, (char*)imgAlphaData) != KErrNone) { status = KNI_FALSE; } if (imgAlphaData) { midp_set_jobject_field(KNIPASSARGS imageData, "alphaData", "[B", alphaData); } } else { status = KNI_FALSE; } } } KNI_EndHandles(); KNI_ReturnBoolean(status); }
/* private native int _eglChooseConfig ( int display , int [ ] attrib_list , int [ ] configs , int config_size , int [ ] num_config ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglChooseConfig() { jint display = KNI_GetParameterAsInt(1); jint config_size = KNI_GetParameterAsInt(4); EGLint *attrib_list = (EGLint *)0; EGLConfig *configs = (EGLConfig *)0; EGLint num_config; jint returnValue = EGL_FALSE; KNI_StartHandles(3); KNI_DeclareHandle(attrib_listHandle); KNI_DeclareHandle(configsHandle); KNI_DeclareHandle(num_configHandle); KNI_GetParameterAsObject(2, attrib_listHandle); KNI_GetParameterAsObject(3, configsHandle); KNI_GetParameterAsObject(5, num_configHandle); if (!KNI_IsNullHandle(attrib_listHandle)) { jint attrib_list_length, attrib_list_size; /* Construct attrib_list as a copy of attrib_listHandle */ attrib_list_length = KNI_GetArrayLength(attrib_listHandle); attrib_list_size = (attrib_list_length + 2)*sizeof(jint); attrib_list = (EGLint *)JSR239_malloc(attrib_list_size); if (!attrib_list) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig"); goto exit; } KNI_GetRawArrayRegion(attrib_listHandle, 0, attrib_list_size, (jbyte *)attrib_list); } #ifdef ALL_WINDOWS_ARE_PIXMAPS // Force queries with SURFACE_TYPE == WINDOW to actually query pixmap if (attrib_list) { jint attr, val, idx; idx = 0; while (1) { attr = attrib_list[idx]; #ifdef DEBUG printf("attr[%d] = %d\n", idx, attr); #endif if (attr == EGL_NONE) { #ifdef DEBUG printf("attr = EGL_NONE, done\n"); #endif break; } if (attr == EGL_SURFACE_TYPE) { #ifdef DEBUG printf("attr = EGL_SURFACE_TYPE\n"); #endif val = attrib_list[idx + 1]; if ((val & EGL_WINDOW_BIT) != 0) { #ifdef DEBUG printf("Switching WINDOW_BIT to PIXMAP_BIT\n"); #endif val |= EGL_PIXMAP_BIT; val &= ~EGL_WINDOW_BIT; } } idx += 2; } } #endif /* Allocate config_size elements if configsHandle is non-null */ if (!KNI_IsNullHandle(configsHandle)) { configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint)); if (!configs) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglChooseConfig"); goto exit; } } returnValue = (jint)eglChooseConfig((EGLDisplay)display, attrib_list, configs, config_size, &num_config); #ifdef DEBUG printf("eglChooseConfig(0x%x, attrib_list, configs, %d, num_config<-%d) = %d\n", display, config_size, num_config, returnValue); #endif /* Copy configs back to Java */ if (returnValue == EGL_TRUE && !KNI_IsNullHandle(configsHandle)) { KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint), (const jbyte *)configs); } /* Set output parameter via num_configHandle */ if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) { KNI_SetIntArrayElement(num_configHandle, 0, num_config); } exit: if (attrib_list) { JSR239_free(attrib_list); } if (configs) { JSR239_free(configs); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/** * private static native void setLinks0(int isolateid, Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_setLinks0(void) { int targetIsolate; int len; int i; int ok = 1; rendezvous *rp; rendezvous **newrppa = NULL; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, linkArray); if (KNI_IsNullHandle(linkArray)) { len = 0; } else { len = KNI_GetArrayLength(linkArray); } for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); if (rp == NULL || rp->state == CLOSED) { ok = 0; KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } if (ok && portals == NULL) { portals = (portal *)pcsl_mem_malloc(JVM_MaxIsolates() * sizeof(portal)); if (portals == NULL) { ok = 0; KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portals[i].count = -1; portals[i].rppa = NULL; } } } if (ok && len > 0) { newrppa = (rendezvous **)pcsl_mem_malloc(len * sizeof(rendezvous *)); if (newrppa == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); ok = 0; } } if (ok) { portal *pp = &portals[targetIsolate]; portal_free(pp); /* at this point the portal's count is zero and rppa is null */ if (len > 0) { for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); /* rp not null, checked above */ newrppa[i] = rp; rp_incref(rp); } pp->count = len; pp->rppa = newrppa; } else if (KNI_IsNullHandle(linkArray)) { pp->count = -1; pp->rppa = NULL; } else { /* len == 0 */ pp->count = 0; pp->rppa = NULL; } midp_thread_signal(LINK_PORTAL_SIGNAL, targetIsolate, 0); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Gets an ARGB integer array from this <tt>ImmutableImage</tt>. The * array consists of values in the form of 0xAARRGGBB. * <p> * Java declaration: * <pre> * getRGB([IIIIIII)V * </pre> * * @param rgbData The target integer array for the ARGB data * @param offset Zero-based index of first ARGB pixel to be saved * @param scanlen Number of intervening pixels between pixels in * the same column but in adjacent rows * @param x The x coordinate of the upper left corner of the * selected region * @param y The y coordinate of the upper left corner of the * selected region * @param width The width of the selected region * @param height The height of the selected region */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(javax_microedition_lcdui_Image_getRGB) { int height = KNI_GetParameterAsInt(7); int width = KNI_GetParameterAsInt(6); int y = KNI_GetParameterAsInt(5); int x = KNI_GetParameterAsInt(4); int scanlength = KNI_GetParameterAsInt(3); int offset = KNI_GetParameterAsInt(2); int buflen; int *rgbBuffer; int img_width; int img_height; jboolean iae = KNI_FALSE; java_imagedata * srcImageDataPtr = NULL; KNI_StartHandles(2); KNI_DeclareHandle(rgbData); KNI_DeclareHandle(thisObject); KNI_GetParameterAsObject(1, rgbData); KNI_GetThisPointer(thisObject); srcImageDataPtr = GET_IMAGE_PTR(thisObject)->imageData; img_width = srcImageDataPtr->width; img_height = srcImageDataPtr->height; /* see if absolute value of scanlength is greater than or equal to width */ if (scanlength >= 0 && scanlength < width) { iae = KNI_TRUE; } else if (scanlength < 0 && (0 - scanlength) < width) { iae = KNI_TRUE; } if (KNI_IsNullHandle(rgbData)) { KNI_ThrowNew(midpNullPointerException, NULL); } else if((y < 0) || (x < 0) || (x + width > img_width) || (y + height > img_height) || iae == KNI_TRUE) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else if (height < 0 || width < 0 ) { /* spec says noop in this case */ } else { buflen = KNI_GetArrayLength(rgbData); if (offset < 0 || offset + ((height - 1) * scanlength) + width > buflen || offset + ((height - 1) * scanlength) < 0) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); } else { gxutl_native_image_error_codes error = GXUTL_NATIVE_IMAGE_NO_ERROR; SNI_BEGIN_RAW_POINTERS; rgbBuffer = JavaIntArray(rgbData); gx_get_argb(srcImageDataPtr, rgbBuffer, offset, scanlength, x, y, width, height, &error); SNI_END_RAW_POINTERS; if (error != GXUTL_NATIVE_IMAGE_NO_ERROR) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Populates a passed in immutable <tt>ImageData</tt> * from the given ARGB integer * array. The array consists of values in the form of 0xAARRGGBB. * <p> * Java declaration: * <pre> * createImmutableImageDecodeRGBImage([Ljavax/microedition/lcdui/ImageData;III)V * </pre> * * @param imageData The <tt>ImadgeData</tt> to be populated * @param rgbData The array of argb image data * @param width The width of the new image * @param height The height of the new image * @param processAlpha If <tt>true</tt>, alpha channel bytes will * be used, otherwise, alpha channel bytes will * be ignored */ KNIEXPORT KNI_RETURNTYPE_VOID Java_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDecodeRGBImage() { jboolean processAlpha = KNI_GetParameterAsBoolean(5); int height = KNI_GetParameterAsInt(4); int width = KNI_GetParameterAsInt(3); jint *imageBuffer = NULL; int buflen; img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; /* pointer to native image structure */ gxpport_image_native_handle newImagePtr; KNI_StartHandles(2); KNI_DeclareHandle(rgbData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, rgbData); KNI_GetParameterAsObject(1, imageData); do { if (KNI_IsNullHandle(rgbData)) { KNI_ThrowNew(midpNullPointerException, NULL); break; } if ((width <= 0) || (height <= 0)) { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } buflen = KNI_GetArrayLength(rgbData); if ((width * height) > buflen) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); break; } imageBuffer = JavaIntArray(rgbData); SNI_BEGIN_RAW_POINTERS; gxpport_decodeimmutable_from_argb(imageBuffer, width, height, processAlpha, &newImagePtr, &creationError); SNI_END_RAW_POINTERS; if (IMG_NATIVE_IMAGE_NO_ERROR == creationError) { java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData); dstImageDataPtr->height = (jint)height; dstImageDataPtr->width = (jint)width; dstImageDataPtr->nativeImageData = (jint)newImagePtr; break; } if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for immutable image"); break; } KNI_ThrowNew(midpIllegalArgumentException, NULL); } while (0); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Performs data transfer to the device. * <p>Java declaration: * <pre> * private native int cmdXfer0(byte[] request, byte[] response); * </pre> * @param request Buffer with request data * @param response Buffer for response data * @return Length of response in case of success, else -1 */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_cardreader_PlatformCardDevice_cmdXfer0) { jint retcode; javacall_int32 tx_length, rx_length; char *tx_buffer, *rx_buffer; MidpReentryData* info; void *context = NULL; javacall_result status_code; KNI_StartHandles(2); KNI_DeclareHandle(request_handle); KNI_DeclareHandle(response_handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); KNI_GetParameterAsObject(1, request_handle); if (KNI_IsNullHandle(request_handle)) { tx_buffer = NULL; tx_length = 0; retcode = -1; goto end; } else { tx_length = KNI_GetArrayLength(request_handle); tx_buffer = SNI_GetRawArrayPointer(request_handle); } KNI_GetParameterAsObject(2, response_handle); if (KNI_IsNullHandle(response_handle)) { rx_buffer = NULL; rx_length = 0; retcode = -1; goto end; } else { rx_length = KNI_GetArrayLength(response_handle); rx_buffer = SNI_GetRawArrayPointer(response_handle); } if (tx_length > 5) { jsize apdu_len = 5 + (tx_buffer[4]&0xFF) + 1; if (tx_length > apdu_len) { tx_length = apdu_len; } } if (info == NULL) { status_code = javacall_carddevice_xfer_data_start(tx_buffer, tx_length, rx_buffer, &rx_length, &context); } else { context = info->pResult; status_code = javacall_carddevice_xfer_data_finish(tx_buffer, tx_length, rx_buffer, &rx_length, context); } if (status_code == JAVACALL_WOULD_BLOCK) { midp_thread_wait(CARD_READER_DATA_SIGNAL, SIGNAL_XFER, context); goto end; } if (status_code != JAVACALL_OK) { retcode = -1; } else { retcode = rx_length; } end: KNI_EndHandles(); KNI_ReturnInt(retcode); }
/** * Extract the parameters ID, Type, URL, arguments and data * and update/copy their values to the InvocStore instance. * @param invoc the StoreInvoc to update * @param invocObj the Java invoc instance * @param tmp1 a temporary object * @param tmp2 a 2nd temporary object * @return TRUE if all the allocations and modifications worked */ static jboolean setParamsFromObj(StoredInvoc* invoc, jobject invocObj, jobject tmp1, jobject tmp2) { jboolean ret = KNI_ENOMEM; /* Assume failure */ do { /* On any error break out of this block */ int len; KNI_GetObjectField(invocObj, urlFid, tmp1); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->url)) break; KNI_GetObjectField(invocObj, typeFid, tmp1); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->type )) break; KNI_GetObjectField(invocObj, actionFid, tmp1); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->action )) break; KNI_GetObjectField(invocObj, IDFid, tmp1); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->ID)) break; /* * Copy the arguments if non-empty. * Always keep the pointers safe so invocFree() * can function correctly. */ KNI_GetObjectField(invocObj, argumentsFid, tmp2); len = (KNI_IsNullHandle(tmp2)? 0: KNI_GetArrayLength(tmp2)); if (len <= 0) { invoc->argsLen = 0; invoc->args = NULL; } else { pcsl_string* args; args = (pcsl_string*)pcsl_mem_malloc(len * sizeof(pcsl_string)); if (args == NULL) break; invoc->argsLen = len; invoc->args = args; args += len; while (len-- > 0) { KNI_GetObjectArrayElement(tmp2, len, tmp1); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, --args)) break; } } /* Copy any data from the Invocation to malloc's memory. */ KNI_GetObjectField(invocObj, dataFid, tmp2); len = (KNI_IsNullHandle(tmp2)? 0: KNI_GetArrayLength(tmp2)); if (len <= 0) { invoc->data = NULL; invoc->dataLen = 0; } else { invoc->data = pcsl_mem_malloc(len); if (invoc->data == NULL) break; KNI_GetRawArrayRegion(tmp2, 0, len, invoc->data); invoc->dataLen = len; } /* Clear to indicate everything worked. */ ret = KNI_TRUE; } while (0); return ret; }
/** * Copy a native Invocation to the supplied Invocation instance. * @param invoc the native InvocStore * @param mode the mode of copyout * @param invocObj the Invocation object to copy to * @param argsObj an object to use to refer to the arguments array * @param obj a temporary object handle * @return 0 if there were problems allocating Java Strings; * 1 if all the copies succeeded; * -1 if the Java Arrays allocated for args or data were insufficient */ static int copyOut(StoredInvoc *invoc, int mode, jobject invocObj, jobject argsObj, jobject obj) { int datalen = 0; int arraylen = 0; /* Set the required lengths for args and data arrays. */ KNI_SetIntField(invocObj, argsLenFid, invoc->argsLen); KNI_SetIntField(invocObj, dataLenFid, invoc->dataLen); /* Check if size of argument array and data array are correct. */ KNI_GetObjectField(invocObj, dataFid, obj); datalen = KNI_GetArrayLength(obj); if (datalen != invoc->dataLen) { /* Data array allocated by Java is not correct size. */ return -1; } KNI_GetObjectField(invocObj, argumentsFid, obj); arraylen = KNI_GetArrayLength(obj); if (arraylen != invoc->argsLen) { /* Args array allocated by Java is not correct size. */ return -1; } /* Copy out all the string fields. */ if (!(storeField(&invoc->url, invocObj, urlFid, obj) && storeField(&invoc->type, invocObj, typeFid, obj) && storeField(&invoc->action, invocObj, actionFid, obj) && storeField(&invoc->ID, invocObj, IDFid, obj) && storeField(&invoc->invokingClassname, invocObj, invokingClassnameFid, obj) && storeField(&invoc->invokingAuthority, invocObj, invokingAuthorityFid, obj) && storeField(&invoc->invokingAppName, invocObj, invokingAppNameFid, obj) && storeField(&invoc->invokingID, invocObj, invokingIDFid, obj) && storeField(&invoc->username, invocObj, usernameFid, obj) && storeField(&invoc->password, invocObj, passwordFid, obj))) { /* Some String allocation failed. */ return 0; } KNI_SetIntField(invocObj, invokingSuiteIdFid, invoc->invokingSuiteId); /* See if the suite and classname are needed. */ if (mode == MODE_TID || mode == MODE_TID_PREV || mode == MODE_TID_NEXT) { if (!storeField(&invoc->classname, invocObj, classnameFid, obj)) { /* A string allocation failed. */ return 0; } KNI_SetIntField(invocObj, suiteIdFid, invoc->suiteId); } /* Return the arguments if any; array length already checked. */ if (invoc->argsLen > 0) { int ndx; pcsl_string* args; /* For each stored arg create a string and store in the array. * No stored arg is null. If a string cannot be created * it is due to insufficient heap memory. */ KNI_GetObjectField(invocObj, argumentsFid, argsObj); args = invoc->args; for (ndx = 0; ndx < invoc->argsLen; ndx++, args++) { if (!pcsl_string_is_null(args)) { if (PCSL_STRING_OK != midp_jstring_from_pcsl_string(args, obj)) { /* String create failed; exit now. */ return 0; } } else { KNI_ReleaseHandle(obj); } KNI_SetObjectArrayElement(argsObj, ndx, obj); } } /* Return the data array if any; array length was already checked. */ if (invoc->dataLen > 0) { KNI_GetObjectField(invocObj, dataFid, obj); KNI_SetRawArrayRegion(obj, 0, invoc->dataLen, invoc->data); } KNI_SetBooleanField(invocObj, responseRequiredFid, invoc->responseRequired); KNI_SetIntField(invocObj, statusFid, invoc->status); KNI_SetIntField(invocObj, tidFid, invoc->tid); KNI_SetIntField(invocObj, previousTidFid, invoc->previousTid); /* Successful copy out. */ return 1; }