Selectable Class Referenceabstract

#include <Pt/System/Selectable.h>

Operation that runs through an event loop. More...

Inherits NonCopyable.

Inherited by Script, TcpServer, AsyncYield [private], IODevice, and IONotifier.

Public Member Functions

virtual ~Selectable ()
 Destructor.
void setActive (EventLoop &parent)
 Sets the parent loop, so that operations can be run.
void detach ()
 Remove from event loop and cancels outstanding operations.
void cancel ()
 Cancels all operations.
bool run ()
 Run operation if it is ready.
EventLoopparent () const
 Returns the used event loop.

Protected Member Functions

 Selectable ()
 Default Constructor.
void post ()
 Posts this selectable to its event loop from any thread.
virtual void onAttach (EventLoop &)
 Attached to loop.
virtual void onDetach (EventLoop &)
 Detached from loop.
virtual void onCancel ()=0
 Blocks until operation has cancelled.
virtual bool onRun ()=0
 Check if ready and run.

Detailed Description

Selectable is the attachment between an asynchronous operation and an EventLoop. setActive() attaches it. The loop then monitors the operation. detach() removes it and cancels work that is still running. cancel() cancels without detaching. parent() is the loop.

run() executes the operation when the loop has marked it ready. post() asks the loop to run it from any thread. IODevice and IONotifier are selectables. Timer is not; it registers with the loop on its own.

The loop does not own the selectable. The caller keeps it alive while it is attached.