Extends the basic_convar_task with a message queue support. More...

#include <mn_msg_task.hpp>

+ Inheritance diagram for mn::ext::basic_message_task:
+ Collaboration diagram for mn::ext::basic_message_task:

Public Types

using message_id = typename task_message::message_id
 
- Public Types inherited from mn::basic_task
enum class  priority {
  Idle = MN_THREAD_CONFIG_CORE_PRIORITY_IDLE , Low = MN_THREAD_CONFIG_CORE_PRIORITY_LOW , Normal = MN_THREAD_CONFIG_CORE_PRIORITY_NORM , HalfCritical = MN_THREAD_CONFIG_CORE_PRIORITY_HALFCRT ,
  Urgent = MN_THREAD_CONFIG_CORE_PRIORITY_URGENT , Critical = MN_THREAD_CONFIG_CORE_PRIORITY_CRITICAL
}
 Task priority. More...
 
enum class  state {
  Running = 0 , Ready , Blocked , Suspended ,
  Deleted
}
 
using native_handle_type = xTaskHandle
 

Public Member Functions

 basic_message_task (std::string strName="message_task", basic_task::priority uiPriority=priority::Normal, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE)
 Constructor for this task. More...
 
void post_msg (task_message *msg, unsigned int timeout)
 Add a pre-created task message to the task queue. More...
 
void post_msg (message_id msg_id, unsigned int timeout)
 Create the task message and add the message to the task queue, without message data. More...
 
void post_msg (message_id msg_id, void *message_data, unsigned int timeout)
 Create the task message and add the message to the task queue, with message data. More...
 
 basic_message_task (const basic_message_task &)=delete
 
basic_message_taskoperator= (const basic_message_task &)=delete
 
- Public Member Functions inherited from mn::ext::basic_convar_task
 basic_convar_task ()
 
 basic_convar_task (std::string strName, basic_task::priority uiPriority, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE)
 
virtual void signal ()
 
virtual int wait (convar_t &cv, mutex_t &cvl, TickType_t timeOut=portMAX_DELAY)
 
- Public Member Functions inherited from mn::basic_task
 basic_task () noexcept
 
 basic_task (std::string strName, basic_task::priority uiPriority=basic_task::priority::Normal, unsigned short usStackDepth=MN_THREAD_CONFIG_MINIMAL_STACK_SIZE) noexcept
 
virtual ~basic_task ()
 Our destructor. Delete the task. More...
 
virtual int start (int uiCore=MN_THREAD_CONFIG_DEFAULT_CORE)
 Create and starts the Task. More...
 
int kill ()
 Destroy and delete the task and call the function 'on_kill'. More...
 
bool is_running ()
 Is the Task running? More...
 
std::string get_name ()
 Get the debug name of this task. More...
 
basic_task::priority get_priority ()
 Get the priority of this task. More...
 
unsigned short get_stackdepth ()
 Get the stack depth of this task. More...
 
xTaskHandle get_handle ()
 Accessor to get the task's backing task handle. There is no setter, on purpose. More...
 
int get_return_value ()
 Get the return value of this task - after run. More...
 
timespan_t get_time_since_start () const
 Get the time since start of this task. More...
 
int32_t get_id ()
 Get the FreeRTOS task Numberid of this task. More...
 
int32_t get_on_core ()
 Get the core number of this task run. More...
 
void set_priority (basic_task::priority uiPriority)
 Set the priority of this task. More...
 
void suspend ()
 Suspend this task. More...
 
void resume ()
 Resume a specific task. More...
 
bool joinable () const noexcept
 
int join (unsigned int xTickTimeout=portMAX_DELAY)
 join the task, Wait in other task to end this task. More...
 
int join (timespan_t time)
 join the task, Wait in other task to end this task. More...
 
int wait (unsigned int xTimeOut)
 Wait for start the task. More...
 
int wait (timespan_t time)
 Wait for start the task. More...
 
virtual void on_start ()
 This virtual function call on creating, use for user code It is optional whether you implement this or not. More...
 
virtual void on_kill ()
 This virtual function call on kill, use for user code It is optional whether you implement this or not. More...
 
virtual void on_cleanup ()
 Called on exit from your on_task() routine. More...
 
state get_state ()
 Get the state of the task. More...
 
 operator xTaskHandle ()
 Operator to get the task's backing task handle. More...
 
 operator int ()
 Operator to get the ID assigned to the task. More...
 
bool operator== (const basic_task &r) const
 
bool operator!= (const basic_task &r) const
 
bool operator< (const basic_task &r) const
 
bool operator> (const basic_task &r) const
 

Protected Member Functions

virtual void on_message (id_t id, void *message)=0
 Implementation of your actual message code. More...
 
- Protected Member Functions inherited from mn::ext::basic_convar_task
virtual void on_signal ()
 

