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.

52 lines
1.4 KiB

5 years ago
#ifndef HELPERS_H_
#define HELPERS_H_
#define _GNU_SOURCE
#include <stdint.h>
#include "types.h"
#include "node.h"
#include "message.h"
#include "circ_buff.h"
// Macros to turn a numeric macro into a string literal
#define xstr(s) str(s)
#define str(s) #s
// AEMs file related definitions
#define AEM_ID_LEN 4
#define AEM_BUFFER_LEN 5
// Format for fscanf() to read the AEM numbers
#define AEM_LINE_FORMAT "%" xstr(AEM_ID_LEN) "s\n"
node_id_t extract_id_from_ip(const ipv4_t ip);
void set_timer_and_handler(void (*handler)(int), long int timer_interval);
uint16_t create_message(char *new_message, uint16_t max_message_length,
node_handle_t *neighbors, uint8_t num_neighbors, node_id_t own_id);
int create_socket_and_listen(port_t port, uint8_t backlog_size);
void send_message(node_handle_t peer, message_handle_t message);
node_id_t accept_connection(int sock, address_t *client_name,
fd_set *active_fd_set, int *listens_on);
uint16_t checkAddNode(node_handle_t **neighbors, uint16_t num_neighbors ,
address_t peer_name, node_id_t node_id);
void write_to_peer(int filedes, const char *message);
int read_from_peer(int file_des, uint16_t max_line,
cbuf_handle_t *message_buffer, node_handle_t **neighbors,
uint16_t num_neighbors);
uint16_t fread_neighbors(char *AEM_file, node_handle_t **neighbors,
port_t port);
void init_sockaddr(address_t *peer_name, const ipv4_t hostname, port_t port);
#endif //HELPERS_H_