/*
 * queue.c
 *
 *  Created on: Oct 25, 2015
 *      Author: tkl
 */

#include <stddef.h>
#include <stdbool.h>
#include <string.h>

#include "queue.h"

int queue_init(struct queue *head)
{
	if(NULL == head)
		return -1;

	head->front = NULL;
	head->rear = NULL;

	return 0;
}

int queue_push(struct queue *head, struct queue_node *node)
{
	if((NULL == head) || (NULL == node))
		return -1;

	if(head->front == NULL) {
		head->front = node;
		head->rear = node;
	}
	else {
		head->rear->next = node;
		head->rear = node;
	}
	return 1;
}

int queue_pop(struct queue *head, struct queue_node *node)
{
	if(NULL == head)
		return -1;

	if(head->front == NULL)
		return 0;
	else {
		memcpy(node, head->front, sizeof(struct queue_node));
		head->front = node->next;
		return 1;
	}
	return 0;
}

bool queue_is_empty(struct queue *head)
{
	if(NULL == head)
		return false;

	if(head->front == NULL)
		return true;
	return false;
}
