Пример #1
0
void wxCFEventLoop::CommonModeObserverCallBack(CFRunLoopObserverRef WXUNUSED(observer), int activity)
{
    if ( activity & kCFRunLoopBeforeTimers )
    {
        // process pending wx events first as they correspond to low-level events
        // which happened before, i.e. typically pending events were queued by a
        // previous call to Dispatch() and if we didn't process them now the next
        // call to it might enqueue them again (as happens with e.g. socket events
        // which would be generated as long as there is input available on socket
        // and this input is only removed from it when pending event handlers are
        // executed)

        if ( wxTheApp && ShouldProcessIdleEvents() )
            wxTheApp->ProcessPendingEvents();
    }

    if ( activity & kCFRunLoopBeforeWaiting )
    {
        if ( ShouldProcessIdleEvents() && ProcessIdle() )
        {
            WakeUp();
        }
        else
        {
#if wxUSE_THREADS
            wxMutexGuiLeaveOrEnter();
#endif
        }
    }
}
Пример #2
0
bool NesulatorApp::DoWindowsEvents()
{
	//if ( g_activeMainboard != NULL && !g_activeMainboard->IsRunning() )
	//	return false;

	while ( !Pending() && ProcessIdle() );

	while ( Pending() )
	{
		if ( !Dispatch() )
		{
			mQuitNow = true;
			break;
		}
	}

	if ( mQuitNow )
	{
		while (Pending())
			Dispatch(); // dispatch final waiting messages
		m_mainLoop = NULL;
	}

	return !mQuitNow;
}
Пример #3
0
/**
 * Provide gcBlue's main loop.
 *
 * Called by wxWindows on creation of the application.
 *
 * @return ??
 */
