Lines Matching refs:ri

95     def _complex_member_type(self, ri):  argument
101 def free(self, ri, var, ref): argument
103 ri.cw.p(f'free({var}->{ref}{self.c_name});')
105 def arg_member(self, ri): argument
106 member = self._complex_member_type(ri)
114 def struct_member(self, ri): argument
116 ri.cw.p(f"unsigned int n_{self.c_name};")
117 member = self._complex_member_type(ri)
120 ri.cw.p(f"{member} {ptr}{self.c_name};")
122 members = self.arg_member(ri)
124 ri.cw.p(one + ';')
142 def _attr_put_line(self, ri, var, line): argument
144 ri.cw.p(f"if ({var}->_present.{self.c_name})")
146 ri.cw.p(f"if ({var}->_present.{self.c_name}_len)")
147 ri.cw.p(f"{line};")
149 def _attr_put_simple(self, ri, var, put_type): argument
151 self._attr_put_line(ri, var, line)
153 def attr_put(self, ri, var): argument
156 def _attr_get(self, ri, var): argument
159 def attr_get(self, ri, var, first): argument
160 lines, init_lines, local_vars = self._attr_get(ri, var)
167 ri.cw.block_start(line=f"{kw} (type == {self.enum_name})")
170 ri.cw.p(local)
171 ri.cw.nl()
174 ri.cw.p("if (ynl_attr_validate(yarg, attr))")
175 ri.cw.p("return MNL_CB_ERROR;")
177 ri.cw.p(f"{var}->_present.{self.c_name} = 1;")
180 ri.cw.nl()
182 ri.cw.p(line)
185 ri.cw.p(line)
186 ri.cw.block_end()
189 def _setter_lines(self, ri, member, presence): argument
192 def setter(self, ri, space, direction, deref=False, ref=None): argument
206 code += self._setter_lines(ri, member, presence)
213 ri.cw.write_func('static inline void', func_name, body=code,
214 … args=[f'{type_name(ri, direction, deref=deref)} *{var}'] + self.arg_member(ri))
221 def arg_member(self, ri): argument
224 def _attr_get(self, ri, var): argument
238 def arg_member(self, ri): argument
244 def attr_put(self, ri, var): argument
247 def attr_get(self, ri, var, first): argument
253 def setter(self, ri, space, direction, deref=False, ref=None): argument
317 def arg_member(self, ri): argument
320 def attr_put(self, ri, var): argument
321 self._attr_put_simple(ri, var, self._mnl_type())
323 def _attr_get(self, ri, var): argument
326 def _setter_lines(self, ri, member, presence): argument
331 def arg_member(self, ri): argument
337 def attr_put(self, ri, var): argument
338 self._attr_put_line(ri, var, f"mnl_attr_put(nlh, {self.enum_name}, 0, NULL)")
340 def _attr_get(self, ri, var): argument
343 def _setter_lines(self, ri, member, presence): argument
348 def arg_member(self, ri): argument
354 def struct_member(self, ri): argument
355 ri.cw.p(f"char *{self.c_name};")
376 def attr_put(self, ri, var): argument
377 self._attr_put_simple(ri, var, 'strz')
379 def _attr_get(self, ri, var): argument
388 def _setter_lines(self, ri, member, presence): argument
397 def arg_member(self, ri): argument
403 def struct_member(self, ri): argument
404 ri.cw.p(f"void *{self.c_name};")
420 def attr_put(self, ri, var): argument
421 self._attr_put_line(ri, var, f"mnl_attr_put(nlh, {self.enum_name}, " +
424 def _attr_get(self, ri, var): argument
432 def _setter_lines(self, ri, member, presence): argument
440 def _complex_member_type(self, ri): argument
443 def free(self, ri, var, ref): argument
444 ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name});')
452 def attr_put(self, ri, var): argument
453 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
456 def _attr_get(self, ri, var): argument
463 def setter(self, ri, space, direction, deref=False, ref=None): argument
466 for _, attr in ri.family.pure_nested_structs[self.nested_attrs].member_list():
467 attr.setter(ri, self.nested_attrs, direction, deref=deref, ref=ref)
489 def _complex_member_type(self, ri): argument
493 scalar_pfx = '__' if ri.ku_space == 'user' else ''
501 def free(self, ri, var, ref): argument
503 ri.cw.p(f"free({var}->{ref}{self.c_name});")
505 ri.cw.p(f"for (i = 0; i < {var}->{ref}n_{self.c_name}; i++)")
506 ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name}[i]);')
507 ri.cw.p(f"free({var}->{ref}{self.c_name});")
517 def _attr_get(self, ri, var): argument
520 def attr_put(self, ri, var): argument
523 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
524 ri.cw.p(f"mnl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
526 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
527 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
532 def _setter_lines(self, ri, member, presence): argument
547 def _complex_member_type(self, ri): argument
551 scalar_pfx = '__' if ri.ku_space == 'user' else ''
559 def _attr_get(self, ri, var): argument
568 def _complex_member_type(self, ri): argument
574 def _attr_get(self, ri, var): argument
1286 def op_prefix(ri, direction, deref=False): argument
1289 if not ri.op_mode or ri.op_mode == 'do':
1295 if ri.type_consistent:
1299 suffix += op_mode_to_wrapper[ri.op_mode]
1307 def type_name(ri, direction, deref=False): argument
1311 def print_prototype(ri, direction, terminate=True, doc=None): argument
1314 fname = ri.op.render_name
1315 if ri.op_mode == 'dump':
1319 if 'request' in ri.op[ri.op_mode]:
1323 if 'reply' in ri.op[ri.op_mode]:
1326 ri.cw.write_func_prot(ret, fname, args, doc=doc, suffix=suffix)
1329 def print_req_prototype(ri): argument
1330 print_prototype(ri, "request", doc=ri.op['doc'])
1333 def print_dump_prototype(ri): argument
1334 print_prototype(ri, "request")
1406 def put_req_nested(ri, struct): argument
1411 ri.cw.write_func_prot('int', f'{struct.render_name}_put', func_args)
1412 ri.cw.block_start()
1413 ri.cw.write_func_lvar('struct nlattr *nest;')
1415 ri.cw.p("nest = mnl_attr_nest_start(nlh, attr_type);")
1418 arg.attr_put(ri, "obj")
1420 ri.cw.p("mnl_attr_nest_end(nlh, nest);")
1422 ri.cw.nl()
1423 ri.cw.p('return 0;')
1424 ri.cw.block_end()
1425 ri.cw.nl()
1428 def _multi_parse(ri, struct, init_lines, local_vars): argument
1455 ri.cw.block_start()
1456 ri.cw.write_func_lvar(local_vars)
1459 ri.cw.p(line)
1460 ri.cw.nl()
1463 ri.cw.p(f'dst->{arg} = {arg};')
1467 ri.cw.p(f"if (dst->{aspec.c_name})")
1468ri.cw.p(f'return ynl_error_parse(yarg, "attribute already present ({struct.attr_set.name}.{aspec.n…
1470 ri.cw.nl()
1471 ri.cw.block_start(line=iter_line)
1472 ri.cw.p('unsigned int type = mnl_attr_get_type(attr);')
1473 ri.cw.nl()
1477 good = arg.attr_get(ri, 'dst', first=first)
1481 ri.cw.block_end()
1482 ri.cw.nl()
1487 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
1488 ri.cw.p(f"dst->{aspec.c_name} = calloc({aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1489 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1490 ri.cw.p('i = 0;')
1491 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
1492 ri.cw.block_start(line=f"mnl_attr_for_each_nested(attr, attr_{aspec.c_name})")
1493 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1494 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, mnl_attr_get_type(attr)))")
1495 ri.cw.p('return MNL_CB_ERROR;')
1496 ri.cw.p('i++;')
1497 ri.cw.block_end()
1498 ri.cw.block_end()
1499 ri.cw.nl()
1503 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
1504 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1505 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1506 ri.cw.p('i = 0;')
1508 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
1509 ri.cw.block_start(line=iter_line)
1510 ri.cw.block_start(line=f"if (mnl_attr_get_type(attr) == {aspec.enum_name})")
1512 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1513 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr))")
1514 ri.cw.p('return MNL_CB_ERROR;')
1519 ri.cw.p(f"dst->{aspec.c_name}[i] = mnl_attr_get_{t}(attr);")
1522 ri.cw.p('i++;')
1523 ri.cw.block_end()
1524 ri.cw.block_end()
1525 ri.cw.block_end()
1526 ri.cw.nl()
1529 ri.cw.p('return 0;')
1531 ri.cw.p('return MNL_CB_OK;')
1532 ri.cw.block_end()
1533 ri.cw.nl()
1536 def parse_rsp_nested(ri, struct): argument
1546 ri.cw.write_func_prot('int', f'{struct.render_name}_parse', func_args)
1548 _multi_parse(ri, struct, init_lines, local_vars)
1551 def parse_rsp_msg(ri, deref=False): argument
1552 if 'reply' not in ri.op[ri.op_mode] and ri.op_mode != 'event':
1563 ri.cw.write_func_prot('int', f'{op_prefix(ri, "reply", deref=deref)}_parse', func_args)
1565 if ri.struct["reply"].member_list():
1566 _multi_parse(ri, ri.struct["reply"], init_lines, local_vars)
1569 ri.cw.block_start()
1570 ri.cw.p('return MNL_CB_OK;')
1571 ri.cw.block_end()
1572 ri.cw.nl()
1575 def print_req(ri): argument
1582 if 'reply' in ri.op[ri.op_mode]:
1588 print_prototype(ri, direction, terminate=False)
1589 ri.cw.block_start()
1590 ri.cw.write_func_lvar(local_vars)
1592 ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1594 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
1595 if 'reply' in ri.op[ri.op_mode]:
1596 ri.cw.p(f"yrs.yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
1597 ri.cw.nl()
1598 for _, attr in ri.struct["request"].member_list():
1599 attr.attr_put(ri, "req")
1600 ri.cw.nl()
1603 if 'reply' in ri.op[ri.op_mode]:
1604 ri.cw.p('rsp = calloc(1, sizeof(*rsp));')
1605 ri.cw.p('yrs.yarg.data = rsp;')
1606 ri.cw.p(f"yrs.cb = {op_prefix(ri, 'reply')}_parse;")
1607 if ri.op.value is not None:
1608 ri.cw.p(f'yrs.rsp_cmd = {ri.op.enum_name};')
1610 ri.cw.p(f'yrs.rsp_cmd = {ri.op.rsp_value};')
1611 ri.cw.nl()
1613 ri.cw.p(f"err = ynl_exec(ys, nlh, {parse_arg});")
1614 ri.cw.p('if (err < 0)')
1615 if 'reply' in ri.op[ri.op_mode]:
1616 ri.cw.p('goto err_free;')
1618 ri.cw.p('return -1;')
1619 ri.cw.nl()
1621 ri.cw.p(f"return {ret_ok};")
1622 ri.cw.nl()
1624 if 'reply' in ri.op[ri.op_mode]:
1625 ri.cw.p('err_free:')
1626 ri.cw.p(f"{call_free(ri, rdir(direction), 'rsp')}")
1627 ri.cw.p(f"return {ret_err};")
1629 ri.cw.block_end()
1632 def print_dump(ri): argument
1634 print_prototype(ri, direction, terminate=False)
1635 ri.cw.block_start()
1641 ri.cw.p(f'{var}')
1642 ri.cw.nl()
1644 ri.cw.p('yds.ys = ys;')
1645 ri.cw.p(f"yds.alloc_sz = sizeof({type_name(ri, rdir(direction))});")
1646 ri.cw.p(f"yds.cb = {op_prefix(ri, 'reply', deref=True)}_parse;")
1647 if ri.op.value is not None:
1648 ri.cw.p(f'yds.rsp_cmd = {ri.op.enum_name};')
1650 ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};')
1651 ri.cw.p(f"yds.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
1652 ri.cw.nl()
1653 ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1655 if "request" in ri.op[ri.op_mode]:
1656 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
1657 ri.cw.nl()
1658 for _, attr in ri.struct["request"].member_list():
1659 attr.attr_put(ri, "req")
1660 ri.cw.nl()
1662 ri.cw.p('err = ynl_exec_dump(ys, nlh, &yds);')
1663 ri.cw.p('if (err < 0)')
1664 ri.cw.p('goto free_list;')
1665 ri.cw.nl()
1667 ri.cw.p('return yds.first;')
1668 ri.cw.nl()
1669 ri.cw.p('free_list:')
1670 ri.cw.p(call_free(ri, rdir(direction), 'yds.first'))
1671 ri.cw.p('return NULL;')
1672 ri.cw.block_end()
1675 def call_free(ri, direction, var): argument
1685 def print_alloc_wrapper(ri, direction): argument
1686 name = op_prefix(ri, direction)
1687 ri.cw.write_func_prot(f'static inline struct {name} *', f"{name}_alloc", [f"void"])
1688 ri.cw.block_start()
1689 ri.cw.p(f'return calloc(1, sizeof(struct {name}));')
1690 ri.cw.block_end()
1693 def print_free_prototype(ri, direction, suffix=';'): argument
1694 name = op_prefix(ri, direction)
1696 if ri.type_name_conflict:
1699 ri.cw.write_func_prot('void', f"{name}_free", [f"struct {struct_name} *{arg}"], suffix=suffix)
1702 def _print_type(ri, direction, struct): argument
1704 if not direction and ri.type_name_conflict:
1707 if ri.op_mode == 'dump':
1710 ri.cw.block_start(line=f"struct {ri.family['name']}{suffix}")
1715 line = attr.presence_member(ri.ku_space, type_filter)
1718 ri.cw.block_start(line=f"struct")
1720 ri.cw.p(line)
1722 ri.cw.block_end(line='_present;')
1723 ri.cw.nl()
1726 ri.cw.p(f"__u32 {arg};")
1729 attr.struct_member(ri)
1731 ri.cw.block_end(line=';')
1732 ri.cw.nl()
1735 def print_type(ri, direction): argument
1736 _print_type(ri, direction, ri.struct[direction])
1739 def print_type_full(ri, struct): argument
1740 _print_type(ri, "", struct)
1743 def print_type_helpers(ri, direction, deref=False): argument
1744 print_free_prototype(ri, direction)
1745 ri.cw.nl()
1747 if ri.ku_space == 'user' and direction == 'request':
1748 for _, attr in ri.struct[direction].member_list():
1749 attr.setter(ri, ri.attr_set, direction, deref=deref)
1750 ri.cw.nl()
1753 def print_req_type_helpers(ri): argument
1754 print_alloc_wrapper(ri, "request")
1755 print_type_helpers(ri, "request")
1758 def print_rsp_type_helpers(ri): argument
1759 if 'reply' not in ri.op[ri.op_mode]:
1761 print_type_helpers(ri, "reply")
1764 def print_parse_prototype(ri, direction, terminate=True): argument
1768 ri.cw.write_func_prot('void', f"{ri.op.render_name}{suffix}_parse",
1774 def print_req_type(ri): argument
1775 print_type(ri, "request")
1778 def print_req_free(ri): argument
1779 if 'request' not in ri.op[ri.op_mode]:
1781 _free_type(ri, 'request', ri.struct['request'])
1784 def print_rsp_type(ri): argument
1785 if (ri.op_mode == 'do' or ri.op_mode == 'dump') and 'reply' in ri.op[ri.op_mode]:
1787 elif ri.op_mode == 'event':
1791 print_type(ri, direction)
1794 def print_wrapped_type(ri): argument
1795 ri.cw.block_start(line=f"{type_name(ri, 'reply')}")
1796 if ri.op_mode == 'dump':
1797 ri.cw.p(f"{type_name(ri, 'reply')} *next;")
1798 elif ri.op_mode == 'notify' or ri.op_mode == 'event':
1799 ri.cw.p('__u16 family;')
1800 ri.cw.p('__u8 cmd;')
1801 ri.cw.p('struct ynl_ntf_base_type *next;')
1802 ri.cw.p(f"void (*free)({type_name(ri, 'reply')} *ntf);")
1803 ri.cw.p(f"{type_name(ri, 'reply', deref=True)} obj __attribute__ ((aligned (8)));")
1804 ri.cw.block_end(line=';')
1805 ri.cw.nl()
1806 print_free_prototype(ri, 'reply')
1807 ri.cw.nl()
1810 def _free_type_members_iter(ri, struct): argument
1813 ri.cw.p('unsigned int i;')
1814 ri.cw.nl()
1818 def _free_type_members(ri, var, struct, ref=''): argument
1820 attr.free(ri, var, ref)
1823 def _free_type(ri, direction, struct): argument
1826 print_free_prototype(ri, direction, suffix='')
1827 ri.cw.block_start()
1828 _free_type_members_iter(ri, struct)
1829 _free_type_members(ri, var, struct)
1831 ri.cw.p(f'free({var});')
1832 ri.cw.block_end()
1833 ri.cw.nl()
1836 def free_rsp_nested(ri, struct): argument
1837 _free_type(ri, "", struct)
1840 def print_rsp_free(ri): argument
1841 if 'reply' not in ri.op[ri.op_mode]:
1843 _free_type(ri, 'reply', ri.struct['reply'])
1846 def print_dump_type_free(ri): argument
1847 sub_type = type_name(ri, 'reply')
1849 print_free_prototype(ri, 'reply', suffix='')
1850 ri.cw.block_start()
1851 ri.cw.p(f"{sub_type} *next = rsp;")
1852 ri.cw.nl()
1853 ri.cw.block_start(line='while ((void *)next != YNL_LIST_END)')
1854 _free_type_members_iter(ri, ri.struct['reply'])
1855 ri.cw.p('rsp = next;')
1856 ri.cw.p('next = rsp->next;')
1857 ri.cw.nl()
1859 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
1860 ri.cw.p(f'free(rsp);')
1861 ri.cw.block_end()
1862 ri.cw.block_end()
1863 ri.cw.nl()
1866 def print_ntf_type_free(ri): argument
1867 print_free_prototype(ri, 'reply', suffix='')
1868 ri.cw.block_start()
1869 _free_type_members_iter(ri, ri.struct['reply'])
1870 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
1871 ri.cw.p(f'free(rsp);')
1872 ri.cw.block_end()
1873 ri.cw.nl()
1876 def print_req_policy_fwd(cw, struct, ri=None, terminate=True): argument
1877 if terminate and ri and policy_should_be_static(struct.family):
1883 if ri and policy_should_be_static(struct.family):
1891 if ri:
1892 name = ri.op.render_name
1893 if ri.op.dual_policy:
1894 name += '_' + ri.op_mode
1900 def print_req_policy(cw, struct, ri=None): argument
1901 print_req_policy_fwd(cw, struct, ri=ri, terminate=False)
2275 def _render_user_ntf_entry(ri, op): argument
2276 ri.cw.block_start(line=f"[{op.enum_name}] = ")
2277 ri.cw.p(f".alloc_sz\t= sizeof({type_name(ri, 'event')}),")
2278 ri.cw.p(f".cb\t\t= {op_prefix(ri, 'reply', deref=True)}_parse,")
2279 ri.cw.p(f".policy\t\t= &{ri.struct['reply'].render_name}_nest,")
2280 ri.cw.p(f".free\t\t= (void *){op_prefix(ri, 'notify')}_free,")
2281 ri.cw.block_end(line=',')
2295 ri = RenderInfo(cw, family, "user", op, "notify")
2297 ri = RenderInfo(cw, family, "user", ntf_op, "event")
2300 _render_user_ntf_entry(ri, ntf_op)
2304 ri = RenderInfo(cw, family, "user", op, "event")
2305 _render_user_ntf_entry(ri, op)
2447 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2448 print_req_policy_fwd(cw, ri.struct['request'], ri=ri)
2476 ri = RenderInfo(cw, parsed, args.mode, op, op_mode)
2477 print_req_policy(cw, ri.struct['request'], ri=ri)
2496 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
2497 print_type_full(ri, struct)
2504 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2505 print_req_type(ri)
2506 print_req_type_helpers(ri)
2508 print_rsp_type(ri)
2509 print_rsp_type_helpers(ri)
2511 print_req_prototype(ri)
2516 ri = RenderInfo(cw, parsed, args.mode, op, 'dump')
2518 print_req_type(ri)
2519 print_req_type_helpers(ri)
2520 if not ri.type_consistent:
2521 print_rsp_type(ri)
2522 print_wrapped_type(ri)
2523 print_dump_prototype(ri)
2528 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
2529 if not ri.type_consistent:
2531 print_wrapped_type(ri)
2535 ri = RenderInfo(cw, parsed, args.mode, op, 'event')
2537 print_rsp_type(ri)
2539 print_wrapped_type(ri)
2560 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
2562 free_rsp_nested(ri, struct)
2564 put_req_nested(ri, struct)
2566 parse_rsp_nested(ri, struct)
2572 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2573 print_req_free(ri)
2574 print_rsp_free(ri)
2575 parse_rsp_msg(ri)
2576 print_req(ri)
2581 ri = RenderInfo(cw, parsed, args.mode, op, "dump")
2582 if not ri.type_consistent:
2583 parse_rsp_msg(ri, deref=True)
2584 print_dump_type_free(ri)
2585 print_dump(ri)
2590 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
2591 if not ri.type_consistent:
2593 print_ntf_type_free(ri)
2599 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2600 parse_rsp_msg(ri)
2602 ri = RenderInfo(cw, parsed, args.mode, op, "event")
2603 print_ntf_type_free(ri)