priority_pktqueue.h
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (C) 2015 Daniel Krebs
* 2016 INRIA
*
* 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.
*/
/**
* @defgroup net_gnrc_priority_pktqueue Priority packet queue for GNRC
* @ingroup net_gnrc
* @brief Wrapper for priority_queue that holds gnrc_pktsnip_t*
* @{
*
* @file
* @brief gnrc priority packet queue API
*
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Shuguo Zhuo <shuguo.zhuo@inria.fr>
*/
#ifndef NET_GNRC_PRIORITY_PKTQUEUE_H
#define NET_GNRC_PRIORITY_PKTQUEUE_H
#include <stdint.h>
#include "priority_queue.h"
#include "net/gnrc/pkt.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief data type for gnrc priority packet queue nodes
*/
typedef struct gnrc_priority_pktqueue_node {
struct gnrc_priority_pktqueue_node *next; /**< next queue node */
uint32_t priority; /**< queue node priority */
gnrc_pktsnip_t *pkt; /**< queue node data */
} gnrc_priority_pktqueue_node_t;
/**
* @brief data type for gnrc priority packet queues
*/
typedef priority_queue_t gnrc_priority_pktqueue_t;
/**
* @brief Static initializer for gnrc_priority_pktqueue_node_t.
*/
#define PRIORITY_PKTQUEUE_NODE_INIT(priority, pkt) { NULL, priority, pkt }
/**
* @brief Static initializer for gnrc_priority_pktqueue_t.
*/
#define PRIORITY_PKTQUEUE_INIT { NULL }
/**
* @brief Initialize a gnrc priority packet queue node object.
*
* @param[out] node
* pre-allocated gnrc_priority_pktqueue_node_t object, must not be NULL.
* @param[in] priority
* the priority of the gnrc packet snip
* @param[in] pkt
* the gnrc packet snip
*/
static inline void gnrc_priority_pktqueue_node_init(gnrc_priority_pktqueue_node_t *node,
uint32_t priority,
gnrc_pktsnip_t *pkt)
{
node->next = NULL;
node->priority = priority;
node->pkt = pkt;
}
/**
* @brief Initialize a gnrc priority packet queue object.
*
* @param[out] queue
* pre-allocated gnrc_priority_pktqueue_t object, must not be NULL.
*/
static inline void gnrc_priority_pktqueue_init(gnrc_priority_pktqueue_t *queue)
{
gnrc_priority_pktqueue_t qn = PRIORITY_PKTQUEUE_INIT;
*queue = qn;
}
/**
* @brief Get the length information of a gnrc priority packet queue object.
*
* @param[in] queue
* pre-allocated gnrc_priority_pktqueue_t object, must not be NULL.
* @return the length of @p queue
*/
uint32_t gnrc_priority_pktqueue_length(gnrc_priority_pktqueue_t *queue);
/**
* @brief flush the gnrc priority packet queue
*
* @param[out] queue the gnrc priority packet queue, must not be NULL
*/
void gnrc_priority_pktqueue_flush(gnrc_priority_pktqueue_t *queue);
/**
* @brief Get first element and remove it from @p queue
*
* @param[out] queue the gnrc priority packet queue, may not be NULL
*
* @return the old head
*/
gnrc_pktsnip_t *gnrc_priority_pktqueue_pop(gnrc_priority_pktqueue_t *queue);
/**
* @brief Get first element from @p queue without removing
*
* @param[in] queue the gnrc priority packet queue, may not be NULL
*
* @return the head of @p queue
*/
gnrc_pktsnip_t *gnrc_priority_pktqueue_head(gnrc_priority_pktqueue_t *queue);
/**
* @brief add @p node into @p queue based on its priority
*
* @param[in,out] queue the gnrc priority packet queue, must not be NULL
* @param[in] node the node to add.
*/
void gnrc_priority_pktqueue_push(gnrc_priority_pktqueue_t *queue,
gnrc_priority_pktqueue_node_t *node);
#ifdef __cplusplus
}
#endif
#endif /* NET_GNRC_PRIORITY_PKTQUEUE_H */
/** @} */