diff options
Diffstat (limited to 'lcmtype/path_ctrl_t.c')
-rw-r--r-- | lcmtype/path_ctrl_t.c | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/lcmtype/path_ctrl_t.c b/lcmtype/path_ctrl_t.c new file mode 100644 index 0000000..2298a56 --- /dev/null +++ b/lcmtype/path_ctrl_t.c | |||
@@ -0,0 +1,241 @@ | |||
1 | // THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY | ||
2 | // BY HAND!! | ||
3 | // | ||
4 | // Generated by lcm-gen | ||
5 | |||
6 | #include <string.h> | ||
7 | #include "path_ctrl_t.h" | ||
8 | |||
9 | static int __path_ctrl_t_hash_computed; | ||
10 | static uint64_t __path_ctrl_t_hash; | ||
11 | |||
12 | uint64_t __path_ctrl_t_hash_recursive(const __lcm_hash_ptr *p) | ||
13 | { | ||
14 | const __lcm_hash_ptr *fp; | ||
15 | for (fp = p; fp != NULL; fp = fp->parent) | ||
16 | if (fp->v == __path_ctrl_t_get_hash) | ||
17 | return 0; | ||
18 | |||
19 | __lcm_hash_ptr cp; | ||
20 | cp.parent = p; | ||
21 | cp.v = (void*)__path_ctrl_t_get_hash; | ||
22 | (void) cp; | ||
23 | |||
24 | uint64_t hash = (uint64_t)0x5cf946463c463b9eLL | ||
25 | + __int8_t_hash_recursive(&cp) | ||
26 | + __int8_t_hash_recursive(&cp) | ||
27 | ; | ||
28 | |||
29 | return (hash<<1) + ((hash>>63)&1); | ||
30 | } | ||
31 | |||
32 | int64_t __path_ctrl_t_get_hash(void) | ||
33 | { | ||
34 | if (!__path_ctrl_t_hash_computed) { | ||
35 | __path_ctrl_t_hash = (int64_t)__path_ctrl_t_hash_recursive(NULL); | ||
36 | __path_ctrl_t_hash_computed = 1; | ||
37 | } | ||
38 | |||
39 | return __path_ctrl_t_hash; | ||
40 | } | ||
41 | |||
42 | int __path_ctrl_t_encode_array(void *buf, int offset, int maxlen, const path_ctrl_t *p, int elements) | ||
43 | { | ||
44 | int pos = 0, element; | ||
45 | int thislen; | ||
46 | |||
47 | for (element = 0; element < elements; element++) { | ||
48 | |||
49 | thislen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].cmd), 1); | ||
50 | if (thislen < 0) return thislen; else pos += thislen; | ||
51 | |||
52 | thislen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].speed), 1); | ||
53 | if (thislen < 0) return thislen; else pos += thislen; | ||
54 | |||
55 | } | ||
56 | return pos; | ||
57 | } | ||
58 | |||
59 | int path_ctrl_t_encode(void *buf, int offset, int maxlen, const path_ctrl_t *p) | ||
60 | { | ||
61 | int pos = 0, thislen; | ||
62 | int64_t hash = __path_ctrl_t_get_hash(); | ||
63 | |||
64 | thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1); | ||
65 | if (thislen < 0) return thislen; else pos += thislen; | ||
66 | |||
67 | thislen = __path_ctrl_t_encode_array(buf, offset + pos, maxlen - pos, p, 1); | ||
68 | if (thislen < 0) return thislen; else pos += thislen; | ||
69 | |||
70 | return pos; | ||
71 | } | ||
72 | |||
73 | int __path_ctrl_t_encoded_array_size(const path_ctrl_t *p, int elements) | ||
74 | { | ||
75 | int size = 0, element; | ||
76 | for (element = 0; element < elements; element++) { | ||
77 | |||
78 | size += __int8_t_encoded_array_size(&(p[element].cmd), 1); | ||
79 | |||
80 | size += __int8_t_encoded_array_size(&(p[element].speed), 1); | ||
81 | |||
82 | } | ||
83 | return size; | ||
84 | } | ||
85 | |||
86 | int path_ctrl_t_encoded_size(const path_ctrl_t *p) | ||
87 | { | ||
88 | return 8 + __path_ctrl_t_encoded_array_size(p, 1); | ||
89 | } | ||
90 | |||
91 | int __path_ctrl_t_decode_array(const void *buf, int offset, int maxlen, path_ctrl_t *p, int elements) | ||
92 | { | ||
93 | int pos = 0, thislen, element; | ||
94 | |||
95 | for (element = 0; element < elements; element++) { | ||
96 | |||
97 | thislen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].cmd), 1); | ||
98 | if (thislen < 0) return thislen; else pos += thislen; | ||
99 | |||
100 | thislen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].speed), 1); | ||
101 | if (thislen < 0) return thislen; else pos += thislen; | ||
102 | |||
103 | } | ||
104 | return pos; | ||
105 | } | ||
106 | |||
107 | int __path_ctrl_t_decode_array_cleanup(path_ctrl_t *p, int elements) | ||
108 | { | ||
109 | int element; | ||
110 | for (element = 0; element < elements; element++) { | ||
111 | |||
112 | __int8_t_decode_array_cleanup(&(p[element].cmd), 1); | ||
113 | |||
114 | __int8_t_decode_array_cleanup(&(p[element].speed), 1); | ||
115 | |||
116 | } | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | int path_ctrl_t_decode(const void *buf, int offset, int maxlen, path_ctrl_t *p) | ||
121 | { | ||
122 | int pos = 0, thislen; | ||
123 | int64_t hash = __path_ctrl_t_get_hash(); | ||
124 | |||
125 | int64_t this_hash; | ||
126 | thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this_hash, 1); | ||
127 | if (thislen < 0) return thislen; else pos += thislen; | ||
128 | if (this_hash != hash) return -1; | ||
129 | |||
130 | thislen = __path_ctrl_t_decode_array(buf, offset + pos, maxlen - pos, p, 1); | ||
131 | if (thislen < 0) return thislen; else pos += thislen; | ||
132 | |||
133 | return pos; | ||
134 | } | ||
135 | |||
136 | int path_ctrl_t_decode_cleanup(path_ctrl_t *p) | ||
137 | { | ||
138 | return __path_ctrl_t_decode_array_cleanup(p, 1); | ||
139 | } | ||
140 | |||
141 | int __path_ctrl_t_clone_array(const path_ctrl_t *p, path_ctrl_t *q, int elements) | ||
142 | { | ||
143 | int element; | ||
144 | for (element = 0; element < elements; element++) { | ||
145 | |||
146 | __int8_t_clone_array(&(p[element].cmd), &(q[element].cmd), 1); | ||
147 | |||
148 | __int8_t_clone_array(&(p[element].speed), &(q[element].speed), 1); | ||
149 | |||
150 | } | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | path_ctrl_t *path_ctrl_t_copy(const path_ctrl_t *p) | ||
155 | { | ||
156 | path_ctrl_t *q = (path_ctrl_t*) malloc(sizeof(path_ctrl_t)); | ||
157 | __path_ctrl_t_clone_array(p, q, 1); | ||
158 | return q; | ||
159 | } | ||
160 | |||
161 | void path_ctrl_t_destroy(path_ctrl_t *p) | ||
162 | { | ||
163 | __path_ctrl_t_decode_array_cleanup(p, 1); | ||
164 | free(p); | ||
165 | } | ||
166 | |||
167 | int path_ctrl_t_publish(lcm_t *lc, const char *channel, const path_ctrl_t *p) | ||
168 | { | ||
169 | int max_data_size = path_ctrl_t_encoded_size (p); | ||
170 | uint8_t *buf = (uint8_t*) malloc (max_data_size); | ||
171 | if (!buf) return -1; | ||
172 | int data_size = path_ctrl_t_encode (buf, 0, max_data_size, p); | ||
173 | if (data_size < 0) { | ||
174 | free (buf); | ||
175 | return data_size; | ||
176 | } | ||
177 | int status = lcm_publish (lc, channel, buf, data_size); | ||
178 | free (buf); | ||
179 | return status; | ||
180 | } | ||
181 | |||
182 | struct _path_ctrl_t_subscription_t { | ||
183 | path_ctrl_t_handler_t user_handler; | ||
184 | void *userdata; | ||
185 | lcm_subscription_t *lc_h; | ||
186 | }; | ||
187 | static | ||
188 | void path_ctrl_t_handler_stub (const lcm_recv_buf_t *rbuf, | ||
189 | const char *channel, void *userdata) | ||
190 | { | ||
191 | int status; | ||
192 | path_ctrl_t p; | ||
193 | memset(&p, 0, sizeof(path_ctrl_t)); | ||
194 | status = path_ctrl_t_decode (rbuf->data, 0, rbuf->data_size, &p); | ||
195 | if (status < 0) { | ||
196 | fprintf (stderr, "error %d decoding path_ctrl_t!!!\n", status); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | path_ctrl_t_subscription_t *h = (path_ctrl_t_subscription_t*) userdata; | ||
201 | h->user_handler (rbuf, channel, &p, h->userdata); | ||
202 | |||
203 | path_ctrl_t_decode_cleanup (&p); | ||
204 | } | ||
205 | |||
206 | path_ctrl_t_subscription_t* path_ctrl_t_subscribe (lcm_t *lcm, | ||
207 | const char *channel, | ||
208 | path_ctrl_t_handler_t f, void *userdata) | ||
209 | { | ||
210 | path_ctrl_t_subscription_t *n = (path_ctrl_t_subscription_t*) | ||
211 | malloc(sizeof(path_ctrl_t_subscription_t)); | ||
212 | n->user_handler = f; | ||
213 | n->userdata = userdata; | ||
214 | n->lc_h = lcm_subscribe (lcm, channel, | ||
215 | path_ctrl_t_handler_stub, n); | ||
216 | if (n->lc_h == NULL) { | ||
217 | fprintf (stderr,"couldn't reg path_ctrl_t LCM handler!\n"); | ||
218 | free (n); | ||
219 | return NULL; | ||
220 | } | ||
221 | return n; | ||
222 | } | ||
223 | |||
224 | int path_ctrl_t_subscription_set_queue_capacity (path_ctrl_t_subscription_t* subs, | ||
225 | int num_messages) | ||
226 | { | ||
227 | return lcm_subscription_set_queue_capacity (subs->lc_h, num_messages); | ||
228 | } | ||
229 | |||
230 | int path_ctrl_t_unsubscribe(lcm_t *lcm, path_ctrl_t_subscription_t* hid) | ||
231 | { | ||
232 | int status = lcm_unsubscribe (lcm, hid->lc_h); | ||
233 | if (0 != status) { | ||
234 | fprintf(stderr, | ||
235 | "couldn't unsubscribe path_ctrl_t_handler %p!\n", hid); | ||
236 | return -1; | ||
237 | } | ||
238 | free (hid); | ||
239 | return 0; | ||
240 | } | ||
241 | |||