summaryrefslogtreecommitdiff
path: root/cesar/cp2/conn/src/link.c
blob: b8be55f3993166afee3170cb6800750328fd682a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    link.c
 * \brief   link management
 * \ingroup cp2/conn
 *
 * « long description »
 */
#include "common/std.h"
#include "cp2/cp.h"
#include "cp2/inc/context.h"
#include "cp2/conn/conn.h"
#include "cp2/conn/link.h"
#include "lib/blk.h"
/**
 * init a link
 * \param  table_ble  ble elements
 * \param  nb_ble  number of element in this table
 * \return  the link initialised
 *
 * init the memory
 * fill the elements concerning the link
 */
cp_link_t*
cp_link_init (void)
{
    cp_link_t *link;

    link = blk_alloc();
    link->cinfo = blk_alloc();
    link->ble = NULL;
    blk_print_memory();
    
    return link;
}

/**
 * del a connection regarding to its CID.
 * \param  ctx  conn context.
 * \param  lid  Connection identifier
 *
 */
void
cp_link_uninit (cp_link_t *link)
{

    blk_release(link->cinfo);

    blk_print_memory();

    release_ble (link);

    blk_print_memory();
}

/**
 * BLE memory allocation 
 * \param first first BLE of a link
 * \param new new element to add to the heap
 *
 * link the BLE 
 */
void
push_ble(cp_link_t *link, u8 ble, u16 et)
{

    cp_link_ble_interval_t *new;
    cp_link_ble_interval_t *tmp;

    dbg_assert(link);
    
    new = blk_alloc();
    new->ble = ble;
    new->et = et;
    new->next = NULL;

    tmp = link->ble;

    if (!tmp)
        link->ble = new;
    else
    {
        while(tmp->next)
            tmp = tmp->next;

        tmp->next = new;
    }
}

void
release_ble(cp_link_t *link)
{
    cp_link_ble_interval_t *ble;
    cp_link_ble_interval_t *tmp_ble;

    dbg_assert(link);

    ble = link->ble;

    while(ble) 
    {
        tmp_ble = ble->next;

        blk_release(ble);
        ble = tmp_ble;
    }
}