コード例 #1
0
/**
 * The function blocks the calling thread if Transaction Store is locked.
 * <p>Java declaration:
 * <pre>
 * private native void lockStore();
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_j2me_payment_TransactionStorageImpl_lockStore() {
    MidpReentryData *info = NULL;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    if (locked == KNI_FALSE) {
        locked = KNI_TRUE;
        KNI_GetThisPointer(thisObject);
        getStorageOpenFlag(thisObject)->isOpen = (jboolean)KNI_TRUE;
    } else {
        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {
            info = (MidpReentryData*)
                (SNI_AllocateReentryData(sizeof (MidpReentryData)));
        }
        info->waitingFor = PAYMENT_TRANSACTION_STORE_SIGNAL;
        info->descriptor = 0;
        info->status = KNI_FALSE;
        info->pResult = NULL;

        /* try again later */
        SNI_BlockThread();
    }
    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();
}
コード例 #3
0
ファイル: btSPPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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();
}
コード例 #4
0
ファイル: socketProtocol.c プロジェクト: jiangxilong/yari
/**
 * Gets the requested port number.
 * <p>
 * Java declaration:
 * <pre>
 *     getPort(Z)I
 * </pre>
 *
 * @param local <tt>true</tt> to get the local port number, or
 *              <tt>false</tt> to get the remote port number
 *
 * @return the port number
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_socket_Protocol_getPort0(void) {
    int local;
    void *pcslHandle;
    int port = 0;
    int status = PCSL_NET_INVALID;

    local = (int)KNI_GetParameterAsInt(1);

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

    KNI_EndHandles();

    if (INVALID_HANDLE == pcslHandle) {
        KNI_ThrowNew(midpIOException, 
                     "invalid handle during socket::getPort");
    } else {
        if (local == 1) {
            status = pcsl_network_getlocalport(pcslHandle, &port);
        } else {
            status = pcsl_network_getremoteport(pcslHandle, &port);
        }

        if (status == PCSL_NET_IOERROR) {
            KNI_ThrowNew(midpIOException, NULL);
        }
    }

    KNI_ReturnInt((jint)port);
}
コード例 #5
0
/**
 * private native void init0(int sender, int receiver);
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_Link_init0(void)
{
    int sender;
    int receiver;
    rendezvous *rp;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObj);

    sender = KNI_GetParameterAsInt(1);
    receiver = KNI_GetParameterAsInt(2);
    KNI_GetThisPointer(thisObj);

    rp = rp_create(sender, receiver);
    if (rp == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        setNativePointer(thisObj, rp);
        rp_incref(rp);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #6
0
/**
 * public native void close();
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_Link_close(void)
{
    rendezvous *rp;
    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObj);

    KNI_GetThisPointer(thisObj);
    rp = getNativePointer(thisObj);

    /* ignore if closed twice */
    if (rp != NULL) {
        if (rp->sender == JVM_CurrentIsolateID()
                && rp->msg != INVALID_REFERENCE_ID) {
            /* we're the sender, make sure to clean out our message */
            SNI_DeleteReference(rp->msg);
            rp->msg = INVALID_REFERENCE_ID;
        }

        rp->state = CLOSED;
        midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0);
        setNativePointer(thisObj, NULL);
        rp_decref(rp);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #7
