midpnativeappmanagerpeer.c

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

C
864
字号
 * 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: ALL_OK if successful, *                     NOT_FOUND if the application was not found, *                     BAD_PARAMS if pSuiteId is null */MIDPError midp_midlet_get_suite_id(jint appId, SuiteIdType* pSuiteId) {    (void)appId; /* not finished */    if (pSuiteId == NULL) {        return BAD_PARAMS;    }    return ALL_OK;}/** * Gets runtime information about the specified MIDlet. * * This call is asynchronous, the result will be reported later through * passing a MIDLET_INFO_READY_EVENT event to SYSTEM_EVENT_LISTENER. * * @param appId The ID used to identify the application * * @return error code: ALL_OK if successful (operation started), *                     NOT_FOUND if the application was not found */MIDPError midp_midlet_request_runtime_info(jint appId) {    MidpEvent evt;    MIDP_EVENT_INITIALIZE(evt);    evt.type = NATIVE_MIDLET_GETINFO_REQUEST;    evt.intParam1 = appId;    midpStoreEventAndSignalAms(evt);    return ALL_OK;}/** * Saves runtime information from the given structure * into the native buffer. * * @param runtimeInfo structure holding the information to save */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_saveRuntimeInfoInNative(void) {    KNI_StartHandles(2);    KNI_DeclareHandle(runtimeInfo);    KNI_DeclareHandle(clazz);    /* KNI_DeclareHandle(string); */    KNI_GetParameterAsObject(1, runtimeInfo);    KNI_GetObjectClass(runtimeInfo, clazz);    KNI_SAVE_INT_FIELD(runtimeInfo, clazz, "memoryReserved",                       g_runtimeInfoBuf.memoryReserved);    KNI_SAVE_INT_FIELD(runtimeInfo, clazz, "memoryTotal",                       g_runtimeInfoBuf.memoryTotal);    KNI_SAVE_INT_FIELD(runtimeInfo, clazz, "usedMemory",                       g_runtimeInfoBuf.usedMemory);    KNI_SAVE_INT_FIELD(runtimeInfo, clazz, "priority",                       g_runtimeInfoBuf.priority);    g_runtimeInfoBuf.profileName    = NULL;    g_runtimeInfoBuf.profileNameLen = 0;    /*    do {        KNI_SAVE_PCSL_STRING_FIELD(runtimeInfo, clazz, "profileName",                                   &g_runtimeInfoBuf.profileName, string);    } while (0);    */    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager that the system has completed * the requested operation and the result (if any) is available. * * @param operation code of the operation that has completed * @param externalAppId ID assigned by the external application manager * @param retCode completion code (0 if OK) */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyOperationCompleted(void) {    NamsEventData eventData;    int retCode = KNI_GetParameterAsInt(3);    memset((char*)&eventData, 0, sizeof(NamsEventData));    eventData.event  = MIDP_NAMS_EVENT_OPERATION_COMPLETED;    eventData.reason = KNI_GetParameterAsInt(1);    eventData.appId  = KNI_GetParameterAsInt(2);    if (retCode == 0) {        eventData.state = ALL_OK;        if (eventData.reason == NATIVE_MIDLET_GETINFO_REQUEST) {            eventData.pRuntimeInfo = &g_runtimeInfoBuf;        }    } else {        eventData.state = BAD_PARAMS;    }        nams_listeners_notify(SYSTEM_EVENT_LISTENER, &eventData);    KNI_ReturnVoid();}/** * Notify the native application manager that the system had an error starting. */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifySystemStartError(void) {    NamsEventData eventData;    memset((char*)&eventData, 0, sizeof(NamsEventData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;    eventData.state = MIDP_SYSTEM_STATE_ERROR;    nams_listeners_notify(SYSTEM_EVENT_LISTENER, &eventData);    KNI_ReturnVoid();}/** * Notify the native application manager of the system start up. */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifySystemStart(void) {    NamsEventData eventData;    memset((char*)&eventData, 0, sizeof(NamsEventData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.state = MIDP_SYSTEM_STATE_ACTIVE;    nams_listeners_notify(SYSTEM_EVENT_LISTENER, &eventData);    KNI_ReturnVoid();}/** * Notify the native application manager of the system suspension. */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifySystemSuspended(void) {    NamsEventData eventData;    memset((char*)&eventData, 0, sizeof(NamsEventData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.state = MIDP_SYSTEM_STATE_SUSPENDED;    nams_listeners_notify(SYSTEM_EVENT_LISTENER, &eventData);    KNI_ReturnVoid();}/** * Notify the native application manager of the MIDlet creation. * * @param externalAppId ID assigned by the external application manager * @param suiteId ID of the midlet suite * @param className class name of the midlet that failed to start * @param error error code */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyMidletStartError(void) {    jint externalAppId = KNI_GetParameterAsInt(1);    jint error = KNI_GetParameterAsInt(4);    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.appId = externalAppId;    eventData.state = MIDP_MIDLET_STATE_ERROR;    eventData.reason = error;    msd.suiteId = KNI_GetParameterAsInt(2);    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(3, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    /*     * notify the listeners even failed to get the midlet's class name,     * just don't use it     */    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager of the MIDlet creation. * * @param externalAppId ID assigned by the external application manager * @param suiteId ID of the suite the created midlet belongs to * @param className class name of the midlet that was created */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyMidletCreated(void) {    jint externalAppId = KNI_GetParameterAsInt(1);    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.appId = externalAppId;    eventData.state = MIDP_MIDLET_STATE_PAUSED;    msd.suiteId = KNI_GetParameterAsInt(2);    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(3, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager that the MIDlet is active. * * @param externalAppId ID assigned by the external application manager * @param suiteId ID of the suite the started midlet belongs to * @param className class name of the midlet that was started */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyMidletActive(void) {    jint externalAppId = KNI_GetParameterAsInt(1);    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.appId = externalAppId;    eventData.state = MIDP_MIDLET_STATE_ACTIVE;    msd.suiteId = KNI_GetParameterAsInt(2);    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(3, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager that the MIDlet is paused. * * @param externalAppId ID assigned by the external application manager * @param suiteId ID of the suite the paused midlet belongs to * @param className class name of the midlet that was paused */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyMidletPaused(void) {    jint externalAppId = KNI_GetParameterAsInt(1);    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.appId = externalAppId;    eventData.state = MIDP_MIDLET_STATE_PAUSED;    msd.suiteId = KNI_GetParameterAsInt(2);    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(3, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager that the MIDlet is destroyed. * * @param externalAppId ID assigned by the external application manager * @param suiteId ID of the suite the destroyed midlet belongs to * @param className class name of the midlet that was destroyed */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifyMidletDestroyed(void) {    jint externalAppId = KNI_GetParameterAsInt(1);    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;    eventData.appId = externalAppId;    eventData.state = MIDP_MIDLET_STATE_DESTROYED;    eventData.reason = MIDP_REASON_EXIT;    msd.suiteId = KNI_GetParameterAsInt(2);    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(3, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Notify the native application manager that the suite is terminated. * * @param suiteId ID of the MIDlet suite * @param className class name of the midlet that was terminated */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_notifySuiteTerminated(void) {    SuiteIdType suiteId;    NamsEventData eventData;    MidletSuiteData msd;    pcsl_string_status res;    suiteId = KNI_GetParameterAsInt(1);    memset((char*)&eventData, 0, sizeof(NamsEventData));    memset((char*)&msd, 0, sizeof(MidletSuiteData));    eventData.event = MIDP_NAMS_EVENT_STATE_CHANGED;        eventData.state = MIDP_MIDLET_STATE_DESTROYED;    eventData.reason = MIDP_REASON_TERMINATED;    msd.suiteId = suiteId;    eventData.pSuiteData = &msd;    KNI_StartHandles(1);    KNI_DeclareHandle(handle);    KNI_GetParameterAsObject(2, handle);    res = midp_jstring_to_pcsl_string(handle,                                      &msd.varSuiteData.midletClassName);    nams_listeners_notify(MIDLET_EVENT_LISTENER, &eventData);    if (res == PCSL_STRING_OK) {        pcsl_string_free(&msd.varSuiteData.midletClassName);    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Register the Isolate ID of the AMS Isolate by making a native * method call that will call JVM_CurrentIsolateId and set * it in the proper native variable. */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_registerAmsIsolateId(void) {    midpRegisterAmsIsolateId();    KNI_ReturnVoid();}/** * Stops the VM and exit immediately. * <p> * Java declaration: * <pre> *     exitInternal(I)V * </pre> * * @param value The return code of the VM. */KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_main_NativeAppManagerPeer_exitInternal(void) {    int value = (int)KNI_GetParameterAsInt(1);    midp_remove_all_event_listeners(ANY_EVENT_LISTENER);    midp_exitVM(value);    KNI_ReturnVoid();}

⌨️ 快捷键说明

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