24 #include <utils/ipc/msg.h> 25 #include <utils/ipc/msg_exceptions.h> 29 #include <sys/types.h> 36 class IPCMessageQueueData
78 bool create,
bool destroy_on_delete)
80 data =
new IPCMessageQueueData();
82 this->destroy_on_delete = destroy_on_delete;
86 data->msgflg |= IPC_CREAT;
89 data->key = ftok(path,
id);
90 data->msgqid = msgget(data->key, data->msgflg);
105 data =
new IPCMessageQueueData();
107 this->destroy_on_delete = destroy_on_delete;
111 data->msgflg |= IPC_CREAT;
115 data->msgqid = msgget(data->key, data->msgflg);
122 if ((data->msgqid != -1) && destroy_on_delete) {
123 msgctl(data->msgqid, IPC_RMID, 0);
138 if (data->msgqid == -1) {
139 data->msgqid = msgget(data->key, data->msgflg);
140 if (data->msgqid == -1) {
144 if (msgctl(data->msgqid, IPC_STAT, &m) != -1) {
153 if (msgctl(data->msgqid, IPC_STAT, &m) != -1) {
181 if (data->msgqid == -1)
return false;
183 if ( msgrcv(data->msgqid, (
struct msgbuf *)msg, data_size -
sizeof(
long),
184 mtype, IPC_NOWAIT) == -1 ) {
185 if ((errno == EIDRM) || (errno == EINVAL)) {
188 if (errno == E2BIG) {
214 if (data->msgqid == -1)
return false;
216 if ( (*data_size = msgrcv(data->msgqid, (
struct msgbuf *)msg,
217 max_data_size -
sizeof(
long), 0, IPC_NOWAIT)) == -1 ) {
218 if ((errno == EIDRM) || (errno == EINVAL)) {
238 if (data->msgqid == -1)
return false;
240 if (msgsnd(data->msgqid, msg, data_size -
sizeof(
long), IPC_NOWAIT) == -1) {
241 if (errno == EIDRM) {
bool send(MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size)
Receive messages from this queue of any type.
Fawkes library namespace.
bool isValid()
Check if the message queue is valid If the queue could not be opened yet (for example if you gave cre...
~IPCMessageQueue()
Destructor.
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 o...
static const int MaxMessageSize
Maximum size of a message.
This is the struct of the messages that has to be fed to send and receive methods.
bool recv(long mtype, MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Message did not fit into buffer.