Subversion Repositories HelenOS

Rev

Rev 4731 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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