Protected Attributes

mutex_t m_ltMessageQueueLock
 
queue::queue_t m_qeMessageQueue
 
convar_t m_cvMessage
 
- Protected Attributes inherited from mn::basic_task
LockType_t m_runningMutex
 Lock Objekt for task safty. More...
 
LockType_t m_contextMutext
 
LockType_t m_continuemutex
 
std::string m_strName
 The name of this task. More...
 
basic_task::priority m_uiPriority
 A saved / cached copy of what the task's priority is. More...
 
unsigned short m_usStackDepth
 Stack depth of this task, in words. More...
 
int m_retval
 The return value from user task routine. More...
 
bool m_bRunning
 Flag whether or not the task was started. More...
 
int32_t m_iID
 The FreeRTOS task Number. More...
 
int32_t m_iCore
 A saved / cached copy of which core this task is running on. More...
 
native_handle_type m_pHandle
 Reference to the underlying task handle for this task. More...
 
event_group_t m_eventGroup
 

Private Member Functions

int on_task ()
 The current message handling code. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from mn::basic_task
static void suspend (basic_task *t)
 Suspend the given task. More...
 
static void resume (basic_task *t)
 Resume the given task. More...
 
static void yield ()
 Yield the scheduler. More...
 
static void sleep (unsigned int secs)
 sleep this task for n seconds More...
 
static void usleep (unsigned int usec)
 sleep this task for n micro seconds More...
 
static void nsleep (const timespan_t &req, timespan_t *rem)
 pause execution for a specified time More...
 
static uint32_t get_tasks ()
 Get current number of tasks. More...
 
static bool is_current (basic_task *task)
 Is the given task the current running task ? More...
 
static basic_taskget_self ()
 Get the current task. More...
 
- Static Protected Member Functions inherited from mn::basic_task
static void runtaskstub (void *parm)
 Adapter function that allows you to write a class specific on_task() function that interfaces with FreeRTOS. More...
 

Detailed Description

Extends the basic_convar_task with a message queue support.

Note
This is an abstract base class.
To use this, you need to subclass it. All of your task should
be derived from the basic_task class. Then implement the virtual on_message
function.

Member Typedef Documentation

◆ message_id

Constructor & Destructor Documentation

◆ basic_message_task() [1/2]

mn::ext::basic_message_task::basic_message_task ( std::string  strName = "message_task",
basic_task::priority  uiPriority = priority::Normal,
unsigned short  usStackDepth = MN_THREAD_CONFIG_MINIMAL_STACK_SIZE 
)
explicit

Constructor for this task.

Parameters
strNameName of the Task. Only useful for debugging.
uiPriorityFreeRTOS priority of this Task.
usStackDepthNumber of "words" allocated for the Task stack. default 2048

◆ basic_message_task() [2/2]

mn::ext::basic_message_task::basic_message_task ( const basic_message_task )
delete

Member Function Documentation

◆ on_message()

virtual void mn::ext::basic_message_task::on_message ( id_t  id,
void *  message 
)
protectedpure virtual

Implementation of your actual message code.

Note
You must override this function.
Parameters
[in]idThe current message id
[in]messagePointer of the real message

◆ on_task()

int mn::ext::basic_message_task::on_task ( )
privatevirtual

The current message handling code.

Returns
NULL

Reimplemented from mn::basic_task.

◆ operator=()

basic_message_task& mn::ext::basic_message_task::operator= ( const basic_message_task )
delete

◆ post_msg() [1/3]

void mn::ext::basic_message_task::post_msg ( message_id  msg_id,
unsigned int  timeout 
)
inline

Create the task message and add the message to the task queue, without message data.

Parameters
msg_idThe message id
timeoutHow long to wait to add the item to the queue

◆ post_msg() [2/3]

void mn::ext::basic_message_task::post_msg ( message_id  msg_id,
void *  message_data,
unsigned int  timeout 
)
inline

Create the task message and add the message to the task queue, with message data.

Parameters
msg_idThe message id
message_dataThe user message data for the task message
timeoutHow long to wait to add the item to the queue

◆ post_msg() [3/3]

void mn::ext::basic_message_task::post_msg ( task_message msg,
unsigned int  timeout 
)

Add a pre-created task message to the task queue.

Parameters
[in]msgThe specific message you are adding to the task queue
timeoutHow long to wait to add the item to the queue

Member Data Documentation

◆ m_cvMessage

convar_t mn::ext::basic_message_task::m_cvMessage
protected

◆ m_ltMessageQueueLock

mutex_t mn::ext::basic_message_task::m_ltMessageQueueLock
protected

◆ m_qeMessageQueue

queue::queue_t mn::ext::basic_message_task::m_qeMessageQueue
protected

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