OSStatus TkMacOSXReceiveAndProcessEvent() { static EventTargetRef targetRef = NULL; EventRef eventRef; OSStatus err; /* * This is a poll, since we have already counted the events coming * into this routine, and are guaranteed to have one waiting. */ err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef); if (err == noErr) { if (!targetRef) { targetRef = GetEventDispatcherTarget(); } TkMacOSXStartTclEventLoopCarbonTimer(); err = SendEventToEventTarget(eventRef,targetRef); TkMacOSXStopTclEventLoopCarbonTimer(); #ifdef TK_MAC_DEBUG if (err != noErr && err != eventLoopTimedOutErr && err != eventNotHandledErr ) { char buf [256]; fprintf(stderr, "RCNE SendEventToEventTarget (%s) failed, %d\n", CarbonEventToAscii(eventRef, buf), (int)err); } #endif ReleaseEvent(eventRef); } return err; }
// Is a message/event pending? bool wxApp::Pending() { // without the receive event (with pull param = false ) nothing is ever reported EventRef theEvent; ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent); return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; }
void MessagePump::dispatchAll() { _initReceiverQueue(); while( true ) { EventRef event; if( _needGlobalLock ) Global::enterCarbon(); const OSStatus status = ReceiveNextEvent( 0, 0, 0.0, true, &event ); if( status == eventLoopTimedOutErr ) break; if( status != noErr ) { EQWARN << "ReceiveNextEvent failed: " << status << std::endl; break; } EQVERB << "Dispatch Carbon event " << event << std::endl; if( !_needGlobalLock ) Global::enterCarbon(); const EventTargetRef target = GetEventDispatcherTarget(); SendEventToEventTarget( event, target ); Global::leaveCarbon(); ReleaseEvent( event ); } if( _needGlobalLock ) Global::leaveCarbon(); }
void wxApp::MacDoOneEvent() { wxMacAutoreleasePool autoreleasepool; EventRef theEvent; s_inReceiveEvent = true ; OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ; s_inReceiveEvent = false ; switch (status) { case eventLoopTimedOutErr : if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait ; else sleepTime = kEventDurationSecond; break; case eventLoopQuitErr : // according to QA1061 this may also occur // when a WakeUp Process is executed break; default: MacHandleOneEvent( theEvent ) ; ReleaseEvent( theEvent ); sleepTime = kEventDurationNoWait ; break; } // repeaters DeletePendingObjects() ; wxMacProcessNotifierAndPendingEvents() ; }
int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout) { wxMacAutoreleasePool autoreleasepool; EventRef event; OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); switch ( status ) { default: wxFAIL_MSG( "unexpected ReceiveNextEvent() error" ); // fall through case eventLoopTimedOutErr: return -1; case eventLoopQuitErr: // according to QA1061 this may also occur // when a WakeUp Process is executed return 0; case noErr: DispatchAndReleaseEvent(event); return 1; } }
IEventQueueBuffer::Type OSXEventQueueBuffer::getEvent(Event& event, UInt32& dataID) { // release the previous event if (m_event != NULL) { ReleaseEvent(m_event); m_event = NULL; } // get the next event OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &m_event); // handle the event if (error == eventLoopQuitErr) { event = Event(Event::kQuit); return kSystem; } else if (error != noErr) { return kNone; } else { UInt32 eventClass = GetEventClass(m_event); switch (eventClass) { case 'Syne': dataID = GetEventKind(m_event); return kUser; default: event = Event(Event::kSystem, m_eventQueue->getSystemTarget(), &m_event); return kSystem; } } }
void wxApp::MacDoOneEvent() { EventRef theEvent; s_inReceiveEvent = true ; OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ; s_inReceiveEvent = false ; if ( status == eventLoopTimedOutErr ) { if ( wxTheApp->ProcessIdle() ) sleepTime = kEventDurationNoWait ; else sleepTime = kEventDurationSecond; } else if ( status == eventLoopQuitErr ) { // according to QA1061 this may also occur when a WakeUp Process // is executed } else { MacHandleOneEvent( theEvent ) ; ReleaseEvent(theEvent); sleepTime = kEventDurationNoWait ; } // repeaters DeletePendingObjects() ; wxMacProcessNotifierAndPendingEvents() ; }
bool OSXEventQueueBuffer::isEmpty() const { EventRef event; OSStatus status = ReceiveNextEvent(0, NULL, 0.0, false, &event); return (status == eventLoopTimedOutErr); }
bool wxApp::Yield(bool onlyIfNeeded) { if (s_inYield) { if ( !onlyIfNeeded ) { wxFAIL_MSG( wxT("wxYield called recursively" ) ); } return false; } #if wxUSE_THREADS // Yielding from a non-gui thread needs to bail out, otherwise we end up // possibly sending events in the thread too. if ( !wxThread::IsMain() ) { return true; } #endif // wxUSE_THREADS s_inYield = true; // by definition yield should handle all non-processed events EventRef theEvent; OSStatus status = noErr ; while ( status == noErr ) { s_inReceiveEvent = true ; status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; s_inReceiveEvent = false ; if ( status == eventLoopTimedOutErr ) { // make sure next time the event loop will trigger idle events sleepTime = kEventDurationNoWait ; } else if ( status == eventLoopQuitErr ) { // according to QA1061 this may also occur when a WakeUp Process // is executed } else { MacHandleOneEvent( theEvent ) ; ReleaseEvent(theEvent); } } wxMacProcessNotifierAndPendingEvents() ; s_inYield = false; return true; }
//--------------------------------------------------------------------------------// void WindowEventUtilities::messagePump() { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 // Windows Message Loop (NULL means check all HWNDs belonging to this context) MSG msg; while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX //GLX Message Pump RenderWindowList::iterator win = _msWindows.begin(); RenderWindowList::iterator end = _msWindows.end(); Display* xDisplay = 0; // same for all windows for (; win != end; win++) { XID xid; XEvent event; if (!xDisplay) (*win)->getCustomAttribute("XDISPLAY", &xDisplay); (*win)->getCustomAttribute("WINDOW", &xid); while (XCheckWindowEvent (xDisplay, xid, StructureNotifyMask | VisibilityChangeMask | FocusChangeMask, &event)) { GLXProc(*win, event); } // The ClientMessage event does not appear under any Event Mask while (XCheckTypedWindowEvent (xDisplay, xid, ClientMessage, &event)) { GLXProc(*win, event); } } #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE && !defined __OBJC__ && !defined __LP64__ // OSX Message Pump EventRef event = NULL; EventTargetRef targetWindow; targetWindow = GetEventDispatcherTarget(); // If we are unable to get the target then we no longer care about events. if( !targetWindow ) return; // Grab the next event, process it if it is a window event while( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr ) { // Dispatch the event SendEventToEventTarget( event, targetWindow ); ReleaseEvent( event ); } #endif }
void QuartzWindow::check_carbon_events() { BlockGlueFlag f(quartz_semaphore); for (;;) { EventRef evt; ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &evt); if (!evt) return; SendEventToEventTarget(evt, GetEventDispatcherTarget()); } }
void _glfwPlatformWaitEvents( void ) { EventRef event; // Wait for new events ReceiveNextEvent( 0, NULL, kEventDurationForever, FALSE, &event ); // Poll new events _glfwPlatformPollEvents(); }
void CL_DisplayWindow_OpenGL::keep_alive() { EventRef theEvent; while(ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent)== noErr) { SendEventToEventTarget (theEvent, target_ref); ReleaseEvent(theEvent); } }
void appleMultiContext::checkEvent() { // Event management for Apple EventRef theEvent; EventTargetRef theTarget; theTarget = GetEventDispatcherTarget(); while (ReceiveNextEvent(0, NULL,kEventDurationNoWait,true, &theEvent) == noErr) { SendEventToEventTarget (theEvent, theTarget); ReleaseEvent(theEvent); } }
void _glfwPlatformPollEvents( void ) { EventRef event; EventTargetRef eventDispatcher = GetEventDispatcherTarget(); while ( ReceiveNextEvent( 0, NULL, 0.0, TRUE, &event ) == noErr ) { SendEventToEventTarget( event, eventDispatcher ); ReleaseEvent( event ); } }
bool wxGUIEventLoop::Pending() const { EventRef theEvent; return ReceiveNextEvent ( 0, // we want any event at all so we don't specify neither NULL, // the number of event types nor the types themselves kEventDurationNoWait, false, // don't remove the event from queue &theEvent ) == noErr; }
bool wxApp::Yield(bool onlyIfNeeded) { if (s_inYield) { if ( !onlyIfNeeded ) { wxFAIL_MSG( wxT("wxYield called recursively" ) ); } return FALSE; } s_inYield = TRUE; // by definition yield should handle all non-processed events EventRef theEvent; OSStatus status = noErr ; do { s_inReceiveEvent = true ; status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; s_inReceiveEvent = false ; if ( status == eventLoopTimedOutErr ) { // make sure next time the event loop will trigger idle events sleepTime = kEventDurationNoWait ; } else if ( status == eventLoopQuitErr ) { // according to QA1061 this may also occur when a WakeUp Process // is executed } else { MacHandleOneEvent( theEvent ) ; ReleaseEvent(theEvent); } } while( status == noErr ) ; wxMacProcessNotifierAndPendingEvents() ; s_inYield = FALSE; return TRUE; }
void MacOSXLoop::run() { // Main event loop while( !m_exit ) { EventRef pEvent; OSStatus err = ReceiveNextEvent( 0, NULL, kEventDurationForever, true, &pEvent ); if( err != noErr ) { // Get the event type UInt32 evClass = GetEventClass( pEvent ); switch( evClass ) { case kEventClassMouse: { break; } case kEventClassKeyboard: { break; } case kEventClassWindow: { handleWindowEvent( pEvent ); break; } default: { EventTargetRef pTarget; pTarget = GetEventDispatcherTarget(); SendEventToEventTarget( pEvent, pTarget ); ReleaseEvent( pEvent ); } } } } }
static int ReceiveAndProcessEvent() { TkMacOSXEvent macEvent; MacEventStatus eventStatus; int err; char buf [ 256 ]; /* * This is a poll, since we have already counted the events coming * into this routine, and are guaranteed to have one waiting. */ err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &macEvent.eventRef); if (err != noErr) { return err; } else { macEvent.eClass = GetEventClass(macEvent.eventRef); macEvent.eKind = GetEventKind(macEvent.eventRef); bzero(&eventStatus, sizeof(eventStatus)); TkMacOSXProcessEvent(&macEvent,&eventStatus); if (!eventStatus.stopProcessing) { if (!targetRef) { targetRef = GetEventDispatcherTarget(); } err = SendEventToEventTarget(macEvent.eventRef,targetRef); if (err != noErr #if !TK_MAC_DEBUG && err != eventNotHandledErr #endif ) { fprintf(stderr, "RCNE SendEventToEventTarget (%s) failed, %d\n", CarbonEventToAscii(macEvent.eventRef, buf),err); } } ReleaseEvent(macEvent.eventRef); return 0; } }
gii_event_mask GII_quartz_eventpoll(gii_input *inp, void *arg) { gii_event_mask mask = 0; EventRef theEvent; EventTargetRef theTarget; OSStatus theErr; /* Get event */ theTarget = GetEventDispatcherTarget(); theErr = ReceiveNextEvent(0,0, kEventDurationNoWait, TRUE, &theEvent); if (theErr == noErr && theEvent != NULL) { mask = transEvent2Mask(theEvent); SendEventToEventTarget(theEvent, theTarget); ReleaseEvent(theEvent); } /* if */ return mask; } /* GII_quartz_eventpoll */
int wxGUIEventLoop::DispatchTimeout(unsigned long timeout) { EventRef event; OSStatus status = ReceiveNextEvent(0, NULL, timeout/1000, true, &event); switch ( status ) { default: wxFAIL_MSG( "unexpected ReceiveNextEvent() error" ); // fall through case eventLoopTimedOutErr: return -1; case eventLoopQuitErr: return 0; case noErr: DispatchAndReleaseEvent(event); return 1; } }
bool wxGUIEventLoop::Dispatch() { if ( !wxTheApp ) return false; wxMacAutoreleasePool autoreleasepool; EventRef theEvent; OSStatus status = ReceiveNextEvent(0, NULL, m_sleepTime, true, &theEvent) ; switch (status) { case eventLoopTimedOutErr : if ( wxTheApp->ProcessIdle() ) m_sleepTime = kEventDurationNoWait ; else { m_sleepTime = kEventDurationSecond; #if wxUSE_THREADS wxMutexGuiLeave(); wxMilliSleep(20); wxMutexGuiEnter(); #endif } break; case eventLoopQuitErr : // according to QA1061 this may also occur // when a WakeUp Process is executed break; default: DispatchAndReleaseEvent(theEvent); m_sleepTime = kEventDurationNoWait ; break; } return true; }
void MessagePump::dispatchOne( const uint32_t timeout ) { _initReceiverQueue(); _clock.reset(); for( int64_t timeLeft = timeout; timeleft >= 0; timeleft = timeout - _clock.getTime64( )) { if( _needGlobalLock ) Global::enterCarbon(); EventRef event; const float wait = EQ_MIN( float( timeLeft ) * .001f, .05f /* 50ms */ ); const OSStatus status = ReceiveNextEvent( 0, 0, wait, true, &event ); if( status == noErr ) { LBVERB << "Dispatch Carbon event " << event << std::endl; if( !_needGlobalLock ) Global::enterCarbon(); const EventTargetRef target = GetEventDispatcherTarget(); SendEventToEventTarget( event, target ); Global::leaveCarbon(); ReleaseEvent( event ); return; } if( _needGlobalLock ) Global::leaveCarbon(); if( status != eventLoopTimedOutErr ) { LBWARN << "ReceiveNextEvent failed: " << status << std::endl; return; } } }
//----------------------------------------------------------------------------- void PluginGUIEditor::doIdleStuff () { // get the current time uint32_t currentTicks = getTicks (); // YG TEST idle (); if (currentTicks < lLastTicks) { #if (MAC && TARGET_API_MAC_CARBON) RunCurrentEventLoop (kEventDurationMillisecond * kIdleRateMin); #else wait (kIdleRateMin); #endif currentTicks += kIdleRateMin; if (currentTicks < lLastTicks - kIdleRate2) return; } idle (); // TEST #if WINDOWS struct tagMSG windowsMessage; if (PeekMessage (&windowsMessage, NULL, WM_PAINT, WM_PAINT, PM_REMOVE)) DispatchMessage (&windowsMessage); #elif MAC && !__LP64__ EventRef event; EventTypeSpec eventTypes[] = { {kEventClassWindow, kEventWindowUpdate}, {kEventClassWindow, kEventWindowDrawContent} }; if (ReceiveNextEvent (GetEventTypeCount (eventTypes), eventTypes, kEventDurationNoWait, true, &event) == noErr) { SendEventToEventTarget (event, GetEventDispatcherTarget ()); ReleaseEvent (event); } #endif // save the next time lLastTicks = currentTicks + kIdleRate; }
void CSMNativeWindow::carbonMainLoop(void) { EventRef pEvent; EventTargetRef pTarget = GetEventDispatcherTarget(); while(_bRun == true) { while(ReceiveNextEvent(0, NULL, 0, //kEventDurationForever, true, &pEvent) == noErr) { SendEventToEventTarget(pEvent, pTarget); ReleaseEvent (pEvent ); } ComplexSceneManager::the()->frame(); Thread::getCurrentChangeList()->commitChangesAndClear(); } ComplexSceneManager::the()->terminate(); }
bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherMac); #if 0 //TrackDrag says you may not use the EventManager things.. if(qt_mac_in_drag) { qWarning("Qt: Cannot process events whilst dragging!"); return false; } #endif d->interrupt = false; emit awake(); #ifndef QT_MAC_NO_QUICKDRAW if(!qt_mac_safe_pdev) { //create an empty widget and this can be used for a port anytime QWidget *tlw = new QWidget; tlw->setAttribute(Qt::WA_DeleteOnClose); tlw->setObjectName(QLatin1String("empty_widget")); tlw->hide(); qt_mac_safe_pdev = tlw; } #endif bool retVal = false; for (;;) { QApplicationPrivate::sendPostedEvents(0, 0, d->threadData); if (d->activateTimers() > 0) //send null timers retVal = true; do { EventRef event; if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) { // process a pending user input event event = d->queuedUserInputEvents.takeFirst(); } else { OSStatus err = ReceiveNextEvent(0,0, kEventDurationNoWait, true, &event); if(err != noErr) continue; // else if (flags & QEventLoop::ExcludeUserInputEvents) { UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); switch(eclass) { case kEventClassQt: if(ekind != kEventQtRequestContext) break; // fall through case kEventClassMouse: case kEventClassKeyboard: d->queuedUserInputEvents.append(event); continue; } } } if (!filterEvent(&event) && qt_mac_send_event(flags, event)) retVal = true; ReleaseEvent(event); } while(!d->interrupt && GetNumEventsInQueue(GetMainEventQueue()) > 0); bool canWait = (d->threadData->canWait && !retVal && !d->interrupt && (flags & QEventLoop::WaitForMoreEvents) && !d->zero_timer_count); if (canWait) { emit aboutToBlock(); while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, true) == kCFRunLoopRunTimedOut); flags &= ~QEventLoop::WaitForMoreEvents; emit awake(); } else { CFRunLoopRunInMode(kCFRunLoopDefaultMode, kEventDurationNoWait, true); break; } } return retVal; }
int main(int argc, char **argv) #endif { ll_init_apr(); // Set up llerror logging { LLError::initForApplication("."); LLError::setDefaultLevel(LLError::LEVEL_INFO); // LLError::setTagLevel("Plugin", LLError::LEVEL_DEBUG); // LLError::logToFile("slplugin.log"); } #if LL_WINDOWS if( strlen( lpCmdLine ) == 0 ) { LL_ERRS("slplugin") << "usage: " << "SLPlugin" << " launcher_port" << LL_ENDL; }; U32 port = 0; if(!LLStringUtil::convertToU32(lpCmdLine, port)) { LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL; }; // Insert our exception handler into the system so this plugin doesn't // display a crash message if something bad happens. The host app will // see the missing heartbeat and log appropriately. initExceptionHandler(); #elif LL_DARWIN || LL_LINUX if(argc < 2) { LL_ERRS("slplugin") << "usage: " << argv[0] << " launcher_port" << LL_ENDL; } U32 port = 0; if(!LLStringUtil::convertToU32(argv[1], port)) { LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL; } // Catch signals that most kinds of crashes will generate, and exit cleanly so the system crash dialog isn't shown. signal(SIGILL, &crash_handler); // illegal instruction # if LL_DARWIN signal(SIGEMT, &crash_handler); // emulate instruction executed # endif // LL_DARWIN signal(SIGFPE, &crash_handler); // floating-point exception signal(SIGBUS, &crash_handler); // bus error signal(SIGSEGV, &crash_handler); // segmentation violation signal(SIGSYS, &crash_handler); // non-existent system call invoked #endif LLPluginProcessChild *plugin = new LLPluginProcessChild(); plugin->init(port); LLTimer timer; timer.start(); #if LL_WINDOWS checkExceptionHandler(); #endif #if LL_DARWIN EventTargetRef event_target = GetEventDispatcherTarget(); #endif while(!plugin->isDone()) { timer.reset(); plugin->idle(); #if LL_DARWIN { // Some plugins (webkit at least) will want an event loop. This qualifies. EventRef event; if(ReceiveNextEvent(0, 0, kEventDurationNoWait, true, &event) == noErr) { SendEventToEventTarget (event, event_target); ReleaseEvent(event); } } #endif F64 elapsed = timer.getElapsedTimeF64(); F64 remaining = plugin->getSleepTime() - elapsed; if(remaining <= 0.0f) { // We've already used our full allotment. // LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, not sleeping" << LL_ENDL; // Still need to service the network... plugin->pump(); } else { // LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, sleeping for " << remaining * 1000.0f << " ms" << LL_ENDL; // timer.reset(); // This also services the network as needed. plugin->sleep(remaining); // LL_INFOS("slplugin") << "slept for "<< timer.getElapsedTimeF64() * 1000.0f << " ms" << LL_ENDL; } #if LL_WINDOWS // More agressive checking of interfering exception handlers. // Doesn't appear to be required so far - even for plugins // that do crash with a single call to the intercept // exception handler such as QuickTime. //checkExceptionHandler(); #endif } delete plugin; ll_cleanup_apr(); return 0; }
void osx_launch_special_handling(MCAP_CMD_S *mc_cmd, char *image_file) { CFStringRef str_ref = NULL; CFURLRef url_ref = NULL; LSLaunchFSRefSpec launch_spec; FSRef app_ref, file_ref; static EXEC_EVENT_DATA_S event_data; install_app_launch_cb((void *)&event_data); if((str_ref = CFStringCreateWithCString(NULL, mc_cmd->command, kCFStringEncodingASCII)) == NULL) return; if((url_ref = CFURLCreateWithString(NULL, str_ref, NULL)) == NULL) return; if(CFURLGetFSRef(url_ref, &app_ref) == false) return; if(FSPathMakeRef((unsigned char *)image_file, &file_ref, NULL) != noErr) return; launch_spec.appRef = &app_ref; launch_spec.numDocs = 1; launch_spec.itemRefs = &file_ref; launch_spec.passThruParams = NULL; launch_spec.launchFlags = kLSLaunchDontAddToRecents | kLSLaunchNoParams | kLSLaunchAsync | kLSLaunchNewInstance; /* would want to use this if we ever did true event handling */ launch_spec.asyncRefCon = 0; if(LSOpenFromRefSpec( &launch_spec, NULL) == noErr){ /* * Here's the strategy: we want to be able to just launch * the app and then just delete the temp file, but that * doesn't work because the called app needs the temp file * at least until it's finished loading. Being that there's * no way to tell when the app has finished loading, we wait * until the program has exited, which is the safest thing to * do and is what we do for windows. Since we haven't totally * embraced event handling at this point, we must do the waiting * synchronously. We allow for a keystroke to stop waiting, and * just delete the temp file. * Ideally, we would launch the app, and keep running, checking * the events until the process terminates, and then delete the * temp file. In this method, we would delete the temp file * at close time if the app was still running. */ int ch; OSStatus rne_rv; EventTargetRef target; EventRef out_event; EventTypeSpec event_types[2] = { {kEventClassApplication, kEventAppTerminated}, {kEventClassApplication, kEventAppLaunchNotification}}; q_status_message(SM_ORDER, 0, 4, "Waiting for program to finish, or press a key to stop waiting..."); flush_status_messages(1); target = GetEventDispatcherTarget(); event_data.done = 0; event_data.set_pid = 0; while(!event_data.done){ if((rne_rv = ReceiveNextEvent(2, event_types, 1, true, &out_event)) == noErr){ SendEventToEventTarget(out_event, target); ReleaseEvent(out_event); } else if(rne_rv == eventLoopTimedOutErr){ ch = read_char(1); if(ch) event_data.done = 1; } else if(rne_rv == eventLoopQuitErr) event_data.done = 1; } our_unlink(image_file); } q_status_message(SM_ORDER, 0, 4, "VIEWER command completed"); }
void OSXEventQueueBuffer::waitForEvent(double timeout) { EventRef event; ReceiveNextEvent(0, NULL, timeout, false, &event); }
int main(int argc, char **argv) #endif { ll_init_apr(); // Set up llerror logging { LLError::initForApplication("."); LLError::setDefaultLevel(LLError::LEVEL_INFO); // LLError::setTagLevel("Plugin", LLError::LEVEL_DEBUG); // LLError::logToFile("slplugin.log"); } #if LL_WINDOWS if( strlen( lpCmdLine ) == 0 ) { LL_ERRS("slplugin") << "usage: " << "SLPlugin" << " launcher_port" << LL_ENDL; }; U32 port = 0; if(!LLStringUtil::convertToU32(lpCmdLine, port)) { LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL; }; // Insert our exception handler into the system so this plugin doesn't // display a crash message if something bad happens. The host app will // see the missing heartbeat and log appropriately. initExceptionHandler(); #elif LL_DARWIN || LL_LINUX if(argc < 2) { LL_ERRS("slplugin") << "usage: " << argv[0] << " launcher_port" << LL_ENDL; } U32 port = 0; if(!LLStringUtil::convertToU32(argv[1], port)) { LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL; } // Catch signals that most kinds of crashes will generate, and exit cleanly so the system crash dialog isn't shown. signal(SIGILL, &crash_handler); // illegal instruction # if LL_DARWIN signal(SIGEMT, &crash_handler); // emulate instruction executed # endif // LL_DARWIN signal(SIGFPE, &crash_handler); // floating-point exception signal(SIGBUS, &crash_handler); // bus error signal(SIGSEGV, &crash_handler); // segmentation violation signal(SIGSYS, &crash_handler); // non-existent system call invoked #endif #if LL_DARWIN setupCocoa(); createAutoReleasePool(); #endif LLPluginProcessChild *plugin = new LLPluginProcessChild(); plugin->init(port); #if LL_DARWIN deleteAutoReleasePool(); #endif LLTimer timer; timer.start(); #if LL_WINDOWS checkExceptionHandler(); #endif #if LL_DARWIN // If the plugin opens a new window (such as the Flash plugin's fullscreen player), we may need to bring this plugin process to the foreground. // Use this to track the current frontmost window and bring this process to the front if it changes. WindowRef front_window = NULL; WindowGroupRef layer_group = NULL; int window_hack_state = 0; CreateWindowGroup(kWindowGroupAttrFixedLevel, &layer_group); if(layer_group) { // Start out with a window layer that's way out in front (fixes the problem with the menubar not getting hidden on first switch to fullscreen youtube) SetWindowGroupName(layer_group, CFSTR("SLPlugin Layer")); SetWindowGroupLevel(layer_group, kCGOverlayWindowLevel); } #endif #if LL_DARWIN EventTargetRef event_target = GetEventDispatcherTarget(); #endif while(!plugin->isDone()) { #if LL_DARWIN createAutoReleasePool(); #endif timer.reset(); plugin->idle(); #if LL_DARWIN { // Some plugins (webkit at least) will want an event loop. This qualifies. EventRef event; if(ReceiveNextEvent(0, 0, kEventDurationNoWait, true, &event) == noErr) { SendEventToEventTarget (event, event_target); ReleaseEvent(event); } // Check for a change in this process's frontmost window. if(FrontWindow() != front_window) { ProcessSerialNumber self = { 0, kCurrentProcess }; ProcessSerialNumber parent = { 0, kNoProcess }; ProcessSerialNumber front = { 0, kNoProcess }; Boolean this_is_front_process = false; Boolean parent_is_front_process = false; { // Get this process's parent ProcessInfoRec info; info.processInfoLength = sizeof(ProcessInfoRec); info.processName = NULL; info.processAppSpec = NULL; if(GetProcessInformation( &self, &info ) == noErr) { parent = info.processLauncher; } // and figure out whether this process or its parent are currently frontmost if(GetFrontProcess(&front) == noErr) { (void) SameProcess(&self, &front, &this_is_front_process); (void) SameProcess(&parent, &front, &parent_is_front_process); } } if((FrontWindow() != NULL) && (front_window == NULL)) { // Opening the first window if(window_hack_state == 0) { // Next time through the event loop, lower the window group layer window_hack_state = 1; } if(layer_group) { SetWindowGroup(FrontWindow(), layer_group); } if(parent_is_front_process) { // Bring this process's windows to the front. (void) SetFrontProcess( &self ); } ActivateWindow(FrontWindow(), true); } else if((FrontWindow() == NULL) && (front_window != NULL)) { // Closing the last window if(this_is_front_process) { // Try to bring this process's parent to the front (void) SetFrontProcess(&parent); } } else if(window_hack_state == 1) { if(layer_group) { // Set the window group level back to something less extreme SetWindowGroupLevel(layer_group, kCGNormalWindowLevel); } window_hack_state = 2; } front_window = FrontWindow(); } } #endif F64 elapsed = timer.getElapsedTimeF64(); F64 remaining = plugin->getSleepTime() - elapsed; if(remaining <= 0.0f) { // We've already used our full allotment. // LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, not sleeping" << LL_ENDL; // Still need to service the network... plugin->pump(); } else { // LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, sleeping for " << remaining * 1000.0f << " ms" << LL_ENDL; // timer.reset(); // This also services the network as needed. plugin->sleep(remaining); // LL_INFOS("slplugin") << "slept for "<< timer.getElapsedTimeF64() * 1000.0f << " ms" << LL_ENDL; } #if LL_WINDOWS // More agressive checking of interfering exception handlers. // Doesn't appear to be required so far - even for plugins // that do crash with a single call to the intercept // exception handler such as QuickTime. //checkExceptionHandler(); #endif #if LL_DARWIN deleteAutoReleasePool(); #endif } delete plugin; ll_cleanup_apr(); return 0; }