/** * Closes this server connection. * Releases all native resources (such as sockets) owned by this notifier. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object. * * @throws IOException IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_close0(void) { javacall_handle handle, peer; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::close"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); if (handle != BT_INVALID_HANDLE) { if (javacall_bt_l2cap_close(handle) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "Notifier handle closing failed in btl2cap_notif::close"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("L2CAP notifier closing failed")); } else { // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_SER, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, notifHandleID, (jint)BT_INVALID_HANDLE); } peer = (javacall_handle)KNI_GetIntField(thisHandle, peerHandleID); if (peer != BT_INVALID_HANDLE) { if (javacall_bt_l2cap_close(peer) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "Peer handle closing failed in btl2cap_notif::close"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("L2CAP notifier closing failed")); } else { // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, peerHandleID, (jint)BT_INVALID_HANDLE); } REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::close done!"); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Closes this server connection. * Releases all native resources (such as sockets) owned by this notifier. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object. * * @throws IOException IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_close0(void) { bt_handle_t handle, peer; REPORT_INFO(LC_PROTOCOL, "btspp_notif::close0"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (bt_handle_t)KNI_GetIntField(thisHandle, notifHandleID); if (handle != BT_INVALID_HANDLE) { if (bt_rfcomm_close(handle) == BT_RESULT_FAILURE) { REPORT_ERROR(LC_PROTOCOL, "Notifier handle closing failed in btspp_notif::close"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("RFCOMM notifier closing failed")); } else { // IMPL_NOTE: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_SER, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, notifHandleID, (jint)BT_INVALID_HANDLE); } peer = (bt_handle_t)KNI_GetIntField(thisHandle, peerHandleID); if (peer != BT_INVALID_HANDLE) { if (bt_rfcomm_close(peer) == BT_RESULT_FAILURE) { REPORT_ERROR(LC_PROTOCOL, "Peer handle closing failed in btspp_notif::close"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("RFCOMM notifier closing failed")); } else { // IMPL_NOTE: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, peerHandleID, (jint)BT_INVALID_HANDLE); } REPORT_INFO(LC_PROTOCOL, "btspp_notif::close0 done!"); KNI_EndHandles(); KNI_ReturnVoid(); }
/* * Returns the number of bytes available to be read from the connection * without blocking. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPConnectionImpl</code> object. * * @return the number of available bytes * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_available0) { javacall_handle handle; int count = -1; char* pError; REPORT_INFO(LC_PROTOCOL, "btspp::available"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); switch (javacall_bt_rfcomm_get_available(handle, &count)) { case JAVACALL_OK: REPORT_INFO(LC_PROTOCOL, "btspp::available done!"); break; case JAVACALL_FAIL: javacall_bt_rfcomm_get_error(handle, &pError); JAVAME_SNPRINTF(gBtBuffer, BT_BUFFER_SIZE, "IO error during btspp::::available (%s)", pError); REPORT_ERROR(LC_PROTOCOL, gBtBuffer); KNI_ThrowNew(jsropIOException, EXCEPTION_MSG(gBtBuffer)); break; default: /* illegal argument */ REPORT_ERROR(LC_PROTOCOL, "Internal error in btspp::available"); } KNI_EndHandles(); KNI_ReturnInt(count); }
/* * Closes client connection. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object. * * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_close0) { javacall_handle handle; REPORT_INFO(LC_PROTOCOL, "btspp::close"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); if (handle != JAVACALL_BT_INVALID_HANDLE) { if (javacall_bt_rfcomm_close(handle) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "RFCOMM connection closing failed in btspp::close"); KNI_ThrowNew(jsropIOException, EXCEPTION_MSG("RFCOMM connection closing failed")); } else { // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } KNI_SetIntField(thisHandle, connHandleID, (jint)JAVACALL_BT_INVALID_HANDLE); } REPORT_INFO(LC_PROTOCOL, "btspp::close done!"); KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Force Bluetooth stack to listen for incoming client connections. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object. * * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_listen0(void) { javacall_handle handle = BT_INVALID_HANDLE; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::listen"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); if (KNI_GetIntField(thisHandle, pushHandleID) == BT_INVALID_PUSH_HANDLE) { handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID); /* force listening */ if (javacall_bt_l2cap_listen(handle) == JAVACALL_FAIL) { javacall_bt_l2cap_close(handle); REPORT_ERROR(LC_PROTOCOL, "L2CAP notifier listen failed in btl2cap_notif::listen"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("L2CAP notifier listen failed")); } else { REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::listen done!"); } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Force Bluetooth stack to listen for incoming client connections. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object. * * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_listen0(void) { bt_handle_t handle = BT_INVALID_HANDLE; REPORT_INFO(LC_PROTOCOL, "btspp_notif::listen"); KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); if (KNI_GetIntField(thisHandle, pushHandleID) == BT_INVALID_PUSH_HANDLE) { handle = (bt_handle_t)KNI_GetIntField(thisHandle, notifHandleID); /* force listening */ if (bt_rfcomm_listen(handle) == BT_RESULT_FAILURE) { bt_rfcomm_close(handle); REPORT_ERROR(LC_PROTOCOL, "RFCOMM notifier listen failed in btspp_notif::listen"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("RFCOMM notifier listen failed")); } else { REPORT_INFO(LC_PROTOCOL, "btspp_notif::listen done!"); } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Creates a server connection object. * * Note: the method sets native connection handle directly to * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object. * * @param imtu receive MTU or <code>-1</code> if not specified * @param omtu transmit MTU or <code>-1</code> if not specified * @param auth <code>true</code> if authication is required * @param authz <code>true</code> if authorization 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 * @return reserved PSM to listen for incoming connections on * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_create0(void) { int imtu = (int)KNI_GetParameterAsInt(1); int omtu = (int)KNI_GetParameterAsInt(2); javacall_bool auth = (KNI_GetParameterAsBoolean(3) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_bool authz = (KNI_GetParameterAsBoolean(4) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_bool enc = (KNI_GetParameterAsBoolean(5) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_bool master = (KNI_GetParameterAsBoolean(6) == KNI_TRUE) ? JAVACALL_TRUE : JAVACALL_FALSE; javacall_handle handle = BT_INVALID_HANDLE; int psm = BT_L2CAP_INVALID_PSM; REPORT_INFO(LC_PROTOCOL, "btl2cap_notif::create"); // Need revisit: add resource counting /* if (midpCheckResourceLimit(RSC_TYPE_BT_SER, 1) == 0) { const char* pMsg = "Resource limit exceeded for BT server sockets"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } else { */ /* create L2CAP server connection */ if (javacall_bt_l2cap_create_server(imtu, omtu, auth, authz, enc, master, &handle, &psm) == JAVACALL_FAIL) { REPORT_ERROR(LC_PROTOCOL, "L2CAP notifier creation failed in btl2cap_notif::create"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("Can not create L2CAP notifier ")); KNI_ReturnInt(BT_L2CAP_INVALID_PSM); } KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); /* store native connection handle to Java object */ KNI_SetIntField(thisHandle, notifHandleID, (jint)handle); // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_SER, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "BT Server: Resource limit update error"); } */ // } REPORT_INFO2(LC_PROTOCOL, "btl2cap_notif::create notifier created" ", port = %d, handle = %d\n", psm, handle); KNI_EndHandles(); KNI_ReturnInt(psm); }
/** * Creates a server connection object. * * Note: the method sets native connection handle directly to * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object. * * @param auth <code>true</code> if authication is required * @param authz <code>true</code> if authorization 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 * @return selected channel number to listen for incoming connections on * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_create0(void) { bt_bool_t auth = (KNI_GetParameterAsBoolean(1) == KNI_TRUE) ? BT_BOOL_TRUE : BT_BOOL_FALSE; bt_bool_t authz = (KNI_GetParameterAsBoolean(2) == KNI_TRUE) ? BT_BOOL_TRUE : BT_BOOL_FALSE; bt_bool_t enc = (KNI_GetParameterAsBoolean(3) == KNI_TRUE) ? BT_BOOL_TRUE : BT_BOOL_FALSE; bt_bool_t master = (KNI_GetParameterAsBoolean(4) == KNI_TRUE) ? BT_BOOL_TRUE : BT_BOOL_FALSE; bt_handle_t handle = BT_INVALID_HANDLE; int cn = BT_RFCOMM_INVALID_CN; REPORT_INFO(LC_PROTOCOL, "btspp_notif::create0"); // IMPL_NOTE: add resource counting /* if (midpCheckResourceLimit(RSC_TYPE_BT_SER, 1) == 0) { const char* pMsg = "Resource limit exceeded for BT server sockets"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } else { */ /* create RFCOMM server connection */ if (bt_rfcomm_create_server(auth, authz, enc, master, &handle, &cn) == BT_RESULT_FAILURE) { REPORT_ERROR(LC_PROTOCOL, "RFCOMM notifier creation failed in btspp_notif::create"); KNI_ThrowNew(midpIOException, EXCEPTION_MSG("Can not create RFCOMM notifier")); KNI_ReturnInt(BT_RFCOMM_INVALID_CN); } KNI_StartHandles(1); KNI_DeclareHandle(thisHandle); KNI_GetThisPointer(thisHandle); /* store native connection handle to Java object */ KNI_SetIntField(thisHandle, notifHandleID, (jint)handle); // IMPL_NOTE: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_SER, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "BT Server: Resource limit update error"); } */ // } REPORT_INFO2(LC_PROTOCOL, "btspp_notif::create notifier created" ", port = %d, handle = %d\n", cn, handle); KNI_EndHandles(); KNI_ReturnInt(cn); }
void hlsl_shader::init_domain_shader(ID3D11Device* p_device, const hlsl_shader_desc& desc) { try { p_domain_shader_bytecode = compile_shader(desc.source_code, desc.source_filename, desc.compile_flags, hlsl_shader_desc::domain_shader_entry_point, hlsl_shader_desc::domain_shader_model); HRESULT hr = p_device->CreateDomainShader( p_domain_shader_bytecode->GetBufferPointer(), p_domain_shader_bytecode->GetBufferSize(), nullptr, &p_domain_shader.ptr); ENFORCE(hr == S_OK, std::to_string(hr)); } catch (...) { const std::string exc_msg = EXCEPTION_MSG("Domain shader creation error."); std::throw_with_nested(std::runtime_error(exc_msg)); } }
/* * 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>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(); }
/** * 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); }
/* * Performs client connection establishment. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPConnectionImpl</code> object. * * @param addr bluetooth address of device to connect to * @param psm Protocol Service Multiplexor (PSM) value * @return Negotiated ReceiveMTU and TransmitMTU. * 16 high bits is ReceiveMTU, 16 low bits is TransmitMTU. * * @throws IOException if any I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPConnectionImpl_connect0(void) { unsigned char *address = NULL; int psm = (int)KNI_GetParameterAsInt(2); javacall_handle handle = JAVACALL_BT_INVALID_HANDLE; int status, i, imtu, omtu, mtus; void* context = NULL; MidpReentryData* info; javacall_bt_address addr; jfieldID connHandleID = NULL; KNI_StartHandles(3); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(arrayHandle); KNI_DeclareHandle(classHandle); KNI_GetThisPointer(thisHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", connHandleID) KNI_GetParameterAsObject(1, arrayHandle); handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); REPORT_INFO1(LC_PROTOCOL, "btl2cap::connect handle=%d", handle); /* copy address from Java input array */ SNI_BEGIN_RAW_POINTERS; address = JavaByteArray(arrayHandle); for (i = 0; i < JAVACALL_BT_ADDRESS_SIZE; i++) { addr[i] = address[i]; } SNI_END_RAW_POINTERS; info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* First invocation */ // Need revisit: add resource counting /* * Verify that the resource is available well within limit as per * the policy in ResourceLimiter */ /* if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) { const char* pMsg = "Resource limit exceeded for BT client sockets"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } else { */ status = javacall_bt_l2cap_connect(handle, address, psm, &imtu, &omtu); if (status == JAVACALL_OK) { // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ } else if (status == JAVACALL_FAIL) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IO error in btl2cap::connect (%s)\n", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); } else if (status == JAVACALL_WOULD_BLOCK) { // Need revisit: add bluetooth activity indicator // INC_BT_INDICATOR; // Need revisit: add resource counting /* if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ REPORT_INFO1(LC_PROTOCOL, "btl2cap::connect is waiting for complete notify" ", handle = %d\n", handle); midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)handle, context); } else { char* pMsg = "Unknown error during btl2cap::connect"; REPORT_INFO(LC_PROTOCOL, pMsg); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg)); } // } } else { /* Reinvocation after unblocking the thread */ context = info->pResult; if ((javacall_handle)info->descriptor != handle) { REPORT_CRIT2(LC_PROTOCOL, "btl2cap::connect handles mismatched %d != %d\n", handle, (javacall_handle)info->descriptor); } status = javacall_bt_l2cap_connect(handle, address, psm, &imtu, &omtu); if (status == JAVACALL_OK) { // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else if (status == JAVACALL_WOULD_BLOCK) { midp_thread_wait(NETWORK_WRITE_SIGNAL, (int)handle, context); } else { char* pError; KNI_SetIntField(thisHandle, connHandleID, (jint)JAVACALL_BT_INVALID_HANDLE); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; // Need revisit: add resource counting /* if (midpDecResourceCount(RSC_TYPE_BT_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } */ javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Error in btl2cap::connect (%s)", pError); REPORT_INFO(LC_PROTOCOL, gKNIBuffer); KNI_ThrowNew(midpConnectionNotFoundException, EXCEPTION_MSG(gKNIBuffer)); } } mtus = (imtu << 16) & 0xFFFF0000; mtus |= omtu & 0xFFFF; KNI_EndHandles(); KNI_ReturnInt(mtus); }
/* * Reads data from a packet received via Bluetooth stack. * * Note: the method gets native connection handle directly from * <code>handle<code> field of <code>L2CAPConnectionImpl</code> object. * * @param buf the buffer to read to * @param offset he start offset in array <code>buf</code> * at which the data to be written * @param size the maximum number of bytes to read, * the rest of the packet is discarded. * @return total number of bytes read into the buffer or * <code>0</code> if a zero length packet is received * @throws IOException if an I/O error occurs */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPConnectionImpl_receive0(void) { int length, offset; javacall_handle handle; int bytesRead = -1; int status = JAVACALL_FAIL; void* context = NULL; MidpReentryData* info; jfieldID connHandleID = NULL; offset = (int)KNI_GetParameterAsInt(2); length = (int)KNI_GetParameterAsInt(3); KNI_StartHandles(3); KNI_DeclareHandle(arrayHandle); KNI_DeclareHandle(thisHandle); KNI_DeclareHandle(classHandle); KNI_GetThisPointer(thisHandle); KNI_GetClassPointer(classHandle); GET_FIELDID(classHandle, "handle", "I", connHandleID) handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID); KNI_GetParameterAsObject(1, arrayHandle); REPORT_INFO3(LC_PROTOCOL, "btl2cap::receive off=%d len=%d handle=%d\n", offset, length, handle); info = (MidpReentryData*)SNI_GetReentryData(NULL); // Need revisit: add bluetooth activity indicator // START_BT_INDICATOR; if (info == NULL) { /* First invocation */ if (JAVACALL_BT_INVALID_HANDLE == handle) { KNI_ThrowNew(midpIOException, EXCEPTION_MSG( "Invalid handle during btl2cap::receive")); } else { // Need revisit: add bluetooth activity indicator // INC_BT_INDICATOR; SNI_BEGIN_RAW_POINTERS; status = javacall_bt_l2cap_receive(handle, (unsigned char*)&(JavaByteArray(arrayHandle)[offset]), length, &bytesRead); SNI_END_RAW_POINTERS; } } else { /* Reinvocation after unblocking the thread */ if (JAVACALL_BT_INVALID_HANDLE == handle) { /* closed by another thread */ KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG( "Interrupted IO error during btl2cap::receive")); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { if ((javacall_handle)info->descriptor != handle) { REPORT_CRIT2(LC_PROTOCOL, "btl2cap::receive handles mismatched %d != %d\n", handle, (javacall_handle)info->descriptor); } context = info->pResult; SNI_BEGIN_RAW_POINTERS; status = javacall_bt_l2cap_receive(handle, (unsigned char*)&(JavaByteArray(arrayHandle)[offset]), length, &bytesRead); SNI_END_RAW_POINTERS; } } REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive bytes=%d\n", bytesRead); if (JAVACALL_BT_INVALID_HANDLE != handle) { if (status == JAVACALL_OK) { // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { char* pError; javacall_bt_l2cap_get_error(handle, &pError); REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive (%s)\n", pError); if (status == JAVACALL_WOULD_BLOCK) { midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context); } else if (status == JAVACALL_INTERRUPTED) { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Interrupted IO error during btl2cap::receive (%s)", pError); KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(gKNIBuffer)); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } else { char* pError; javacall_bt_l2cap_get_error(handle, &pError); midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "Unknown error during btl2cap::receive (%s)", pError); KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer)); // Need revisit: add bluetooth activity indicator // DEC_BT_INDICATOR; } } } // Need revisit: add bluetooth activity indicator // STOP_BT_INDICATOR; KNI_EndHandles(); KNI_ReturnInt((jint)bytesRead); }
/** * 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(); }