libcopp  1.1.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
cotask::task_manager< TTask, TTaskContainer > Class Template Reference

task manager More...

#include <task_manager.h>

Collaboration diagram for cotask::task_manager< TTask, TTaskContainer >:
Collaboration graph

Data Structures

struct  flag_guard_t
 
struct  flag_t
 

Public Types

typedef TTask task_t
 
typedef TTaskContainer container_t
 
typedef task_t::id_t id_t
 
typedef task_t::ptr_t task_ptr_t
 
typedef task_manager< task_t, container_tself_t
 
typedef std::shared_ptr< self_tptr_t
 

Public Member Functions

 task_manager ()
 
 ~task_manager ()
 
void reset ()
 
int add_task (const task_ptr_t &task, time_t timeout_sec, int timeout_nsec)
 add task to manager please make the task has method of get_id() and will return a unique id More...
 
int add_task (const task_ptr_t &task)
 add task to manager please make the task has method of get_id() and will return a unique id More...
 
int remove_task (id_t id)
 remove task in this manager More...
 
task_ptr_t find_task (id_t id)
 find task by id More...
 
int start (id_t id, void *priv_data=NULL)
 
int resume (id_t id, void *priv_data=NULL)
 
int cancel (id_t id, void *priv_data=NULL)
 
int kill (id_t id, enum EN_TASK_STATUS status, void *priv_data=NULL)
 
int kill (id_t id, void *priv_data=NULL)
 
int tick (time_t sec, int nsec=0)
 active tick event and deal with clock More...
 
size_t get_tick_checkpoint_size () const UTIL_CONFIG_NOEXCEPT
 get timeout checkpoint number in this manager More...
 
size_t get_task_size () const UTIL_CONFIG_NOEXCEPT
 get task number in this manager More...
 
detail::tickspec_t get_last_tick_time () const UTIL_CONFIG_NOEXCEPT
 get last tick time More...
 
const container_tget_container () const UTIL_CONFIG_NOEXCEPT
 task container, this api is just used for provide information to users More...
 
const std::multimap< detail::tickspec_t, id_t > & get_checkpoints () const UTIL_CONFIG_NOEXCEPT
 get all task checkpoints, this api is just used for provide information to users More...
 

Static Public Member Functions

static ptr_t create ()
 create a new task manager More...
 

Private Attributes

container_t tasks_
 
detail::tickspec_t last_tick_time_
 
std::multimap< detail::tickspec_t, id_ttask_timeout_checkpoints_
 
util::lock::spin_lock action_lock_
 
int flags_
 

Detailed Description

template<typename TTask, typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
class cotask::task_manager< TTask, TTaskContainer >

task manager

Definition at line 56 of file task_manager.h.

Member Typedef Documentation

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef TTaskContainer cotask::task_manager< TTask, TTaskContainer >::container_t

Definition at line 59 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef task_t::id_t cotask::task_manager< TTask, TTaskContainer >::id_t

Definition at line 60 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef std::shared_ptr<self_t> cotask::task_manager< TTask, TTaskContainer >::ptr_t

Definition at line 63 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef task_manager<task_t, container_t> cotask::task_manager< TTask, TTaskContainer >::self_t

Definition at line 62 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef task_t::ptr_t cotask::task_manager< TTask, TTaskContainer >::task_ptr_t

Definition at line 61 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
typedef TTask cotask::task_manager< TTask, TTaskContainer >::task_t

Definition at line 58 of file task_manager.h.

Constructor & Destructor Documentation

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
cotask::task_manager< TTask, TTaskContainer >::task_manager ( )
inline

Definition at line 95 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
cotask::task_manager< TTask, TTaskContainer >::~task_manager ( )
inline

Definition at line 100 of file task_manager.h.

Member Function Documentation

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::add_task ( const task_ptr_t task,
time_t  timeout_sec,
int  timeout_nsec 
)
inline

add task to manager please make the task has method of get_id() and will return a unique id

Parameters
tasktask to be inserted
timeout_sectimeout in second ( unix time stamp recommanded )
timeout_nsectimeout in nanosecond ( must be in the range 0-999999999 )
Returns
0 or error code
Note
if a task added before the first calling of tick method, the timeout will be set releative to the first calling time of tick method
See also
tick

Definition at line 154 of file task_manager.h.

