libtasks Documentation  1.6
tasks::event_task Class Referenceabstract

#include <event_task.h>

Inheritance diagram for tasks::event_task:
Collaboration diagram for tasks::event_task:

Classes

struct  error_func_t
 

Public Types

typedef std::function< void(worker
*worker, const tasks_exception
&e)> 
error_func_worker_t
 
typedef std::function< void(const
tasks_exception &e)> 
error_func_void_t
 
- Public Types inherited from tasks::task
typedef std::function< void(worker
*worker)> 
finish_func_worker_t
 
typedef std::function< void()> finish_func_void_t
 

Public Member Functions

virtual ~event_task ()
 
virtual bool handle_event (worker *worker, int events)=0
 
virtual void init_watcher ()=0
 Initialize the underlying watcher object. More...
 
virtual void stop_watcher (worker *worker)=0
 Deactivate the underlying watcher. More...
 
virtual void start_watcher (worker *worker)=0
 Activate the underlying watcher to listen for I/O or timer events. More...
 
workerassigned_worker () const
 Returns a pointer to the assigned worker. More...
 
void assign_worker (worker *worker)
 
void notify_error (worker *worker=nullptr)
 
void on_error (error_func_worker_t f)
 
void on_error (error_func_void_t f)
 Install an error callback. More...
 
- Public Member Functions inherited from tasks::task
virtual ~task ()
 
bool auto_delete () const
 Returns true if auto deletion is active. More...
 
void disable_auto_delete ()
 Call this to deactivate auto deletion. More...
 
void finish (worker *worker=nullptr)
 Called by a worker when a task has auto_deletion enabled. More...
 
void on_finish (finish_func_worker_t f)
 
void on_finish (finish_func_void_t f)
 
- Public Member Functions inherited from tasks::error_base
 error_base ()
 
virtual ~error_base ()
 
bool error () const
 Return true if an error occured. More...
 
tasks_error error_code () const
 Return the error code. More...
 
const std::string & error_message () const
 Return the error message. More...
 
int sys_errno () const
 Return the errno if available. More...
 
std::string sys_errno_str () const
 Return the errno description if available. More...
 
const tasks_exceptionexception () const
 Return the underlying exception object. More...
 
void set_exception (tasks_exception &e)
 Set an exception to report an error. More...
 
void reset_error ()
 Reset the error state. More...
 

Private Attributes

workerm_worker = nullptr
 
std::vector< error_func_tm_error_funcs
 

Detailed Description

Definition at line 21 of file event_task.h.

Member Typedef Documentation

typedef std::function<void(const tasks_exception& e)> tasks::event_task::error_func_void_t

Definition at line 24 of file event_task.h.

typedef std::function<void(worker* worker, const tasks_exception& e)> tasks::event_task::error_func_worker_t

Definition at line 23 of file event_task.h.

Constructor & Destructor Documentation

virtual tasks::event_task::~event_task ( )
inlinevirtual

Definition at line 45 of file event_task.h.

Member Function Documentation

void tasks::event_task::assign_worker ( worker worker)

Assigns a worker to the task in multi loop mode.

For multi loop mode a task does not leave the context of a worker thread, as each thread runs its own event loop. That also means this worker has to execute a dispose action. As dispose allows to be called from outside of the task system (a non worker thread context), a handle to the worker the task belongs to is needed. The method does nothing in single loop mode.

Parameters
workerThe worker to assign.

Definition at line 13 of file event_task.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

worker* tasks::event_task::assigned_worker ( ) const
inline

Returns a pointer to the assigned worker.

Definition at line 68 of file event_task.h.

Here is the caller graph for this function:

virtual bool tasks::event_task::handle_event ( worker worker,
int  events 
)
pure virtual

Will be called for each I/O or timer event.

Each task needs to implement the handle_event method. Returns true if the task stays active and false otherwise. The task will be deleted if false is returned and auto_delete() returns true.

Parameters
workerThe worker thread executing the task.
eventsThe events bitmask.
Returns
True to continue execution. False to remove the task.

Implemented in tasks::net::acceptor< T >, echo_handler, tasks::net::http_sender< handler_type >, tasks::net::uwsgi_task, tasks::disk_io_task, test_http_close_handler, stats, tasks::cleanup_task, stats, stats, and echo_handler.

virtual void tasks::event_task::init_watcher ( )
pure virtual

Initialize the underlying watcher object.

Implemented in tasks::io_task_base, tasks::timer_task, and tasks::disk_io_task.

Here is the caller graph for this function:

void tasks::event_task::notify_error ( worker worker = nullptr)

Called by a worker when a task reports an error. All error callbacks will be executed. A worker calls this method after handle_event.

Definition at line 22 of file event_task.cpp.

Here is the call graph for this function:

void tasks::event_task::on_error ( error_func_worker_t  f)
inline

If a task failed it can execute callback functions. Note that no locks will be used at this level.

Definition at line 86 of file event_task.h.

void tasks::event_task::on_error ( error_func_void_t  f)
inline

Install an error callback.

Definition at line 91 of file event_task.h.

virtual void tasks::event_task::start_watcher ( worker worker)
pure virtual

Activate the underlying watcher to listen for I/O or timer events.

Implemented in tasks::io_task_base, tasks::timer_task, and tasks::disk_io_task.

Here is the caller graph for this function:

virtual void tasks::event_task::stop_watcher ( worker worker)
pure virtual

Deactivate the underlying watcher.

Implemented in tasks::io_task_base, tasks::timer_task, and tasks::disk_io_task.

Here is the caller graph for this function:

Member Data Documentation

std::vector<error_func_t> tasks::event_task::m_error_funcs
private

Definition at line 97 of file event_task.h.

worker* tasks::event_task::m_worker = nullptr
private

Definition at line 96 of file event_task.h.


The documentation for this class was generated from the following files: