Ejemplo n.º 1
0
/**
 * 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();
}
Ejemplo n.º 2
0
/**
 * Force Bluetooth stack to listen for incoming client connections.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object.
 *
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_listen0(void) {

    bt_handle_t handle = BT_INVALID_HANDLE;

    REPORT_INFO(LC_PROTOCOL, "btspp_notif::listen");

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisHandle);
    KNI_GetThisPointer(thisHandle);
    if (KNI_GetIntField(thisHandle, pushHandleID) == BT_INVALID_PUSH_HANDLE) {
        handle = (bt_handle_t)KNI_GetIntField(thisHandle, notifHandleID);

        /* force listening */
        if (bt_rfcomm_listen(handle) == BT_RESULT_FAILURE) {
            bt_rfcomm_close(handle);
            REPORT_ERROR(LC_PROTOCOL,
                "RFCOMM notifier listen failed in btspp_notif::listen");
            KNI_ThrowNew(midpIOException,
                EXCEPTION_MSG("RFCOMM notifier listen failed"));
        } else {
            REPORT_INFO(LC_PROTOCOL, "btspp_notif::listen done!");
        }
    }
    KNI_EndHandles();
    KNI_ReturnVoid();
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
0
/**
 * Sends a native event a given Isolate.
 *
 * @param event A event to queued
 * @param isolateId ID of the target Isolate
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_events_EventQueue_sendNativeEventToIsolate(void) {
    MidpEvent event;
    jint isolateId;
    int noExceptions = 0;

    MIDP_EVENT_INITIALIZE(event);

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

    KNI_GetParameterAsObject(1, eventObj);

    isolateId = KNI_GetParameterAsInt(2);

    cacheEventFieldIDs(eventObj, classObj);    

    event.type = KNI_GetIntField(eventObj, typeFieldID);

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

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

        noExceptions = 1;
    } while (0);

    KNI_EndHandles();

    if (noExceptions) {
        StoreMIDPEventInVmThread(event, isolateId);
    } else {
        freeMIDPEventFields(event);
    }

    KNI_ReturnVoid();
}
Ejemplo n.º 5
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();
}
/**
 * Native method void finalize of
 * com.sun.midp.midletsuite.MIDletSuiteImpl.
 * <p>
 *
 * native finalizer
 *
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_midletsuite_MIDletSuiteImpl_finalize) {
    SuiteIdType suiteId;
    jboolean locked;

    KNI_StartHandles(2);
    KNI_DeclareHandle(object);
    KNI_DeclareHandle(clazz);

    KNI_GetThisPointer(object);

    KNI_GetObjectClass(object, clazz);

    locked = KNI_GetBooleanField(object,
                                 midp_get_field_id(KNIPASSARGS clazz, "locked", "Z"));

    if (locked) {
        suiteId = KNI_GetIntField(object,
                                  midp_get_field_id(KNIPASSARGS clazz, "id", "I"));
        unlock_storage(suiteId);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Ejemplo n.º 7
0
/**
 * Updates the parameters of the invocation in the native store.
 * The ID, URL, Type, arguments, and data are stored again in native.
 * The key into the native store is the TID;
 *
 * @param invoc the InvocationImpl to update the native params
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setParams0(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;
        if (KNI_TRUE != setParamsFromObj(invoc, invocObj, obj1, obj2)) {
            KNI_ThrowNew(midpOutOfMemoryError,
                 "invocStore.c: setParam0() allocation failed");
        }
    } else {
#if REPORT_LEVEL <= LOG_CRITICAL
    REPORT_CRIT(LC_NONE,
            "invocStore.c: setParam0() no entry for tid");
#endif
    }

    KNI_EndHandles();
    KNI_ReturnVoid();

}
Ejemplo n.º 8
0
/*
 * 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();
}
Ejemplo n.º 9
0
/*
 * Returns the number of bytes available to be read from the connection
 * without blocking.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>BTSPPConnectionImpl</code> object.
 *
 * @return the number of available bytes
 * @throws IOException if any I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_jsr082_bluetooth_btspp_BTSPPConnectionImpl_available0) {
    javacall_handle handle;
    int count = -1;
    char* pError;

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

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisHandle);
    KNI_GetThisPointer(thisHandle);
    handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID);

    switch (javacall_bt_rfcomm_get_available(handle, &count)) {
    case JAVACALL_OK:
        REPORT_INFO(LC_PROTOCOL, "btspp::available done!");
        break;

    case JAVACALL_FAIL:
        javacall_bt_rfcomm_get_error(handle, &pError);
        JAVAME_SNPRINTF(gBtBuffer, BT_BUFFER_SIZE,
            "IO error during btspp::::available (%s)", pError);
        REPORT_ERROR(LC_PROTOCOL, gBtBuffer);
        KNI_ThrowNew(jsropIOException, EXCEPTION_MSG(gBtBuffer));
        break;
    default: /* illegal argument */
        REPORT_ERROR(LC_PROTOCOL, "Internal error in btspp::available");
    }

    KNI_EndHandles();
    KNI_ReturnInt(count);
}
Ejemplo n.º 10
0
static void sendControlIntField(kjobject objectHandle, jfieldID fieldID) {
    int n = KNI_GetIntField(objectHandle, fieldID);
    write(controlPipe[1], &n, sizeof(int));
#ifdef CVM_DEBUG
    printf("%d ", n);
#endif
}
Ejemplo n.º 11
0
static void
getRange(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");
    *offset = KNI_GetIntField(linkMessageObj, offsetField);
    *length = KNI_GetIntField(linkMessageObj, lengthField);

    KNI_EndHandles();
}
Ejemplo n.º 12
0
/*
 * 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();
}
Ejemplo n.º 13
0
static rendezvous *
getNativePointer(jobject linkObj)
{
    rendezvous *rp;
    jfieldID nativePointerField;

    KNI_StartHandles(1);
    KNI_DeclareHandle(linkClass);

    KNI_GetObjectClass(linkObj, linkClass);
    nativePointerField = KNI_GetFieldID(linkClass, "nativePointer", "I");
    rp = (rendezvous *)KNI_GetIntField(linkObj, nativePointerField);

    KNI_EndHandles();
    return rp;
}
Ejemplo n.º 14
0
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();
}
Ejemplo n.º 15
0
/*
 * 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();
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_VOID
    KNIDECL(com_sun_j2me_location_LocationPersistentStorage_updateLandmarkImpl) {
    
    jint landmarkID;
    javacall_result res;
    javacall_landmarkstore_landmark *landmark;
    jint numAddressFields;
    
    KNI_StartHandles(3);
    KNI_DeclareHandle(landmarkObj);
    KNI_DeclareHandle(stringObj);
    GET_PARAMETER_AS_UTF16_STRING(1, storeName)
    landmarkID = KNI_GetParameterAsInt(2);
    KNI_GetParameterAsObject(3, landmarkObj);
    numAddressFields = KNI_GetIntField(landmarkObj, 
            landmarkImplFieldID.numAddressInfoFields);
    landmark = JAVAME_MALLOC(SIZE_OF_LANDMARK_INFO(numAddressFields));

    if (landmark != NULL) {
        if (fill_landmark(landmarkObj, landmark, stringObj) == KNI_TRUE) {
            res = javacall_landmarkstore_landmark_update(storeName, 
                                    (javacall_handle)landmarkID, landmark);
            switch (res) {
                case JAVACALL_OK:
                    /* Landmark updated successfully */
                    break;
                case JAVACALL_INVALID_ARGUMENT:
                    /* wrong landmark ID */
                    KNI_ThrowNew(jsropIllegalArgumentException, 
                                "Landmark does not belong to this store");
                    break;
                default:
                    /* operation Failed */
                    KNI_ThrowNew(jsropIOException, "I/O error");
                    break;
            }
        }
        JAVAME_FREE(landmark);
    }

    RELEASE_UTF16_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnVoid();
}
Ejemplo n.º 17
0
/**
 * Native finalizer.
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_comm_Protocol_finalize()
{
    int hPort;

    KNI_StartHandles(2);
    KNI_DeclareHandle(instance);
    KNI_DeclareHandle(clazz);
    KNI_GetThisPointer(instance);

    KNI_GetObjectClass(instance, clazz);
    hPort = KNI_GetIntField(instance, KNI_GetFieldID(clazz, "handle", "I"));

    if (hPort != -1) {
        REPORT_INFO1(LC_PROTOCOL, "closePort(1st) >> hPort=%d\n",hPort);
        closePort(hPort);
    }

    KNI_EndHandles();

    KNI_ReturnVoid();
}
Ejemplo n.º 18
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_VOID
    Java_com_sun_j2me_location_PlatformLocationProvider_finalize() {

    jint provider;

    KNI_StartHandles(2);
    KNI_DeclareHandle(this_obj);
    KNI_DeclareHandle(class_obj);

    KNI_GetThisPointer(this_obj);
    KNI_GetObjectClass(this_obj, class_obj);

    provider = KNI_GetIntField(this_obj, 
                    KNI_GetFieldID(class_obj, "provider", "I"));

    if (unregister_provider(provider) == KNI_TRUE) {
        jsr179_provider_close((jsr179_handle)provider);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    KNIDECL(com_sun_j2me_location_LocationPersistentStorage_addLandmarkToStoreImpl) {
    
    javacall_handle landmarkID = 0;
    javacall_result res;
    javacall_utf16_string categoryName = NULL;
    javacall_landmarkstore_landmark *landmark;
    jint numAddressFields;
    
    KNI_StartHandles(3);
    KNI_DeclareHandle(landmarkObj);
    KNI_DeclareHandle(stringObj);

    GET_PARAMETER_AS_UTF16_STRING(1, storeName)
    KNI_GetParameterAsObject(2, landmarkObj);

    /* CategoryName can be NULL -> check it and extract */
    KNI_GetParameterAsObject(3, stringObj);
    if (!KNI_IsNullHandle(stringObj)) {
        if (JAVACALL_OK != 
            jsrop_jstring_to_utf16_string(stringObj, &categoryName)) {
            categoryName = NULL;
        }
    }
    
    numAddressFields = KNI_GetIntField(landmarkObj, 
            landmarkImplFieldID.numAddressInfoFields);
    landmark = JAVAME_MALLOC(SIZE_OF_LANDMARK_INFO(numAddressFields));

    if (landmark != NULL) {
        if ( fill_landmark(landmarkObj, landmark, stringObj) == KNI_TRUE ) {
            res = javacall_landmarkstore_landmark_add_to_landmarkstore(storeName, 
                                    landmark, categoryName, &landmarkID);
            switch (res) {
                case JAVACALL_OK:
                    /* Category added successfully */
                    break;
                case JAVACALL_INVALID_ARGUMENT:
                    /* wrong category name */
                    KNI_ThrowNew(jsropIllegalArgumentException, 
                                "category name is invalid");
                    break;
                default:
                    /* operation Failed */
                    KNI_ThrowNew(jsropIOException, "I/O error");
                    break;
            }
        } else {
            KNI_ThrowNew(jsropIllegalArgumentException, 
                        "landmark name is too long");
        }
        JAVAME_FREE(landmark);
    }
    if (categoryName != NULL) {
        JAVAME_FREE(categoryName);
    }

    RELEASE_UTF16_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnInt((jint)landmarkID);
}
Ejemplo n.º 20
0
/**
 * Fills <code>JSR211_content_handler</code> structure with data from 
 * <code>ContentHandlerImpl</code> object.
 * <BR>Fields <code>ID, storageId</code> and <code>classname</code>
 * are mandatory. They must have not 0 length.
 *
 * @param o <code>ContentHandlerImpl</code> object
 * @param handler pointer on <code>JSR211_content_handler</code> structure
 * to be filled up
 * @return KNI_OK - if successfully get all fields, 
 * KNI_ERR or KNI_ENOMEM - otherwise
 */
