void sdmprofile__flush_remaining_heap ( ) { struct sdmprofile__list_item__heap * heap ; long icc = sdmprofile__list_maximum_index_used__heap + 10; long ix ; for (ix = 0 ;ix < icc ;ix ++) { if (sdmprofile__List__heap[ix] != NullPointer) { heap = sdmprofile__List__heap[ix] ; { tpl_node *tnheader; int header = 4 ; tnheader = tpl_map("A(i)", &header ); tpl_pack(tnheader ,1); tpl_dump(tnheader , TPL_FD , sdmprofile__FD ) ; tpl_free(tnheader ); } { tpl_node *tn; tn = tpl_map("A(S(UUUuffu))", heap); tpl_pack(tn,1); tpl_dump(tn, TPL_FD , sdmprofile__FD ) ; tpl_free(tn); } } } return; }
int testbinary(char *request, char* buffer, int buf_len) { tpl_node *tn; int id = 0; int sz = 0; struct struct_type { int x; char *string; char c; } local_struct = { .x = 1024, .string = "This is a string\n", .c = 'a' }; tn = tpl_map("S(isc)", &local_struct); tpl_pack(tn, 0); tpl_dump(tn, TPL_GETSIZE, &sz); tpl_dump(tn, TPL_MEM|TPL_PREALLOCD, buffer, buf_len); tpl_free(tn); if (DEBUG) fprintf(stderr, "testbinary: returning %d\n", sz); return sz; } #endif /* Add new commands here */ static struct command_def command_defs[] = { { .request = "ifconfig", .type = shell, .responder_command = "ifconfig -a", .responder = NULL }, { .request = "reassociate",
void sdmprofile__free (void * pointer ) { struct sdmprofile__list_item__heap * heap = sdmprofile__list_getitem__heap((u_int64_t) pointer ); heap->freedtime = sdmprofile__getRealTime(); { { tpl_node *tnheader; int header = 4 ; tnheader = tpl_map("A(i)", &header ); tpl_pack(tnheader ,1); tpl_dump(tnheader , TPL_FD , sdmprofile__FD ) ; tpl_free(tnheader ); } { tpl_node *tn; tn = tpl_map("A(S(UUUuffu))", heap); tpl_pack(tn,1); tpl_dump(tn, TPL_FD , sdmprofile__FD ) ; tpl_free(tn); } } sdmprofile__list_Remove__heap((u_int64_t) pointer ); free ( pointer); return; }
void sdmprofile__Exit_Current_executing_function(struct sdmprofile__executing_function_info * cf ) { cf->thread->current_function = cf->Caller ; { struct sdmprofile__stack_allocations_info * ptr = cf->stack_allocation_head ; struct sdmprofile__stack_allocations_info * freeptr ; while (ptr != 0) { { tpl_node *tnheader; int header = 5 ; tnheader = tpl_map("A(i)", &header ); tpl_pack(tnheader ,1); tpl_dump(tnheader , TPL_FD , sdmprofile__FD ) ; tpl_free(tnheader ); } { tpl_node *tn; tn = tpl_map("A(S(UUUuu))", ptr); tpl_pack(tn,1); tpl_dump(tn, TPL_FD , sdmprofile__FD ) ; tpl_free(tn); } freeptr = ptr ; ptr = ptr->next ; free (freeptr ); } free (cf ); } }
void sdmprofile__flush_remaining_stack ( ) { struct sdmprofile__stack_allocations_info * ptr = sdmprofile__MainThread->current_function->stack_allocation_head ; struct sdmprofile__stack_allocations_info * freeptr ; while (ptr != 0) { { tpl_node *tnheader; int header = 5 ; tnheader = tpl_map("A(i)", &header ); tpl_pack(tnheader ,1); tpl_dump(tnheader , TPL_FD , sdmprofile__FD ) ; tpl_free(tnheader ); } { tpl_node *tn; tn = tpl_map("A(S(UUUuu))", ptr); tpl_pack(tn,1); tpl_dump(tn, TPL_FD , sdmprofile__FD ) ; tpl_free(tn); } freeptr = ptr ; ptr = ptr->next ; free (freeptr ); } }
/* Uses the tlp library and serialize * the structures in binary format */ void store_structures() { int i = 0; tpl_node *tn_modules, *tn_instances; Module tmp_module; Instance tmp_instance, *curr; // Map an array with structs tn_modules = tpl_map("A(S(c#))", &tmp_module, SIZE); // Pack the informations of the array for (i = 0; i < number_of_modules; i++) { tmp_module = *modules[i]; tpl_pack(tn_modules, 1); } // Save to tlp file tpl_dump(tn_modules, TPL_FILE, "modules.tpl"); // Free memory tpl_free(tn_modules); // Map a two dimensional array with lists tn_instances = tpl_map("A(A(S(ic#)))", &tmp_instance, SIZE); // Pack the informations of the array for (i = 0; i < number_of_modules; i++) { for(curr = cells[i]; curr != NULL; curr = curr->next) { tmp_instance = *curr; tpl_pack(tn_instances, 2); } tpl_pack(tn_instances, 1); } // Save to tlp file tpl_dump(tn_instances, TPL_FILE, "instances.tpl"); // Free memory tpl_free(tn_instances); }
static int handle(void * buffer, size_t size) { tpl_node * node = NULL; int op, ret; char * cucco = NULL; if(!get(buffer, size, &op, &cucco)) { return -1; } switch(op) { case DB_GET: { node = tpl_map("A(s)", &resp_aux); ret = database_cuccos_get(database, cucco, callback, node); if(ret) { tpl_dump(node, TPL_MEM, &resp_buffer, &resp_size); } tpl_free(node); } break; case DB_ADD: { ret = database_cuccos_add(database, cucco); db_ret(&resp_buffer, &resp_size, ret); } break; case DB_REMOVE: { ret = database_cuccos_remove(database, cucco); db_ret(&resp_buffer, &resp_size, ret); } break; case DB_LIST: { node = tpl_map("A(s)", &resp_aux); ret = database_cuccos_list(database, callback, node); if(ret) { tpl_dump(node, TPL_MEM, &resp_buffer, &resp_size); } tpl_free(node); } break; case DB_EXIT: { return 1; } break; default: { return -1; } break; } free(cucco); if(!smemory_write(server, resp_buffer, resp_size)) { free(resp_buffer); return -1; } free(resp_buffer); return ret ? 0 : -1; }
/** 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 {
/** 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; }
int main() { test_t s[5], t[5]; tpl_node *tn; int i; s[0].i = 0; strcpy(s[0].c, "cat"); s[1].i = 1; strcpy(s[1].c, "dog"); s[2].i = 2; strcpy(s[2].c, "eel"); s[3].i = 3; strcpy(s[3].c, "emu"); s[4].i = 4; strcpy(s[4].c, "ant"); tn = tpl_map("S(ic#)#", &s, 4, 5); tpl_pack(tn,0); tpl_dump(tn,TPL_FILE,filename); tpl_free(tn); tn = tpl_map("S(ic#)#", &t, 4, 5); tpl_load(tn,TPL_FILE,filename); tpl_unpack(tn,0); tpl_free(tn); for(i=0; i < 5; i++) { printf("%d %s\n", s[i].i, s[i].c); } return 0; }
void serialize_gesture(const gesture g, void* buffer, size_t bufsize) { tpl_node *tn; tn = tpl_map(gesture_format_string, &g); tpl_pack(tn, 0); tpl_dump(tn, TPL_MEM|TPL_PREALLOCD, buffer, bufsize); tpl_free(tn); }
int main ( int n , char* a [ ] ) { tpl_node* tn ; char c='a',c2='b',c3,c4; int64_t cn = -100, cn2 ; uint64_t ucn = 200, ucn2; tn = tpl_map ( "A(cIcU)" , &c, &cn, &c2, &ucn ) ; tpl_pack ( tn , 1 ) ; c += 1; cn -= 1; c2 += 1; ucn += 1; tpl_pack ( tn , 1 ) ; tpl_dump ( tn , TPL_FILE , "/tmp/test92.tpl" ) ; tpl_free ( tn ) ; tn = tpl_map ( "A(cIcU)" , &c3, &cn2, &c4, &ucn2 ) ; tpl_load(tn,TPL_FILE,"/tmp/test92.tpl"); /* Hesitant to rely on portability of %lld to print int64_t. At least on MinGW it is questionable. */ /* * while (tpl_unpack(tn,1) > 0) { * printf("%c %lld %c %llu\n", c3, cn2, c4, ucn2); * } */ tpl_unpack(tn,1); if (c3 != 'a' || cn2 != -100 || c4 != 'b' || ucn2 != 200) printf("unpack error 1\n"); tpl_unpack(tn,1); if (c3 != 'b' || cn2 != -101 || c4 != 'c' || ucn2 != 201) printf("unpack error 2\n"); return ( 0 ) ; }
irpc_retval_t irpc_recv_usb_reset_device(struct irpc_connection_info *ci, irpc_device_handle *handle) { tpl_node *tn = NULL; irpc_retval_t retval; irpc_func_t func = IRPC_USB_RESET_DEVICE; int sock = ci->server_sock; irpc_send_func(func, sock); // Send irpc_device_handle to server. tn = tpl_map(IRPC_DEV_HANDLE_FMT, handle); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_reset_device packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
void irpc_send_usb_bulk_transfer(struct irpc_connection_info *ci) { tpl_node *tn = NULL; irpc_retval_t retval = IRPC_SUCCESS; irpc_device_handle handle; char endpoint, data[IRPC_MAX_DATA];; int length, transfered, timeout; int sock = ci->client_sock; tn = tpl_map(IRPC_BULK_TRANSFER_FMT, &handle, &endpoint, &length, &transfered, &timeout); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); retval = libusb_bulk_transfer(irpc_handle, endpoint, data, length, &transfered, timeout); // Send libusb_bulk_transfer packet. tn = tpl_map(IRPC_STR_INT_INT_FMT, &retval, &transfered, &data, IRPC_MAX_DATA); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
irpc_retval_t irpc_recv_usb_set_configuration(struct irpc_connection_info *ci, irpc_device_handle *handle, int config) { tpl_node *tn = NULL; irpc_retval_t retval; irpc_func_t func = IRPC_USB_SET_CONFIGURATION; int sock = ci->server_sock; irpc_send_func(func, sock); // Send irpc_device_handle and config to server. tn = tpl_map(IRPC_DEV_HANDLE_INT_FMT, handle, &config); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_set_configuration packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
int main() { tpl_node *tn; int i; struct example dst, src = { /* .s1 = */ "string", /* .s2 = */ {'b','y','t','e',' ','a','r','r','a','y'} }; tn = tpl_map( "S(sc#)", &src, S2_LEN); /* NOTE S(...) */ tpl_pack( tn, 0 ); tpl_dump( tn, TPL_FILE, "/tmp/test77.tpl" ); tpl_free( tn ); /* unpack it now into another struct */ tn = tpl_map( "S(sc#)", &dst, S2_LEN); tpl_load( tn, TPL_FILE, "/tmp/test77.tpl" ); tpl_unpack( tn, 0 ); tpl_free( tn ); printf("%s\n", dst.s1); for(i=0; i < S2_LEN; i++) printf("%c", dst.s2[i]); printf("\n"); free(dst.s1); /* tpl allocated it for us; we must free it */ return(0); }
irpc_retval_t irpc_recv_usb_get_device_descriptor(struct irpc_connection_info *ci, irpc_device *idev, struct irpc_device_descriptor *desc) { tpl_node *tn = NULL; irpc_func_t func = IRPC_USB_GET_DEVICE_DESCRIPTOR; irpc_retval_t retval; int sock = ci->server_sock; irpc_send_func(func, sock); // Send irpc_device to server. tn = tpl_map(IRPC_DEV_FMT, idev); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_get_device_descriptor packet. tn = tpl_map(IRPC_DESC_FMT, desc, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
void irpc_send_usb_get_device_list(struct irpc_connection_info *ci) { tpl_node *tn = NULL; libusb_device **list = NULL; struct irpc_device_list devlist; int sock = ci->client_sock; bzero(&devlist, sizeof(struct irpc_device_list)); int i; ssize_t cnt = libusb_get_device_list(irpc_ctx, &list); for (i = 0; i < cnt && i < IRPC_MAX_DEVS; i++) { libusb_device *dev = *(list + i); irpc_device *idev = &devlist.devs[i]; idev->bus_number = dev->bus_number; idev->device_address = dev->device_address; idev->num_configurations = dev->num_configurations; idev->session_data = dev->session_data; devlist.n_devs++; } // Send usb_get_device_list packet. tn = tpl_map(IRPC_DEVLIST_FMT, &devlist.n_devs, devlist.devs, IRPC_MAX_DEVS); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); libusb_free_device_list(list, 1); }
irpc_retval_t irpc_recv_usb_get_string_descriptor_ascii(struct irpc_connection_info *ci, irpc_device_handle *handle, int idx, char data[], int length) { tpl_node *tn = NULL; int retval; irpc_func_t func = IRPC_USB_GET_STRING_DESCRIPTOR_ASCII; int sock = ci->server_sock; irpc_send_func(func, sock); tn = tpl_map(IRPC_STRING_DESC_FMT, handle, &idx, &length); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); tn = tpl_map(IRPC_STR_INT_FMT, &retval, data, IRPC_MAX_DATA); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
irpc_retval_t irpc_recv_usb_clear_halt(struct irpc_connection_info *ci, irpc_device_handle *handle, char endpoint) { tpl_node *tn = NULL; irpc_retval_t retval; irpc_func_t func = IRPC_USB_CLEAR_HALT; int sock = ci->server_sock; irpc_send_func(func, sock); // Send irpc_device_handle, and endpoint to server. tn = tpl_map(IRPC_CLEAR_HALT_FMT, handle, &endpoint); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_clear_halt packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
int main() { test_t t; char *s; tpl_node *tn; tn = tpl_map("A(S(c#)s)", &t, LEN, &s); printf("mapped\n"); memcpy(t.name,"abcdefghi\0",10); s="first"; tpl_pack(tn,1); memcpy(t.name,"jklmnopqr\0",10); s="second"; tpl_pack(tn,1); tpl_dump(tn,TPL_FILE,filename); tpl_free(tn); printf("freed\n"); tn = tpl_map("A(S(c#)s)", &t, LEN, &s); tpl_load(tn,TPL_FILE,filename); while(tpl_unpack(tn,1) > 0) { printf("%s %s\n", t.name, s); } tpl_free(tn); return 0; }
irpc_retval_t irpc_recv_usb_set_interface_alt_setting(struct irpc_connection_info *ci, irpc_device_handle *handle, int intf, int alt_setting) { tpl_node *tn = NULL; irpc_retval_t retval; irpc_func_t func = IRPC_USB_SET_INTERFACE_ALT_SETTING; int sock = ci->server_sock; irpc_send_func(func, sock); // Send irpc_device_handle, interface, and alt_setting to server. tn = tpl_map(IRPC_DEV_HANDLE_INT_INT_FMT, handle, &intf, &alt_setting); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_set_interface_alt_setting packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
irpc_retval_t irpc_recv_usb_bulk_transfer(struct irpc_connection_info *ci, irpc_device_handle *handle, char endpoint, char data[], int length, int *transfered, int timeout) { tpl_node *tn = NULL; int retval; irpc_func_t func = IRPC_USB_BULK_TRANSFER; int sock = ci->server_sock; irpc_send_func(func, sock); tn = tpl_map(IRPC_BULK_TRANSFER_FMT, handle, &endpoint, &length, transfered, &timeout); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_bulk_transfer packet. tn = tpl_map(IRPC_STR_INT_INT_FMT, &retval, &transfered, data, IRPC_MAX_DATA); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
void irpc_send_usb_set_interface_alt_setting(struct irpc_connection_info *ci) { tpl_node *tn = NULL; irpc_retval_t retval = IRPC_SUCCESS; irpc_device_handle handle; int sock = ci->client_sock; int intf, alt_setting; // Read irpc_device_handle, interface, and alt_setting from client. tn = tpl_map(IRPC_DEV_HANDLE_INT_INT_FMT, &handle, &intf, &alt_setting); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); if (libusb_set_interface_alt_setting(irpc_handle, intf, alt_setting) != 0) retval = IRPC_FAILURE; // Send libusb_set_interface_alt_setting packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
int main() { struct st dst, s = {'a', {0,1,2,3,4,5,6,7,8,9}}; tpl_node *tn; int j; tn = tpl_map("A(S(ci#))", &s, ILEN); tpl_pack(tn,1); /* fiddle with the fields and pack another element */ s.c++; for(j=0;j<ILEN;j++) s.i[j]++; tpl_pack(tn,1); tpl_dump(tn,TPL_FILE,"/tmp/test81.tpl"); tpl_free(tn); tn = tpl_map("A(S(ci#))", &dst, ILEN); tpl_load(tn,TPL_FILE,"/tmp/test81.tpl"); while (tpl_unpack(tn,1) > 0) { printf("%c ", dst.c); for(j=0;j<ILEN;j++) printf("%d ", dst.i[j]); printf("\n"); } tpl_free(tn); return(0); }
int main() { struct st s[NUM], t[NUM]; tpl_node *tn; int i; int a=5,d=8, A, D; char b='6',c='7', B, C; memset(s, 0, sizeof(s)); /* clear s */ memset(t, 0, sizeof(t)); /* clear t */ /* fill s with random stuff */ for(i=0; i < NUM; i++) { s[i].i = i; s[i].f = 3.14159 * i; s[i].v[0] = NUM*i; s[i].v[1] = NUM+i; strncpy(s[i].c, "abcdefg",8); s[i].c[0] += 1; } tn = tpl_map("icS(ic#fv#)#ci", &a, &b, s, 8, 2, NUM, &c, &d); tpl_pack(tn,0); tpl_dump(tn,TPL_FILE,filename); tpl_free(tn); tn = tpl_map("icS(ic#fv#)#ci", &A, &B, t, 8, 2, NUM, &C, &D); tpl_load(tn,TPL_FILE,filename); tpl_unpack(tn,0); tpl_free(tn); /* see if the result is the same as the s */ printf("structures %s\n", (!memcmp(t,s,sizeof(d)))? "match" : "mismatch"); printf("A %s\n", (a==A)? "matches" : "mismatches"); printf("B %s\n", (b==B)? "matches" : "mismatches"); printf("C %s\n", (c==C)? "matches" : "mismatches"); printf("D %s\n", (d==D)? "matches" : "mismatches"); return 0; }
int main() { tpl_node *tn; int i,j,d=1,D=-1; char c='a', C='0'; char *strs[NUM_STRS]; char *STRS[NUM_STRS]; tn = tpl_map("cA(s#)i", &c, strs, NUM_STRS, &d); for(i=0; i<NUM_ELMT; i++) { /* pack the same thing this many times*/ for(j=0; j<NUM_STRS; j++) {/* each time just tweaking them a bit */ strs[j] = malloc( SLEN+1 ); memcpy(strs[j], STR, SLEN+1); strs[j][0] = 'a'+j; } tpl_pack(tn,1); } tpl_pack(tn,0); tpl_dump(tn,TPL_FILE,filename); tpl_free(tn); tn = tpl_map("cA(s#)i", &C, STRS, NUM_STRS, &D); tpl_load(tn,TPL_FILE,filename); tpl_unpack(tn,0); while(tpl_unpack(tn,1)>0) { for(i=0; i<NUM_STRS; i++) { printf("%s\n", STRS[i]); free(STRS[i]); } } tpl_free(tn); printf("%d %c\n", D, C); return 0; }
void irpc_send_func(irpc_func_t func, int sock) { tpl_node *tn = tpl_map(IRPC_INT_FMT, &func); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
void irpc_send_usb_open(struct irpc_connection_info *ci) { tpl_node *tn = NULL; irpc_retval_t retval = IRPC_SUCCESS; irpc_device idev; libusb_device *f = NULL; libusb_device **list = NULL; irpc_device_handle ihandle; int sock = ci->client_sock; // Read irpc_device from client. tn = tpl_map(IRPC_DEV_FMT, &idev); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); int i; ssize_t cnt = libusb_get_device_list(irpc_ctx, &list); for (i = 0; i < cnt; i++) { libusb_device *dev = list[i]; if (dev->session_data == idev.session_data) { f = dev; break; } } if (!f) { retval = IRPC_FAILURE; goto send; } // Close an already opened handle. if (irpc_handle) { libusb_close(irpc_handle); irpc_handle = NULL; } if (libusb_open(f, &irpc_handle) != 0) { retval = IRPC_FAILURE; goto send; } libusb_free_device_list(list, 1); 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 packet. tn = tpl_map(IRPC_DEV_HANDLE_RET_FMT, &ihandle, &retval); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
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; }