int GcbApp::MainLoop()
{
    bool m_keepGoing = TRUE;

    while (m_keepGoing)
    {

    #if wxUSE_THREADS
        wxMutexGuiLeaveOrEnter();
    #endif

        while (Pending())
        {
            Dispatch();
        }

        ProcessIdle();

        if (!closeApp)
        {
            if (gameFrame->UpdateFrame())  // called until it returns true
            {
                closeApp = TRUE;
                m_keepGoing = FALSE;
            }
        }
    }

    return 0; // ((MSG*)current_msg)->wParam;
}
Пример #4
0
void WCommandInterpreter_Process() {
    
    /* Reset Condition */
    if (!WCmdMedium_IsRunning() && (GL_WCommandInterpreter_CurrentState_E != WCMD_INTERPRETER_STATE_IDLE))
        TransitionToIdle();

    /* State Machine */ 
	switch (GL_WCommandInterpreter_CurrentState_E) {
		case WCMD_INTERPRETER_STATE_IDLE :
			ProcessIdle();
			break;

        case WCMD_INTERPRETER_STATE_WAIT_PACKET :
            ProcessWaitPacket();
            break;

		case WCMD_INTERPRETER_STATE_CHECK_CMD :
			ProcessCheckCmd();
			break;

		case WCMD_INTERPRETER_STATE_PROCESS_CMD :
			ProcessProcessCmd();
			break;

		case WCMD_INTERPRETER_STATE_SEND_RESP :
			ProcessSendResp();
			break;

	}
}
Пример #5
0
bool wxApp::DoIdle()
{
    guint id_save;
    {
        // Allow another idle source to be added while this one is busy.
        // Needed if an idle event handler runs a new event loop,
        // for example by showing a dialog.
#if wxUSE_THREADS
        wxMutexLocker lock(m_idleMutex);
#endif
        id_save = m_idleSourceId;
        m_idleSourceId = 0;
        wx_add_idle_hooks();

#if wxDEBUG_LEVEL
        // don't generate the idle events while the assert modal dialog is shown,
        // this matches the behaviour of wxMSW
        if (m_isInAssert)
            return false;
#endif
    }

    gdk_threads_enter();
    bool needMore;
    do {
        ProcessPendingEvents();

        needMore = ProcessIdle();
    } while (needMore && gtk_events_pending() == 0);
    gdk_threads_leave();

#if wxUSE_THREADS
    wxMutexLocker lock(m_idleMutex);
#endif
    // if a new idle source was added during ProcessIdle
    if (m_idleSourceId != 0)
    {
        // remove it
        g_source_remove(m_idleSourceId);
        m_idleSourceId = 0;
    }

    // Pending events can be added asynchronously,
    // need to keep idle source if any have appeared
    if (HasPendingEvents())
        needMore = true;

    // if more idle processing requested
    if (needMore)
    {
        // keep this source installed
        m_idleSourceId = id_save;
        return true;
    }
    // add hooks and remove this source
    wx_add_idle_hooks();
    return false;
}
Пример #6
0
Файл: app.cpp Проект: EdgarTx/wx
bool wxApp::Yield(bool onlyIfNeeded)
{
    // Sometimes only 2 yields seem
    // to do the trick, e.g. in the
    // progress dialog
    int i;
    for (i = 0; i < 2; i++)
    {
        static bool s_inYield = false;

        if ( s_inYield )
        {
            if ( !onlyIfNeeded )
            {
                wxFAIL_MSG( wxT("wxYield called recursively" ) );
            }

            return false;
        }

        s_inYield = true;

        // Make sure we have an event loop object,
        // or Pending/Dispatch will fail
        wxEventLoop* eventLoop = wxEventLoop::GetActive();
        wxEventLoop* newEventLoop = NULL;
        if (!eventLoop)
        {
            newEventLoop = new wxEventLoop;
            wxEventLoop::SetActive(newEventLoop);
        }

        // Call dispatch at least once so that sockets
        // can be tested
        wxTheApp->Dispatch();

        while (wxTheApp && wxTheApp->Pending())
            wxTheApp->Dispatch();

#if wxUSE_TIMER
        wxTimer::NotifyTimers();
#endif
        ProcessIdle();

        if (newEventLoop)
        {
            wxEventLoop::SetActive(NULL);
            delete newEventLoop;
        }

        s_inYield = false;
    }

    return true;
}
Пример #7
0
bool wxApp::DoIdle()
{
    guint id_save;
    {
        // Allow another idle source to be added while this one is busy.
        // Needed if an idle event handler runs a new event loop,
        // for example by showing a dialog.
#if wxUSE_THREADS
        wxMutexLocker lock(m_idleMutex);
#endif
        id_save = m_idleSourceId;
        m_idleSourceId = 0;
        wx_add_idle_hooks();

#if wxDEBUG_LEVEL
        // don't generate the idle events while the assert modal dialog is shown,
        // this matches the behaviour of wxMSW
        if (m_isInAssert)
            return false;
#endif
    }

    gdk_threads_enter();
    bool needMore;
    do {
        ProcessPendingEvents();

        needMore = ProcessIdle();
    } while (needMore && gtk_events_pending() == 0);
    gdk_threads_leave();

#if wxUSE_THREADS
    wxMutexLocker lock(m_idleMutex);
#endif

    bool keepSource = false;
    // if a new idle source has not been added, either as a result of idle
    // processing above or by another thread calling WakeUpIdle()
    if (m_idleSourceId == 0)
    {
        // if more idle processing was requested or pending events have appeared
        if (needMore || HasPendingEvents())
        {
            // keep this source installed
            m_idleSourceId = id_save;
            keepSource = true;
        }
        else // add hooks and remove this source
            wx_add_idle_hooks();
    }
    // else remove this source, leave new one installed
    // we must keep an idle source, otherwise a wakeup could be lost

    return keepSource;
}
Пример #8
0
bool wxApp::Yield(bool onlyIfNeeded)
{
    if ( wxIsInsideYield )
    {
        if ( !onlyIfNeeded )
        {
            wxFAIL_MSG( wxT("wxYield called recursively" ) );
        }

        return false;
    }

#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
    {
        // can't call gtk_main_iteration() from other threads like this
        return true;
    }
#endif // wxUSE_THREADS

    wxIsInsideYield = true;

    // We need to remove idle callbacks or the loop will
    // never finish.
    SuspendIdleCallback();

#if wxUSE_LOG
    // disable log flushing from here because a call to wxYield() shouldn't
    // normally result in message boxes popping up &c
    wxLog::Suspend();
#endif

    while (gtk_events_pending())
        gtk_main_iteration();

    // It's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect). But we
    // call ProcessIdle() only once since this is not meant for longish
    // background jobs (controlled by wxIdleEvent::RequestMore() and the
    // return value of Processidle().
    ProcessIdle();

#if wxUSE_LOG
    // let the logs be flashed again
    wxLog::Resume();
#endif

    wxIsInsideYield = false;

    return true;
}
Пример #9
0
void wxCFEventLoop::DoYieldFor(long eventsToProcess)
{
    // process all pending events:
    while ( DoProcessEvents() == 1 )
        ;

    // it's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect)
    while ( ProcessIdle() ) {}

    wxEventLoopBase::DoYieldFor(eventsToProcess);
}
Пример #10
0
// The override of the "game loop" isn't much different from the base class version.
// We purposely render here rather than within in an OnPaint handler.
// This method returns the wParam of the WM_QUIT message.
int TApp::MainLoop()
{
    m_keepGoing = TRUE;

    while (m_keepGoing)
    {
        frame->canvas->Draw();
        while (!Pending() && ProcessIdle())
            ;

        DoMessage();
    }

    return s_currentMsg.wParam;
}
Пример #11
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	g_hInst = hInstance;
	g_hMainWnd = InitWindow(nCmdShow); 

	if(!g_hMainWnd)
		return -1;

	if(InitDirectDraw() < 0)
	{
		CleanUp();
		MessageBox(g_hMainWnd, "Could start DirectX engine in your computer. Make sure you have at least version 7 of DirectX installed.", "Error", MB_OK | MB_ICONEXCLAMATION);
		return 0;
	}


	g_surfCar.Create(g_pDD, 1500, 280);
	g_surfCar.LoadBitmap(g_hInst, IDB_GREENCAR, 0, 0, 1500, 280);
	
    while( TRUE )
    {
        MSG msg;

        if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
        {
            // Check for a quit message
            if( msg.message == WM_QUIT )
                break;

            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
            ProcessIdle();
        }
    }

	CleanUp();

	return 0;
}
Пример #12
0
void wxGUIEventLoop::DoYieldFor(long eventsToProcess)
{
    // TODO: implement event filtering using the eventsToProcess mask

    // process all pending events:
    while ( Pending() )
        Dispatch();

    // handle timers, sockets etc.
    OnNextIteration();

    // it's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect)
    while ( ProcessIdle() ) {}

    wxEventLoopBase::DoYieldFor(eventsToProcess);
}
Пример #13
0
bool wxCFEventLoop::YieldFor(long eventsToProcess)
{
#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

    m_isInsideYield = true;
    m_eventsToProcessInsideYield = eventsToProcess;

#if wxUSE_LOG
    // disable log flushing from here because a call to wxYield() shouldn't
    // normally result in message boxes popping up &c
    wxLog::Suspend();
#endif // wxUSE_LOG

    // process all pending events:
    while ( DoProcessEvents() == 1 )
        ;

    // it's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect)
    while ( ProcessIdle() ) {}

    // if there are pending events, we must process them.
    if (wxTheApp)
        wxTheApp->ProcessPendingEvents();

#if wxUSE_LOG
    wxLog::Resume();
#endif // wxUSE_LOG
    m_isInsideYield = false;

    return true;
}
Пример #14
0
bool wxApp::Yield(bool onlyIfNeeded)
{
#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
        return true; // can't process events from other threads
#endif // wxUSE_THREADS

    static bool s_inYield = false;

    if ( s_inYield )
    {
        if ( !onlyIfNeeded )
        {
            wxFAIL_MSG( wxT("wxYield called recursively" ) );
        }

        return false;
    }

    s_inYield = true;

    wxLog::Suspend();

    if ( wxEventLoop::GetActive() )
    {
        while (wxEventLoop::GetActive()->Pending())
            wxEventLoop::GetActive()->Dispatch();
    }

    // it's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect)
    while ( ProcessIdle() ) {}

    wxLog::Resume();

    s_inYield = false;

    return true;
}
Пример #15
0
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
{
#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
        return true; // can't process events from other threads
#endif // wxUSE_THREADS

    m_isInsideYield = true;
    m_eventsToProcessInsideYield = eventsToProcess;

#if wxUSE_LOG
    wxLog::Suspend();
#endif // wxUSE_LOG

    // TODO: implement event filtering using the eventsToProcess mask

    // process all pending events:
    while ( Pending() )
        Dispatch();

    // handle timers, sockets etc.
    OnNextIteration();

    // it's necessary to call ProcessIdle() to update the frames sizes which
    // might have been changed (it also will update other things set from
    // OnUpdateUI() which is a nice (and desired) side effect)
    while ( ProcessIdle() ) {}

#if wxUSE_LOG
    wxLog::Resume();
#endif // wxUSE_LOG

    m_isInsideYield = false;

    return true;
}
Пример #16
0
int wxEventLoopManual::Run()
{
    // event loops are not recursive, you need to create another loop!
    wxCHECK_MSG( !IsRunning(), -1, wxT("can't reenter a message loop") );

    // ProcessIdle() and ProcessEvents() below may throw so the code here should
    // be exception-safe, hence we must use local objects for all actions we
    // should undo
    wxEventLoopActivator activate(this);

    // we must ensure that OnExit() is called even if an exception is thrown
    // from inside ProcessEvents() but we must call it from Exit() in normal
    // situations because it is supposed to be called synchronously,
    // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
    // something similar here)
#if wxUSE_EXCEPTIONS
    for ( ;; )
    {
        try
        {
#endif // wxUSE_EXCEPTIONS

            // this is the event loop itself
            for ( ;; )
            {
                // give them the possibility to do whatever they want
                OnNextIteration();

                // generate and process idle events for as long as we don't
                // have anything else to do
                while ( !Pending() && ProcessIdle() )
                    ;

                // if the "should exit" flag is set, the loop should terminate
                // but not before processing any remaining messages so while
                // Pending() returns true, do process them
                if ( m_shouldExit )
                {
                    while ( Pending() )
                        ProcessEvents();

                    break;
                }

                // a message came or no more idle processing to do, dispatch
                // all the pending events and call Dispatch() to wait for the
                // next message
                if ( !ProcessEvents() )
                {
                    // we got WM_QUIT
                    break;
                }
            }

#if wxUSE_EXCEPTIONS
            // exit the outer loop as well
            break;
        }
        catch ( ... )
        {
            try
            {
                if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
                {
                    OnExit();
                    break;
                }
                //else: continue running the event loop
            }
            catch ( ... )
            {
                // OnException() throwed, possibly rethrowing the same
                // exception again: very good, but we still need OnExit() to
                // be called
                OnExit();
                throw;
            }
        }
    }
#endif // wxUSE_EXCEPTIONS

    return m_exitcode;
}
Пример #17
0
bool InboundHTTP4RTMP::SignalInputData(IOBuffer &buffer) {
	//1. Get the HTTP far protool and test to see if it has ContentLength
	InboundHTTPProtocol *pHTTP = (InboundHTTPProtocol *) _pFarProtocol;
	if (pHTTP == NULL || pHTTP->GetContentLength() == 0) {
		FATAL("Invalid HTTP request");
		return false;
	}

	//2. Test it and see if all the data was transfered
	if (!pHTTP->TransferCompleted()) {
		return true;
	}

	//3. Get the HTTP request
	Variant request = pHTTP->GetHeaders();

	//4. Is this a keep-alive?
	pHTTP->SetDisconnectAfterTransfer(
			request[HTTP_HEADERS][HTTP_HEADERS_CONNECTION]
			!= HTTP_HEADERS_CONNECTION_KEEP_ALIVE);
	DeleteNearProtocol(false);

	//4. Get the URL
	string url = request[HTTP_FIRST_LINE][HTTP_URL];

	//5. split it in meaningful parts
	vector<string> parts;
	split(url, "/", parts);
	if (parts.size() < 2) {
		FATAL("Invalid request:\n%s", STR(request.ToString()));
		return false;
	}

	//7. Do the dammage
	bool result;
	if (parts[1] == "fcs") {
		result = ProcessFcs(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "open") {
		result = ProcessOpen(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "idle") {
		result = ProcessIdle(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "send") {
		if (GETAVAILABLEBYTESCOUNT(buffer) < 1)
			return false;
		_inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), pHTTP->GetContentLength());
		buffer.Ignore(pHTTP->GetContentLength());
		result = ProcessSend(parts);
	} else {
		FATAL("Invalid command: %s", STR(parts[1]));
		result = false;
	}

	//8. Cleanup
	if (!result) {
		DeleteNearProtocol(true);
		EnqueueForDelete();
	}

	//9. Done
	return result;
}
Пример #18
0
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
{
#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
    {
        // can't call gtk_main_iteration() from other threads like this
        return true;
    }
#endif // wxUSE_THREADS

    m_isInsideYield = true;
    m_eventsToProcessInsideYield = eventsToProcess;

#if wxUSE_LOG
    // disable log flushing from here because a call to wxYield() shouldn't
    // normally result in message boxes popping up &c
    wxLog::Suspend();
#endif

    // temporarily replace the global GDK event handler with our function, which
    // categorizes the events and using m_eventsToProcessInsideYield decides
    // if an event should be processed immediately or not
    // NOTE: this approach is better than using gdk_display_get_event() because
    //       gtk_main_iteration() does more than just calling gdk_display_get_event()
    //       and then call gtk_main_do_event()!
    //       In particular in this way we also process input from sources like
    //       GIOChannels (this is needed for e.g. wxGUIAppTraits::WaitForChild).
    gdk_event_handler_set ((GdkEventFunc)wxgtk_main_do_event, this, NULL);
    while (Pending())   // avoid false positives from our idle source
        gtk_main_iteration();
    gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);

    if (eventsToProcess != wxEVT_CATEGORY_CLIPBOARD)
    {
        // It's necessary to call ProcessIdle() to update the frames sizes which
        // might have been changed (it also will update other things set from
        // OnUpdateUI() which is a nice (and desired) side effect). But we
        // call ProcessIdle() only once since this is not meant for longish
        // background jobs (controlled by wxIdleEvent::RequestMore() and the
        // return value of Processidle().
        ProcessIdle();      // ProcessIdle() also calls ProcessPendingEvents()
    }
    //else: if we are inside ~wxClipboardSync() and we call ProcessIdle() and
    //      the user app contains an UI update handler which calls wxClipboard::IsSupported,
    //      then we fall into a never-ending loop...

    // put all unprocessed GDK events back in the queue
    GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
    for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++)
    {
        GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i];

        // NOTE: gdk_display_put_event makes a copy of the event passed to it
        gdk_display_put_event(disp, ev);
        gdk_event_free(ev);
    }

    m_arrGdkEvents.Clear();

