aboutsummaryrefslogtreecommitdiffstats
path: root/lcmtype/path_ctrl_t.c
blob: 2298a569172f5995289631b522ce2db7541652bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// THIS IS AN AUTOMATICALLY GENERATED FILE.  DO NOT MODIFY
// BY HAND!!
//
// Generated by lcm-gen

#include <string.h>
#include "path_ctrl_t.h"

static int __path_ctrl_t_hash_computed;
static uint64_t __path_ctrl_t_hash;

uint64_t __path_ctrl_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_ctrl_t_get_hash)
            return 0;

    __lcm_hash_ptr cp;
    cp.parent =  p;
    cp.v = (void*)__path_ctrl_t_get_hash;
    (void) cp;

    uint64_t hash = (uint64_t)0x5cf946463c463b9eLL
         + __int8_t_hash_recursive(&cp)
         + __int8_t_hash_recursive(&cp)
        ;

    return (hash<<1) + ((hash>>63)&1);
}

int64_t __path_ctrl_t_get_hash(void)
{
    if (!__path_ctrl_t_hash_computed) {
        __path_ctrl_t_hash = (int64_t)__path_ctrl_t_hash_recursive(NULL);
        __path_ctrl_t_hash_computed = 1;
    }

    return __path_ctrl_t_hash;
}

int __path_ctrl_t_encode_array(void *buf, int offset, int maxlen, const path_ctrl_t *p, int elements)
{
    int pos = 0, element;
    int thislen;

    for (element = 0; element < elements; element++) {

        thislen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].cmd), 1);
        if (thislen < 0) return thislen; else pos += thislen;

        thislen = __int8_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].speed), 1);
        if (thislen < 0) return thislen; else pos += thislen;

    }
    return pos;
}

int path_ctrl_t_encode(void *buf, int offset, int maxlen, const path_ctrl_t *p)
{
    int pos = 0, thislen;
    int64_t hash = __path_ctrl_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_ctrl_t_encode_array(buf, offset + pos, maxlen - pos, p, 1);
    if (thislen < 0) return thislen; else pos += thislen;

    return pos;
}

int __path_ctrl_t_encoded_array_size(const path_ctrl_t *p, int elements)
{
    int size = 0, element;
    for (element = 0; element < elements; element++) {

        size += __int8_t_encoded_array_size(&(p[element].cmd), 1);

        size += __int8_t_encoded_array_size(&(p[element].speed), 1);

    }
    return size;
}

int path_ctrl_t_encoded_size(const path_ctrl_t *p)
{
    return 8 + __path_ctrl_t_encoded_array_size(p, 1);
}

int __path_ctrl_t_decode_array(const void *buf, int offset, int maxlen, path_ctrl_t *p, int elements)
{
    int pos = 0, thislen, element;

    for (element = 0; element < elements; element++) {

        thislen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].cmd), 1);
        if (thislen < 0) return thislen; else pos += thislen;

        thislen = __int8_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].speed), 1);
        if (thislen < 0) return thislen; else pos += thislen;

    }
    return pos;
}

int __path_ctrl_t_decode_array_cleanup(path_ctrl_t *p, int elements)
{
    int element;
    for (element = 0; element < elements; element++) {

        __int8_t_decode_array_cleanup(&(p[element].cmd), 1);

        __int8_t_decode_array_cleanup(&(p[element].speed), 1);

    }
    return 0;
}

int path_ctrl_t_decode(const void *buf, int offset, int maxlen, path_ctrl_t *p)
{
    int pos = 0, thislen;
    int64_t hash = __path_ctrl_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_ctrl_t_decode_array(buf, offset + pos, maxlen - pos, p, 1);
    if (thislen < 0) return thislen; else pos += thislen;

    return pos;
}

int path_ctrl_t_decode_cleanup(path_ctrl_t *p)
{
    return __path_ctrl_t_decode_array_cleanup(p, 1);
}

int __path_ctrl_t_clone_array(const path_ctrl_t *p, path_ctrl_t *q, int elements)
{
    int element;
    for (element = 0; element < elements; element++) {

        __int8_t_clone_array(&(p[element].cmd), &(q[element].cmd), 1);

        __int8_t_clone_array(&(p[element].speed), &(q[element].speed), 1);

    }
    return 0;
}

path_ctrl_t *path_ctrl_t_copy(const path_ctrl_t *p)
{
    path_ctrl_t *q = (path_ctrl_t*) malloc(sizeof(path_ctrl_t));
    __path_ctrl_t_clone_array(p, q, 1);
    return q;
}

void path_ctrl_t_destroy(path_ctrl_t *p)
{
    __path_ctrl_t_decode_array_cleanup(p, 1);
    free(p);
}

int path_ctrl_t_publish(lcm_t *lc, const char *channel, const path_ctrl_t *p)
{
      int max_data_size = path_ctrl_t_encoded_size (p);
      uint8_t *buf = (uint8_t*) malloc (max_data_size);
      if (!buf) return -1;
      int data_size = path_ctrl_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_ctrl_t_subscription_t {
    path_ctrl_t_handler_t user_handler;
    void *userdata;
    lcm_subscription_t *lc_h;
};
static
void path_ctrl_t_handler_stub (const lcm_recv_buf_t *rbuf,
                            const char *channel, void *userdata)
{
    int status;
    path_ctrl_t p;
    memset(&p, 0, sizeof(path_ctrl_t));
    status = path_ctrl_t_decode (rbuf->data, 0, rbuf->data_size, &p);
    if (status < 0) {
        fprintf (stderr, "error %d decoding path_ctrl_t!!!\n", status);
        return;
    }

    path_ctrl_t_subscription_t *h = (path_ctrl_t_subscription_t*) userdata;
    h->user_handler (rbuf, channel, &p, h->userdata);

    path_ctrl_t_decode_cleanup (&p);
}

path_ctrl_t_subscription_t* path_ctrl_t_subscribe (lcm_t *lcm,
                    const char *channel,
                    path_ctrl_t_handler_t f, void *userdata)
{
    path_ctrl_t_subscription_t *n = (path_ctrl_t_subscription_t*)
                       malloc(sizeof(path_ctrl_t_subscription_t));
    n->user_handler = f;
    n->userdata = userdata;
    n->lc_h = lcm_subscribe (lcm, channel,
                                 path_ctrl_t_handler_stub, n);
    if (n->lc_h == NULL) {
        fprintf (stderr,"couldn't reg path_ctrl_t LCM handler!\n");
        free (n);
        return NULL;
    }
    return n;
}

int path_ctrl_t_subscription_set_queue_capacity (path_ctrl_t_subscription_t* subs,
                              int num_messages)
{
    return lcm_subscription_set_queue_capacity (subs->lc_h, num_messages);
}

int path_ctrl_t_unsubscribe(lcm_t *lcm, path_ctrl_t_subscription_t* hid)
{
    int status = lcm_unsubscribe (lcm, hid->lc_h);
    if (0 != status) {
        fprintf(stderr,
           "couldn't unsubscribe path_ctrl_t_handler %p!\n", hid);
        return -1;
    }
    free (hid);
    return 0;
}