Beispiel #1
0
/**
 * 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();
}
Beispiel #2
0
/**
 * 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 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();
}
Beispiel #4
0
/**
 * 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);
}
Beispiel #5
0
static void
setRange(jobject linkMessageObj, int offset, int length)
{
    jfieldID offsetField;
    jfieldID lengthField;

    KNI_StartHandles(1);
    KNI_DeclareHandle(linkMessageClass);

    KNI_GetObjectClass(linkMessageObj, linkMessageClass);
    offsetField = KNI_GetFieldID(linkMessageClass, "offset", "I");
    lengthField = KNI_GetFieldID(linkMessageClass, "length", "I");
    KNI_SetIntField(linkMessageObj, offsetField, offset);
    KNI_SetIntField(linkMessageObj, lengthField, length);

    KNI_EndHandles();
}
/*
 * 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);
}
Beispiel #7
0
/**
 * 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);
}
Beispiel #8
0
/**
 * Reads a native event without blocking. Must be called from a KNI method.
 *
 * @param event The parameter is on the java stack,
 *              An empty event to be filled in if there is a queued
 *              event.
 * @param isolateId Isolate ID of the event queue
 * @return -1 for no event read or the number of events still pending after
 * this event
 */
static int readNativeEventCommon(int isolateId) {
    MidpEvent event;
    int eventsPending;

    eventsPending = getPendingMIDPEvent(&event, isolateId);
    if (eventsPending == -1) {
        return eventsPending;
    }

    KNI_StartHandles(3);
    KNI_DeclareHandle(eventObj);
    KNI_DeclareHandle(stringObj);
    KNI_DeclareHandle(classObj);

    KNI_GetParameterAsObject(1, eventObj);

    cacheEventFieldIDs(eventObj, classObj);    

    KNI_SetIntField(eventObj, typeFieldID, event.type);

    KNI_SetIntField(eventObj, intParam1FieldID, event.intParam1);
    KNI_SetIntField(eventObj, intParam2FieldID, event.intParam2);
    KNI_SetIntField(eventObj, intParam3FieldID, event.intParam3);
    KNI_SetIntField(eventObj, intParam4FieldID, event.intParam4);

    SET_STRING_EVENT_FIELD(event.stringParam1, stringObj, eventObj,
                           stringParam1FieldID);
    SET_STRING_EVENT_FIELD(event.stringParam2, stringObj, eventObj,
                           stringParam2FieldID);
    SET_STRING_EVENT_FIELD(event.stringParam3, stringObj, eventObj,
                           stringParam3FieldID);
    SET_STRING_EVENT_FIELD(event.stringParam4, stringObj, eventObj,
                           stringParam4FieldID);
    SET_STRING_EVENT_FIELD(event.stringParam5, stringObj, eventObj,
                           stringParam5FieldID);
    SET_STRING_EVENT_FIELD(event.stringParam6, stringObj, eventObj,
                           stringParam6FieldID);

    freeMIDPEventFields(event);

    KNI_EndHandles();

    return eventsPending;
}
/*
 * Retrieves native connection handle from temporary storage
 * inside <code>RFCOMMNotifierImpl</code> instance
 * and sets it to this <code>RFCOMMConnectionImpl</code> instance.
 *
 * Note: the method sets native connection handle directly to
 * <code>handle<code> field of <code>RFCOMMConnectionImpl</code> object.
 *
 * @param notif reference to corresponding <code>RFCOMMNotifierImpl</code>
 *              instance storing native peer handle
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_setThisConnHandle0) {

    REPORT_INFO(LC_PROTOCOL, "btspp::setThisConnHandle");

    KNI_StartHandles(2);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(notifHandle);
    KNI_GetThisPointer(thisHandle);
    KNI_GetParameterAsObject(1, notifHandle);

    if (KNI_IsNullHandle(notifHandle)) {
        REPORT_ERROR(LC_PROTOCOL,
            "Notifier handle is null in btspp::setThisConnHandle");
    } else {
        jfieldID peerHandleID = GetRFCOMMPeerHandleID();

        if (peerHandleID == NULL) {
            REPORT_ERROR(LC_PROTOCOL,
                "Peer handle ID is not initialized"
                "in btspp::setThisConnHandle");
        } else {
            javacall_handle handle =
                (javacall_handle)KNI_GetIntField(notifHandle, peerHandleID);

            if (handle != JAVACALL_BT_INVALID_HANDLE) {
                /* store native connection handle to Java */
                KNI_SetIntField(thisHandle, connHandleID, (jint)handle);

                /* reset temporary storing field */
                KNI_SetIntField(notifHandle,
                    peerHandleID, (jint)JAVACALL_BT_INVALID_HANDLE);

                REPORT_INFO(LC_PROTOCOL, "btspp::setThisConnHandle done!");
            } else {
                REPORT_ERROR(LC_PROTOCOL,
                    "Peer handle is invalid in btspp::setThisConnHandle");
            }
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #10
0
static void
setNativePointer(jobject linkObj, rendezvous *rp)
{
    jfieldID nativePointerField;

    KNI_StartHandles(1);
    KNI_DeclareHandle(linkClass);

    KNI_GetObjectClass(linkObj, linkClass);
    nativePointerField = KNI_GetFieldID(linkClass, "nativePointer", "I");
    KNI_SetIntField(linkObj, nativePointerField, (jint)rp);

    KNI_EndHandles();
}
Beispiel #11
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);
}
/*
 * Native finalizer.
 * Releases all native resources used by this connection.
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_finalize) {
    javacall_handle handle;
    int status = JAVACALL_FAIL;

    REPORT_INFO(LC_PROTOCOL, "btspp::finalize");

    KNI_StartHandles(2);
    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);

    if (handle != JAVACALL_BT_INVALID_HANDLE) {
        status = javacall_bt_rfcomm_close(handle);

        KNI_SetIntField(thisHandle, connHandleID, (jint)JAVACALL_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_rfcomm_get_error(handle, &pError);
            JAVAME_SNPRINTF(gBtBuffer, BT_BUFFER_SIZE,
                "IO error in btspp::finalize (%s)\n", pError);
            REPORT_ERROR(LC_PROTOCOL, gBtBuffer);
        } else if (status == JAVACALL_WOULD_BLOCK) {
            /* blocking during finalize is not supported */
            REPORT_ERROR1(LC_PROTOCOL,
                "btspp::finalize blocked, handle= %d\n", handle);
        }
    }
    // Need revisit: add bluetooth activity indicator
