forked from PDXostc/vehicle_signal_distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsd_internal.h
129 lines (99 loc) · 4.19 KB
/
vsd_internal.h
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
// Copyright (C) 2018, Jaguar Land Rover
// This program is licensed under the terms and conditions of the
// Mozilla Public License, version 2.0. The full text of the
// Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
//
// Author: Magnus Feuer ([email protected])
//
#include <stdint.h>
#include <rmc_list.h>
#include "uthash.h"
#include "dstc.h"
#define vsd_data_u_nil ({ vsd_data_u res = {0}; res; })
struct vsd_desc;
RMC_LIST(vsd_subscriber_list, vsd_subscriber_node, vsd_subscriber_cb_t)
typedef vsd_subscriber_list vsd_subscriber_list_t;
typedef vsd_subscriber_node vsd_subscriber_node_t;
typedef struct vsd_desc {
vsd_elem_type_e elem_type;
vsd_data_type_e data_type;
vsd_id_t id;
char* name;
char* description;
struct vsd_desc_branch* parent;
UT_hash_handle hh; // Make this struct hashable. https://troydhanson.github.io/uthash/
// Subscribers can subscribe to any part of the tree, getting
// a callback whenever one or more nodes in the tree have been updated.
vsd_subscriber_list subscribers;
} vsd_desc_t;
typedef struct vsd_desc_branch {
vsd_desc_t base;
vsd_desc_list_t children;
} vsd_desc_branch_t;
typedef struct vsd_desc_leaf {
vsd_desc_t base;
vsd_data_u min;
vsd_data_u max;
vsd_data_u val;
} vsd_desc_leaf_t;
RMC_LIST(vsd_enum_list, vsd_enum_node, vsd_data_u)
typedef vsd_enum_list vsd_enum_list_t;
typedef vsd_enum_node vsd_enum_node_t;
typedef struct vsd_desc_enum {
vsd_desc_leaf_t leaf;
vsd_enum_list_t enums;
} vsd_desc_enum_t;
typedef struct vsd_context {
vsd_desc_branch_t* root;
vsd_desc_t* hash_table; // Hashed on id
} vsd_context_t;
extern int vsd_desc_init(vsd_context_t* ctx,
vsd_desc_t* desc,
vsd_elem_type_e elem_type,
vsd_data_type_e data_type,
vsd_desc_branch_t* parent,
vsd_id_t id,
char* name,
char* description);
extern int vsd_desc_create_branch(vsd_context_t* ctx,
vsd_desc_branch_t** res,
char* name,
vsd_id_t id,
char* description,
vsd_desc_branch_t* parent);
extern int vsd_desc_create_leaf(vsd_context_t* ctx,
vsd_desc_leaf_t** res,
vsd_elem_type_e elem_type,
vsd_data_type_e data_type,
vsd_id_t id,
char* name,
char* description,
vsd_desc_branch_t* parent,
vsd_data_u min,
vsd_data_u max,
vsd_data_u val);
extern int vsd_desc_create_enum(vsd_context_t* ctx,
vsd_desc_enum_t** res,
vsd_elem_type_e elem_type,
vsd_data_type_e data_type,
vsd_id_t id,
char* name,
char* description,
vsd_desc_branch_t* parent,
vsd_data_u* enums, // Array of allowed values.
int enum_count,
vsd_data_u val);
extern int vsd_desc_delete(vsd_context_t* context, vsd_desc_t* desc);
extern int vsd_context_init(vsd_context_t* ctx);
extern int vsd_string_to_data(vsd_data_type_e type,
char* str,
vsd_data_u* res);
extern int vsd_publish(vsd_desc_t* desc);
extern int vsd_subscribe(vsd_context_t* ctx,
vsd_desc_t* desc,
vsd_subscriber_cb_t callback);
extern int vsd_unsubscribe(vsd_context_t* ctx,
vsd_desc_t* desc,
vsd_subscriber_cb_t callback);
extern void signal_transmit(vsd_id_t id, dstc_dynamic_data_t dynarg);
extern int vsd_transmit(vsd_id_t id, dstc_dynamic_data_t dynarg);