/**
 * Native method String getComponentId(String, String) of
 * com.sun.midp.midletsuite.DynamicComponentStorage.
 * <p>
 * Gets the unique identifier of the dynamic component defined by its
 * vendor and name.
 *
 * @param suiteId ID of the suite the component belongs to
 * @param vendor name of the vendor that created the component,
 *        as given in a JAD file
 * @param name name of the component, as given in a JAD file
 *
 * @return ID of the component given by vendor and name or
 *         ComponentInfo.UNUSED_COMPONENT_ID if the component
 *         does not exist
 */
KNIEXPORT KNI_RETURNTYPE_INT
KNIDECL(com_sun_midp_midletsuite_DynamicComponentStorage_getComponentId) {
    ComponentIdType componentId = UNUSED_COMPONENT_ID;
    MIDPError error;
    SuiteIdType suiteId = KNI_GetParameterAsInt(1);

    KNI_StartHandles(2);

    GET_PARAMETER_AS_PCSL_STRING(2, vendor)
    GET_PARAMETER_AS_PCSL_STRING(3, name)

    error = midp_get_component_id(suiteId, &vendor, &name, &componentId);

    switch(error) {
        case OUT_OF_MEMORY:
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
            break;
        case SUITE_CORRUPTED_ERROR:
            KNI_ThrowNew(midpIOException, NULL);
            break;
        case NOT_FOUND:
            componentId = UNUSED_COMPONENT_ID;
            break;
        default:
            break;
    }

    RELEASE_PCSL_STRING_PARAMETER
    RELEASE_PCSL_STRING_PARAMETER

    KNI_EndHandles();

    KNI_ReturnInt(componentId);
}
/**
 * Loads a native image data from image cache into ImageData..
 * <p>
 * Java declaration:
 * <pre>
 *     boolean loadAndCreateImmutableImageDataFromCache0(ImageData imageData,
 *                                                       int suiteId,
 *                                                       String resName);
 * </pre>
 *
 * @param imageData The ImageData to be populated
 * @param suiteId   The suite Id
 * @param resName   The name of the image resource
 * @return true if a cached image was loaded, false otherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
KNIDECL(javax_microedition_lcdui_SuiteImageCacheImpl_loadAndCreateImmutableImageDataFromCache0) {
#if ENABLE_IMAGE_CACHE
    int len;
    SuiteIdType suiteId;
    jboolean status = KNI_FALSE;
    unsigned char *rawBuffer = NULL;

    KNI_StartHandles(2);

    GET_PARAMETER_AS_PCSL_STRING(3, resName)

    KNI_DeclareHandle(imageData);
    KNI_GetParameterAsObject(1, imageData);

    suiteId = KNI_GetParameterAsInt(2);

    len = loadImageFromCache(suiteId, &resName, &rawBuffer);
    if (len != -1 && rawBuffer != NULL) {
        /* image is found in cache */
        status = img_load_imagedata_from_raw_buffer(KNIPASSARGS
                 imageData, rawBuffer, len);
    }

    midpFree(rawBuffer);

    RELEASE_PCSL_STRING_PARAMETER

    KNI_EndHandles();
    KNI_ReturnBoolean(status);
#else
    KNI_ReturnBoolean(KNI_FALSE);
