Final assignment for the course "Real Time and Embedded Systems" of THMMY in AUTH university.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 lines
1.5 KiB

#ifndef MESSAGE_H_
#define MESSAGE_H_
#include <stdbool.h>
#include <stdint.h>
#include "types.h"
// max_message_length = sender_id 4 chars
// + underscore 1 char
// + receiver_id 4 chars
// + underscore 1 char
// + time-stamp 10 chars
// + underscore 1 char
// + message_text 256 chars (max)
// = 277 chars
#define MAX_MESSAGE_LENGTH 277
// Message structure
typedef struct message_t message_t;
// and handle type
typedef message_t *message_handle_t;
// Initializes a message structure and returns the message handle. User must provide the length of
// the message without the null termination character (strlen);
message_handle_t message_init(const char *message, uint16_t length, node_id_t received_from);
// Frees a message structure.
void message_free(message_handle_t message_handle);
// Adds an new receiver to the message.
void message_add_sent_to(message_handle_t message_handle, node_id_t sent_to);
// Returns the message. This functions returns a string in a statically allocated buffer, which
// subsequent calls will overwrite!
char *message_get(message_handle_t message_handle, int *message_length);
// Returns true if the message has been previously sent to this ip, false otherwise.
bool message_sent_to(message_handle_t message_handle, node_id_t id);
#endif //MESSAGE_H_