#ifndef MESSAGE_H_ #define MESSAGE_H_ #include #include #define MAX_MESSAGE_LENGTH 277 // Message structure typedef struct message_t message_t; // and handle type typedef message_t *message_handle_t; typedef void (*observer_func)(void); #ifdef TEST //This is a test build // Makes private functions reachable by the tester #define unit_static // Calls all observer functions attached to this message. unit_static void message_state_changed(message_handle_t message_handle); #else #define unit_static static #endif // 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, int message_length, uint16_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, uint16_t sent_to); // Returns the message. char *message_get(message_handle_t message_handle, int *message_length); // Returns true if the message has been previously sent to this node, false otherwise. bool message_sent_to(message_handle_t message_handle, uint16_t node); // Attaches an observer function to the message. void message_attach_observer(message_handle_t message_handle, observer_func observer); #endif //MESSAGE_H_