#endif
}
Пример #3
0
/**
 * KNI function that makes native form visible.
 * CLASS:         javax.microedition.lcdui.FormLFImpl
 * Java Prototype: int createNativeResource0(String title,
 * 	                                    String tickerText)
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_FormLFImpl_createNativeResource0() {

    MidpError err = KNI_OK;
    MidpDisplayable *formPtr = NULL;

    KNI_StartHandles(2);

    GET_PARAMETER_AS_PCSL_STRING(1, title)
    GET_PARAMETER_AS_PCSL_STRING(2, tickerText)
    /* NULL and empty strings are acceptable. */

	formPtr = MidpNewDisplayable(MIDP_FORM_TYPE);
	if (formPtr == NULL) {
	    err = KNI_ENOMEM;
	} else {
	    /* Fill in platform dependent portion of form structure */
	    err = lfpport_form_create((MidpDisplayable *)formPtr,
				      &title, &tickerText);
	    /*
	      IMPL_NOTE: Move this to midp_displayable.c
	      extern C in mscreen.cpp:
	    */
	   /* pdSetTicker(&tickerText);*/
	    formPtr->setTicker(formPtr, &tickerText);
	}

    RELEASE_PCSL_STRING_PARAMETER
    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();

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

    KNI_ReturnInt(formPtr);
}
Пример #4
0
/**
 * Called 1st time predictive text library is accessed.
 * it calls platform specific predictive text initialization functions.
 * If library has been already initialized it's just initialized once again. 
 * It can not guarantee the returned handler will be identical to the
 * previous one. 
 *
 * @param lang the language used to select the library. If the language is
 * NULL or it's not supported this function returns handle for the default
 * language library. 
 * @return the handle of the library. If some error occurs 0 is returned
 * as a library handle. 
 */
