Exemplo n.º 1
0
/*
 * Checks out (takes ownership of) an active server connection maintained
 * by push subsystem.
 *
 * @param url URL used during registration of the push entry
 * @param suiteId suite id
 * @return true if the operation succeeds, false otherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPNotifierImpl_pushCheckout(void)
{
    jboolean retval = KNI_FALSE;
    SuiteIdType suiteId;
    MidpString wsUrl;
    char *szUrl;
    bt_port_t port;
    jfieldID notifHandleID = NULL;
    jfieldID pushHandleID  = NULL;

    KNI_StartHandles(3);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(urlHandle);
    KNI_DeclareHandle(classHandle);

    KNI_GetThisPointer(thisHandle);
    KNI_GetClassPointer(classHandle);

    GET_FIELDID(classHandle, "handle", "I", notifHandleID)
    GET_FIELDID(classHandle, "pushHandle", "I", pushHandleID)

    KNI_GetParameterAsObject(1, urlHandle);
    suiteId = KNI_GetParameterAsInt(2);

    wsUrl = midpNewString(urlHandle);
    szUrl = midpJcharsToChars(wsUrl);
    if (bt_push_parse_url(szUrl, &port, NULL) == JAVACALL_OK) {
        if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) {
            KNI_ThrowNew(midpIOException, "Port already in use.");
        } else {
            javacall_handle handle;
            bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL);
            if (pushid != BT_INVALID_PUSH_HANDLE) {
                KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid);
                KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);
                retval = KNI_TRUE;
            }
        }
    }
    midpFree(szUrl);
    MIDP_FREE_STRING(wsUrl);
    KNI_EndHandles();
    KNI_ReturnBoolean(retval);
}
Exemplo n.º 2
0
/**
 * Checks out (takes ownership of) an active server connection maintained
 * by push subsystem.
 *
 * @param url URL used during registration of the push entry
 * @param suiteId suite id
 * @return true if the operation succeeds, false otherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_pushCheckout(void) {
    jboolean retval = KNI_FALSE;
    SuiteIdType suiteId;
    MidpString wsUrl;
    char *szUrl;
    bt_port_t port;

    KNI_StartHandles(2);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(urlHandle);
    KNI_GetThisPointer(thisHandle);
    KNI_GetParameterAsObject(1, urlHandle);
    suiteId = KNI_GetParameterAsInt(2);

    wsUrl = midpNewString(urlHandle);
    szUrl = midpJcharsToChars(wsUrl);

    if (bt_push_parse_url(szUrl, &port, NULL) == BT_RESULT_SUCCESS) {
        if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) {
            KNI_ThrowNew(midpIOException, "Port already in use.");
        } else {
            bt_handle_t handle;
            bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL);
            if (pushid != BT_INVALID_PUSH_HANDLE) {
                KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid);
                KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);
                retval = KNI_TRUE;
            }
        }
    }

    midpFree(szUrl);
    MIDP_FREE_STRING(wsUrl);
    KNI_EndHandles();
    KNI_ReturnBoolean(retval);
}
Exemplo n.º 3
0
/**
 * 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();
}