2014-09-05 18:21:58 +02:00
|
|
|
/*
|
2015-01-30 15:41:14 +01:00
|
|
|
* Copyright (C) 2014, 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License v2.1. See the file LICENSE in the top level directory for
|
|
|
|
* more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-02-13 12:35:11 +01:00
|
|
|
* @defgroup net_ng_pktqueue Packet Queue
|
2014-10-13 19:30:12 +02:00
|
|
|
* @brief Packet wrapper for the Priority Queue
|
2014-10-11 08:20:50 +02:00
|
|
|
* @ingroup net
|
2014-09-05 18:21:58 +02:00
|
|
|
* @{
|
|
|
|
*
|
2015-01-30 15:41:14 +01:00
|
|
|
* @file
|
2015-02-13 12:35:11 +01:00
|
|
|
* @brief ng_pktsnip_t-centric wrapper for @ref priority_queue_t
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2015-01-30 15:41:14 +01:00
|
|
|
#ifndef NG_PKTQUEUE_H_
|
|
|
|
#define NG_PKTQUEUE_H_
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-01-30 15:41:14 +01:00
|
|
|
#include "net/ng_pkt.h"
|
2014-09-05 18:21:58 +02:00
|
|
|
#include "priority_queue.h"
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-09-05 18:21:58 +02:00
|
|
|
/**
|
|
|
|
* @brief data type for packet queue nodes
|
|
|
|
*
|
|
|
|
* @extends priority_queue_node_t
|
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
typedef struct ng_pktqueue_node {
|
|
|
|
struct ng_pktqueue_node *next; /**< next node in queue */
|
2014-09-05 18:21:58 +02:00
|
|
|
uint32_t priority; /**< priority of the node */
|
2015-01-30 15:41:14 +01:00
|
|
|
ng_pktsnip_t *data; /**< pointer to the data */
|
|
|
|
} ng_pktqueue_node_t;
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief data type for packet queues
|
|
|
|
*
|
2014-10-11 08:20:50 +02:00
|
|
|
* @extends priority_queue_t
|
2014-09-05 18:21:58 +02:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2015-01-30 15:41:14 +01:00
|
|
|
ng_pktqueue_node_t *first; /**< first node in the queue */
|
|
|
|
} ng_pktqueue_t;
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
/**
|
2015-01-30 15:41:14 +01:00
|
|
|
* @brief Static initializer for ng_pktqueue_node_t
|
2014-09-05 18:21:58 +02:00
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
#define NG_PKTQUEUE_NODE_INIT { NULL, NULL, 0 }
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes a packet queue node.
|
2015-01-30 15:41:14 +01:00
|
|
|
* @details For initialization of variables use NG_PKTQUEUE_NODE_INIT instead.
|
2014-09-05 18:21:58 +02:00
|
|
|
* Only use this function for dynamically allocated packet queue nodes.
|
|
|
|
*
|
2015-01-30 15:41:14 +01:00
|
|
|
* @param[out] node pre-allocated ng_pktqueue_node_t object. must not be NULL.
|
2014-09-05 18:21:58 +02:00
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline void ng_pktqueue_node_init(ng_pktqueue_node_t *node)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
|
|
|
priority_queue_node_init((priority_queue_node_t *)node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-30 15:41:14 +01:00
|
|
|
* @brief Static initializer for ng_pktqueue_t.
|
2014-09-05 18:21:58 +02:00
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
#define NG_PKTQUEUE_INIT PRIORITY_QUEUE_INIT
|
2014-09-05 18:21:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize a packet queue object.
|
2015-01-30 15:41:14 +01:00
|
|
|
* @details For initialization of variables use NG_PKTQUEUE_INIT
|
2014-09-05 18:21:58 +02:00
|
|
|
* instead. Only use this function for dynamically allocated
|
|
|
|
* packet queues.
|
2015-01-30 15:41:14 +01:00
|
|
|
* @param[out] queue pre-allocated ng_pktqueue_t object, must not be NULL.
|
2014-09-05 18:21:58 +02:00
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline void ng_pktqueue_init(ng_pktqueue_t *queue)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
|
|
|
priority_queue_init((priority_queue_t *)queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get the packet queue's head without removing it
|
|
|
|
*
|
2014-11-30 22:34:50 +01:00
|
|
|
* @param[out] queue the queue
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* @return the head
|
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline ng_pktqueue_node_t *ng_pktqueue_get_head(ng_pktqueue_t *queue)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
|
|
|
return queue->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief remove the packet queue's head
|
|
|
|
*
|
2014-11-30 22:34:50 +01:00
|
|
|
* @param[in] queue the queue
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* @return the old head
|
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline ng_pktqueue_node_t *ng_pktqueue_remove_head(ng_pktqueue_t *queue)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
2015-01-30 15:41:14 +01:00
|
|
|
return (ng_pktqueue_node_t *)priority_queue_remove_head((priority_queue_t *)queue);
|
2014-09-05 18:21:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-13 12:35:11 +01:00
|
|
|
* @brief add @p node into @p queue based on its priority
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* @details The new node will be appended after objects with the same
|
|
|
|
* priority.
|
|
|
|
*
|
|
|
|
* @param[in] queue the queue
|
|
|
|
* @param[in] node the node to add
|
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline void ng_pktqueue_add(ng_pktqueue_t *queue, ng_pktqueue_node_t *node)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
|
|
|
priority_queue_add((priority_queue_t *)queue, (priority_queue_node_t *) node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-13 12:35:11 +01:00
|
|
|
* @brief remove @p node from @p queue
|
2014-09-05 18:21:58 +02:00
|
|
|
*
|
|
|
|
* @param[in] queue the queue
|
|
|
|
* @param[in] node the node to remove
|
|
|
|
*/
|
2015-01-30 15:41:14 +01:00
|
|
|
static inline void ng_pktqueue_remove(ng_pktqueue_t *queue, ng_pktqueue_node_t *node)
|
2014-09-05 18:21:58 +02:00
|
|
|
{
|
|
|
|
priority_queue_remove((priority_queue_t *)queue, (priority_queue_node_t *) node);
|
|
|
|
}
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-30 15:41:14 +01:00
|
|
|
#endif /* NG_PKTQUEUE_H_ */
|
2014-09-05 18:21:58 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|