Exemplo n.º 1
0
size_t gesture_size() {
    size_t size;
    gesture g;
    tpl_node *tn;
    tn = tpl_map(gesture_format_string, &g);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_GETSIZE, &size);
    tpl_free(tn);
    return size;
}
Exemplo n.º 2
0
int main() {
    tpl_node *tn;
    int i;

    tn = tpl_map("A(i)",&i);
    for(i=0;i<10;i++) tpl_pack(tn,1);

    /* test pack-then-unpack without dump/load; implicit dump/load*/
    while (tpl_unpack(tn,1) > 0) printf("i is %d\n", i);

    /* implicit conversion back to output tpl (discards previous data in tpl */
    for(i=0;i>-10;i--) tpl_pack(tn,1);

    /* one more implicit conversion */
    while (tpl_unpack(tn,1) > 0) printf("i is %d\n", i);

    tpl_free(tn);
    return(0);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: ifzz/ticketd
/** Raft callback for sending appendentries message */
static int __raft_send_appendentries(
    raft_server_t* raft,
    void *user_data,
    int nodeidx,
    msg_appendentries_t* m
    )
{
    uv_buf_t bufs[3];

    raft_node_t* node = raft_get_node(raft, nodeidx);
    peer_connection_t* conn = raft_node_get_udata(node);

    int e = __connect_if_needed(conn);
    if (-1 == e)
        return 0;

    char buf[RAFT_BUFLEN], *ptr = buf;
    msg_t msg;

    memset(&msg, 0, sizeof(msg));
    msg.type = MSG_APPENDENTRIES;
    msg.ae.term = m->term;
    msg.ae.prev_log_idx   = m->prev_log_idx;
    msg.ae.prev_log_term = m->prev_log_term;
    msg.ae.leader_commit = m->leader_commit;
    msg.ae.n_entries = m->n_entries;
    ptr += __peer_msg_serialize(tpl_map("S(I$(IIIII))", &msg), bufs, ptr);

    /* appendentries with payload */
    if (0 < m->n_entries)
    {
        tpl_bin tb = {
            .sz   = m->entries[0].data.len,
            .addr = m->entries[0].data.buf
        };

        /* list of entries */
        tpl_node *tn = tpl_map("IIB", &m->entries[0].id, &m->entries[0].term,
                               &tb);
        size_t sz;
        tpl_pack(tn, 0);
        tpl_dump(tn, TPL_GETSIZE, &sz);
        e = tpl_dump(tn, TPL_MEM | TPL_PREALLOCD, ptr, RAFT_BUFLEN);
        assert(0 == e);
        bufs[1].len = sz;
        bufs[1].base = ptr;

        e = uv_write(&conn->wreq, conn->stream, bufs, 2, __peer_write_cb);
        if (-1 == e)
            uv_fatal(e);

        tpl_free(tn);
    }
    else
    {
Exemplo n.º 4
0
Arquivo: main.c Projeto: ifzz/ticketd
/** Serialize a peer message using TPL
 * @param[out] bufs libuv buffer to insert serialized message into
 * @param[out] buf Buffer to write serialized message into */
static size_t __peer_msg_serialize(tpl_node *tn, uv_buf_t *buf, char* data)
{
    size_t sz;
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_GETSIZE, &sz);
    tpl_dump(tn, TPL_MEM | TPL_PREALLOCD, data, RAFT_BUFLEN);
    tpl_free(tn);
    buf->len = sz;
    buf->base = data;
    return sz;
}
Exemplo n.º 5
0
int main() {
    tpl_node *tn;
    int i;

    tn = tpl_map( "A(i)", &i );
    for( i=0; i<10; i++ ) {
        tpl_pack( tn, 1 );  
    }
    tpl_dump( tn, TPL_FILE, "/tmp/test47.tpl" );
    tpl_free( tn );
    return(0);
}
Exemplo n.º 6
0
int main() {
    int i;
    char c;
    tpl_node *tn;

    tn = tpl_map("A(i)c", &i, &c);

    /* pack index number 0 (char c) */
    c = 'a';
    tpl_pack(tn, 0);  
   
    /* pack A(i) (that is, index number 1) a few times */
    i = 3;
    tpl_pack(tn, 1);
    i = 4;
    tpl_pack(tn, 1);

    tpl_dump(tn, TPL_FILE, "/tmp/test78.tpl");
    tpl_free(tn);
    return(0);
}
Exemplo n.º 7
0
void ClientMapPacker::packToNet(render_t source, unsigned char *buf)
{
    tpl_node *tn; // may need to remove this declaration later
    
    // We prepare our s_render_t lMap struct for packing
    s_render_t sMap = clientToSerial(source);
    
    /* fixed-length array of s_render_t structures */
    tn = tpl_map((char *)"S(iiifffi)", &sMap);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_MEM | TPL_PREALLOCD, buf, TILE_PACKET_SIZE);
    tpl_free(tn);
}
Exemplo n.º 8
0
void
irpc_send_usb_init(struct irpc_connection_info *ci)
{
    tpl_node *tn = NULL;
    int sock = ci->client_sock;
    irpc_retval_t retval = libusb_init(&irpc_ctx);
    
    // Send usb_init packet.
    tn = tpl_map(IRPC_INT_FMT, &retval);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_FD, sock);
    tpl_free(tn);
}
Exemplo n.º 9
0
int main() {
    tpl_node *tn;
    int o,i,j=-1;
    void *addr;
    int sz;

    tn = tpl_map("A(A(i))",&i);
    for(o=0;o<10;o++) {
        for(i=o; i < o+10; i++) tpl_pack(tn,2);
        tpl_pack(tn,1);
    }
    tpl_dump(tn,TPL_MEM,&addr,&sz);
    tpl_free(tn);

    tn = tpl_map("A(A(i))",&j);
    tpl_load(tn,TPL_MEM,addr,sz);
    while (tpl_unpack(tn,1) > 0) {
        while (tpl_unpack(tn,2) > 0) printf("j is %d\n", j);
    }
    tpl_free(tn);
    free(addr);
    return(0);
}
Exemplo n.º 10
0
int main(int argc, char * argv[]) {
  int opt,verbose=0, dump_image=0, x, y;
  FILE *ifilef=stdin;
  char *ifile=NULL,line[100], *s;
 
  tpl_node *tn;
  char *buf, *obuf;
  size_t sz,  osz;

  while ( (opt = getopt(argc, argv, "v+ih")) != -1) {
    switch (opt) {
      case 'v': verbose++; break;
      case 'i': dump_image=1; break;
      case 'h': default: usage(argv[0]); break;
    }
  }
  if (optind < argc) ifile=argv[optind++];
 
  if (ifile) {
    if ( (ifilef = fopen(ifile,"r")) == NULL) {
      fprintf(stderr,"can't open %s: %s\n", ifile, strerror(errno));
      exit(-1);
    }
  }

  /* prepare input buffer for layout algorithm */
  s = line;
  tn = tpl_map("A(s)", &s);
  while (fgets(line,sizeof(line),ifilef) != NULL) tpl_pack(tn, 1);
  tpl_dump(tn, TPL_MEM, &buf, &sz);
  tpl_free(tn);

  /* perform layout */
  layout(buf,sz,&obuf,&osz);
  free(buf);

  /* inspect output buffer from layout algorithm */
  tn = tpl_map("A(sii)", &s, &x, &y);
  if (tpl_load(tn, TPL_MEM, obuf, osz)) exit(-1);
  while (tpl_unpack(tn,1) > 0) {
    if (verbose) fprintf(stderr,"%-5d %-5d    %s", x, y, s);
    free(s);
  }
  tpl_free(tn);
  if (dump_image) write(STDOUT_FILENO, obuf, osz);
  free(obuf);

  fclose(ifilef);
  return 0;
}
Exemplo n.º 11
0
Arquivo: test125.c Projeto: 91yuan/tpl
int main(int argc, char *argv[]) {
  tpl_node *tn;
  tn = tpl_map("S(s)#", &tests, 3);
  tpl_pack(tn, 0);
  tpl_dump(tn, TPL_MEM|TPL_PREALLOCD, buffer, sizeof(buffer));
  /* at the next line, when the tpl tree is freed, the string node
   * is followed by a pound node. The string node has actually had
   * its data member multipled by the pound node's factor, but we
   * don't know that, until after we freed the string node at tpl.c:710.
   * if you run this example under valgrind --leak-check=full you can
   * see 13 bytes lost which are "second" and "third" above
   */
  tpl_free(tn);
  return 0;
}
Exemplo n.º 12
0
void Save(char* szFileName)
{
	tpl_node *tn;
	int id = 0;
	char *name, *names[] = { "joe", "bob", "cary" };

	tn = tpl_map("A(is)", &id, &name);

	for (name = names[0]; id < 3; name = names[++id]) {
		tpl_pack(tn, 1);
	}

	tpl_dump(tn, TPL_FILE, szFileName);
	tpl_free(tn);
}
Exemplo n.º 13
0
int main() {
  tpl_node *tn;
  char *s = NULL;
  tn = tpl_map("s", &s);
  tpl_pack(tn,0);
  tpl_dump(tn,TPL_FILE,filename);
  tpl_free(tn);

  s = (char*)0x1; /* overwritten below */
  tn  = tpl_map("s", &s);
  tpl_load(tn,TPL_FILE,filename);
  tpl_unpack(tn,0);
  tpl_free(tn);
  printf("s %s null\n", (s==NULL?"is":"is NOT"));
  return(0);
}
Exemplo n.º 14
0
Arquivo: track.c Projeto: Tolchi/misc
int main(int argc, char *argv[]) {
  int i, n, a,b,l, w, p;
  SDL_Joystick *j;
  SDL_Event e;
  tpl_node *tn;
  tn = tpl_map("cccc",&R,&G,&B,&D);

  if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
    fprintf(stderr,"SDL init failed: %s\n", SDL_GetError());
    return -1;
  }
  n = SDL_NumJoysticks();
  if (n==0) {fprintf(stderr, "No joystick\n"); return 0;}

  j = SDL_JoystickOpen(0); // open the first one 
  if (!j) {fprintf(stderr,"can't open joystick: %s\n", SDL_GetError()); return -1;}

  fprintf(stderr,"detecting motion. press joystick button to exit\n");
  while ( (w=SDL_WaitEvent(&e)) != 0) {

    switch (e.type) {
    case SDL_JOYAXISMOTION: 
      if ((e.jaxis.value < -3200) || (e.jaxis.value > 3200)) {// reduce tweakiness
        p = (int)(e.jaxis.value*100.0/JOYAXIS_MAX) + 100;
        switch (e.jaxis.axis) {
         case 0: /* left right */ R = p; break;
         case 1: /* up down */ G = p; break;
         case 2: /* twist */ B = p; break;
         case 3: /* throttle */ D = p; break;
         default: break;
         }
        assert(R>=0 && R<256); assert(G>=0 && G<256); assert(B>=0 && B<256); assert(D>=0 && D<256);
        tpl_pack(tn, 0);
        tpl_dump(tn,TPL_FD,1);
      }
      break;

    //case SDL_JOYBUTTONDOWN: fprintf(stderr,"button press\n"); goto done; break;
    case SDL_QUIT: goto done; break;
    }
  }

 done:
  tpl_free(tn);
  SDL_JoystickClose(j);
}
Exemplo n.º 15
0
int layout(char *buf, size_t sz, char **obuf, size_t *osz) {
  UT_array *namev,*hashv, *xv, *yv;
  int i, pos, rc=-1, x, y;
  unsigned char *s;
  unsigned h;

  utarray_new(namev, &ut_str_icd);
  utarray_new(hashv, &ut_int_icd);
  utarray_new(xv, &ut_int_icd);
  utarray_new(yv, &ut_int_icd);

  tpl_node *tn = tpl_map("A(s)", &s);
  if (tpl_load(tn, TPL_MEM, buf, sz)) goto done;
  while (tpl_unpack(tn,1) > 0) {
    h = get_hash(s);
    utarray_push_back(namev, &s);
    utarray_push_back(hashv, &h);
    free(s);
  }
  tpl_free(tn);

  for(pos=0; pos < utarray_len(namev); pos++) {
    place(pos,hashv,xv,yv);
  }

  /* every item has a place. prepare output. */
  tn = tpl_map("A(sii)", &s, &x, &y);
  for(i=0; i < utarray_len(namev); i++) {
    s = *(unsigned char**)utarray_eltptr(namev,i);
    x =            *(int*)utarray_eltptr(xv,i);
    y =            *(int*)utarray_eltptr(yv,i);
    tpl_pack(tn,1);
  }
  tpl_dump(tn, TPL_MEM, obuf, osz);
  tpl_free(tn);

  rc = 0;

 done:
  utarray_free(namev);
  utarray_free(hashv);
  utarray_free(xv);
  utarray_free(yv);
  return rc;
}
Exemplo n.º 16
0
cl_mem clCreateBuffer (cl_context context,
                      cl_mem_flags flags,
                      size_t size,
                      void *host_ptr,
                      cl_int *errcode_ret)
{
    printf("doing createbuffer\n");
    int64_t *buffer_l = mem_ptrs + mem_idx++;
    uint64_t l_size = size;
    uint64_t ptr_sz = 0;
    char c;
    char *buf;
    size_t cb = size;
    _buf[M_IDX] = CREATE_BUF;
    tpl_node *stn, *rtn;

    stn = tpl_map("IiIIA(c)", context, &flags, &l_size, &ptr_sz, &c);
    rtn = tpl_map("I", buffer_l);

    if (host_ptr != NULL) {
        uLongf i, len = cb;
        int err;
        if (cb > CMP_LIM) {
            len = (uLongf)(cb + (cb * 0.1) + 12);
            buf = (char *)malloc((size_t)len);
            err = compress2((Bytef *)buf, &len, (const Bytef *)host_ptr, (uLongf)cb, 
                           Z_BEST_COMPRESSION);
        }

        for (i = 0; i < len; i++) {
            c = buf[i];
            tpl_pack(stn, 1);
        }
        ptr_sz = size;
    }

    tpl_rpc_call(stn, rtn);
    tpl_deserialize(stn, rtn);

    if (errcode_ret != NULL) {
        *errcode_ret = CL_SUCCESS;
    }

    return buffer_l;
}
Exemplo n.º 17
0
int main() {
    tpl_node *tn;
    int i,j=-1;

    tn = tpl_map("i",&i);
    i=1;
    tpl_pack(tn,0);
    tpl_dump(tn,TPL_FILE,"/tmp/test2.tpl");
    tpl_free(tn);

    tn = tpl_map("i",&j);
    tpl_load(tn,TPL_FILE,"/tmp/test2.tpl");
    tpl_unpack(tn,0);
    printf("j is %d\n", j);
    tpl_free(tn);
    return(0);
    
}
Exemplo n.º 18
0
/* this returns memory that caller must free */
int set_to_buf(void *set, char **buf, size_t *len) {
  int rc=-1;
  char *key, *val;
  tpl_node *tn = tpl_map("A(ss)",&key,&val); assert(tn);
  kv_t *kv = NULL;
  while (kv = kv_next(set,kv)) {
    key = kv->key;
    val = kv->val;
    tpl_pack(tn,1);
  }
  if (tpl_dump(tn,TPL_MEM,buf,len) < 0) goto done;
  tpl_free(tn);

  rc = 0;

 done:
  return rc;
}
Exemplo n.º 19
0
int main() {
    tpl_node *tn;
    char *s1 = NULL, *s2 = "", *s3 = "hello";
    tn = tpl_map("sss", &s1, &s2, &s3);
    tpl_pack(tn,0);
    tpl_dump(tn,TPL_FILE,filename);
    tpl_free(tn);

    s1 = s2 = s3 = (char*)0x1; /* overwritten below */
    tn  = tpl_map("sss", &s1, &s2, &s3);
    tpl_load(tn,TPL_FILE,filename);
    tpl_unpack(tn,0);
    tpl_free(tn);
    printf("s1 %s\n", s1?s1:"NULL");
    printf("s2 %s\n", s2?s2:"NULL");
    printf("s3 %s\n", s3?s3:"NULL");
    return(0);
}
Exemplo n.º 20
0
int main() {
    tpl_node *tn;
    struct ms_t ms = {/*.c =*/ 'a', /*.i =*/ 1, /*.s =*/ {'h','i'}, /*.o =*/ 'o', /*.x =*/ "matilda", /*.y =*/ 'y', /*.d =*/ 3.14 };
    struct ms_t ms2;

    tn = tpl_map("S(cic#cscf)", &ms, 2);
    tpl_pack(tn,0);
    tpl_dump(tn,TPL_FILE,"/tmp/test70.tpl");
    tpl_free(tn);

    memset(&ms2,0,sizeof(struct ms_t));
    tn = tpl_map("S(cic#cscf)", &ms2, 2);
    tpl_load(tn,TPL_FILE,"/tmp/test70.tpl");
    tpl_unpack(tn,0);
    tpl_free(tn);
    printf("%c\n%d\n%c%c\n%c\n%s\n%c\n%f\n", ms2.c, ms2.i, ms2.s[0], ms2.s[1], ms2.o, ms2.x, ms2.y, ms2.d);
    free(ms2.x);
    return(0);
}
Exemplo n.º 21
0
int main()
{

    void* store_mem = NULL;
    int   store_len = 0;

    tpl_node* tn;

    TEST_T test;
    memset(&test, 0, sizeof(TEST_T));
    test.status = 1;
    test.opcode = 2;
    test.c = 0x45;
    test.d = 0x32;

    tn = tpl_map("S(iiii)", &test);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_MEM, &store_mem, &store_len);
    tpl_free(tn);

    int i = 0;
    for (; i < store_len; i++)
    {
        printf("%d - 0x%.2x\n", i, ((char*)store_mem)[i]);
    }

    printf("pack success total length is %d, and now start unpack\n", store_len);

    TEST_T test1;
    memset(&test1, 0, sizeof(TEST_T));

    tn = tpl_map("S(iiii)", &test1);
    tpl_load(tn, TPL_MEM, store_mem, store_len);
    tpl_unpack(tn, 0);
    tpl_free(tn);

    free(store_mem);

    printf("unpack status %d, opcode %d, c is 0x%.2x, d is 0x%.2x\n", test1.status, test1.opcode,  test1.c, test1.d);


    return 0;
}
Exemplo n.º 22
0
void
irpc_send_usb_control_transfer(struct irpc_connection_info *ci)
{
    tpl_node *tn = NULL;
    int retval, status = 0;
    irpc_device_handle handle;
    int req_type, req, val, idx, length, timeout;
    char data[IRPC_MAX_DATA];
    int sock = ci->client_sock;
    
    tn = tpl_map(IRPC_CTRL_TRANSFER_FMT,
                 &handle,
                 &req_type,
                 &req,
                 &val,
                 &idx,
                 &length,
                 &timeout);
    tpl_load(tn, TPL_FD, sock);
    tpl_unpack(tn, 0);
    tpl_free(tn);
    
    retval = libusb_control_transfer(irpc_handle,
                                     req_type,
                                     req,
                                     val,
                                     idx,
                                     data,
                                     length,
                                     timeout);
    // FIXME: Works but its no convenience method.
    if (retval >= 5)
    {
        status = (int)data[4];
    }
    
    // Send libusb_control_transfer packet.
    tn = tpl_map(IRPC_CTRL_STR_INT_INT_FMT, &retval, &status, &data, IRPC_MAX_DATA);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_FD, sock);
    tpl_free(tn);
}
Exemplo n.º 23
0
int main() {
    tpl_node *tn;
    int i,rc,j;
    char toosmall[10];
    char buf[60];

    tn = tpl_map("A(i)",&i);
    for(i=0;i<10;i++) tpl_pack(tn,1);
    rc=tpl_dump(tn,TPL_MEM|TPL_PREALLOCD,toosmall,sizeof(toosmall));
    printf("testing undersized output buffer... %d \n", rc);
    rc=tpl_dump(tn,TPL_MEM|TPL_PREALLOCD,buf,sizeof(buf));
    printf("testing sufficient output buffer... %d \n", rc);
    tpl_free(tn);

    tn = tpl_map("A(i)",&j);
    tpl_load(tn,TPL_MEM|TPL_EXCESS_OK,buf,sizeof(buf)); 
    while (tpl_unpack(tn,1) > 0) printf("j is %d\n", j);
    tpl_free(tn);
    return(0);
}
Exemplo n.º 24
0
cl_int clEnqueueWriteBuffer (cl_command_queue command_queue,
                            cl_mem buffer,
                            cl_bool blocking_write,
                            size_t offset,
                            size_t cb,
                            const void *ptr,
                            cl_uint num_events_in_wait_list,
                            const cl_event *event_wait_list,
                            cl_event *event)
{
    printf("doing write buffer %d\n", cb);
    const char *buf = ptr;
    char c;
    int result;
    _buf[M_IDX] = ENQ_WRITE_BUF;
    tpl_node *stn, *rtn;

    stn = tpl_map("IIiiiiA(c)", command_queue, buffer, &blocking_write, 
        &offset, &cb, &num_events_in_wait_list, &c);
    rtn = tpl_map("i", &result);

    uLongf i, len = cb;
    int err;
    if (cb > CMP_LIM) {
        len = (uLongf)(cb + (cb * 0.1) + 12);
        buf = (char *)malloc((size_t)len);
        err = compress2((Bytef *)buf, &len, (const Bytef *)ptr, (uLongf)cb, 
                           Z_BEST_COMPRESSION);
    }

    for (i = 0; i < len; i++) {
        c = buf[i];
        tpl_pack(stn, 1);
    }
    printf("cb %d len %lu i %lu err %d\n", cb, len, i, err);

    tpl_rpc_call(stn, rtn);
    tpl_deserialize(stn, rtn);

    return result;
}
Exemplo n.º 25
0
void
irpc_send_usb_open_device_with_vid_pid(struct irpc_connection_info *ci)
{
    tpl_node *tn = NULL;
    irpc_device_handle ihandle;
    int vendor_id, product_id;
    int sock = ci->client_sock;
    
    bzero(&ihandle, sizeof(irpc_device_handle));
    
    // Read vendor and product id from client.
    tn = tpl_map(IRPC_PRID_VEID_FMT,
                 &vendor_id,
                 &product_id);
    tpl_load(tn, TPL_FD, sock);
    tpl_unpack(tn, 0);
    tpl_free(tn);
    
    // Close an already opened handle.
    if (irpc_handle) {
        libusb_close(irpc_handle);
        irpc_handle = NULL;
    }
    
    irpc_handle = libusb_open_device_with_vid_pid(irpc_ctx, vendor_id, product_id);
    if (!irpc_handle)
        goto send;
    
    ihandle.dev.bus_number = irpc_handle->dev->bus_number;
    ihandle.dev.device_address = irpc_handle->dev->device_address;
    ihandle.dev.num_configurations = irpc_handle->dev->num_configurations;
    ihandle.dev.session_data = irpc_handle->dev->session_data;
    
send:
    // Send libusb_open_device_with_vid_pid packet.
    tn = tpl_map(IRPC_DEV_HANDLE_FMT, &ihandle);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_FD, sock);
    tpl_free(tn);
}
Exemplo n.º 26
0
DLPSPEC_ERR_CODE dlpspec_serialize(const void* struct_p, void *pBuffer,
	   	const size_t buffer_size, BLOB_TYPES data_type)
