Ejemplo n.º 1
0
/**
 * private static native void getLinks0(Link[] linkarray);
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_LinkPortal_getLinks0(void)
{
    int targetIsolate;
    jsize len;
    int i;
    KNI_StartHandles(2);
    KNI_DeclareHandle(linkArray);
    KNI_DeclareHandle(linkObj);

    targetIsolate = JVM_CurrentIsolateID();
    KNI_GetParameterAsObject(1, linkArray);
    len = KNI_GetArrayLength(linkArray);

    if (portals != NULL) {
        if (portals[targetIsolate].count > 0) {
            rendezvous **rpp = portals[targetIsolate].rppa;
            for (i = 0; i < len; i++) {
                KNI_GetObjectArrayElement(linkArray, i, linkObj);
                setNativePointer(linkObj, rpp[i]);
                rp_incref(rpp[i]);
            }
        }
        portal_free(&portals[targetIsolate]);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_finalize) {
#if ENABLE_MULTIPLE_ISOLATES
    if ((JVM_CurrentIsolateID() == midpGetAmsIsolateId()) &&
        (skinProperties >= 0)) {
        SNI_DeleteReference(skinProperties);
        skinProperties = -1;
    }
#endif
    KNI_ReturnVoid();
}
Ejemplo n.º 4
0
/**
 * private static native int getLinkCount0();
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_links_LinkPortal_getLinkCount0(void)
{
    int retval = 0;
    int targetIsolate = JVM_CurrentIsolateID();

    if (portals == NULL || portals[targetIsolate].count == -1) {
        midp_thread_wait(LINK_PORTAL_SIGNAL, targetIsolate, NULL);
    } else {
        retval = portals[targetIsolate].count;
    }

    KNI_ReturnInt(retval);
}
Ejemplo n.º 5
0
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(com_sun_midp_chameleon_skins_resources_SkinResourcesImpl_ifLoadAllResources0) {
    
#if ENABLE_MULTIPLE_ISOLATES
    /* 
     * There is no need to load all images for non AMS 
     * isolates, they are to be loaded later on demand
     */
    if (JVM_CurrentIsolateID() == midpGetAmsIsolateId()) {
        KNI_ReturnBoolean(KNI_TRUE);
    } else {
        KNI_ReturnBoolean(KNI_FALSE);
    }
#else
    KNI_ReturnBoolean(KNI_FALSE);
#endif

}
Ejemplo n.º 6
0
/**
 * private native void send0(LinkMessage msg)
 *     throws ClosedLinkException,
 *            InterruptedIOException,
 *            IOException;
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_Link_send0(void)
{
    rendezvous *rp;
    KNI_StartHandles(3);
    KNI_DeclareHandle(thisObj);
    KNI_DeclareHandle(messageObj);
    KNI_DeclareHandle(otherMessageObj);

    KNI_GetThisPointer(thisObj);
    KNI_GetParameterAsObject(1, messageObj);

    rp = getNativePointer(thisObj);

    if (rp == NULL) {
        if (SNI_GetReentryData(NULL) == NULL) {
            KNI_ThrowNew(midpClosedLinkException, NULL);
        } else {
            KNI_ThrowNew(midpInterruptedIOException, NULL);
        }
    } else if (JVM_CurrentIsolateID() != rp->sender) {
        KNI_ThrowNew(midpIllegalArgumentException, NULL);
    } else {
        switch (rp->state) {
            case IDLE:
                rp->msg = SNI_AddStrongReference(messageObj);
                rp->state = SENDING;
                midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                break;

            case RECEIVING:
                rp->msg = SNI_AddStrongReference(messageObj);
                rp->state = RENDEZVOUS;
                midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0);
                midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                break;

            case SENDING:
            case RENDEZVOUS:
                midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                break;

            case DONE:
                getReference(rp->msg, "send0/DONE", otherMessageObj);
                if (KNI_IsSameObject(messageObj, otherMessageObj)) {
                    /* it's our message, finish processing */
                    SNI_DeleteReference(rp->msg);
                    rp->msg = INVALID_REFERENCE_ID;
                    rp->state = IDLE;
                    midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0);
                    if (rp->retcode != OK) {
                        KNI_ThrowNew(midpIOException, NULL);
                    }
                } else {
                    /* somebody else's message, just go back to sleep */
                    midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                }

                break;
            case CLOSED:
                setNativePointer(thisObj, NULL);
                if (rp->msg != INVALID_REFERENCE_ID) {
                    /* a message was stranded in the link; clean it out */
                    SNI_DeleteReference(rp->msg);
                    rp->msg = INVALID_REFERENCE_ID;
                }
                rp_decref(rp);
                if (SNI_GetReentryData(NULL) == NULL) {
                    KNI_ThrowNew(midpClosedLinkException, NULL);
                } else {
                    KNI_ThrowNew(midpInterruptedIOException, NULL);
                }
                break;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Ejemplo n.º 7
0
/**
 * private native void receive0(LinkMessage msg, Link link)
 *         throws ClosedLinkException,
 *                InterruptedIOException,
 *                IOException;
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_Link_receive0(void)
{
    rendezvous *rp;

    KNI_StartHandles(4);
    KNI_DeclareHandle(thisObj);
    KNI_DeclareHandle(recvMessageObj);
    KNI_DeclareHandle(sendMessageObj);
    KNI_DeclareHandle(linkObj);

    KNI_GetThisPointer(thisObj);
    KNI_GetParameterAsObject(1, recvMessageObj);
    KNI_GetParameterAsObject(2, linkObj);

    rp = getNativePointer(thisObj);

    if (rp == NULL) {
        if (SNI_GetReentryData(NULL) == NULL) {
            KNI_ThrowNew(midpClosedLinkException, NULL);
        } else {
            KNI_ThrowNew(midpInterruptedIOException, NULL);
        }
    } else if (JVM_CurrentIsolateID() != rp->receiver) {
        KNI_ThrowNew(midpIllegalArgumentException, NULL);
    } else {
        jboolean ok;

        switch (rp->state) {
            case IDLE:
                rp->state = RECEIVING;
                midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                break;

            case SENDING:
                getReference(rp->msg, "receive0/SENDING",
                    sendMessageObj);
                ok = copy(sendMessageObj, recvMessageObj, linkObj);
                if (ok) {
                    rp->retcode = OK;
                } else {
                    rp->retcode = ERROR;
                    KNI_ThrowNew(midpIOException, NULL);
                }
                rp->state = DONE;
                midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0);
                break;

            case RENDEZVOUS:
                getReference(rp->msg, "receive0/RENDEZVOUS", sendMessageObj);
                ok = copy(sendMessageObj, recvMessageObj, linkObj);
                if (ok) {
                    rp->retcode = OK;
                } else {
                    rp->retcode = ERROR;
                    KNI_ThrowNew(midpIOException, NULL);
                }
                rp->state = DONE;
                midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0);

                break;

            case RECEIVING:
            case DONE:
                midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL);
                break;

            case CLOSED:
                setNativePointer(thisObj, NULL);
                rp_decref(rp);
                if (SNI_GetReentryData(NULL) == NULL) {
                    KNI_ThrowNew(midpClosedLinkException, NULL);
                } else {
                    KNI_ThrowNew(midpInterruptedIOException, NULL);
                }
                break;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}