Ejemplo n.º 1
0
SgVector *sg_make_vector()
{
    SgVector *v = sg_alloc(sizeof(SgVector));
    v->head = sg_alloc(VBLSZ * sizeof(void*));
    v->head[0] = NULL;
    v->tail = v->head;
    v->_rtail = v->head + VBLSZ;
    v->size = 0;
    return v;
}
Ejemplo n.º 2
0
SgInt sg_btree_insert(SgBTree *h, void *key, void *data)
{
    SgBTreeNode *p = LAST, *c = h->root, *n;
    SgCmpFun const cmpf = h->cmpf;
    SgInt r;

    for (; c != LAST;) {
        p = c;
        r = cmpf(key, c->key);
        if (r < 0)
            c = c->left;
        else if (r > 0)
            c = c->right;
        else
            return -1;
    }

    n = sg_alloc(sizeof(SgBTreeNode) + sizeof(void*));
    n->left = LAST;
    n->right = LAST;
    n->parent = p;
    n->mlevel = 1;
    n->key = key;
    n->data[0] = data;
    if (p == LAST)
        h->root = n;
    else {
        if (r < 0)
            p->left = n;
        else
            p->right = n;
        equilibrate(p, &h->root);
    }
    return 0;
}
Ejemplo n.º 3
0
SgBTree *sg_make_btree(SgCmpFun cmpf)
{
    SgBTree *h = sg_alloc(sizeof(SgBTree));
    h->root = LAST;
    h->cmpf = cmpf;
    return h;
}
Ejemplo n.º 4
0
void l2capServiceTx_ADK(uint16_t conn, uint16_t remChan, const uint8_t* data, uint32_t size){ //send data over L2CAP

    sg_buf* buf = sg_alloc();

    if(!buf) return;
    if(sg_add_back(buf, data, size, SG_FLAG_MAKE_A_COPY)) l2capServiceTx(conn, remChan, buf);
    else sg_free(buf);
}
Ejemplo n.º 5
0
/*
 * Make a node with a specified data size (in bytes).
 */
SgBTreeNode *sg_btree_make_node(void *key, SgSize size)
{
    SgBTreeNode *n = sg_alloc(sizeof(SgBTreeNode) + size);
    n->parent = LAST;
    n->left = LAST;
    n->right = LAST;
    n->mlevel = 1;
    n->key = key;
    return n;
}
Ejemplo n.º 6
0
static void l2capSendControlRawBuf(uint16_t conn, const uint8_t* data, uint16_t len){

    sg_buf* buf;

    buf = sg_alloc();
    if(buf){

        if(sg_add_back(buf, data, len, SG_FLAG_MAKE_A_COPY)){

            l2capServiceTx(conn, 1, buf);
        }
        else{

            sg_free(buf);
            free(buf);
        }
    }
}
Ejemplo n.º 7
0
static void btRfcommSend(uint16_t conn, uint16_t remChan, const uint8_t* data, uint16_t sz){

    int i;

    #if UGLY_SCARY_DEBUGGING_CODE
        dbgPrintf("Sending RFCOMM packet:");
        for(i = 0; i < sz; i++) dbgPrintf(" %02X", data[i]);
        dbgPrintf("\n\n");
    #endif

    sg_buf* buf = sg_alloc();
    if(!buf) return;
    if(sg_add_front(buf, data, sz, SG_FLAG_MAKE_A_COPY)){

        l2capServiceTx(conn, remChan, buf);
        return;
    }
    sg_free(buf);
    free(buf);
}
Ejemplo n.º 8
0
SgList *sg_list_insert_sorted(SgList *ls, SgCmpFun cmpf, void *data)
{
    SgList *c, *p, *q = sg_alloc(sizeof(SgList) + sizeof(void*));
    q->data[0] = data;
    for (c = ls, p = NULL; ; p = c) {
        if (!c) {
            q->prev = p;
            q->next = NULL;
            break;
        }
        if (cmpf(data, c->data[0]) < 0) {
            q->prev = c->prev;
            q->next = c;
            c->prev = q;
            break;
        }
    }
    if (!p)
        return q;
    return ls;
}
Ejemplo n.º 9
0
void sg_display_btree(SgBTreeNode *n)
{
    SgSize ml, ls, i, j;
    SgChar *buff;

    if (n == LAST)
        return;
    ml = n->mlevel;
    ls = (2 << ml) / 2;
    buff = sg_alloc(ls * ml);

    for (i = 0; i < ml; i++) {
        for (j = 0; j < (ls - 1); j++) {
            buff[i*ls+j] = ' ';
        }
        buff[i*ls+j] = 0;
    }

    fill_buff(n, buff, 0, 0, ml, ls);
    for (; ml;) {
        printf("%s\n", &buff[--ml*ls]);
    }
    sg_free(buff);
}
Ejemplo n.º 10
0
static void btRfcommSend(uint16_t conn, uint16_t remChan, const uint8_t* data, uint16_t sz){

    int i;


        SIOPrintString("Sending RFCOMM packet:");
        for(i = 0; i < sz; i++)
        {
            SIOPutHex(data[i]);
            SIOPutChar(' ');
        }
        SIOPrintString("\r\n");


    sg_buf* buf = sg_alloc();
    if(!buf) return;
    if(sg_add_front(buf, data, sz, SG_FLAG_MAKE_A_COPY)){

        l2capServiceTx(conn, remChan, buf);
        return;
    }
    sg_free(buf);
    free(buf);
}
Ejemplo n.º 11
0
SgList *sg_list_append(SgList *ls, void *data)
{
    SgList *c = sg_alloc(sizeof(SgList) + sizeof(void*));
    c->data[0] = data;
    return sg_list_append_cell(ls, c);
}