static int fillHandlerData(jobject o, JSR211_content_handler* handler) {
    int ret;    // returned result code
    KNI_StartHandles(1);
    KNI_DeclareHandle(fldObj);   // field object

    do {
        // ID
        KNI_GetObjectField(o, chImplId, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->id))) {
            ret = KNI_ENOMEM;
            break;
        }
        // check mandatory field
        if (pcsl_string_length(&(handler->id)) <= 0) {
            ret = KNI_ERR;
            break;
        }

        // suiteId
        handler->suite_id = KNI_GetIntField(o, chImplSuiteId);

        // classname
        KNI_GetObjectField(o, chImplClassname, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->class_name))) {
            ret = KNI_ENOMEM;
            break;
        }

        // flag
        handler->flag = KNI_GetIntField(o, chImplregMethod);

        // types
        KNI_GetObjectField(o, chImplTypes, fldObj);
        handler->type_num = getStringArray(fldObj, &(handler->types));
        if (handler->type_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // suffixes        
        KNI_GetObjectField(o, chImplSuffixes, fldObj);
        handler->suff_num = getStringArray(fldObj, &(handler->suffixes));
        if (handler->suff_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // actions
        KNI_GetObjectField(o, chImplActions, fldObj);
        handler->act_num = getStringArray(fldObj, &(handler->actions));
        if (handler->act_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // action names
        if (handler->act_num > 0) {
            KNI_GetObjectField(o, chImplActionnames, fldObj);
            ret = fillActionMap(fldObj, handler);
            if (KNI_OK != ret) {
                break;
            }
        }

        // accesses
        KNI_GetObjectField(o, chImplAccesses, fldObj);
        handler->access_num = getStringArray(fldObj, &(handler->accesses));
        if (handler->access_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        ret = KNI_OK;
    } while (0);

    KNI_EndHandles();
    return ret;
}
Ejemplo n.º 21
0
/**
 * KNI function that creates native resource for the current StringItem.
 *
 * Class: javax.microedition.lcdui.StringItemLFImpl
 *
 * Java prototype:
 * private native int createNativeResource0(int ownerId,
 *	    		String label, int layout, String text, int maxSize,
 *			int constraints, String initialInputMode)
 *
 * INTERFACE (operand stack manipulation):
 *   parameters:  ownerId            id of the owner's native resource
 *                label              StringItem's label
 *                layout             StringItem's layout
 *                text               StringItem's text
 *                appearanceMode     the appearanceMode of StringItem
 *                font               font to paint text
 *   returns:     id of the created platform widget
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_StringItemLFImpl_createNativeResource0() {
    MidpError err = KNI_OK;
    MidpDisplayable  *ownerPtr;
    MidpItem *itemPtr = NULL;
    pcsl_string label, text;
    pcsl_string_status rc1 = PCSL_STRING_OK, rc2 = PCSL_STRING_OK;
    PlatformFontPtr fontPtr = NULL;
    int appearanceMode, layout;

    KNI_StartHandles(4);

    KNI_DeclareHandle(labelJString);
    KNI_DeclareHandle(textJString);
    KNI_DeclareHandle(fontJFont);
    KNI_DeclareHandle(fontHandle);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, labelJString);
    layout = KNI_GetParameterAsInt(3);
    KNI_GetParameterAsObject(4, textJString);
    appearanceMode = KNI_GetParameterAsInt(5);
    KNI_GetParameterAsObject(6, fontJFont);

    if (KNI_IsNullHandle(fontJFont) != KNI_TRUE) {
        int face, style, size;

        KNI_FindClass("javax/microedition/lcdui/Font", fontHandle);

        face  = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face",
                                "I", _f_face_cache));
        style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "style",
                                "I", _f_style_cache));
        size  = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size",
                                "I", _f_size_cache));

        err = lfpport_get_font(&fontPtr, face, style, size);
    }

    if (err == KNI_OK) {
        rc1 = midp_kjstring_to_pcsl_string(labelJString, &label);
        rc2 = midp_kjstring_to_pcsl_string(textJString, &text);
    }

    KNI_EndHandles();

    if (err != KNI_OK || PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) {
        err = KNI_ENOMEM;
        goto cleanup;
    }


    itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_STRING_ITEM_TYPE+appearanceMode);
    if (itemPtr == NULL) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    err = lfpport_stringitem_create(itemPtr, ownerPtr, &label, layout,
                                    &text, fontPtr, appearanceMode);

cleanup:
    pcsl_string_free(&text);
    pcsl_string_free(&label);

    if (err != KNI_OK) {
        MidpDeleteItem(itemPtr);
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_ReturnInt(itemPtr);
}
Ejemplo n.º 22
0
/*
 * Reads data from a packet received via Bluetooth stack.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>L2CAPConnectionImpl</code> object.
 *
 * @param buf the buffer to read to
 * @param offset he start offset in array <code>buf</code>
 *               at which the data to be written
 * @param size the maximum number of bytes to read,
 *             the rest of the packet is discarded.
 * @return total number of bytes read into the buffer or
 *             <code>0</code> if a zero length packet is received
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_jsr082_bluetooth_btl2cap_L2CAPConnectionImpl_receive0(void) {
    int length, offset;
    javacall_handle handle;
    int bytesRead = -1;
    int status = JAVACALL_FAIL;
    void* context = NULL;
    MidpReentryData* info;
    jfieldID connHandleID = NULL;

    offset = (int)KNI_GetParameterAsInt(2);
    length = (int)KNI_GetParameterAsInt(3);

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

    KNI_GetThisPointer(thisHandle);
    KNI_GetClassPointer(classHandle);
    GET_FIELDID(classHandle, "handle", "I", connHandleID)

    handle = (javacall_handle)KNI_GetIntField(thisHandle, connHandleID);
    KNI_GetParameterAsObject(1, arrayHandle);

    REPORT_INFO3(LC_PROTOCOL,
        "btl2cap::receive off=%d len=%d handle=%d\n", offset, length, handle);

    info = (MidpReentryData*)SNI_GetReentryData(NULL);

    // Need revisit: add bluetooth activity indicator
//    START_BT_INDICATOR;

    if (info == NULL) {   /* First invocation */
        if (JAVACALL_BT_INVALID_HANDLE == handle) {
            KNI_ThrowNew(midpIOException, EXCEPTION_MSG(
                "Invalid handle during btl2cap::receive"));
        } else {
            // Need revisit: add bluetooth activity indicator
//            INC_BT_INDICATOR;

            SNI_BEGIN_RAW_POINTERS;
            status = javacall_bt_l2cap_receive(handle,
                (unsigned char*)&(JavaByteArray(arrayHandle)[offset]),
                length, &bytesRead);
            SNI_END_RAW_POINTERS;
        }
    } else {  /* Reinvocation after unblocking the thread */
        if (JAVACALL_BT_INVALID_HANDLE == handle) {
            /* closed by another thread */
            KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(
                         "Interrupted IO error during btl2cap::receive"));

            // Need revisit: add bluetooth activity indicator
//            DEC_BT_INDICATOR;
        } else {
            if ((javacall_handle)info->descriptor != handle) {
                REPORT_CRIT2(LC_PROTOCOL,
                    "btl2cap::receive handles mismatched %d != %d\n",
                    handle, (javacall_handle)info->descriptor);
            }
            context = info->pResult;
            SNI_BEGIN_RAW_POINTERS;
            status = javacall_bt_l2cap_receive(handle,
                (unsigned char*)&(JavaByteArray(arrayHandle)[offset]),
                length, &bytesRead);
            SNI_END_RAW_POINTERS;
        }
    }

    REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive bytes=%d\n", bytesRead);

    if (JAVACALL_BT_INVALID_HANDLE != handle) {
        if (status == JAVACALL_OK) {
            // Need revisit: add bluetooth activity indicator
//            DEC_BT_INDICATOR;
        } else {
            char* pError;
            javacall_bt_l2cap_get_error(handle, &pError);
            REPORT_INFO1(LC_PROTOCOL, "btl2cap::receive (%s)\n", pError);

            if (status == JAVACALL_WOULD_BLOCK) {
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context);
            } else if (status == JAVACALL_INTERRUPTED) {
                char* pError;
                javacall_bt_l2cap_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                        "Interrupted IO error during btl2cap::receive (%s)",
                        pError);
                KNI_ThrowNew(midpInterruptedIOException,
                    EXCEPTION_MSG(gKNIBuffer));

                // Need revisit: add bluetooth activity indicator
//                DEC_BT_INDICATOR;
            } else {
                char* pError;
                javacall_bt_l2cap_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "Unknown error during btl2cap::receive (%s)", pError);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer));

                // Need revisit: add bluetooth activity indicator
