-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhandlers.cpp
More file actions
120 lines (72 loc) · 2.97 KB
/
Copy pathhandlers.cpp
File metadata and controls
120 lines (72 loc) · 2.97 KB
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
// Handler functions
@ for device_type in graph_type['device_types']
@ set device_class = get_device_class(device_type['id'])
@ set state_class = get_state_class(graph_type["id"], device_type['id'])
@ set props_class = get_props_class(graph_type["id"], device_type['id'])
{% macro include_handler_defs() %}
{{ state_class }}* deviceState = &state;
{{ props_class }}* deviceProperties = &props;
{% endmacro %}
{% macro include_rts_constants() %}
@ for out_pin in device_type['output_pins']
@ set RTS_FLAG = get_rts_flag_variable(out_pin['name'])
@ set RTS_FLAG_OBSOLETE = get_rts_flag_obsolete_variable(device_type['id'], out_pin['name'])
const int {{ RTS_FLAG }} = 1 << {{ loop.index0 }};
const int {{ RTS_FLAG_OBSOLETE }} = 1 << {{ loop.index0 }};
@ endfor
{% endmacro %}
void {{ device_class }}::receive(int pin_id, msg_t *msg) {
{{ include_handler_defs() }}
{{ include_rts_constants() }}
@ for pin in device_type['input_pins']
if (pin_id == {{ loop.index0 }}) {
@ set msg_class = get_msg_class(graph_type["id"], pin['message_type'])
{{ msg_class }} *message = ({{ msg_class }}*) msg;
{{ pin['on_receive'] or "// no handler code" }}
compute_rts();
return;
}
@ endfor
}
msg_t* {{ device_class }}::send(int pin_id) {
{{ include_handler_defs() }}
{{ include_rts_constants() }}
@ for pin in device_type['output_pins']
if (pin_id == {{ loop.index0 }}) {
@ set msg_class = get_msg_class(graph_type["id"], pin['message_type'])
{{ msg_class }} *message = new {{ msg_class }}();
{{ pin['on_send'] or "// no handler code" }}
compute_rts();
return message;
}
@ endfor
}
msg_t* {{ device_class }}::generate_output_msg(int pin_id, int* fields) {
// Generate an output message using given an output port id and an
// array of message fields.
@ for pin in device_type['output_pins']
@ set msg_class = get_msg_class(graph_type["id"], pin['message_type'])
if (pin_id == {{ loop.index0 }})
return new {{ msg_class }}(fields);
@ endfor
}
void {{ device_class }}::init() {
@ set init_pin = schema.get_pin(device_type['id'], '__init__')
{{ include_handler_defs() }}
{{ include_rts_constants() }}
{{ init_pin['on_receive'] if init_pin else '' }}
compute_rts();
}
void {{ device_class }}::compute_rts() {
int* readyToSend = &rts;
{{ include_handler_defs() }}
{{ include_rts_constants() }}
{{ device_type['ready_to_send'] or "// no handler code" }}
}
int {{ device_class }}::get_rts() {
return rts;
}
void {{ device_class }}::print() {
state.print();
}
@ endfor