References copp::COPP_EC_ALREADY_EXIST, copp::COPP_EC_ARGS_ERROR, copp::COPP_EC_CAST_FAILED, copp::COPP_EC_EXTERNAL_INSERT_FAILED, copp::COPP_EC_IN_RESET, copp::COPP_EC_SUCCESS, cotask::task_mgr_node< TTask >::expired_time_, and cotask::task_mgr_node< TTask >::task_.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::add_task ( const task_ptr_t task)
inline

add task to manager please make the task has method of get_id() and will return a unique id

Parameters
tasktask to be inserted
Returns
0 or error code

Definition at line 208 of file task_manager.h.

References cotask::task_manager< TTask, TTaskContainer >::add_task().

Referenced by cotask::task_manager< TTask, TTaskContainer >::add_task().

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::cancel ( id_t  id,
void *  priv_data = NULL 
)
inline
template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
static ptr_t cotask::task_manager< TTask, TTaskContainer >::create ( )
inlinestatic

create a new task manager

Returns
smart pointer of task manager

Definition at line 139 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
task_ptr_t cotask::task_manager< TTask, TTaskContainer >::find_task ( id_t  id)
inline

find task by id

Parameters
idtask id
Returns
smart pointer of task

Definition at line 250 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
const std::multimap<detail::tickspec_t, id_t>& cotask::task_manager< TTask, TTaskContainer >::get_checkpoints ( ) const
inline

get all task checkpoints, this api is just used for provide information to users

Returns
task checkpoints

Definition at line 516 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
const container_t& cotask::task_manager< TTask, TTaskContainer >::get_container ( ) const
inline

task container, this api is just used for provide information to users

Returns
task container

Definition at line 510 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
detail::tickspec_t cotask::task_manager< TTask, TTaskContainer >::get_last_tick_time ( ) const
inline

get last tick time

Returns
last tick time

Definition at line 504 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
size_t cotask::task_manager< TTask, TTaskContainer >::get_task_size ( ) const
inline

get task number in this manager

Returns
task number

Definition at line 498 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
size_t cotask::task_manager< TTask, TTaskContainer >::get_tick_checkpoint_size ( ) const
inline

get timeout checkpoint number in this manager

Returns
checkpoint number

Definition at line 492 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::kill ( id_t  id,
enum EN_TASK_STATUS  status,
void *  priv_data = NULL 
)
inline
template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::kill ( id_t  id,
void *  priv_data = NULL 
)
inline
template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::remove_task ( id_t  id)
inline

remove task in this manager

Parameters
idtask id
Returns
0 or error code

Definition at line 215 of file task_manager.h.

References copp::COPP_EC_IN_RESET, copp::COPP_EC_NOT_FOUND, copp::COPP_EC_SUCCESS, COPP_MACRO_STD_MOVE, cotask::EN_TS_CREATED, cotask::EN_TS_DONE, and cotask::EN_TS_KILLED.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
void cotask::task_manager< TTask, TTaskContainer >::reset ( )
inline

Definition at line 105 of file task_manager.h.

References cotask::EN_TS_KILLED.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::resume ( id_t  id,
void *  priv_data = NULL 
)
inline
template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::start ( id_t  id,
void *  priv_data = NULL 
)
inline
template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::tick ( time_t  sec,
int  nsec = 0 
)
inline

active tick event and deal with clock

Parameters
seccurrent time in second ( unix time stamp recommanded )
nseccurrent time in nanosecond ( must be in the range 0-999999999 )
Returns
0 or error code
Note
timeout tasks will be removed here

Definition at line 412 of file task_manager.h.

References copp::COPP_EC_IN_RESET, copp::COPP_EC_SUCCESS, COPP_MACRO_STD_MOVE, cotask::EN_TS_TIMEOUT, cotask::detail::tickspec_t::tv_nsec, and cotask::detail::tickspec_t::tv_sec.

Field Documentation

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
util::lock::spin_lock cotask::task_manager< TTask, TTaskContainer >::action_lock_
private

Definition at line 526 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
int cotask::task_manager< TTask, TTaskContainer >::flags_
private

Definition at line 528 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
detail::tickspec_t cotask::task_manager< TTask, TTaskContainer >::last_tick_time_
private

Definition at line 522 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
std::multimap<detail::tickspec_t, id_t> cotask::task_manager< TTask, TTaskContainer >::task_timeout_checkpoints_
private

Definition at line 523 of file task_manager.h.

template<typename TTask , typename TTaskContainer = std::map<typename TTask::id_t, task_mgr_node<TTask> >>
container_t cotask::task_manager< TTask, TTaskContainer >::tasks_
private

Definition at line 521 of file task_manager.h.


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