Ejemplo n.º 1
0
/* Uses the tlp library and deserialize the binary file
 * with the structures from parsing */
void load_structures() {
    int i = 0;
    tpl_node *tn_modules, *tn_instances;
    Module tmp_module;
    Instance tmp_instance;
    Instance *head = NULL;

    // Map an array structs
    tn_modules = tpl_map("A(S(c#))", &tmp_module, SIZE);
    // Load file with structure
    tpl_load(tn_modules, TPL_FILE, "modules.tpl");
    // Unpack the array and save the structrure
    while(tpl_unpack(tn_modules, 1) > 0) {
        add_module(tmp_module.name);
    }
    // Free the memory
    tpl_free(tn_modules);

    // Map a two dimensional array with lists
    tn_instances = tpl_map("A(A(S(ic#)))", &tmp_instance, SIZE);
    // Load file with structure
    tpl_load(tn_instances, TPL_FILE, "instances.tpl");
    // Unpack the array and save the structure
    while(tpl_unpack(tn_instances, 1) > 0) {
        while(tpl_unpack(tn_instances, 2) > 0) {
            head = addInstance(head, tmp_instance.instance_name, tmp_instance.module_key);
        }
        cells[i] = head;
        i++;
        head = NULL;
    }
    // Free the memory
    tpl_free(tn_instances);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
  char *prog = argv[0];
  int opt, rc=-1;
  hex_t h;

  utarray_new(cfg.hexv, &hex_icd);

  while ( (opt = getopt(argc, argv, "v+i:o:h")) != -1) {
    switch (opt) {
      case 'v': cfg.verbose++; break;
      case 'i': cfg.infile = strdup(optarg); break;
      case 'o': cfg.outfile = strdup(optarg); break;
      case 'h': default: usage(prog); break;
    }
  }

  if (!cfg.outfile || !cfg.infile) usage(prog);

  /* read input file */
  tpl_node *tn = tpl_map("A(sii)", &h.id, &h.x, &h.y);
  if (tpl_load(tn, TPL_FILE, cfg.infile)) goto done;
  while(tpl_unpack(tn,1) > 0) utarray_push_back(cfg.hexv, &h);
  tpl_free(tn);

  find_bounds();
  draw_image();
  rc = 0;

 done:
  utarray_free(cfg.hexv);
  return rc;

}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
void ClientMapPacker::unpackFromNet(ClientMap *client, unsigned char *buf, GraphicsTCOD *screen)
{
    clientMap = client;
    s_render_t sMap;
    
    tn = tpl_map((char *)"S(iiifffi)", &sMap);
    
    if(!tpl_load(tn, TPL_MEM | TPL_EXCESS_OK, buf, TILE_PACKET_SIZE))
    {
        
        tpl_unpack(tn, 0);
        
        clientMap->refreshSquare(sMap.x, sMap.y);
                
        rMap = clientMap->cMap[sMap.x][sMap.y];
        render_t cMap = serialToClient(sMap);
        
        clientMap->cMap[cMap.x][cMap.y]->x = cMap.x;
        clientMap->cMap[cMap.x][cMap.y]->y = cMap.y;
        clientMap->cMap[cMap.x][cMap.y]->H = cMap.H;
        clientMap->cMap[cMap.x][cMap.y]->S = cMap.S;
        clientMap->cMap[cMap.x][cMap.y]->V = cMap.V;
        clientMap->cMap[cMap.x][cMap.y]->explored = cMap.explored; 
        clientMap->cMap[cMap.x][cMap.y]->visible = cMap.visible;
        clientMap->cMap[cMap.x][cMap.y]->drawn = false;
        
    }
    
    
    tpl_free(tn);
    
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
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 ) ;

}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
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;
}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
gesture deserialize_gesture(void* buffer, size_t bufsize) {
    gesture g;
    tpl_node *tn;
    tn = tpl_map(gesture_format_string, &g);
    tpl_load(tn, TPL_MEM, buffer, bufsize);
    tpl_unpack(tn, 0);
    tpl_free(tn);
    return g;
}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
0
int32_t DecodeMsg(struct Msg* messageStruct, place_t _rec_from) {
	int32_t fdToReadFrom =  _get_read_fd(_rec_from);
	tpl_node * tn;
	tpl_bin tb;

	//struct MsgRead* msgStruct =  (struct MsgRead*)GC_MALLOC(sizeof(struct MsgRead));
	tn = tpl_map("S(iiiU)B", messageStruct, &tb);
	//writeDebug("MSG Mapped");
	
	int32_t 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");
	int32_t 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;
		}

	//writeDebug("unpacking reading msg");
	tpl_unpack(tn, 0);
	//writeDebug("msg unpacked succesfully");
	//messageStruct->msgType = msgStruct->msgType;
	//messageStruct->placeFrom = msgStruct->placeFrom;
	//messageStruct->size = msgStruct->size;
	//messageStruct->placeTo = msgStruct->placeTo;
	messageStruct->tb.addr = tb.addr;
	messageStruct->tb.sz = tb.sz;
//	uint64_t temp2 = getMicroTime();
//	int64_t temp = (temp2-(messageStruct->time));
//	fprintf(stderr, "%d GOING TO %d TOTAL TIME THIS MESSAGE TOOK TIME: %lld, %llu, %llu \n", messageStruct->placeFrom, messageStruct->placeTo, temp, temp2, messageStruct->time);	
//	writeDebugMsg(messageStruct);
		
  //fprintf(stderr, "%d:blob READ iuuubefore %s make sure msg is correct \n", _here(), (char *)tb.addr);
	//writeDebug("tpl will be freed");

	tpl_free(tn);
	return EXIT_SUCCESS;	
