Subversion Repositories HelenOS

Rev

Rev 4243 | Rev 4704 | Go to most recent revision | 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
 
3990 mejdrech 55
/** Type of the received packet.
3912 mejdrech 56
 */
3990 mejdrech 57
enum packet_type{
58
    /** The packet is from the local subsystem.
3912 mejdrech 59
     */
3990 mejdrech 60
    PACKET_SELF,
61
    /** The packet is for all hosts.
3912 mejdrech 62
     */
3990 mejdrech 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
3901 mejdrech 70
};
71
 
3912 mejdrech 72
/** Finds the packet mapping.
73
 *  @param packet_id The packet identifier to be found. Input parameter.
74
 *  @returns The found packet reference.
75
 *  @returns NULL if the mapping does not exist.
76
 */
77
packet_t    pm_find( packet_id_t packet_id );
3901 mejdrech 78
 
3912 mejdrech 79
/** Adds the packet mapping.
80
 *  @param packet The packet to be remembered. Input parameter.
81
 *  @returns EOK on success.
82
 *  @returns EINVAL if the packet is not valid.
83
 *  @returns EINVAL if the packet map is not initialized.
84
 *  @returns ENOMEM if there is not enough memory left.
85
 */
86
int pm_add( packet_t packet );
87
 
88
/** Initializes the packet map.
89
 *  @returns EOK on success.
90
 *  @returns ENOMEM if there is not enough memory left.
91
 */
92
int pm_init( void );
93
 
94
/** Releases the packet map.
95
 */
96
void    pm_destroy( void );
97
 
98
/** Add packet to the sorted queue.
99
 *  The queue is sorted in the ascending order.
100
 *  The packet is inserted right before the packets of the same order value.
101
 *  @param first The first packet of the queue. May be NULL. Input parameter.
102
 *  @param packet The packet to be added. Input parameter.
103
 *  @param order The packet order value. Input parameter.
104
 *  @param metric The metric value of the packet. Input parameter.
105
 *  @returns The first packet of the queue. The original first packet may be shifted by the new packet.
106
 *  @returns NULL if the packet is not valid.
107
 */
3901 mejdrech 108
packet_t    pq_add( packet_t first, packet_t packet, int order, size_t metric );
3912 mejdrech 109
 
4505 mejdrech 110
/** Inserts packet after the given one.
111
 *  @param packet The packet in the queue. Input parameter.
112
 *  @param new_packet The new packet to be inserted.
113
 *  @returns EOK on success.
114
 *  @returns EINVAL if etiher of the packets is invalid.
115
 */
116
int pq_insert_after( packet_t packet, packet_t new_packet );
117
 
3912 mejdrech 118
/** Detach the packet from the queue.
119
 *  @param packet The packet to be detached. Input parameter.
120
 *  @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 121
 *  @returns NULL if there is no packet left.
3912 mejdrech 122
 *  @returns NULL if the packet is not valid.
123
 */
124
packet_t    pq_detach( packet_t packet );
125
 
126
/** Sets the packet order and metric attributes.
127
 *  @param packet The packet to be set. Input parameter.
128
 *  @param order The packet order value. Input parameter.
129
 *  @param metric The metric value of the packet. Input parameter.
130
 */
3901 mejdrech 131
int pq_set( packet_t packet, int order, size_t metric );
3912 mejdrech 132
 
133
/** Releases the whole queue.
134
 *  Detaches all packets of the queue and calls the packet_release() for each of them.
135
 *  @param first The first packet of the queue. Input parameter.
136
 *  @param packet_release The releasing function called for each of the packets after its detachment. Input parameter.
137
 */
3901 mejdrech 138
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
139
 
4075 mejdrech 140
/** Returns the next packet in the queue.
141
 *  @param packet The packet queue member. Input parameter.
142
 *  @returns The next packet in the queue.
143
 *  @returns NULL if there is no next packet.
144
 *  @returns NULL if the packet is not valid.
145
 */
146
packet_t    pq_next( packet_t packet );
147
 
148
/** Returns the previous packet in the queue.
149
 *  @param packet The packet queue member. Input parameter.
150
 *  @returns The previous packet in the queue.
151
 *  @returns NULL if there is no previous packet.
152
 *  @returns NULL if the packet is not valid.
153
 */
154
packet_t    pq_previous( packet_t packet );
155
 
3886 mejdrech 156
#endif
157
 
158
/** @}
159
 */