/*    FINISH_BT_INDICATOR; */


    REPORT_INFO(LC_PROTOCOL, "btspp::finalize done!");

    KNI_EndHandles();
    KNI_ReturnVoid();
}
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(KNITest_testGetSetIntField) {
    jint x = KNI_GetParameterAsInt(1);
    jint y;
    jfieldID typeFieldID;
    KNI_StartHandles(2);
    KNI_DeclareHandle(this);
    KNI_DeclareHandle(clazz);
    KNI_GetThisPointer(this);
    KNI_GetObjectClass(this, clazz);
    typeFieldID = KNI_GetFieldID(clazz, "i", "I");
    y = KNI_GetIntField(this, typeFieldID);
    KNI_SetIntField(this, typeFieldID, x*y);
    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #14
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_jsr82emul_EmulationPolling_getRequest() {
    static jfieldID bufID = 0;
    static jfieldID lengthID = 0;
    int len = emul_data.req_offset > 512? 512 : emul_data.req_offset;
    
    KNI_StartHandles(3);
    KNI_DeclareHandle(thisHandle);     
    KNI_DeclareHandle(classHandle);     
    KNI_DeclareHandle(bufHandle);     
    
    if (bufID == 0) {
        KNI_GetClassPointer(classHandle);
        bufID = KNI_GetFieldID(classHandle, "requestBuf", "[B");
        lengthID = KNI_GetFieldID(classHandle, "length", "I");
    }
    
    KNI_GetThisPointer(thisHandle);
    KNI_SetIntField(thisHandle, lengthID, (jint)len);
    
    if (emul_data.req_offset > 0) {
        LOG1("EmulationPolling_getRequest(): getting %d request bytes", 
            emul_data.req_offset);
        
        KNI_GetObjectField(thisHandle, bufID, bufHandle);          
        memcpy(JavaByteArray(bufHandle), emul_data.request, len);
        if (len < emul_data.req_offset) {
            emul_data.req_offset -= len;
            memmove(emul_data.request, &emul_data.request[len], 
                emul_data.req_offset);
        } else {
            emul_data.req_offset = 0;
        }
    }
    
    KNI_EndHandles();
    KNI_ReturnVoid();
}
/*
 * 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();
}
Beispiel #16
0
static void readControlIntField(kjobject objectHandle, jfieldID fieldID) {
    int n;
    read(controlPipe[0], &n, sizeof(int));
    KNI_SetIntField(objectHandle, fieldID, n);
}
/*
 * 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();
}
Beispiel #18
0
/**
 * Implementation of native method to queue a new Invocation.
 * The state of the InvocationImpl is copied to the heap
 * and inserted in the head of the invocation queue.
 * An StoredInvoc struct is allocated on the native heap and 
 * the non-null strings for each field of the InvocationImpl class
 * are copied to the heap.
 * A new transaction ID is assigned to this Invocation
 * and returned in the tid field of the InvocationImpl.
 * @param invoc the InvocationImpl to store
 * @throws OutOfMemoryError if the memory allocation fails
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_put0(void) {
    StoredInvoc* invoc = NULL;

    KNI_StartHandles(4);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(classObj);
    KNI_DeclareHandle(argsObj);
    KNI_DeclareHandle(str);

    KNI_GetParameterAsObject(1, invocObj);
    init(invocObj, classObj);

    do {
        /* On any error break out of this block */
        /* Allocate a new zero'ed struct to save the values in */
        invoc = (StoredInvoc*) pcsl_mem_calloc(1, sizeof (StoredInvoc));
        if (invoc == NULL) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                                "InvocationStore_put0 no memory for [invoc]");
            break;
        }
    
        /* Assign a new transaction id and set it */
        invoc->tid = invocNextTid();
        KNI_SetIntField(invocObj, tidFid, invoc->tid);
    
        /*
         * Copy all the parameters to native
         * Includes ID, type,url, action, args, data
         */
        if (KNI_TRUE != setParamsFromObj(invoc, invocObj, str, argsObj))
            break;
    
        invoc->previousTid = KNI_GetIntField(invocObj, previousTidFid);
    
        invoc->status = KNI_GetIntField(invocObj, statusFid);
        invoc->responseRequired =
            KNI_GetBooleanField(invocObj, responseRequiredFid);
    
        invoc->suiteId = KNI_GetIntField(invocObj, suiteIdFid);
    
        KNI_GetObjectField(invocObj, classnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->classname))
            break;
    
        KNI_GetObjectField(invocObj, invokingAuthorityFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAuthority))
            break;
    
        KNI_GetObjectField(invocObj, invokingAppNameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAppName))
            break;
    
        invoc->invokingSuiteId = KNI_GetIntField(invocObj, invokingSuiteIdFid);
    
        KNI_GetObjectField(invocObj, invokingClassnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingClassname))
            break;
    
        KNI_GetObjectField(invocObj, invokingIDFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingID))
            break;
    
        KNI_GetObjectField(invocObj, usernameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->username))
            break;
    
        KNI_GetObjectField(invocObj, passwordFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->password))
            break;
    
        /* Insert the new Invocation at the end of the queue */
        if (!invocPut(invoc))
            break;
    
        unblockWaitingThreads(STATUS_OK);
    
        /* Clear to skip cleanup and throwing exception */
        invoc = NULL;
    } while (0);

    if (invoc != NULL) {
        /* An allocation error occurred; free any remaining */
        invocFree(invoc);
        KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c allocation failed");
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #19
0
/**
 * Implementation of native method to set the status of an Invocation.
 * If the status is set to a response status then the "finish"
 * behavior is performed.  If a response is required, the Invocation
 * is requeued to the invoking application. Otherwise, the Invocation
 * is discarded.
 *
 * @param invoc the InvocationImpl to update the native status
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setStatus0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    int tid;

    KNI_StartHandles(3);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(obj1);
    KNI_DeclareHandle(obj2);

    KNI_GetParameterAsObject(1, invocObj);
    init(invocObj, obj1);

    /* Find the matching entry in the queue */
    tid = KNI_GetIntField(invocObj, tidFid);
    link = invocFindTid(tid);
    if (link != NULL) {
        invoc = link->invoc;
        /* Update the status */
        invoc->status = KNI_GetIntField(invocObj, statusFid);
    
        switch (invoc->status) {
        case STATUS_OK:
        case STATUS_CANCELLED:
        case STATUS_ERROR:
        case STATUS_INITIATED:
            /* 
             * If a response is required, switch the target
             * application; if not then discard the Invocation.
             */
            if (invoc->responseRequired) {
                /* Swap the source and target suite and classname */
                SuiteIdType tmpSuiteId = invoc->invokingSuiteId;
                SuiteIdType tmpSuiteId2;
                pcsl_string tmpClassname = invoc->invokingClassname;
                invoc->invokingSuiteId = invoc->suiteId;
                invoc->invokingClassname = invoc->classname;
                invoc->suiteId = tmpSuiteId;
                invoc->classname = tmpClassname;
        
                /* Unmark the response it is "new" to the target */
                invoc->cleanup = KNI_FALSE;
                invoc->notified = KNI_FALSE;
        
                /* Swap the references in the Invocation object. */
                tmpSuiteId = KNI_GetIntField(invocObj, suiteIdFid);
                tmpSuiteId2 = KNI_GetIntField(invocObj, invokingSuiteIdFid);
                KNI_SetIntField(invocObj, invokingSuiteIdFid, tmpSuiteId);
                KNI_SetIntField(invocObj, suiteIdFid, tmpSuiteId2);

                KNI_GetObjectField(invocObj, invokingClassnameFid, obj1);
                KNI_GetObjectField(invocObj, classnameFid, obj2);
                KNI_SetObjectField(invocObj, classnameFid, obj1);
                KNI_SetObjectField(invocObj, invokingClassnameFid, obj2);
        
                /* Unblock any waiting threads so they can retrieve this. */
                unblockWaitingThreads(STATUS_OK);
                break;
            }
            /* If no response; Fall into DISPOSE */
    
        case STATUS_DISPOSE:
            /*
             * Free the Invocation, clean the Tid in the Invocation
             */
            invoc->tid = 0;
            KNI_SetIntField(invocObj, tidFid, 0);
            removeEntry(link);
            invocFree(invoc);
            break;
        case STATUS_ACTIVE:
        case STATUS_HOLD:
        case STATUS_WAITING:
            /* No Action. */
            break;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #20
0
/**
 * 
 * Gets an InvocationImpl from the store using a MIDlet suiteId
 * and optional classname.
 * Getting an Invocation from the store removes it from the store.
 * If an OutOfMemory exception is thrown the matched Invocation
 * is NOT removed from the queue. If the heap memory can be
 * replenished then the operation can be retried.
 *
 * @param invoc an Invocation Object to fill in
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE},
 *    or {@link #MODE_CLEANUP}
 * @param blocking true to block until a matching invocation is available
 * @return 1 if a matching invocation was found and returned 
 *    in its entirety; zero if there was no matching invocation;
 *    -1 if the sizes of the arguments or parameter array were wrong
 * @see StoredInvoc
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_content_InvocationStore_get0(void) {
    int ret = 0;          /* return value = nothing matched */
    KNI_StartHandles(4);
    KNI_DeclareHandle(obj);      /* multipurpose handle */
    KNI_DeclareHandle(argsObj);      /* handle for argument array */
    KNI_DeclareHandle(invocObj);  /* Arg1: Invocation object; non-null */
    KNI_DeclareHandle(classname); /* Arg3: non-null classname */
    int mode = MODE_REQUEST;      /* Arg4: mode for get */
    jboolean blocking = KNI_FALSE; /* Arg5: true if should block */

    /* Argument indices must match Java native method declaration */
#define getInvokeObjArg 1
#define getSuiteIdArg 2
#define getClassnameArg 3
#define getModeArg 4
#define getBlockingArg 5

    StoredLink* match = NULL;

    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    do {/* Block to break out of on exceptions */
        /* Check if blocked invocation was cancelled. */
        if (isThreadCancelled()) {
            /* blocking is always false to cleanup and exit immediately */
            break;
        }
    
        /* Get the desired blocking mode. */
        blocking = KNI_GetParameterAsBoolean(getBlockingArg);
    
        if (!isEmpty()) {
            /* Queue is not empty, get InvocationImpl obj and init. */
            KNI_GetParameterAsObject(getInvokeObjArg, invocObj);
            init(invocObj, obj);
    
            /* Get the desired type of invocation. */
            mode = KNI_GetParameterAsInt(getModeArg);
            if (mode == MODE_TID || 
                mode == MODE_TID_NEXT ||
                mode == MODE_TID_PREV) {
                int tid = KNI_GetIntField(invocObj, tidFid);
                if (tid != 0) {
                    match = invocFindTid(tid);
                } else {
                    /* start with the root */
                    match = invocQueue;
                }
                if (match != NULL) {
                    /* Link to the next or previous depending on the mode. */
                    if (mode == MODE_TID_NEXT) {
                        match = match->flink;
                    } else if (mode == MODE_TID_PREV) {
                        match = match->blink;
                    }
                }
            } else {
                desiredSuiteId = KNI_GetParameterAsInt(getSuiteIdArg);
                KNI_GetParameterAsObject(getClassnameArg, classname);
                if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                                        &desiredClassname)) {
                    KNI_ThrowNew(midpOutOfMemoryError, 
                       "InvocationStore_get0 no memory for [desiredClassname]");
                    break;
                }
                match = invocFind(desiredSuiteId, &desiredClassname, mode);
            }
        }
    } while (KNI_FALSE);

    /* Always free strings allocated */
    pcsl_string_free(&desiredClassname);

    if (match != NULL) {
        StoredInvoc *invoc = match->invoc;
        int st = copyOut(invoc, mode, invocObj, argsObj, obj);
        switch (st) {
        case 1:
            /* If a match was found and successfully copied;
             * do final set of actions on the Invocation selected.
             */
            switch (mode) {
            case MODE_REQUEST:
                if (invoc->status == STATUS_INIT) {
                    /* 
                     * Returning new request, change status to ACTIVE
                     * Keep this entry in the queue.
                     */
                    invoc->status = STATUS_ACTIVE;
                    KNI_SetIntField(invocObj, statusFid, invoc->status);
                }
                break;
            case MODE_RESPONSE:
                if (invoc->status >= STATUS_OK &&
                    invoc->status <= STATUS_INITIATED) {
                    /*
                     * Remove responses from the list and free.
                     */
                    removeEntry(match);
                    invocFree(invoc);
                }
                break;
            case MODE_LREQUEST:
            case MODE_LRESPONSE:
            case MODE_CLEANUP:
            case MODE_TID:
            case MODE_TID_NEXT:
            case MODE_TID_PREV:
            default:
                /* No additional action */
                break;
            }
            /* Returning an Invocation */
            ret = 1;
            break;
        case 0:
            /* Insufficient memory for strings. */
            KNI_ThrowNew(midpOutOfMemoryError, "invocStore returning strings");
            KNI_ReleaseHandle(invocObj);
            ret = 0;
            break;
        case -1:
            /* Either args array or data array is incorrect size. */
            ret = -1;
        }
    } else {
        /* No match found. */
        /* If blocking, setup to block. */
        if (blocking) {
            blockThread();
            /* Fall into the return to manage handles correctly */
        }
        ret = 0;
    }
    KNI_EndHandles();
    KNI_ReturnInt(ret);
}
Beispiel #21
0
/**
 * Copy a native Invocation to the supplied Invocation instance.
 * @param invoc the native InvocStore 
 * @param mode the mode of copyout
 * @param invocObj the Invocation object to copy to
 * @param argsObj an object to use to refer to the arguments array
 * @param obj a temporary object handle
 * @return 0 if there were problems allocating Java Strings;
 *    1 if all the copies succeeded;
 *    -1 if the Java Arrays allocated for args or data were insufficient
 */
