Subversion Repositories HelenOS

Rev

Rev 4743 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3886 mejdrech 1
/*
3912 mejdrech 2
 * Copyright (c) 2009 Lukas Mejdrech
3886 mejdrech 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
3912 mejdrech 29
/** @addtogroup packet
3901 mejdrech 30
 *  @{
3886 mejdrech 31
 */
32
 
33
/** @file
3912 mejdrech 34
 *  Packet map and queue.
3886 mejdrech 35
 */
36
 
37
#ifndef __NET_PACKET_H__
38
#define __NET_PACKET_H__
39
 
3912 mejdrech 40
/** Packet identifier type.
41
 *  Value zero (0) is used as an invalid identifier.
42
 */
4243 mejdrech 43
typedef int packet_id_t;
3886 mejdrech 44
 
3912 mejdrech 45
/** Type definition of the packet.
46
 *  @see packet
47
 */
3886 mejdrech 48
typedef struct packet * packet_t;
49
 
3912 mejdrech 50
/** Type definition of the packet pointer.
51
 *  @see packet
52
 */
53
typedef packet_t *      packet_ref;
54
 
4704 mejdrech 55
/** @name Packet management system interface
56
 */
57
/*@{*/
58
 
3912 mejdrech 59
/** Finds the packet mapping.
4756 mejdrech 60
 *  @param[in] packet_id The packet identifier to be found.
3912 mejdrech 61
 *  @returns The found packet reference.
62
 *  @returns NULL if the mapping does not exist.
63
 */
64
packet_t    pm_find( packet_id_t packet_id );
3901 mejdrech 65
 
3912 mejdrech 66
/** Adds the packet mapping.
4756 mejdrech 67
 *  @param[in] packet The packet to be remembered.
3912 mejdrech 68
 *  @returns EOK on success.
69
 *  @returns EINVAL if the packet is not valid.
70
 *  @returns EINVAL if the packet map is not initialized.
71
 *  @returns ENOMEM if there is not enough memory left.
72
 */
73
int pm_add( packet_t packet );
74
 
75
/** Initializes the packet map.
76
 *  @returns EOK on success.
77
 *  @returns ENOMEM if there is not enough memory left.
78
 */
79
int pm_init( void );
80
 
81
/** Releases the packet map.
82
 */
83
void    pm_destroy( void );
84
 
85
/** Add packet to the sorted queue.
86
 *  The queue is sorted in the ascending order.
87
 *  The packet is inserted right before the packets of the same order value.
4756 mejdrech 88
 *  @param[in] first The first packet of the queue. May be NULL.
89
 *  @param[in] packet The packet to be added.
90
 *  @param[in] order The packet order value.
91
 *  @param[in] metric The metric value of the packet.
3912 mejdrech 92
 *  @returns The first packet of the queue. The original first packet may be shifted by the new packet.
93
 *  @returns NULL if the packet is not valid.
94
 */
4731 mejdrech 95
packet_t    pq_add( packet_t first, packet_t packet, size_t order, size_t metric );
3912 mejdrech 96
 
4731 mejdrech 97
/** Finds the packet with the given order.
4756 mejdrech 98
 *  @param[in] first The first packet of the queue.
99
 *  @param[in] order The packet order value.
4731 mejdrech 100
 *  @returns The packet with the given order.
101
 *  @returns NULL if the first packet is not valid.
102
 *  @returns NULL if the packet is not found.
103
 */
104
packet_t    pq_find( packet_t first, size_t order );
105
 
4505 mejdrech 106
/** Inserts packet after the given one.
4756 mejdrech 107
 *  @param[in] packet The packet in the queue.
108
 *  @param[in] new_packet The new packet to be inserted.
4505 mejdrech 109
 *  @returns EOK on success.
110
 *  @returns EINVAL if etiher of the packets is invalid.
111
 */
112
int pq_insert_after( packet_t packet, packet_t new_packet );
113
 
3912 mejdrech 114
/** Detach the packet from the queue.
4756 mejdrech 115
 *  @param[in] packet The packet to be detached.
3912 mejdrech 116
 *  @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one.
3990 mejdrech 117
 *  @returns NULL if there is no packet left.
3912 mejdrech 118
 *  @returns NULL if the packet is not valid.
119
 */
120
packet_t    pq_detach( packet_t packet );
121
 
122
/** Sets the packet order and metric attributes.
4756 mejdrech 123
 *  @param[in] packet The packet to be set.
124
 *  @param[in] order The packet order value.
125
 *  @param[in] metric The metric value of the packet.
4731 mejdrech 126
 *  @returns EOK on success.
127
 *  @returns EINVAL if the packet is invalid..
3912 mejdrech 128
 */
4731 mejdrech 129
int pq_set_order( packet_t packet, size_t order, size_t metric );
3912 mejdrech 130
 
4731 mejdrech 131
/** Sets the packet order and metric attributes.
4756 mejdrech 132
 *  @param[in] packet The packet to be set.
133
 *  @param[out] order The packet order value.
134
 *  @param[out] metric The metric value of the packet.
4731 mejdrech 135
 *  @returns EOK on success.
136
 *  @returns EINVAL if the packet is invalid..
137
 */
138
int pq_get_order( packet_t packet, size_t * order, size_t * metric );
139
 
3912 mejdrech 140
/** Releases the whole queue.
141
 *  Detaches all packets of the queue and calls the packet_release() for each of them.
4756 mejdrech 142
 *  @param[in] first The first packet of the queue.
143
 *  @param[in] packet_release The releasing function called for each of the packets after its detachment.
3912 mejdrech 144
 */
3901 mejdrech 145
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
146
 
4075 mejdrech 147
/** Returns the next packet in the queue.
4756 mejdrech 148
 *  @param[in] packet The packet queue member.
4075 mejdrech 149
 *  @returns The next packet in the queue.
150
 *  @returns NULL if there is no next packet.
151
 *  @returns NULL if the packet is not valid.
152
 */
153
packet_t    pq_next( packet_t packet );
154
 
155
/** Returns the previous packet in the queue.
4756 mejdrech 156
 *  @param[in] packet The packet queue member.
4075 mejdrech 157
 *  @returns The previous packet in the queue.
158
 *  @returns NULL if there is no previous packet.
159
 *  @returns NULL if the packet is not valid.
160
 */
161
packet_t    pq_previous( packet_t packet );
162
 
4704 mejdrech 163
/*@}*/
164
 
3886 mejdrech 165
#endif
166
 
167
/** @}
168
 */