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
203 code += self._setter_lines(ri, member, presence)
210 ri.cw.write_func('static inline void', func_name, body=code,
211 … args=[f'{type_name(ri, direction, deref=deref)} *{var}'] + self.arg_member(ri))
218 def arg_member(self, ri): argument
221 def _attr_get(self, ri, var): argument
235 def arg_member(self, ri): argument
241 def attr_put(self, ri, var): argument
244 def attr_get(self, ri, var, first): argument
250 def setter(self, ri, space, direction, deref=False, ref=None): argument
314 def arg_member(self, ri): argument
317 def attr_put(self, ri, var): argument
318 self._attr_put_simple(ri, var, self._mnl_type())
320 def _attr_get(self, ri, var): argument
323 def _setter_lines(self, ri, member, presence): argument
328 def arg_member(self, ri): argument
334 def attr_put(self, ri, var): argument
335 self._attr_put_line(ri, var, f"mnl_attr_put(nlh, {self.enum_name}, 0, NULL)")
337 def _attr_get(self, ri, var): argument
340 def _setter_lines(self, ri, member, presence): argument
345 def arg_member(self, ri): argument
351 def struct_member(self, ri): argument
352 ri.cw.p(f"char *{self.c_name};")
373 def attr_put(self, ri, var): argument
374 self._attr_put_simple(ri, var, 'strz')
376 def _attr_get(self, ri, var): argument
385 def _setter_lines(self, ri, member, presence): argument
394 def arg_member(self, ri): argument
400 def struct_member(self, ri): argument
401 ri.cw.p(f"void *{self.c_name};")
417 def attr_put(self, ri, var): argument
418 self._attr_put_line(ri, var, f"mnl_attr_put(nlh, {self.enum_name}, " +
421 def _attr_get(self, ri, var): argument
429 def _setter_lines(self, ri, member, presence): argument
437 def _complex_member_type(self, ri): argument
440 def free(self, ri, var, ref): argument
441 ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name});')
449 def attr_put(self, ri, var): argument
450 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
453 def _attr_get(self, ri, var): argument
460 def setter(self, ri, space, direction, deref=False, ref=None): argument
463 for _, attr in ri.family.pure_nested_structs[self.nested_attrs].member_list():
464 attr.setter(ri, self.nested_attrs, direction, deref=deref, ref=ref)
486 def _complex_member_type(self, ri): argument
490 scalar_pfx = '__' if ri.ku_space == 'user' else ''
498 def free(self, ri, var, ref): argument
500 ri.cw.p(f"free({var}->{ref}{self.c_name});")
502 ri.cw.p(f"for (i = 0; i < {var}->{ref}n_{self.c_name}; i++)")
503 ri.cw.p(f'{self.nested_render_name}_free(&{var}->{ref}{self.c_name}[i]);')
504 ri.cw.p(f"free({var}->{ref}{self.c_name});")
514 def _attr_get(self, ri, var): argument
517 def attr_put(self, ri, var): argument
520 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
521 ri.cw.p(f"mnl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
523 ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
524 self._attr_put_line(ri, var, f"{self.nested_render_name}_put(nlh, " +
529 def _setter_lines(self, ri, member, presence): argument
544 def _complex_member_type(self, ri): argument
548 scalar_pfx = '__' if ri.ku_space == 'user' else ''
556 def _attr_get(self, ri, var): argument
565 def _complex_member_type(self, ri): argument
571 def _attr_get(self, ri, var): argument
1283 def op_prefix(ri, direction, deref=False): argument
1286 if not ri.op_mode or ri.op_mode == 'do':
1292 if ri.type_consistent:
1296 suffix += op_mode_to_wrapper[ri.op_mode]
1304 def type_name(ri, direction, deref=False): argument
1308 def print_prototype(ri, direction, terminate=True, doc=None): argument
1311 fname = ri.op.render_name
1312 if ri.op_mode == 'dump':
1316 if 'request' in ri.op[ri.op_mode]:
1320 if 'reply' in ri.op[ri.op_mode]:
1323 ri.cw.write_func_prot(ret, fname, args, doc=doc, suffix=suffix)
1326 def print_req_prototype(ri): argument
1327 print_prototype(ri, "request", doc=ri.op['doc'])
1330 def print_dump_prototype(ri): argument
1331 print_prototype(ri, "request")
1403 def put_req_nested(ri, struct): argument
1408 ri.cw.write_func_prot('int', f'{struct.render_name}_put', func_args)
1409 ri.cw.block_start()
1410 ri.cw.write_func_lvar('struct nlattr *nest;')
1412 ri.cw.p("nest = mnl_attr_nest_start(nlh, attr_type);")
1415 arg.attr_put(ri, "obj")
1417 ri.cw.p("mnl_attr_nest_end(nlh, nest);")
1419 ri.cw.nl()
1420 ri.cw.p('return 0;')
1421 ri.cw.block_end()
1422 ri.cw.nl()
1425 def _multi_parse(ri, struct, init_lines, local_vars): argument
1452 ri.cw.block_start()
1453 ri.cw.write_func_lvar(local_vars)
1456 ri.cw.p(line)
1457 ri.cw.nl()
1460 ri.cw.p(f'dst->{arg} = {arg};')
1464 ri.cw.p(f"if (dst->{aspec.c_name})")
1465ri.cw.p(f'return ynl_error_parse(yarg, "attribute already present ({struct.attr_set.name}.{aspec.n…
1467 ri.cw.nl()
1468 ri.cw.block_start(line=iter_line)
1469 ri.cw.p('unsigned int type = mnl_attr_get_type(attr);')
1470 ri.cw.nl()
1474 good = arg.attr_get(ri, 'dst', first=first)
1478 ri.cw.block_end()
1479 ri.cw.nl()
1484 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
1485 ri.cw.p(f"dst->{aspec.c_name} = calloc({aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1486 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1487 ri.cw.p('i = 0;')
1488 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
1489 ri.cw.block_start(line=f"mnl_attr_for_each_nested(attr, attr_{aspec.c_name})")
1490 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1491 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr, mnl_attr_get_type(attr)))")
1492 ri.cw.p('return MNL_CB_ERROR;')
1493 ri.cw.p('i++;')
1494 ri.cw.block_end()
1495 ri.cw.block_end()
1496 ri.cw.nl()
1500 ri.cw.block_start(line=f"if (n_{aspec.c_name})")
1501 ri.cw.p(f"dst->{aspec.c_name} = calloc(n_{aspec.c_name}, sizeof(*dst->{aspec.c_name}));")
1502 ri.cw.p(f"dst->n_{aspec.c_name} = n_{aspec.c_name};")
1503 ri.cw.p('i = 0;')
1505 ri.cw.p(f"parg.rsp_policy = &{aspec.nested_render_name}_nest;")
1506 ri.cw.block_start(line=iter_line)
1507 ri.cw.block_start(line=f"if (mnl_attr_get_type(attr) == {aspec.enum_name})")
1509 ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
1510 ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr))")
1511 ri.cw.p('return MNL_CB_ERROR;')
1516 ri.cw.p(f"dst->{aspec.c_name}[i] = mnl_attr_get_{t}(attr);")
1519 ri.cw.p('i++;')
1520 ri.cw.block_end()
1521 ri.cw.block_end()
1522 ri.cw.block_end()
1523 ri.cw.nl()
1526 ri.cw.p('return 0;')
1528 ri.cw.p('return MNL_CB_OK;')
1529 ri.cw.block_end()
1530 ri.cw.nl()
1533 def parse_rsp_nested(ri, struct): argument
1543 ri.cw.write_func_prot('int', f'{struct.render_name}_parse', func_args)
1545 _multi_parse(ri, struct, init_lines, local_vars)
1548 def parse_rsp_msg(ri, deref=False): argument
1549 if 'reply' not in ri.op[ri.op_mode] and ri.op_mode != 'event':
1560 ri.cw.write_func_prot('int', f'{op_prefix(ri, "reply", deref=deref)}_parse', func_args)
1562 if ri.struct["reply"].member_list():
1563 _multi_parse(ri, ri.struct["reply"], init_lines, local_vars)
1566 ri.cw.block_start()
1567 ri.cw.p('return MNL_CB_OK;')
1568 ri.cw.block_end()
1569 ri.cw.nl()
1572 def print_req(ri): argument
1579 if 'reply' in ri.op[ri.op_mode]:
1585 print_prototype(ri, direction, terminate=False)
1586 ri.cw.block_start()
1587 ri.cw.write_func_lvar(local_vars)
1589 ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1591 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
1592 if 'reply' in ri.op[ri.op_mode]:
1593 ri.cw.p(f"yrs.yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
1594 ri.cw.nl()
1595 for _, attr in ri.struct["request"].member_list():
1596 attr.attr_put(ri, "req")
1597 ri.cw.nl()
1600 if 'reply' in ri.op[ri.op_mode]:
1601 ri.cw.p('rsp = calloc(1, sizeof(*rsp));')
1602 ri.cw.p('yrs.yarg.data = rsp;')
1603 ri.cw.p(f"yrs.cb = {op_prefix(ri, 'reply')}_parse;")
1604 if ri.op.value is not None:
1605 ri.cw.p(f'yrs.rsp_cmd = {ri.op.enum_name};')
1607 ri.cw.p(f'yrs.rsp_cmd = {ri.op.rsp_value};')
1608 ri.cw.nl()
1610 ri.cw.p(f"err = ynl_exec(ys, nlh, {parse_arg});")
1611 ri.cw.p('if (err < 0)')
1612 if 'reply' in ri.op[ri.op_mode]:
1613 ri.cw.p('goto err_free;')
1615 ri.cw.p('return -1;')
1616 ri.cw.nl()
1618 ri.cw.p(f"return {ret_ok};")
1619 ri.cw.nl()
1621 if 'reply' in ri.op[ri.op_mode]:
1622 ri.cw.p('err_free:')
1623 ri.cw.p(f"{call_free(ri, rdir(direction), 'rsp')}")
1624 ri.cw.p(f"return {ret_err};")
1626 ri.cw.block_end()
1629 def print_dump(ri): argument
1631 print_prototype(ri, direction, terminate=False)
1632 ri.cw.block_start()
1638 ri.cw.p(f'{var}')
1639 ri.cw.nl()
1641 ri.cw.p('yds.ys = ys;')
1642 ri.cw.p(f"yds.alloc_sz = sizeof({type_name(ri, rdir(direction))});")
1643 ri.cw.p(f"yds.cb = {op_prefix(ri, 'reply', deref=True)}_parse;")
1644 if ri.op.value is not None:
1645 ri.cw.p(f'yds.rsp_cmd = {ri.op.enum_name};')
1647 ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};')
1648 ri.cw.p(f"yds.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
1649 ri.cw.nl()
1650 ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1652 if "request" in ri.op[ri.op_mode]:
1653 ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
1654 ri.cw.nl()
1655 for _, attr in ri.struct["request"].member_list():
1656 attr.attr_put(ri, "req")
1657 ri.cw.nl()
1659 ri.cw.p('err = ynl_exec_dump(ys, nlh, &yds);')
1660 ri.cw.p('if (err < 0)')
1661 ri.cw.p('goto free_list;')
1662 ri.cw.nl()
1664 ri.cw.p('return yds.first;')
1665 ri.cw.nl()
1666 ri.cw.p('free_list:')
1667 ri.cw.p(call_free(ri, rdir(direction), 'yds.first'))
1668 ri.cw.p('return NULL;')
1669 ri.cw.block_end()
1672 def call_free(ri, direction, var): argument
1682 def print_alloc_wrapper(ri, direction): argument
1683 name = op_prefix(ri, direction)
1684 ri.cw.write_func_prot(f'static inline struct {name} *', f"{name}_alloc", [f"void"])
1685 ri.cw.block_start()
1686 ri.cw.p(f'return calloc(1, sizeof(struct {name}));')
1687 ri.cw.block_end()
1690 def print_free_prototype(ri, direction, suffix=';'): argument
1691 name = op_prefix(ri, direction)
1693 if ri.type_name_conflict:
1696 ri.cw.write_func_prot('void', f"{name}_free", [f"struct {struct_name} *{arg}"], suffix=suffix)
1699 def _print_type(ri, direction, struct): argument
1701 if not direction and ri.type_name_conflict:
1704 if ri.op_mode == 'dump':
1707 ri.cw.block_start(line=f"struct {ri.family['name']}{suffix}")
1712 line = attr.presence_member(ri.ku_space, type_filter)
1715 ri.cw.block_start(line=f"struct")
1717 ri.cw.p(line)
1719 ri.cw.block_end(line='_present;')
1720 ri.cw.nl()
1723 ri.cw.p(f"__u32 {arg};")
1726 attr.struct_member(ri)
1728 ri.cw.block_end(line=';')
1729 ri.cw.nl()
1732 def print_type(ri, direction): argument
1733 _print_type(ri, direction, ri.struct[direction])
1736 def print_type_full(ri, struct): argument
1737 _print_type(ri, "", struct)
1740 def print_type_helpers(ri, direction, deref=False): argument
1741 print_free_prototype(ri, direction)
1742 ri.cw.nl()
1744 if ri.ku_space == 'user' and direction == 'request':
1745 for _, attr in ri.struct[direction].member_list():
1746 attr.setter(ri, ri.attr_set, direction, deref=deref)
1747 ri.cw.nl()
1750 def print_req_type_helpers(ri): argument
1751 print_alloc_wrapper(ri, "request")
1752 print_type_helpers(ri, "request")
1755 def print_rsp_type_helpers(ri): argument
1756 if 'reply' not in ri.op[ri.op_mode]:
1758 print_type_helpers(ri, "reply")
1761 def print_parse_prototype(ri, direction, terminate=True): argument
1765 ri.cw.write_func_prot('void', f"{ri.op.render_name}{suffix}_parse",
1771 def print_req_type(ri): argument
1772 print_type(ri, "request")
1775 def print_req_free(ri): argument
1776 if 'request' not in ri.op[ri.op_mode]:
1778 _free_type(ri, 'request', ri.struct['request'])
1781 def print_rsp_type(ri): argument
1782 if (ri.op_mode == 'do' or ri.op_mode == 'dump') and 'reply' in ri.op[ri.op_mode]:
1784 elif ri.op_mode == 'event':
1788 print_type(ri, direction)
1791 def print_wrapped_type(ri): argument
1792 ri.cw.block_start(line=f"{type_name(ri, 'reply')}")
1793 if ri.op_mode == 'dump':
1794 ri.cw.p(f"{type_name(ri, 'reply')} *next;")
1795 elif ri.op_mode == 'notify' or ri.op_mode == 'event':
1796 ri.cw.p('__u16 family;')
1797 ri.cw.p('__u8 cmd;')
1798 ri.cw.p('struct ynl_ntf_base_type *next;')
1799 ri.cw.p(f"void (*free)({type_name(ri, 'reply')} *ntf);")
1800 ri.cw.p(f"{type_name(ri, 'reply', deref=True)} obj __attribute__ ((aligned (8)));")
1801 ri.cw.block_end(line=';')
1802 ri.cw.nl()
1803 print_free_prototype(ri, 'reply')
1804 ri.cw.nl()
1807 def _free_type_members_iter(ri, struct): argument
1810 ri.cw.p('unsigned int i;')
1811 ri.cw.nl()
1815 def _free_type_members(ri, var, struct, ref=''): argument
1817 attr.free(ri, var, ref)
1820 def _free_type(ri, direction, struct): argument
1823 print_free_prototype(ri, direction, suffix='')
1824 ri.cw.block_start()
1825 _free_type_members_iter(ri, struct)
1826 _free_type_members(ri, var, struct)
1828 ri.cw.p(f'free({var});')
1829 ri.cw.block_end()
1830 ri.cw.nl()
1833 def free_rsp_nested(ri, struct): argument
1834 _free_type(ri, "", struct)
1837 def print_rsp_free(ri): argument
1838 if 'reply' not in ri.op[ri.op_mode]:
1840 _free_type(ri, 'reply', ri.struct['reply'])
1843 def print_dump_type_free(ri): argument
1844 sub_type = type_name(ri, 'reply')
1846 print_free_prototype(ri, 'reply', suffix='')
1847 ri.cw.block_start()
1848 ri.cw.p(f"{sub_type} *next = rsp;")
1849 ri.cw.nl()
1850 ri.cw.block_start(line='while ((void *)next != YNL_LIST_END)')
1851 _free_type_members_iter(ri, ri.struct['reply'])
1852 ri.cw.p('rsp = next;')
1853 ri.cw.p('next = rsp->next;')
1854 ri.cw.nl()
1856 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
1857 ri.cw.p(f'free(rsp);')
1858 ri.cw.block_end()
1859 ri.cw.block_end()
1860 ri.cw.nl()
1863 def print_ntf_type_free(ri): argument
1864 print_free_prototype(ri, 'reply', suffix='')
1865 ri.cw.block_start()
1866 _free_type_members_iter(ri, ri.struct['reply'])
1867 _free_type_members(ri, 'rsp', ri.struct['reply'], ref='obj.')
1868 ri.cw.p(f'free(rsp);')
1869 ri.cw.block_end()
1870 ri.cw.nl()
1873 def print_req_policy_fwd(cw, struct, ri=None, terminate=True): argument
1874 if terminate and ri and policy_should_be_static(struct.family):
1880 if ri and policy_should_be_static(struct.family):
1888 if ri:
1889 name = ri.op.render_name
1890 if ri.op.dual_policy:
1891 name += '_' + ri.op_mode
1897 def print_req_policy(cw, struct, ri=None): argument
1898 print_req_policy_fwd(cw, struct, ri=ri, terminate=False)
2272 def _render_user_ntf_entry(ri, op): argument
2273 ri.cw.block_start(line=f"[{op.enum_name}] = ")
2274 ri.cw.p(f".alloc_sz\t= sizeof({type_name(ri, 'event')}),")
2275 ri.cw.p(f".cb\t\t= {op_prefix(ri, 'reply', deref=True)}_parse,")
2276 ri.cw.p(f".policy\t\t= &{ri.struct['reply'].render_name}_nest,")
2277 ri.cw.p(f".free\t\t= (void *){op_prefix(ri, 'notify')}_free,")
2278 ri.cw.block_end(line=',')
2292 ri = RenderInfo(cw, family, "user", op, "notify")
2294 ri = RenderInfo(cw, family, "user", ntf_op, "event")
2297 _render_user_ntf_entry(ri, ntf_op)
2301 ri = RenderInfo(cw, family, "user", op, "event")
2302 _render_user_ntf_entry(ri, op)
2444 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2445 print_req_policy_fwd(cw, ri.struct['request'], ri=ri)
2473 ri = RenderInfo(cw, parsed, args.mode, op, op_mode)
2474 print_req_policy(cw, ri.struct['request'], ri=ri)
2493 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
2494 print_type_full(ri, struct)
2501 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2502 print_req_type(ri)
2503 print_req_type_helpers(ri)
2505 print_rsp_type(ri)
2506 print_rsp_type_helpers(ri)
2508 print_req_prototype(ri)
2513 ri = RenderInfo(cw, parsed, args.mode, op, 'dump')
2515 print_req_type(ri)
2516 print_req_type_helpers(ri)
2517 if not ri.type_consistent:
2518 print_rsp_type(ri)
2519 print_wrapped_type(ri)
2520 print_dump_prototype(ri)
2525 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
2526 if not ri.type_consistent:
2528 print_wrapped_type(ri)
2532 ri = RenderInfo(cw, parsed, args.mode, op, 'event')
2534 print_rsp_type(ri)
2536 print_wrapped_type(ri)
2557 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
2559 free_rsp_nested(ri, struct)
2561 put_req_nested(ri, struct)
2563 parse_rsp_nested(ri, struct)
2569 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2570 print_req_free(ri)
2571 print_rsp_free(ri)
2572 parse_rsp_msg(ri)
2573 print_req(ri)
2578 ri = RenderInfo(cw, parsed, args.mode, op, "dump")
2579 if not ri.type_consistent:
2580 parse_rsp_msg(ri, deref=True)
2581 print_dump_type_free(ri)
2582 print_dump(ri)
2587 ri = RenderInfo(cw, parsed, args.mode, op, 'notify')
2588 if not ri.type_consistent:
2590 print_ntf_type_free(ri)
2596 ri = RenderInfo(cw, parsed, args.mode, op, "do")
2597 parse_rsp_msg(ri)
2599 ri = RenderInfo(cw, parsed, args.mode, op, "event")
2600 print_ntf_type_free(ri)