KNIEXPORT KNI_RETURNTYPE_LONG
KNIDECL(KNITest_testIntLongArgs) {
    jlong x = KNI_GetParameterAsLong(1);
    jint y = KNI_GetParameterAsInt(3);
    jlong z = KNI_GetParameterAsLong(4);
    KNI_ReturnLong(x*y+z);
}
/**
 * Adds an entry to the alarm registry.
 * <p>
 * Java declaration:
 * <pre>
 *     addalarm0([BJ)J
 * </pre>
 *
 * @param midlet The entry to add to the alarm registry
 * @param time The time the alarm will be go off
 *
 * @return <tt>0</tt> if this is the first alarm registered with
 *         the given <tt>midlet</tt>, otherwise the time of the
 *         previosly registered alarm.
 */
KNIEXPORT KNI_RETURNTYPE_LONG
KNIDECL(com_sun_midp_io_j2me_push_ConnectionRegistry_addAlarm0) {

    char *szConn = NULL;
    int connLen;
    jlong alarm = 0;
    jlong lastalarm = 0;
    int ret = 0;

    alarm = KNI_GetParameterAsLong(2);

    KNI_StartHandles(1);
    KNI_DeclareHandle(conn);

    KNI_GetParameterAsObject(1, conn);
    connLen = KNI_GetArrayLength(conn);

    szConn = midpMalloc(connLen);
    if (szConn != NULL) {
        KNI_GetRawArrayRegion(conn, 0, connLen, (jbyte*)szConn);
        ret = alarmadd(szConn, alarm, &lastalarm);
        midpFree(szConn);
    }

    if ((szConn == NULL) || (ret == -2)) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_EndHandles();
    KNI_ReturnLong(lastalarm);
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_receiveNewLocationImpl() {

    ProviderInfo *pInfo = NULL;
    jlong timestamp = 0;
    jboolean ret = KNI_FALSE;
    jint provider;

    provider = KNI_GetParameterAsInt(1);
    timestamp = KNI_GetParameterAsLong(2);
    pInfo = getProviderInfo(provider);
    if(pInfo != NULL) {
		if (pInfo->newLocationAvailable == KNI_TRUE) {
			if(jsr179_location_get((jsr179_handle)provider, &pInfo->lastLocation) ==
					JSR179_STATUSCODE_OK) {
				/* get addressInfo if it is present */
				if (pInfo->lastLocation.addressInfoFieldNumber > 0) {
					if(jsr179_get_addressinfo((jsr179_handle)provider,
						&pInfo->lastLocation.addressInfoFieldNumber, 
						pInfo->lastAddressInfo) != JSR179_STATUSCODE_OK) {
						/* drop Address Info for this location */
						pInfo->lastLocation.addressInfoFieldNumber = 0;
					}
				}

				/* get extraInfo if it is present */
				if (pInfo->lastLocation.extraInfoSize > 0) {
					if (jsr179_get_extrainfo((jsr179_handle)provider, 
								pInfo->lastLocation.extraInfoSize, 
								pInfo->lastExtraInfo,
                                pInfo->otherExtraInfoMimeType) != JSR179_STATUSCODE_OK) {
						pInfo->lastLocation.extraInfoSize = 0;
					}
				}
				
				pInfo->lastLocationTimestamp = timestamp;
				pInfo->newLocationAvailable = KNI_FALSE;

				lastUpdatedProvider = provider;

		        ret = KNI_TRUE;
			}
		} else {
			ret = KNI_TRUE;
		}
    }

    KNI_ReturnBoolean(ret);
}
示例#4
0
/**
 * 
 * The datetime parameter coming from java is in milliseconds since the
 * epoch 00:00 1/1/1970. It is needed to translate this value to the native
 * date/time representation. (for example, QT uses the same epoch, but in
 * resolution of seconds rather than milliseconds).
 *
 * private native void setDate0 ( int nativeId , long date ) ; 
 * @param date in milliseconds since 00:00 1/1/1970
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_DateFieldLFImpl_setDate0() {
    MidpItem *dfPtr = NULL;
    MidpError err;

    jint nativeId = KNI_GetParameterAsInt(1);
    jlong date = KNI_GetParameterAsLong(2); /* Long occupies two parameters */

    dfPtr = (MidpItem *)nativeId;

    err = lfpport_datefield_set_date(dfPtr,(long)(date/1000));

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

    KNI_ReturnVoid();
}
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_waitForNewLocation() {

    jboolean ret = KNI_FALSE;
    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jint provider;
    jlong timeout;
    KNI_StartHandles(1);
    provider = KNI_GetParameterAsInt(1);
    timeout = KNI_GetParameterAsLong(2);
    pInfo = getProviderInfo(provider);
    if(pInfo != NULL) {
        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {
            /* First call -request */
            if(pInfo->locked == KNI_TRUE) {
                lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
            } else {
                /* request new location */
                res = jsr179_update_set((jsr179_handle)provider, timeout);
                switch (res) {
                    case JSR179_STATUSCODE_WOULD_BLOCK:
                        /* wait for javanotify */
                        pInfo->locked = KNI_TRUE;
                        lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
                        break;
                    case JSR179_STATUSCODE_OK:
                        /* location updated successfully */
                        pInfo->locked = KNI_FALSE;
			            pInfo->newLocationAvailable = KNI_TRUE;
                        ret = KNI_TRUE;
                        break;
                    case JSR179_STATUSCODE_FAIL:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        /* wrong provider name */
                        KNI_ThrowNew(midpIllegalArgumentException, 
                                    "wrong provider");
                        break;
                    default:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        break;
                }
            }
        } else {
            /* Response */
            if (info->status == JSR179_STATUSCODE_OK) {
                /* location updated successfully */
				pInfo->newLocationAvailable = KNI_TRUE;
                ret = KNI_TRUE;
            } else {
                /* location updated failed */
                ret = KNI_FALSE;
            }
            pInfo->locked = KNI_FALSE;
        }
    }
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
示例#6
0
KNIEXPORT jdouble KNI_GetParameterAsDouble(jint index) {
  GUARANTEE(!_in_kvm_native_method, "sanity");
  jlong j = KNI_GetParameterAsLong(index);
  return *(jdouble*)&j;
}
示例#7
0
KNI_RETURNTYPE_DOUBLE Java_java_lang_Double_longBitsToDouble() {
  return double_from_bits(KNI_GetParameterAsLong(1));
}
示例#8
0
/**
 * KNI function that create native resource for current DateField.
 *
 * The native widget created by this function must take into account
 * label and body locations, using Item methods.
 * The implementation must create a native date/time widget that can be
 * displayed as date only, time only, or date/time modes.
 *
 * The displayMode is a two bit mask in which the MSB is the date, and the
 * LSB (ie. binary 10 is date only, 01 is time only, 11 is both).
 *
 * As the datetime parameter coming from java is in milliseconds since the
 * epoch 00:00 1/1/1970, it is needed to translate this value to the native
 * date/time representation. (for example, QT uses the same epoch, but in
 * resolution of seconds rather than milliseconds).
 *
 *
 * Class: javax.microedition.lcdui.DateFieldLFImpl
 * Java prototype:
 * 	private native int createNativeResource0 ( int ownerId , 
 * 	String label , int layout, long datetime , int displayMode,
 *	String timeZone);
 * @param datetime in milliseconds since 00:00 1/1/1970
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_DateFieldLFImpl_createNativeResource0() {

    MidpDisplayable *ownerPtr;
    pcsl_string label;
    pcsl_string timezone;
    pcsl_string_status rc1, rc2;
    jint layout;
    jint displayMode;
    jlong datetime;

    long qtime = 0;

    MidpError err = KNI_OK;
    MidpItem *dfPtr = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(labelHandle);
    KNI_DeclareHandle(timezoneHandle);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, labelHandle);
    layout = KNI_GetParameterAsInt(3);
    datetime = KNI_GetParameterAsLong(4); /* Long occupies two parameters */
    displayMode = KNI_GetParameterAsInt(6);
    KNI_GetParameterAsObject(7, timezoneHandle);

    rc1 = midp_jstring_to_pcsl_string(labelHandle, &label);
    rc2 = midp_jstring_to_pcsl_string(timezoneHandle, &timezone);
    
    KNI_EndHandles();

    /* NULL and empty strings are acceptable */
    if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    dfPtr = MidpNewItem(ownerPtr, MIDP_DATE_FIELD_TYPE);
    if (dfPtr == NULL) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    qtime = (long)(datetime/1000); /* qt date works in seconds */

    err = lfpport_datefield_create(dfPtr, ownerPtr, &label, layout,
				   displayMode, qtime, &timezone);

cleanup:

    pcsl_string_free(&label);
    pcsl_string_free(&timezone);

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

    KNI_ReturnInt(dfPtr);

}