My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
msu_message.c File Reference
#include "msu_message.h"
#include "logging.h"
#include "communication.h"
#include "local_msu.h"
#include "uthash.h"
#include "runtime_dfg.h"
#include "profiler.h"
#include <stdlib.h>

Go to the source code of this file.

Functions

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...
 
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 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...
 
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 enqueue_msu_msg (struct msg_queue *q, struct msu_msg *data)
 Enqueues a message for immediate delivery. 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...
 
struct msu_msgdequeue_msu_msg (struct msg_queue *q)
 Dequeues an MSU message from the provided message queue. More...
 
int read_msu_msg_hdr (int fd, struct msu_msg_hdr *hdr)
 
void destroy_msu_msg_and_contents (struct msu_msg *msg)
 Frees both the message and message data. 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...
 
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...
 
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...
 

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 read_msu_msg_hdr ( int  fd,
struct msu_msg_hdr hdr 
)

Definition at line 147 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.