IPC message queue.
More...
#include <utils/ipc/msg.h>
|
struct | MessageStruct |
| This is the struct of the messages that has to be fed to send and receive methods. More...
|
|
|
| IPCMessageQueue (const char *path, char id, bool create=false, bool destroy_on_delete=false) |
| Create or open a message queue If a message key with the given identification criteria exists it is opened for sending and receiving. More...
|
|
| IPCMessageQueue (int id, bool create=false, bool destroy_on_delete=false) |
| Create or open a message queue This is a simplified version of the above function. More...
|
|
| ~IPCMessageQueue () |
| Destructor. More...
|
|
bool | isValid () |
| Check if the message queue is valid If the queue could not be opened yet (for example if you gave create=false to the constructor) isValid() will try to open the queue. More...
|
|
bool | recv (long mtype, MessageStruct *msg, unsigned int data_size) |
| Receive messages from this queue of the given message type. More...
|
|
bool | recvNext (MessageStruct *msg, unsigned int max_data_size, int *data_size) |
| Receive messages from this queue of any type. More...
|
|
bool | send (MessageStruct *msg, unsigned int data_size) |
| Receive messages from this queue of the given message type. More...
|
|
|
static long | mtype (char *buffer) |
| Get the message type. More...
|
|
IPC message queue.
This class gives access to IPC message queues. You can use this to send messages between different applications running on the same host.
- See also
- qa_ipc_msg.cpp
- Author
- Tim Niemueller
Definition at line 32 of file msg.h.
◆ IPCMessageQueue() [1/2]
fawkes::IPCMessageQueue::IPCMessageQueue |
( |
const char * |
path, |
|
|
char |
id, |
|
|
bool |
create = false , |
|
|
bool |
destroy_on_delete = false |
|
) |
| |
Create or open a message queue If a message key with the given identification criteria exists it is opened for sending and receiving.
If no such queue exists a new one is create. Use isValid() to check success.
- Parameters
-
path | path given to ftok to create the message queue identifier |
id | id given to ftok to create the message queue identifier |
destroy_on_delete | destroy the message queue if the dtor is called? |
create | Create the queue if it does not exist, do not create the queue otherwise, use isValid() to check if queue was opened |
Definition at line 77 of file msg.cpp.
◆ IPCMessageQueue() [2/2]
fawkes::IPCMessageQueue::IPCMessageQueue |
( |
int |
id, |
|
|
bool |
create = false , |
|
|
bool |
destroy_on_delete = false |
|
) |
| |
Create or open a message queue This is a simplified version of the above function.
The path is omitted and . (dot, the current working directory) is used instead.
- Parameters
-
id | id give to ftok to create the message queue identifier, preferably use an id from msg_registry.h |
destroy_on_delete | set to true to destroy the message queue if the dtor is called |
create | if true create the queue if it does not exist, do not create the queue otherwise, use isValid() to check if queue was opened successfully. |
Definition at line 103 of file msg.cpp.
◆ ~IPCMessageQueue()
fawkes::IPCMessageQueue::~IPCMessageQueue |
( |
| ) |
|
Destructor.
Definition at line 120 of file msg.cpp.
◆ isValid()
bool fawkes::IPCMessageQueue::isValid |
( |
| ) |
|
Check if the message queue is valid If the queue could not be opened yet (for example if you gave create=false to the constructor) isValid() will try to open the queue.
- Returns
- This method returns false if the message queue could not be opened or if it has been closed, it returns true if messages can be sent or received.
Definition at line 136 of file msg.cpp.
◆ mtype()
static long fawkes::IPCMessageQueue::mtype |
( |
char * |
buffer | ) |
|
|
inlinestatic |
Get the message type.
- Parameters
-
buffer | the buffer of the message as returned by getMessage() |
- Returns
- the message type
Definition at line 67 of file msg.h.
◆ recv()
bool fawkes::IPCMessageQueue::recv |
( |
long |
mtype, |
|
|
MessageStruct * |
msg, |
|
|
unsigned int |
data_size |
|
) |
| |
Receive messages from this queue of the given message type.
- Parameters
-
mtype | the message type |
msg | The place where the received data will be copied on success. You must have the mtype long field as described for MessageStruct. On recv the struct does not have to be inialized, but the memory has to be allocated already. See the note about the data_size! |
data_size | The size of the whole struct, including the mtype field. NOT just the size of the mtext field as for msgrcv! |
- Returns
- returns true, if a message of the appropriate type could be read that fitted the given memory size. The received data is stored in data.
- See also
- MessageStruct
- Exceptions
-
Definition at line 179 of file msg.cpp.
◆ recvNext()
bool fawkes::IPCMessageQueue::recvNext |
( |
MessageStruct * |
msg, |
|
|
unsigned int |
max_data_size, |
|
|
int * |
data_size |
|
) |
| |
Receive messages from this queue of any type.
- Parameters
-
msg | a pointer to a message struct of the appropriate size. This is most likely your own incarnation. It must point to a chunk of memory which has at least max_data_size bytes. |
max_data_size | The maximum size the data may have. |
data_size | after successfuly recv will contain the number of bytes actually copied into data including the size of the mtype field! |
- Returns
- true, if a message could be read that fitted the given memory size. The received data is stored in data. False, if no message was in the queue or the queue has been removed.
- See also
- MessageStruct
Definition at line 211 of file msg.cpp.
◆ send()
bool fawkes::IPCMessageQueue::send |
( |
MessageStruct * |
msg, |
|
|
unsigned int |
data_size |
|
) |
| |
Receive messages from this queue of the given message type.
- Parameters
-
msg | The data to be sent, see note for recv() |
data_size | the full data size (sizeof(typeof(data))), NOT just the size of the mtext field (see recv()). |
- Returns
- true, if the message could be sent, false otherwise.
- See also
- MessageStruct
Definition at line 236 of file msg.cpp.
◆ destroy_on_delete
fawkes::IPCMessageQueue::destroy_on_delete |
|
protected |
destroy this message queue on delete?
Definition at line 73 of file msg.h.
◆ MaxMessageSize
const int fawkes::IPCMessageQueue::MaxMessageSize = 8192 |
|
static |
Maximum size of a message.
Definition at line 35 of file msg.h.
The documentation for this class was generated from the following files: