KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(KNITest_testVirtualArg) { jint x = KNI_GetParameterAsInt(1); KNI_ReturnInt(x*2); }
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); }
/* 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); }
KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf() { KNI_ReturnInt(-1); }
/** * Accepts incoming client connection request. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object. * * Note: new native connection handle to work with accepted incoming * client connection is setted directly to <code>handle</code> field of * appropriate <code>L2CAPConnectionImpl</code> object. * * @return Negotiated ReceiveMTU and TransmitMTU. * 16 high bits is ReceiveMTU, 16 low bits is TransmitMTU. * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_accept0(void) { javacall_handle handle = BT_INVALID_HANDLE; javacall_handle peer_handle = BT_INVALID_HANDLE; MidpReentryData* info; int status = JAVACALL_FAIL; int processStatus = KNI_FALSE; int imtu, omtu, mtus; void *context = NULL; javacall_bt_address peer_addr; unsigned char *address = NULL; KNI_StartHandles(2); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(arrayHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle); if (handle == BT_INVALID_HANDLE) { REPORT_ERROR(LC_PROTOCOL, "L2CAP server socket was closed before btl2cap_notif::accept"); KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG( "L2CAP notifier was closed")); } else { bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID); if (pushid != BT_INVALID_PUSH_HANDLE) { if (bt_push_checkout_client(pushid, &peer_handle, peer_addr, &imtu, &omtu) == JAVACALL_OK) { pushcheckoutaccept((int)handle); processStatus = KNI_TRUE; status = JAVACALL_OK; } } if (peer_handle == BT_INVALID_HANDLE) { info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ REPORT_INFO1(LC_PROTOCOL, "btl2cap_notif::accept handle=%d\n", handle); // Need revisit: add resource counting /* * An incoming socket connection counts against the client socket * resource limit. */ /* 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_accept( handle, &peer_handle, &peer_addr, &imtu, &omtu); processStatus = KNI_TRUE; // } } else { /* Reinvocation after unblocking the thread */ if ((javacall_handle)info->descriptor != handle) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "btl2cap_notif::accept handles mismatched %d != %d\n", handle, info->descriptor); REPORT_CRIT(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG( "Internal error in btl2cap_notif::accept")); } else { // Need revisit: add resource counting /* 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_accept( handle, &peer_handle, &peer_addr, &imtu, &omtu); processStatus = KNI_TRUE; // } } } } if (processStatus) { REPORT_INFO1(LC_PROTOCOL, "btl2cap_notif::accept server handle=%d\n", handle); if (status == JAVACALL_OK) { int i; // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "btl2cap_notif: Resource limit update error"); } */ // store client native connection handle for temporary storing KNI_SetIntField(thisHandle, peerHandleID, (jint)peer_handle); // copy address to Java object field SNI_BEGIN_RAW_POINTERS; address = JavaByteArray(arrayHandle); for (i = 0; i < BT_ADDRESS_SIZE; i++) { address[i] = peer_addr[i]; } SNI_END_RAW_POINTERS; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::accept incoming connection accepted!"); } else if (status == JAVACALL_WOULD_BLOCK) { midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context); } else if (status == JAVACALL_FAIL) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in btl2cap_notif::accept (%s)\n", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); } else { char* pMsg = "Unknown error during btl2cap_notif::accept"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } } } mtus = (imtu << 16) & 0xFFFF0000; mtus |= omtu & 0xFFFF; KNI_EndHandles(); KNI_ReturnInt(mtus); }
/* 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); }
/* 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); }
/** * Sends an SMS message. * * @param handle The handle to the open SMS connection. * @param messageType The type of message: binary or text. * @param address The SMS-formatted address. * @param destPort The port number of the recipient. * @param sourcePort The port number of the sender. * @param messageBuffer The buffer containing the SMS message. * * @return Always returns <code>0</code>. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_sms_Protocol_send0) { WMA_STATUS status = WMA_ERR; jint messageLength = 0; jint messageType; jint sourcePort; jint destPort; jint handle; jint msAddress_len; jchar* msAddress_data; int i; unsigned char *pAddress = NULL; unsigned char *pMessageBuffer = NULL; jboolean stillWaiting = KNI_FALSE; jboolean trySend = KNI_FALSE; void *pdContext = NULL; #if ENABLE_REENTRY MidpReentryData *info; jsr120_sms_message_state_data *messageStateData = NULL; #endif jboolean isOpen; KNI_StartHandles(4); KNI_DeclareHandle(this); KNI_DeclareHandle(thisClass); KNI_GetThisPointer(this); KNI_GetObjectClass(this, thisClass); isOpen = KNI_GetBooleanField(this, KNI_GetFieldID(thisClass, "open", "Z")); if (isOpen) { /* No close in progress */ KNI_DeclareHandle(messageBuffer); KNI_DeclareHandle(address); handle = KNI_GetParameterAsInt(1); messageType = KNI_GetParameterAsInt(2); KNI_GetParameterAsObject(3, address); destPort = KNI_GetParameterAsInt(4); sourcePort = KNI_GetParameterAsInt(5); KNI_GetParameterAsObject(6, messageBuffer); do { #if ENABLE_REENTRY info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation. */ #endif if (KNI_IsNullHandle(address)) { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } else { msAddress_len = KNI_GetStringLength(address); msAddress_data = (jchar *)pcsl_mem_malloc(msAddress_len * sizeof (jchar)); if (msAddress_data == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } else { KNI_GetStringRegion(address, 0, msAddress_len, msAddress_data); pAddress = (unsigned char*)pcsl_mem_malloc(msAddress_len + 1); if (pAddress != NULL) { for (i = 0; i < msAddress_len; i++) { pAddress[i] = (unsigned char)msAddress_data[i]; } pAddress[msAddress_len] = 0; } //pAddress = (unsigned char *)midpJcharsToChars(msAddress); pcsl_mem_free(msAddress_data); if (!KNI_IsNullHandle(messageBuffer)) { messageLength = KNI_GetArrayLength(messageBuffer); } if (messageLength >= 0) { if (messageLength > 0) { pMessageBuffer = (unsigned char *)pcsl_mem_malloc(messageLength); memset(pMessageBuffer, 0, messageLength); KNI_GetRawArrayRegion(messageBuffer, 0, messageLength, (jbyte *)pMessageBuffer); } trySend = KNI_TRUE; } } } #if ENABLE_REENTRY } else { /* Reinvocation after unblocking the thread. */ if (info->pResult == NULL) { /* waiting for mms_send_completed event */ if (info->status == WMA_ERR) { KNI_ThrowNew(midpInterruptedIOException, "Sending SMS"); } break; } messageStateData = info->pResult; pMessageBuffer = messageStateData->pMessageBuffer; pAddress = messageStateData->pAddress; pdContext = messageStateData->pdContext; trySend = KNI_TRUE; } #endif if (trySend == KNI_TRUE) { /* send message. */ status = jsr120_send_sms((jchar)messageType, pAddress, pMessageBuffer, (jchar)messageLength, (jchar)sourcePort, (jchar)destPort, handle, &pdContext); if (status == WMA_ERR) { KNI_ThrowNew(midpIOException, "Sending SMS"); break; } #if ENABLE_REENTRY else if (status == WMA_NET_WOULDBLOCK) { if (messageStateData == NULL) { messageStateData = (jsr120_sms_message_state_data *)pcsl_mem_malloc( sizeof(*messageStateData)); messageStateData->pMessageBuffer = pMessageBuffer; messageStateData->pAddress = pAddress; } messageStateData->pdContext = pdContext; /* Block calling Java Thread. */ midp_thread_wait(WMA_SMS_WRITE_SIGNAL, handle, messageStateData); stillWaiting = KNI_TRUE; break; } else { /* waiting for sms_send_completed event */ midp_thread_wait(WMA_SMS_WRITE_SIGNAL, handle, NULL); } #endif } } while (0); if (!stillWaiting) { pcsl_mem_free(pMessageBuffer); pcsl_mem_free(pAddress); } } KNI_EndHandles(); KNI_ReturnInt(0); /* currently ignored. */ }
/** * Opens an SMS connection. * * @param host The host name. * @param port The port number used to match against incoming SMS messages. * * @return A handle to the open SMS connection. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_io_j2me_sms_Protocol_open0) { int handle = 0; int port; /* The midlet suite name for this connection. */ AppIdType msid = UNUSED_APP_ID; port = KNI_GetParameterAsInt(3); jsr120_sms_pool_init(); /* When port is 0 then return else continue */ if (port) { /* Create handles for all Java objects. */ KNI_StartHandles(1); KNI_DeclareHandle(javaStringHost); /* Pick up the host string. */ KNI_GetParameterAsObject(1, javaStringHost); /* Pick up the Midlet Suite ID. */ msid = KNI_GetParameterAsInt(2); do { /* * Get unique handle, to identify this * SMS "session".. */ handle = (int)(pcsl_mem_malloc(1)); if (handle == 0) { KNI_ThrowNew(midpOutOfMemoryError, "Unable to start SMS."); break; } /* * Register the port with the message pool, only if this * is a server connection (NULL host name.). */ // if (!KNI_IsNullHandle(javaStringHost) && KNI_GetStringLength(javaStringHost) > 0) { if (KNI_IsNullHandle(javaStringHost)) { /* register SMS port with SMS pool */ if (jsr120_is_sms_midlet_listener_registered((jchar)port) == WMA_ERR) { if (jsr120_register_sms_midlet_listener((jchar)port, msid, handle) == WMA_ERR) { KNI_ThrowNew(midpIOException, "already in use"); break; } } else { /* port already registered, throw exception */ KNI_ThrowNew(midpIOException, "already in use"); break; } } } while (0); KNI_EndHandles(); } KNI_ReturnInt(handle); }
/** * Writes to the open socket connection. * <p> * Java declaration: * <pre> * write0([BII)I * </pre> * * @param b the buffer of the data to write * @param off the start offset in array <tt>b</tt> * at which the data is written. * @param len the number of bytes to write. * * @return the total number of bytes written */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_socket_Protocol_write0(void) { int length; int offset; void *pcslHandle; int bytesWritten = 0; int status = PCSL_NET_INVALID; void *context = NULL; MidpReentryData* info; length = (int)KNI_GetParameterAsInt(3); offset = (int)KNI_GetParameterAsInt(2); KNI_StartHandles(2); KNI_DeclareHandle(bufferObject); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); KNI_GetParameterAsObject(1, bufferObject); pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); REPORT_INFO3(LC_PROTOCOL, "socket::write0 o=%d l=%d fd=%d\n", offset, length, pcslHandle); info = (MidpReentryData*)SNI_GetReentryData(NULL); START_NETWORK_INDICATOR; if (info == NULL) { /* First invocation */ if (INVALID_HANDLE == pcslHandle) { KNI_ThrowNew(midpIOException, "invalid handle during socket::write"); } else { INC_NETWORK_INDICATOR; SNI_BEGIN_RAW_POINTERS; status = pcsl_socket_write_start(pcslHandle, (char*)&(JavaByteArray(bufferObject)[offset]), length, &bytesWritten, &context); SNI_END_RAW_POINTERS; } } else { /* Reinvocation after unblocking the thread */ if (INVALID_HANDLE == pcslHandle) { /* closed by another thread */ KNI_ThrowNew(midpInterruptedIOException, "Interrupted IO error during socket::read"); DEC_NETWORK_INDICATOR; } else { if ((void *)info->descriptor != pcslHandle) { REPORT_CRIT2(LC_PROTOCOL, "socket::write Handles mismatched 0x%x != 0x%x\n", pcslHandle, info->descriptor); } context = info->pResult; SNI_BEGIN_RAW_POINTERS; status = pcsl_socket_write_finish(pcslHandle, (char*)&(JavaByteArray(bufferObject)[offset]), length, &bytesWritten, context); SNI_END_RAW_POINTERS; } } if (INVALID_HANDLE != pcslHandle) { if (status == PCSL_NET_SUCCESS) { DEC_NETWORK_INDICATOR; } else { REPORT_INFO1(LC_PROTOCOL, "socket::write error=%d\n", (int)pcsl_network_error(pcslHandle)); if (status == PCSL_NET_WOULDBLOCK) { midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)pcslHandle, context); } else if (status == PCSL_NET_INTERRUPTED) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Interrupted IO error %d during socket::write ", pcsl_network_error(pcslHandle)); KNI_ThrowNew(midpInterruptedIOException, gKNIBuffer); DEC_NETWORK_INDICATOR; } else { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError %d during socket:: write \n", pcsl_network_error(pcslHandle)); KNI_ThrowNew(midpIOException, gKNIBuffer); DEC_NETWORK_INDICATOR; } } } REPORT_INFO1(LC_PROTOCOL, "socket::write0 bytesWritten=%d\n", bytesWritten); KNI_EndHandles(); KNI_ReturnInt((jint)bytesWritten); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(javax_microedition_lcdui_TextFieldLFImpl_getNativeEditorCursorIndex) { KNI_ReturnInt(0); }
/** * Get the Isolate ID of the AMS Isolate. * * @return Isolate ID of AMS Isolate */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_midp_main_MIDletSuiteLoader_getAmsIsolateId) { (void) _p_mb; KNI_ReturnInt(0); }
/** * KNI function that creates native resource for the current StringItem. * <p> * Java declaration: * <pre> * createNativeResource0(ISIII[OII)I * </pre> * * @param ownerId Owner screen's native resource id (MidpDisplayable *) * @param label - label to be used for this ChoiceGroup * @param layout layout directive associated with this ChoiceGroup * @param choiceType - should be EXCLUSIVE, MULTIPLE, IMPLICIT, POPUP * @param fitPolicy - to be used to display created ChoiceGroup * @param cgElements - elements array with string, image, font, selected state * information per element * @param numChoices - number of elements in the ChoiceGroup * @param selectedIndex - currently selected index (for EXCLUSIVE, IMPLICIT, and * POPUP) * @return native resource id (MidpItem *) of this StringItem */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_ChoiceGroupLFImpl_createNativeResource0() { MidpError err = KNI_OK; MidpDisplayable *ownerPtr = NULL; MidpItem *cgPtr = NULL; pcsl_string label_str; MidpChoiceGroupElement *cgChoices = NULL; int choiceType, layout; int fitPolicy; int numChoices = 0; int selectedIndex; int i = 0; pcsl_string_status perr; ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); layout = KNI_GetParameterAsInt(3); choiceType = KNI_GetParameterAsInt(4); fitPolicy = KNI_GetParameterAsInt(5); numChoices = KNI_GetParameterAsInt(7); selectedIndex = KNI_GetParameterAsInt(8); KNI_StartHandles(8); KNI_DeclareHandle(labelJString); KNI_DeclareHandle(cgElementsJObject); KNI_DeclareHandle(cgElement); KNI_DeclareHandle(strJString); KNI_DeclareHandle(imgJImage); KNI_DeclareHandle(fontJFont); KNI_DeclareHandle(cgElementHandle); KNI_DeclareHandle(fontHandle); KNI_GetParameterAsObject(2, labelJString); KNI_GetParameterAsObject(6, cgElementsJObject); if (numChoices > 0) { jobjectArray cgElementsArray; KNI_FindClass("javax/microedition/lcdui/ChoiceGroup$CGElement", cgElementHandle); KNI_FindClass("javax/microedition/lcdui/Font", fontHandle); cgElementsArray = (jobjectArray)cgElementsJObject; cgChoices = (MidpChoiceGroupElement *) midpMalloc(sizeof(MidpChoiceGroupElement) * numChoices); if (cgChoices == NULL) { err = KNI_ENOMEM; } for (i = 0; err == KNI_OK && i < numChoices; i++) { KNI_GetObjectArrayElement(cgElementsArray, i, cgElement); KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "stringEl", "Ljava/lang/String;", _cgEl_stringEl_cache), strJString); perr = midp_jstring_to_pcsl_string(strJString, &cgChoices[i].string); if (PCSL_STRING_OK != perr) { err = KNI_ENOMEM; } else { KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "imageDataEl", "Ljavax/microedition/lcdui/ImageData;", _cgEl_imageDataEl_cache), imgJImage); if (KNI_IsNullHandle(imgJImage) == KNI_TRUE) { cgChoices[i].image = NULL; } else { cgChoices[i].image = gxp_get_imagedata(imgJImage); } cgChoices[i].selected = KNI_GetBooleanField(cgElement, _CACHE_FIELDID(cgElementHandle, "selected", "Z", _cgEl_selected_cache)); KNI_GetObjectField(cgElement, _CACHE_FIELDID(cgElementHandle, "fontEl", "Ljavax/microedition/lcdui/Font;", _cgEl_font_cache), fontJFont); if (KNI_IsNullHandle(fontJFont) == KNI_TRUE) { cgChoices[i].font = NULL; } else { int face, style, size; /* usually only few fonts are set */ 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)); if ((err = lfpport_get_font(&(cgChoices[i].font), face, style, size)) != KNI_OK) { err = KNI_ENOMEM; i++; break; } } } } } if (err == KNI_OK) { if(PCSL_STRING_OK != midp_jstring_to_pcsl_string(labelJString, &label_str)) { err = KNI_ENOMEM; } } KNI_EndHandles(); if (err == KNI_OK) { cgPtr = MidpNewItem(ownerPtr, MIDP_EXCLUSIVE_CHOICE_GROUP_TYPE + choiceType - 1); if (cgPtr == NULL) { err = KNI_ENOMEM; } else { err = lfpport_choicegroup_create(cgPtr, ownerPtr, &label_str, layout, choiceType, cgChoices, numChoices, selectedIndex, fitPolicy); } } // do clean up pcsl_string_free(&label_str); for (i--; i >= 0; i--) { pcsl_string_free(&cgChoices[i].string); } midpFree(cgChoices); if (err != KNI_OK) { MidpDeleteItem(cgPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(cgPtr); }
/*========================================================================= * FUNCTION: modExp([B[B[B[B[B)V (STATIC) * CLASS: com/sun/midp/crypto/RSA * TYPE: static native function * OVERVIEW: Perform modular exponentiation. * INTERFACE (operand stack manipulation): * parameters: data contains the data on which exponentiation is to * be performed * exponent contains the exponent, e.g. 65537 (decimal) is * written as a three-byte array containing * 0x01, 0x00, 0x01 * modulus contains the modulus * result the result of the modular exponentiation is * returned in this array * returns: the length of the result *=======================================================================*/ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_crypto_RSA_modExp() { jint dataLen, expLen, modLen, resLen; jint maxLen; INTEGER numbytes = 0; unsigned char *buf; BIGNUM *a, *b, *c, *d; BN_CTX *ctx; KNI_StartHandles(4); KNI_DeclareHandle(ires); KNI_DeclareHandle(imod); KNI_DeclareHandle(iexp); KNI_DeclareHandle(idata); KNI_GetParameterAsObject(4, ires); KNI_GetParameterAsObject(3, imod); KNI_GetParameterAsObject(2, iexp); KNI_GetParameterAsObject(1, idata); resLen = KNI_GetArrayLength(ires); modLen = KNI_GetArrayLength(imod); expLen = KNI_GetArrayLength(iexp); dataLen = KNI_GetArrayLength(idata); /* Find which parameter is largest and allocate that much space */ maxLen = MAX(MAX(MAX(resLen, modLen), expLen), dataLen); if (maxLen > (BN_MAX_INTEGER / 8)) { /* The number of BITS must fit in a BN integer. */ KNI_ThrowNew(midpIllegalArgumentException, "arg too long"); } else { buf = (unsigned char *) midpMalloc(maxLen * sizeof(unsigned char)); if (buf == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_GetRawArrayRegion(idata, 0, dataLen, (jbyte*)buf); a = BN_bin2bn(buf, (INTEGER)dataLen, NULL); KNI_GetRawArrayRegion(iexp, 0, expLen, (jbyte*)buf); b = BN_bin2bn(buf, (INTEGER)expLen, NULL); KNI_GetRawArrayRegion(imod, 0, modLen, (jbyte*)buf); c = BN_bin2bn(buf, (INTEGER)modLen, NULL); d = BN_new((INTEGER)resLen); ctx = BN_CTX_new((INTEGER)maxLen); /* do the actual exponentiation */ if (a != NULL && b != NULL && c != NULL && d != NULL && ctx != NULL && BN_mod_exp_mont(d,a,b,c,ctx)) { /* Covert result from BIGNUM d to char array */ numbytes = BN_bn2bin(d, buf); KNI_SetRawArrayRegion(ires, 0, numbytes, (jbyte*)buf); } else { /* assume out of mem */ KNI_ThrowNew(midpOutOfMemoryError, "Mod Exp"); } midpFree(buf); BN_free(a); BN_free(b); BN_free(c); BN_free(d); BN_CTX_free(ctx); } } KNI_EndHandles(); KNI_ReturnInt((jint)numbytes); }
/** * Initializes the device. * <p>Java declaration: * <pre> * private native boolean init0(); * </pre> * @return KNI_TRUE in case of success, else KNI_FALSE * @throws CardDeviceException If configuration failed. */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL (com_sun_cardreader_PlatformCardDevice_init0) { jboolean retcode = KNI_FALSE; javacall_result status; char *err_msg; char *buffer; const char *prop_value; prop_value = getInternalProperty(hostsandports); if (prop_value != NULL) { status = javacall_carddevice_set_property(hostsandports, prop_value); if (status != JAVACALL_OK) { goto err; } prop_value = getInternalProperty(satselectapdu); status = javacall_carddevice_set_property(satselectapdu, prop_value); if (status != JAVACALL_OK) { goto err; } } if ((status = javacall_carddevice_init()) == JAVACALL_OK) { javacall_carddevice_clear_error(); retcode = KNI_TRUE; } else if (status == JAVACALL_NOT_IMPLEMENTED) { /* We throw special exception to tell i3tests to skip real testing*/ KNI_ThrowNew(cardDeviceException, "stub"); retcode = KNI_TRUE; } goto end; err: #define BUFFER_SIZE 128 buffer = malloc(BUFFER_SIZE); if (buffer == NULL) { err_msg = "init0()"; KNI_ThrowNew(jsropOutOfMemoryError, err_msg); goto end; } switch (status) { case JAVACALL_NOT_IMPLEMENTED: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "Required property not supported"; } KNI_ThrowNew(cardDeviceException, err_msg); break; case JAVACALL_OUT_OF_MEMORY: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "init0()"; } KNI_ThrowNew(jsropOutOfMemoryError, err_msg); break; default: if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) { err_msg = buffer; } else { err_msg = "Invalid internal property"; } KNI_ThrowNew(cardDeviceException, err_msg); break; } free(buffer); end: KNI_ReturnInt(retcode); }
/** * Gets the maximum length in bytes for a converted string. * <p> * Java declaration: * <pre> * getMaxByteLength(I)I * </pre> * * @param handler handle returned from getHandler * * @return maximum byte length, or zero if the handler is not valid */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_i18n_j2me_Conv_getMaxByteLength() { int id = KNI_GetParameterAsInt(1); KNI_ReturnInt(lcConv[id] ? lcConv[id]->byteMaxLen() : 0); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_amms_directcontrol_DirectEqualizerControl_nGetEctlVtbl) { KNI_ReturnInt( (int)( &equalizer_ectl_vtbl ) ); }
KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_cldc_io_j2me_socket_Protocol_available0() { // unsupported. Not used by CLDC TCK KNI_ReturnInt(0); }
/* 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); }
KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_jsr82emul_ConnectionEmul_getHandle() { int protocol = (int)KNI_GetParameterAsInt(1); jint handle = (jint)getNextHandle(protocol); KNI_ReturnInt(handle); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_amms_directcontrol_DirectReverbControl_nGetEctlVtbl) { KNI_ReturnInt( (int)( &reverb_ectl_vtbl ) ); }
/** * 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); }
/** * Create a new iterator instance. * * @param lib library handle. If library handle is not valid 0 is returned * as an iterator handle. * * @return handle of new iterator. If some error occurs 0 is returned * as an iterator handle. */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_chameleon_input_PTIteratorImpl_ptNewIterator0() { jint lib; lib = KNI_GetParameterAsInt(1); KNI_ReturnInt(ptOpenIterator(lib)); }
/* * 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_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); }
/* * 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); }
/* 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); }
/** * 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); }
/** * Retrieves service classes of a record in the SDDB. * * @param handle handle of the service record * @return service classes set for the record */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_kvem_jsr082_bluetooth_SDDB_getServiceClasses(void) { KNI_ReturnInt(javacall_bt_sddb_get_service_classes(KNI_GetParameterAsInt(1))); }
/** * KNI function that create native resource for current DateField. * * The native widget created by this function must take into account * label and body locations, using Item methods. * The implementation must create a native date/time widget that can be * displayed as date only, time only, or date/time modes. * * The displayMode is a two bit mask in which the MSB is the date, and the * LSB (ie. binary 10 is date only, 01 is time only, 11 is both). * * As the datetime parameter coming from java is in milliseconds since the * epoch 00:00 1/1/1970, it is needed to translate this value to the native * date/time representation. (for example, QT uses the same epoch, but in * resolution of seconds rather than milliseconds). * * * Class: javax.microedition.lcdui.DateFieldLFImpl * Java prototype: * private native int createNativeResource0 ( int ownerId , * String label , int layout, long datetime , int displayMode, * String timeZone); * @param datetime in milliseconds since 00:00 1/1/1970 */ KNIEXPORT KNI_RETURNTYPE_INT Java_javax_microedition_lcdui_DateFieldLFImpl_createNativeResource0() { MidpDisplayable *ownerPtr; pcsl_string label; pcsl_string timezone; pcsl_string_status rc1, rc2; jint layout; jint displayMode; jlong datetime; long qtime = 0; MidpError err = KNI_OK; MidpItem *dfPtr = NULL; KNI_StartHandles(2); KNI_DeclareHandle(labelHandle); KNI_DeclareHandle(timezoneHandle); ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, labelHandle); layout = KNI_GetParameterAsInt(3); datetime = KNI_GetParameterAsLong(4); /* Long occupies two parameters */ displayMode = KNI_GetParameterAsInt(6); KNI_GetParameterAsObject(7, timezoneHandle); rc1 = midp_jstring_to_pcsl_string(labelHandle, &label); rc2 = midp_jstring_to_pcsl_string(timezoneHandle, &timezone); KNI_EndHandles(); /* NULL and empty strings are acceptable */ if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) { err = KNI_ENOMEM; goto cleanup; } dfPtr = MidpNewItem(ownerPtr, MIDP_DATE_FIELD_TYPE); if (dfPtr == NULL) { err = KNI_ENOMEM; goto cleanup; } qtime = (long)(datetime/1000); /* qt date works in seconds */ err = lfpport_datefield_create(dfPtr, ownerPtr, &label, layout, displayMode, qtime, &timezone); cleanup: pcsl_string_free(&label); pcsl_string_free(&timezone); if (err != KNI_OK) { MidpDeleteItem(dfPtr); KNI_ThrowNew(midpOutOfMemoryError, NULL); } KNI_ReturnInt(dfPtr); }