XDispatch 0.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions
xdispatch::timer Class Reference

Provides a timer executing a block or an operation on a specific queue when a timeout occurs. More...

#include <xdispatch/timer.h>

+ Inheritance diagram for xdispatch::timer:

List of all members.

Public Member Functions

 timer (uint64_t interval, const xdispatch::queue &target=global_queue(), const time &starting=time_now)
 Constructs a new periodic timer.
 timer (const timer &)
 ~timer ()
void interval (uint64_t)
 Use this to set the interval in nanoseconds.
void latency (uint64_t)
 Use this to set the latency in nanoseconds which the timer might be early or late.
void start ()
 Will start the timer.
void stop ()
 Will stop the timer.
timeroperator= (const timer &)
void resume ()
 Resumes the invocation of operations or blocks assigned to the object.
void suspend ()
 Suspends the invocation of operations or blocks assigned to the object.
void handler (xdispatch::operation *)
 Sets the handler to dispatch each time the source becomes ready.
virtual void handler (dispatch_block_t b)
 Sets the handler to dispatch each time the source becomes ready.
void target_queue (const xdispatch::queue &)
 Sets the queue the handler will be executed on.
xdispatch::queue target_queue () const
virtual dispatch_object_t native () const
dispatch_source_t native_source () const
void cancel ()
 Asynchronously cancels the dispatch source, preventing any further invocation of its event handler block.
void cancel_handler (xdispatch::operation *)
 Sets the cancellation handler block for the given dispatch source.
virtual void cancel_handler (dispatch_block_t b)
 Sets the cancellation handler block for the given dispatch source.
bool operator== (const object &)
bool operator== (const dispatch_object_t &)
bool operator!= (const object &)
bool operator!= (const dispatch_object_t &)

Static Public Member Functions

static timercurrent ()
static void single_shot (dispatch_time_t, const xdispatch::queue &, xdispatch::operation *)
 Creates a single shot timer executing the given operation on the given queue at the given time.
static void single_shot (struct tm *, const xdispatch::queue &, xdispatch::operation *)
 Creates a single shot timer executing the given operation on the given queue at the given time.
static void single_shot (dispatch_time_t t, const xdispatch::queue &q, dispatch_block_t b)
 Creates a single shot timer executing the given block on the given queue at the given time.
static void single_shot (struct tm *t, const xdispatch::queue &q, dispatch_block_t b)
 Creates a single shot timer executing the given block on the given queue at the given time.
static void single_shot (dispatch_time_t t, const xdispatch::queue &q, const lambda_function &b)
 Creates a single shot timer executing the given function on the given queue at the given time.
static void single_shot (struct tm *t, const xdispatch::queue &q, const lambda_function &b)
 Creates a single shot timer executing the given function on the given queue at the given time.
template<typename T >
static T data ()

Detailed Description

Provides a timer executing a block or an operation on a specific queue when a timeout occurs.

Remarks:
Although you can get the dispatch_source_t associated with this timer by calling native(), please be aware that as soon as you do any changes to this source not by using the timer object it is not garanteed, that the timer object will still work as expected.

Definition at line 46 of file timer.h.


Constructor & Destructor Documentation

xdispatch::timer::timer ( uint64_t  interval,
const xdispatch::queue target = global_queue(),
const time starting = time_now 
)

Constructs a new periodic timer.

The timer will be stopped, call start() to execute it

Parameters:
intervalThe interval in nanoseconds at which the timer will fire after the timeout occured.
targetThe queue to execute the timer on, defaults to the global_queue
startingThe time at which the timer will fire for the first time

Member Function Documentation

void xdispatch::source::cancel ( ) [inherited]

Asynchronously cancels the dispatch source, preventing any further invocation of its event handler block.

Cancellation prevents any further invocation of the event handler block for the specified dispatch source, but does not interrupt an event handler block that is already in progress. The optional cancellation handler is submitted to the target queue once the event handler block has been completed.

The cancellation handler is submitted to the source's target queue when the source's event handler has finished, indicating that it is safe to close the source's handle (e.g. file descriptor or mach port if any).

The optional cancellation handler is submitted to the xdispatch::source object's target queue only after the system has released all of its references to any underlying system objects (file descriptors or mach ports). Thus, the cancellation handler is a convenient place to close or deallocate such system objects.

Remarks:
It is invalid to close a file descriptor or deallocate a mach port currently being tracked by a xdispatch::source object before the cancellation handler is invoked.

Sets the cancellation handler block for the given dispatch source.

The cancellation handler (if specified) is submitted to the source's target queue in response to a call to dispatch_source_cancel when the system has released all references to the source's underlying handle and the source's event handler block has returned.

virtual void xdispatch::source::cancel_handler ( dispatch_block_t  b) [inline, virtual, inherited]

Sets the cancellation handler block for the given dispatch source.

The cancellation handler (if specified) is submitted to the source's target queue in response to a call to dispatch_source_cancel when the system has released all references to the source's underlying handle and the source's event handler block has returned.

