Skip to content

Commit

Permalink
tools: ynl-gen: support code gen for events
Browse files Browse the repository at this point in the history
Netlink specs support both events and notifications (former can
define their own message contents). Plug in missing code to
generate types, parsers and include events into notification
tables.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jun 9, 2023
1 parent ced1568 commit 6da3424
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tools/net/ynl/lib/nlspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def _dictify_ops_directional(self):
self.fixed_header = self.yaml['operations'].get('fixed-header')
req_val = rsp_val = 1
for elem in self.yaml['operations']['list']:
if 'notify' in elem:
if 'notify' in elem or 'event' in elem:
if 'value' in elem:
rsp_val = elem['value']
req_val_next = req_val
Expand Down
17 changes: 12 additions & 5 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def _mock_up_events(self):
}

def _load_root_sets(self):
for op_name, op in self.ops.items():
for op_name, op in self.msgs.items():
if 'attribute-set' not in op:
continue

Expand All @@ -839,6 +839,8 @@ def _load_root_sets(self):
req_attrs.update(set(op[op_mode]['request']['attributes']))
if op_mode in op and 'reply' in op[op_mode]:
rsp_attrs.update(set(op[op_mode]['reply']['attributes']))
if 'event' in op:
rsp_attrs.update(set(op['event']['attributes']))

if op['attribute-set'] not in self.root_sets:
self.root_sets[op['attribute-set']] = {'request': req_attrs, 'reply': rsp_attrs}
Expand Down Expand Up @@ -2193,10 +2195,13 @@ def render_user_family(family, cw, prototype):
if family.ntfs:
cw.block_start(line=f"static const struct ynl_ntf_info {family['name']}_ntf_info[] = ")
for ntf_op_name, ntf_op in family.ntfs.items():
if 'notify' not in ntf_op:
continue
op = family.ops[ntf_op['notify']]
ri = RenderInfo(cw, family, "user", op, op.name, "notify")
if 'notify' in ntf_op:
op = family.ops[ntf_op['notify']]
ri = RenderInfo(cw, family, "user", op, op.name, "notify")
elif 'event' in ntf_op:
ri = RenderInfo(cw, family, "user", ntf_op, ntf_op_name, "event")
else:
raise Exception('Invalid notification ' + ntf_op_name)
_render_user_ntf_entry(ri, ntf_op)
for op_name, op in family.ops.items():
if 'event' not in op:
Expand Down Expand Up @@ -2424,6 +2429,7 @@ def main():
raise Exception(f'Only notifications with consistent types supported ({op.name})')
print_wrapped_type(ri)

for op_name, op in parsed.ntfs.items():
if 'event' in op:
ri = RenderInfo(cw, parsed, args.mode, op, op_name, 'event')
cw.p(f"/* {op.enum_name} - event */")
Expand Down Expand Up @@ -2485,6 +2491,7 @@ def main():
raise Exception(f'Only notifications with consistent types supported ({op.name})')
print_ntf_type_free(ri)

for op_name, op in parsed.ntfs.items():
if 'event' in op:
cw.p(f"/* {op.enum_name} - event */")

Expand Down

0 comments on commit 6da3424

Please sign in to comment.