#if wxUSE_LOG
    // let the logs be flashed again
    wxLog::Resume();
#endif

    m_isInsideYield = false;

    return true;
}
Пример #19
0
    int DoRun()
    {
        // we must ensure that OnExit() is called even if an exception is thrown
        // from inside ProcessEvents() but we must call it from Exit() in normal
        // situations because it is supposed to be called synchronously,
        // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
        // something similar here)
    #if wxUSE_EXCEPTIONS
        for( ; ; )
        {
            try
            {
    #endif // wxUSE_EXCEPTIONS

                // this is the event loop itself
                for( ; ; )
                {
                    // generate and process idle events for as long as we don't
                    // have anything else to do
                    while ( !m_shouldExit && !Pending() && ProcessIdle() )
                        ;

                    if ( m_shouldExit )
                        break;

                    // a message came or no more idle processing to do, dispatch
                    // all the pending events and call Dispatch() to wait for the
                    // next message
                    if ( !ProcessEvents() )
                    {
                        // we got WM_QUIT
                        break;
                    }
                }

                // Process the remaining queued messages, both at the level of the
                // underlying toolkit level (Pending/Dispatch()) and wx level
                // (Has/ProcessPendingEvents()).
                //
                // We do run the risk of never exiting this loop if pending event
                // handlers endlessly generate new events but they shouldn't do
                // this in a well-behaved program and we shouldn't just discard the
                // events we already have, they might be important.
                for( ; ; )
                {
                    bool hasMoreEvents = false;
                    if ( wxTheApp && wxTheApp->HasPendingEvents() )
                    {
                        wxTheApp->ProcessPendingEvents();
                        hasMoreEvents = true;
                    }

                    if ( Pending() )
                    {
                        Dispatch();
                        hasMoreEvents = true;
                    }

                    if ( !hasMoreEvents )
                        break;
                }

    #if wxUSE_EXCEPTIONS
                // exit the outer loop as well
                break;
            }
            catch ( ... )
            {
                try
                {
                    if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
                    {
                        OnExit();
                        break;
                    }
                    //else: continue running the event loop
                }
                catch ( ... )
                {
                    // OnException() throwed, possibly rethrowing the same
                    // exception again: very good, but we still need OnExit() to
                    // be called
                    OnExit();
                    throw;
                }
            }
        }
    #endif // wxUSE_EXCEPTIONS

        return m_exitcode;
    }
Пример #20
0
 void ProcessExhaustive() {
   ProcessIdle(true);
 }