Contiki 2.6

Packet queue

The packetqueue module handles a list of queued packets. More...

Data Structures

struct  packetqueue
 Representation of a packet queue. More...
struct  packetqueue_item
 Representation of an item in a packet queue. More...

Files

file  packetqueue.c
 

Packet queue management.


file  packetqueue.h
 

Header file for the packetqueue module.


Defines

#define PACKETQUEUE(name, size)
 Define a packet queue.

Packet queue functions.

void packetqueue_init (struct packetqueue *q)
 Initialize a packet queue.
int packetqueue_enqueue_packetbuf (struct packetqueue *q, clock_time_t lifetime, void *ptr)
 Enqueue a packetbuf on a packet queue.
struct packetqueue_itempacketqueue_first (struct packetqueue *q)
 Access the first item on the packet buffer.
void packetqueue_dequeue (struct packetqueue *q)
 Remove the first item on the packet buffer.
int packetqueue_len (struct packetqueue *q)
 Get the length of the packet queue.

Packet queue item functions

struct queuebuf * packetqueue_queuebuf (struct packetqueue_item *i)
 Access the queuebuf in a packet queue item.
void * packetqueue_ptr (struct packetqueue_item *i)
 Access the user-defined pointer in a packet queue item.

Detailed Description

The packetqueue module handles a list of queued packets.


Define Documentation

#define PACKETQUEUE (   name,
  size 
)
Value:
LIST(name##_list); \
                                MEMB(name##_memb, struct packetqueue_item, size); \
                                static struct packetqueue name = { &name##_list, \
                                                                   &name##_memb }

Define a packet queue.

Parameters:
nameThe variable name of the packet queue
sizeThe maximum size of the packet queue

This statement defines a packet queue. A packet queue is defined on a per-module basis.

Definition at line 105 of file packetqueue.h.


Function Documentation

void packetqueue_dequeue ( struct packetqueue q)

Remove the first item on the packet buffer.

Parameters:
qA pointer to a struct packetqueue.

This function removes the first item on the packet queue. The function does not return the first item: to access the first item, the packetqueue_first() function must have been used prior to calling packetqueue_dequeue().

Definition at line 113 of file packetqueue.c.

References ctimer_stop(), list_head(), list_remove(), memb_free(), and NULL.

int packetqueue_enqueue_packetbuf ( struct packetqueue q,
clock_time_t  lifetime,
void *  ptr 
)

Enqueue a packetbuf on a packet queue.

Parameters:
qA pointer to a struct packetqueue.
lifetimeThe maximum time that the packet should stay in the packet queue, or zero if the packet should stay on the packet queue indefinitely.
ptrAn opaque, user-defined pointer that can be used to identify the packet when it later is dequeued.
Return values:
ZeroIf memory could not be allocated for the packet.
Non-zeroIf the packet was successfully enqueued.

This function enqueues the packetbuf to the packet queue pointed to by the q parameter. The packet queue must previously have been defined with PACKETQUEUE() and initialized with packetqueue_init().

Each packet queue item has a maximum lifetime. When the lifetime expires, the packet queue item is automatically removed from the packet queue. If the lifetime parameter is given as zero, the packet never times out from the packet queue.

Each packet queue item is tagged with a user-defined pointer. This pointer can be used to identify packets as they later are dequeued from the queue. This is useful if two modules is using the same packet queue: the modules can use the pointer to distinguish to which module a dequeued packet belongs.

Definition at line 70 of file packetqueue.c.

References ctimer_set(), list_add(), memb_alloc(), memb_free(), and NULL.

struct packetqueue_item * packetqueue_first ( struct packetqueue q) [read]

Access the first item on the packet buffer.

Parameters:
qA pointer to a struct packetqueue.
Returns:
A pointer to the first item on the packet queue.

This function returns the first item on the packet queue. The packet queue is unchanged by this function. To dequeue the first item on the list, use the packetqueue_dequeue() function.

Definition at line 107 of file packetqueue.c.

References list_head().

void packetqueue_init ( struct packetqueue q)

Initialize a packet queue.

Parameters:
qA pointer to a struct packetqueue that was defined with PACKETQUEUE().

This function initializes a packetqueue that has previously been defined with PACKETQUEUE().

Definition at line 50 of file packetqueue.c.

References list_init(), and memb_init().

int packetqueue_len ( struct packetqueue q)

Get the length of the packet queue.

Parameters:
qA pointer to a struct packetqueue.
Returns:
The number of packets queued on the packet queue

This function returns the number of packets that are queued on the packet queue.

Definition at line 127 of file packetqueue.c.

References list_length().

void * packetqueue_ptr ( struct packetqueue_item i)

Access the user-defined pointer in a packet queue item.

Parameters:
iA packet queue item, obtained with packetqueue_first().
Returns:
A pointer to the user-defined pointer in the packet queue item.

Definition at line 143 of file packetqueue.c.

References NULL.

struct queuebuf * packetqueue_queuebuf ( struct packetqueue_item i) [read]

Access the queuebuf in a packet queue item.

Parameters:
iA packet queue item, obtained with packetqueue_first().
Returns:
A pointer to the queuebuf in the packet queue item.

Definition at line 133 of file packetqueue.c.

References NULL.