Definition at line 294 of file source.h.

static timer* xdispatch::timer::current ( ) [static]
Returns:
The timer responsible for the handler to be executed or NULL if the handler was not executed because of a timer firing

Reimplemented in QDispatchTimer.

template<typename T >
static T xdispatch::source::data ( ) [inline, static, inherited]
Returns:
the data that is associated with the currently dispatched and executed handler. The returned data is defined by the sourcetype used.

Pass the type of the data to retrieve as template parameter. If the requested datatype cannot be provided, a bad_cast exception will be thrown.

Remarks:
Calling this method from outside of a handler is undefined
When using a native_source, no data will be available here but has to be retrieved using the dispatch_source_get_*() functions

Definition at line 237 of file source.h.

Sets the handler to dispatch each time the source becomes ready.

You can use data() to obtain a pointer to data provided by the source and possibly being the reason for the handler to be dispatched.

virtual void xdispatch::source::handler ( dispatch_block_t  b) [inline, virtual, inherited]

Sets the handler to dispatch each time the source becomes ready.

You can use data() to obtain a pointer to data provided by the source and possibly being the reason for the handler to be dispatched.

Definition at line 202 of file source.h.

void xdispatch::timer::interval ( uint64_t  )

Use this to set the interval in nanoseconds.

When called for the first time on a single-shot timer, the timer will be converted to a periodic timer with the given interval.

void xdispatch::timer::latency ( uint64_t  )

Use this to set the latency in nanoseconds which the timer might be early or late.

When not set the latency will be kept as low as possible.

virtual dispatch_object_t xdispatch::source::native ( ) const [virtual, inherited]
Returns:
the native dispatch_object_t associated with this source. This depends on the sourcetype used and will normally return NULL
See also:
native_source();

Implements xdispatch::object.

Returns:
the native dispatch_source_t associated with this source. This depends on the sourcetype used and will normally return NULL
See also:
native()
bool xdispatch::object::operator!= ( const object ) [inherited]
bool xdispatch::object::operator!= ( const dispatch_object_t ) [inherited]
timer& xdispatch::timer::operator= ( const timer )
bool xdispatch::object::operator== ( const object ) [inherited]
bool xdispatch::object::operator== ( const dispatch_object_t ) [inherited]
void xdispatch::source::resume ( ) [virtual, inherited]

Resumes the invocation of operations or blocks assigned to the object.

Reimplemented from xdispatch::object.

Creates a single shot timer executing the given operation on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

static void xdispatch::timer::single_shot ( struct tm *  ,
const xdispatch::queue ,
xdispatch::operation  
) [static]

Creates a single shot timer executing the given operation on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

static void xdispatch::timer::single_shot ( dispatch_time_t  t,
const xdispatch::queue q,
dispatch_block_t  b 
) [inline, static]

Creates a single shot timer executing the given block on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

Definition at line 106 of file timer.h.

static void xdispatch::timer::single_shot ( struct tm *  t,
const xdispatch::queue q,
dispatch_block_t  b 
) [inline, static]

Creates a single shot timer executing the given block on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

Definition at line 113 of file timer.h.

static void xdispatch::timer::single_shot ( dispatch_time_t  t,
const xdispatch::queue q,
const lambda_function &  b 
) [inline, static]

Creates a single shot timer executing the given function on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

Definition at line 121 of file timer.h.

static void xdispatch::timer::single_shot ( struct tm *  t,
const xdispatch::queue q,
const lambda_function &  b 
) [inline, static]

Creates a single shot timer executing the given function on the given queue at the given time.

This is quite similar to using xdispatch::queue::after()

Definition at line 128 of file timer.h.

void xdispatch::timer::start ( ) [inline]

Will start the timer.

Remarks:
A new created timer will be stopped and needs to me started first. Once started, ensure balanced calls between start() and stop().
See also:
resume();

Reimplemented in QDispatchTimer.

Definition at line 78 of file timer.h.

void xdispatch::timer::stop ( ) [inline]

Will stop the timer.

Remarks:
A new created timer will be stopped and needs to me started first. Once started, ensure balanced calls between start() and stop().
See also:
suspend()

Reimplemented in QDispatchTimer.

Definition at line 85 of file timer.h.

void xdispatch::source::suspend ( ) [virtual, inherited]

Suspends the invocation of operations or blocks assigned to the object.

The object will be suspended as soon as the currently executed operation or block finished.

Remarks:
Calls to suspend() should be balanced with calls to resume() to continue an object

Reimplemented from xdispatch::object.

void xdispatch::source::target_queue ( const xdispatch::queue ) [virtual, inherited]

Sets the queue the handler will be executed on.

Reimplemented from xdispatch::object.

Returns:
the queue the handler will be executed on

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Oct 28 2012 22:12:47 for XDispatch by Doxygen 1.7.6.1
© 2010-2012 MLBA (about | privacy) All Rights reserved.