javacall_native_ams.c

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

C
666
字号
/* * * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include <javautil_unicode.h>#include <javacall_native_ams.h>#include <midpNativeAppManager.h>#include <midpEvents.h>#include <midp_logging.h>#include <midp_runtime_info.h>#include <listeners_intern.h>#include <commandLineUtil_md.h>#include <midpAMS.h>#define MAX_CLASS_NAME_LEN   256#define MAX_PROFILE_NAME_LEN 64#define MAX_SUPPORTED_ARGS   3#define MAX_ARG_LEN          256/* * Forward declarations. */static javacall_opcode midp_operation2javacall(jint midpOpcode);static javacall_lifecycle_statemidp_midlet_state2javacall(jint midpMidletState);static javacall_midlet_ui_statemidp_midlet_ui_state2javacall(jint midpMidletUiState);static javacall_change_reasonmidp_midlet_event_reason2javacall(jint midpEventReason);void midp_listener_ams_system_status(const NamsEventData* pEventData);void midp_listener_ams_operation_completed(const NamsEventData* pEventData);void midp_listener_ams_midlet_state_changed(const NamsEventData* pEventData);void midp_listener_ams_midlet_ui_state_changed(const NamsEventData* pEventData);/** * Platform invokes this function to start the MIDP system. * It does not return until the system is stopped. * * @return <tt>JAVACALL_OK</tt> if successful, *         <tt>JAVACALL_FAIL</tt> otherwise */javacall_result javanotify_ams_system_start() {    MIDPError res = midp_system_initialize();    if (res != ALL_OK) {        return JAVACALL_FAIL;    }    if (midp_add_event_listener(midp_listener_ams_system_status,                                SYSTEM_EVENT_LISTENER) != ALL_OK ||        midp_add_event_listener(midp_listener_ams_operation_completed,                                SYSTEM_EVENT_LISTENER) != ALL_OK ||        midp_add_event_listener(midp_listener_ams_midlet_ui_state_changed,                                DISPLAY_EVENT_LISTENER) != ALL_OK ||        midp_add_event_listener(midp_listener_ams_midlet_state_changed,                                MIDLET_EVENT_LISTENER) != ALL_OK) {        return JAVACALL_FAIL;    }    return (midp_system_start() == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to stop the MIDP system. * * @return <tt>JAVACALL_OK</tt> if successful, *         <tt>JAVACALL_FAIL</tt> otherwise */javacall_result javanotify_ams_system_stop() {    MIDPError res = midp_system_stop();    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to inform VM to start a specific MIDlet * suite. * * @param suiteId      ID of the suite to start * @param appId        ID of runtime midlet, ID must not be Zero * @param className    Fully qualified name of the MIDlet class * @param pRuntimeInfo Quotas and profile to set for the new application * @return <tt>JAVACALL_OK</tt> if all parameter are valid, *         <tt>JAVACALL_FAIL</tt> otherwise * @note this function just checks the parameters accuracy, *       the real status of MIDlet startup will be notified *       by <link>javacall_ams_midlet_stateChanged</link> */javacall_resultjavanotify_ams_midlet_start(javacall_suite_id suiteId,                            javacall_app_id appId,                            javacall_const_utf16_string className,                            const javacall_midlet_runtime_info* pRuntimeInfo) {    return javanotify_ams_midlet_start_with_args(suiteId, appId,        className, NULL, 0, pRuntimeInfo);}/** * Platform invokes this function to inform VM to start a specific MIDlet * suite with arguments. * * @param suiteId      ID of the suite to start with * @param appId        ID of runtime midlet * @param className    Fully qualified name of the MIDlet class * @param args         An array containning up to 3 arguments for *                     the MIDlet to be run * @param argsNum      Number of arguments * @param pRuntimeInfo Quotas and profile to set for the new application * @return <tt>JAVACALL_OK</tt> if all parameter are valid, *         <tt>JAVACALL_FAIL</tt> otherwise * @note  this function just checks the parameters accuracy, *        the real status of MIDlet startup will be notified by *        <link>javacall_ams_midlet_stateChanged</link> */javacall_resultjavanotify_ams_midlet_start_with_args(javacall_suite_id suiteId,                                      javacall_app_id appId,                                      javacall_const_utf16_string className,                                      javacall_const_utf16_string *args,                                      int argsNum,                                      const javacall_midlet_runtime_info*                                      pRuntimeInfo) {    MIDPError res;                                              MidletRuntimeInfo mri, *pMri = NULL;    javacall_result jcRes;    javacall_int32 utf16Len;    static jchar pProfileNameBuf[MAX_PROFILE_NAME_LEN];    static jchar pClassName[MAX_CLASS_NAME_LEN];    static jchar chArgs[MAX_SUPPORTED_ARGS][MAX_ARG_LEN];    jint classNameLen = 0, argsLen[MAX_SUPPORTED_ARGS] = {0, 0, 0};    int i;    if (className == NULL || argsNum < 0 || (argsNum > 0 && args == NULL) ||            (argsNum > MAX_SUPPORTED_ARGS)) {        return JAVACALL_FAIL;    }    /* javacall_utf16_string and jchar* is actually the same */    jcRes = javautil_unicode_utf16_ulength(className, &utf16Len);    if (jcRes != JAVACALL_OK) {        return JAVACALL_FAIL;    }    if (utf16Len + 1 >= MAX_CLASS_NAME_LEN) {        return JAVACALL_FAIL;    }    memcpy((unsigned char*)pClassName, (unsigned char*)className,           utf16Len << 1);    classNameLen = utf16Len;    pClassName[utf16Len] = (jchar)0;    /* copying the midlet's arguments */    for (i = 0; i < argsNum; i++) {        if (args[i] == 0) {            return JAVACALL_FAIL;        }        jcRes = javautil_unicode_utf16_ulength(args[i], &utf16Len);        if (jcRes != JAVACALL_OK) {            return JAVACALL_FAIL;        }        if (utf16Len + 1 >= MAX_ARG_LEN) {            return JAVACALL_FAIL;        }        memcpy((unsigned char*)chArgs[i], (unsigned char*)args[i],               utf16Len << 1);        argsLen[i] = utf16Len;        chArgs[i][utf16Len] = (jchar)0;    }    /*     * converting the structure with the runtime information from     * javacall to MIDP format     */    if (pRuntimeInfo != NULL) {        mri.memoryReserved = (jint) pRuntimeInfo->memoryReserved;        mri.memoryTotal    = (jint) pRuntimeInfo->memoryTotal;        mri.usedMemory     = (jint) pRuntimeInfo->usedMemory;        mri.priority       = (jint) pRuntimeInfo->priority;        /* handling profileName */        jcRes = javautil_unicode_utf16_ulength(pRuntimeInfo->profileName,            &utf16Len);        if (jcRes != JAVACALL_OK) {            return JAVACALL_FAIL;        }        if (utf16Len > 0 && pRuntimeInfo->profileName != NULL) {            if (utf16Len + 1 >= MAX_CLASS_NAME_LEN) {                return JAVACALL_FAIL;            }            memcpy((unsigned char*)pProfileNameBuf,                   (unsigned char*)pRuntimeInfo->profileName,                   utf16Len << 1);            mri.profileNameLen = utf16Len;            pProfileNameBuf[utf16Len] = 0;            mri.profileName = pProfileNameBuf;        } else {            mri.profileNameLen = 0;            mri.profileName = NULL;        }        pMri = &mri;    }        res = midp_midlet_create_start_with_args((SuiteIdType)suiteId,        (const jchar*)pClassName, classNameLen, (const jchar**)args, argsLen,            (jint)argsNum, (jint)appId, pMri);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to inform VM to shutdown a specific * running MIDlet. If it doesn't exit in the specified amount of milliseconds, * it will be forcefully terminated. * * @param appId appId of the suite to shutdown * @param timeoutMillSecond shutdown the suite in timeout millseconds * @return <tt>JAVACALL_OK</tt> if <code>suiteId</code> has a proper value *         <tt>JAVACALL_FAIL</tt> otherwise * @note the real status of operation will be notified by *       <link>javacall_ams_midlet_state_changed</link> */javacall_resultjavanotify_ams_midlet_shutdown(javacall_app_id appId,                               int timeoutMillSeconds) {    MIDPError res = midp_midlet_destroy((jint)appId, (jint)timeoutMillSeconds);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;                                   }/** * Platform invokes this function to inform VM to switch a specific MIDlet * suite to foreground. * * @param appId appId of the suite to switch * * @return <tt>JAVACALL_OK</tt> if <code>suiteId</code> has a proper value *         <tt>JAVACALL_FAIL</tt> otherwise * @note the real status of operation will be notified by *       <link>javacall_ams_midlet_stateChanged</link> */javacall_resultjavanotify_ams_midlet_switch_foreground(javacall_app_id appId) {    MIDPError res = midp_midlet_set_foreground((jint)appId);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to inform VM to switch current MIDlet * suite to background, and no MIDlet will switch to foregound. * * @return <tt>JAVACALL_OK</tt> if <code>suiteId</code> has a proper value *         <tt>JAVACALL_FAIL</tt> otherwise * @note the real status of operation will be notified by *       <link>javacall_ams_midlet_stateChanged</link> */javacall_result javanotify_ams_midlet_switch_background() {    MIDPError res = midp_midlet_set_foreground(MIDLET_APPID_NO_FOREGROUND);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to inform VM to pause a specific MIDlet * * @param appId appId of the suite to pause * @return <tt>JAVACALL_OK</tt> if <code>suiteId</code> has a proper value *         <tt>JAVACALL_FAIL</tt> otherwise * @note the real status of operation will be notified by *       <link>javacall_ams_midlet_stateChanged</link> */javacall_result javanotify_ams_midlet_pause(javacall_app_id appId) {    MIDPError res = midp_midlet_pause((jint)appId);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * Platform invokes this function to inform VM to resume a specific MIDlet * * @param appId appId of the suite to resume * @return <tt>JAVACALL_OK</tt> if <code>suiteId</code> has a proper value *         <tt>JAVACALL_FAIL</tt> otherwise * @note the real status of operation will be notified by *       <link>javacall_ams_midlet_stateChanged</link> */javacall_result javanotify_ams_midlet_resume(javacall_app_id appId) {    MIDPError res = midp_midlet_resume((jint)appId);    return (res == ALL_OK) ? JAVACALL_OK : JAVACALL_FAIL;}/** * App Manager invokes this function to get information about the suite * containing the specified running MIDlet. This call is synchronous. * * @param appId    [in]  the ID used to identify the application * @param pSuiteId [out] on exit will hold an ID of the suite the midlet *                       belongs to * * @return error code: <tt>JAVACALL_OK</tt> if successful, *                     <tt>JAVACALL_FAIL</tt> otherwise */

⌨️ 快捷键说明

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