/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY * BY HAND!! * * Generated by lcm-gen **/ #include "path_t.h" #include static int __path_t_hash_computed; static int64_t __path_t_hash; int64_t __path_t_hash_recursive(const __lcm_hash_ptr *p) { const __lcm_hash_ptr *fp; for (fp = p; fp != NULL; fp = fp->parent) if (fp->v == __path_t_get_hash) return 0; const __lcm_hash_ptr cp = {p, (void *)__path_t_get_hash}; (void)cp; int64_t hash = 0xecdb2a054c696658LL + __int64_t_hash_recursive(&cp) + __int16_t_hash_recursive(&cp) + __double_hash_recursive(&cp); return (hash << 1) + ((hash >> 63) & 1); } int64_t __path_t_get_hash(void) { if (!__path_t_hash_computed) { __path_t_hash = __path_t_hash_recursive(NULL); __path_t_hash_computed = 1; } return __path_t_hash; } int __path_t_encode_array(void *buf, int offset, int maxlen, const path_t *p, int elements) { int pos = 0, thislen, element; for (element = 0; element < elements; element++) { thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].utime), 1); if (thislen < 0) return thislen; else pos += thislen; thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].length), 1); if (thislen < 0) return thislen; else pos += thislen; { int a; for (a = 0; a < p[element].length; a++) { thislen = __double_encode_array(buf, offset + pos, maxlen - pos, p[element].xyr[a], 3); if (thislen < 0) return thislen; else pos += thislen; } } } return pos; } int path_t_encode(void *buf, int offset, int maxlen, const path_t *p) { int pos = 0, thislen; int64_t hash = __path_t_get_hash(); thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1); if (thislen < 0) return thislen; else pos += thislen; thislen = __path_t_encode_array(buf, offset + pos, maxlen - pos, p, 1); if (thislen < 0) return thislen; else pos += thislen; return pos; } int __path_t_encoded_array_size(const path_t *p, int elements) { int size = 0, element; for (element = 0; element < elements; element++) { size += __int64_t_encoded_array_size(&(p[element].utime), 1); size += __int16_t_encoded_array_size(&(p[element].length), 1); { int a; for (a = 0; a < p[element].length; a++) { size += __double_encoded_array_size(p[element].xyr[a], 3); } } } return size; } int path_t_encoded_size(const path_t *p) { return 8 + __path_t_encoded_array_size(p, 1); } int __path_t_decode_array(const void *buf, int offset, int maxlen, path_t *p, int elements) { int pos = 0, thislen, element; for (element = 0; element < elements; element++) { thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].utime), 1); if (thislen < 0) return thislen; else pos += thislen; thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].length), 1); if (thislen < 0) return thislen; else pos += thislen; p[element].xyr = (double **)lcm_malloc(sizeof(double *) * p[element].length); { int a; for (a = 0; a < p[element].length; a++) { p[element].xyr[a] = (double *)lcm_malloc(sizeof(double) * 3); thislen = __double_decode_array(buf, offset + pos, maxlen - pos, p[element].xyr[a], 3); if (thislen < 0) return thislen; else pos += thislen; } } } return pos; } int __path_t_decode_array_cleanup(path_t *p, int elements) { int element; for (element = 0; element < elements; element++) { __int64_t_decode_array_cleanup(&(p[element].utime), 1); __int16_t_decode_array_cleanup(&(p[element].length), 1); { int a; for (a = 0; a < p[element].length; a++) { __double_decode_array_cleanup(p[element].xyr[a], 3); if (p[element].xyr[a]) free(p[element].xyr[a]); } } if (p[element].xyr) free(p[element].xyr); } return 0; } int path_t_decode(const void *buf, int offset, int maxlen, path_t *p) { int pos = 0, thislen; int64_t hash = __path_t_get_hash(); int64_t this_hash; thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this_hash, 1); if (thislen < 0) return thislen; else pos += thislen; if (this_hash != hash) return -1; thislen = __path_t_decode_array(buf, offset + pos, maxlen - pos, p, 1); if (thislen < 0) return thislen; else pos += thislen; return pos; } int path_t_decode_cleanup(path_t *p) { return __path_t_decode_array_cleanup(p, 1); } int __path_t_clone_array(const path_t *p, path_t *q, int elements) { int element; for (element = 0; element < elements; element++) { __int64_t_clone_array(&(p[element].utime), &(q[element].utime), 1); __int16_t_clone_array(&(p[element].length), &(q[element].length), 1); q[element].xyr = (double **)lcm_malloc(sizeof(double *) * q[element].length); { int a; for (a = 0; a < p[element].length; a++) { q[element].xyr[a] = (double *)lcm_malloc(sizeof(double) * 3); __double_clone_array(p[element].xyr[a], q[element].xyr[a], 3); } } } return 0; } path_t *path_t_copy(const path_t *p) { path_t *q = (path_t *)malloc(sizeof(path_t)); __path_t_clone_array(p, q, 1); return q; } void path_t_destroy(path_t *p) { __path_t_decode_array_cleanup(p, 1); free(p); } int path_t_publish(lcm_t *lc, const char *channel, const path_t *p) { int max_data_size = path_t_encoded_size(p); uint8_t *buf = (uint8_t *)malloc(max_data_size); if (!buf) return -1; int data_size = path_t_encode(buf, 0, max_data_size, p); if (data_size < 0) { free(buf); return data_size; } int status = lcm_publish(lc, channel, buf, data_size); free(buf); return status; } struct _path_t_subscription_t { path_t_handler_t user_handler; void *userdata; lcm_subscription_t *lc_h; }; static void path_t_handler_stub(const lcm_recv_buf_t *rbuf, const char *channel, void *userdata) { int status; path_t p; memset(&p, 0, sizeof(path_t)); status = path_t_decode(rbuf->data, 0, rbuf->data_size, &p); if (status < 0) { fprintf(stderr, "error %d decoding path_t!!!\n", status); return; } path_t_subscription_t *h = (path_t_subscription_t *)userdata; h->user_handler(rbuf, channel, &p, h->userdata); path_t_decode_cleanup(&p); } path_t_subscription_t *path_t_subscribe(lcm_t *lcm, const char *channel, path_t_handler_t f, void *userdata) { path_t_subscription_t *n = (path_t_subscription_t *)malloc(sizeof(path_t_subscription_t)); n->user_handler = f; n->userdata = userdata; n->lc_h = lcm_subscribe(lcm, channel, path_t_handler_stub, n); if (n->lc_h == NULL) { fprintf(stderr, "couldn't reg path_t LCM handler!\n"); free(n); return NULL; } return n; } int path_t_subscription_set_queue_capacity(path_t_subscription_t *subs, int num_messages) { return lcm_subscription_set_queue_capacity(subs->lc_h, num_messages); } int path_t_unsubscribe(lcm_t *lcm, path_t_subscription_t *hid) { int status = lcm_unsubscribe(lcm, hid->lc_h); if (0 != status) { fprintf(stderr, "couldn't unsubscribe path_t_handler %p!\n", hid); return -1; } free(hid); return 0; }