/**
 * Serializes a blob into @p pBuffer for the passed in struct pointer @p struct_p.
 * 
 * @param[in]     struct_p    pointer to the struct to be serialized.
 * @param[out]    pBuffer     pointer to the buffer 
 * @param[in]     buffer_size size allocated to @p pBuffer
 * @param[in]     data_type   blob type to be serialized
 * 
 * @return        Error code
 *
 */
{
    tpl_node *tn;
    DLPSPEC_ERR_CODE ret_val = DLPSPEC_PASS;
    int tpl_err = 0;

	tn = map_data_to_tplnode(struct_p, data_type);
	if(tn != NULL)
	{
		tpl_err = tpl_pack(tn, 0);
        if (0 == tpl_err)
        {
            tpl_err = tpl_dump(tn, TPL_MEM|TPL_PREALLOCD, pBuffer, buffer_size);
        }
		if (0 != tpl_err) // TPL error in dumping
        {
            ret_val = ERR_DLPSPEC_TPL;
        }
		tpl_free(tn);
	}
    else
    {
        ret_val = ERR_DLPSPEC_TPL;
    }

    return ret_val;
}
Exemplo n.º 27
0
irpc_retval_t
irpc_recv_usb_control_transfer(struct irpc_connection_info *ci,
                               irpc_device_handle *handle,
                               int req_type,
                               int req,
                               int val,
                               int idx,
                               char data[],
                               int length,
                               int timeout,
                               int *status)
{
    tpl_node *tn = NULL;
    int retval;
    irpc_func_t func = IRPC_USB_CONTROL_TRANSFER;
    int sock = ci->server_sock;
    
    irpc_send_func(func, sock);
    
    tn = tpl_map(IRPC_CTRL_TRANSFER_FMT,
                 handle,
                 &req_type,
                 &req,
                 &val,
                 &idx,
                 &length,
                 &timeout);
    tpl_pack(tn, 0);
    tpl_dump(tn, TPL_FD, sock);
    tpl_free(tn);    
    
    // Read libusb_control_transfer packet.
    tn = tpl_map(IRPC_CTRL_STR_INT_INT_FMT, &retval, status, data, IRPC_MAX_DATA);
    tpl_load(tn, TPL_FD, sock);
    tpl_unpack(tn, 0);
    tpl_free(tn);
    
    return retval;
}
Exemplo n.º 28
0
DLPSPEC_ERR_CODE dlpspec_get_serialize_dump_size(const void* struct_p, 
	   	size_t *pBufSize, BLOB_TYPES data_type)