//writeDebug("tpl freed");
}
Ejemplo n.º 24
0
int DecodeMsg(struct Msg* messageStruct, place_t _rec_from) {
	int fdToReadFrom =  _get_read_fd(_rec_from);
	tpl_node * tn;
	tpl_bin tb;

	//struct MsgRead* msgStruct =  (struct MsgRead*)malloc(sizeof(struct MsgRead));
	tn = tpl_map("S(iiU)B", messageStruct, &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;
		}

	//writeDebug("unpacking reading msg");
	tpl_unpack(tn, 0);
	//writeDebug("msg unpacked succesfully");
	//messageStruct->msgType = msgStruct->msgType;
	//messageStruct->placeFrom = msgStruct->placeFrom;
	//messageStruct->size = msgStruct->size;
	messageStruct->tb.addr = tb.addr;
	messageStruct->tb.sz = tb.sz;
	
	writeDebugMsg(messageStruct);
	
	//writeDebug("tpl will be freed");

	tpl_free(tn);
	//writeDebug("tpl freed");
	if (success) {
		return EXIT_SUCCESS;
	} else {
		return EXIT_FAILURE;
	}
}
Ejemplo n.º 25
0
irpc_func_t
irpc_read_func(int sock)
{
    irpc_func_t func;
    tpl_node *tn = tpl_map(IRPC_INT_FMT, &func);
    tpl_load(tn, TPL_FD, sock);
    tpl_unpack(tn, 0);
    tpl_free(tn);
    
    return func;
}
Ejemplo n.º 26
0
int main() {
    tpl_node *tn;
    int i;

    tpl_hook.oops = printf;

    tn = tpl_map("A(i)",&i);
    tpl_load(tn,TPL_FILE,"test13.tpl");
    while (tpl_unpack(tn,1) > 0) printf("i is %d\n", i);
    tpl_free(tn);
    return(0);
}
Ejemplo n.º 27
0
int tpl_cb(void *tpl, size_t tpllen, void*data) {
    int i;
    tpl_node *tn;

    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); 
    return 0;
    
}
Ejemplo n.º 28
0
static int
tpl_deserialize_array(tpl_node *stn, tpl_node *rtn, int cb, char *c, char *buf)
{
    if (cb > 1024) {
        fprintf(stderr, "big tpl_load %d\n", cb);
        if (tpl_load(rtn, TPL_MEM|TPL_EXCESS_OK, _big_buf + H_OFFSET, 
            cb - H_OFFSET) < 0) {
            fprintf(stderr, "load failed\n");
            tpl_free(stn);
            tpl_free(rtn);
            return 0;
        }
    }
    else {
        if (tpl_load(rtn, TPL_MEM|TPL_EXCESS_OK, _buf + H_OFFSET, 
            sizeof(_buf) - H_OFFSET) < 0) {
            fprintf(stderr, "load failed\n");
            tpl_free(stn);
            tpl_free(rtn);
            return 0;
        }
    }

    tpl_unpack(rtn, 0);
    int i = 0;
    while (tpl_unpack(rtn, 1) > 0) {
        buf[i] = *c;
        i++;
    }

    tpl_free(stn);
    tpl_free(rtn);

    if (cb > 1020) {
        free(_big_buf);
    }

    return i;
}
Ejemplo n.º 29
0
static int get(void * buffer, int size, int * op, char ** name) {
	tpl_node * node = NULL;

	node = tpl_map("is", op, name);
	if(tpl_load(node, TPL_MEM, buffer, size) == -1) {
		tpl_free(node);
		return FALSE;
	}
	tpl_unpack(node, 0);
	tpl_free(node);

	return TRUE;
}
Ejemplo n.º 30
0
DLPSPEC_ERR_CODE dlpspec_deserialize(void* struct_p, const size_t buffer_size,
	   	BLOB_TYPES data_type)
/**
 * Deserializes a blob in place for the passed in struct pointer @p struct_p. 
 * Upon return, @p struct_p holds a struct of the type determined by @p data_type.
 * 
 * @param[in,out] struct_p    pointer to the blob of data, returned as applicable struct.
 * @param[in]     buffer_size size allocated to blob
 * @param[in]     data_type   blob type to be deserialized in place
 *    
 * @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)
	{
#ifdef NANO_PRE_1_1_8_BLE_WORKAROUND
        // If 'tpl\0' was overwritten by BLE in DLP NIRscan Nano firmware 
		// ≤ v1.1.7, try unpacking anyway
        if ((data_type == REF_CAL_MATRIX_TYPE) || (data_type == SCAN_DATA_TYPE))
        {
            const char tpl_header[] = "tpl\0";
            memcpy(struct_p, tpl_header, sizeof(tpl_header));
        }
#endif
        
        // unpack data
        tpl_err = tpl_load(tn, TPL_MEM|TPL_EXCESS_OK, struct_p, buffer_size);
        if ( 0 != tpl_err) // TPL error in loading
        {
            ret_val = ERR_DLPSPEC_TPL;
        }
        else
        {
            tpl_err = tpl_unpack(tn, 0);
        }

        tpl_free(tn);
	}
    else
    {
        ret_val = ERR_DLPSPEC_TPL;
    }
  
    return ret_val;
}