void ChameleonMScreen::keyPressEvent(QKeyEvent *key) { seen_key_press = KNI_TRUE; #if ENABLE_MULTIPLE_ISOLATES if (key->key() == Qt::Key_F12|| key->key() == Qt::Key_Home) { /* F12 to display the foreground selector */ if (!key->isAutoRepeat()) { MidpEvent evt; MIDP_EVENT_INITIALIZE(evt); evt.type = SELECT_FOREGROUND_EVENT; evt.intParam1 = 0; midpStoreEventAndSignalAms(evt); } #ifdef QT_KEYPAD_MODE } else if (key->key() == Qt::Key_Flip) { #else } else if (key->key() == Qt::Key_F4) { #endif if (!key->isAutoRepeat()) { MidpEvent evt; MIDP_EVENT_INITIALIZE(evt); evt.type = SELECT_FOREGROUND_EVENT; evt.intParam1 = 1; midpStoreEventAndSignalAms(evt); } } #else /* F12 pause or activate all Java apps */ if ((key->key() == Qt::Key_F12 || key->key() == Qt::Key_Home) && !key->isAutoRepeat()) { pauseAll(); } #endif else { MidpEvent evt; MIDP_EVENT_INITIALIZE(evt); if ((evt.CHR = mapKey(key)) != KEYMAP_KEY_INVALID) { if (evt.CHR == KEYMAP_KEY_SCREEN_ROT) { evt.type = ROTATION_EVENT; } else { evt.type = MIDP_KEY_EVENT; } evt.ACTION = key->isAutoRepeat() ? KEYMAP_STATE_REPEATED : KEYMAP_STATE_PRESSED; midpStoreEventAndSignalForeground(evt); } } }
/* This is called by MIDPWindow when it's above to draw the "wash" layer * (to grey-out the current Form before drawing the menu). * * At this point, we don't know what the current active TextFieldLFImpl is. * So we just send a message to the FormLFImpl.uCallPeerStateChanged() * method, who will have a better idea about the active TextFieldLFImpl. * * We must withdraw the text editor now. We save its content to a malloc'ed * buffer to pass to FormLFImpl.uCallPeerStateChanged(). * * TODO: there's probably a better way to handle this. */ KNIEXPORT KNI_RETURNTYPE_VOID KNIDECL(com_sun_midp_chameleon_MIDPWindow_disableAndSyncNativeEditor) { MidpEvent event; MIDP_EVENT_INITIALIZE(event); if (editBoxShown) { int strLen = GetWindowTextLength(hwndTextActive); jchar *tmp = (jchar*)midpMalloc((strLen + 1) * sizeof(jchar)); if (tmp) { GetWindowText(hwndTextActive, (LPTSTR)tmp, strLen+1); /* 0-terminated */ WORD w = (WORD)SendMessage(hwndTextActive, EM_GETSEL, 0, 0L); int caret = LOWORD(w); event.type = MIDP_PEER_CHANGED_EVENT; event.intParam1 = (int)tmp; event.intParam2 = strLen; event.intParam3 = caret; midpStoreEventAndSignalForeground(event); } } ShowWindow(hwndTextActive, SW_HIDE); editBoxShown = 0; KNI_ReturnVoid(); }
/** * Reports a fatal error that cannot be handled in Java. * Must be called from a KNI method * */ void handleFatalError(void) { KNI_StartHandles(1); KNI_DeclareHandle(throwableObj); KNI_GetParameterAsObject(1, throwableObj); /* IMPL NOTE: Figure out what throwable class this is and log the error? */ REPORT_CRIT1(LC_CORE, "handleFatalError: uncaught exception in " "isolate %d event processing thread", getCurrentIsolateId()); KNI_EndHandles(); if (getCurrentIsolateId() == midpGetAmsIsolateId()) { /* AMS isolate or SVM mode, terminate VM */ midp_exitVM(-1); } else { MidpEvent event; /* Application isolate, notify the AMS isolate. */ MIDP_EVENT_INITIALIZE(event); event.type = FATAL_ERROR_NOTIFICATION; event.intParam1 = getCurrentIsolateId(); /* Send the shutdown event. */ StoreMIDPEventInVmThread(event, midpGetAmsIsolateId()); } KNI_ReturnVoid(); }
/** * Sends a native event a given Isolate. * * @param event A event to queued * @param isolateId ID of the target Isolate */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_events_EventQueue_sendNativeEventToIsolate(void) { MidpEvent event; jint isolateId; int noExceptions = 0; MIDP_EVENT_INITIALIZE(event); KNI_StartHandles(3); KNI_DeclareHandle(eventObj); KNI_DeclareHandle(stringObj); KNI_DeclareHandle(classObj); KNI_GetParameterAsObject(1, eventObj); isolateId = KNI_GetParameterAsInt(2); cacheEventFieldIDs(eventObj, classObj); event.type = KNI_GetIntField(eventObj, typeFieldID); event.intParam1 = KNI_GetIntField(eventObj, intParam1FieldID); event.intParam2 = KNI_GetIntField(eventObj, intParam2FieldID); event.intParam3 = KNI_GetIntField(eventObj, intParam3FieldID); event.intParam4 = KNI_GetIntField(eventObj, intParam4FieldID); event.intParam5 = KNI_GetIntField(eventObj, intParam5FieldID); do { GET_STRING_EVENT_FIELD(eventObj, stringParam1FieldID, stringObj, event.stringParam1); GET_STRING_EVENT_FIELD(eventObj, stringParam2FieldID, stringObj, event.stringParam2); GET_STRING_EVENT_FIELD(eventObj, stringParam3FieldID, stringObj, event.stringParam3); GET_STRING_EVENT_FIELD(eventObj, stringParam4FieldID, stringObj, event.stringParam4); GET_STRING_EVENT_FIELD(eventObj, stringParam5FieldID, stringObj, event.stringParam5); GET_STRING_EVENT_FIELD(eventObj, stringParam6FieldID, stringObj, event.stringParam6); noExceptions = 1; } while (0); KNI_EndHandles(); if (noExceptions) { StoreMIDPEventInVmThread(event, isolateId); } else { freeMIDPEventFields(event); } KNI_ReturnVoid(); }
void ChameleonMScreen::mouseMoveEvent( QMouseEvent *mouse) { MidpEvent evt; MIDP_EVENT_INITIALIZE(evt); evt.type = MIDP_PEN_EVENT; evt.ACTION = KEYMAP_STATE_DRAGGED; evt.X_POS = mouse->x(); evt.Y_POS = mouse->y(); midpStoreEventAndSignalForeground(evt); }
DWORD WINAPI CreateWinCEWindow(LPVOID lpParam) { static MidpReentryData newSignal; static MidpEvent newMidpEvent; int screenSize = sizeof(gxj_pixel_type) * CHAM_WIDTH * CHAM_HEIGHT; /* IMPL_NOTE: Need a better way to load the library */ #ifdef CVM_PRELOAD_LIB instanceMain = LoadLibrary(TEXT("cvmi.dll")); #else #ifdef CVM_DEBUG instanceMain = LoadLibrary(TEXT("libmidp_g.dll")); #else instanceMain = LoadLibrary(TEXT("libmidp.dll")); #endif #endif gxj_system_screen_buffer.width = CHAM_WIDTH; gxj_system_screen_buffer.height = CHAM_HEIGHT; gxj_system_screen_buffer.alphaData = 0; gxj_system_screen_buffer.pixelData = (gxj_pixel_type *)midpMalloc(screenSize); memset(gxj_system_screen_buffer.pixelData, 0xff, screenSize); if (!init_windows(GetModuleHandle(NULL), SW_SHOW)) { REPORT_ERROR(LC_AMS, "init_gui() failed"); MessageBox(NULL, TEXT("Failed to start JWC"), TEXT("Bye"), MB_OK); } updateVisibleDesktop(); #if JWC_WINCE_USE_DIRECT_DRAW init_DirectDraw(); #else if (GXOpenDisplay(hwndMain, 0) == 0) { REPORT_ERROR(LC_HIGHUI, "GXOpenDisplay() failed"); } gxDispProps = GXGetDisplayProperties(); #endif createEditors(); #ifdef ENABLE_JSR_184 engine_initialize(); #endif MIDP_EVENT_INITIALIZE(newMidpEvent); while (1) { checkForSystemSignal(&newSignal, &newMidpEvent, 200); } }
/** * Sends a shutdown event to the event queue of the current Isolate. * */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_events_EventQueue_sendShutdownEvent0(void) { MidpEvent event; jint queueId; /* Initialize the event with just the SHUTDOWN type */ MIDP_EVENT_INITIALIZE(event); event.type = EVENT_QUEUE_SHUTDOWN; /* Send the shutdown event. */ queueId = KNI_GetParameterAsInt(1); StoreMIDPEventInVmThreadImp(event, queueId); KNI_ReturnVoid(); }
/** * Sends a shutdown event to the event queue of the current Isolate. * */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_events_EventQueue_sendShutdownEvent(void) { MidpEvent event; jint isolateId; /* Initialize the event with just the SHUTDOWN type */ MIDP_EVENT_INITIALIZE(event); event.type = EVENT_QUEUE_SHUTDOWN; /* Send the shutdown event. */ isolateId = getCurrentIsolateId(); StoreMIDPEventInVmThread(event, isolateId); KNI_ReturnVoid(); }
/** * Store a peer changed event to Java event queue. * * @param compPtr pointer to the MidpComponent structure * @param hint some value up to Java peer to interpret */ static void storePeerChangedEvent(MidpComponent *compPtr, int hint) { MidpEvent event; MIDP_EVENT_INITIALIZE(event); event.type = MIDP_PEER_CHANGED_EVENT; /* Will be compared to FormLFImpl.modelVersion */ event.intParam1 = MidpCurrentScreen->component.modelVersion; /* Will be compared to FormLFImpl.nativeId or * to FormLFImpl.itemLFs[0..numOfLFs].nativeId */ event.intParam2 = (int)compPtr; /* Some integer that is up to Java peer to interpret */ event.intParam3 = hint; midpStoreEventAndSignalForeground(event); }
/** Notifies registered record store listeneres about record store change */ void rms_registry_send_record_store_change_event( int suiteId, pcsl_string *storeName, int changeType, int recordId) { RecordStoreListener *listenerPtr; listenerPtr = findRecordStoreListener(suiteId, storeName); if (listenerPtr != NULL) { int i; pcsl_string_status rc; int taskId = getCurrentIsolateId(); for (i = 0; i < listenerPtr->count; i++) { int listenerId = listenerPtr->listenerId[i]; if (listenerId != taskId) { int counter; MidpEvent evt; int requiresAcknowledgment = 0; /* Request acknowledgment from receiver after sending a series * of notifications to protect receiver from queue overflow. */ counter = incNotificationCounter(listenerId); if (counter == RECORD_STORE_NOTIFICATION_QUEUE_SIZE / 2) { requiresAcknowledgment = 1; } MIDP_EVENT_INITIALIZE(evt); evt.type = RECORD_STORE_CHANGE_EVENT; evt.intParam1 = suiteId; evt.intParam2 = changeType; evt.intParam3 = recordId; evt.intParam4 = requiresAcknowledgment; rc = pcsl_string_dup(storeName, &evt.stringParam1); if (rc != PCSL_STRING_OK) { REPORT_CRIT(LC_RMS, "rms_registry_notify_record_store_change(): OUT OF MEMORY"); return; } StoreMIDPEventInVmThread(evt, listenerId); REPORT_INFO1(LC_RMS, "rms_registry_notify_record_store_change(): " "notify VM task %d of RMS changes", listenerId); } } } }
void ChameleonMScreen::keyReleaseEvent(QKeyEvent *key) { if (!seen_key_press || key->isAutoRepeat()) { /* * We may have a left-over keyReleaseEvent from a previous * invocation of the VM! */ return; } MidpEvent evt; MIDP_EVENT_INITIALIZE(evt); if ((evt.CHR = mapKey(key)) != KEYMAP_KEY_INVALID) { evt.type = MIDP_KEY_EVENT; evt.ACTION = KEYMAP_STATE_RELEASED; midpStoreEventAndSignalForeground(evt); } }
/** * Gets the next pending event for an isolate. * <p> * <b>NOTE:</b> Any string parameter data must be de-allocated with * <tt>midpFree</tt>. * * @param pResult where to put the pending event * @param isolateId ID of an Isolate or 0 for SVM mode * * @return -1 for no event pending, number of event still pending after this * event */ static int getPendingMIDPEvent(MidpEvent* pResult, int isolateId) { EventQueue* pEventQueue = getIsolateEventQueue(isolateId); if (pEventQueue->numEvents == 0) { return -1; } *pResult = pEventQueue->events[pEventQueue->eventOut]; /* Empty out the events so we do not free it when finalizing. */ MIDP_EVENT_INITIALIZE(pEventQueue->events[pEventQueue->eventOut]); pEventQueue->numEvents--; pEventQueue->eventOut++; if (pEventQueue->eventOut == MAX_EVENTS) { /* This is a circular queue start back a zero. */ pEventQueue->eventOut = 0; } return pEventQueue->numEvents; }
void FOX_FASTCALL(midp_check_events)(jlonglong timeout) { #else void midp_check_events(JVMSPI_BlockedThreadInfo *blocked_threads, int blocked_threads_count, jlong timeout) { if (midp_waitWhileSuspended()) { /* System has been requested to resume. Returning control to VM * to perform java-side resume routines. Timeout may be too long * here or even -1, thus do not check other events this time. */ return; } #endif newSignal.waitingFor = NO_SIGNAL; newSignal.pResult = ADDR_ZERO; MIDP_EVENT_INITIALIZE(newMidpEvent); checkForSystemSignal(&newSignal, &newMidpEvent, timeout); 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: midpStoreEventAndSignalForeground(newMidpEvent); break; case NETWORK_READ_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else 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); } #endif #if (ENABLE_JSR_120 || ENABLE_JSR_205) else jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor); #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)) #endif #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); #endif break; case NETWORK_EXCEPTION_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else /* 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); #endif return; case PUSH_ALARM_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else 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); } #endif break; #if (ENABLE_JSR_135 || ENABLE_JSR_234) case MEDIA_EVENT_SIGNAL: StoreMIDPEventInVmThread(newMidpEvent, newMidpEvent.MM_ISOLATE); eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_EVENT_SIGNAL, newSignal.descriptor, newSignal.status); break; case MEDIA_SNAPSHOT_SIGNAL: eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_SNAPSHOT_SIGNAL, newSignal.descriptor, newSignal.status); 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); 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 */ default: break; } /* switch */ } /** * Runs the VM in either master or slave mode depending on the * platform. It does not return until the VM is finished. In slave mode * it will contain a system event loop. * * @param classPath string containing the class path * @param mainClass string containing the main class for the VM to run. * @param argc the number of arguments to pass to the main method * @param argv the arguments to pass to the main method * * @return exit status of the VM */ #if 0 int midpRunVm(JvmPathChar* classPath, char* mainClass, int argc, char** argv) { /* Master mode does not need VM time slice requests. */ midp_thread_set_timeslice_proc(ADDR_ZERO); return JVM_Start(classPath, mainClass, argc, argv); }
/* * This function is called by the VM periodically. It has to check if * any of the blocked threads are ready for execution, and call * SNI_UnblockThread() on those threads that are ready. * * Values for the <timeout> paramater: * >0 = Block until an event happens, or until <timeout> milliseconds * has elapsed. * 0 = Check the events sources but do not block. Return to the * caller immediately regardless of the status of the event sources. * -1 = Do not timeout. Block until an event happens. */ void midp_check_events(JVMSPI_BlockedThreadInfo *blocked_threads, int blocked_threads_count, jlong timeout) { if (midp_waitWhileSuspended()) { /* System has been requested to resume. Returning control to VM * to perform java-side resume routines. Timeout may be too long * here or even -1, thus do not check other events this time. */ return; } newSignal.waitingFor = 0; newSignal.pResult = NULL; MIDP_EVENT_INITIALIZE(newMidpEvent); checkForSystemSignal(&newSignal, &newMidpEvent, timeout); 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: midpStoreEventAndSignalForeground(newMidpEvent); 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); #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)) #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); return; 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: StoreMIDPEventInVmThread(newMidpEvent, newMidpEvent.MM_ISOLATE); eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_EVENT_SIGNAL, newSignal.descriptor, newSignal.status); break; case MEDIA_SNAPSHOT_SIGNAL: eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_SNAPSHOT_SIGNAL, newSignal.descriptor, newSignal.status); 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); 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 */ default: break; } /* switch */ }