diff options
Diffstat (limited to 'lcmtype/path_t.cpp')
-rw-r--r-- | lcmtype/path_t.cpp | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/lcmtype/path_t.cpp b/lcmtype/path_t.cpp new file mode 100644 index 0000000..d6fde92 --- /dev/null +++ b/lcmtype/path_t.cpp | |||
@@ -0,0 +1,297 @@ | |||
1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY | ||
2 | * BY HAND!! | ||
3 | * | ||
4 | * Generated by lcm-gen | ||
5 | **/ | ||
6 | |||
7 | #include "path_t.h" | ||
8 | #include <string.h> | ||
9 | |||
10 | static int __path_t_hash_computed; | ||
11 | static int64_t __path_t_hash; | ||
12 | |||
13 | int64_t __path_t_hash_recursive(const __lcm_hash_ptr *p) { | ||
14 | const __lcm_hash_ptr *fp; | ||
15 | for (fp = p; fp != NULL; fp = fp->parent) | ||
16 | if (fp->v == __path_t_get_hash) | ||
17 | return 0; | ||
18 | |||
19 | const __lcm_hash_ptr cp = {p, (void *)__path_t_get_hash}; | ||
20 | (void)cp; | ||
21 | |||
22 | int64_t hash = 0xecdb2a054c696658LL + __int64_t_hash_recursive(&cp) + | ||
23 | __int16_t_hash_recursive(&cp) + __double_hash_recursive(&cp); | ||
24 | |||
25 | return (hash << 1) + ((hash >> 63) & 1); | ||
26 | } | ||
27 | |||
28 | int64_t __path_t_get_hash(void) { | ||
29 | if (!__path_t_hash_computed) { | ||
30 | __path_t_hash = __path_t_hash_recursive(NULL); | ||
31 | __path_t_hash_computed = 1; | ||
32 | } | ||
33 | |||
34 | return __path_t_hash; | ||
35 | } | ||
36 | |||
37 | int __path_t_encode_array(void *buf, int offset, int maxlen, const path_t *p, | ||
38 | int elements) { | ||
39 | int pos = 0, thislen, element; | ||
40 | |||
41 | for (element = 0; element < elements; element++) { | ||
42 | |||
43 | thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, | ||
44 | &(p[element].utime), 1); | ||
45 | if (thislen < 0) | ||
46 | return thislen; | ||
47 | else | ||
48 | pos += thislen; | ||
49 | |||
50 | thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, | ||
51 | &(p[element].length), 1); | ||
52 | if (thislen < 0) | ||
53 | return thislen; | ||
54 | else | ||
55 | pos += thislen; | ||
56 | |||
57 | { | ||
58 | int a; | ||
59 | for (a = 0; a < p[element].length; a++) { | ||
60 | thislen = __double_encode_array(buf, offset + pos, maxlen - pos, | ||
61 | p[element].xyr[a], 3); | ||
62 | if (thislen < 0) | ||
63 | return thislen; | ||
64 | else | ||
65 | pos += thislen; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | return pos; | ||
70 | } | ||
71 | |||
72 | int path_t_encode(void *buf, int offset, int maxlen, const path_t *p) { | ||
73 | int pos = 0, thislen; | ||
74 | int64_t hash = __path_t_get_hash(); | ||
75 | |||
76 | thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1); | ||
77 | if (thislen < 0) | ||
78 | return thislen; | ||
79 | else | ||
80 | pos += thislen; | ||
81 | |||
82 | thislen = __path_t_encode_array(buf, offset + pos, maxlen - pos, p, 1); | ||
83 | if (thislen < 0) | ||
84 | return thislen; | ||
85 | else | ||
86 | pos += thislen; | ||
87 | |||
88 | return pos; | ||
89 | } | ||
90 | |||
91 | int __path_t_encoded_array_size(const path_t *p, int elements) { | ||
92 | int size = 0, element; | ||
93 | for (element = 0; element < elements; element++) { | ||
94 | |||
95 | size += __int64_t_encoded_array_size(&(p[element].utime), 1); | ||
96 | |||
97 | size += __int16_t_encoded_array_size(&(p[element].length), 1); | ||
98 | |||
99 | { | ||
100 | int a; | ||
101 | for (a = 0; a < p[element].length; a++) { | ||
102 | size += __double_encoded_array_size(p[element].xyr[a], 3); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | return size; | ||
107 | } | ||
108 | |||
109 | int path_t_encoded_size(const path_t *p) { | ||
110 | return 8 + __path_t_encoded_array_size(p, 1); | ||
111 | } | ||
112 | |||
113 | int __path_t_decode_array(const void *buf, int offset, int maxlen, path_t *p, | ||
114 | int elements) { | ||
115 | int pos = 0, thislen, element; | ||
116 | |||
117 | for (element = 0; element < elements; element++) { | ||
118 | |||
119 | thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, | ||
120 | &(p[element].utime), 1); | ||
121 | if (thislen < 0) | ||
122 | return thislen; | ||
123 | else | ||
124 | pos += thislen; | ||
125 | |||
126 | thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, | ||
127 | &(p[element].length), 1); | ||
128 | if (thislen < 0) | ||
129 | return thislen; | ||
130 | else | ||
131 | pos += thislen; | ||
132 | |||
133 | p[element].xyr = | ||
134 | (double **)lcm_malloc(sizeof(double *) * p[element].length); | ||
135 | { | ||
136 | int a; | ||
137 | for (a = 0; a < p[element].length; a++) { | ||
138 | p[element].xyr[a] = (double *)lcm_malloc(sizeof(double) * 3); | ||
139 | thislen = __double_decode_array(buf, offset + pos, maxlen - pos, | ||
140 | p[element].xyr[a], 3); | ||
141 | if (thislen < 0) | ||
142 | return thislen; | ||
143 | else | ||
144 | pos += thislen; | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | return pos; | ||
149 | } | ||
150 | |||
151 | int __path_t_decode_array_cleanup(path_t *p, int elements) { | ||
152 | int element; | ||
153 | for (element = 0; element < elements; element++) { | ||
154 | |||
155 | __int64_t_decode_array_cleanup(&(p[element].utime), 1); | ||
156 | |||
157 | __int16_t_decode_array_cleanup(&(p[element].length), 1); | ||
158 | |||
159 | { | ||
160 | int a; | ||
161 | for (a = 0; a < p[element].length; a++) { | ||
162 | __double_decode_array_cleanup(p[element].xyr[a], 3); | ||
163 | if (p[element].xyr[a]) | ||
164 | free(p[element].xyr[a]); | ||
165 | } | ||
166 | } | ||
167 | if (p[element].xyr) | ||
168 | free(p[element].xyr); | ||
169 | } | ||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | int path_t_decode(const void *buf, int offset, int maxlen, path_t *p) { | ||
174 | int pos = 0, thislen; | ||
175 | int64_t hash = __path_t_get_hash(); | ||
176 | |||
177 | int64_t this_hash; | ||
178 | thislen = | ||
179 | __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this_hash, 1); | ||
180 | if (thislen < 0) | ||
181 | return thislen; | ||
182 | else | ||
183 | pos += thislen; | ||
184 | if (this_hash != hash) | ||
185 | return -1; | ||
186 | |||
187 | thislen = __path_t_decode_array(buf, offset + pos, maxlen - pos, p, 1); | ||
188 | if (thislen < 0) | ||
189 | return thislen; | ||
190 | else | ||
191 | pos += thislen; | ||
192 | |||
193 | return pos; | ||
194 | } | ||
195 | |||
196 | int path_t_decode_cleanup(path_t *p) { | ||
197 | return __path_t_decode_array_cleanup(p, 1); | ||
198 | } | ||
199 | |||
200 | int __path_t_clone_array(const path_t *p, path_t *q, int elements) { | ||
201 | int element; | ||
202 | for (element = 0; element < elements; element++) { | ||
203 | |||
204 | __int64_t_clone_array(&(p[element].utime), &(q[element].utime), 1); | ||
205 | |||
206 | __int16_t_clone_array(&(p[element].length), &(q[element].length), 1); | ||
207 | |||
208 | q[element].xyr = | ||
209 | (double **)lcm_malloc(sizeof(double *) * q[element].length); | ||
210 | { | ||
211 | int a; | ||
212 | for (a = 0; a < p[element].length; a++) { | ||
213 | q[element].xyr[a] = (double *)lcm_malloc(sizeof(double) * 3); | ||
214 | __double_clone_array(p[element].xyr[a], q[element].xyr[a], 3); | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | path_t *path_t_copy(const path_t *p) { | ||
222 | path_t *q = (path_t *)malloc(sizeof(path_t)); | ||
223 | __path_t_clone_array(p, q, 1); | ||
224 | return q; | ||
225 | } | ||
226 | |||
227 | void path_t_destroy(path_t *p) { | ||
228 | __path_t_decode_array_cleanup(p, 1); | ||
229 | free(p); | ||
230 | } | ||
231 | |||
232 | int path_t_publish(lcm_t *lc, const char *channel, const path_t *p) { | ||
233 | int max_data_size = path_t_encoded_size(p); | ||
234 | uint8_t *buf = (uint8_t *)malloc(max_data_size); | ||
235 | if (!buf) | ||
236 | return -1; | ||
237 | int data_size = path_t_encode(buf, 0, max_data_size, p); | ||
238 | if (data_size < 0) { | ||
239 | free(buf); | ||
240 | return data_size; | ||
241 | } | ||
242 | int status = lcm_publish(lc, channel, buf, data_size); | ||
243 | free(buf); | ||
244 | return status; | ||
245 | } | ||
246 | |||
247 | struct _path_t_subscription_t { | ||
248 | path_t_handler_t user_handler; | ||
249 | void *userdata; | ||
250 | lcm_subscription_t *lc_h; | ||
251 | }; | ||
252 | static void path_t_handler_stub(const lcm_recv_buf_t *rbuf, const char *channel, | ||
253 | void *userdata) { | ||
254 | int status; | ||
255 | path_t p; | ||
256 | memset(&p, 0, sizeof(path_t)); | ||
257 | status = path_t_decode(rbuf->data, 0, rbuf->data_size, &p); | ||
258 | if (status < 0) { | ||
259 | fprintf(stderr, "error %d decoding path_t!!!\n", status); | ||
260 | return; | ||
261 | } | ||
262 | |||
263 | path_t_subscription_t *h = (path_t_subscription_t *)userdata; | ||
264 | h->user_handler(rbuf, channel, &p, h->userdata); | ||
265 | |||
266 | path_t_decode_cleanup(&p); | ||
267 | } | ||
268 | |||
269 | path_t_subscription_t *path_t_subscribe(lcm_t *lcm, const char *channel, | ||
270 | path_t_handler_t f, void *userdata) { | ||
271 | path_t_subscription_t *n = | ||
272 | (path_t_subscription_t *)malloc(sizeof(path_t_subscription_t)); | ||
273 | n->user_handler = f; | ||
274 | n->userdata = userdata; | ||
275 | n->lc_h = lcm_subscribe(lcm, channel, path_t_handler_stub, n); | ||
276 | if (n->lc_h == NULL) { | ||
277 | fprintf(stderr, "couldn't reg path_t LCM handler!\n"); | ||
278 | free(n); | ||
279 | return NULL; | ||
280 | } | ||
281 | return n; | ||
282 | } | ||
283 | |||
284 | int path_t_subscription_set_queue_capacity(path_t_subscription_t *subs, | ||
285 | int num_messages) { | ||
286 | return lcm_subscription_set_queue_capacity(subs->lc_h, num_messages); | ||
287 | } | ||
288 | |||
289 | int path_t_unsubscribe(lcm_t *lcm, path_t_subscription_t *hid) { | ||
290 | int status = lcm_unsubscribe(lcm, hid->lc_h); | ||
291 | if (0 != status) { | ||
292 | fprintf(stderr, "couldn't unsubscribe path_t_handler %p!\n", hid); | ||
293 | return -1; | ||
294 | } | ||
295 | free(hid); | ||
296 | return 0; | ||
297 | } | ||