int testInstalFileUsingJad(void) { int res = ALL_OK; int myArgc = 2; REPORT_INFO(LC_AMS, "############# This test should pass.\n"); res = fileInstaller(myArgc, myArgv); if (res != ALL_OK) { REPORT_WARN2(LC_AMS, "\n%s failed. Result code is %d\n", fileInstallerTest, res); } else { REPORT_INFO1(LC_AMS, "%s passed\n", fileInstallerTest); } return res; } /* testInstalFileUsingJad */
int testInstalFileUsingBadJad(void) { int res = -1; int myArgc = 2; REPORT_INFO(LC_AMS, "############# This test should fail. Using Jad without JAR-Size\n"); res = fileInstaller(myArgc, mrgvbad); if (res >= 0) { REPORT_WARN2(LC_AMS, "\n%s failed. Result code is %d\n", fileInstallerTestBadJad, res); res = -1; } else { REPORT_INFO1(LC_AMS, "%s passed\n", fileInstallerTestBadJad); res = ALL_OK; } return res; }
/** * The platform should invoke this function in platform context to start * the Java VM with arbitrary arguments. * * @param argc number of command-line arguments * @param argv array of command-line arguments * * @note This is a service function and it is introduced in the javacall * interface for debug purposes. Please DO NOT CALL this function without * being EXPLICITLY INSTRUCTED to do so. */ void javanotify_start_java_with_arbitrary_args(int argc, char* argv[]) { javacall_result res; REPORT_INFO(LC_CORE, "javanotify_start_java_with_arbitrary_args() >>\n"); if (argc > MIDP_RUNMIDLET_MAXIMUM_ARGS) { argc = MIDP_RUNMIDLET_MAXIMUM_ARGS; } if (initialize_memory_slavemode() != JAVACALL_OK) { return; } javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
extern "C" void gxpport_create_mutable(gxpport_mutableimage_native_handle *newImagePtr, int width, int height, gxutl_native_image_error_codes* creationErrorPtr) { /* set optimization for all QPixmaps move this to startup/initialization code. */ QPixmap::setDefaultOptimization(QPixmap::BestOptim); /* * Populate Java data pointer before calling checkResourceLimit * because it might trigger GC and makes the Java pointer invalid. */ QPixmap* qpixmap = new QPixmap(); /* Start with a NULL image object */ if (NULL == qpixmap) { *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR; return; } /* Check resource limit before really creating image memory */ if (midpCheckResourceLimit(RSC_TYPE_IMAGE_MUT, ImgRegionRscSize(width, height)) == 0) { *creationErrorPtr = GXUTL_NATIVE_IMAGE_RESOURCE_LIMIT; delete qpixmap; return; } /* ALLOCATE MEMORY FOR QT IMAGE DATA */ qpixmap->resize(width, height); /* INITIALIZE CONTENTS TO WHITE */ qpixmap->fill(); /* Update the resource count */ if (midpIncResourceCount(RSC_TYPE_IMAGE_MUT, ImgRscSize(qpixmap)) == 0) { REPORT_INFO(LC_LOWUI,"Error in updating resource" " limit for Mutable image"); } /* return the qpixmap pointer */ *newImagePtr = qpixmap; *creationErrorPtr = GXUTL_NATIVE_IMAGE_NO_ERROR; }
/** * This implementation causes java stack to resume after * standard timeout after having been suspended. */ jboolean midp_checkResumeRequest() { static long lastSuspendStart = -1; long time_passed; jboolean result = KNI_FALSE; if (lastSuspendStart == -1) { REPORT_INFO(LC_LIFECYCLE, "midp_checkResumeRequest(): init timeout"); lastSuspendStart = midp_getCurrentTime(); } time_passed = midp_getCurrentTime() - lastSuspendStart; if (time_passed >= sr_resume_timeout) { lastSuspendStart = -1; sr_resume_timeout = DEFAULT_TIMEOUT; result = KNI_TRUE; } return result; }
/* * Close a opened by storage_open. Does no block. * * If not successful *ppszError will set to point to an error string, * on success it will be set to NULL. */ void storageClose(char** ppszError, int handle) { int status; *ppszError = NULL; status = pcsl_file_close((void *)handle); REPORT_INFO2(LC_CORE, "storageClose on file_desc %d returns %d\n", handle, status); if (status < 0) { *ppszError = getLastError("storageClose()"); } /* File is successfully closed, decrement the count */ if (midpDecResourceCount(RSC_TYPE_FILE, 1) == 0) { REPORT_INFO(LC_CORE, "FILE: resource" " limit update error"); } }
/** * The platform should invoke this function in platform context to start * Java. */ void javanotify_start(void) { midp_jc_event_union e; midp_jc_event_start_arbitrary_arg *data = &e.data.startMidletArbitraryArgEvent; REPORT_INFO(LC_CORE,"javanotify_start() >>\n"); e.eventType = MIDP_JC_EVENT_START_ARBITRARY_ARG; data->argc = 0; data->argv[data->argc++] = "runMidlet"; data->argv[data->argc++] = "-1"; data->argv[data->argc++] = #if ENABLE_MULTIPLE_ISOLATES "com.sun.midp.appmanager.MVMManager"; #else "com.sun.midp.appmanager.Manager"; #endif midp_jc_event_send(&e); }
/** * Refresh the area specified. * @param x relative to drawable * @param y relative to drawable * @param width width of the area to be updated * @param height height of the area to be updated */ MidpError CustomItem::refresh(int x, int y, int width, int height) { #if REPORT_LEVEL <= LOG_INFORMATION PlatformMScreen * mscreen = PlatformMScreen::getMScreen(); reportToLog(LOG_INFORMATION, LC_HIGHUI, "+ CustomItem::refresh: (%d,%d) (%dx%d)\n", x, y, width, height); reportToLog(LOG_INFORMATION, LC_HIGHUI, "+ QWidget::pos() = (%d,%d) drawable->pos() = (%d,%d)\n", QWidget::pos().x(), QWidget::pos().y(), drawable->pos().x(), drawable->pos().y()); reportToLog(LOG_INFORMATION, LC_HIGHUI, "+ scroll position = %d\n", mscreen->scrollPosition()); reportToLog(LOG_INFORMATION, LC_HIGHUI, "+\t\tbitBlt(\tdst, %d, %d,\n\t\t\tsrc, %d, %d, %d, %d); ", x, // dx y, // dy QWidget::pos().x() + drawable->pos().x() + x, QWidget::pos().y() + drawable->pos().y() + y - mscreen->scrollPosition(), width, height); #endif drawable->refresh(x, y, width, height); REPORT_INFO(LC_HIGHUI, "bitBlt complete.\n\n"); return KNI_OK; }
/** * A notification function for telling Java to perform installation of * a content via http, for SprintAMS. * * This function requires that the descriptor (JADfile, or GCDfile) * has already been downloaded and resides somewhere on the file system. * The function also requires the full URL that was used to download the * file. * * The given URL should be of the form http://www.sun.com/a/b/c/d.jad * or http://www.sun.com/a/b/c/d.gcd. * Java will start a graphical installer which will download the content * fom the Internet. * * @param httpUrl null-terminated http URL string of the content * descriptor. The URL is of the following form: * http://www.website.com/a/b/c/d.jad * @param descFilePath full path of the descriptor file which is of the * form: * /a/b/c/d.jad or /a/b/c/d.gcd * @param descFilePathLen length of the file path * @param isJadFile set to TRUE if the mime type of of the downloaded * descriptor file is <tt>text/vnd.sun.j2me.app-descriptor</tt>. If * the mime type is anything else (e.g., <tt>text/x-pcs-gcd</tt>), * this must be set to FALSE. * @param isSilent set to TRUE if the content is to be installed silently, * without intervention from the user. (e.g., in the case of SL * or SI messages) * */ void javanotify_install_content(const char * httpUrl, const javacall_utf16* descFilePath, unsigned int descFilePathLen, javacall_bool isJadFile, javacall_bool isSilent) { const static int SchemaLen = 16; const static javacall_utf16 SchemaFile[] = {'f','i','l','e',':','/','/','/'}; midp_jc_event_union e; int httpUrlLength, dscFileOffset; REPORT_INFO(LC_CORE, "javanotify_install_content() >>\n"); if ((httpUrl == NULL) || (httpUrl == NULL)) { return; /* mandatory parameter is NULL */ } httpUrlLength = strlen(httpUrl) + 1; dscFileOffset = (httpUrlLength + 1) & (-2); /* align to WORD boundary */ if ((descFilePathLen <= 0) || (descFilePathLen * 2 + dscFileOffset > sizeof(urlAddress))) { return; /* static buffer so small */ } /* Is it nessasary to add schema file like: "file:///"? */ /* Let move the input strings to the static buffer - urlAddress */ memcpy(urlAddress, httpUrl, httpUrlLength); memcpy(urlAddress + dscFileOffset, descFilePath, descFilePathLen * 2); e.eventType = MIDP_JC_EVENT_INSTALL_CONTENT; e.data.install_content.httpUrl = urlAddress; e.data.install_content.descFilePath = (javacall_utf16*) urlAddress + dscFileOffset; e.data.install_content.descFilePathLen = descFilePathLen; e.data.install_content.isJadFile = isJadFile; e.data.install_content.isSilent = isSilent; midp_jc_event_send(&e); }
/** * Releases any native resources used by the socket connection. * <p> * Java declaration: * <pre> * finalize(V)V * </pre> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_socket_Protocol_finalize(void) { void *pcslHandle; int status = PCSL_NET_INVALID; void* context = NULL; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); REPORT_INFO1(LC_PROTOCOL, "socket::finalize handle=%d\n", pcslHandle); if (INVALID_HANDLE != pcslHandle) { status = pcsl_socket_close_start(pcslHandle, &context); getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } if (status == PCSL_NET_IOERROR) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError in socket::finalize error=%d\n", (int)pcsl_network_error(pcslHandle)); REPORT_ERROR1(LC_PROTOCOL, "%s", gKNIBuffer); } else if (status == PCSL_NET_WOULDBLOCK) { /* blocking during finalize is not supported */ REPORT_CRIT1(LC_PROTOCOL, "socket::finalize = 0x%x blocked\n", pcslHandle); } } FINISH_NETWORK_INDICATOR; KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Releases any native resources used by the datagram connection. * <p> * Java declaration: * <pre> * finalize(V)V * </pre> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_datagram_Protocol_finalize(void) { void *handle; int status; void *context = NULL; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); handle = (void *)getMidpDatagramProtocolPtr(thisObject)->nativeHandle; if (handle != INVALID_HANDLE) { if (pushcheckin((int)handle) == -1) { status = pcsl_datagram_close_start(handle, &context); if (status == PCSL_NET_SUCCESS) { if (midpDecResourceCount(RSC_TYPE_UDP, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Datagrams: resource limit update error"); } } else if (status == PCSL_NET_IOERROR) { REPORT_INFO2(LC_PROTOCOL, "datagram::finalize handle 0x%x I/O error code %d", (int)handle, pcsl_network_error(handle)); } else if (status == PCSL_NET_WOULDBLOCK) { REPORT_ERROR1(LC_PROTOCOL, "datagram::finalize handle 0x%x WOULDBLOCK not supported", (int)handle); } getMidpDatagramProtocolPtr(thisObject)->nativeHandle = (jint)INVALID_HANDLE; } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * A notification function for telling Java to perform installation of * a MIDlet from filesystem, * * The installation will be performed in the background without launching * the graphic installer application. * * The given path is the full path to MIDlet's jad file or jad. * In case the MIDlet's jad file is specified, then * the MIDlet's jar file muts reside in the same directory as the jad * file. * * @param jadFilePath full path the jad (or jar) file which is of the form: * file://a/b/c/d.jad * @param jadFilePathLen length of the file path * @param userWasAsked a flag indicating whether the platform already asked * the user for permission to download and install the application * so there's no need to ask again and we can immediately install. */ void javanotify_install_midlet_from_filesystem(const javacall_utf16 * jadFilePath, int jadFilePathLen, int userWasAsked) { midp_jc_event_union e; midp_jc_event_start_arbitrary_arg *data = &e.data.startMidletArbitraryArgEvent; REPORT_INFO(LC_CORE,"javanotify_install_midlet_from_filesystem() >>\n"); e.eventType = MIDP_JC_EVENT_START_ARBITRARY_ARG; data->argc = 0; data->argv[data->argc++] = "runMidlet"; data->argv[data->argc++] = "-1"; data->argv[data->argc++] = "com.sun.midp.scriptutil.CommandLineInstaller"; data->argv[data->argc++] = "I"; if (jadFilePathLen >= BINARY_BUFFER_MAX_LEN) return; memset(urlAddress, 0, BINARY_BUFFER_MAX_LEN); unicodeToNative(jadFilePath, jadFilePathLen, (unsigned char *) urlAddress, BINARY_BUFFER_MAX_LEN); data->argv[data->argc++] = urlAddress; midp_jc_event_send(&e); }
/* * Creates a client connection object. * * Note: the method sets native connection handle directly to * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object. * * @param auth <code>true</code> if authication is required * @param enc <code>true</code> indicates * what connection must be encrypted * @param master <code>true</code> if client requires to be * a connection's master * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_create0) { javacall_bool auth = (KNI_GetParameterAsBoolean(1) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_bool enc = (KNI_GetParameterAsBoolean(2) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_bool master = (KNI_GetParameterAsBoolean(3) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_handle handle = JAVACALL_BT_INVALID_HANDLE; REPORT_INFO(LC_PROTOCOL, "btspp::create"); /* create RFCOMMC server connection */ if (javacall_bt_rfcomm_create_client(auth, enc, master, &handle) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "Connection creation failed during btspp::create"); KNI_ThrowNew(jsropIOException, EXCEPTION_MSG("Can not create RFCOMM connection")); KNI_ReturnVoid(); } KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); /* store native connection handle to Java object */ KNI_SetIntField(thisHandle, connHandleID, (jint)handle); REPORT_INFO1(LC_PROTOCOL, "btspp::create0 handle=%d connection created", handle); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * 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); }
/** * Accepts incoming client connection request. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPNotifierImpl</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>RFCOMMConnectionImpl</code> object. * * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_accept0(void) { bt_handle_t handle = BT_INVALID_HANDLE; bt_handle_t peer_handle = BT_INVALID_HANDLE; MidpReentryData* info; int status = BT_RESULT_FAILURE; int processStatus = KNI_FALSE; void *context = NULL; bt_bdaddr_t peer_addr; unsigned char *address = NULL; KNI_StartHandles(2); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(arrayHandle); KNI_GetThisPointer(thisHandle); handle = (bt_handle_t)KNI_GetIntField(thisHandle, notifHandleID); KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle); if (handle == BT_INVALID_HANDLE) { REPORT_ERROR(LC_PROTOCOL, "RFCOMM notifier was closed before btspp_notif::accept"); KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG( "RFCOMM 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, NULL, NULL) == BT_RESULT_SUCCESS) { pushcheckoutaccept((int)handle); processStatus = KNI_TRUE; status = BT_RESULT_SUCCESS; } } if (peer_handle == BT_INVALID_HANDLE) { info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ REPORT_INFO1(LC_PROTOCOL, "btspp_notif::accept handle=%d\n", handle); // IMPL_NOTE: 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 = bt_rfcomm_accept_start( handle, &peer_handle, peer_addr, &context); processStatus = KNI_TRUE; // } } else { /* Reinvocation after unblocking the thread */ if ((bt_handle_t)info->descriptor != handle) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "btspp_notif::accept handles mismatched %d != %d\n", handle, info->descriptor); REPORT_CRIT(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG( "Internal error in btspp_notif::accept")); } else { // IMPL_NOTE: 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 = bt_rfcomm_accept_finish( handle, &peer_handle, peer_addr, context); processStatus = KNI_TRUE; // } } } } if (processStatus) { REPORT_INFO1(LC_PROTOCOL, "btspp_notif::accept server handle=%d\n", handle); if (status == BT_RESULT_SUCCESS) { int i; // IMPL_NOTE: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "btspp_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 = (unsigned char*)JavaByteArray(arrayHandle); for (i = 0; i < BT_ADDRESS_SIZE; i++) { address[i] = peer_addr[i]; } SNI_END_RAW_POINTERS; RegisterRFCOMMConnection0(peer_addr, peer_handle); REPORT_INFO(LC_PROTOCOL, "btspp_notif::accept incoming connection accepted!"); } else if (status == BT_RESULT_WOULDBLOCK) { midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context); } else if (status == BT_RESULT_FAILURE) { char* pError; bt_rfcomm_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in btspp_notif::accept (%s)\n", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); } else { char* pMsg = "Unknown error during btspp_notif::accept"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } } } KNI_EndHandles(); KNI_ReturnVoid(); }
static MidpProperties midpParseMf(jchar* jchar_buffer) { MidpProperties mfsmp = {0, ALL_OK, NULL}; pcsl_string mfkey; pcsl_string mfkey_trimmed; pcsl_string mfvalue; pcsl_string mfvalue_trimmed; pcsl_string mfline; MIDPError err; pcsl_string_status rc; int countLines = 0; int index = 0; int count = 0; if (!jchar_buffer) { mfsmp.status = BAD_PARAMS; return mfsmp; } countLines = count_mf_lines(jchar_buffer); if (countLines <= 0) { REPORT_INFO(LC_AMS, "midpParseMf(): Empty manifest."); mfsmp.status = OUT_OF_MEMORY; return mfsmp; } mfsmp.pStringArr = alloc_pcsl_string_list(countLines * 2); if (mfsmp.pStringArr == NULL) { mfsmp.status = OUT_OF_MEMORY; return mfsmp; } mfsmp.numberOfProperties = countLines; for (count = 0; count < countLines * 2 ; /* count increased at the end of for */ ) { /* memory for the line is allocated here */ /* line continuation striped out */ err = readMfLine(&jchar_buffer, &mfline); if (OUT_OF_MEMORY == err) { midp_free_properties(&mfsmp); mfsmp.status = OUT_OF_MEMORY; return mfsmp; } else if (END_OF_MF == err) { /* we are done */ mfsmp.status = ALL_OK; break; } index = pcsl_string_index_of(&mfline, ':'); if (index <= 0) { mfsmp.status = BAD_MF_KEY; pcsl_string_free(&mfline); continue; } /* memory for mfkey is allocated here */ if (PCSL_STRING_OK != pcsl_string_substring(&mfline, 0, index, &mfkey)) { midp_free_properties(&mfsmp); mfsmp.status = OUT_OF_MEMORY; pcsl_string_free(&mfline); return mfsmp; } rc = pcsl_string_trim(&mfkey, &mfkey_trimmed); pcsl_string_free(&mfkey); if (PCSL_STRING_OK != rc) { mfsmp.status = OUT_OF_MEMORY; midp_free_properties(&mfsmp); pcsl_string_free(&mfline); return mfsmp; } if (pcsl_string_length(&mfkey_trimmed) < 1) { mfsmp.status = BAD_PARAMS; pcsl_string_free(&mfline); pcsl_string_free(&mfkey_trimmed); continue; } err = checkMfKeyChars(&mfkey_trimmed); if (OUT_OF_MEMORY == err) { mfsmp.status = OUT_OF_MEMORY; midp_free_properties(&mfsmp); pcsl_string_free(&mfline); pcsl_string_free(&mfkey_trimmed); return mfsmp; } else if (BAD_MF_KEY == err) { mfsmp.status = BAD_MF_KEY; pcsl_string_free(&mfline); pcsl_string_free(&mfkey_trimmed); continue; } rc = pcsl_string_substring(&mfline, index + 1, pcsl_string_length(&mfline), &mfvalue); /* free the mfline once we have got the key and value */ pcsl_string_free(&mfline); if (PCSL_STRING_OK != rc) { mfsmp.status = OUT_OF_MEMORY; midp_free_properties(&mfsmp); pcsl_string_free(&mfkey_trimmed); return mfsmp; } /* memory for value is allocated here */ rc = pcsl_string_trim(&mfvalue, &mfvalue_trimmed); pcsl_string_free(&mfvalue); if (PCSL_STRING_OK != rc) { mfsmp.status = OUT_OF_MEMORY; midp_free_properties(&mfsmp); pcsl_string_free(&mfkey_trimmed); return mfsmp; } if (pcsl_string_is_null(&mfvalue_trimmed)) { mfsmp.status = NULL_LEN; pcsl_string_free(&mfkey_trimmed); continue; } err = checkMfValueChars(&mfvalue_trimmed); if (OUT_OF_MEMORY == err) { mfsmp.status = OUT_OF_MEMORY; midp_free_properties(&mfsmp); pcsl_string_free(&mfkey_trimmed); pcsl_string_free(&mfvalue_trimmed); return mfsmp; } else if (BAD_MF_VALUE == err) { mfsmp.status = BAD_MF_VALUE; pcsl_string_free(&mfkey_trimmed); pcsl_string_free(&mfvalue_trimmed); continue; } printPcslStringWithMessage("midpParseMf()", &mfkey_trimmed); printPcslStringWithMessage(" = ", &mfvalue_trimmed); /* Store key:value pair. */ mfsmp.pStringArr[count] = mfkey_trimmed; mfsmp.pStringArr[count+1] = mfvalue_trimmed; count += 2; } /* end of for */ mfsmp = verifyMfMustProperties(mfsmp); REPORT_INFO3(LC_AMS, "End of midpParseMf: Status=%d, count=%d, countLines=%d", mfsmp.status, count, countLines); return mfsmp; } /* end of midpParseMf */
MidpProperties mf_main(char* mfbuf, int mflength) { MidpProperties mfsmp = {0, ALL_OK, NULL}; jchar* save_jchar_buffer = NULL; jchar* jchar_buffer = NULL; int jbufsize = -1; #if REPORT_LEVEL <= LOG_INFORMATION int res = 0; #endif if ((mflength <= 0) || (!mfbuf)) { mfsmp.status = OUT_OF_MEMORY; return mfsmp; } jbufsize = mflength * sizeof(jchar); jchar_buffer = (jchar*)midpMalloc(jbufsize+2); if (!jchar_buffer) { midpFree(mfbuf); mfsmp.status = OUT_OF_MEMORY; return mfsmp; } memset(jchar_buffer,0,(jbufsize + 2)); convertChar2JChar(mfbuf,jchar_buffer,mflength); midpFree(mfbuf); save_jchar_buffer = jchar_buffer; REPORT_INFO(LC_AMS, "######################### Start of manifest parsing"); /* during execution of this, jchar_buffer pointer will be changed */ mfsmp = midpParseMf(jchar_buffer); midpFree(save_jchar_buffer); switch (mfsmp.status) { case NO_SUITE_NAME_PROP: midp_free_properties(&mfsmp); return mfsmp; case NO_SUITE_VENDOR_PROP: midp_free_properties(&mfsmp); return mfsmp; case NO_SUITE_VERSION_PROP: midp_free_properties(&mfsmp); return mfsmp; case NO_MIDLET_ONE_PROP: midp_free_properties(&mfsmp); return mfsmp; case NO_MICROEDITION_PROFILE_PROP: midp_free_properties(&mfsmp); return mfsmp; case NO_MICROEDITION_CONFIGURATION_PROP: REPORT_INFO1(LC_AMS, "Manifest MUST property missing %d", mfsmp.status); return mfsmp; case BAD_PARAMS: case BAD_MF_KEY: case BAD_MF_VALUE: REPORT_INFO1(LC_AMS, "Some NOT MUST Manifest property is not valid %d", mfsmp.status); break; case ALL_OK: REPORT_INFO1(LC_AMS, "Manifest ALL_OK %d", mfsmp.status); break; default: REPORT_INFO1(LC_AMS, "MF parse OUT_OF_MEMORY %d", mfsmp.status); /* for unknown result assuming OUT_OF_MEMORY */ return mfsmp; } /* end of switch */ #if REPORT_LEVEL <= LOG_INFORMATION reportToLog(LOG_INFORMATION, LC_AMS, "%s %s %d", "########################### End of manifest parsing: ", "mf_main() : number of Manifest properties = ", mfsmp.numberOfProperties); for (res = 0; res < mfsmp.numberOfProperties * 2; res += 2) { printPcslStringWithMessage(" ", &mfsmp.pStringArr[res]); printPcslStringWithMessage(" ", &mfsmp.pStringArr[res+1]); } #endif return mfsmp; } /* end of mf_main */
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_suspend_test_TestUtil_resumeMidp() { REPORT_INFO(LC_LIFECYCLE, "TestUtil_resumeMidp()"); sr_resume_timeout = RESUME_NOW_TIMEOUT; KNI_ReturnVoid(); }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_suspend_test_TestUtil_suspendMidp() { REPORT_INFO(LC_LIFECYCLE, "TestUtil_suspendMidp()"); midp_suspend(); KNI_ReturnVoid(); }
static MidpProperties verifyJadMustProperties(MidpProperties jadsmp) { /* 5 MUST fields in JAD */ pcsl_string * name = NULL; pcsl_string * version = NULL; pcsl_string * vendor = NULL; pcsl_string * jarUrl = NULL; pcsl_string * jarSizeString = NULL; int permittedJarSize = 0; jint jarSizeByJad = 0; jarUrl = midp_find_property(&jadsmp, &JAR_URL_PROP); if (pcsl_string_is_null(jarUrl)) { REPORT_INFO(LC_AMS, "Missing Jar URL"); jadsmp.status = NO_JAR_URL_PROP; return jadsmp; } jarSizeString = midp_find_property(&jadsmp, &JAR_SIZE_PROP); if (pcsl_string_is_null(jarSizeString)) { REPORT_INFO(LC_AMS, "Missing Jar size"); jadsmp.status = NO_JAR_SIZE_PROP; return jadsmp; } if (PCSL_STRING_OK != pcsl_string_convert_to_jint(jarSizeString, &jarSizeByJad)) { /* NUMBER_ERROR */ REPORT_INFO1(LC_AMS, "JAD size ERROR %d", jarSizeByJad); jadsmp.status = NUMBER_ERROR; return jadsmp; } /* verify that requested jar size is not to big */ permittedJarSize = midpGetMaxJarSizePermitted(); if (jarSizeByJad > permittedJarSize) { REPORT_INFO2(LC_AMS, "Jar size requested by Jad is to big %d > %d", jarSizeByJad, permittedJarSize); REPORT_INFO(LC_AMS, "Out Of Storage"); jadsmp.status = OUT_OF_STORAGE; return jadsmp; } name = midp_find_property(&jadsmp, &SUITE_NAME_PROP); if (pcsl_string_is_null(name)) { REPORT_INFO(LC_AMS, "Missing suite name"); jadsmp.status = NO_SUITE_NAME_PROP; return jadsmp; } vendor = midp_find_property(&jadsmp, &SUITE_VENDOR_PROP); if (pcsl_string_is_null(vendor)) { REPORT_INFO(LC_AMS, "Missing suite vendor"); jadsmp.status = NO_SUITE_VENDOR_PROP; return jadsmp; } version = midp_find_property(&jadsmp, &SUITE_VERSION_PROP); if (pcsl_string_is_null(version)) { REPORT_INFO(LC_AMS, "Missing suite version"); jadsmp.status = NO_SUITE_VERSION_PROP; return jadsmp; } if (!midpCheckVersion(version)) { REPORT_INFO(LC_AMS, "Corrupted suite version"); jadsmp.status = NO_SUITE_VERSION_PROP; return jadsmp; } return jadsmp; } /* verifyJadMUSTProperties */
/** * Closes the socket connection. * <p> * Java declaration: * <pre> * close0(V)V * </pre> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_socket_Protocol_close0(void) { void *pcslHandle; int status = PCSL_NET_INVALID; void* context = NULL; MidpReentryData* info; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* initial invocation */ pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); if (INVALID_HANDLE == pcslHandle) { KNI_ThrowNew(midpIOException, "invalid handle during socket::close"); } else { status = pcsl_socket_close_start(pcslHandle, &context); getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; midp_thread_signal(NETWORK_READ_SIGNAL, (int)pcslHandle, 0); midp_thread_signal(NETWORK_WRITE_SIGNAL, (int)pcslHandle, 0); } } else { /* reinvocation */ pcslHandle = (void *)(info->descriptor); context = info->pResult; status = pcsl_socket_close_finish(pcslHandle, context); } REPORT_INFO1(LC_PROTOCOL, "socket::close handle=%d\n", pcslHandle); if (INVALID_HANDLE != pcslHandle) { if (status == PCSL_NET_SUCCESS) { if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } } else if (status == PCSL_NET_WOULDBLOCK) { REPORT_INFO1(LC_PROTOCOL, "socket::close = 0x%x blocked\n", pcslHandle); /* IMPL NOTE: unclear whether this is the right signal */ midp_thread_wait(NETWORK_READ_SIGNAL, (int)pcslHandle, context); } else { /* must be PCSL_NET_IOERROR */ midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError in socket::close = %d\n", (int)pcsl_network_error(pcslHandle)); REPORT_INFO1(LC_PROTOCOL, "%s", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); } } KNI_EndHandles(); KNI_ReturnVoid(); }
MidpProperties jad_main(char* jadbuf, int jadsize) { MidpProperties jadsmp = {0,ALL_OK,NULL}; jchar* jchar_buffer = NULL; jchar* save_jchar_buffer = NULL; int jbufsize = -1; #if REPORT_LEVEL <= LOG_INFORMATION int res = 0; #endif jbufsize = jadsize * sizeof(jchar); jchar_buffer = (jchar*)midpMalloc(jbufsize+2); if (!jchar_buffer) { midpFree(jadbuf); jadsmp.status = OUT_OF_MEMORY; return jadsmp; } memset(jchar_buffer,0,(jbufsize + 2)); convertChar2JChar(jadbuf,jchar_buffer,jadsize); midpFree(jadbuf); save_jchar_buffer = jchar_buffer; REPORT_INFO(LC_AMS, "####################### Start JAD parsing"); /* during execution of this function jadbuf pointer will be changed status will be set during midpParseJad() execution */ jadsmp = midpParseJad(jchar_buffer); midpFree(save_jchar_buffer); switch (jadsmp.status) { case OUT_OF_STORAGE: REPORT_WARN1(LC_AMS, "OUT_OF_STORAGE by JAD %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NO_JAR_URL_PROP: REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NO_SUITE_NAME_PROP: REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NO_SUITE_VENDOR_PROP: REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NO_SUITE_VERSION_PROP: REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NO_JAR_SIZE_PROP: REPORT_WARN1(LC_AMS, "Jad property missing %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case NUMBER_ERROR: REPORT_INFO1(LC_AMS, "Error during parsing JAR size written in JAD %d", jadsmp.status); midp_free_properties(&jadsmp); return jadsmp; case BAD_PARAMS: case BAD_JAD_KEY: case BAD_JAD_VALUE: REPORT_INFO1(LC_AMS, "Some NOT mandatory Jad properties is not valid %d", jadsmp.status); break; case ALL_OK: REPORT_INFO1(LC_AMS, "Jad ALL_OK %d", jadsmp.status); break; default: /* for an unknown result assuming OUT_OF_MEMORY */ REPORT_INFO1(LC_AMS, "JAD parse OUT_OF_MEMORY %d", jadsmp.status); return jadsmp; } /* end of switch */ #if REPORT_LEVEL <= LOG_INFORMATION reportToLog(LOG_INFORMATION, LC_AMS, "######################### End of JAD parsing\n" "jad_main() : number of JAD properties = %d", jadsmp.numberOfProperties); for (res = 0; res < jadsmp.numberOfProperties*2; res+=2 ) { printPcslStringWithMessage(" ", &jadsmp.pStringArr[res]); printPcslStringWithMessage(" ", &jadsmp.pStringArr[res+1]); } #endif return jadsmp; } /* end of jad_main */
static MidpProperties midpParseJad(jchar* jchar_buffer) { MidpProperties jadsmp = {0, ALL_OK, NULL}; pcsl_string jadkey; pcsl_string jadkey_trimmed; pcsl_string jadvalue; pcsl_string jadvalue_trimmed; pcsl_string jadline; MIDPError err; pcsl_string_status rc; int countLines = 0; jint index = 0; int count = 0; if (!jchar_buffer) { jadsmp.status = BAD_PARAMS; return jadsmp; } countLines = count_jad_lines(jchar_buffer); if (countLines <= 0) { REPORT_INFO(LC_AMS, "midpParseJad(): Empty jad file."); jadsmp.status = OUT_OF_MEMORY; return jadsmp; } jadsmp.pStringArr = alloc_pcsl_string_list(countLines * 2); if (jadsmp.pStringArr == NULL) { jadsmp.status = OUT_OF_MEMORY; return jadsmp; } jadsmp.numberOfProperties = countLines; for (count = 0; count < countLines * 2 ; /* count increased at the end of for */ ) { /* memory for the line is allocated here */ err = readJadLine(&jchar_buffer, &jadline); if (OUT_OF_MEMORY == err) { midp_free_properties(&jadsmp); jadsmp.status = OUT_OF_MEMORY; return jadsmp; } else if (END_OF_JAD == err) { /* we are done */ jadsmp.status = ALL_OK; break; } index = pcsl_string_index_of(&jadline, ':'); if (index <= 0) { jadsmp.status = BAD_JAD_KEY; pcsl_string_free(&jadline); continue; } /* memory for key is allocated here */ if (PCSL_STRING_OK != pcsl_string_substring(&jadline, 0, index, &jadkey)) { midp_free_properties(&jadsmp); jadsmp.status = OUT_OF_MEMORY; pcsl_string_free(&jadline); return jadsmp; } rc = pcsl_string_trim(&jadkey, &jadkey_trimmed); pcsl_string_free(&jadkey); if (PCSL_STRING_OK != rc) { jadsmp.status = OUT_OF_MEMORY; midp_free_properties(&jadsmp); pcsl_string_free(&jadline); return jadsmp; } if (pcsl_string_length(&jadkey_trimmed) < 1) { jadsmp.status = BAD_PARAMS; pcsl_string_free(&jadline); pcsl_string_free(&jadkey_trimmed); continue; } err = checkJadKeyChars(&jadkey_trimmed); if (OUT_OF_MEMORY == err) { jadsmp.status = OUT_OF_MEMORY; midp_free_properties(&jadsmp); pcsl_string_free(&jadline); pcsl_string_free(&jadkey_trimmed); return jadsmp; } else if (BAD_JAD_KEY == err) { jadsmp.status = BAD_JAD_KEY; pcsl_string_free(&jadline); pcsl_string_free(&jadkey_trimmed); continue; } rc = pcsl_string_substring(&jadline, index + 1, pcsl_string_length(&jadline), &jadvalue); /* free the jadline once we have got the key and value */ pcsl_string_free(&jadline); if (PCSL_STRING_OK != rc) { jadsmp.status = OUT_OF_MEMORY; midp_free_properties(&jadsmp); pcsl_string_free(&jadkey_trimmed); return jadsmp; } /* memory for value is allocated here */ rc = pcsl_string_trim(&jadvalue, &jadvalue_trimmed); pcsl_string_free(&jadvalue); if (PCSL_STRING_OK != rc) { jadsmp.status = OUT_OF_MEMORY; midp_free_properties(&jadsmp); pcsl_string_free(&jadkey_trimmed); return jadsmp; } if (pcsl_string_is_null(&jadvalue_trimmed)) { jadsmp.status = NULL_LEN; pcsl_string_free(&jadkey_trimmed); continue; } err = checkJadValueChars(&jadvalue_trimmed); if (OUT_OF_MEMORY == err) { jadsmp.status = OUT_OF_MEMORY; midp_free_properties(&jadsmp); pcsl_string_free(&jadkey_trimmed); pcsl_string_free(&jadvalue_trimmed); return jadsmp; } else if (BAD_JAD_VALUE == err) { jadsmp.status = BAD_JAD_VALUE; pcsl_string_free(&jadkey_trimmed); pcsl_string_free(&jadvalue_trimmed); continue; } printPcslStringWithMessage("midpParseJad()", &jadkey_trimmed); printPcslStringWithMessage("midpParseJad()", &jadvalue_trimmed); /* Store key:value pair. */ jadsmp.pStringArr[count] = jadkey_trimmed; jadsmp.pStringArr[count+1] = jadvalue_trimmed; count += 2; } /* end of for */ jadsmp = verifyJadMustProperties(jadsmp); REPORT_INFO3(LC_AMS, "End jad parsing. Status=%d, count=%d, countLines=%d.", jadsmp.status, count, countLines); return jadsmp; } /* end of midpParseJad */
/* * Accepts incoming client connection request. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPNotifierImpl</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>RFCOMMConnectionImpl</code> object. * * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_jsr082_bluetooth_btspp_BTSPPNotifierImpl_accept0(void) { javacall_handle handle = JAVACALL_BT_INVALID_HANDLE; javacall_handle peer_handle = JAVACALL_BT_INVALID_HANDLE; MidpReentryData* info; int status = JAVACALL_FAIL; int processStatus = KNI_FALSE; void *context = NULL; javacall_bt_address peer_addr; jfieldID notifHandleID = NULL; jfieldID peerHandleID = NULL; jfieldID peerAddrID = NULL; jfieldID pushHandleID = NULL; KNI_StartHandles(3); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(arrayHandle); KNI_DeclareHandle(classHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", notifHandleID) GET_FIELDID(classHandle, "peerHandle", "I", peerHandleID) GET_FIELDID(classHandle, "peerAddress", "[B", peerAddrID) GET_FIELDID(classHandle, "pushHandle", "I", pushHandleID) KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle); if (handle == JAVACALL_BT_INVALID_HANDLE) { REPORT_ERROR(LC_PROTOCOL, "RFCOMM notifier was closed before btspp_notif::accept"); KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG( "RFCOMM notifier was closed")); } else { #ifndef NO_PUSH bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID); if (pushid != BT_INVALID_PUSH_HANDLE) { if (bt_push_checkout_client(pushid, &peer_handle, peer_addr, NULL, NULL) == JAVACALL_OK) { pushcheckoutaccept((int)handle); processStatus = KNI_TRUE; status = JAVACALL_OK; } } #endif if (peer_handle == JAVACALL_BT_INVALID_HANDLE) { info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ REPORT_INFO1(LC_PROTOCOL, "btspp_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_rfcomm_accept( handle, &peer_handle, &peer_addr); processStatus = KNI_TRUE; // } } else { /* Reinvocation after unblocking the thread */ if ((javacall_handle)info->descriptor != handle) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "btspp_notif::accept handles mismatched %d != %d\n", handle, info->descriptor); REPORT_CRIT(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG( "Internal error in btspp_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 { */ context = info->pResult; status = javacall_bt_rfcomm_accept( handle, &peer_handle, &peer_addr); processStatus = KNI_TRUE; // } } } } if (processStatus) { REPORT_INFO1(LC_PROTOCOL, "btspp_notif::accept server handle=%d\n", handle); if (status == JAVACALL_OK) { // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "btspp_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 KNI_SetRawArrayRegion(arrayHandle, 0, JAVACALL_BT_ADDRESS_SIZE, (jbyte*) peer_addr); REPORT_INFO(LC_PROTOCOL, "btspp_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_rfcomm_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in btspp_notif::accept (%s)\n", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); } else { char* pMsg = "Unknown error during btspp_notif::accept"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Opens a TCP connection to a server. * <p> * Java declaration: * <pre> * open([BI)V * </pre> * * @param ipBytes Byte array that represents a raw IP address * @param port TCP port at host * * @return a native handle to the network connection. */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_socket_Protocol_open0(void) { int port; void *pcslHandle = INVALID_HANDLE; int status; void* context = NULL; MidpReentryData* info; port = (int)KNI_GetParameterAsInt(2); KNI_StartHandles(2); KNI_DeclareHandle(thisObject); KNI_DeclareHandle(bufferObject); KNI_GetThisPointer(thisObject); KNI_GetParameterAsObject(1, bufferObject); info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; /** * Verify that the resource is available well within limit as per * the policy in ResourceLimiter */ if (midpCheckResourceLimit(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit exceeded for TCP client sockets"); KNI_ThrowNew(midpIOException, "Resource limit exceeded for TCP client sockets"); } else { SNI_BEGIN_RAW_POINTERS; status = pcsl_socket_open_start( (unsigned char*)JavaByteArray(bufferObject), port, &pcslHandle, &context); SNI_END_RAW_POINTERS; if (status == PCSL_NET_SUCCESS) { getMidpSocketProtocolPtr(thisObject)->handle = (jint)pcslHandle; if (midpIncResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } } else if (status == PCSL_NET_IOERROR) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError in socket::open = %d\n", (int)pcsl_network_error(pcslHandle)); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); } else if (status == PCSL_NET_CONNECTION_NOTFOUND) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "ConnectionNotFound error in socket::open :" " error = %d\n", (int)pcsl_network_error(pcslHandle)); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpConnectionNotFoundException, gKNIBuffer); } else if (status == PCSL_NET_WOULDBLOCK) { INC_NETWORK_INDICATOR; getMidpSocketProtocolPtr(thisObject)->handle = (jint)pcslHandle; if (midpIncResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } REPORT_INFO1(LC_PROTOCOL, " handle = %d\n", pcslHandle); midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)pcslHandle, context); } else { REPORT_INFO(LC_PROTOCOL, "Unknown error during socket::open"); KNI_ThrowNew(midpIOException, NULL); } } } else { /* Reinvocation after unblocking the thread */ pcslHandle = (void *) info->descriptor; context = (void *)info->status; if (getMidpSocketProtocolPtr(thisObject)->handle != (jint)pcslHandle) { REPORT_CRIT2(LC_PROTOCOL, "socket::open Handles mismatched 0x%x != 0x%x\n", pcslHandle, getMidpSocketProtocolPtr(thisObject)->handle); } status = pcsl_socket_open_finish(pcslHandle, context); if (status == PCSL_NET_SUCCESS) { DEC_NETWORK_INDICATOR; } else if (status == PCSL_NET_WOULDBLOCK) { midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)pcslHandle, context); } else { DEC_NETWORK_INDICATOR; getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "error %d in socket::open", (int)pcsl_network_error(pcslHandle)); REPORT_INFO1(LC_PROTOCOL, "%s\n", gKNIBuffer); KNI_ThrowNew(midpConnectionNotFoundException, gKNIBuffer); } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * An entry point of a thread devoted to run java */ void JavaTask(void) { midp_jc_event_union event; javacall_bool res = JAVACALL_OK; javacall_bool JavaTaskIsGoOn = JAVACALL_TRUE; long timeTowaitInMillisec = -1; int outEventLen; int main_memory_chunk_size; /* Get java heap memory size */ main_memory_chunk_size = getInternalPropertyInt("MAIN_MEMORY_CHUNK_SIZE"); if (main_memory_chunk_size == 0) { main_memory_chunk_size = -1; } /* Outer Event Loop */ while (JavaTaskIsGoOn) { if (midpInitializeMemory(main_memory_chunk_size) != 0) { REPORT_CRIT(LC_CORE,"JavaTask() >> midpInitializeMemory() Not enough memory.\n"); break; } REPORT_INFO(LC_CORE,"JavaTask() >> memory initialized.\n"); #if !ENABLE_CDC res = javacall_event_receive(timeTowaitInMillisec, (unsigned char *)&event, sizeof(midp_jc_event_union), &outEventLen); #else res = javacall_event_receive_cvm(MIDP_EVENT_QUEUE_ID, (unsigned char *)&event, sizeof(midp_jc_event_union), &outEventLen); #endif if (!JAVACALL_SUCCEEDED(res)) { REPORT_ERROR(LC_CORE,"JavaTask() >> Error javacall_event_receive()\n"); continue; } switch (event.eventType) { case MIDP_JC_EVENT_START_ARBITRARY_ARG: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_START_ARBITRARY_ARG >>\n"); javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK, NULL); JavaTaskImpl(event.data.startMidletArbitraryArgEvent.argc, event.data.startMidletArbitraryArgEvent.argv); JavaTaskIsGoOn = JAVACALL_FALSE; break; case MIDP_JC_EVENT_SET_VM_ARGS: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_SET_VM_ARGS >>\n"); midpHandleSetVmArgs(event.data.startMidletArbitraryArgEvent.argc, event.data.startMidletArbitraryArgEvent.argv); break; case MIDP_JC_EVENT_SET_HEAP_SIZE: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_SET_HEAP_SIZE >>\n"); midpHandleSetHeapSize(event.data.heap_size); break; case MIDP_JC_EVENT_LIST_MIDLETS: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_LIST_MIDLETS >>\n"); midpHandleListMIDlets(); JavaTaskIsGoOn = JAVACALL_FALSE; break; case MIDP_JC_EVENT_LIST_STORAGE_NAMES: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_LIST_STORAGE_NAMES >>\n"); midpHandleListStorageNames(); JavaTaskIsGoOn = JAVACALL_FALSE; break; case MIDP_JC_EVENT_REMOVE_MIDLET: REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_REMOVE_MIDLET >>\n"); midpHandleRemoveMIDlet(event.data.removeMidletEvent); JavaTaskIsGoOn = JAVACALL_FALSE; break; case MIDP_JC_EVENT_END: REPORT_INFO(LC_CORE,"JavaTask() >> MIDP_JC_EVENT_END\n"); JavaTaskIsGoOn = JAVACALL_FALSE; break; default: REPORT_ERROR(LC_CORE,"Unknown event.\n"); break; } /* end of switch */ midpFinalizeMemory(); } /* end of while 'JavaTaskIsGoOn' */ } /* end of JavaTask */
/* * 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); }
javacall_result bt_push_startup() { int i; char *error; pcsl_string full_name = PCSL_STRING_NULL; int storage; REPORT_INFO(LC_PUSH, "Bluetooth PushRegistry is now starting."); javacall_bt_sddb_initialize(); pcsl_string_cat(storage_get_root(INTERNAL_STORAGE_ID), &BT_PUSH_FILENAME, &full_name); if (!storage_file_exists(&full_name)) { pcsl_string_free(&full_name); return JAVACALL_OK; } storage = storage_open(&error, &full_name, OPEN_READ); pcsl_string_free(&full_name); if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Failed to open `BtPush' file: %s", error); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)&g_count, sizeof(g_count)); for (i = 0; error == NULL && i < g_count; i++) { bt_push_t *push = (bt_push_t *)pcsl_mem_malloc(sizeof(bt_push_t)); if (push == NULL) { REPORT_ERROR(LC_PUSH, "Failed to allocate memory."); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)&push->port, sizeof(push->port)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->params, sizeof(push->params)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.classes, sizeof(push->record.classes)); if (error != NULL) { pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.size, sizeof(push->record.size)); if (error != NULL) { pcsl_mem_free(push); break; } push->record.data = pcsl_mem_malloc(push->record.size); if (push->record.data == NULL) { pcsl_mem_free(push); REPORT_ERROR(LC_PUSH, "Failed to allocate memory."); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } storageRead(&error, storage, (char *)push->record.data, push->record.size); if (error != NULL) { pcsl_mem_free(push->record.data); pcsl_mem_free(push); break; } storageRead(&error, storage, (char *)&push->record.id, sizeof(push->record.id)); if (error != NULL) { pcsl_mem_free(push); break; } push->server = BT_INVALID_HANDLE; push->client = NULL; push->next = g_registry; g_registry = push; } if (error != NULL) { REPORT_ERROR1(LC_PUSH, "Error reading `BtPush' file: %s", error); storageFreeError(error); storageClose(&error, storage); storageFreeError(error); return JAVACALL_FAIL; } REPORT_INFO1(LC_PUSH, "%d record(s) read.", g_count); storageClose(&error, storage); storageFreeError(error); if (g_count > 0) { /* Attempt to enable Bluetooth radio, if it is not already on. */ javacall_bool enabled; javacall_bt_stack_initialize(); if (javacall_bt_stack_is_enabled(&enabled) == JAVACALL_OK && enabled == JAVACALL_FALSE) { javacall_bt_stack_enable(); } } return JAVACALL_OK; }
/** * Native finalizer. * Releases all native resources used by this connection. */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_finalize(void) { javacall_handle handle, peer; int status = JAVACALL_FAIL; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::finalize"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); if (handle != BT_INVALID_HANDLE) { status = javacall_bt_l2cap_close(handle); KNI_SetIntField(thisHandle, notifHandleID, (jint)BT_INVALID_HANDLE); // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_SER, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ if (status == JAVACALL_FAIL) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in bt_l2cap_notif::finalize (%s)\n", pError); REPORT_ERROR(LC_PROTOCOL, gKNIBuffer); } else if (status == JAVACALL_WOULD_BLOCK) { /* blocking during finalize is not supported */ REPORT_CRIT1(LC_PROTOCOL, "btl2cap_notif::finalize notifier blocked, handle = %d\n", handle); } } peer = (javacall_handle)KNI_GetIntField(thisHandle, peerHandleID); if (peer != BT_INVALID_HANDLE) { status = javacall_bt_l2cap_close(peer); KNI_SetIntField(thisHandle, peerHandleID, (jint)BT_INVALID_HANDLE); // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ if (status == JAVACALL_FAIL) { char* pError; javacall_bt_l2cap_get_error(peer, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in bt_l2cap_notif::finalize (%s)\n", pError); REPORT_ERROR(LC_PROTOCOL, gKNIBuffer); } else if (status == JAVACALL_WOULD_BLOCK) { /* blocking during finalize is not supported */ REPORT_CRIT1(LC_PROTOCOL, "btl2cap_notif::finalize blocked, handle = %d\n", peer); } } REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::finalize done!"); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Opens a datagram connection on the given port. * <p> * Java declaration: * <pre> * open0(I[B)V * </pre> * * @param port port to listen on, or 0 to have one selected * @param suiteId the ID of the current MIDlet suite */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_datagram_Protocol_open0(void) { int port; SuiteIdType suiteId; jboolean tryOpen = KNI_TRUE; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); port = (int)KNI_GetParameterAsInt(1); suiteId = KNI_GetParameterAsInt(2); if (getMidpDatagramProtocolPtr(thisObject)->nativeHandle != (jint)INVALID_HANDLE) { KNI_ThrowNew(midpIOException, "already open"); tryOpen = KNI_FALSE; } if (tryOpen) { int pushReturn; pushReturn = pushcheckout("datagram", port, (char*)midp_suiteid2chars(suiteId)); /* * pushcheckout() returns -1 if the handle wasn't found, -2 if it's * already in use by another suite, otherwise a valid checked-out * handle. */ if (pushReturn == -1) { /* leave tryOpen == KNI_TRUE and try again below */ } else if (pushReturn == -2) { KNI_ThrowNew(midpIOException, "already in use"); tryOpen = KNI_FALSE; } else { /* IMPL NOTE: need to do resource accounting for this case */ getMidpDatagramProtocolPtr(thisObject)->nativeHandle = (jint)pushReturn; tryOpen = KNI_FALSE; } } if (tryOpen) { if (midpCheckResourceLimit(RSC_TYPE_UDP, 1) == 0) { KNI_ThrowNew(midpIOException, "resource limit exceeded"); } else { MidpReentryData* info; int status; void *socketHandle; void *context; info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* initial invocation */ INC_NETWORK_INDICATOR; status = pcsl_datagram_open_start(port, &socketHandle, &context); } else { /* reinvocation */ socketHandle = (void *)info->descriptor; context = info->pResult; status = pcsl_datagram_open_finish(socketHandle, context); } if (status == PCSL_NET_SUCCESS) { if (midpIncResourceCount(RSC_TYPE_UDP, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Datagrams: resource limit update error"); } getMidpDatagramProtocolPtr(thisObject)->nativeHandle = (jint)socketHandle; DEC_NETWORK_INDICATOR; } else if (status == PCSL_NET_WOULDBLOCK) { midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)socketHandle, context); } else { /* status == PCSL_NET_IOERROR */ midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "error code %d", pcsl_network_error(socketHandle)); REPORT_INFO1(LC_PROTOCOL, "datagram::open0 %s", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); DEC_NETWORK_INDICATOR; } } } KNI_EndHandles(); KNI_ReturnVoid(); }