0
ファイル: datagramProtocol.c プロジェクト: jiangxilong/yari
/**
 * Gets the local port number of a datagram connection.
 * <p>
 * Java declaration:
 * <pre>
 *     getPort0(V)I
 * </pre>
 *
 * @return the local port number of the given datagram connection
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_datagram_Protocol_getPort0(void) {
    void *socketHandle;
    int port = -1;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    socketHandle =
        (void *)getMidpDatagramProtocolPtr(thisObject)->nativeHandle;

    if (socketHandle != INVALID_HANDLE) {
        int status;
        status = pcsl_network_getlocalport(socketHandle, &port);
        if (status != PCSL_NET_SUCCESS) {
            KNI_ThrowNew(midpIOException, NULL);
        }
    } else {
        KNI_ThrowNew(midpIOException, "socket closed");
    }

    KNI_EndHandles();
    KNI_ReturnInt((jint)port);
}
コード例 #8
0
/**
 * Releases any native resources used by this immutable <tt>ImageData</tt>.
 * <p>
 * Java declaration:
 * <pre>
 *     finalize()V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageData_finalize() {
    java_imagedata * imageDataPtr = NULL;
    gxpport_image_native_handle h;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    imageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(thisObject);

    /*
     * Image objects with NULL nativeImageData could exist when loading
     * romized image but failed.
     */
    h = (gxpport_image_native_handle)imageDataPtr->nativeImageData;
    if (h != NULL) {
        if (imageDataPtr->isMutable) {
            gxpport_destroy_mutable(h);
        } else {
            gxpport_destroy_immutable(h);
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #9
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();
}
コード例 #10
0
/**
 * Native finalizer to reset the native peer event queue when
 * the Isolate ends.
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_events_EventQueue_finalize(void) {
   jint queueId;
   EventQueue* pEventQueue;

   KNI_StartHandles(1);
   KNI_DeclareHandle(thisObject);
   KNI_GetThisPointer(thisObject);

   SNI_BEGIN_RAW_POINTERS;
   queueId = getEventQueuePtr(thisObject)->queueId;
   SNI_END_RAW_POINTERS;

   KNI_EndHandles();

   if (queueId >= 0) {
       resetEventQueue(queueId);

       /* Mark queue as inactive */
       GET_EVENT_QUEUE_BY_ID(pEventQueue, queueId);
       pEventQueue->isActive = KNI_FALSE;
   }

   KNI_ReturnVoid();
}
コード例 #11
0
ファイル: socketProtocol.c プロジェクト: jiangxilong/yari
/**
 * Sets the requested socket option.
 * <p>
 * Java declaration:
 * <pre>
 *     setSockOpt(II)V
 * </pre>
 *
 * @param option socket option to set
 * @param value the value to set <tt>option</tt> to
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_socket_Protocol_setSockOpt0(void) {
    int option;
    int value;
    void *pcslHandle;
    int status = PCSL_NET_INVALID;
    
    value  = (int)KNI_GetParameterAsInt(2);
    option = (int)KNI_GetParameterAsInt(1);

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle);

    KNI_EndHandles();

    if (INVALID_HANDLE == pcslHandle) {
        KNI_ThrowNew(midpIOException, 
                     "invalid handle during socket::getPort");
    } else {
        status = pcsl_network_setsockopt(pcslHandle, option, value);
        if (status == PCSL_NET_IOERROR) {
            KNI_ThrowNew(midpIllegalArgumentException, "Unsupported Socket Option");
        } else if (PCSL_NET_INVALID == status) {
            KNI_ThrowNew(midpIllegalArgumentException, "Illegal Socket Option Value");
        }
    }

    KNI_ReturnVoid();
}
コード例 #12
0
ファイル: btL2CAPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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();
}
コード例 #13
0
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(KNITest_returnThis) {
    KNI_StartHandles(1);
    KNI_DeclareHandle(this);
    KNI_GetThisPointer(this);
    KNI_EndHandlesAndReturnObject(this);
}
コード例 #14
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);
}
コード例 #15
0
ファイル: btL2CAPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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);
}
コード例 #16
0
ファイル: btSPPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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);
}
コード例 #17
0
ファイル: JAbstractSurface.c プロジェクト: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_pisces_AbstractSurface_nativeFinalize() {
    KNI_StartHandles(1);
    KNI_DeclareHandle(objectHandle);

    KNI_GetThisPointer(objectHandle);

    surface_finalize(objectHandle);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #18
0
ファイル: btSPPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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();
}
コード例 #19
0
ファイル: btL2CAPNotifierGlue.c プロジェクト: sfsy1989/j2me
/**
 * 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();
}
コード例 #20
0
/**
 * Receives an SMS message.
 *
 * @param port The port number to be matched against incoming SMS messages.
 * @param handle The handle to the open SMS message connection.
 * @param messageObject The Java message object to be populated.
 *
 * @return The length of the SMS message (in bytes).
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_midp_io_j2me_sms_Protocol_receive0) {
#if ENABLE_REENTRY
    MidpReentryData *info = (MidpReentryData*)SNI_GetReentryData(NULL);
#endif
    int port, handle;
    int messageLength = -1;
    SmsMessage *psmsData = NULL;
    /* The midlet suite name for this connection. */
    AppIdType msid = UNUSED_APP_ID;
    jboolean isOpen;

    KNI_StartHandles(6);

    KNI_DeclareHandle(this);
    KNI_DeclareHandle(thisClass);
    KNI_GetThisPointer(this);
    KNI_GetObjectClass(this, thisClass);
    isOpen = KNI_GetBooleanField(this, KNI_GetFieldID(thisClass, "open", "Z"));

    if (isOpen) { /* No close in progress */
        KNI_DeclareHandle(messageClazz);
        KNI_DeclareHandle(messageObject);
        KNI_DeclareHandle(addressArray);
        KNI_DeclareHandle(byteArray);

        port = KNI_GetParameterAsInt(1);
        msid = KNI_GetParameterAsInt(2);
        handle = KNI_GetParameterAsInt(3);
        KNI_GetParameterAsObject(4, messageObject);

        do {
#if ENABLE_REENTRY
            if (!info) {
#endif
                psmsData = jsr120_sms_pool_peek_next_msg((jchar)port);
                if (psmsData == NULL) {
#if ENABLE_REENTRY
                    /* block and wait for a message. */
                    midp_thread_wait(WMA_SMS_READ_SIGNAL, handle, NULL);
#else
        do {
            CVMD_gcSafeExec(_ee, {
                jsr120_wait_for_signal(handle, WMA_SMS_READ_SIGNAL);
            });
            psmsData = jsr120_sms_pool_peek_next_msg((jchar)port);
            isOpen = KNI_GetBooleanField(this, KNI_GetFieldID(thisClass, "open", "Z"));
        } while (psmsData == NULL && isOpen);
#endif
                }
#if ENABLE_REENTRY
            } else {
コード例 #21
0
ファイル: gxapi_image_kni.c プロジェクト: sfsy1989/j2me
/**
 * Draws the specified image by using the anchor point.
 * The image can be drawn in different positions relative to
 * the anchor point by passing the appropriate position constants.
 * See <a href="#anchor">anchor points</a>.
 *
 * <p>If the source image contains transparent pixels, the corresponding
 * pixels in the destination image must be left untouched.  If the source
 * image contains partially transparent pixels, a compositing operation
 * must be performed with the destination pixels, leaving all pixels of
 * the destination image fully opaque.</p>
 *
 * <p>If <code>img</code> is the same as the destination of this Graphics
 * object, the result is undefined.  For copying areas within an
 * <code>Image</code>, {@link #copyArea copyArea} should be used instead.
 * </p>
 *
 * @param g the specified Graphics to be drawn
 * @param x the x coordinate of the anchor point
 * @param y the y coordinate of the anchor point
 * @param anchor the anchor point for positioning the image
 * @throws IllegalArgumentException if <code>anchor</code>
 * is not a legal value
 * @throws NullPointerException if <code>g</code> is <code>null</code>
 * @see Image
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(javax_microedition_lcdui_Image_render) {
    jboolean success = KNI_TRUE;

    int anchor = KNI_GetParameterAsInt(4);
    int y      = KNI_GetParameterAsInt(3);
    int x      = KNI_GetParameterAsInt(2);

    KNI_StartHandles(3);
    KNI_DeclareHandle(img);
    KNI_DeclareHandle(g);
    KNI_DeclareHandle(gImg);

    KNI_GetParameterAsObject(1, g);
    KNI_GetThisPointer(img);

    if (GRAPHICS_OP_IS_ALLOWED(g)) {
        /* null checking is handled by the Java layer, but test just in case */
        if (KNI_IsNullHandle(img)) {
            success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL);
        } else {
  	    const java_imagedata * srcImageDataPtr =
	      GET_IMAGE_PTR(img)->imageData;

            GET_IMAGE_PTR(gImg) =
	      (struct Java_javax_microedition_lcdui_Image *)
	      (GXAPI_GET_GRAPHICS_PTR(g)->img);
            if (KNI_IsSameObject(gImg, img) || !gxutl_check_anchor(anchor,0)) {
                success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);
            } else if (!gxutl_normalize_anchor(&x, &y, srcImageDataPtr->width, 
					       srcImageDataPtr->height, 
					       anchor)) {
                success = KNI_FALSE;//KNI_ThrowNew(midpIllegalArgumentException, NULL);
            } else {
	        jshort clip[4]; /* Defined in Graphics.java as 4 shorts */
	        const java_imagedata * dstMutableImageDataPtr = 
		  GXAPI_GET_IMAGEDATA_PTR_FROM_GRAPHICS(g);

                GXAPI_TRANSLATE(g, x, y);
		GXAPI_GET_CLIP(g, clip);

		gx_render_image(srcImageDataPtr, dstMutableImageDataPtr,
				clip, x, y);

            }
        }
    }

    KNI_EndHandles();
    KNI_ReturnBoolean(success);
}
コード例 #22
0
/**
 * Gets an ARGB integer array from this <tt>ImmutableImage</tt>. The
 * array consists of values in the form of 0xAARRGGBB.
 * <p>
 * Java declaration:
 * <pre>
 *     getRGB([IIIIIII)V
 * </pre>
 *
 * @param rgbData The target integer array for the ARGB data
 * @param offset Zero-based index of first ARGB pixel to be saved
 * @param scanlen Number of intervening pixels between pixels in
 *                the same column but in adjacent rows
 * @param x The x coordinate of the upper left corner of the
 *          selected region
 * @param y The y coordinate of the upper left corner of the
 *          selected region
 * @param width The width of the selected region
 * @param height The height of the selected region
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(javax_microedition_lcdui_ImageData_getRGB) {
    int height = KNI_GetParameterAsInt(7);
    int width = KNI_GetParameterAsInt(6);
    int y = KNI_GetParameterAsInt(5);
    int x = KNI_GetParameterAsInt(4);
    int scanlength = KNI_GetParameterAsInt(3);
    int offset = KNI_GetParameterAsInt(2);
    int *rgbBuffer;
    java_imagedata *srcImageDataPtr;
    gxpport_mutableimage_native_handle srcImageNativeData;
    img_native_error_codes error = IMG_NATIVE_IMAGE_NO_ERROR;

    KNI_StartHandles(2);
    KNI_DeclareHandle(rgbData);
    KNI_DeclareHandle(thisObject);

    KNI_GetParameterAsObject(1, rgbData);
    KNI_GetThisPointer(thisObject);


    SNI_BEGIN_RAW_POINTERS;
    
    rgbBuffer = JavaIntArray(rgbData);

    srcImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(thisObject);
    srcImageNativeData =
      (gxpport_mutableimage_native_handle)srcImageDataPtr->nativeImageData;    

    if (srcImageDataPtr->isMutable) {
        gxpport_get_mutable_argb(srcImageNativeData,
                                 rgbBuffer, offset, scanlength,
                                 x, y, width, height, 
                                 &error);
    } else {
        gxpport_get_immutable_argb(srcImageNativeData,
                                   rgbBuffer, offset, scanlength,
                                   x, y, width, height, 
                                   &error);
    }

    SNI_END_RAW_POINTERS;
    
    if (error != IMG_NATIVE_IMAGE_NO_ERROR) {
      KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #23
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_pisces_NativeFinalizer_00024SurfaceNativeFinalizer_finalize() {
    KNI_StartHandles(2);
    KNI_DeclareHandle(objectHandle);
    KNI_DeclareHandle(guardedHandle);

    KNI_GetThisPointer(objectHandle);
    KNI_GetObjectField(objectHandle, fieldIds[FINALIZER_GUARDED_OBJ],
                       guardedHandle);

    surface_finalize(guardedHandle);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #24
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();
}
コード例 #25
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_pisces_NativeFinalizer_initialize() {
    KNI_StartHandles(1);
    KNI_DeclareHandle(objectHandle);

    KNI_GetThisPointer(objectHandle);

    if (!initializeFinalizerFieldIds(objectHandle)) {
        KNI_ThrowNew("java/lang/IllegalStateException", "");
    }

    // don't do anything here (see the throw above)!

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #26
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();
}
コード例 #27
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_khronos_egl_EGLSurfaceImpl_finalize() {
    _eglsurface_impl* surface;
    jint pixmap_pointer;

    KNI_StartHandles(1);
    KNI_DeclareHandle(thisObject);
    KNI_GetThisPointer(thisObject);

    surface = GET_EGL_SURFACE(thisObject);
    pixmap_pointer = surface->pixmapPointer;

    JSR239_destroyPixmap((JSR239_Pixmap *)pixmap_pointer);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
コード例 #28
0
ファイル: JAbstractSurface.c プロジェクト: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_pisces_AbstractSurface_drawRGBImpl() {
    KNI_StartHandles(2);
    KNI_DeclareHandle(objectHandle);
    KNI_DeclareHandle(arrayHandle);

    jint offset = KNI_GetParameterAsInt(2);
    jint scanLength = KNI_GetParameterAsInt(3);
    jint x = KNI_GetParameterAsInt(4);
    jint y = KNI_GetParameterAsInt(5);
    jint width = KNI_GetParameterAsInt(6);
    jint height = KNI_GetParameterAsInt(7);
    jfloat opacity = KNI_GetParameterAsFloat(8);

    jint srcX = 0;
    jint srcY = 0;

    Surface* surface;

    KNI_GetParameterAsObject(1, arrayHandle);

    KNI_GetThisPointer(objectHandle);
    surface = (Surface*)JLongToPointer(
                  KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR]));

    CORRECT_DIMS(surface, x, y, width, height, srcX, srcY);

    if ((width > 0) && (height > 0)) {
        jint* tempArray;
        offset += srcY * scanLength + srcX;

        SNI_BEGIN_RAW_POINTERS;

        tempArray = &JavaIntArray(arrayHandle)[offset];

        ACQUIRE_SURFACE(surface, objectHandle);
        surface_drawRGB(surface, x, y, width, height, tempArray, scanLength,
                        opacity);
        RELEASE_SURFACE(surface, objectHandle);

        SNI_END_RAW_POINTERS;
    }

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

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

    KNI_GetThisPointer(thisHandle);
    KNI_GetClassPointer(classHandle);

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

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

    wsUrl = midpNewString(urlHandle);
    szUrl = midpJcharsToChars(wsUrl);
    if (bt_push_parse_url(szUrl, &port, NULL) == JAVACALL_OK) {
        if (pushcheckout(szUrl, 0, (char*)midp_suiteid2chars(suiteId)) == -2) {
            KNI_ThrowNew(midpIOException, "Port already in use.");
        } else {
            javacall_handle handle;
            bt_pushid_t pushid = bt_push_checkout_server(&port, &handle, NULL);
            if (pushid != BT_INVALID_PUSH_HANDLE) {
                KNI_SetIntField(thisHandle, pushHandleID, (jint)pushid);
                KNI_SetIntField(thisHandle, notifHandleID, (jint)handle);
                retval = KNI_TRUE;
            }
        }
    }
    midpFree(szUrl);
    MIDP_FREE_STRING(wsUrl);
    KNI_EndHandles();
    KNI_ReturnBoolean(retval);
}
コード例 #30
0
ファイル: JAbstractSurface.c プロジェクト: sfsy1989/j2me
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_pisces_AbstractSurface_getHeight() {
    jint height;

    KNI_StartHandles(1);
    KNI_DeclareHandle(objectHandle);

    Surface* surface;

    KNI_GetThisPointer(objectHandle);
    surface = (Surface*)JLongToPointer(KNI_GetLongField(objectHandle,
                                       fieldIds[SURFACE_NATIVE_PTR]));

    height = surface->height;

    KNI_EndHandles();
    KNI_ReturnInt(height);
}