Webmaster  |  Imprint 
Platinum
Platinum C++ Framework
Main  |  License  |  Documentation  |  Download  |  Support 

SelectorBase Class Reference

Reports activity on a set of devices. More...

#include <Pt/System/Selector.h>

Inheritance diagram for SelectorBase:

Connectable NonCopyable EventLoopBase EventLoop

List of all members.

Public Member Functions

virtual ~SelectorBase ()
 Destructor.
void add (Selectable &s)
 Adds an IOResult.
void remove (Selectable &s)
 Cancel an IOResult.
void add (Timer &timer)
 Adds a Timer.
void remove (Timer &timer)
 Removes a Timer.
bool wait (std::size_t msecs=WaitInfinite)
 Wait for activity.
void wake ()
 Wakes the selctor from waiting.

Static Public Attributes

static const std::size_t WaitInfinite = static_cast<const std::size_t>(-1)

Protected Member Functions

 SelectorBase ()
 Default constructor.
void onAddTimer (Timer &timer)
void onRemoveTimer (Timer &timer)
void onTimerChanged (Timer &timer)
virtual void onAdd (Selectable &)=0
virtual void onRemove (Selectable &)=0
virtual void onChanged (Selectable &s)=0
virtual bool onWait (std::size_t msecs)=0
virtual void onWake ()=0

Friends

class Selectable
class Timer


Detailed Description

A Selector can be used to monitor a set of Selectables and Timers and wait for activity on them. The wait call can be performed with a timeout and the respective timeout signal is sent if it occurs. Clients can be notified about Timer and Selectable activity by connecting to the appropriate signals of the Timer and Selectable classes.

The following example uses a Selector 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 cxxtools::System;

            Timer timer;
            timer.start(1000);
            connect(timer.timeout, ontimer);

            Selector selector;
            selector.addTimer(timer);
            selector wait();

            return 0;
        }

A Selector is the heart of the EventLoop, which calls Selector::wait continously. The EventLoop and Application classes provide the same API as the Selector itself.


Member Function Documentation

void add ( Selectable &  s  ) 

Adds an IOResult to the selector. IOResult are removed automatically when they get destroyed.

void add ( Timer timer  ) 

Adds a Timer to the selector. Timers are removed automatically when they get destroyed.

Parameters:
timer The device to add

void remove ( Timer timer  ) 

Parameters:
timer The timer to remove

bool wait ( std::size_t  msecs = WaitInfinite  ) 

This method will wait for activity on the registered Selectables and Timers. Use Selector::WaitInfinite to wait without timeout.

Parameters:
msecs timeout in miliseconds

void wake (  ) 

This method can be used to end a Selector::wait call before the timeout expires. It is supposed to be used from another thread and thus is thread-safe.

Copyright © 2003-2007 The Pt Development Team
Pt 1.0