Top: Multithreading: message
#include <pasync.h> message::message(int id, int param = 0); int message::id; int message::result; int message::param;
A message object or an object of a derived class can be used to post data to a message queue (msgqueue). Since all messages in the given queue are processed by one handler, they have to be distinguished by some ID. Like in Windows, you define your own message IDs in the range MSG_USER to MSG_USER_MAX. A simple message can also contain an additional parameter of type int.
For more complex message structures you can define classes derived from message - the message queue manager can work with any descendant class as well.
IMPORTANT NOTES: (1) a message object should always be constructed dynamically, i.e. using operator new; (2) a message object is always destroyed by the queue manager after it has been processed; (3) a message object can be sent and processed only once.
message::message(int id, int param = 0) constructs a message object and assigns id and param fields. param is an additional field that can be used in your application at your own discretion.
int message::id -- this field contains a message ID assigned through the constructor.
int message::result -- through this field a message handler can return some simple answer to the sender of this message.
int message::param contains the optional parameter.