MainLoop Class Reference

#include <Pt/System/MainLoop.h>

Thread-safe event loop supporting I/O multiplexing and Timers. More...

Inherits EventLoop.

Public Member Functions

 MainLoop ()
 Default Constructor.
 
 MainLoop (Allocator &a)
 Construct with allocator.
 
virtual ~MainLoop ()
 Destructor.
 
void run ()
 Starts the loop.
 
void exit ()
 Stops the loop.
 
void processEvents ()
 Process all queued events.
 
Signal< const Event & > & eventReceived ()
 Reports all events.
 
Signalexited ()
 Emited when the eventloop is exited.
 
void post (Selectable &s)
 Posts the loop to run a selectable. More...
 
void setReady (Selectable &s)
 Sets the Selectable as ready without waking the loop.
 
void commitEvent (const Event &ev)
 Queues an event and triggers event processing.
 
void queueEvent (const Event &ev)
 Only queues an event.
 
void wake ()
 Triggers event processing.
 

Protected Member Functions

virtual void onCommitEvent (const Event &ev)
 Queues an event and triggers event processing.
 
virtual void onQueueEvent (const Event &ev)
 Only queues an event.
 
virtual void onWake ()
 Triggers event processing.
 

Detailed Description

The following example uses a MainLoop to wait on acitvity on a Timer, which is set to time-out after 1000 msecs.

// slot to handle timer activity
void onTimer();
int main()
{
using Pt::System;
MainLoop loop;
Timer timer;
timer.setActive(loop);
timer.start(1000);
timer.timeout() += Pt::slot(onTimer);
loop.run();
return 0;
}

Member Function Documentation

◆ post()

void post ( Selectable s)
inherited

The event loop is woken up and the selectable's run function is called in the event loop thread. This function may be called from any thread, especially from a selectable, that is based on a parallel execution model e.g. using a worker thread.

MainLoop()
Default Constructor.
System programming
Definition: Client.h:41