/**
 * Serializes a blob into @p pBuffer for the passed in struct pointer @p struct_p.
 * 
 * @param[in]     struct_p    pointer to the struct to be serialized.
 * @param[out]    pBufSize	  size of buffer required to dump returned in this.
 * @param[in]     data_type   blob type to be serialized
 * 
 * @return        Error code
 *
 */
{
    tpl_node *tn;
    DLPSPEC_ERR_CODE ret_val = DLPSPEC_PASS;
    int tpl_err = 0;

	tn = map_data_to_tplnode(struct_p, data_type);
	if(tn != NULL)
	{
		tpl_err = tpl_pack(tn, 0);
        if (0 == tpl_err)
        {
            tpl_err = tpl_dump(tn, TPL_GETSIZE, pBufSize);
        }
		if (0 != tpl_err) // TPL error in dumping
        {
            ret_val = ERR_DLPSPEC_TPL;
        }
		tpl_free(tn);
	}
    else
    {
        ret_val = ERR_DLPSPEC_TPL;
    }

    return ret_val;
}
Exemplo n.º 29
0
int main(int argc, char*argv[]) {
    tpl_bin bin;
    tpl_node *tn;
    int i;
    char *file = "/tmp/test32.tpl";
    char str[10];

    strcpy(str,"good egg");
    bin.addr = str;
    bin.sz = 4;  /* just going to pack 'good' (no NUL) */

    tn = tpl_map("A(B)", &bin);
    for(i=0; i < 5; i++) {
        tpl_pack(tn,1);
        bin.addr = (char*)(bin.addr) + 1;
    }
    memset(str,0,10);   /* just to test that buf was copied */
    tpl_dump(tn,TPL_FILE,file);
    tpl_free(tn);

    bin.addr = NULL;
    bin.sz = 0;

    tn = tpl_map("A(B)", &bin);
    tpl_load(tn,TPL_FILE,file);
    while (tpl_unpack(tn,1) > 0) {
        /* print the buffer char-by-char ; its not a nul-termd string */
        printf("buffer length: %u\n", bin.sz);
        for(i=0; i < bin.sz; i++) printf("%c", ((char*)bin.addr)[i]);
        printf("\n");

        if (bin.sz > 0) 
            free(bin.addr);  /* malloc'd for us by tpl_unpack, we must free */
    }
    tpl_free(tn);
    return(0);

}
Exemplo n.º 30
0
int main() {
    tpl_node *tn;
    /* some meaningless test data */
    struct st s = {'z', {0.9, 0.8, 0.7, 0.6, 0.5 }};
    int j; 
    int i[ILEN] = {-1, -2, -3, -4, -5, -6, -7, -8, -9, -10};
    int k[KLEN] = {100, 200, 300, 400, 500, 600, 700, 800};
    char a = '&';
    char b = 'x';
    const char *fmt;
    uint32_t num_fxlens, *fxlens;

    tn = tpl_map("cA(i#)S(cf#)A(ci#)", &a, i, ILEN, &s, FLEN, &b, k, KLEN);
    tpl_pack(tn,0);

    tpl_pack(tn,1);
    for(j=0; j < ILEN; j++) i[j]--;
    tpl_pack(tn,1);
    for(j=0; j < ILEN; j++) i[j]--;
    tpl_pack(tn,1);

    tpl_pack(tn,2);
    b++;
    for(j=0; j < KLEN; j++) k[j] += 50;  
    tpl_pack(tn,2);
    b++;
    for(j=0; j < KLEN; j++) k[j] += 50; 
    tpl_pack(tn,2);

    tpl_dump(tn,TPL_FILE,filename);
    tpl_free(tn);

    /* now peek at the fxlens */
    fmt = tpl_peek(TPL_FILE|TPL_FXLENS, filename, &num_fxlens, &fxlens);
    printf("format %s\n", fmt);
    printf("num_fxlens %u\n", num_fxlens);
    for(j=0; j<num_fxlens; j++) printf("fxlens[%u] %u\n", j, fxlens[j]);
    if (num_fxlens>0) free(fxlens);
    return(0);
}