/**
 * Gets the integer value of the specified property key in the internal
 * property set.  
 *
 * @param key The key to search for
 *
 * @return The value associated with <tt>key</tt> if found, otherwise
 *         <tt>0</tt>
 */
int getInternalPropertyInt(const char* key) {
    const char *tmp;    

    tmp = getInternalProperty(key); 

    return(NULL == tmp) ? 0 : atoi(tmp);
}
/**
 * Gets the value of the specified property key in the internal
 * property set. If the key is not found in the internal property
 * set, the application property set is then searched.
 * <p>
 * Java declaration:
 * <pre>
 *     getProperty0(Ljava.lang.String;)Ljava.lang.String;
 * <pre>
 *
 * @param key The key to search for
 *
 * @return The value associated with <tt>key<tt> if found, otherwise
 *         <tt>null<tt>
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
KNIDECL(com_sun_midp_main_Configuration_getProperty0) {
    jchar* uStr;
    const char* key;
    const char* value;
    int strLen;

    KNI_StartHandles(2);
    KNI_DeclareHandle(str);
    KNI_DeclareHandle(result);

    KNI_GetParameterAsObject(1, str);
    strLen = KNI_GetStringLength(str);

    if (strLen <= 0 || (uStr = (jchar*) midpMalloc(strLen * sizeof(jchar))) == NULL) {
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    } else {
        KNI_GetStringRegion(str, 0, strLen, uStr);
        key = UnicodeToCString(uStr, strLen);
        midpFree(uStr);

        /* Look up the property value */
        value = getInternalProperty(key);
        midpFree((void *)key);

        if (value != NULL) {
            KNI_NewStringUTF(value, result);
        } else {
            KNI_ReleaseHandle(result);
        }
    }
    KNI_EndHandlesAndReturnObject(result);
}
Exemplo n.º 3
0
/**
 * Initialize string variable from environment or internal properties.
 * 
 * When environment setting is defined, variable receives the value from it.
 * Else it is initialized from property.
 *
 * @param ptrVar The variable address.
 * @param nameEnv The name of environment setting.
 * @param nameProp The name of internal property.
 */
static void load_var_char_env_prop(char **ptrVar, char *nameEnv, char *nameProp) {
    char *charName = getenv(nameEnv);
    if(charName != NULL) {
        *ptrVar = charName;
    } else {
        charName = (char*)getInternalProperty(nameProp);
        if (charName != NULL) {
            *ptrVar = charName;
        }
    }
}
/**
 * Starts a new process to handle the given URL. The new process executes
 * the value of the <tt>com.sun.midp.midlet.platformRequestCommand</tt>
 * system property. The URL is passed as this process' sole command-line
 * argument.
 *
 * @param pszUrl The 'C' string URL
 *
 * @return true if the platform request is configured
 */
int platformRequest(char* pszUrl) {
    char *execargs[3];

    if (strlen(pszUrl) == 0) {
        /*
         * This is a request to cancel. Since a process was already spawned
         * to handle the previous URL, it too late.
         */
        return 1;
    }

    execargs[0] = (char *)getInternalProperty(PLATFORM_REQUEST_KEY);
    if (execargs[0] == NULL) {
        REPORT_WARN(LC_AMS, "PlatformRequest is not configured.");
	return 0;
    }

    execargs[1] = pszUrl;
    execargs[2] = NULL;

    REPORT_WARN(LC_AMS, "PlatformRequest: stubbed out.");
    // spawn the request using the configured URL handler and URL parameter
    return 1;
}
Exemplo n.º 5
0
/**
 * Initializes the UI.
 *
 * @return <tt>0</tt> upon successful initialization, otherwise
 *         <tt>-1</tt>
 */
static int
midpInitializeUI(void) {
    /*
    if (InitializeEvents() != 0) {
        return -1;
    }
    */

    /*
     * Porting consideration:
     * Here is a good place to put I18N init.
     * function. e.g. initLocaleMethod();
     */

#if ENABLE_JAVA_DEBUGGER
    {
        char* argv[2];

        /* Get the VM debugger port property. */
        argv[1] = (char *)getInternalProperty("VmDebuggerPort");
        if (argv[1] != NULL) {
            argv[0] = "-port";
            (void)JVM_ParseOneArg(2, argv);
        }
    }
#endif

    /* 
        IMPL_NOTE if (pushopen() != 0) {
            return -1;
        }
    */

    /*    lcdlf_ui_init();*/
    return 0;
}
Exemplo n.º 6
0
/**
 * Initializes the device.
 * <p>Java declaration:
 * <pre>
 * private native boolean init0();
 * </pre>
 * @return KNI_TRUE in case of success, else KNI_FALSE 
 * @throws CardDeviceException If configuration failed.
 */
KNIEXPORT KNI_RETURNTYPE_INT 
KNIDECL (com_sun_cardreader_PlatformCardDevice_init0) {
    jboolean retcode = KNI_FALSE;
    javacall_result status;
    char *err_msg;
    char *buffer;
    const char *prop_value;
    
    prop_value = getInternalProperty(hostsandports);
    if (prop_value != NULL) {
        status = javacall_carddevice_set_property(hostsandports, prop_value);
        if (status != JAVACALL_OK) {
            goto err;
        }

        prop_value = getInternalProperty(satselectapdu);
        status = javacall_carddevice_set_property(satselectapdu, prop_value);
        if (status != JAVACALL_OK) {
            goto err;
        }
    }

    if ((status = javacall_carddevice_init()) == JAVACALL_OK) {
        javacall_carddevice_clear_error();
        retcode = KNI_TRUE;
    } else
    if (status == JAVACALL_NOT_IMPLEMENTED) {
        
        /* We throw special exception to tell i3tests to skip real testing*/
        KNI_ThrowNew(cardDeviceException, "stub");
        retcode = KNI_TRUE;
    }
    goto end;

err:        
#define BUFFER_SIZE 128
    buffer = malloc(BUFFER_SIZE);
    if (buffer == NULL) {
        err_msg = "init0()";
        KNI_ThrowNew(jsropOutOfMemoryError, err_msg);
        goto end;
    }

    switch (status) {
    case JAVACALL_NOT_IMPLEMENTED:
        if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) {
            err_msg = buffer;
        } else {
            err_msg = "Required property not supported";
        }
        KNI_ThrowNew(cardDeviceException, err_msg);
        break;
    case JAVACALL_OUT_OF_MEMORY:
        if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) {
            err_msg = buffer;
        } else {
            err_msg = "init0()";
        }
        KNI_ThrowNew(jsropOutOfMemoryError, err_msg);
        break;
    default:
        if (javacall_carddevice_get_error(buffer, BUFFER_SIZE)) {
            err_msg = buffer;
        } else {
            err_msg = "Invalid internal property";
        }
        KNI_ThrowNew(cardDeviceException, err_msg);
        break;
    }
    free(buffer);

end:
    KNI_ReturnInt(retcode);
}