static int copyOut(StoredInvoc *invoc, int mode, 
            jobject invocObj, jobject argsObj, jobject obj)
{
    int datalen = 0;
    int arraylen = 0;

    /* Set the required lengths for args and data arrays. */
    KNI_SetIntField(invocObj, argsLenFid, invoc->argsLen);
    KNI_SetIntField(invocObj, dataLenFid, invoc->dataLen);

    /* Check if size of argument array and data array are correct. */
    KNI_GetObjectField(invocObj, dataFid, obj);
    datalen = KNI_GetArrayLength(obj);
    if (datalen != invoc->dataLen) {
        /* Data array allocated by Java is not correct size. */
        return -1;
    }
    KNI_GetObjectField(invocObj, argumentsFid, obj);
    arraylen = KNI_GetArrayLength(obj);
    if (arraylen != invoc->argsLen) {
        /* Args array allocated by Java is not correct size. */
        return -1;
    }

    /* Copy out all the string fields. */
    if (!(storeField(&invoc->url, invocObj, urlFid, obj) &&
          storeField(&invoc->type, invocObj, typeFid, obj) &&
          storeField(&invoc->action, invocObj, actionFid, obj) &&
          storeField(&invoc->ID, invocObj, IDFid, obj) &&
          storeField(&invoc->invokingClassname, 
                 invocObj, invokingClassnameFid, obj) &&
          storeField(&invoc->invokingAuthority,
                 invocObj, invokingAuthorityFid, obj) &&
          storeField(&invoc->invokingAppName,
                 invocObj, invokingAppNameFid, obj) &&
          storeField(&invoc->invokingID,
                 invocObj, invokingIDFid, obj) &&
          storeField(&invoc->username,
                 invocObj, usernameFid, obj) &&
          storeField(&invoc->password,
                 invocObj, passwordFid, obj))) {
        /* Some String allocation failed. */
        return 0;
    }
    KNI_SetIntField(invocObj, invokingSuiteIdFid, invoc->invokingSuiteId);
    /* See if the suite and classname are needed. */
    if (mode == MODE_TID || 
        mode == MODE_TID_PREV ||
        mode == MODE_TID_NEXT) {
        if (!storeField(&invoc->classname, invocObj, classnameFid, obj)) {
            /* A string allocation failed. */
            return 0;
        }
            KNI_SetIntField(invocObj, suiteIdFid, invoc->suiteId);
    }

    /* Return the arguments if any; array length already checked. */
    if (invoc->argsLen > 0) {
        int ndx;
        pcsl_string* args;
    
        /* For each stored arg create a string and store in the array.
         * No stored arg is null.  If a string cannot be created
         * it is due to insufficient heap memory. 
         */
        KNI_GetObjectField(invocObj, argumentsFid, argsObj);
        args = invoc->args;
        for (ndx = 0; ndx < invoc->argsLen; ndx++, args++) {
            if (!pcsl_string_is_null(args)) {
                if (PCSL_STRING_OK != 
                        midp_jstring_from_pcsl_string(args, obj)) {
                    /* String create failed; exit now. */
                    return 0;
                }
            } else {
                KNI_ReleaseHandle(obj);
            }
            KNI_SetObjectArrayElement(argsObj, ndx, obj);
        }
    }

    /* Return the data array if any; array length was already checked. */
    if (invoc->dataLen > 0) {
        KNI_GetObjectField(invocObj, dataFid, obj);
        KNI_SetRawArrayRegion(obj, 0, invoc->dataLen, invoc->data);
    }

    KNI_SetBooleanField(invocObj, responseRequiredFid,
            invoc->responseRequired);
    KNI_SetIntField(invocObj, statusFid, invoc->status);
    KNI_SetIntField(invocObj, tidFid, invoc->tid);
    KNI_SetIntField(invocObj, previousTidFid, invoc->previousTid);
    /* Successful copy out. */
    return 1;
}
static jboolean getLocation(jobject locationInfo, jobject string_obj, ProviderInfo *pInfo) {
    jint i;
    jfieldID fid;
    jboolean ret = KNI_FALSE;

    if(pInfo != NULL) {
		if (pInfo->lastLocationTimestamp != 0) {
			/* Get location parameters */
			KNI_SetBooleanField(locationInfo,   
				locationInfoFieldID.isValid,    
				pInfo->lastLocation.isValidCoordinate);
			KNI_SetDoubleField(locationInfo,    
				locationInfoFieldID.latitude,   
				pInfo->lastLocation.latitude);
			KNI_SetDoubleField(locationInfo,    
				locationInfoFieldID.longitude,  
				pInfo->lastLocation.longitude);
			KNI_SetFloatField(locationInfo,     
				locationInfoFieldID.altitude,   
				pInfo->lastLocation.altitude);
			KNI_SetFloatField(locationInfo,     
				locationInfoFieldID.horizontalAccuracy, 
				pInfo->lastLocation.horizontalAccuracy);
			KNI_SetFloatField(locationInfo,     
				locationInfoFieldID.verticalAccuracy, 
				pInfo->lastLocation.verticalAccuracy);
			KNI_SetFloatField(locationInfo,     
				locationInfoFieldID.speed,      
				pInfo->lastLocation.speed);
			KNI_SetFloatField(locationInfo,     
				locationInfoFieldID.course,     
				pInfo->lastLocation.course);
			KNI_SetIntField(locationInfo,       
				locationInfoFieldID.method,     
				pInfo->lastLocation.method);
			KNI_SetLongField(locationInfo,      
				locationInfoFieldID.timestamp,  
				pInfo->lastLocationTimestamp);
			if (pInfo->lastLocation.addressInfoFieldNumber == 0) {
				KNI_SetBooleanField(locationInfo,   
					locationInfoFieldID.isAddressInfo, KNI_FALSE);
			} else {
				KNI_SetBooleanField(locationInfo,   
					locationInfoFieldID.isAddressInfo, KNI_TRUE);
			
				for(i=0; i<pInfo->lastLocation.addressInfoFieldNumber; i++) {
			        midp_jstring_from_pcsl_string(&pInfo->lastAddressInfo[i].data, string_obj);

					switch(pInfo->lastAddressInfo[i].fieldId) {
						case JSR179_ADDRESSINFO_EXTENSION:
							fid = locationInfoFieldID.
									AddressInfo_EXTENSION;
							break;
						case JSR179_ADDRESSINFO_STREET:
							fid = locationInfoFieldID.
									AddressInfo_STREET;
							break;
						case JSR179_ADDRESSINFO_POSTAL_CODE:
							fid = locationInfoFieldID.
									AddressInfo_POSTAL_CODE;
							break;
						case JSR179_ADDRESSINFO_CITY:
							fid = locationInfoFieldID.
									AddressInfo_CITY;
							break;
						case JSR179_ADDRESSINFO_COUNTY:
							fid = locationInfoFieldID.
									AddressInfo_COUNTY;
							break;
						case JSR179_ADDRESSINFO_STATE:
							fid = locationInfoFieldID.
									AddressInfo_STATE;
							break;
						case JSR179_ADDRESSINFO_COUNTRY:
							fid = locationInfoFieldID.
									AddressInfo_COUNTRY;
							break;
						case JSR179_ADDRESSINFO_COUNTRY_CODE:
							fid = locationInfoFieldID.
									AddressInfo_COUNTRY_CODE;
							break;
						case JSR179_ADDRESSINFO_DISTRICT:
							fid = locationInfoFieldID.
									AddressInfo_DISTRICT;
							break;
						case JSR179_ADDRESSINFO_BUILDING_NAME:
							fid = locationInfoFieldID.
									AddressInfo_BUILDING_NAME;
							break;
						case JSR179_ADDRESSINFO_BUILDING_FLOOR:
							fid = locationInfoFieldID.
									AddressInfo_BUILDING_FLOOR;
							break;
						case JSR179_ADDRESSINFO_BUILDING_ROOM:
							fid = locationInfoFieldID.
									AddressInfo_BUILDING_ROOM;
							break;
						case JSR179_ADDRESSINFO_BUILDING_ZONE:
							fid = locationInfoFieldID.
									AddressInfo_BUILDING_ZONE;
							break;
						case JSR179_ADDRESSINFO_CROSSING1:
							fid = locationInfoFieldID.
									AddressInfo_CROSSING1;
							break;
						case JSR179_ADDRESSINFO_CROSSING2:
							fid = locationInfoFieldID.
									AddressInfo_CROSSING2;
							break;
						case JSR179_ADDRESSINFO_URL:
							fid = locationInfoFieldID.
									AddressInfo_URL;
							break;
						case JSR179_ADDRESSINFO_PHONE_NUMBER:
							fid = locationInfoFieldID.
									AddressInfo_PHONE_NUMBER;
							break;
						default:
							fid = 0;
							break;
					}
					if(fid != 0) {
						KNI_SetObjectField(locationInfo, fid, 
							string_obj);
					}
				}
			}			
			if (pInfo->lastLocation.extraInfoSize > 0) {
		        midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[0], string_obj);
				KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoNMEA, 
					string_obj);
		        midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[1], string_obj);
				KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoLIF, 
					string_obj);
		        midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[2], string_obj);
				KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoPlain, 
					string_obj);
		        midp_jstring_from_pcsl_string(&pInfo->lastExtraInfo[3], string_obj);
				KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOther, 
					string_obj);
		        midp_jstring_from_pcsl_string(&pInfo->otherExtraInfoMimeType, string_obj);
				KNI_SetObjectField(locationInfo, locationInfoFieldID.extraInfoOtherMIMEType, 
					string_obj);


			}
			ret = KNI_TRUE;
        }
    }
    return ret;
}
Beispiel #23
0
/**
 * 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);
}
Beispiel #24
0
/**
 * 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();
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    KNIDECL(com_sun_j2me_location_LocationPersistentStorage_landmarkGetNext) {
    
    jint hndl;
    jint landmarkID = 0;
    javacall_result res;
    javacall_landmarkstore_landmark *landmark;
    jfieldID fid;
    jint i;

    KNI_StartHandles(2);
    KNI_DeclareHandle(landmarkObj);
    KNI_DeclareHandle(stringObj);
    hndl = KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, landmarkObj);

    res = javacall_landmarkstore_landmarklist_next((javacall_handle)hndl, &landmarkID, &landmark);
    switch (res) {
        case JAVACALL_OK:
            if (landmark != NULL) {
                /* landmark.name */
                jsrop_jstring_from_utf16_string(KNIPASSARGS landmark->name, stringObj);
                KNI_SetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj);

                /* landmark.description */
                jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->description);
                KNI_SetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj);

                if (!landmark->isValidCoordinate)
                {
                    /* landmark.isCoordinates */
                    KNI_SetBooleanField(landmarkObj, 
                                      landmarkImplFieldID.isCoordinates, KNI_FALSE);
                } else {
                    /* landmark.latitude */
                    KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.latitude,
                                        landmark->latitude);
                    /* landmark.longitude */
                    KNI_SetDoubleField(landmarkObj, landmarkImplFieldID.longitude,
                                        landmark->longitude);
                    /* landmark.altitude */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.altitude,
                                        landmark->altitude);
                    /* landmark.horizontalAccuracy */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.horizontalAccuracy,
                                        landmark->horizontalAccuracy);
                    /* landmark.verticalAccuracy */
                    KNI_SetFloatField(landmarkObj, landmarkImplFieldID.verticalAccuracy,
                                        landmark->verticalAccuracy);
                    /* landmark.isCoordinates */
                    KNI_SetBooleanField(landmarkObj, 
                                      landmarkImplFieldID.isCoordinates, KNI_TRUE);
                }
                /* landmark.addressInfoFieldNumber */
                KNI_SetIntField(landmarkObj, 
                                landmarkImplFieldID.numAddressInfoFields,
                                landmark->addressInfoFieldNumber);
                /* landmark.isAddressInfo */
                KNI_SetBooleanField(landmarkObj, 
                                  landmarkImplFieldID.isAddressInfo, 
                 (landmark->addressInfoFieldNumber > 0) ? KNI_TRUE : KNI_FALSE);
                for (i=0; i < landmark->addressInfoFieldNumber; i++) {
                    switch (landmark->fields[i].fieldId) {
                        case JAVACALL_LOCATION_ADDRESSINFO_EXTENSION:
                            fid = landmarkImplFieldID.
                                    AddressInfo_EXTENSION;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_STREET:
                            fid = landmarkImplFieldID.
                                    AddressInfo_STREET;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_POSTAL_CODE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CITY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CITY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_STATE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_STATE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTRY;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_COUNTRY_CODE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_DISTRICT:
                            fid = landmarkImplFieldID.
                                    AddressInfo_DISTRICT;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_NAME;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_FLOOR;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_ROOM;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE:
                            fid = landmarkImplFieldID.
                                    AddressInfo_BUILDING_ZONE;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CROSSING1:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CROSSING1;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_CROSSING2:
                            fid = landmarkImplFieldID.
                                    AddressInfo_CROSSING2;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_URL:
                            fid = landmarkImplFieldID.
                                    AddressInfo_URL;
                            break;
                        case JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER:
                            fid = landmarkImplFieldID.
                                    AddressInfo_PHONE_NUMBER;
                            break;
                        default:
                            fid = 0;
                            break;
                    }
                    if (fid != 0) {
                        /* addressInfo */
                        jsr179_jstring_from_utf16(KNIPASSARGS &stringObj, landmark->fields[i].data);
                        KNI_SetObjectField(landmarkObj, fid, stringObj);
                    }
                }
            }
            break;
        default:
            /* operation Failed */
            KNI_ThrowNew(jsropIOException, "I/O error");
            break;
    }

    KNI_EndHandles();
    KNI_ReturnInt(landmarkID);    
}
Beispiel #26
0
/**
 * 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();
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_getCriteria() {

    jsr179_provider_info provider_info;
    jsr179_result res;
    jboolean ret = KNI_FALSE;

    KNI_StartHandles(3);
    /* get NULL terminated provider name */
    KNI_DeclareHandle(criteria);
    KNI_DeclareHandle(class_obj);
    
    GET_PARAMETER_AS_PCSL_STRING(1, name)

    /* call provider_open to get provider handler */
    res = jsr179_provider_getinfo(name, &provider_info);
    if (res == JSR179_STATUSCODE_OK) {
        KNI_GetParameterAsObject(2, criteria);
        KNI_GetObjectClass(criteria, class_obj);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.incurCost, 
            provider_info.incurCost);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportAltitude, 
            provider_info.canReportAltitude);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportAddressInfo, 
            provider_info.canReportAddressInfo);
        KNI_SetBooleanField(criteria, 
            locationProviderInfoFieldID.canReportSpeedCource, 
            provider_info.canReportSpeedCource);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.powerConsumption, 
            provider_info.powerConsumption);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.horizontalAccuracy, 
            provider_info.horizontalAccuracy);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.verticalAccuracy, 
            provider_info.verticalAccuracy);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultTimeout, 
            provider_info.defaultTimeout);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultMaxAge, 
            provider_info.defaultMaxAge);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultInterval, 
            provider_info.defaultInterval);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.averageResponseTime, 
            provider_info.averageResponseTime);
        KNI_SetIntField(criteria, 
            locationProviderInfoFieldID.defaultStateInterval, 
            provider_info.defaultStateInterval);

        ret = KNI_TRUE;
    } else if (res == JSR179_STATUSCODE_INVALID_ARGUMENT) {
        /* wrong provider name */
        KNI_ThrowNew(midpIllegalArgumentException, "wrong provider name");
    }

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
/*
 * 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);
}