midp_run.c

来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,116 行 · 第 1/3 页

C
1,116
字号
        reserved = getInternalPropertyInt("AMS_MEMORY_RESERVED_MVM");        if (0 == reserved) {            REPORT_ERROR(LC_AMS, "AMS_MEMORY_RESERVED_MVM property not set");            reserved = AMS_MEMORY_RESERVED_MVM;        }        limit = getInternalPropertyInt("AMS_MEMORY_LIMIT_MVM");        if (0 == limit) {            REPORT_ERROR(LC_AMS, "AMS_MEMORY_LIMIT_MVM property not set");            limit = AMS_MEMORY_LIMIT_MVM;        }        reserved = reserved * 1024;        JVM_SetConfig(JVM_CONFIG_FIRST_ISOLATE_RESERVED_MEMORY, reserved);        if (limit <= 0) {            limit = 0x7FFFFFFF;  /* MAX_INT */        } else {            limit = limit * 1024;        }        JVM_SetConfig(JVM_CONFIG_FIRST_ISOLATE_TOTAL_MEMORY, limit);    }#endif}/** * Initializes the Debugger. */static voidmidpInitializeDebugger(void) {#if ENABLE_ON_DEVICE_DEBUG || ENABLE_WTK_DEBUG    {#if ENABLE_MULTIPLE_ISOLATES    #define OPT_NUM 3#else    #define OPT_NUM 2#endif        char* argv[OPT_NUM] = {            "-nosuspend", "-debugger"#if ENABLE_MULTIPLE_ISOLATES            , "-debug_isolate"#endif        };        int i;        for (i = 0; i < OPT_NUM; i++) {            (void)JVM_ParseOneArg(1, &argv[i]);        }#undef OPT_NUM     }#endif /* ENABLE_ON_DEVICE_DEBUG || ENABLE_WTK_DEBUG */#if ENABLE_JAVA_DEBUGGER    {        char* argv[2];        /* memory profiler */		if (getInternalProperty("VmMemoryProfiler") != NULL) {		    argv[0] = "-memory_profiler";            (void)JVM_ParseOneArg(1, argv);		}        /* Get the VM debugger port property. */        argv[1] = (char *)getInternalProperty("VmDebuggerPort");        if (argv[1] != NULL) {            argv[0] = "-port";            (void)JVM_ParseOneArg(2, argv);        }    }#endif}/** * Initializes the UI. * * @return <tt>0</tt> upon successful initialization, otherwise *         <tt>-1</tt> */static intmidpInitializeUI(void) {    if (0 == lcdlf_ui_init()) {        /* Get the initial screen rotation mode property */        const char* pRotationArg = getSystemProperty(ROTATION_ARG);        if (pRotationArg) {            if (atoi(pRotationArg) == 1) {	      lcdlf_reverse_orientation(lcdlf_get_current_hardwareId());            }        }        return 0;    } else {        return -1;    }}/** * Initializes the VM. * * @return <tt>0</tt> upon successful initialization, otherwise *         <tt>-1</tt> */static intmidpInitializeVM(void) {    if (InitializeEvents() != 0) {        return -1;    }    /*     * Porting consideration:     * Here is a good place to put I18N init.     * function. e.g. initLocaleMethod();     */    midpInitializeAMS();    midpInitializeDebugger();    if (pushopen() != 0) {        return -1;    }    if (midpInitializeUI() != 0) {        return -1;    }    return 0;}/** * Finalizes the AMS. */static voidmidpFinalizeAMS(void) {    finalizeCommandState();    /*     * Note: the AMS isolate will have been registered by a native method     * call, so there is no corresponding midpRegisterAmsIsolateId in the     * midpInitializeAMS() function.     */    midpUnregisterAmsIsolateId();}/** * Finalizes the UI. */static voidmidpFinalizeUI(void) {    lcdlf_ui_finalize();}/** * Finalizes the VM. */static voidmidpFinalizeVM(void) {    midpFinalizeUI();    pushclose();    midpFinalizeAMS();    /*      * Porting consideration:     * Here is a good place to put I18N finalization     * function. e.g. finalizeLocaleMethod();     */    FinalizeEvents();}/** * Sets the the system property "classpathext" to the given value. * * @param classPathExt the new value of the "classpath" system property */static voidputClassPathExtToSysProperty(char* classPathExt) {    /* store class path as system variable for another isolates */    if (NULL != classPathExt) {        char* argv[1];        const char prefix[] = "-Dclasspathext=";        argv[0] = midpMalloc(sizeof(prefix) + strlen(classPathExt));        if (NULL != argv[0]) {            memcpy(argv[0], prefix, sizeof(prefix));            /* copy extention + trailing zero */            memcpy(argv[0] + sizeof(prefix) - 1, classPathExt,                   strlen(classPathExt) + 1);            (void)JVM_ParseOneArg(1, argv);            midpFree(argv[0]);        }    }}#if ENABLE_JAVA_DEBUGGER/** * Passes an argument corresponding to the given debug option to the VM. * * @param debugOption debug option to pass to the VM */static void setDebugOption(int debugOption) {    char* argv[1];    if (debugOption > MIDP_NO_DEBUG) {        argv[0] = "-debugger";        (void)JVM_ParseOneArg(1, argv);#if ENABLE_MULTIPLE_ISOLATES        argv[0] = "-debug_isolate";        (void)JVM_ParseOneArg(1, argv);#endif        if (debugOption == MIDP_DEBUG_SUSPEND) {            argv[0] = "-suspend";            (void)JVM_ParseOneArg(1, argv);        } else if (debugOption == MIDP_DEBUG_NO_SUSPEND) {            argv[0] = "-nosuspend";            (void)JVM_ParseOneArg(1, argv);        }    }}#endif/** * Runs the given MIDlet from the specified MIDlet suite with the * given arguments. Up to 3 arguments will be made available to * the MIDlet as properties <tt>arg-&lt;num&gt;</tt>, where * <tt><i>num</i></tt> is <tt>0</tt> for the first argument, etc. * * @param suiteId The MIDlet Suite ID that the MIDlet is in * @param midletClassName The class name of MIDlet to run * @param arg0 The first argument for the MIDlet to be run. * @param arg1 The second argument for the MIDlet to be run. * @param arg2 The third argument for the MIDlet to be run. * @param debugOption 0 for no debug, 1 debug: suspend the VM until the *   debugger sends a continue command, 2 debug: do not wait for the debugger * @param classPathExt additional path to be passed to the VM * * @return <tt>0</tt> if successful, *         <tt>MIDP_SHUTDOWN_STATUS</tt> if the system is shutting down, *         <tt>MIDP_ERROR_STATUS</tt> if an error, *         <tt>SUITE_NOT_FOUND_STATUS</tt> if the MIDlet suite not found */intmidp_run_midlet_with_args_cp(SuiteIdType suiteId,                             const pcsl_string* midletClassName,                             const pcsl_string* arg0,                             const pcsl_string* arg1,                             const pcsl_string* arg2,                             int debugOption,                             char* classPathExt) {    int vmStatus = 0;    MIDPCommandState* commandState;    JvmPathChar* classPath = NULL;    pcsl_string_status res;#if (VERIFY_ONCE)    jboolean classVerifier = JVM_GetUseVerifier();#endif    if (midpInitCallback(VM_LEVEL, midpInitializeVM, midpFinalizeVM) != 0) {        REPORT_WARN(LC_CORE, "Out of memory during init of VM.\n");        return MIDP_ERROR_STATUS;    }#if (ENABLE_JSR_205 || ENABLE_JSR_120)    /*     * Start listening for wireless messages.     * Consider moving this as appropriate in course of pause/resume     * framework implementation     */    if (init_jsr120() != WMA_NET_SUCCESS) {        REPORT_WARN(LC_CORE, "Cannot init WMA");        return MIDP_ERROR_STATUS;    }#endif    commandState = midpGetCommandState();    commandState->suiteId = suiteId;    if (! pcsl_string_is_null(midletClassName)) {        pcsl_string_free(&commandState->midletClassName);        res = pcsl_string_dup(midletClassName, &commandState->midletClassName);        if (PCSL_STRING_OK != res) {            REPORT_WARN(LC_CORE, "Out of memory: could not dup classname.\n");            return MIDP_ERROR_STATUS;        }    }    if (! pcsl_string_is_null(arg0)) {        pcsl_string_free(&commandState->arg0);        res = pcsl_string_dup(arg0, &commandState->arg0);        if (PCSL_STRING_OK != res) {            REPORT_WARN(LC_CORE, "Out of memory: could not dup arg0.\n");            return MIDP_ERROR_STATUS;        }    }    if (! pcsl_string_is_null(arg1)) {        pcsl_string_free(&commandState->arg1);        res = pcsl_string_dup(arg1, &commandState->arg1);        if (PCSL_STRING_OK != res) {            REPORT_WARN(LC_CORE, "Out of memory: could not dup arg1.\n");            return MIDP_ERROR_STATUS;        }    }    if (! pcsl_string_is_null(arg2)) {        pcsl_string_free(&commandState->arg2);        res = pcsl_string_dup(arg2, &commandState->arg2);        if (PCSL_STRING_OK != res) {            REPORT_WARN(LC_CORE, "Out of memory: could not dup arg2.\n");            return MIDP_ERROR_STATUS;        }    }#if ENABLE_JAVA_DEBUGGER    setDebugOption(debugOption);#else    (void)debugOption;#endif    putClassPathExtToSysProperty(classPathExt);    do {        MIDP_ERROR status = MIDP_ERROR_NONE;#if (VERIFY_ONCE)        /* For cached suite verification we should add the suite classpath */        status = getClassPathForVerifyOnce(&classPath,            commandState->suiteId, &commandState->midletClassName,            &commandState->arg1);        /* Since it is not suite verifier call follow the common way */        if (status == MIDP_ERROR_UNSUPPORTED) {            status = getClassPathPlus(commandState->suiteId,                &classPath, classPathExt);        }#else        status = getClassPathPlus(commandState->suiteId,                    &classPath, classPathExt);#endif        switch (status) {        case MIDP_ERROR_OUT_MEM:            REPORT_WARN(LC_CORE, "Out of memory: could allocate classpath.\n");            return MIDP_ERROR_STATUS;        case MIDP_ERROR_AMS_SUITE_CORRUPTED:            REPORT_WARN(LC_CORE, "I/O error reading appdb.\n");            return MIDP_ERROR_STATUS;        case MIDP_ERROR_AMS_SUITE_NOT_FOUND:            REPORT_WARN(LC_CORE, "Suite not found.\n");            return SUITE_NOT_FOUND_STATUS;        default:            break;        }        midp_resetEvents();        midpMIDletProxyListReset();        pushcheckinLeftOvers(commandState->suiteId);        measureStack(KNI_TRUE);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?