mn_msg_task.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_ESP32_MESSAGE_TASK_
20 #define MINLIB_ESP32_MESSAGE_TASK_
21 
22 #include "mn_config.hpp"
23 #if MN_THREAD_CONFIG_CONDITION_VARIABLE_SUPPORT == MN_THREAD_CONFIG_YES
24 
25 
26 #include "mn_convar.hpp"
27 #include "mn_convar_task.hpp"
28 #include "queue/mn_queue.hpp"
29 
30 namespace mn {
31  namespace ext {
35  struct task_message {
36  using message_id = int;
37 
39  void* message;
42  task_message(message_id _id, void* _message = nullptr)
43  : id(_id), message(_message) { }
44  };
56  public:
58 
66  explicit basic_message_task(std::string strName = "message_task",
68  unsigned short usStackDepth = MN_THREAD_CONFIG_MINIMAL_STACK_SIZE);
69 
76  void post_msg(task_message* msg, unsigned int timeout);
77 
85  void post_msg(message_id msg_id, unsigned int timeout) {
86  post_msg(new task_message(msg_id, nullptr), timeout );
87  }
96  void post_msg(message_id msg_id, void* message_data, unsigned int timeout) {
97  post_msg(new task_message(msg_id, message_data), timeout );
98  }
99 
102  protected:
110  virtual void on_message(id_t id, void* message) = 0;
111  private:
116  int on_task();
117  protected:
121  };
122 
124  }
125 }
126 #endif
127 
128 #endif
Definition: mn_mutex.hpp:37
priority
Task priority.
Definition: mn_task.hpp:93
Definition: mn_convar.hpp:55
Definition: mn_convar_task.hpp:42
Extends the basic_convar_task with a message queue support.
Definition: mn_msg_task.hpp:55
mutex_t m_ltMessageQueueLock
Definition: mn_msg_task.hpp:118
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.
Definition: mn_msg_task.hpp:85
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.
Definition: mn_msg_task.cpp:28
int on_task()
The current message handling code.
Definition: mn_msg_task.cpp:50
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.
Definition: mn_msg_task.hpp:96
basic_message_task & operator=(const basic_message_task &)=delete
typename task_message::message_id message_id
Definition: mn_msg_task.hpp:57
virtual void on_message(id_t id, void *message)=0
Implementation of your actual message code.
basic_message_task(const basic_message_task &)=delete
void post_msg(task_message *msg, unsigned int timeout)
Add a pre-created task message to the task queue.
Definition: mn_msg_task.cpp:41
convar_t m_cvMessage
Definition: mn_msg_task.hpp:120
queue::queue_t m_qeMessageQueue
Definition: mn_msg_task.hpp:119
Queue class wrapper for FreeRTOS queues.
Definition: queue/mn_queue.hpp:31
#define MN_THREAD_CONFIG_MINIMAL_STACK_SIZE
Definition: mn_config.hpp:219
Definition: mn_allocator_typetraits.hpp:25
Definition: mn_msg_task.hpp:35
int message_id
Definition: mn_msg_task.hpp:36
message_id id
Definition: mn_msg_task.hpp:38
void * message
Definition: mn_msg_task.hpp:39
task_message(message_id _id, void *_message=nullptr)
Definition: mn_msg_task.hpp:42