/** * KNI function that creates native resource for the current StringItem. * * Class: javax.microedition.lcdui.StringItemLFImpl * * Java prototype: * private native int createNativeResource0(int ownerId, * String label, int layout, String text, int maxSize, * int constraints, String initialInputMode) * * INTERFACE (operand stack manipulation): * parameters: ownerId id of the owner's native resource * label StringItem's label * layout StringItem's layout * text StringItem's text * appearanceMode the appearanceMode of StringItem * font font to paint text * returns: id of the created platform widget */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_StringItemLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr; MidpItem *itemPtr = NULL; pcsl_string label, text; pcsl_string_status rc1 = PCSL_STRING_OK, rc2 = PCSL_STRING_OK; PlatformFontPtr fontPtr = NULL; int appearanceMode, layout; KNI_StartHandles(4); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(textJString); KNI_DeclareHandle(fontJFont); KNI_DeclareHandle(fontHandle); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelJString); layout = KNI_GetParameterAsInt(3); KNI_GetParameterAsObject(4, textJString); appearanceMode = KNI_GetParameterAsInt(5); KNI_GetParameterAsObject(6, fontJFont); if (KNI_IsNullHandle(fontJFont) != KNI_TRUE) { int face, style, size; KNI_FindClass("javax/microedition/lcdui/Font", fontHandle); face = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face", "I", _f_face_cache)); style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "style", "I", _f_style_cache)); size = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size", "I", _f_size_cache)); err = lfpport_get_font(&fontPtr, face, style, size); } if (err == KNI_OK) { rc1 = midp_kjstring_to_pcsl_string(labelJString, &label); rc2 = midp_kjstring_to_pcsl_string(textJString, &text); } KNI_EndHandles(); if (err != KNI_OK || PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) { err = KNI_ENOMEM; goto cleanup; } itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_STRING_ITEM_TYPE+appearanceMode); if (itemPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } err = lfpport_stringitem_create(itemPtr, ownerPtr, &label, layout, &text, fontPtr, appearanceMode); cleanup: pcsl_string_free(&text); pcsl_string_free(&label); if (err != KNI_OK) { MidpDeleteItem(itemPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(itemPtr); }
/** * Open a serial port by system dependent device name. * * @param name device name of the port * @param baud baud rate to set the port at * @param flags options for the serial port * * @return handle to a native serial port * * @exception IOException if an I/O error occurs. */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_comm_Protocol_native_1openByName() { int flags = (int)KNI_GetParameterAsInt(3); int baud = (int)KNI_GetParameterAsInt(2); int nameLen; char szName[MAX_NAME_LEN]; jchar* temp; int hPort = (int)INVALID_HANDLE; int i; int status = PCSL_NET_IOERROR; void* context = NULL; MidpReentryData* info; KNI_StartHandles(1); KNI_DeclareHandle(nameObject); KNI_GetParameterAsObject(1, nameObject); info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { nameLen = KNI_GetStringLength(nameObject); if (nameLen > MAX_NAME_LEN) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Serial device name has wrong length: %d\n", nameLen); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpIllegalArgumentException, gKNIBuffer); } else { temp = (jchar*)szName; KNI_GetStringRegion(nameObject, 0, nameLen, temp); /* device names are in ASCII */ for (i = 0; i < nameLen; i++) { szName[i] = (char)temp[i]; } szName[nameLen] = 0; status = openPortByNameStart(szName, baud, flags, &hPort, &context); } } else { /* reinvocation */ hPort = info->descriptor; context = info->pResult; status = openPortByNameFinish(szName, baud, flags, &hPort, context); } switch (status) { case PCSL_NET_SUCCESS: /* do nothing and return normally */ break; case PCSL_NET_INTERRUPTED: midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Opening port %s has been interrupted\n", szName); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpInterruptedIOException, gKNIBuffer); break; case PCSL_NET_WOULDBLOCK: midp_thread_wait(COMM_OPEN_SIGNAL, hPort, context); break; default: midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Opening port %s was failed\n", szName); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); } KNI_EndHandles(); KNI_ReturnInt((jint)hPort); }
/** * 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(); }
/** * * Resets the request or response flags for listener notification. * Each request or response is marked as not having been notified. * * @param suiteId to match a pending invocation * @param classname to match a pending invocation * @param mode one of {@link #MODE_LREQUEST}, {@link #MODE_LRESPONSE} */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_content_InvocationStore_setListenNotify0(void) { StoredLink* link; StoredInvoc* invoc; SuiteIdType desiredSuiteId; pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER; KNI_StartHandles(2); KNI_DeclareHandle(classname); /* Arg2: non-null classname */ int mode; /* Arg3: requested invocation mode */ /* Argument indices must match Java native method declaration */ #define listenSuiteIdArg 1 #define listenClassnameArg 2 #define listenModeArg 3 do {/* Block to break out of on exceptions */ if (!isEmpty()) { /* Queue is not empty * Need a string copy of the desired suiteId and classname * to use for comparisons */ desiredSuiteId = KNI_GetParameterAsInt(listenSuiteIdArg); KNI_GetParameterAsObject(listenClassnameArg, classname); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, &desiredClassname)) { KNI_ThrowNew(midpOutOfMemoryError, "InvocationStore_setListenNotify0 no memory for [desiredClassname]"); break; } /* Get the desired request mode. */ mode = KNI_GetParameterAsInt(listenModeArg); /* Inspect the queue of Invocations and pick one that * matches the suiteId and classname */ for (link = invocQueue; link != NULL; link = link->flink) { invoc = link->invoc; /* * If the status matches the request * and the suite matches and the classname matches. */ if (mode == MODE_LREQUEST && invoc->status == STATUS_INIT) { /* This invocation is a match; check classname and suite below */ } else if (mode == MODE_LRESPONSE && (invoc->status >= STATUS_OK && invoc->status <= STATUS_INITIATED)) { /* A pending response; check classname and suite below */ } else { /* Not this invocation; on to the next */ continue; } /* Check if this is the right class and suite */ if (desiredSuiteId == invoc->suiteId && pcsl_string_equals(&desiredClassname, &invoc->classname)) { /* Reset the flag so this Invocation will notify. */ invoc->notified = KNI_FALSE; } } } } while (KNI_FALSE); /* TBD: MidpMalloc failure not reported; not found is returned */ /* Always free strings allocated */ pcsl_string_free(&desiredClassname); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Implementation of native method to set the status of an Invocation. * If the status is set to a response status then the "finish" * behavior is performed. If a response is required, the Invocation * is requeued to the invoking application. Otherwise, the Invocation * is discarded. * * @param invoc the InvocationImpl to update the native status * @see StoredInvoc * @see #invocQueue */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_content_InvocationStore_setStatus0(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; /* Update the status */ invoc->status = KNI_GetIntField(invocObj, statusFid); switch (invoc->status) { case STATUS_OK: case STATUS_CANCELLED: case STATUS_ERROR: case STATUS_INITIATED: /* * If a response is required, switch the target * application; if not then discard the Invocation. */ if (invoc->responseRequired) { /* Swap the source and target suite and classname */ SuiteIdType tmpSuiteId = invoc->invokingSuiteId; SuiteIdType tmpSuiteId2; pcsl_string tmpClassname = invoc->invokingClassname; invoc->invokingSuiteId = invoc->suiteId; invoc->invokingClassname = invoc->classname; invoc->suiteId = tmpSuiteId; invoc->classname = tmpClassname; /* Unmark the response it is "new" to the target */ invoc->cleanup = KNI_FALSE; invoc->notified = KNI_FALSE; /* Swap the references in the Invocation object. */ tmpSuiteId = KNI_GetIntField(invocObj, suiteIdFid); tmpSuiteId2 = KNI_GetIntField(invocObj, invokingSuiteIdFid); KNI_SetIntField(invocObj, invokingSuiteIdFid, tmpSuiteId); KNI_SetIntField(invocObj, suiteIdFid, tmpSuiteId2); KNI_GetObjectField(invocObj, invokingClassnameFid, obj1); KNI_GetObjectField(invocObj, classnameFid, obj2); KNI_SetObjectField(invocObj, classnameFid, obj1); KNI_SetObjectField(invocObj, invokingClassnameFid, obj2); /* Unblock any waiting threads so they can retrieve this. */ unblockWaitingThreads(STATUS_OK); break; } /* If no response; Fall into DISPOSE */ case STATUS_DISPOSE: /* * Free the Invocation, clean the Tid in the Invocation */ invoc->tid = 0; KNI_SetIntField(invocObj, tidFid, 0); removeEntry(link); invocFree(invoc); break; case STATUS_ACTIVE: case STATUS_HOLD: case STATUS_WAITING: /* No Action. */ break; } } KNI_EndHandles(); KNI_ReturnVoid(); }
KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_io_j2me_socket_Protocol_open0() { init_sockets(); SocketOpenParameter *p = (SocketOpenParameter*) SNI_GetReentryData(NULL); if (p == NULL) { p = (SocketOpenParameter*) SNI_AllocateReentryData(sizeof(*p)); p->fd = -1; struct hostent *phostent; KNI_StartHandles(1); KNI_DeclareHandle(hostname_object); KNI_GetParameterAsObject(1, hostname_object); // hostname is always NUL terminated. See socket/Protocol.java for detail. char *hostname = (char*) SNI_GetRawArrayPointer(hostname_object); phostent = (struct hostent*)jvm_gethostbyname(hostname); KNI_EndHandles(); if (phostent == NULL) { KNI_ReturnInt(-1); } struct sockaddr_in destination_sin; destination_sin.sin_family = AF_INET; int port = KNI_GetParameterAsInt(2); destination_sin.sin_port = jvm_htons(port); jvm_memcpy((char *) &destination_sin.sin_addr, phostent->h_addr, phostent->h_length); p->fd = jvm_socket(AF_INET, SOCK_STREAM, 0); if (p->fd < 0) { KNI_ReturnInt(-1); } if (!set_blocking_flags(&p->fd, /*is_blocking*/ KNI_FALSE)) { KNI_ReturnInt(-1); } if (jvm_connect(p->fd, (struct sockaddr *) &destination_sin, sizeof(destination_sin)) < 0) { int err_code = GET_LAST_ERROR(); if (err_code == EINPROGRESS) { // When the socket is ready for connect, it becomes *writable* // (according to BSD socket spec of select()) p->check_flags = CHECK_WRITE | CHECK_EXCEPTION; SNI_BlockThread(); } else { jvm_shutdown(p->fd, 2); closesocket(p->fd); p->fd = -1; } } KNI_ReturnInt(p->fd); } else { // When we come to here, a CheckEvent() call has reported one of the // following: // [1] connect() has succeeded. In this case we return the socket fd. // [2] connect() has failed. In this case CheckEvent has already closed // the socket and set p->fd to -1. So we'd be returning -1. KNI_ReturnInt(p->fd); } }
/** * * Gets an InvocationImpl from the store using a MIDlet suiteId * and optional classname. * Getting an Invocation from the store removes it from the store. * If an OutOfMemory exception is thrown the matched Invocation * is NOT removed from the queue. If the heap memory can be * replenished then the operation can be retried. * * @param invoc an Invocation Object to fill in * @param suiteId to match a pending invocation * @param classname to match a pending invocation * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE}, * or {@link #MODE_CLEANUP} * @param blocking true to block until a matching invocation is available * @return 1 if a matching invocation was found and returned * in its entirety; zero if there was no matching invocation; * -1 if the sizes of the arguments or parameter array were wrong * @see StoredInvoc */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_content_InvocationStore_get0(void) { int ret = 0; /* return value = nothing matched */ KNI_StartHandles(4); KNI_DeclareHandle(obj); /* multipurpose handle */ KNI_DeclareHandle(argsObj); /* handle for argument array */ KNI_DeclareHandle(invocObj); /* Arg1: Invocation object; non-null */ KNI_DeclareHandle(classname); /* Arg3: non-null classname */ int mode = MODE_REQUEST; /* Arg4: mode for get */ jboolean blocking = KNI_FALSE; /* Arg5: true if should block */ /* Argument indices must match Java native method declaration */ #define getInvokeObjArg 1 #define getSuiteIdArg 2 #define getClassnameArg 3 #define getModeArg 4 #define getBlockingArg 5 StoredLink* match = NULL; SuiteIdType desiredSuiteId; pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER; do {/* Block to break out of on exceptions */ /* Check if blocked invocation was cancelled. */ if (isThreadCancelled()) { /* blocking is always false to cleanup and exit immediately */ break; } /* Get the desired blocking mode. */ blocking = KNI_GetParameterAsBoolean(getBlockingArg); if (!isEmpty()) { /* Queue is not empty, get InvocationImpl obj and init. */ KNI_GetParameterAsObject(getInvokeObjArg, invocObj); init(invocObj, obj); /* Get the desired type of invocation. */ mode = KNI_GetParameterAsInt(getModeArg); if (mode == MODE_TID || mode == MODE_TID_NEXT || mode == MODE_TID_PREV) { int tid = KNI_GetIntField(invocObj, tidFid); if (tid != 0) { match = invocFindTid(tid); } else { /* start with the root */ match = invocQueue; } if (match != NULL) { /* Link to the next or previous depending on the mode. */ if (mode == MODE_TID_NEXT) { match = match->flink; } else if (mode == MODE_TID_PREV) { match = match->blink; } } } else { desiredSuiteId = KNI_GetParameterAsInt(getSuiteIdArg); KNI_GetParameterAsObject(getClassnameArg, classname); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, &desiredClassname)) { KNI_ThrowNew(midpOutOfMemoryError, "InvocationStore_get0 no memory for [desiredClassname]"); break; } match = invocFind(desiredSuiteId, &desiredClassname, mode); } } } while (KNI_FALSE); /* Always free strings allocated */ pcsl_string_free(&desiredClassname); if (match != NULL) { StoredInvoc *invoc = match->invoc; int st = copyOut(invoc, mode, invocObj, argsObj, obj); switch (st) { case 1: /* If a match was found and successfully copied; * do final set of actions on the Invocation selected. */ switch (mode) { case MODE_REQUEST: if (invoc->status == STATUS_INIT) { /* * Returning new request, change status to ACTIVE * Keep this entry in the queue. */ invoc->status = STATUS_ACTIVE; KNI_SetIntField(invocObj, statusFid, invoc->status); } break; case MODE_RESPONSE: if (invoc->status >= STATUS_OK && invoc->status <= STATUS_INITIATED) { /* * Remove responses from the list and free. */ removeEntry(match); invocFree(invoc); } break; case MODE_LREQUEST: case MODE_LRESPONSE: case MODE_CLEANUP: case MODE_TID: case MODE_TID_NEXT: case MODE_TID_PREV: default: /* No additional action */ break; } /* Returning an Invocation */ ret = 1; break; case 0: /* Insufficient memory for strings. */ KNI_ThrowNew(midpOutOfMemoryError, "invocStore returning strings"); KNI_ReleaseHandle(invocObj); ret = 0; break; case -1: /* Either args array or data array is incorrect size. */ ret = -1; } } else { /* No match found. */ /* If blocking, setup to block. */ if (blocking) { blockThread(); /* Fall into the return to manage handles correctly */ } ret = 0; } KNI_EndHandles(); KNI_ReturnInt(ret); }
/** * private native void send0(LinkMessage msg) * throws ClosedLinkException, * InterruptedIOException, * IOException; */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_send0(void) { rendezvous *rp; KNI_StartHandles(3); KNI_DeclareHandle(thisObj); KNI_DeclareHandle(messageObj); KNI_DeclareHandle(otherMessageObj); KNI_GetThisPointer(thisObj); KNI_GetParameterAsObject(1, messageObj); rp = getNativePointer(thisObj); if (rp == NULL) { if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } } else if (JVM_CurrentIsolateID() != rp->sender) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { switch (rp->state) { case IDLE: rp->msg = SNI_AddStrongReference(messageObj); rp->state = SENDING; midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case RECEIVING: rp->msg = SNI_AddStrongReference(messageObj); rp->state = RENDEZVOUS; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case SENDING: case RENDEZVOUS: midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case DONE: getReference(rp->msg, "send0/DONE", otherMessageObj); if (KNI_IsSameObject(messageObj, otherMessageObj)) { /* it's our message, finish processing */ SNI_DeleteReference(rp->msg); rp->msg = INVALID_REFERENCE_ID; rp->state = IDLE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); if (rp->retcode != OK) { KNI_ThrowNew(midpIOException, NULL); } } else { /* somebody else's message, just go back to sleep */ midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); } break; case CLOSED: setNativePointer(thisObj, NULL); if (rp->msg != INVALID_REFERENCE_ID) { /* a message was stranded in the link; clean it out */ SNI_DeleteReference(rp->msg); rp->msg = INVALID_REFERENCE_ID; } rp_decref(rp); if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } break; } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * 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(); }
/** * 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); }
/** * private native void receive0(LinkMessage msg, Link link) * throws ClosedLinkException, * InterruptedIOException, * IOException; */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_receive0(void) { rendezvous *rp; KNI_StartHandles(4); KNI_DeclareHandle(thisObj); KNI_DeclareHandle(recvMessageObj); KNI_DeclareHandle(sendMessageObj); KNI_DeclareHandle(linkObj); KNI_GetThisPointer(thisObj); KNI_GetParameterAsObject(1, recvMessageObj); KNI_GetParameterAsObject(2, linkObj); rp = getNativePointer(thisObj); if (rp == NULL) { if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } } else if (JVM_CurrentIsolateID() != rp->receiver) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { jboolean ok; switch (rp->state) { case IDLE: rp->state = RECEIVING; midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case SENDING: getReference(rp->msg, "receive0/SENDING", sendMessageObj); ok = copy(sendMessageObj, recvMessageObj, linkObj); if (ok) { rp->retcode = OK; } else { rp->retcode = ERROR; KNI_ThrowNew(midpIOException, NULL); } rp->state = DONE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); break; case RENDEZVOUS: getReference(rp->msg, "receive0/RENDEZVOUS", sendMessageObj); ok = copy(sendMessageObj, recvMessageObj, linkObj); if (ok) { rp->retcode = OK; } else { rp->retcode = ERROR; KNI_ThrowNew(midpIOException, NULL); } rp->state = DONE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); break; case RECEIVING: case DONE: midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case CLOSED: setNativePointer(thisObj, NULL); rp_decref(rp); if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } break; } } KNI_EndHandles(); KNI_ReturnVoid(); }
/* * Performs client connection establishment. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPConnectionImpl</code> object. * * @param addr bluetooth address of device to connect to * @param psm Protocol Service Multiplexor (PSM) value * @return Negotiated ReceiveMTU and TransmitMTU. * 16 high bits is ReceiveMTU, 16 low bits is TransmitMTU. * * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPConnectionImpl_connect0(void) { unsigned char *address = NULL; int psm = (int)KNI_GetParameterAsInt(2); javacall_handle handle = JAVACALL_BT_INVALID_HANDLE; int status, i, imtu, omtu, mtus; void* context = NULL; MidpReentryData* info; javacall_bt_address addr; jfieldID connHandleID = NULL; KNI_StartHandles(3); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(arrayHandle); KNI_DeclareHandle(classHandle); KNI_GetThisPointer(thisHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", connHandleID) KNI_GetParameterAsObject(1, arrayHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); REPORT_INFO1(LC_PROTOCOL, "btl2cap::connect handle=%d", handle); /* copy address from Java input array */ SNI_BEGIN_RAW_POINTERS; address = JavaByteArray(arrayHandle); for (i = 0; i < JAVACALL_BT_ADDRESS_SIZE; i++) { addr[i] = address[i]; } SNI_END_RAW_POINTERS; info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ // Need revisit: add resource counting /* * Verify that the resource is available well within limit as per * the policy in ResourceLimiter */ /* if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) { const char* pMsg = "Resource limit exceeded for BT client sockets"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } else { */ status = javacall_bt_l2cap_connect(handle, address, psm, &imtu, &omtu); if (status == JAVACALL_OK) { // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } else if (status == JAVACALL_FAIL) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in btl2cap::connect (%s)\n", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); } else if (status == JAVACALL_WOULD_BLOCK) { // Need revisit: add bluetooth activity indicator // INC_BT_INDICATOR; // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ REPORT_INFO1(LC_PROTOCOL, "btl2cap::connect is waiting for complete notify" ", handle = %d\n", handle); midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)handle, context); } else { char* pMsg = "Unknown error during btl2cap::connect"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } // } } else { /* Reinvocation after unblocking the thread */ context = info->pResult; if ((javacall_handle)info->descriptor != handle) { REPORT_CRIT2(LC_PROTOCOL, "btl2cap::connect handles mismatched %d != %d\n", handle, (javacall_handle)info->descriptor); } status = javacall_bt_l2cap_connect(handle, address, psm, &imtu, &omtu); if (status == JAVACALL_OK) { // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else if (status == JAVACALL_WOULD_BLOCK) { midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)handle, context); } else { char* pError; KNI_SetIntField(thisHandle, connHandleID, (jint)JAVACALL_BT_INVALID_HANDLE); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Error in btl2cap::connect (%s)", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpConnectionNotFoundException, EXCEPTION_MSG(gKNIBuffer)); } } mtus = (imtu << 16) & 0xFFFF0000; mtus |= omtu & 0xFFFF; KNI_EndHandles(); KNI_ReturnInt(mtus); }
/* * Reads data from a packet received via Bluetooth stack. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPConnectionImpl</code> object. * * @param buf the buffer to read to * @param offset he start offset in array <code>buf</code> * at which the data to be written * @param size the maximum number of bytes to read, * the rest of the packet is discarded. * @return total number of bytes read into the buffer or * <code>0</code> if a zero length packet is received * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPConnectionImpl_receive0(void) { int length, offset; javacall_handle handle; int bytesRead = -1; int status = JAVACALL_FAIL; void* context = NULL; MidpReentryData* info; jfieldID connHandleID = NULL; offset = (int)KNI_GetParameterAsInt(2); length = (int)KNI_GetParameterAsInt(3); KNI_StartHandles(3); KNI_DeclareHandle(arrayHandle); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(classHandle); KNI_GetThisPointer(thisHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", connHandleID) handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); KNI_GetParameterAsObject(1, arrayHandle); REPORT_INFO3(LC_PROTOCOL, "btl2cap::receive off=%d len=%d handle=%d\n", offset, length, handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); // Need revisit: add bluetooth activity indicator // START_BT_INDICATOR; if (info == NULL) { /* First invocation */ if (JAVACALL_BT_INVALID_HANDLE == handle) { KNI_ThrowNew(midpIOException, EXCEPTION_MSG( "Invalid handle during btl2cap::receive")); } else { // Need revisit: add bluetooth activity indicator // INC_BT_INDICATOR; SNI_BEGIN_RAW_POINTERS; status = javacall_bt_l2cap_receive(handle, (unsigned char*)&(JavaByteArray(arrayHandle)[offset]), length, &bytesRead); SNI_END_RAW_POINTERS; } } else { /* Reinvocation after unblocking the thread */ if (JAVACALL_BT_INVALID_HANDLE == handle) { /* closed by another thread */ KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG( "Interrupted IO error during btl2cap::receive")); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { if ((javacall_handle)info->descriptor != handle) { REPORT_CRIT2(LC_PROTOCOL, "btl2cap::receive handles mismatched %d != %d\n", handle, (javacall_handle)info->descriptor); } context = info->pResult; SNI_BEGIN_RAW_POINTERS; status = javacall_bt_l2cap_receive(handle, (unsigned char*)&(JavaByteArray(arrayHandle)[offset]), length, &bytesRead); SNI_END_RAW_POINTERS; } } REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive bytes=%d\n", bytesRead); if (JAVACALL_BT_INVALID_HANDLE != handle) { if (status == JAVACALL_OK) { // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { char* pError; javacall_bt_l2cap_get_error(handle, &pError); REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive (%s)\n", pError); if (status == JAVACALL_WOULD_BLOCK) { midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context); } else if (status == JAVACALL_INTERRUPTED) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Interrupted IO error during btl2cap::receive (%s)", pError); KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(gKNIBuffer)); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Unknown error during btl2cap::receive (%s)", pError); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } } } // Need revisit: add bluetooth activity indicator // STOP_BT_INDICATOR; KNI_EndHandles(); KNI_ReturnInt((jint)bytesRead); }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_AbstractSurface_getRGB() { KNI_StartHandles(2); KNI_DeclareHandle(objectHandle); KNI_DeclareHandle(arrayHandle); jint offset = KNI_GetParameterAsInt(2); jint scanLength = KNI_GetParameterAsInt(3); jint x = KNI_GetParameterAsInt(4); jint y = KNI_GetParameterAsInt(5); jint width = KNI_GetParameterAsInt(6); jint height = KNI_GetParameterAsInt(7); jint dstX = 0; jint dstY = 0; Surface* surface; KNI_GetParameterAsObject(1, arrayHandle); KNI_GetThisPointer(objectHandle); surface = (Surface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); CORRECT_DIMS(surface, x, y, width, height, dstX, dstY); if ((width > 0) && (height > 0)) { jint size = ((height - 1) * scanLength + width) * sizeof(jint); jint* tempArray = (jint*)PISCESmalloc(size); if (NULL == tempArray) { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of temporary renderer memory buffer failed."); } else { jint* src; jint* dst; jint srcScanRest = surface->width - width; jint dstScanRest = scanLength - width; ACQUIRE_SURFACE(surface, objectHandle); src = (jint*)surface->data + y * surface->width + x; dst = tempArray; for (; height > 0; --height) { jint w2 = width; for (; w2 > 0; --w2) { *dst++ = *src++; } src += srcScanRest; dst += dstScanRest; } offset += dstY * scanLength + dstX; KNI_SetRawArrayRegion(arrayHandle, offset * sizeof(jint), size, (const jbyte*)tempArray); RELEASE_SURFACE(surface, objectHandle); PISCESfree(tempArray); } } KNI_EndHandles(); KNI_ReturnVoid(); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_addLandmarkToStoreImpl) { javacall_handle landmarkID = 0; javacall_result res; javacall_utf16_string categoryName = NULL; javacall_landmarkstore_landmark *landmark; jint numAddressFields; KNI_StartHandles(3); KNI_DeclareHandle(landmarkObj); KNI_DeclareHandle(stringObj); GET_PARAMETER_AS_UTF16_STRING(1, storeName) KNI_GetParameterAsObject(2, landmarkObj); /* CategoryName can be NULL -> check it and extract */ KNI_GetParameterAsObject(3, stringObj); if (!KNI_IsNullHandle(stringObj)) { if (JAVACALL_OK != jsrop_jstring_to_utf16_string(stringObj, &categoryName)) { categoryName = NULL; } } numAddressFields = KNI_GetIntField(landmarkObj, landmarkImplFieldID.numAddressInfoFields); landmark = JAVAME_MALLOC(SIZE_OF_LANDMARK_INFO(numAddressFields)); if (landmark != NULL) { if ( fill_landmark(landmarkObj, landmark, stringObj) == KNI_TRUE ) { res = javacall_landmarkstore_landmark_add_to_landmarkstore(storeName, landmark, categoryName, &landmarkID); switch (res) { case JAVACALL_OK: /* Category added successfully */ break; case JAVACALL_INVALID_ARGUMENT: /* wrong category name */ KNI_ThrowNew(jsropIllegalArgumentException, "category name is invalid"); break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } } else { KNI_ThrowNew(jsropIllegalArgumentException, "landmark name is too long"); } JAVAME_FREE(landmark); } if (categoryName != NULL) { JAVAME_FREE(categoryName); } RELEASE_UTF16_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnInt((jint)landmarkID); }
/* 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); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_j2me_location_LocationPersistentStorage_landmarkGetNext) { jint hndl; jint landmarkID = 0; javacall_result res; javacall_landmarkstore_landmark *landmark; jfieldID fid; jint i; KNI_StartHandles(2); KNI_DeclareHandle(landmarkObj); KNI_DeclareHandle(stringObj); hndl = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, landmarkObj); res = javacall_landmarkstore_landmarklist_next((javacall_handle)hndl, &landmarkID, &landmark); switch (res) { case JAVACALL_OK: if (landmark != NULL) { /* landmark.name */ jsrop_jstring_from_utf16_string(KNIPASSARGS landmark->name, stringObj); KNI_SetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj); /* landmark.description */ jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->description); KNI_SetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj); if (!landmark->isValidCoordinate) { /* landmark.isCoordinates */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isCoordinates, KNI_FALSE); } else { /* landmark.latitude */ KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.latitude, landmark->latitude); /* landmark.longitude */ KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.longitude, landmark->longitude); /* landmark.altitude */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.altitude, landmark->altitude); /* landmark.horizontalAccuracy */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.horizontalAccuracy, landmark->horizontalAccuracy); /* landmark.verticalAccuracy */ KNI_SetFloatField(landmarkObj, landmarkImplFieldID.verticalAccuracy, landmark->verticalAccuracy); /* landmark.isCoordinates */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isCoordinates, KNI_TRUE); } /* landmark.addressInfoFieldNumber */ KNI_SetIntField(landmarkObj, landmarkImplFieldID.numAddressInfoFields, landmark->addressInfoFieldNumber); /* landmark.isAddressInfo */ KNI_SetBooleanField(landmarkObj, landmarkImplFieldID.isAddressInfo, (landmark->addressInfoFieldNumber > 0) ? KNI_TRUE : KNI_FALSE); for (i=0; i < landmark->addressInfoFieldNumber; i++) { switch (landmark->fields[i].fieldId) { case JAVACALL_LOCATION_ADDRESSINFO_EXTENSION: fid = landmarkImplFieldID. AddressInfo_EXTENSION; break; case JAVACALL_LOCATION_ADDRESSINFO_STREET: fid = landmarkImplFieldID. AddressInfo_STREET; break; case JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE: fid = landmarkImplFieldID. AddressInfo_POSTAL_CODE; break; case JAVACALL_LOCATION_ADDRESSINFO_CITY: fid = landmarkImplFieldID. AddressInfo_CITY; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTY: fid = landmarkImplFieldID. AddressInfo_COUNTY; break; case JAVACALL_LOCATION_ADDRESSINFO_STATE: fid = landmarkImplFieldID. AddressInfo_STATE; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY: fid = landmarkImplFieldID. AddressInfo_COUNTRY; break; case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE: fid = landmarkImplFieldID. AddressInfo_COUNTRY_CODE; break; case JAVACALL_LOCATION_ADDRESSINFO_DISTRICT: fid = landmarkImplFieldID. AddressInfo_DISTRICT; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME: fid = landmarkImplFieldID. AddressInfo_BUILDING_NAME; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR: fid = landmarkImplFieldID. AddressInfo_BUILDING_FLOOR; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM: fid = landmarkImplFieldID. AddressInfo_BUILDING_ROOM; break; case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE: fid = landmarkImplFieldID. AddressInfo_BUILDING_ZONE; break; case JAVACALL_LOCATION_ADDRESSINFO_CROSSING1: fid = landmarkImplFieldID. AddressInfo_CROSSING1; break; case JAVACALL_LOCATION_ADDRESSINFO_CROSSING2: fid = landmarkImplFieldID. AddressInfo_CROSSING2; break; case JAVACALL_LOCATION_ADDRESSINFO_URL: fid = landmarkImplFieldID. AddressInfo_URL; break; case JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER: fid = landmarkImplFieldID. AddressInfo_PHONE_NUMBER; break; default: fid = 0; break; } if (fid != 0) { /* addressInfo */ jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->fields[i].data); KNI_SetObjectField(landmarkObj, fid, stringObj); } } } break; default: /* operation Failed */ KNI_ThrowNew(jsropIOException, "I/O error"); break; } KNI_EndHandles(); KNI_ReturnInt(landmarkID); }
/* 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); }
/* JAVADOC COMMENT ELIDED */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_j2me_location_PlatformLocationProvider_getCriteria() { jsr179_provider_info provider_info; jsr179_result res; jboolean ret = KNI_FALSE; KNI_StartHandles(3); /* get NULL terminated provider name */ KNI_DeclareHandle(criteria); KNI_DeclareHandle(class_obj); GET_PARAMETER_AS_PCSL_STRING(1, name) /* call provider_open to get provider handler */ res = jsr179_provider_getinfo(name, &provider_info); if (res == JSR179_STATUSCODE_OK) { KNI_GetParameterAsObject(2, criteria); KNI_GetObjectClass(criteria, class_obj); KNI_SetBooleanField(criteria, locationProviderInfoFieldID.incurCost, provider_info.incurCost); KNI_SetBooleanField(criteria, locationProviderInfoFieldID.canReportAltitude, provider_info.canReportAltitude); KNI_SetBooleanField(criteria, locationProviderInfoFieldID.canReportAddressInfo, provider_info.canReportAddressInfo); KNI_SetBooleanField(criteria, locationProviderInfoFieldID.canReportSpeedCource, provider_info.canReportSpeedCource); KNI_SetIntField(criteria, locationProviderInfoFieldID.powerConsumption, provider_info.powerConsumption); KNI_SetIntField(criteria, locationProviderInfoFieldID.horizontalAccuracy, provider_info.horizontalAccuracy); KNI_SetIntField(criteria, locationProviderInfoFieldID.verticalAccuracy, provider_info.verticalAccuracy); KNI_SetIntField(criteria, locationProviderInfoFieldID.defaultTimeout, provider_info.defaultTimeout); KNI_SetIntField(criteria, locationProviderInfoFieldID.defaultMaxAge, provider_info.defaultMaxAge); KNI_SetIntField(criteria, locationProviderInfoFieldID.defaultInterval, provider_info.defaultInterval); KNI_SetIntField(criteria, locationProviderInfoFieldID.averageResponseTime, provider_info.averageResponseTime); KNI_SetIntField(criteria, locationProviderInfoFieldID.defaultStateInterval, provider_info.defaultStateInterval); ret = KNI_TRUE; } else if (res == JSR179_STATUSCODE_INVALID_ARGUMENT) { /* wrong provider name */ KNI_ThrowNew(midpIllegalArgumentException, "wrong provider name"); } RELEASE_PCSL_STRING_PARAMETER KNI_EndHandles(); KNI_ReturnBoolean(ret); }
/** * 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); }
/** * * Listens for an InvocationImpl from the store using a MIDlet suiteId * and optional, and status. Each Invocation must be returned only * once. When an Invocation is returned; it is marked as being * notified. * * @param suiteId to match a pending invocation * @param classname to match a pending invocation * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE}, * or {@link #MODE_CLEANUP} * @param blocking true to block until a matching invocation is available * @return true if an Invocation is found with * the same MIDlet suiteId and classname; false is returne dotherwise */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_midp_content_InvocationStore_listen0(void) { StoredLink* match = NULL; SuiteIdType desiredSuiteId; pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER; KNI_StartHandles(1); KNI_DeclareHandle(classname); /* Arg2: non-null classname */ int mode; /* Arg3: requested invocation mode */ jboolean blocking = KNI_FALSE; /* Arg4: true if should block */ /* Argument indices must match Java native method declaration */ #define listenSuiteIdArg 1 #define listenClassnameArg 2 #define listenModeArg 3 #define listenBlockingArg 4 do {/* Block to break out of on exceptions */ /* Check if blocked invocation was cancelled. */ if (isThreadCancelled()) { /* blocking is always false to cleanup and exit immediately */ break; } /* Get the desired blocking mode. */ blocking = KNI_GetParameterAsBoolean(listenBlockingArg); if (!isEmpty()) { /* Queue is not empty * Need a string copy of the desired suiteID and classname * to use for comparisons */ desiredSuiteId = KNI_GetParameterAsInt(listenSuiteIdArg); KNI_GetParameterAsObject(listenClassnameArg, classname); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, &desiredClassname)) { KNI_ThrowNew(midpOutOfMemoryError, "InvocationStore_listen0 no memory for [desiredClassname]"); break; } /* Get the desired request mode. */ mode = KNI_GetParameterAsInt(listenModeArg); match = invocFind(desiredSuiteId, &desiredClassname, mode); } } while (KNI_FALSE); /* Always free strings allocated */ pcsl_string_free(&desiredClassname); if (match != NULL) { match->invoc->notified = KNI_TRUE; } else { if (blocking) { /* No found; block the thread in the VM */ blockThread(); /* Fall into the return to manage handles correctly */ } } KNI_EndHandles(); KNI_ReturnBoolean(match != NULL); }
/** * Decodes the given byte array into the <tt>ImageData</tt>. * <p> * Java declaration: * <pre> * loadPNG(Ljavax/microedition/lcdui/ImageData;[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 there is alpha data */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadPNG) { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); int status = KNI_TRUE; 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(4); KNI_DeclareHandle(alphaData); KNI_DeclareHandle(pixelData); KNI_DeclareHandle(pngData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, pngData); KNI_GetParameterAsObject(1, imageData); midpImageData = GXAPI_GET_IMAGEDATA_PTR(imageData); /* assert * (KNI_IsNullHandle(pngData)) */ srcBuffer = (unsigned char *)JavaByteArray(pngData); /* * JAVA_TRACE("loadPNG pngData length=%d %x\n", * JavaByteArray(pngData)->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("loadPNG pixelData length=%d\n", * JavaByteArray(pixelData)->length); */ } else { image.pixelData = NULL; } unhand(jbyte_array, alphaData) = midpImageData->alphaData; if (!KNI_IsNullHandle(alphaData)) { image.alphaData = (gxj_alpha_type *)JavaByteArray(alphaData); /* * JAVA_TRACE("decodePNG alphaData length=%d\n", * JavaByteArray(alphaData)->length); */ } else { image.alphaData = NULL; } /* assert * (imagedata.pixelData != NULL && imagedata.alphaData != NULL) */ status = decode_png((srcBuffer + offset), length, &image, &creationError); if (GXUTL_NATIVE_IMAGE_NO_ERROR != creationError) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } KNI_EndHandles(); KNI_ReturnBoolean(status); }
/** * Implementation of native method to queue a new Invocation. * The state of the InvocationImpl is copied to the heap * and inserted in the head of the invocation queue. * An StoredInvoc struct is allocated on the native heap and * the non-null strings for each field of the InvocationImpl class * are copied to the heap. * A new transaction ID is assigned to this Invocation * and returned in the tid field of the InvocationImpl. * @param invoc the InvocationImpl to store * @throws OutOfMemoryError if the memory allocation fails * @see StoredInvoc * @see #invocQueue */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_content_InvocationStore_put0(void) { StoredInvoc* invoc = NULL; KNI_StartHandles(4); KNI_DeclareHandle(invocObj); KNI_DeclareHandle(classObj); KNI_DeclareHandle(argsObj); KNI_DeclareHandle(str); KNI_GetParameterAsObject(1, invocObj); init(invocObj, classObj); do { /* On any error break out of this block */ /* Allocate a new zero'ed struct to save the values in */ invoc = (StoredInvoc*) pcsl_mem_calloc(1, sizeof (StoredInvoc)); if (invoc == NULL) { KNI_ThrowNew(midpOutOfMemoryError, "InvocationStore_put0 no memory for [invoc]"); break; } /* Assign a new transaction id and set it */ invoc->tid = invocNextTid(); KNI_SetIntField(invocObj, tidFid, invoc->tid); /* * Copy all the parameters to native * Includes ID, type,url, action, args, data */ if (KNI_TRUE != setParamsFromObj(invoc, invocObj, str, argsObj)) break; invoc->previousTid = KNI_GetIntField(invocObj, previousTidFid); invoc->status = KNI_GetIntField(invocObj, statusFid); invoc->responseRequired = KNI_GetBooleanField(invocObj, responseRequiredFid); invoc->suiteId = KNI_GetIntField(invocObj, suiteIdFid); KNI_GetObjectField(invocObj, classnameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->classname)) break; KNI_GetObjectField(invocObj, invokingAuthorityFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingAuthority)) break; KNI_GetObjectField(invocObj, invokingAppNameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingAppName)) break; invoc->invokingSuiteId = KNI_GetIntField(invocObj, invokingSuiteIdFid); KNI_GetObjectField(invocObj, invokingClassnameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingClassname)) break; KNI_GetObjectField(invocObj, invokingIDFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingID)) break; KNI_GetObjectField(invocObj, usernameFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->username)) break; KNI_GetObjectField(invocObj, passwordFid, str); if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->password)) break; /* Insert the new Invocation at the end of the queue */ if (!invocPut(invoc)) break; unblockWaitingThreads(STATUS_OK); /* Clear to skip cleanup and throwing exception */ invoc = NULL; } while (0); if (invoc != NULL) { /* An allocation error occurred; free any remaining */ invocFree(invoc); KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c allocation failed"); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Initializes an <tt>ImageData</tt> from a romized pixel data * <p> * Java declaration: * <pre> * loadRomizedImage(Ljavax/microedition/lcdui/ImageData;I)V * </pre> * * @param imageData The ImageData to load to * @param imageDataPtr native pointer to image data as Java int * @param imageDataLength length of image data array */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(javax_microedition_lcdui_ImageDataFactory_loadRomizedImage) { int imageDataPtr = KNI_GetParameterAsInt(2); int imageDataLength = KNI_GetParameterAsInt(3); int alphaSize; int pixelSize; int imageSize; int expectedLength; gxutl_image_buffer_raw *rawBuffer; java_imagedata *midpImageData; jboolean status = KNI_FALSE; KNI_StartHandles(1); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(1, imageData); rawBuffer = (gxutl_image_buffer_raw*)imageDataPtr; do { if (rawBuffer == NULL) { REPORT_ERROR(LC_LOWUI, "Romized image data is null"); status = KNI_FALSE; break; } /** Check header */ if (memcmp(rawBuffer->header, gxutl_raw_header, 4) != 0) { REPORT_ERROR(LC_LOWUI, "Unexpected romized image type"); status = KNI_FALSE; break; } imageSize = rawBuffer->width * rawBuffer->height; pixelSize = sizeof(gxj_pixel_type) * imageSize; alphaSize = 0; if (rawBuffer->hasAlpha) { alphaSize = sizeof(gxj_alpha_type) * imageSize; } /** Check data array length */ expectedLength = offsetof(gxutl_image_buffer_raw, data) + pixelSize + alphaSize; if (imageDataLength != expectedLength) { REPORT_ERROR(LC_LOWUI, "Unexpected romized image data array length"); status = KNI_FALSE; break; } midpImageData = GXAPI_GET_IMAGEDATA_PTR(imageData); midpImageData->width = (jint)rawBuffer->width; midpImageData->height = (jint)rawBuffer->height; midpImageData->nativePixelData = (jint)rawBuffer->data; if (rawBuffer->hasAlpha) { midpImageData->nativeAlphaData = (jint)(rawBuffer->data + pixelSize); } status = KNI_TRUE; } while (0); KNI_EndHandles(); KNI_ReturnBoolean(status); }
/** * Write to a serial port without blocking. * * @param hPort handle to a native serial port * @param b I/O buffer * @param off starting offset for data * @param len length of data * * @return number of bytes that were written * * @exception IOException if an I/O error occurs. */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_comm_Protocol_native_1writeBytes() { int length = (int)KNI_GetParameterAsInt(4); int offset = (int)KNI_GetParameterAsInt(3); int hPort = (int)KNI_GetParameterAsInt(1); int bytesWritten = 0; int status = PCSL_NET_IOERROR; void* context = NULL; MidpReentryData* info; KNI_StartHandles(1); KNI_DeclareHandle(bufferObject); KNI_GetParameterAsObject(2, bufferObject); info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { if (hPort < 0) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Write to port: handle %d is invalid\n", hPort); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpIllegalArgumentException, gKNIBuffer); } else { SNI_BEGIN_RAW_POINTERS; status = writeToPortStart(hPort, (char*)&(JavaByteArray(bufferObject)[offset]), length, &bytesWritten, &context); SNI_END_RAW_POINTERS; } } else { /* reinvocation */ hPort = info->descriptor; context = info->pResult; SNI_BEGIN_RAW_POINTERS; status = writeToPortFinish(hPort, (char*)&(JavaByteArray(bufferObject)[offset]), length, &bytesWritten, context); SNI_END_RAW_POINTERS; } switch (status) { case PCSL_NET_SUCCESS: /*do nothing and return normally */ break; case PCSL_NET_INTERRUPTED: midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Writing to port %d has been interrupted\n", hPort); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpInterruptedIOException, gKNIBuffer); break; case PCSL_NET_WOULDBLOCK: midp_thread_wait(COMM_WRITE_SIGNAL, hPort, context); break; default: midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Writing to port %d was failed\n", hPort); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); } KNI_EndHandles(); KNI_ReturnInt((jint)bytesWritten); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_mmedia_DefaultConfiguration_nListProtocolsOpen) { const javacall_media_configuration *cfg; javacall_media_caps *caps; ListIterator *iterator = NULL; javacall_int32 proto_mask = 0; javacall_bool supportDeviceProtocol = JAVACALL_FALSE; char *p = NULL; /* stack buffers. Trying to avoid malloc if a string is not big */ jchar stack_string16_buffer[MAX_PROTOCOLNAME_LEN], *string16 = NULL; char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *mime = NULL; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); KNI_GetParameterAsObject(1, stringObj); do { if (KNI_IsNullHandle(stringObj)) { mime = NULL; } else { unsigned int len = KNI_GetStringLength(stringObj); /* if the string is longer than the stack buffer try to malloc it */ if (len >= sizeof stack_string16_buffer / sizeof stack_string16_buffer[0]) { string16 = MMP_MALLOC((len + 1) * sizeof *string16); if (string16 == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { string16 = stack_string16_buffer; } if (len >= sizeof stack_string_buffer / sizeof stack_string_buffer[0]) { mime = MMP_MALLOC(len + 1); if (mime == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { mime = stack_string_buffer; } KNI_GetStringRegion(stringObj, 0, len, string16); if (simple_jcharString_to_asciiString(string16, len, mime, len + 1) != JAVACALL_OK) { KNI_ThrowNew(jsropIllegalArgumentException, "Illegal character in MIME type name"); break; } } if (javacall_media_get_configuration(&cfg) != JAVACALL_OK) { KNI_ThrowNew(jsropRuntimeException, "Couldn't get MMAPI configuration"); break; } if ((mime == NULL || !javautil_stricmp(mime, MIME_AUDIO_MIDI)) && cfg->supportDeviceMIDI) { supportDeviceProtocol = JAVACALL_TRUE; } if (!supportDeviceProtocol && (mime == NULL || !javautil_stricmp(mime, MIME_AUDIO_TONE)) && cfg->supportDeviceTone) { supportDeviceProtocol = JAVACALL_TRUE; } /* trying to find given MIME type among caps->contentTypes */ for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (caps->wholeProtocols != 0 || caps->streamingProtocols != 0) { if (mime != NULL) { char *s; int m_len = strlen(mime); for (p = (char *)caps->contentTypes; p != NULL; p = s) { int p_len; while (*p == ' ') { p++; } if ((s = strchr(p, ' ')) != NULL) { p_len = (int)(s - p); } else { p_len = strlen(p); } if (p_len == m_len && !javautil_strnicmp(mime, p, p_len)) { break; } } } if (mime == NULL || p != NULL) { proto_mask |= caps->wholeProtocols; proto_mask |= caps->streamingProtocols; } } } if (proto_mask != 0 || supportDeviceProtocol) { /* some protocols were found */ unsigned int i; unsigned int len = 0; /* trying to resolve protocol names: calculating needed memory */ for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if ((protocolNames[i].proto_mask & proto_mask) != 0 && protocolNames[i].proto_name != NULL) { len += strlen(protocolNames[i].proto_name) + 1; /* +1 for space char */ } } if (supportDeviceProtocol) { len += strlen(DEVICE_PROTOCOL) + 1; } if (len == 0) { /* Protocol wasn't found in the protocol name table */ KNI_ThrowNew(jsropRuntimeException, "Incorrect MMAPI configuration: missing protocol name"); break; } iterator = (ListIterator*)MMP_MALLOC( sizeof *iterator + len); /* zero terminator instead of last space */ if (iterator == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } /* initialize the iterator */ iterator->current = iterator->list; /* building the list of protocols */ p = iterator->list; for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if ((protocolNames[i].proto_mask & proto_mask) != 0 && protocolNames[i].proto_name != NULL) { int proto_len = strlen(protocolNames[i].proto_name); memcpy(p, protocolNames[i].proto_name, proto_len); p += proto_len; *p++ = ' '; } } if (supportDeviceProtocol) { int proto_len = strlen(DEVICE_PROTOCOL); memcpy(p, DEVICE_PROTOCOL, proto_len); p += proto_len; *p++ = ' '; } p--; *p = '\0'; /* replace last space with zero */ } else { /* No protocols were found for provided MIME type. Return 0 */ break; } mmapi_string_delete_duplicates(iterator->list); } while (0); /* freeing buffers */ if (mime != NULL && mime != stack_string_buffer) { MMP_FREE(mime); } if (string16 != NULL && string16 != stack_string16_buffer) { MMP_FREE(string16); } KNI_EndHandles(); KNI_ReturnInt((jint)iterator); }
/** * Renders the given region of this <tt>ImmutableImage</tt> onto the * given <tt>Graphics</tt> object. * <p> * Java declaration: * <pre> * renderRegion(Ljavax/microedition/lcdui/ImageImpl;IIIIIIII)V * </pre> * * @param g The <tt>Graphics</tt> object to be drawn * @param x_src The x coordinate of the upper-left corner of the * source region * @param y_src The y coordinate of the upper-left corner of the * source region * @param width The width of the source region * @param height The height of the source region * @param transform The transform to apply to the selected region. * @param x_dest The x coordinate of the destination anchor point * @param y_dest The y coordinate of the destination anchor point * @param anchor The anchor point for positioning the destination * <tt>Image</tt> */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN KNIDECL(javax_microedition_lcdui_Image_renderRegion) { int anchor = KNI_GetParameterAsInt(9); int y_dest = KNI_GetParameterAsInt(8); int x_dest = KNI_GetParameterAsInt(7); int transform = KNI_GetParameterAsInt(6); int height = KNI_GetParameterAsInt(5); int width = KNI_GetParameterAsInt(4); int y_src = KNI_GetParameterAsInt(3); int x_src = KNI_GetParameterAsInt(2); jboolean success = KNI_TRUE; 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)) { if (KNI_IsNullHandle(img)) { /* null checking is performed in the Java code, but check just in case */ success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL); } else if ((transform < 0) || (transform > 7)) { success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL); } else if (!gxutl_normalize_anchor(&x_dest, &y_dest, width, height, anchor)) { success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { const java_imagedata * srcImageDataPtr = GET_IMAGE_PTR(img)->imageData; jint img_width = srcImageDataPtr->width; jint img_height = srcImageDataPtr->height; GET_IMAGE_PTR(gImg) = (struct Java_javax_microedition_lcdui_Image *) (GXAPI_GET_GRAPHICS_PTR(g)->img); if (KNI_IsSameObject(gImg, img) || (height < 0) || (width < 0) || (x_src < 0) || (y_src < 0) || ((x_src + width) > img_width) || ((y_src + height) > img_height)) { 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_dest, y_dest); GXAPI_GET_CLIP(g, clip); gx_render_imageregion(srcImageDataPtr, dstMutableImageDataPtr, clip, x_src, y_src, width, height, x_dest, y_dest, transform); } } } KNI_EndHandles(); KNI_ReturnBoolean(success); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_mmedia_DefaultConfiguration_nListContentTypesOpen) { javacall_int32 proto_mask = 0; javacall_bool deviceProtocol = JAVACALL_FALSE; const javacall_media_configuration *cfg; const javacall_media_caps *caps; unsigned int len; ListIterator *iterator = NULL; char *p; /* stack buffers. Trying to avoid malloc if a string is not big */ jchar stack_string16_buffer[MAX_PROTOCOLNAME_LEN], *string16 = NULL; char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *proto = NULL; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); KNI_GetParameterAsObject(1, stringObj); do { if (KNI_IsNullHandle(stringObj)) { proto = NULL; } else { len = KNI_GetStringLength(stringObj); /* if the string is longer than the stack buffer try to malloc it */ if (len >= sizeof stack_string16_buffer / sizeof stack_string16_buffer[0]) { string16 = MMP_MALLOC((len + 1) * sizeof *string16); if (string16 == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { string16 = stack_string16_buffer; } if (len >= sizeof stack_string_buffer) { proto = MMP_MALLOC(len + 1); if (proto == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { proto = stack_string_buffer; } KNI_GetStringRegion(stringObj, 0, len, string16); if (simple_jcharString_to_asciiString(string16, len, proto, len + 1) != JAVACALL_OK) { KNI_ThrowNew(jsropIllegalArgumentException, "Illegal character in protocol name"); break; } } if (proto != NULL) { unsigned int i; /* trying to find protocol by name */ for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if (protocolNames[i].proto_name != NULL && !javautil_stricmp(protocolNames[i].proto_name, proto)) { proto_mask |= protocolNames[i].proto_mask; } } if (!javautil_stricmp(proto, DEVICE_PROTOCOL)) { deviceProtocol = JAVACALL_TRUE; } } if (proto != NULL && proto_mask == 0 && !deviceProtocol) { /* Requested protocol wasn't found. Return 0 */ break; } if (javacall_media_get_configuration(&cfg) != JAVACALL_OK) { KNI_ThrowNew(jsropRuntimeException, "Couldn't get MMAPI configuration"); break; } /* how long will be list of content types? */ len = 0; for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (proto == NULL || (caps->wholeProtocols & proto_mask) != 0 || (caps->streamingProtocols & proto_mask) != 0) { len += strlen(caps->contentTypes) + 1; /* +1 for space char */ } } if (proto == NULL || deviceProtocol) { if (cfg->supportDeviceMIDI) { len += strlen(MIME_AUDIO_MIDI) + 1; } if (cfg->supportDeviceTone) { len += strlen(MIME_AUDIO_TONE) + 1; } } if (len == 0) { /* No MIME types were found for provided protocol. Return 0 */ break; } iterator = (ListIterator*)MMP_MALLOC( sizeof *iterator + len); /* zero terminator instead of last space */ if (iterator == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } /* initialize the iterator */ iterator->current = iterator->list; /* filling the list of content types */ p = iterator->list; for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (proto == NULL || (caps->wholeProtocols & proto_mask) != 0 || (caps->streamingProtocols & proto_mask) != 0) { int types_len = strlen(caps->contentTypes); memcpy(p, caps->contentTypes, types_len); p += types_len; *p++ = ' '; } } if (proto == NULL || deviceProtocol) { int types_len; if (cfg->supportDeviceMIDI) { types_len = strlen(MIME_AUDIO_MIDI); memcpy(p, MIME_AUDIO_MIDI, types_len); p += types_len; *p++ = ' '; } if (cfg->supportDeviceTone) { types_len = strlen(MIME_AUDIO_TONE); memcpy(p, MIME_AUDIO_TONE, types_len); p += types_len; *p++ = ' '; } } p--; *p = '\0'; /* replace last space with zero */ mmapi_string_delete_duplicates(iterator->list); } while (0); /* freeing buffers */ if (proto != NULL && proto != stack_string_buffer) { MMP_FREE(proto); } if (string16 != NULL && string16 != stack_string16_buffer) { MMP_FREE(string16); } KNI_EndHandles(); KNI_ReturnInt((jint)iterator); }
/* private native int _eglGetConfigs ( int display , int [ ] configs , int config_size , int [ ] num_config ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_khronos_egl_EGL10Impl__1eglGetConfigs() { jint display = KNI_GetParameterAsInt(1); jint config_size = KNI_GetParameterAsInt(3); EGLConfig *configs = (EGLConfig *)0; EGLint num_config = 0; jint returnValue = EGL_FALSE; KNI_StartHandles(2); KNI_DeclareHandle(configsHandle); KNI_DeclareHandle(num_configHandle); KNI_GetParameterAsObject(2, configsHandle); KNI_GetParameterAsObject(4, num_configHandle); if (!KNI_IsNullHandle(configsHandle)) { configs = (EGLConfig *)JSR239_malloc(config_size*sizeof(EGLint)); if (!configs) { KNI_ThrowNew("java.lang.OutOfMemoryException", "eglGetConfigs"); goto exit; } } returnValue = (jint)eglGetConfigs((EGLDisplay)display, configs, (EGLint)config_size, &num_config); #ifdef DEBUG printf("num_config = %d\n", num_config); #endif #ifdef ALL_WINDOWS_ARE_PIXMAPS { EGLBoolean ok; EGLint surfaceType; int i, j; // Remove all configs that are for windows only if (returnValue && configs) { for (i = 0; i < num_config; i++) { ok = eglGetConfigAttrib((EGLDisplay)display, configs[i], EGL_SURFACE_TYPE, &surfaceType); if ((surfaceType & (EGL_PIXMAP_BIT | EGL_PBUFFER_BIT)) == 0) { for (j = i; j < num_config - 1; j++) { configs[j] = configs[j + 1]; } configs[--num_config] = 0; #ifdef DEBUG printf("Deleting a config, num_config = %d\n", num_config); #endif } } } } #endif #ifdef DEBUG printf("eglGetConfigs(0x%x, configs, %d, num_config<-%d) = %d\n", display, config_size, num_config, returnValue); #endif if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(configsHandle)) { KNI_SetRawArrayRegion(configsHandle, 0, config_size*sizeof(EGLint), (const jbyte *)configs); } if ((returnValue == EGL_TRUE) && !KNI_IsNullHandle(num_configHandle)) { KNI_SetIntArrayElement(num_configHandle, 0, num_config); } exit: if (configs) { JSR239_free(configs); } KNI_EndHandles(); KNI_ReturnInt(returnValue); }
/** * 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(); }