/* Cesar project {{{ * * Copyright (C) 2008 Spidcom * * <<>> * * }}} */ /** * \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; } }