Subversion Repositories HelenOS

Rev

Rev 3901 | Rev 3990 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3901 Rev 3912
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2008 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:
Line 24... Line 24...
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 net
29
/** @addtogroup packet
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
-
 
34
 *  Packet map and queue.
34
 */
35
 */
35
 
36
 
36
#ifndef __NET_PACKET_H__
37
#ifndef __NET_PACKET_H__
37
#define __NET_PACKET_H__
38
#define __NET_PACKET_H__
38
 
39
 
-
 
40
/** Packet identifier type.
-
 
41
 *  Value zero (0) is used as an invalid identifier.
-
 
42
 */
39
typedef unsigned int    packet_id_t;
43
typedef unsigned int    packet_id_t;
40
 
44
 
-
 
45
/** Type definition of the packet.
-
 
46
 *  @see packet
-
 
47
 */
41
typedef struct packet * packet_t;
48
typedef struct packet * packet_t;
42
typedef packet_t *  packet_ref;
-
 
43
 
49
 
-
 
50
/** Type definition of the packet pointer.
-
 
51
 *  @see packet
-
 
52
 */
-
 
53
typedef packet_t *      packet_ref;
-
 
54
 
-
 
55
/** Packet operation mode type.
-
 
56
 */
44
typedef enum packet_mode    packet_mode_t;
57
typedef enum packet_mode    packet_mode_t;
45
 
58
 
-
 
59
/** Packet operation mode.
-
 
60
 */
46
enum    packet_mode{
61
enum    packet_mode{
-
 
62
    /** The packet is processed in one direction and can be released at any time.
-
 
63
     */
47
    PM_ONEWAY,
64
    PM_ONE_WAY,
-
 
65
    /** The packet should be returned at the end of the processing back to its initiator.
-
 
66
     */
48
    PM_RETURN
67
    PM_RETURN
49
};
68
};
50
 
69
 
-
 
70
/** Finds the packet mapping.
-
 
71
 *  @param packet_id The packet identifier to be found. Input parameter.
-
 
72
 *  @returns The found packet reference.
-
 
73
 *  @returns NULL if the mapping does not exist.
-
 
74
 */
51
packet_t pm_find( packet_id_t packet_id );
75
packet_t    pm_find( packet_id_t packet_id );
-
 
76
 
-
 
77
/** Adds the packet mapping.
-
 
78
 *  @param packet The packet to be remembered. Input parameter.
-
 
79
 *  @returns EOK on success.
-
 
80
 *  @returns EINVAL if the packet is not valid.
-
 
81
 *  @returns EINVAL if the packet map is not initialized.
-
 
82
 *  @returns ENOMEM if there is not enough memory left.
-
 
83
 */
52
int pm_add( packet_t packet );
84
int pm_add( packet_t packet );
-
 
85
 
-
 
86
/** Initializes the packet map.
-
 
87
 *  @returns EOK on success.
-
 
88
 *  @returns ENOMEM if there is not enough memory left.
-
 
89
 */
53
int pm_init( void );
90
int pm_init( void );
-
 
91
 
-
 
92
/** Releases the packet map.
-
 
93
 */
54
void pm_destroy( void );
94
void    pm_destroy( void );
55
 
95
 
-
 
96
/** Add packet to the sorted queue.
-
 
97
 *  The queue is sorted in the ascending order.
-
 
98
 *  The packet is inserted right before the packets of the same order value.
-
 
99
 *  @param first The first packet of the queue. May be NULL. Input parameter.
-
 
100
 *  @param packet The packet to be added. Input parameter.
-
 
101
 *  @param order The packet order value. Input parameter.
-
 
102
 *  @param metric The metric value of the packet. Input parameter.
-
 
103
 *  @returns The first packet of the queue. The original first packet may be shifted by the new packet.
-
 
104
 *  @returns NULL if the packet is not valid.
-
 
105
 */
56
packet_t    pq_add( packet_t first, packet_t packet, int order, size_t metric );
106
packet_t    pq_add( packet_t first, packet_t packet, int order, size_t metric );
-
 
107
 
-
 
108
/** Detach the packet from the queue.
-
 
109
 *  @param packet The packet to be detached. Input parameter.
-
 
110
 *  @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one.
-
 
111
 *  @returns NULL if the packet is not valid.
-
 
112
 */
57
packet_t pq_detach( packet_t packet );
113
packet_t    pq_detach( packet_t packet );
-
 
114
 
-
 
115
/** Sets the packet order and metric attributes.
-
 
116
 *  @param packet The packet to be set. Input parameter.
-
 
117
 *  @param order The packet order value. Input parameter.
-
 
118
 *  @param metric The metric value of the packet. Input parameter.
-
 
119
 */
58
int pq_set( packet_t packet, int order, size_t metric );
120
int pq_set( packet_t packet, int order, size_t metric );
-
 
121
 
-
 
122
/** Releases the whole queue.
-
 
123
 *  Detaches all packets of the queue and calls the packet_release() for each of them.
-
 
124
 *  @param first The first packet of the queue. Input parameter.
-
 
125
 *  @param packet_release The releasing function called for each of the packets after its detachment. Input parameter.
-
 
126
 */
59
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
127
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
60
 
128
 
61
#endif
129
#endif
62
 
130
 
63
/** @}
131
/** @}