KNIEXPORT KNI_RETURNTYPE_INT 
Java_com_sun_midp_chameleon_input_PTDictionaryImpl_ptInitLibrary0() {
    jint handle = 0;

    KNI_StartHandles(1);

    GET_PARAMETER_AS_PCSL_STRING(1, lang);
    handle = ptInitLibrary(&lang);
    RELEASE_PCSL_STRING_PARAMETER;

    KNI_EndHandles();
    KNI_ReturnInt(handle);
}
Пример #5
0
/**
 * KNI function that create native resource for current Gauge.
 * Class: javax.microedition.lcdui.GaugeLFImpl
 * Java prototype:
 * private native int createNativeResource0(int ownerId,
 *	    		String label, int layout, 
 *                      boolean interactive,
 *			int maxValue, int initialValue)
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_GaugeLFImpl_createNativeResource0() {
    
    MidpError err = KNI_OK;
    MidpItem *gaugePtr = NULL;
    MidpDisplayable *ownerPtr;
    int maxValue, initialValue, layout;
    jboolean interactive;

    KNI_StartHandles(1);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    GET_PARAMETER_AS_PCSL_STRING(2, label)
    layout = KNI_GetParameterAsInt(3);
    interactive = KNI_GetParameterAsBoolean(4);
    maxValue = KNI_GetParameterAsInt(5);
    initialValue = KNI_GetParameterAsInt(6);
    {
        gaugePtr = MidpNewItem(ownerPtr,
                   interactive ? MIDP_INTERACTIVE_GAUGE_TYPE
                           : MIDP_NON_INTERACTIVE_GAUGE_TYPE);
        if (gaugePtr == NULL) {
            err = KNI_ENOMEM;
        } else {
            err = lfpport_gauge_create(gaugePtr, ownerPtr, &label, layout,
                           interactive, maxValue, initialValue);
        }
        /* cleanup: */
        if (err != KNI_OK) {
            MidpDeleteItem(gaugePtr);
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
        }
    }
    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();

    KNI_ReturnInt(gaugePtr);
}
Пример #6
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_getCriteria() {

    jsr179_provider_info provider_info;
    jsr179_result res;
    jboolean ret = KNI_FALSE;

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

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

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

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
Пример #7
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_j2me_location_PlatformLocationProvider_open() {

    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jsr179_handle pProvider = NULL;
    jint provider = 0;
    
    KNI_StartHandles(1);
    GET_PARAMETER_AS_PCSL_STRING(1, name)
    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        res = jsr179_provider_open(name, &pProvider);
        switch (res) {
            case JSR179_STATUSCODE_OK:
                /* handler returned immediatelly */
                provider = (jint)pProvider;
                register_provider(provider);
                break;
            case JSR179_STATUSCODE_INVALID_ARGUMENT:
                /* wrong provider name */
                KNI_ThrowNew(midpIllegalArgumentException, 
                            "wrong provider name");
                break;
            case JSR179_STATUSCODE_FAIL:
                /* fail */
                KNI_ThrowNew(midpIOException, "open failed");
                break;
            case JSR179_STATUSCODE_WOULD_BLOCK:
                /* wait for javanotify */
                provider = (jint)pProvider;
                pInfo = register_provider(provider);
                if (pInfo != NULL) {
                    pInfo->locked = KNI_TRUE;
                }
                lock_thread(JSR179_EVENT_OPEN_COMPLETED, provider);
                break;
            default:
                break;
        }
    } else {
        /* Second call for this thread - finish open */
        if (info->status == JSR179_STATUSCODE_OK) {
            /* Provider opened successfully */
            provider = info->descriptor;
            pInfo = getProviderInfo(provider);
            if (pInfo != NULL) {
                pInfo->locked = KNI_FALSE;
            }
        } else {
            /* Provider open failed*/
            unregister_provider(provider);
            provider = 0;
        }
    }

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnInt(provider);
}
Пример #8
0
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_chameleon_skins_resources_LoadedSkinData_beginReadingSkinFile) {
    const unsigned char* skin_description = lfj_get_skin_description();

    if (skin_description != NULL) {
        gsSkinFileDataStart = gsSkinFileDataPos =
            (unsigned char*)skin_description;
        gsSkinFileDataEnd = gsSkinFileDataStart +
            lfj_get_skin_description_size();
    } else {
        char* errorStr = NULL;
        int fileHandle = -1;
        int fileSize;
        int bytesRead;
        jfieldID fid;

        KNI_StartHandles(2);
        KNI_DeclareHandle(classHandle);

        KNI_GetClassPointer(classHandle);

        fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_USASCII", "B");
        STRING_ENCODING_USASCII = (unsigned char)
            KNI_GetStaticByteField(classHandle, fid);

        fid = KNI_GetStaticFieldID(classHandle, "STRING_ENCODING_UTF8", "B");
        STRING_ENCODING_UTF8 = (unsigned char)
            KNI_GetStaticByteField(classHandle, fid);

        GET_PARAMETER_AS_PCSL_STRING(1, fileName);

        do {
            /*
             * Open skin file
             */
            fileHandle = storage_open(&errorStr, &fileName, OPEN_READ);
            if (errorStr != NULL) {
                KNI_ThrowNew(midpIOException, errorStr);
                storageFreeError(errorStr);
                break;
            }

            /*
             * Obtain file size
             */
            fileSize = storageSizeOf(&errorStr, fileHandle);
            if (errorStr != NULL) {
                KNI_ThrowNew(midpIOException, errorStr);
                storageFreeError(errorStr);
                break;
            }

            /*
             * Read whole file into heap memory
             */
            gsSkinFileDataStart = (unsigned char*)midpMalloc(fileSize);
            if (gsSkinFileDataStart == NULL) {
                KNI_ThrowNew(midpOutOfMemoryError, NULL);
                break;
            }

            bytesRead = storageRead(&errorStr, fileHandle,
                    (char*)gsSkinFileDataStart, fileSize);
            if (errorStr != NULL) {
                KNI_ThrowNew(midpIOException, errorStr);
                storageFreeError(errorStr);
                midpFree(gsSkinFileDataStart);
                gsSkinFileDataStart = NULL;
                break;
            }
            if (bytesRead != fileSize) {
                KNI_ThrowNew(midpIOException, "Failed to read whole file");
                midpFree(gsSkinFileDataStart);
                gsSkinFileDataStart = NULL;
                break;
            }

            gsSkinFileDataPos = gsSkinFileDataStart;
            gsSkinFileDataEnd = gsSkinFileDataStart + fileSize;

        } while (0);

        RELEASE_PCSL_STRING_PARAMETER;

        /*
         * Close skin file
         */
        if (fileHandle != -1) {
            storageClose(&errorStr, fileHandle);
        }

        KNI_EndHandles();
    }

    KNI_ReturnVoid();
}