//                DEC_BT_INDICATOR;
            }
        }
    }

    // Need revisit: add bluetooth activity indicator
//    STOP_BT_INDICATOR;

    KNI_EndHandles();
    KNI_ReturnInt((jint)bytesRead);
}
Ejemplo n.º 23
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();
}
Ejemplo n.º 24
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();
}
Ejemplo n.º 25
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);
}
Ejemplo n.º 26
0
/*
 * 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);
}
Ejemplo n.º 27
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_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();
}
Ejemplo n.º 28
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);
}
/**
 * (Internal) Fill landmark structure from the Landmark Object.
 */
static jboolean fill_landmark(jobject landmarkObj, javacall_landmarkstore_landmark *landmark, 
                                jobject stringObj) {
    /* Fill javacall_landmarkstore_landmark structure */
    /* landmark.name */
    KNI_GetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj);
    if (!KNI_IsNullHandle(stringObj) && 
        KNI_GetStringLength(stringObj)<=JAVACALL_LANDMARKSTORE_MAX_LANDMARK_NAME) {
        if (JAVACALL_OK != 
                jsrop_jstring_to_utf16(stringObj, landmark->name, JAVACALL_LANDMARKSTORE_MAX_LANDMARK_NAME)) {
            return KNI_FALSE;
        }
    } else {
        return KNI_FALSE;
    }
    /* landmark.description */
    KNI_GetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj);
    jsr179_jstring_to_utf16(stringObj, landmark->description, JAVACALL_LANDMARKSTORE_MAX_LANDMARK_DESCRIPTION);

    landmark->isValidCoordinate = KNI_GetBooleanField(landmarkObj, 
                                landmarkImplFieldID.isCoordinates);
    if (landmark->isValidCoordinate) {
        /* landmark.latitude */
        landmark->latitude = KNI_GetDoubleField(landmarkObj, 
                                    landmarkImplFieldID.latitude);
        /* landmark.longitude */
        landmark->longitude = KNI_GetDoubleField(landmarkObj, 
                                    landmarkImplFieldID.longitude);
        /* landmark.altitude */
        landmark->altitude = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.altitude);
        /* landmark.horizontalAccuracy */
        landmark->horizontalAccuracy = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.horizontalAccuracy);
        /* landmark.altitude */
        landmark->verticalAccuracy = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.verticalAccuracy);
    }

    /* AddressInfo */
    landmark->addressInfoFieldNumber = KNI_GetIntField(landmarkObj, 
            landmarkImplFieldID.numAddressInfoFields);
    if (landmark->addressInfoFieldNumber > 0) {
            jint counter = 0;
            /* AddressInfo_EXTENSION */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_EXTENSION,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_EXTENSION) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_STREET */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_STREET,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_STREET) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_POSTAL_CODE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_POSTAL_CODE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CITY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CITY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CITY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_STATE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_STATE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_STATE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTRY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTRY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTRY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTRY_CODE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTRY_CODE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_DISTRICT */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_DISTRICT,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_DISTRICT) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_NAME */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_NAME,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_FLOOR */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_FLOOR,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_ROOM */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_ROOM,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_ZONE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_ZONE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CROSSING1 */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CROSSING1,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CROSSING1) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CROSSING2 */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CROSSING2,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CROSSING2) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_URL */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_URL,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_URL) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_PHONE_NUMBER */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_PHONE_NUMBER,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER) == KNI_TRUE)) {
                counter++;
            }
    }
    return KNI_TRUE;
}
Ejemplo n.º 30
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();
}