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); }
int handle_list(struct opcode_context *ctx) { tpl_node *packet; char *peer_id = NULL, *peer_address = NULL; unsigned short peer_port = 0; packet = tpl_map(LIST_TPL_FORMAT, &peer_id, &peer_address, &peer_port); tpl_load(packet, TPL_MEM|TPL_PREALLOCD|TPL_EXCESS_OK, ctx->p_ctx->message, ctx->p_ctx->message_len); while (tpl_unpack(packet, 1) > 0) { printf("Read: %s %s %d\n", peer_id, peer_address, peer_port); } tpl_free(packet); return RESPONSE_HANDLED; }
void irpc_send_usb_release_interface(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; // Read irpc_device_handle and interface from client. tn = tpl_map(IRPC_DEV_HANDLE_INT_FMT, &handle, &intf); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); if (libusb_release_interface(irpc_handle, intf) != 0) retval = IRPC_FAILURE; // Send libusb_release_interface packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
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); }
int main() { tpl_node *tn; int i; tn = tpl_map("A(i)",&i); tpl_load(tn,TPL_FILE,"test61_0.tpl"); while (tpl_unpack(tn,1) > 0) printf("i is %d\n", i); /* test load-then-load: implicit free via tpl_free_keep_map */ tpl_load(tn, TPL_FILE,"test61_1.tpl"); while (tpl_unpack(tn,1) > 0) printf("i is %d\n", i); tpl_free(tn); return(0); }
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; }
void irpc_send_usb_set_configuration(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 config; // Read irpc_device_handle and config from client. tn = tpl_map(IRPC_DEV_HANDLE_INT_FMT, &handle, &config); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); if (libusb_set_configuration(irpc_handle, config) != 0) retval = IRPC_FAILURE; // Send libusb_set_configuration packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
void irpc_recv_usb_open_device_with_vid_pid(struct irpc_connection_info *ci, int vendor_id, int product_id, irpc_device_handle *handle) { tpl_node *tn = NULL; irpc_func_t func = IRPC_USB_OPEN_DEVICE_WITH_VID_PID; int sock = ci->server_sock; irpc_send_func(func, sock); // Send vendor and product id to server. tn = tpl_map(IRPC_PRID_VEID_FMT, &vendor_id, &product_id); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); // Read libusb_open_device_with_vid_pid packet. tn = tpl_map(IRPC_DEV_HANDLE_FMT, handle); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); }
int main() { int err; tpl_node *tn; tpl_hook.oops = catch_oops; /* install fatal handler */ err = setjmp(env); /* on error, control will return here */ if (err) { printf("caught error!\n"); return -1; } tn = tpl_map("@"); /* generate a fatal error */ printf("program ending, without error\n"); return 0; }
void irpc_send_usb_get_string_descriptor_ascii(struct irpc_connection_info *ci) { tpl_node *tn = NULL; int retval; irpc_device_handle handle; int length, idx; char data[IRPC_MAX_DATA]; int sock = ci->client_sock; // Read irpc_device_handle, and endpoint to server. tn = tpl_map(IRPC_STRING_DESC_FMT, &handle, &idx, &length); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); retval = libusb_get_string_descriptor_ascii(irpc_handle, idx, data, length); // Send libusb_clear_halt packet. tn = tpl_map(IRPC_STR_INT_FMT, &retval, &data, IRPC_MAX_DATA); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
void Load(char* szFileName) { tpl_node *tn; int id; char *name; tn = tpl_map("A(is)", &id, &name); tpl_load(tn, TPL_FILE, szFileName); while (tpl_unpack(tn, 1) > 0) { printf("id %d, user %s\n", id, name); free(name); } tpl_free(tn); }
void irpc_send_usb_clear_halt(struct irpc_connection_info *ci) { tpl_node *tn = NULL; irpc_retval_t retval = IRPC_SUCCESS; irpc_device_handle handle; char endpoint; int sock = ci->client_sock; // Read irpc_device_handle, and endpoint to server. tn = tpl_map(IRPC_CLEAR_HALT_FMT, &handle, &endpoint); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); if (libusb_clear_halt(irpc_handle, endpoint) != 0) retval = IRPC_FAILURE; // Send libusb_clear_halt packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_pack(tn, 0); tpl_dump(tn, TPL_FD, sock); tpl_free(tn); }
cl_int clEnqueueCopyBuffer (cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) { printf("doing enqcopybuf\n"); int result; _buf[M_IDX] = ENQ_COPY_BUF; tpl_node *stn, *rtn; stn = tpl_map("IIIiiii", command_queue, src_buffer, dst_buffer, &src_offset, &dst_offset, &cb, &num_events_in_wait_list); rtn = tpl_map("i", &result); tpl_rpc_call(stn, rtn); tpl_deserialize(stn, rtn); return result; }
cl_int clSetKernelArg (cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value) { printf("doing setkernelarg\n"); int64_t ptr = 0; uint64_t l_size = arg_size; int result; _buf[M_IDX] = SET_KERN_ARG; tpl_node *stn, *rtn; if (arg_value == NULL) { stn = tpl_map("IiII", kernel, &arg_index, &l_size, &ptr); } else { int64_t **tmp = (int64_t **)arg_value; if (*tmp >= mem_ptrs && *tmp < mem_ptrs + 20) { l_size = 8; printf("found cl memory %p\n", *tmp); stn = tpl_map("IiII", kernel, &arg_index, &l_size, *tmp); } else { printf("copying value %p\n", *tmp); stn = tpl_map("IiII", kernel, &arg_index, &l_size, arg_value); } } rtn = tpl_map("i", &result); tpl_rpc_call(stn, rtn); tpl_deserialize(stn, rtn); return result; }
int main(int argc, char *argv[]) { tpl_node *tn; int id; char *name; tn = tpl_map("A(is)", &id, &name); tpl_load(tn, TPL_FILE, "/tmp/test35.tpl"); while ( tpl_unpack(tn,1) > 0 ) { printf("id %d, user %s\n", id, name); free(name); } tpl_free(tn); return(0); }
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); }
/* encode a tpl (kv frame) as json. */ void *enc_worker(void *thread_id) { char buf[MAX_BUF], *key, *val; json_t *o = json_object(); int rc=-1, len, nc; tpl_node *tn; while (CF.shutdown == 0) { len = nn_recv(CF.ingress_socket_pull, buf, MAX_BUF, 0); if (len < 0) { fprintf(stderr,"nn_recv: %s\n", nn_strerror(errno)); goto done; } /* decode, then re-encode as json */ json_object_clear(o); tn = tpl_map("A(ss)",&key,&val); assert(tn); if (tpl_load(tn,TPL_MEM,buf,len) < 0) goto done; while(tpl_unpack(tn,1) > 0) { json_t *jval = json_string(val); json_object_set_new(o, key, jval); free(key); key=NULL; free(val); val=NULL; } tpl_free(tn); /* dump the json object, then newline-terminate it. */ if (CF.verbose>1) json_dumpf(o, stderr, JSON_INDENT(1)); char *dump = json_dumps(o, JSON_INDENT(0)); size_t dump_len = strlen(dump); /* give the buffer to nano, from here it goes to kaf thread */ nc = nn_send(CF.egress_socket_push, dump, dump_len, 0); free(dump); if (nc < 0) { fprintf(stderr,"nn_send: %s\n", nn_strerror(errno)); goto done; } } rc = 0; done: CF.shutdown = 1; json_decref(o); return NULL; }
irpc_retval_t irpc_recv_usb_init(struct irpc_connection_info *ci) { tpl_node *tn = NULL; irpc_retval_t retval = IRPC_FAILURE; irpc_func_t func = IRPC_USB_INIT; int sock = ci->server_sock; irpc_send_func(func, sock); // Read usb_init packet. tn = tpl_map(IRPC_INT_FMT, &retval); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); return retval; }
int tpl_cb(void *tpl, size_t tpllen, void*data) { int i; tpl_node *tn; tpl_hook.oops = printf; if (DEBUG) printf("obtained tpl of length %d\n", (int)tpllen); tn = tpl_map("A(i)", &i); tpl_load(tn, TPL_MEM, tpl, tpllen); num_tpls++; while (tpl_unpack(tn,1) > 0) sum_tpls += i; tpl_free(tn); /* this next line is a hack to test the callback's ability * to abort further tpl processing by returning < 0 */ if (num_tpls == 3) return -1; return 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; }
void irpc_recv_usb_get_device_list(struct irpc_connection_info *ci, struct irpc_device_list *devlist) { tpl_node *tn = NULL; irpc_func_t func = IRPC_USB_GET_DEVICE_LIST; int sock = ci->server_sock; irpc_send_func(func, sock); // Read usb_get_device_list packet. tn = tpl_map(IRPC_DEVLIST_FMT, &devlist->n_devs, devlist->devs, IRPC_MAX_DEVS); tpl_load(tn, TPL_FD, sock); tpl_unpack(tn, 0); tpl_free(tn); }
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); }
int main(int argc, char **argv) { struct ftdi_context *ftdi; int f = 0; int vid = 0x403; /* USB vendor ID -- use 'lsusb' to see */ int pid = 0x6001; /* USB product ID */ tpl_node *tn; tn = tpl_map("cccc",&R,&G,&B,&D); if ((ftdi = ftdi_new()) == 0) { fprintf(stderr, "ftdi_new failed\n"); return -1; } ftdi_set_interface(ftdi, INTERFACE_ANY); f = ftdi_usb_open(ftdi, vid, pid); if (f < 0) { fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi)); fprintf(stderr, "you may need to run as root\n"); return -1; } f = ftdi_write_data(ftdi, enttec_msg, sizeof(enttec_msg)); while(tpl_load(tn, TPL_FD, 0) == 0) { tpl_unpack(tn,0); fprintf(stderr,"writing %d %d %d %d\n", R,G,B,D); enttec_msg[6] = R; enttec_msg[7] = G; enttec_msg[8] = B; enttec_msg[9] = 0; enttec_msg[10] = D; ftdi_write_data(ftdi, enttec_msg, sizeof(enttec_msg)); } ftdi_usb_close(ftdi); ftdi_free(ftdi); tpl_free(tn); return 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); }
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); }
int main(int argc, char *argv[]) { int rc = -1; void *buf=NULL; size_t sz; if (tpl_gather(TPL_GATHER_BLOCKING, STDIN_FILENO, &buf, &sz) <= 0) goto done; /* peek into the saved image to see how many samples it has in it */ uint32_t num_fxlens, *fxlens; char *fmt = tpl_peek(TPL_MEM|TPL_FXLENS, buf, sz, &num_fxlens, &fxlens); if ((!fmt) || (num_fxlens<1)) {fprintf(stderr,"invalid buffer\n"); goto done;} cfg.nsamples = fxlens[0]; free(fxlens); /* make a buffer to load the PCM data into */ /* TODO assert cfg.resolution == cfg.resolution in the image */ size_t pcmlen = cfg.resolution * cfg.nsamples; int16_t *pcm; pcm = (int16_t*)malloc(pcmlen); if (!pcm) {fprintf(stderr,"out of memory\n"); goto done;} tpl_node *tn = tpl_map("iiij#", &cfg.sample_rate, &cfg.duration, &cfg.resolution, pcm, cfg.nsamples); tpl_load(tn, TPL_MEM, buf, sz); tpl_unpack(tn,0); tpl_free(tn); if (cfg.verbose) fprintf(stderr,"read the PCM file: " "duration %u s, sample rate %u hz, resolution %u bits\n", cfg.duration, cfg.sample_rate, cfg.resolution*8); play_pcm(argc, argv, pcm, pcmlen, cfg.sample_rate, cfg.verbose); /* TODO cycle if requested, reusing buf? */ rc = 0; done: if (buf) free(buf); return rc; }
static tpl_node *map_data_to_tplnode(const void *struct_p, const BLOB_TYPES data_type) /** * Prepares #tpl_node for serialization or deserialization * * @param[in] struct_p pointer to the blob of data * @param[in] data_type blob type to be mapped * * @return No error: #tpl_node pointer * @return Error: NULL pointer * */ { char format_str[300]; tpl_node *tn=NULL; switch (data_type) { case SCAN_DATA_TYPE: strcpy(format_str, "S("); strcat(format_str, SCAN_DATA_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str, struct_p, SCAN_NAME_LEN, NUM_SHIFT_VECTOR_COEFFS, NUM_PIXEL_NM_COEFFS, NANO_SER_NUM_LEN, NANO_SER_NUM_LEN, SCAN_CFG_FILENAME_LEN, ADC_DATA_LEN); break; case CFG_TYPE: strcpy(format_str, "S("); strcat(format_str, SCAN_CFG_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str, struct_p, NANO_SER_NUM_LEN, SCAN_CFG_FILENAME_LEN); break; case SLEW_CFG_HEAD_TYPE: strcpy(format_str, "S("); strcat(format_str, SLEW_SCAN_CFG_HEAD_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str, struct_p, NANO_SER_NUM_LEN, SCAN_CFG_FILENAME_LEN); break; case SLEW_CFG_SECT_TYPE: strcpy(format_str, "S("); strcat(format_str, SLEW_SCAN_CFG_SECT_FORMAT); strcat(format_str, ")#"); tn = tpl_map(format_str, struct_p, SLEW_SCAN_MAX_SECTIONS); break; case CALIB_TYPE: strcpy(format_str, "S("); strcat(format_str, CALIB_COEFFS_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str , struct_p , NUM_SHIFT_VECTOR_COEFFS, NUM_PIXEL_NM_COEFFS); break; case REF_CAL_MATRIX_TYPE: strcpy(format_str, "S("); strcat(format_str, REF_CAL_MATRIX_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str, struct_p, REF_CAL_INTERP_WIDTH, REF_CAL_INTERP_WAVELENGTH, REF_CAL_INTERP_WIDTH, REF_CAL_INTERP_WAVELENGTH); break; case SLEW_DATA_HEAD_TYPE: strcpy(format_str, "S("); strcat(format_str, SLEW_SCAN_DATA_HEAD_FORMAT); strcat(format_str, ")"); tn = tpl_map(format_str, struct_p, SCAN_NAME_LEN, NUM_SHIFT_VECTOR_COEFFS, NUM_PIXEL_NM_COEFFS, NANO_SER_NUM_LEN); break; case SLEW_DATA_ADC_TYPE: strcpy(format_str, ADC_DATA_FORMAT); tn = tpl_map(format_str, struct_p, ADC_DATA_LEN); break; default: /* Unrecognized type, should not be possible with BLOB_TYPES type */ tn = NULL; break; } return tn; }
int main(int argc, char *argv[]) { int sockfd, newsockfd, portno, clilen, pid; struct sockaddr_in serv_addr, cli_addr; char buf[1024]; int n = 0; #ifdef USE_TPL tpl_node *tn; struct struct_type { int x; char *string; char c; } local_struct; #endif struct timeval timeout; bzero(buf, sizeof(buf)); if (argc < 3) { fprintf(stderr,"usage: %s <server> <port>\n", argv[0]); exit(1); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("Error opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(argv[1]); serv_addr.sin_port = htons(portno); timeout.tv_sec = 5; timeout.tv_usec = 0; if (setsockopt (sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) error("setsockopt failed\n"); if (setsockopt (sockfd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) error("setsockopt failed\n"); if (0 != connect(sockfd, (const struct sockaddr *) &serv_addr, sizeof(serv_addr))) { error("connect failed\n"); } printf(">> $helloworld*\n"); write(sockfd, "$helloworld*\n", sizeof("$helloworld*\n")); n = read(sockfd, buf, sizeof(buf)); printf("Read %d from server: %s\n", n, buf); #ifdef USE_TPL printf(">> $testbinary*\n"); write(sockfd, "$testbinary*\n", sizeof("$testbinary*\n")); n = read(sockfd, buf, sizeof(buf)); printf("Read %d from server: %s\n", n, buf); tn = tpl_map("S(isc)", &local_struct); tpl_load(tn, TPL_MEM|TPL_EXCESS_OK, buf, n); tpl_unpack(tn, 0); printf("S.i = %d, S.s = %s, S.c = %c\n", local_struct.x, local_struct.string, local_struct.c); tpl_free(tn); #endif #ifdef USE_LUA printf(">> $testlua*\n"); write(sockfd, "$testlua*\n", sizeof("$testlua*\n")); n = read(sockfd, buf, sizeof(buf)); printf("Read %d from server: %s\n", n, buf); #endif bzero(buf, sizeof(buf)); return 0; }
cl_int clEnqueueNDRangeKernel (cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) { printf("doing enqndrange\n"); int result; _buf[M_IDX] = ENQ_NDR_KERN; tpl_node *stn, *rtn; uint64_t gwo, gws, lws; stn = tpl_map("IIiiA(U)A(U)A(U)", command_queue, kernel, &work_dim, &num_events_in_wait_list, &gwo, &gws, &lws); rtn = tpl_map("i", &result); int i; for (i = 0; i < work_dim; i++) { if (global_work_offset == NULL) { gwo = 0; } else { gwo = global_work_offset[i]; } tpl_pack(stn, 1); printf("gwo %d i %d\n", gwo, i); } for (i = 0; i < work_dim; i++) { gws = global_work_size[i]; if (global_work_size == NULL) { gws = 0; } else { gws = global_work_size[i]; } tpl_pack(stn, 2); printf("gws %d i %d\n", gws, i); } for (i = 0; i < work_dim; i++) { if (local_work_size == NULL) { lws = 0; } else { lws = local_work_size[i]; } tpl_pack(stn, 3); printf("lws %d i %d\n", lws, i); } tpl_rpc_call(stn, rtn); tpl_deserialize(stn, rtn); return result; }
void *_faninany_start(void* _rec_from_ptr) { int _rec_from = (int)_rec_from_ptr; int exit = 1; //writeDebug("thread faninany started at relay"); while (exit) { struct Msg* msgStruct = (struct Msg*) malloc(sizeof(struct Msg)); int fdToReadFrom = _rec_from; tpl_node * tn; tpl_bin tb; tn = tpl_map("S(iiU)B", msgStruct, &tb); //writeDebug("MSG Mapped"); int validity = (fcntl(fdToReadFrom, F_GETFL) != -1); if (validity) { writeDebugExtraPlace("File descriptor is accessible", fdToReadFrom); } else { writeErrorExtraPlace("File descriptor is not accessible", fdToReadFrom); } //writeDebug("started trying to load msg"); int success = tpl_load(tn, TPL_FD, fdToReadFrom); //writeDebug("Finished loading"); if (success == 0) { writeDebugExtraPlace("msg read on file descriptor", fdToReadFrom); } else { writeErrorExtraPlace("msg failed to read on file descriptor", fdToReadFrom); // return EXIT_FAILURE; } tpl_unpack(tn, 0); tpl_pack(tn, 0); int fdToWrite = 99;//_get_write_fd(_write_to); //writeDebug("unpacking reading msg"); int pthreadRet1; int pthreadRet2; pthread_mutex_t writeLock = getMutexLock(); pthreadRet1 = pthread_mutex_lock(&writeLock); success = tpl_dump(tn, TPL_FD, fdToWrite); pthreadRet2 = pthread_mutex_unlock(&writeLock); if (pthreadRet1 == EXIT_FAILURE) { writeError("Thread locked unsuccessful msg"); } else if (pthreadRet2 == EXIT_FAILURE) { writeError("Thread unlocked unsuccessful"); } else { writeDebug("thread locked and unlocked successful"); } if(msgStruct->msgType == TERMINATE){ exit = 0; } //writeDebug("tpl will be freed"); tpl_free(tn); _deallocate_msg(msgStruct); //writeDebug("tpl freed"); if (success == 0) { writeDebugExtraPlace("msg written on file descriptor", fdToReadFrom); } else { writeErrorExtraPlace("msg failed to read on file descriptor", fdToReadFrom); } } }