Fawkes API  Fawkes Development Version
fawkes::IPCMessageQueue Class Reference

IPC message queue. More...

#include <utils/ipc/msg.h>

List of all members.

Classes

struct  MessageStruct
 This is the struct of the messages that has to be fed to send and receive methods. More...

Public Member Functions

 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.
 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.
 ~IPCMessageQueue ()
 Destructor.
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.
bool recv (long mtype, 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.
bool send (MessageStruct *msg, unsigned int data_size)
 Receive messages from this queue of the given message type.

Static Public Member Functions

static long mtype (char *buffer)
 Get the message type.

Static Public Attributes

static const int MaxMessageSize = 8192
 Maximum size of a message.

Protected Attributes

bool destroy_on_delete
 destroy this message queue on delete?

Detailed Description

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

Constructor & Destructor Documentation

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:
pathpath given to ftok to create the message queue identifier
idid given to ftok to create the message queue identifier
destroy_on_deletedestroy the message queue if the dtor is called?
createCreate 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.

References destroy_on_delete.

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:
idid give to ftok to create the message queue identifier, preferably use an id from msg_registry.h
destroy_on_deleteset to true to destroy the message queue if the dtor is called
createif 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.

References destroy_on_delete.

fawkes::IPCMessageQueue::~IPCMessageQueue ( )

Destructor.

Definition at line 120 of file msg.cpp.

References destroy_on_delete.


Member Function Documentation

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.

static long fawkes::IPCMessageQueue::mtype ( char *  buffer) [inline, static]

Get the message type.

Parameters:
bufferthe buffer of the message as returned by getMessage()
Returns:
the message type

Definition at line 67 of file msg.h.

bool fawkes::IPCMessageQueue::recv ( long  mtype,
MessageStruct msg,
unsigned int  data_size 
)

Receive messages from this queue of the given message type.

Parameters:
mtypethe message type
msgThe 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_sizeThe 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:
MessageTooBigExceptionMessage was too big and did not fit into buffer. Message remains on queue and needs to be fetched with a bigger buffer.

Definition at line 179 of file msg.cpp.

bool fawkes::IPCMessageQueue::recvNext ( MessageStruct msg,
unsigned int  max_data_size,
int *  data_size 
)

Receive messages from this queue of any type.

Parameters:
msga 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_sizeThe maximum size the data may have.
data_sizeafter 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.

bool fawkes::IPCMessageQueue::send ( MessageStruct msg,
unsigned int  data_size 
)

Receive messages from this queue of the given message type.

Parameters:
msgThe data to be sent, see note for recv()
data_sizethe 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.


Member Data Documentation

destroy this message queue on delete?

Definition at line 73 of file msg.h.

Referenced by IPCMessageQueue(), and ~IPCMessageQueue().

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: