/** * 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(); }
/** * 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(); }
static javacall_result close_handle(bt_protocol_t protocol, javacall_handle handle) { javacall_result result = JAVACALL_FAIL; if (handle == BT_INVALID_HANDLE) { return JAVACALL_OK; } switch (protocol) { case BT_L2CAP: result = javacall_bt_l2cap_close(handle); break; case BT_SPP: case BT_GOEP: result = javacall_bt_rfcomm_close(handle); break; default: break; } return result; }
/** * Closes the connection. * * Determines whether the connection is not closed, if so closes it. * * @param handle connection handle * @retval JAVACALL_OK on success, * @retval JAVACALL_FAIL if connection is already closed or * an error occured during close operation */ javacall_result javacall_bt_rfcomm_close(javacall_handle handle) { return javacall_bt_l2cap_close(handle); }
/** * 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(); }