Commit f86b8b5d authored by Andreas Schmidt's avatar Andreas Schmidt

Added const wherever possible.

parent f670e8a7
......@@ -14,7 +14,7 @@ void PrrtBlock_free(PrrtBlock **mblock) {
}
int PrrtBlock_alloc(PrrtBlock **mblock, PrrtCodingParams *cpar) {
int PrrtBlock_alloc(PrrtBlock **mblock, const PrrtCodingParams *cpar) {
*mblock = malloc(sizeof(PrrtBlock));
(*mblock)->coding_params = *cpar;
......@@ -24,19 +24,19 @@ int PrrtBlock_alloc(PrrtBlock **mblock, PrrtCodingParams *cpar) {
return 0;
}
int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, PrrtPacket *packet_ptr) {
int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, const PrrtPacket *packet_ptr) {
List_push(block_ptr->data_blocks, packet_ptr);
block_ptr->data_count++;
block_ptr->largest_data_length = MAX(block_ptr->largest_data_length, packet_ptr->payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
return 0;
}
int PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, PrrtPacket *ptr) {
int PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, const PrrtPacket *ptr) {
List_push(block_ptr->redundancy_blocks, ptr);
block_ptr->redundancy_count++;
return 0;
}
int PrrtBlock_ready(PrrtBlock *block_ptr) {
int PrrtBlock_ready(const PrrtBlock *block_ptr) {
return (block_ptr->data_count == block_ptr->coding_params.k) ? TRUE : FALSE;
}
......
......@@ -19,16 +19,16 @@ typedef struct {
/**
* Allocate space for a block.
*/
int PrrtBlock_alloc(PrrtBlock **mblock, PrrtCodingParams *cpar);
int PrrtBlock_alloc(PrrtBlock **mblock, const PrrtCodingParams *cpar);
/**
* Frees the PrrtBlock data structure.
*/
void PrrtBlock_free(PrrtBlock **mblock);
int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, PrrtPacket *packet_ptr);
int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, const PrrtPacket *packet_ptr);
int PrrtBlock_ready(PrrtBlock *block_ptr);
int PrrtBlock_ready(const PrrtBlock *block_ptr);
PrrtPacket *PrrtBlock_get_first_data(PrrtBlock *block_ptr);
......
......@@ -8,17 +8,17 @@
void *encode_general_header(void *buf_ptr, const PrrtPacket *packet);
void *encode_data_header(void *buf_ptr, void *payload);
void *encode_data_header(void *buf_ptr, const void *payload);
void *encode_redundancy_header(void *buf_ptr, void *payload);
void *encode_redundancy_header(void *buf_ptr, const void *payload);
void *encode_feedback_header(void *buf_ptr, void *payload);
void *encode_feedback_header(void *buf_ptr, const void *payload);
void *decode_data_header(void *buf_ptr, const void *payload_ptr);
void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr);
void *decode_feedback_header(void *buf_ptr, void *payload_ptr);
void *decode_feedback_header(void *buf_ptr, const void *payload_ptr);
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr) {
return (uint8_t) ((packet_ptr->type_priority >> 4) & 0x0F);
......@@ -107,7 +107,7 @@ int PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
return 0;
}
void *encode_redundancy_header(void *buf_ptr, void *payload) {
void *encode_redundancy_header(void *buf_ptr, const void *payload) {
PrrtPacketRedundancyPayload *redundancyPayload = payload;
uint16_t *baseSeqNo = (uint16_t *) buf_ptr;
......@@ -125,7 +125,7 @@ void *encode_redundancy_header(void *buf_ptr, void *payload) {
return buf_ptr;
}
void *encode_feedback_header(void *buf_ptr, void *payload) {
void *encode_feedback_header(void *buf_ptr, const void *payload) {
PrrtPacketFeedbackPayload *feedbackPayload = payload;
uint32_t *receiver_ip = (uint32_t *) buf_ptr;
......@@ -171,7 +171,7 @@ void *encode_feedback_header(void *buf_ptr, void *payload) {
return buf_ptr;
}
void *encode_data_header(void *buf_ptr, void *payload) {
void *encode_data_header(void *buf_ptr, const void *payload) {
PrrtPacketDataPayload *data_payload = payload;
uint32_t *timestamp = (uint32_t *) buf_ptr;
......@@ -262,7 +262,7 @@ void *decode_redundancy_header(void *buf_ptr, const void *payload_ptr) {
return buf_ptr;
}
void *decode_feedback_header(void *buf_ptr, void *payload_ptr) {
void *decode_feedback_header(void *buf_ptr, const void *payload_ptr) {
PrrtPacketFeedbackPayload *feedback_payload = (PrrtPacketFeedbackPayload *) payload_ptr;
uint32_t *receiver_addr = (uint32_t *) buf_ptr;
......
......@@ -11,7 +11,7 @@
#include "feedback_receiver.h"
#include "data_transmitter.h"
int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender) {
int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender) {
sock_ptr->seqno_source = 1;
// Create Data Socket
......@@ -73,7 +73,7 @@ int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender) {
return 0;
}
int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port) {
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port) {
PrrtReceiver recv = {host , port};
if(sock_ptr->receiver_len < PRRT_MAX_RECEIVER_COUNT) {
......@@ -86,7 +86,7 @@ int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port) {
return 0;
}
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len) {
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len) {
pthread_mutex_lock(&sock_ptr->out_queue_filled_mutex);
PrrtPacket * packet = malloc(sizeof(PrrtPacket));
......@@ -100,7 +100,7 @@ int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len) {
return 0;
}
uint32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void* buf_ptr) {
uint32_t PrrtSocket_recv(const PrrtSocket *sock_ptr, void *buf_ptr) {
unsigned char buffer[MAX_PAYLOAD_LENGTH];
while(1)
......@@ -155,7 +155,7 @@ uint32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void* buf_ptr) {
return 0;
}
int PrrtSocket_close(PrrtSocket *sock_ptr) {
int PrrtSocket_close(const PrrtSocket *sock_ptr) {
// TODO: shut down threads;
// TODO: clean up all receivers
......@@ -169,7 +169,7 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
return 0;
}
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, void *bufin, size_t length) {
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length) {
ssize_t n;
struct sockaddr_in remote;
socklen_t addrlen = sizeof(remote);
......
......@@ -10,7 +10,7 @@
#include <pthread.h>
typedef struct {
char* host_name;
const char* host_name;
uint16_t port;
} PrrtReceiver;
......@@ -34,11 +34,11 @@ typedef struct {
} PrrtSocket;
int PrrtSocket_create(PrrtSocket *sock_ptr, uint16_t port, uint8_t is_sender);
int PrrtSocket_close(PrrtSocket *sock_ptr);
int PrrtSocket_connect(PrrtSocket *sock_ptr, char *host, uint16_t port);
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, size_t data_len);
uint32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void* buf_ptr);
PrrtPacket *PrrtSocket_recv_feedback(PrrtSocket *sock_ptr, void *bufin, size_t length);
int PrrtSocket_create(PrrtSocket *sock_ptr, const uint16_t port, const uint8_t is_sender);
int PrrtSocket_close(const PrrtSocket *sock_ptr);
int PrrtSocket_connect(PrrtSocket *sock_ptr, const char *host, const uint16_t port);
int PrrtSocket_send(PrrtSocket *sock_ptr, const void *data, const size_t data_len);
uint32_t PrrtSocket_recv(const PrrtSocket *sock_ptr, void *buf_ptr);
PrrtPacket *PrrtSocket_recv_feedback(const PrrtSocket *sock_ptr, void *bufin, const size_t length);
#endif // PRRT_SOCKET_H
......@@ -2,7 +2,7 @@
#include <arpa/inet.h>
#include "common.h"
int print_buffer(char* buf, int length) {
int print_buffer(const char *buf, const int length) {
int i;
for(i = 0; i < length; i++) {
if(i % 4 == 0) {
......@@ -13,7 +13,7 @@ int print_buffer(char* buf, int length) {
printf("\n");
}
void print_gf(gf* start, int len) {
void print_gf(const gf *start, const int len) {
printf("GF: ");
int i;
for (i = 0; i < len; i++) {
......
......@@ -3,8 +3,8 @@
#include "../prrt/vdmcode/block_code.h"
int print_buffer(char* buf, int length);
void print_gf(gf* start, int len);
int print_buffer(const char *buf, const int length);
void print_gf(const gf *start, const int len);
#define PERROR(fmt, args...) \
printf("PRRT ERROR: " fmt, ## args);
......
......@@ -6,7 +6,7 @@ List *List_create()
return calloc(1, sizeof(List));
}
void List_destroy(List *list)
void List_destroy(const List *list)
{
LIST_FOREACH(list, first, next, cur) {
if(cur->prev) {
......@@ -19,7 +19,7 @@ void List_destroy(List *list)
}
void List_clear(List *list)
void List_clear(const List *list)
{
LIST_FOREACH(list, first, next, cur) {
free(cur->value);
......@@ -27,14 +27,14 @@ void List_clear(List *list)
}
void List_clear_destroy(List *list)
void List_clear_destroy(const List *list)
{
List_clear(list);
List_destroy(list);
}
void List_push(List *list, void *value)
void List_push(List *list, const void *value)
{
ListNode *node = calloc(1, sizeof(ListNode));
......@@ -55,13 +55,13 @@ void List_push(List *list, void *value)
return;
}
void *List_pop(List *list)
void *List_pop(const List *list)
{
ListNode *node = list->last;
return node != NULL ? List_remove(list, node) : NULL;
}
void List_unshift(List *list, void *value)
void List_unshift(List *list, const void *value)
{
ListNode *node = calloc(1, sizeof(ListNode));
......@@ -82,13 +82,13 @@ void List_unshift(List *list, void *value)
return;
}
void *List_shift(List *list)
void *List_shift(const List *list)
{
ListNode *node = list->first;
return node != NULL ? List_remove(list, node) : NULL;
}
void *List_remove(List *list, ListNode *node)
void *List_remove(List *list, const ListNode *node)
{
void *result = NULL;
......
......@@ -20,21 +20,21 @@ typedef struct List {
} List;
List *List_create();
void List_destroy(List *list);
void List_clear(List *list);
void List_clear_destroy(List *list);
void List_destroy(const List *list);
void List_clear(const List *list);
void List_clear_destroy(const List *list);
#define List_count(A) ((A)->count)
#define List_first(A) ((A)->first != NULL ? (A)->first->value : NULL)
#define List_last(A) ((A)->last != NULL ? (A)->last->value : NULL)
void List_push(List *list, void *value);
void *List_pop(List *list);
void List_push(List *list, const void *value);
void *List_pop(const List *list);
void List_unshift(List *list, void *value);
void *List_shift(List *list);
void List_unshift(List *list, const void *value);
void *List_shift(const List *list);
void *List_remove(List *list, ListNode *node);
void *List_remove(List *list, const ListNode *node);
#define LIST_FOREACH(L, S, M, V) ListNode *_node = NULL;\
ListNode *V = NULL;\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment