midp_slavemode_javacall.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 729 行 · 第 1/2 页
C
729 行
{ int len = 0; javacall_utf16_string str = event->data.multimediaEvent.data.str16; while( str[len] != 0 ) len++; pcsl_string_convert_from_utf16( str, len, &pNewMidpEvent->MM_STRING ); free( str ); } break; default: pNewMidpEvent->MM_DATA = event->data.multimediaEvent.data.num32; break; } REPORT_CALL_TRACE4(LC_NONE, "[jsr234 event] External event recevied %d %d %d %d\n", pNewMidpEvent->type, event->data.multimediaEvent.appId, pNewMidpEvent->MM_PLAYER_ID, pNewMidpEvent->MM_DATA); break;#endif#ifdef ENABLE_JSR_179 case JSR179_LOCATION_JC_EVENT: pNewSignal->waitingFor = JSR179_LOCATION_SIGNAL; pNewSignal->descriptor = (int)event->data.jsr179LocationEvent.provider; pNewSignal->status = event->data.jsr179LocationEvent.operation_result; REPORT_CALL_TRACE2(LC_NONE, "[jsr179 event] JSR179_LOCATION_SIGNAL %d %d\n", pNewSignal->descriptor, pNewSignal->status); break; #endif /*ENABLE_JSR_179*/#ifdef ENABLE_JSR_177 case MIDP_JC_EVENT_CARDDEVICE: switch (event->data.carddeviceEvent.eventType) { case MIDP_CARDDEVICE_RESET: pNewSignal->waitingFor = CARD_READER_DATA_SIGNAL; pNewSignal->descriptor = SIGNAL_RESET; pNewSignal->status = SIGNAL_RESET; pNewSignal->pResult = (void *)event->data.carddeviceEvent.handle; break; case MIDP_CARDDEVICE_XFER: pNewSignal->waitingFor = CARD_READER_DATA_SIGNAL; pNewSignal->descriptor = SIGNAL_XFER; pNewSignal->status = SIGNAL_XFER; pNewSignal->pResult = (void *)event->data.carddeviceEvent.handle; break; case MIDP_CARDDEVICE_UNLOCK: pNewSignal->waitingFor = CARD_READER_DATA_SIGNAL; pNewSignal->descriptor = SIGNAL_LOCK; pNewSignal->status = SIGNAL_LOCK; pNewSignal->pResult = NULL; break; default: /* just ignore invalid event type */ REPORT_ERROR1(LC_CORE,"Invalid carddevice event type: %d\n", event->data.carddeviceEvent.eventType); break; } break;#endif /* ENABLE_JSR_177 */#if ENABLE_MULTIPLE_ISOLATES case MIDP_JC_EVENT_SWITCH_FOREGROUND: pNewSignal->waitingFor = AMS_SIGNAL; pNewMidpEvent->type = SELECT_FOREGROUND_EVENT; pNewMidpEvent->intParam1 = 1; break; case MIDP_JC_EVENT_SELECT_APP: pNewSignal->waitingFor = AMS_SIGNAL; pNewMidpEvent->type = SELECT_FOREGROUND_EVENT; pNewMidpEvent->intParam1 = 0; break;#endif /* ENABLE_MULTIPLE_ISOLATES */#if ENABLE_JSR_256 case JSR256_JC_EVENT_SENSOR_AVAILABLE: pNewSignal->waitingFor = JSR256_SIGNAL; pNewMidpEvent->type = SENSOR_EVENT; pNewMidpEvent->intParam1 = event->data.jsr256SensorAvailable.sensor_type; pNewMidpEvent->intParam2 = event->data.jsr256SensorAvailable.is_available; break; case JSR256_JC_EVENT_SENSOR_OPEN_CLOSE: pNewSignal->waitingFor = JSR256_SIGNAL; pNewSignal->descriptor = (int)event->data.jsr256_jc_event_sensor.sensor; break;#endif /* ENABLE_JSR_256 */ default: REPORT_ERROR1(LC_CORE,"checkForSystemSignal(): Unknown event %d.\n", event->eventType); break; }; REPORT_CALL_TRACE(LC_HIGHUI, "LF:STUB:checkForSystemSignal()\n"); return JAVACALL_OK;}/** * Handles the native event notification * * @param blocked_threads blocked threads * @param blocked_threads_count number of blocked threads * @param timeout wait timeout * * @return <tt>JAVACALL_OK</tt> if an event successfully received, * <tt>JAVACALL_FAIL</tt> or if failed or no messages are avaialable */static int midp_slavemode_handle_events(JVMSPI_BlockedThreadInfo *blocked_threads, int blocked_threads_count, jlong timeout) { int ret = -1; static MidpReentryData newSignal; static MidpEvent newMidpEvent; newSignal.waitingFor = 0; newSignal.pResult = NULL; MIDP_EVENT_INITIALIZE(newMidpEvent); if (checkForSystemSignal(&newSignal, &newMidpEvent, blocked_threads, blocked_threads_count, timeout) == JAVACALL_OK){ switch (newSignal.waitingFor) {#if ENABLE_JAVA_DEBUGGER case VM_DEBUG_SIGNAL: if (midp_isDebuggerActive()) { JVM_ProcessDebuggerCmds(); } break;#endif /* ENABLE_JAVA_DEBUGGER */ case AMS_SIGNAL: midpStoreEventAndSignalAms(newMidpEvent); break; case UI_SIGNAL: if (newMidpEvent.type == CHANGE_LOCALE_EVENT) { StoreMIDPEventInVmThread(newMidpEvent, -1); } else { midpStoreEventAndSignalForeground(newMidpEvent); } break; case DISPLAY_DEVICE_SIGNAL: // broadcast event, send it to all isolates to all displays StoreMIDPEventInVmThread(newMidpEvent, -1); break; case NETWORK_READ_SIGNAL: if (eventUnblockJavaThread(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status)) /* Processing is done in eventUnblockJavaThread. */; else if (findPushBlockedHandle(newSignal.descriptor) != 0) { /* The push system is waiting for a read on this descriptor */ midp_thread_signal_list(blocked_threads, blocked_threads_count, PUSH_SIGNAL, 0, 0); }#if (ENABLE_JSR_120 || ENABLE_JSR_205) else jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor, newSignal.status);#endif break; case HOST_NAME_LOOKUP_SIGNAL: case NETWORK_WRITE_SIGNAL:#if (ENABLE_JSR_120 || ENABLE_JSR_205) if (!jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor, newSignal.status))#endif midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); break; case NETWORK_EXCEPTION_SIGNAL: /* Find both the read and write threads and signal the status. */ eventUnblockJavaThread(blocked_threads, blocked_threads_count, NETWORK_READ_SIGNAL, newSignal.descriptor, newSignal.status); eventUnblockJavaThread(blocked_threads, blocked_threads_count, NETWORK_WRITE_SIGNAL, newSignal.descriptor, newSignal.status); break; case PUSH_ALARM_SIGNAL: if (findPushTimerBlockedHandle(newSignal.descriptor) != 0) { /* The push system is waiting for this alarm */ midp_thread_signal_list(blocked_threads, blocked_threads_count, PUSH_SIGNAL, 0, 0); } break;#if (ENABLE_JSR_135 || ENABLE_JSR_234) case MEDIA_EVENT_SIGNAL: if (newMidpEvent.type == MMAPI_EVENT || newMidpEvent.type == AMMS_EVENT) { StoreMIDPEventInVmThread(newMidpEvent, newMidpEvent.MM_ISOLATE); } if (newSignal.descriptor != 0) { int i; for (i = 0; i < blocked_threads_count; i++) { MidpReentryData *pThreadReentryData = (MidpReentryData*)(blocked_threads[i].reentry_data); if (pThreadReentryData != NULL && pThreadReentryData->waitingFor == newSignal.waitingFor && (pThreadReentryData->descriptor == newSignal.descriptor || (pThreadReentryData->descriptor & PLAYER_DESCRIPTOR_EVENT_MASK) == newSignal.descriptor)) { pThreadReentryData->status = newSignal.status; pThreadReentryData->pResult = newSignal.pResult; midp_thread_unblock(blocked_threads[i].thread_id); } } } break;#endif#ifdef ENABLE_JSR_179 case JSR179_LOCATION_SIGNAL: midp_thread_signal_list(blocked_threads, blocked_threads_count, JSR179_LOCATION_SIGNAL, newSignal.descriptor, newSignal.status); break;#endif /* ENABLE_JSR_179 */#if (ENABLE_JSR_120 || ENABLE_JSR_205) case WMA_SMS_READ_SIGNAL: case WMA_CBS_READ_SIGNAL: case WMA_MMS_READ_SIGNAL: case WMA_SMS_WRITE_SIGNAL: case WMA_MMS_WRITE_SIGNAL: jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor, newSignal.status); break;#endif#ifdef ENABLE_JSR_177 case CARD_READER_DATA_SIGNAL: midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); break;#endif /* ENABLE_JSR_177 */#ifdef ENABLE_JSR_256 case JSR256_SIGNAL: if (newMidpEvent.type == SENSOR_EVENT) { StoreMIDPEventInVmThread(newMidpEvent, -1); } else { midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); } break;#endif /* ENABLE_JSR_256 */ case NETWORK_STATUS_SIGNAL: if (MIDP_NETWORK_UP == newSignal.status) { midp_thread_signal_list(blocked_threads, blocked_threads_count, NETWORK_STATUS_SIGNAL, newSignal.descriptor, PCSL_NET_SUCCESS); } else if (MIDP_NETWORK_DOWN == newSignal.status) { midp_thread_signal_list(blocked_threads, blocked_threads_count, NETWORK_STATUS_SIGNAL, newSignal.descriptor, PCSL_NET_IOERROR); midp_thread_signal_list(blocked_threads, blocked_threads_count, NETWORK_READ_SIGNAL, 0, PCSL_NET_IOERROR); midp_thread_signal_list(blocked_threads, blocked_threads_count, NETWORK_WRITE_SIGNAL, 0, PCSL_NET_IOERROR); midp_thread_signal_list(blocked_threads, blocked_threads_count, NETWORK_EXCEPTION_SIGNAL, 0, PCSL_NET_IOERROR); midp_thread_signal_list(blocked_threads, blocked_threads_count, HOST_NAME_LOOKUP_SIGNAL, 0, PCSL_NET_IOERROR); REPORT_INFO(LC_PROTOCOL, "midp_slavemode_handle_events:" "network down\n"); } else { REPORT_ERROR1(LC_PROTOCOL, "midp_slavemode_handle_events:" "NETWORK_STATUS_SIGNAL Unknown net. status = %d\n", newSignal.status); } break; default: break; } /* switch */ ret = 0; } return ret;}/** * Call this function in slave mode to inform VM of new events. */void javanotify_inform_event(void) { int blocked_threads_count; JVMSPI_BlockedThreadInfo * blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); int ret = 0; while (ret == 0){ blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); ret = midp_slavemode_handle_events(blocked_threads, blocked_threads_count, 0 /*timeout*/); }}/* * See comments in javacall_lifecycle.h */javacall_int64 javanotify_vm_timeslice(void) { return midpTimeSlice();}static jlong midpTimeSlice(void) { jlong to = midp_slavemode_time_slice(); javacall_time_milliseconds toInMillisec; if (-2 == to) { measureStack(KNI_FALSE); pushcheckinall(); midpFinalize(); } else { /* convert jlong to long */ if (to > 0x7FFFFFFF) { toInMillisec = -1; } else if (to < 0) { toInMillisec = -1; } else { toInMillisec = (javacall_time_milliseconds)(to&0x7FFFFFFF); } } return to;}/** * Requests that the VM control code schedule a time slice as soon * as possible, since Java platform threads are waiting to be run. */void midp_slavemode_schedule_vm_timeslice(void){ javacall_schedule_vm_timeslice();}/** Runs the platform-specific event loop. */void midp_slavemode_event_loop(void) { REPORT_INFO(LC_CORE, "midp_slavemode_event_loop() is not " "implemented for JavaCall platform\n"); return;}/** * This function is called when the network initialization * or finalization is completed. * * @param isInit 0 if the network finalization has been finished, * not 0 - if the initialization * @param status one of PCSL_NET_* completion codes */void midp_network_status_event_port(int isInit, int status) { jcapp_network_event_received(isInit, status);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?