My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Macros | Functions
msu_message.h File Reference

Messages passed to MSUs. More...

#include "message_queue.h"
#include "msu_type.h"

Go to the source code of this file.

Classes

struct  composite_key
 The composite key is used to store a key of arbitrary length (up to 192 bytes). More...
 
struct  msu_msg_key
 Used to uniquely identify the source of a message, used in state storage as well as routing. More...
 
struct  msu_provinance_item
 Item in the chain of history kept track of in each MSU. More...
 
struct  msg_provinance
 Keeps track of which MSUs have seen a given message header. More...
 
struct  msu_msg_hdr
 Header for messages passed to MSUs. More...
 
struct  msu_msg
 A message that is to be delivered to an instance of an MSU. More...
 

Macros

#define MAX_PATH_LEN   8
 The maximum path length recorded for a messages path through MSUs. More...
 

Functions

unsigned int msu_msg_sender_type (struct msg_provinance *prov)
 
struct msu_provinance_itemget_provinance_item (struct msg_provinance *p, struct msu_type *type)
 
int add_provinance (struct msg_provinance *prov, struct local_msu *sender)
 Adds a new item to the path of MSUs taken within the mesasge provinance in the header. More...
 
int init_msu_msg_hdr (struct msu_msg_hdr *hdr, struct msu_msg_key *key)
 Initializes and resets a message header, storing a copy of the provided key. More...
 
int set_msg_key (int32_t id, struct msu_msg_key *key)
 Sets the key's ID and composite-ID to be equal to the provided id. More...
 
int seed_msg_key (void *seed, size_t seed_size, struct msu_msg_key *key)
 Sets the key's composite-ID to the provided value, and sets the key's ID to a hash of the value. More...
 
void destroy_msu_msg_and_contents (struct msu_msg *msg)
 Frees both the message and message data. More...
 
struct msu_msgread_msu_msg (struct local_msu *msu, int fd, size_t size)
 Reads an MSU message of the given size from the provided file descriptor. More...
 
int schedule_msu_msg (struct msg_queue *q, struct msu_msg *data, struct timespec *interval)
 Schedules an MSU message to be delivered after interval time has passed. More...
 
int enqueue_msu_msg (struct msg_queue *q, struct msu_msg *data)
 Enqueues a message for immediate delivery. More...
 
struct msu_msgdequeue_msu_msg (struct msg_queue *q)
 Dequeues an MSU message from the provided message queue. More...
 
void * serialize_msu_msg (struct msu_msg *msg, struct msu_type *dst_type, size_t *size_out)
 Converts an MSU message into a serializes stream of bytes. More...
 
struct msu_msgcreate_msu_msg (struct msu_msg_hdr *hdr, size_t data_size, void *data)
 Creates an MSU message with the appropriate header, data size, and data. More...
 

Detailed Description

Messages passed to MSUs.

Definition in file msu_message.h.

Macro Definition Documentation

#define MAX_PATH_LEN   8

The maximum path length recorded for a messages path through MSUs.

Definition at line 66 of file msu_message.h.

Function Documentation

int add_provinance ( struct msg_provinance prov,
struct local_msu sender 
)

Adds a new item to the path of MSUs taken within the mesasge provinance in the header.

Parameters
provExisting provinance structure
senderThe sending MSU, to be added to the provinance
Returns
0 on success, -1 on error

Definition at line 74 of file msu_message.c.

struct msu_msg* create_msu_msg ( struct msu_msg_hdr hdr,
size_t  data_size,
void *  data 
)

Creates an MSU message with the appropriate header, data size, and data.

Returns
The newly-allocated MSU message

Definition at line 161 of file msu_message.c.

struct msu_msg* dequeue_msu_msg ( struct msg_queue q)

Dequeues an MSU message from the provided message queue.

Returns
the dequeued message on success, NULL if the message is not available, or is not an MSU_MSG

Definition at line 124 of file msu_message.c.

void destroy_msu_msg_and_contents ( struct msu_msg msg)

Frees both the message and message data.

Definition at line 156 of file msu_message.c.

int enqueue_msu_msg ( struct msg_queue q,
struct msu_msg data 
)

Enqueues a message for immediate delivery.

Parameters
qThe queue into which the message is to be placed
dataThe message to be delivered
Returns
0 on success, -1 on error

Definition at line 101 of file msu_message.c.

struct msu_provinance_item* get_provinance_item ( struct msg_provinance p,
struct msu_type type 
)
Returns
The provinance item with the specified type or NULL if none exists

Definition at line 45 of file msu_message.c.

int init_msu_msg_hdr ( struct msu_msg_hdr hdr,
struct msu_msg_key key 
)

Initializes and resets a message header, storing a copy of the provided key.

Note: key can be a local variable. Its value is copied.

Parameters
hdrThe header to reset
keyThe key to set a copy of in the header
Returns
0 on success, -1 on error

Definition at line 35 of file msu_message.c.

unsigned int msu_msg_sender_type ( struct msg_provinance prov)
Returns
the type of the MSU which last sent this message header

Definition at line 41 of file msu_message.c.

struct msu_msg* read_msu_msg ( struct local_msu msu,
int  fd,
size_t  size 
)

Reads an MSU message of the given size from the provided file descriptor.

Utilizes the msu_type::deserialize function of the provided MSU if applicable, otherwise just reads the provided payload.

Parameters
msuThe msu from which to take the deserialization function
fdThe file descriptor from which to read the message
sizeThe size of the message available in the file descriptor

Definition at line 171 of file msu_message.c.

int schedule_msu_msg ( struct msg_queue q,
struct msu_msg data,
struct timespec *  interval 
)

Schedules an MSU message to be delivered after interval time has passed.

Parameters
qThe queue into which the message is to be placed
dataThe message to be delivered
intervalThe amount of time which must elapse before the message is to be delivered
Returns
0 on success, -1 on error

Definition at line 106 of file msu_message.c.

int seed_msg_key ( void *  seed,
size_t  seed_size,
struct msu_msg_key key 
)

Sets the key's composite-ID to the provided value, and sets the key's ID to a hash of the value.

Definition at line 62 of file msu_message.c.

void* serialize_msu_msg ( struct msu_msg msg,
struct msu_type dst_type,
size_t *  size_out 
)

Converts an MSU message into a serializes stream of bytes.

Parameters
msgThe message to be serialized
dst_typeThe MSU type to which the message is to be delivered. Serialization utilizes msu_type::serialize if non-NULL.
size_outAn output argument, set to the size of the newly serialized message
Returns
A newly-allocated (must be freed externally) serialized copy of msg

Definition at line 216 of file msu_message.c.

int set_msg_key ( int32_t  id,
struct msu_msg_key key 
)

Sets the key's ID and composite-ID to be equal to the provided id.

Definition at line 54 of file msu_message.c.