SW Task Event Loop Framework v1.0.0
High-performance C++ asynchronous event loop framework with timer management and promise-based programming
|
Message object for event-driven communication between threads and handlers. More...
#include <Message.h>
Public Member Functions | |
Message () | |
Default constructor - creates empty message. | |
Message (Message &other) | |
Copy constructor - deep copy from another message. | |
virtual | ~Message () |
Virtual destructor. | |
bool | sendToTarget () |
Send this message to its target handler. | |
std::shared_ptr< Message > | dup () const |
Create a deep copy of this message. | |
template<typename T > | |
void | getObject (std::shared_ptr< T > &obj) |
Get attached object as shared pointer of type T. | |
void | setTo (const Message &other) |
Set this message to another message's contents. | |
Static Public Member Functions | |
static std::shared_ptr< Message > | obtain () |
Obtain a new empty message. | |
static std::shared_ptr< Message > | obtain (const Message *message) |
Obtain a copy of an existing message. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler) |
Obtain a message associated with a handler. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what) |
Obtain a message with handler and type code. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, int32_t obtain_arg1) |
Obtain a message with handler, type code, and argument. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, void *obtain_obj) |
Obtain a message with handler, type code, and object pointer. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, int32_t obtain_arg1, int32_t obtain_arg2) |
Obtain a message with handler, type code, and two arguments. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, int32_t obtain_arg1, int32_t obtain_arg2, void *obtain_obj) |
Obtain a message with handler, type code, two arguments, and object pointer. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, int32_t obtain_arg1, int32_t obtain_arg2, int32_t obtain_arg3) |
Obtain a message with handler, type code, and three arguments. | |
static std::shared_ptr< Message > | obtain (const std::shared_ptr< Handler > &handler, int32_t obtain_what, std::shared_ptr< RefBase > obtain_spRef) |
Obtain a message with handler, type code, and smart pointer reference. | |
Public Attributes | |
std::shared_ptr< Handler > | mHandler |
Target handler. | |
std::shared_ptr< Message > | mNextMessage |
Next message in queue. | |
int32_t | what |
Message type code. | |
int32_t | arg1 |
First argument. | |
int32_t | arg2 |
Second argument. | |
int32_t | arg3 |
Third argument. | |
void * | obj |
Raw object pointer. | |
ssize_t | obj_size |
Size of object (if applicable) | |
std::shared_ptr< RefBase > | spRef |
Smart pointer reference. | |
Protected Member Functions | |
Message & | operator= (const Message &other) |
Assignment operator - deep copy from another message. | |
void | clear () |
Clear all fields in the message. | |
Friends | |
class | Handler |
class | EventQueue |
class | SLLooper |
Message object for event-driven communication between threads and handlers.
Message encapsulates data and metadata for asynchronous communication in the event loop framework. It supports flexible construction, deep copy, and safe transfer between threads. Each Message can be associated with a Handler and posted to an event queue (EventQueue) for timed or immediate processing.
Key features:
swt::Message::Message | ( | ) |
Default constructor - creates empty message.
Definition at line 6 of file Message.cpp.
References mHandler, mNextMessage, and spRef.
swt::Message::Message | ( | Message & | other | ) |
Copy constructor - deep copy from another message.
other | Source message to copy from |
Definition at line 21 of file Message.cpp.
References setTo().
|
virtual |
Virtual destructor.
Definition at line 34 of file Message.cpp.
|
protected |
std::shared_ptr< Message > swt::Message::dup | ( | ) | const |
Create a deep copy of this message.
Definition at line 163 of file Message.cpp.
References obtain().
|
inline |
|
static |
Obtain a new empty message.
Definition at line 38 of file Message.cpp.
Referenced by dup(), obtain(), obtain(), obtain(), obtain(), obtain(), obtain(), obtain(), obtain(), obtain(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), swt::Handler::obtainMessage(), and swt::Handler::obtainMessage().
|
static |
Obtain a message associated with a handler.
handler | Target handler |
Definition at line 44 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler and type code.
handler | Target handler |
obtain_what | Message type code |
Definition at line 51 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, and argument.
handler | Target handler |
obtain_what | Message type code |
obtain_arg1 | First argument |
Definition at line 59 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, and two arguments.
handler | Target handler |
obtain_what | Message type code |
obtain_arg1 | First argument |
obtain_arg2 | Second argument |
Definition at line 80 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, and three arguments.
handler | Target handler |
obtain_what | Message type code |
obtain_arg1 | First argument |
obtain_arg2 | Second argument |
obtain_arg3 | Third argument |
Definition at line 105 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, two arguments, and object pointer.
handler | Target handler |
obtain_what | Message type code |
obtain_arg1 | First argument |
obtain_arg2 | Second argument |
obtain_obj | Object pointer |
Definition at line 92 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, and smart pointer reference.
handler | Target handler |
obtain_what | Message type code |
obtain_spRef | Shared pointer reference |
Definition at line 133 of file Message.cpp.
References obtain().
|
static |
Obtain a message with handler, type code, and object pointer.
handler | Target handler |
obtain_what | Message type code |
obtain_obj | Object pointer |
Definition at line 69 of file Message.cpp.
References obtain().
Assignment operator - deep copy from another message.
other | Source message |
Definition at line 184 of file Message.cpp.
References setTo().
bool swt::Message::sendToTarget | ( | ) |
Send this message to its target handler.
Definition at line 146 of file Message.cpp.
References mHandler.
void swt::Message::setTo | ( | const Message & | other | ) |
|
friend |
int32_t swt::Message::arg1 |
int32_t swt::Message::arg2 |
int32_t swt::Message::arg3 |
std::shared_ptr<Handler> swt::Message::mHandler |
std::shared_ptr<Message> swt::Message::mNextMessage |
void* swt::Message::obj |
ssize_t swt::Message::obj_size |
std::shared_ptr<RefBase> swt::Message::spRef |
int32_t swt::Message::what |