1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/net/ng_pktqueue.h

145 lines
3.5 KiB
C
Raw Normal View History

/*
2015-01-30 15:41:14 +01:00
* Copyright (C) 2014, 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* 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
* @brief Packet wrapper for the Priority Queue
2014-10-11 08:20:50 +02:00
* @ingroup net
* @{
*
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
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
2015-01-30 15:41:14 +01:00
#ifndef NG_PKTQUEUE_H_
#define NG_PKTQUEUE_H_
#include <stdint.h>
#include <stdlib.h>
2015-01-30 15:41:14 +01:00
#include "net/ng_pkt.h"
#include "priority_queue.h"
2014-10-10 11:51:11 +02:00
#ifdef __cplusplus
extern "C" {
#endif
/**
* @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 */
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;
/**
* @brief data type for packet queues
*
2014-10-11 08:20:50 +02:00
* @extends priority_queue_t
*/
typedef struct {
2015-01-30 15:41:14 +01:00
ng_pktqueue_node_t *first; /**< first node in the queue */
} ng_pktqueue_t;
/**
2015-01-30 15:41:14 +01:00
* @brief Static initializer for ng_pktqueue_node_t
*/
2015-01-30 15:41:14 +01:00
#define NG_PKTQUEUE_NODE_INIT { NULL, NULL, 0 }
/**
* @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.
* 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.
*/
2015-01-30 15:41:14 +01:00
static inline void ng_pktqueue_node_init(ng_pktqueue_node_t *node)
{
priority_queue_node_init((priority_queue_node_t *)node);
}
/**
2015-01-30 15:41:14 +01:00
* @brief Static initializer for ng_pktqueue_t.
*/
2015-01-30 15:41:14 +01:00
#define NG_PKTQUEUE_INIT PRIORITY_QUEUE_INIT
/**
* @brief Initialize a packet queue object.
2015-01-30 15:41:14 +01:00
* @details For initialization of variables use NG_PKTQUEUE_INIT
* 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.
*/
2015-01-30 15:41:14 +01:00
static inline void ng_pktqueue_init(ng_pktqueue_t *queue)
{
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
*
* @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)
{
return queue->first;
}
/**
* @brief remove the packet queue's head
*
2014-11-30 22:34:50 +01:00
* @param[in] queue the queue
*
* @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)
{
2015-01-30 15:41:14 +01:00
return (ng_pktqueue_node_t *)priority_queue_remove_head((priority_queue_t *)queue);
}
/**
2015-02-13 12:35:11 +01:00
* @brief add @p node into @p queue based on its priority
*
* @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)
{
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
*
* @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)
{
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_ */
/**
* @}
*/