Ole Troan | 1b1ccad | 2019-10-25 18:30:40 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 2 | |
| 3 | import argparse |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 4 | import inspect |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 5 | import os |
| 6 | import sys |
| 7 | import logging |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 8 | from vapi_json_parser import ( |
| 9 | Field, |
| 10 | Struct, |
| 11 | Enum, |
| 12 | Union, |
| 13 | Message, |
| 14 | JsonParser, |
| 15 | SimpleType, |
| 16 | StructType, |
| 17 | Alias, |
| 18 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 19 | |
| 20 | |
| 21 | class CField(Field): |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 22 | def get_c_name(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 23 | return "vapi_type_%s" % self.name |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 24 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 25 | def get_c_def(self): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 26 | if self.type.get_c_name() == "string": |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 27 | if self.len: |
| 28 | return "u8 %s[%d];" % (self.name, self.len) |
| 29 | else: |
| 30 | return "vl_api_string_t %s;" % (self.name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 31 | else: |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 32 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | return "%s %s[%d];" % (self.type.get_c_name(), self.name, self.len) |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 34 | else: |
| 35 | return "%s %s;" % (self.type.get_c_name(), self.name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 36 | |
| 37 | def get_swap_to_be_code(self, struct, var): |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 38 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 39 | if self.len > 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 40 | return ( |
| 41 | "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }" |
| 42 | " while(0);" |
| 43 | % (self.len, self.type.get_swap_to_be_code(struct, "%s[i]" % var)) |
| 44 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 45 | else: |
| 46 | if self.nelem_field.needs_byte_swap(): |
| 47 | nelem_field = "%s(%s%s)" % ( |
| 48 | self.nelem_field.type.get_swap_to_host_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 49 | struct, |
| 50 | self.nelem_field.name, |
| 51 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 52 | else: |
| 53 | nelem_field = "%s%s" % (struct, self.nelem_field.name) |
| 54 | return ( |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 55 | "do { unsigned i; for (i = 0; i < %s; ++i) { %s } }" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 56 | " while(0);" |
| 57 | % ( |
| 58 | nelem_field, |
| 59 | self.type.get_swap_to_be_code(struct, "%s[i]" % var), |
| 60 | ) |
| 61 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 62 | return self.type.get_swap_to_be_code(struct, "%s" % var) |
| 63 | |
| 64 | def get_swap_to_host_code(self, struct, var): |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 65 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 66 | if self.len > 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 67 | return ( |
| 68 | "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }" |
| 69 | " while(0);" |
| 70 | % (self.len, self.type.get_swap_to_host_code(struct, "%s[i]" % var)) |
| 71 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 72 | else: |
| 73 | # nelem_field already swapped to host here... |
| 74 | return ( |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 75 | "do { unsigned i; for (i = 0; i < %s%s; ++i) { %s } }" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | " while(0);" |
| 77 | % ( |
| 78 | struct, |
| 79 | self.nelem_field.name, |
| 80 | self.type.get_swap_to_host_code(struct, "%s[i]" % var), |
| 81 | ) |
| 82 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 83 | return self.type.get_swap_to_host_code(struct, "%s" % var) |
| 84 | |
| 85 | def needs_byte_swap(self): |
| 86 | return self.type.needs_byte_swap() |
| 87 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 88 | def get_vla_parameter_name(self, path): |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 89 | return "%s_%s_array_size" % ("_".join(path), self.name) |
| 90 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 91 | def get_vla_field_name(self, path): |
| 92 | return ".".join(path + [self.nelem_field.name]) |
| 93 | |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 94 | def get_alloc_vla_param_names(self, path): |
| 95 | if self.is_vla(): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 96 | result = [self.get_vla_parameter_name(path)] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 97 | else: |
| 98 | result = [] |
| 99 | if self.type.has_vla(): |
| 100 | t = self.type.get_alloc_vla_param_names(path + [self.name]) |
| 101 | result.extend(t) |
| 102 | return result |
| 103 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 104 | def get_vla_calc_size_code(self, prefix, path, is_alloc): |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 105 | if self.is_vla(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 106 | result = [ |
| 107 | "sizeof(%s.%s[0]) * %s" |
| 108 | % ( |
| 109 | ".".join([prefix] + path), |
| 110 | self.name, |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 111 | self.get_vla_parameter_name(path) |
| 112 | if is_alloc |
| 113 | else "%s.%s" % (prefix, self.get_vla_field_name(path)), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 114 | ) |
| 115 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 116 | else: |
| 117 | result = [] |
| 118 | if self.type.has_vla(): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 119 | t = self.type.get_vla_calc_size_code(prefix, path + [self.name], is_alloc) |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 120 | result.extend(t) |
| 121 | return result |
| 122 | |
| 123 | def get_vla_assign_code(self, prefix, path): |
| 124 | result = [] |
| 125 | if self.is_vla(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 126 | result.append( |
| 127 | "%s.%s = %s" |
| 128 | % ( |
| 129 | ".".join([prefix] + path), |
| 130 | self.nelem_field.name, |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 131 | self.get_vla_parameter_name(path), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 132 | ) |
| 133 | ) |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 134 | if self.type.has_vla(): |
| 135 | t = self.type.get_vla_assign_code(prefix, path + [self.name]) |
| 136 | result.extend(t) |
| 137 | return result |
| 138 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 139 | |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 140 | class CAlias(CField): |
| 141 | def get_c_name(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 142 | return "vapi_type_%s" % self.name |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 143 | |
| 144 | def get_c_def(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 145 | if self.len is not None: |
Klement Sekera | 173e20c | 2018-12-12 12:57:32 +0100 | [diff] [blame] | 146 | return "typedef %s vapi_type_%s[%d];" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 147 | self.type.get_c_name(), |
| 148 | self.name, |
| 149 | self.len, |
| 150 | ) |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 151 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 152 | return "typedef %s vapi_type_%s;" % (self.type.get_c_name(), self.name) |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 153 | |
| 154 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 155 | class CStruct(Struct): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 156 | def get_c_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 157 | return "\n".join( |
| 158 | [ |
| 159 | "typedef struct __attribute__((__packed__)) {\n%s" |
| 160 | % ("\n".join([" %s" % x.get_c_def() for x in self.fields])), |
| 161 | "} %s;" % self.get_c_name(), |
| 162 | ] |
| 163 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 164 | |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 165 | def get_vla_assign_code(self, prefix, path): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 166 | return [ |
| 167 | x |
| 168 | for f in self.fields |
| 169 | if f.has_vla() |
| 170 | for x in f.get_vla_assign_code(prefix, path) |
| 171 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 172 | |
| 173 | def get_alloc_vla_param_names(self, path): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 174 | return [ |
| 175 | x |
| 176 | for f in self.fields |
| 177 | if f.has_vla() |
| 178 | for x in f.get_alloc_vla_param_names(path) |
| 179 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 180 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 181 | def get_vla_calc_size_code(self, prefix, path, is_alloc): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 182 | return [ |
| 183 | x |
| 184 | for f in self.fields |
| 185 | if f.has_vla() |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 186 | for x in f.get_vla_calc_size_code(prefix, path, is_alloc) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 187 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 188 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 189 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 190 | class CSimpleType(SimpleType): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 191 | swap_to_be_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | "i16": "htobe16", |
| 193 | "u16": "htobe16", |
| 194 | "i32": "htobe32", |
| 195 | "u32": "htobe32", |
| 196 | "i64": "htobe64", |
| 197 | "u64": "htobe64", |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | swap_to_host_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 201 | "i16": "be16toh", |
| 202 | "u16": "be16toh", |
| 203 | "i32": "be32toh", |
| 204 | "u32": "be32toh", |
| 205 | "i64": "be64toh", |
| 206 | "u64": "be64toh", |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 209 | __packed = "__attribute__((packed))" |
| 210 | pack_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 211 | "i8": __packed, |
| 212 | "u8": __packed, |
| 213 | "i16": __packed, |
| 214 | "u16": __packed, |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 217 | def get_c_name(self): |
| 218 | return self.name |
| 219 | |
| 220 | def get_swap_to_be_func_name(self): |
| 221 | return self.swap_to_be_dict[self.name] |
| 222 | |
| 223 | def get_swap_to_host_func_name(self): |
| 224 | return self.swap_to_host_dict[self.name] |
| 225 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 226 | def get_packed_string(self): |
| 227 | return self.pack_dict[self.name] |
| 228 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 229 | def get_swap_to_be_code(self, struct, var, cast=None): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 230 | x = "%s%s" % (struct, var) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 231 | return "%s = %s%s(%s);" % ( |
| 232 | x, |
| 233 | "(%s)" % cast if cast else "", |
| 234 | self.get_swap_to_be_func_name(), |
| 235 | x, |
| 236 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 237 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 238 | def get_swap_to_host_code(self, struct, var, cast=None): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 239 | x = "%s%s" % (struct, var) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 240 | return "%s = %s%s(%s);" % ( |
| 241 | x, |
| 242 | "(%s)" % cast if cast else "", |
| 243 | self.get_swap_to_host_func_name(), |
| 244 | x, |
| 245 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 246 | |
| 247 | def needs_byte_swap(self): |
| 248 | try: |
| 249 | self.get_swap_to_host_func_name() |
| 250 | return True |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 251 | except KeyError: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 252 | pass |
| 253 | return False |
| 254 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 255 | def get_packed(self): |
| 256 | return self.pack_dict.get(self.name, "") |
| 257 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 258 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 259 | class CEnum(Enum): |
| 260 | def get_c_name(self): |
| 261 | return "vapi_enum_%s" % self.name |
| 262 | |
| 263 | def get_c_def(self): |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 264 | return "typedef enum {\n%s\n} %s %s;" % ( |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 265 | "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]), |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 266 | self.type.get_packed(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 267 | self.get_c_name(), |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 268 | ) |
| 269 | |
| 270 | def needs_byte_swap(self): |
| 271 | return self.type.needs_byte_swap() |
| 272 | |
| 273 | def get_swap_to_be_code(self, struct, var): |
| 274 | return self.type.get_swap_to_be_code(struct, var, self.get_c_name()) |
| 275 | |
| 276 | def get_swap_to_host_code(self, struct, var): |
| 277 | return self.type.get_swap_to_host_code(struct, var, self.get_c_name()) |
| 278 | |
| 279 | |
| 280 | class CUnion(Union): |
| 281 | def get_c_name(self): |
| 282 | return "vapi_union_%s" % self.name |
| 283 | |
| 284 | def get_c_def(self): |
| 285 | return "typedef union {\n%s\n} %s;" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 286 | "\n".join([" %s %s;" % (i.get_c_name(), j) for i, j in self.type_pairs]), |
| 287 | self.get_c_name(), |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 288 | ) |
| 289 | |
| 290 | def needs_byte_swap(self): |
| 291 | return False |
| 292 | |
| 293 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 294 | class CStructType(StructType, CStruct): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 295 | def get_c_name(self): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 296 | if self.name == "vl_api_string_t": |
| 297 | return "vl_api_string_t" |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 298 | return "vapi_type_%s" % self.name |
| 299 | |
| 300 | def get_swap_to_be_func_name(self): |
| 301 | return "%s_hton" % self.get_c_name() |
| 302 | |
| 303 | def get_swap_to_host_func_name(self): |
| 304 | return "%s_ntoh" % self.get_c_name() |
| 305 | |
| 306 | def get_swap_to_be_func_decl(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 307 | return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name()) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 308 | |
| 309 | def get_swap_to_be_func_def(self): |
| 310 | return "%s\n{\n%s\n}" % ( |
| 311 | self.get_swap_to_be_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 312 | "\n".join( |
| 313 | [ |
| 314 | " %s" % p.get_swap_to_be_code("msg->", "%s" % p.name) |
| 315 | for p in self.fields |
| 316 | if p.needs_byte_swap() |
| 317 | ] |
| 318 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 319 | ) |
| 320 | |
| 321 | def get_swap_to_host_func_decl(self): |
| 322 | return "void %s(%s *msg)" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 323 | self.get_swap_to_host_func_name(), |
| 324 | self.get_c_name(), |
| 325 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 326 | |
| 327 | def get_swap_to_host_func_def(self): |
| 328 | return "%s\n{\n%s\n}" % ( |
| 329 | self.get_swap_to_host_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 330 | "\n".join( |
| 331 | [ |
| 332 | " %s" % p.get_swap_to_host_code("msg->", "%s" % p.name) |
| 333 | for p in self.fields |
| 334 | if p.needs_byte_swap() |
| 335 | ] |
| 336 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 337 | ) |
| 338 | |
| 339 | def get_swap_to_be_code(self, struct, var): |
| 340 | return "%s(&%s%s);" % (self.get_swap_to_be_func_name(), struct, var) |
| 341 | |
| 342 | def get_swap_to_host_code(self, struct, var): |
| 343 | return "%s(&%s%s);" % (self.get_swap_to_host_func_name(), struct, var) |
| 344 | |
| 345 | def needs_byte_swap(self): |
| 346 | for f in self.fields: |
| 347 | if f.needs_byte_swap(): |
| 348 | return True |
| 349 | return False |
| 350 | |
| 351 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 352 | class CMessage(Message): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 353 | def __init__(self, logger, definition, json_parser): |
| 354 | super(CMessage, self).__init__(logger, definition, json_parser) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 355 | self.payload_members = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 356 | " %s" % p.get_c_def() for p in self.fields if p.type != self.header |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 357 | ] |
| 358 | |
| 359 | def has_payload(self): |
| 360 | return len(self.payload_members) > 0 |
| 361 | |
| 362 | def get_msg_id_name(self): |
| 363 | return "vapi_msg_id_%s" % self.name |
| 364 | |
| 365 | def get_c_name(self): |
| 366 | return "vapi_msg_%s" % self.name |
| 367 | |
| 368 | def get_payload_struct_name(self): |
| 369 | return "vapi_payload_%s" % self.name |
| 370 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 371 | def get_alloc_func_name(self): |
| 372 | return "vapi_alloc_%s" % self.name |
| 373 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 374 | def get_alloc_vla_param_names(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 375 | return [ |
| 376 | x |
| 377 | for f in self.fields |
| 378 | if f.has_vla() |
| 379 | for x in f.get_alloc_vla_param_names([]) |
| 380 | ] |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 381 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 382 | def get_alloc_func_decl(self): |
| 383 | return "%s* %s(struct vapi_ctx_s *ctx%s)" % ( |
| 384 | self.get_c_name(), |
| 385 | self.get_alloc_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 386 | "".join([", size_t %s" % n for n in self.get_alloc_vla_param_names()]), |
| 387 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 388 | |
| 389 | def get_alloc_func_def(self): |
| 390 | extra = [] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 391 | if self.header.has_field("client_index"): |
| 392 | extra.append(" msg->header.client_index = vapi_get_client_index(ctx);") |
| 393 | if self.header.has_field("context"): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 394 | extra.append(" msg->header.context = 0;") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 395 | return "\n".join( |
| 396 | [ |
| 397 | "%s" % self.get_alloc_func_decl(), |
| 398 | "{", |
| 399 | " %s *msg = NULL;" % self.get_c_name(), |
| 400 | " const size_t size = sizeof(%s)%s;" |
| 401 | % ( |
| 402 | self.get_c_name(), |
| 403 | "".join( |
| 404 | [ |
| 405 | " + %s" % x |
| 406 | for f in self.fields |
| 407 | if f.has_vla() |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 408 | for x in f.get_vla_calc_size_code( |
| 409 | "msg->payload", [], is_alloc=True |
| 410 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 411 | ] |
| 412 | ), |
| 413 | ), |
| 414 | " /* cast here required to play nicely with C++ world ... */", |
| 415 | " msg = (%s*)vapi_msg_alloc(ctx, size);" % self.get_c_name(), |
| 416 | " if (!msg) {", |
| 417 | " return NULL;", |
| 418 | " }", |
| 419 | ] |
| 420 | + extra |
| 421 | + [ |
| 422 | " msg->header._vl_msg_id = vapi_lookup_vl_msg_id(ctx, %s);" |
| 423 | % self.get_msg_id_name(), |
| 424 | "".join( |
| 425 | [ |
| 426 | " %s;\n" % line |
| 427 | for f in self.fields |
| 428 | if f.has_vla() |
| 429 | for line in f.get_vla_assign_code("msg->payload", []) |
| 430 | ] |
| 431 | ), |
| 432 | " return msg;", |
| 433 | "}", |
| 434 | ] |
| 435 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 436 | |
| 437 | def get_calc_msg_size_func_name(self): |
| 438 | return "vapi_calc_%s_msg_size" % self.name |
| 439 | |
| 440 | def get_calc_msg_size_func_decl(self): |
| 441 | return "uword %s(%s *msg)" % ( |
| 442 | self.get_calc_msg_size_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 443 | self.get_c_name(), |
| 444 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 445 | |
| 446 | def get_calc_msg_size_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 447 | return "\n".join( |
| 448 | [ |
| 449 | "%s" % self.get_calc_msg_size_func_decl(), |
| 450 | "{", |
| 451 | " return sizeof(*msg)%s;" |
| 452 | % "".join( |
| 453 | [ |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 454 | " + %s" % x |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 455 | for f in self.fields |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 456 | if f.has_vla() |
| 457 | for x in f.get_vla_calc_size_code( |
| 458 | "msg->payload", [], is_alloc=False |
| 459 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 460 | ] |
| 461 | ), |
| 462 | "}", |
| 463 | ] |
| 464 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 465 | |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 466 | def get_verify_msg_size_func_name(self): |
| 467 | return f"vapi_verify_{self.name}_msg_size" |
| 468 | |
| 469 | def get_verify_msg_size_func_decl(self): |
| 470 | return "int %s(%s *msg, uword buf_size)" % ( |
| 471 | self.get_verify_msg_size_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 472 | self.get_c_name(), |
| 473 | ) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 474 | |
| 475 | def get_verify_msg_size_func_def(self): |
| 476 | return inspect.cleandoc( |
| 477 | f""" |
| 478 | {self.get_verify_msg_size_func_decl()} |
| 479 | {{ |
| 480 | if (sizeof({self.get_c_name()}) > buf_size) |
| 481 | {{ |
| 482 | VAPI_ERR("Truncated '{self.name}' msg received, received %lu" |
| 483 | "bytes, expected %lu bytes.", buf_size, |
| 484 | sizeof({self.get_c_name()})); |
| 485 | return -1; |
| 486 | }} |
| 487 | if ({self.get_calc_msg_size_func_name()}(msg) > buf_size) |
| 488 | {{ |
| 489 | VAPI_ERR("Truncated '{self.name}' msg received, received %lu" |
| 490 | "bytes, expected %lu bytes.", buf_size, |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 491 | {self.get_calc_msg_size_func_name()}(msg)); |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 492 | return -1; |
| 493 | }} |
| 494 | return 0; |
| 495 | }} |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 496 | """ |
| 497 | ) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 498 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 499 | def get_c_def(self): |
| 500 | if self.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 501 | return "\n".join( |
| 502 | [ |
| 503 | "typedef struct __attribute__ ((__packed__)) {", |
| 504 | "%s " % "\n".join(self.payload_members), |
| 505 | "} %s;" % self.get_payload_struct_name(), |
| 506 | "", |
| 507 | "typedef struct __attribute__ ((__packed__)) {", |
| 508 | ( |
| 509 | " %s %s;" % (self.header.get_c_name(), self.fields[0].name) |
| 510 | if self.header is not None |
| 511 | else "" |
| 512 | ), |
| 513 | " %s payload;" % self.get_payload_struct_name(), |
| 514 | "} %s;" % self.get_c_name(), |
| 515 | ] |
| 516 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 517 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 518 | return "\n".join( |
| 519 | [ |
| 520 | "typedef struct __attribute__ ((__packed__)) {", |
| 521 | ( |
| 522 | " %s %s;" % (self.header.get_c_name(), self.fields[0].name) |
| 523 | if self.header is not None |
| 524 | else "" |
| 525 | ), |
| 526 | "} %s;" % self.get_c_name(), |
| 527 | ] |
| 528 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 529 | |
| 530 | def get_swap_payload_to_host_func_name(self): |
| 531 | return "%s_payload_ntoh" % self.get_c_name() |
| 532 | |
| 533 | def get_swap_payload_to_be_func_name(self): |
| 534 | return "%s_payload_hton" % self.get_c_name() |
| 535 | |
| 536 | def get_swap_payload_to_host_func_decl(self): |
| 537 | return "void %s(%s *payload)" % ( |
| 538 | self.get_swap_payload_to_host_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 539 | self.get_payload_struct_name(), |
| 540 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 541 | |
| 542 | def get_swap_payload_to_be_func_decl(self): |
| 543 | return "void %s(%s *payload)" % ( |
| 544 | self.get_swap_payload_to_be_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 545 | self.get_payload_struct_name(), |
| 546 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 547 | |
| 548 | def get_swap_payload_to_be_func_def(self): |
| 549 | return "%s\n{\n%s\n}" % ( |
| 550 | self.get_swap_payload_to_be_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 551 | "\n".join( |
| 552 | [ |
| 553 | " %s" % p.get_swap_to_be_code("payload->", "%s" % p.name) |
| 554 | for p in self.fields |
| 555 | if p.needs_byte_swap() and p.type != self.header |
| 556 | ] |
| 557 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 558 | ) |
| 559 | |
| 560 | def get_swap_payload_to_host_func_def(self): |
| 561 | return "%s\n{\n%s\n}" % ( |
| 562 | self.get_swap_payload_to_host_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 563 | "\n".join( |
| 564 | [ |
| 565 | " %s" % p.get_swap_to_host_code("payload->", "%s" % p.name) |
| 566 | for p in self.fields |
| 567 | if p.needs_byte_swap() and p.type != self.header |
| 568 | ] |
| 569 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 570 | ) |
| 571 | |
| 572 | def get_swap_to_host_func_name(self): |
| 573 | return "%s_ntoh" % self.get_c_name() |
| 574 | |
| 575 | def get_swap_to_be_func_name(self): |
| 576 | return "%s_hton" % self.get_c_name() |
| 577 | |
| 578 | def get_swap_to_host_func_decl(self): |
| 579 | return "void %s(%s *msg)" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 580 | self.get_swap_to_host_func_name(), |
| 581 | self.get_c_name(), |
| 582 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 583 | |
| 584 | def get_swap_to_be_func_decl(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 585 | return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name()) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 586 | |
| 587 | def get_swap_to_be_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 588 | return "\n".join( |
| 589 | [ |
| 590 | "%s" % self.get_swap_to_be_func_decl(), |
| 591 | "{", |
| 592 | ( |
| 593 | ' VAPI_DBG("Swapping `%s\'@%%p to big endian", msg);' |
| 594 | % self.get_c_name() |
| 595 | ), |
| 596 | " %s(&msg->header);" % self.header.get_swap_to_be_func_name() |
| 597 | if self.header is not None |
| 598 | else "", |
| 599 | " %s(&msg->payload);" % self.get_swap_payload_to_be_func_name() |
| 600 | if self.has_payload() |
| 601 | else "", |
| 602 | "}", |
| 603 | ] |
| 604 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 605 | |
| 606 | def get_swap_to_host_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 607 | return "\n".join( |
| 608 | [ |
| 609 | "%s" % self.get_swap_to_host_func_decl(), |
| 610 | "{", |
| 611 | ( |
| 612 | ' VAPI_DBG("Swapping `%s\'@%%p to host byte order", msg);' |
| 613 | % self.get_c_name() |
| 614 | ), |
| 615 | " %s(&msg->header);" % self.header.get_swap_to_host_func_name() |
| 616 | if self.header is not None |
| 617 | else "", |
| 618 | " %s(&msg->payload);" % self.get_swap_payload_to_host_func_name() |
| 619 | if self.has_payload() |
| 620 | else "", |
| 621 | "}", |
| 622 | ] |
| 623 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 624 | |
| 625 | def get_op_func_name(self): |
| 626 | return "vapi_%s" % self.name |
| 627 | |
| 628 | def get_op_func_decl(self): |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 629 | stream_param_lines = [] |
| 630 | if self.has_stream_msg: |
| 631 | stream_param_lines = [ |
| 632 | "vapi_error_e (*details_callback)(struct vapi_ctx_s *ctx", |
| 633 | " void *callback_ctx", |
| 634 | " vapi_error_e rv", |
| 635 | " bool is_last", |
| 636 | " %s *details)" |
| 637 | % self.stream_msg.get_payload_struct_name(), |
| 638 | "void *details_callback_ctx", |
| 639 | ] |
| 640 | |
| 641 | return "vapi_error_e %s(%s)" % ( |
| 642 | self.get_op_func_name(), |
| 643 | ",\n ".join( |
| 644 | [ |
| 645 | "struct vapi_ctx_s *ctx", |
| 646 | "%s *msg" % self.get_c_name(), |
| 647 | "vapi_error_e (*reply_callback)(struct vapi_ctx_s *ctx", |
| 648 | " void *callback_ctx", |
| 649 | " vapi_error_e rv", |
| 650 | " bool is_last", |
| 651 | " %s *reply)" |
| 652 | % self.reply.get_payload_struct_name(), |
| 653 | ] |
| 654 | + [ |
| 655 | "void *reply_callback_ctx", |
| 656 | ] |
| 657 | + stream_param_lines |
| 658 | ), |
| 659 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 660 | |
| 661 | def get_op_func_def(self): |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 662 | param_check_lines = [" if (!msg || !reply_callback) {"] |
| 663 | store_request_lines = [ |
| 664 | " vapi_store_request(ctx, req_context, %s, %s, " |
| 665 | % ( |
| 666 | self.reply.get_msg_id_name(), |
| 667 | "VAPI_REQUEST_DUMP" if self.reply_is_stream else "VAPI_REQUEST_REG", |
| 668 | ), |
| 669 | " (vapi_cb_t)reply_callback, reply_callback_ctx);", |
| 670 | ] |
| 671 | if self.has_stream_msg: |
| 672 | param_check_lines = [ |
| 673 | " if (!msg || !reply_callback || !details_callback) {" |
| 674 | ] |
| 675 | store_request_lines = [ |
| 676 | f" vapi_store_request(ctx, req_context, {self.stream_msg.get_msg_id_name()}, VAPI_REQUEST_STREAM, ", |
| 677 | " (vapi_cb_t)details_callback, details_callback_ctx);", |
| 678 | f" vapi_store_request(ctx, req_context, {self.reply.get_msg_id_name()}, VAPI_REQUEST_REG, ", |
| 679 | " (vapi_cb_t)reply_callback, reply_callback_ctx);", |
| 680 | ] |
| 681 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 682 | return "\n".join( |
| 683 | [ |
| 684 | "%s" % self.get_op_func_decl(), |
| 685 | "{", |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 686 | ] |
| 687 | + param_check_lines |
| 688 | + [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 689 | " return VAPI_EINVAL;", |
| 690 | " }", |
| 691 | " if (vapi_is_nonblocking(ctx) && vapi_requests_full(ctx)) {", |
| 692 | " return VAPI_EAGAIN;", |
| 693 | " }", |
| 694 | " vapi_error_e rv;", |
| 695 | " if (VAPI_OK != (rv = vapi_producer_lock (ctx))) {", |
| 696 | " return rv;", |
| 697 | " }", |
| 698 | " u32 req_context = vapi_gen_req_context(ctx);", |
| 699 | " msg->header.context = req_context;", |
| 700 | " %s(msg);" % self.get_swap_to_be_func_name(), |
| 701 | ( |
| 702 | " if (VAPI_OK == (rv = vapi_send_with_control_ping " |
| 703 | "(ctx, msg, req_context))) {" |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 704 | if (self.reply_is_stream and not self.has_stream_msg) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 705 | else " if (VAPI_OK == (rv = vapi_send (ctx, msg))) {" |
| 706 | ), |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 707 | ] |
| 708 | + store_request_lines |
| 709 | + [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 710 | " if (VAPI_OK != vapi_producer_unlock (ctx)) {", |
| 711 | " abort (); /* this really shouldn't happen */", |
| 712 | " }", |
| 713 | " if (vapi_is_nonblocking(ctx)) {", |
| 714 | " rv = VAPI_OK;", |
| 715 | " } else {", |
| 716 | " rv = vapi_dispatch(ctx);", |
| 717 | " }", |
| 718 | " } else {", |
| 719 | " %s(msg);" % self.get_swap_to_host_func_name(), |
| 720 | " if (VAPI_OK != vapi_producer_unlock (ctx)) {", |
| 721 | " abort (); /* this really shouldn't happen */", |
| 722 | " }", |
| 723 | " }", |
| 724 | " return rv;", |
| 725 | "}", |
| 726 | "", |
| 727 | ] |
| 728 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 729 | |
| 730 | def get_event_cb_func_decl(self): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 731 | if not self.is_reply and not self.is_event: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 732 | raise Exception("Cannot register event callback for non-reply message") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 733 | if self.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 734 | return "\n".join( |
| 735 | [ |
| 736 | "void vapi_set_%s_event_cb (" % self.get_c_name(), |
| 737 | " struct vapi_ctx_s *ctx, ", |
| 738 | ( |
| 739 | " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, " |
| 740 | "void *callback_ctx, %s *payload)," |
| 741 | % self.get_payload_struct_name() |
| 742 | ), |
| 743 | " void *callback_ctx)", |
| 744 | ] |
| 745 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 746 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 747 | return "\n".join( |
| 748 | [ |
| 749 | "void vapi_set_%s_event_cb (" % self.get_c_name(), |
| 750 | " struct vapi_ctx_s *ctx, ", |
| 751 | " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, " |
| 752 | "void *callback_ctx),", |
| 753 | " void *callback_ctx)", |
| 754 | ] |
| 755 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 756 | |
| 757 | def get_event_cb_func_def(self): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 758 | if not self.is_reply and not self.is_event: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 759 | raise Exception("Cannot register event callback for non-reply function") |
| 760 | return "\n".join( |
| 761 | [ |
| 762 | "%s" % self.get_event_cb_func_decl(), |
| 763 | "{", |
| 764 | ( |
| 765 | " vapi_set_event_cb(ctx, %s, (vapi_event_cb)callback, " |
| 766 | "callback_ctx);" % self.get_msg_id_name() |
| 767 | ), |
| 768 | "}", |
| 769 | ] |
| 770 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 771 | |
| 772 | def get_c_metadata_struct_name(self): |
| 773 | return "__vapi_metadata_%s" % self.name |
| 774 | |
| 775 | def get_c_constructor(self): |
| 776 | has_context = False |
| 777 | if self.header is not None: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 778 | has_context = self.header.has_field("context") |
| 779 | return "\n".join( |
| 780 | [ |
| 781 | "static void __attribute__((constructor)) __vapi_constructor_%s()" |
| 782 | % self.name, |
| 783 | "{", |
| 784 | ' static const char name[] = "%s";' % self.name, |
| 785 | ' static const char name_with_crc[] = "%s_%s";' |
| 786 | % (self.name, self.crc[2:]), |
| 787 | " static vapi_message_desc_t %s = {" |
| 788 | % self.get_c_metadata_struct_name(), |
| 789 | " name,", |
| 790 | " sizeof(name) - 1,", |
| 791 | " name_with_crc,", |
| 792 | " sizeof(name_with_crc) - 1,", |
| 793 | " true," if has_context else " false,", |
| 794 | " offsetof(%s, context)," % self.header.get_c_name() |
| 795 | if has_context |
| 796 | else " 0,", |
| 797 | (" offsetof(%s, payload)," % self.get_c_name()) |
| 798 | if self.has_payload() |
| 799 | else " VAPI_INVALID_MSG_ID,", |
| 800 | " (verify_msg_size_fn_t)%s," % self.get_verify_msg_size_func_name(), |
| 801 | " (generic_swap_fn_t)%s," % self.get_swap_to_be_func_name(), |
| 802 | " (generic_swap_fn_t)%s," % self.get_swap_to_host_func_name(), |
| 803 | " VAPI_INVALID_MSG_ID,", |
| 804 | " };", |
| 805 | "", |
| 806 | " %s = vapi_register_msg(&%s);" |
| 807 | % (self.get_msg_id_name(), self.get_c_metadata_struct_name()), |
| 808 | ' VAPI_DBG("Assigned msg id %%d to %s", %s);' |
| 809 | % (self.name, self.get_msg_id_name()), |
| 810 | "}", |
| 811 | ] |
| 812 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 813 | |
| 814 | |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 815 | def emit_definition(parser, json_file, emitted, o): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 816 | if o in emitted: |
| 817 | return |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 818 | if o.name in ("msg_header1_t", "msg_header2_t"): |
| 819 | return |
| 820 | if hasattr(o, "depends"): |
| 821 | for x in o.depends: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 822 | emit_definition(parser, json_file, emitted, x) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 823 | if hasattr(o, "reply"): |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 824 | emit_definition(parser, json_file, emitted, o.reply) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 825 | if hasattr(o, "stream_msg"): |
| 826 | emit_definition(parser, json_file, emitted, o.stream_msg) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 827 | if hasattr(o, "get_c_def"): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 828 | if ( |
| 829 | o not in parser.enums_by_json[json_file] |
| 830 | and o not in parser.types_by_json[json_file] |
| 831 | and o not in parser.unions_by_json[json_file] |
| 832 | and o.name not in parser.messages_by_json[json_file] |
| 833 | and o not in parser.aliases_by_json[json_file] |
| 834 | ): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 835 | return |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 836 | guard = "defined_%s" % o.get_c_name() |
| 837 | print("#ifndef %s" % guard) |
| 838 | print("#define %s" % guard) |
| 839 | print("%s" % o.get_c_def()) |
| 840 | print("") |
| 841 | function_attrs = "static inline " |
| 842 | if o.name in parser.messages_by_json[json_file]: |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 843 | if o.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 844 | print("%s%s" % (function_attrs, o.get_swap_payload_to_be_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 845 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 846 | print("%s%s" % (function_attrs, o.get_swap_payload_to_host_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 847 | print("") |
| 848 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 849 | print("") |
| 850 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
| 851 | print("") |
| 852 | print("%s%s" % (function_attrs, o.get_calc_msg_size_func_def())) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 853 | print("") |
| 854 | print("%s%s" % (function_attrs, o.get_verify_msg_size_func_def())) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 855 | if not o.is_reply and not o.is_event and not o.is_stream: |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 856 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 857 | print("%s%s" % (function_attrs, o.get_alloc_func_def())) |
| 858 | print("") |
| 859 | print("%s%s" % (function_attrs, o.get_op_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 860 | print("") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 861 | print("%s" % o.get_c_constructor()) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 862 | if (o.is_reply or o.is_event) and not o.is_stream: |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 863 | print("") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 864 | print("%s%s;" % (function_attrs, o.get_event_cb_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 865 | elif hasattr(o, "get_swap_to_be_func_def"): |
| 866 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 867 | print("") |
| 868 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 869 | print("#endif") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 870 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 871 | emitted.append(o) |
| 872 | |
| 873 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 874 | def gen_json_unified_header(parser, logger, j, io, name): |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 875 | d, f = os.path.split(j) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 876 | logger.info("Generating header `%s'" % name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 877 | orig_stdout = sys.stdout |
| 878 | sys.stdout = io |
| 879 | include_guard = "__included_%s" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 880 | j.replace(".", "_") |
| 881 | .replace("/", "_") |
| 882 | .replace("-", "_") |
| 883 | .replace("+", "_") |
| 884 | .replace("@", "_") |
| 885 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 886 | print("#ifndef %s" % include_guard) |
| 887 | print("#define %s" % include_guard) |
| 888 | print("") |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 889 | print("#include <stdlib.h>") |
| 890 | print("#include <stddef.h>") |
| 891 | print("#include <arpa/inet.h>") |
| 892 | print("#include <vapi/vapi_internal.h>") |
| 893 | print("#include <vapi/vapi.h>") |
| 894 | print("#include <vapi/vapi_dbg.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 895 | print("") |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 896 | print("#ifdef __cplusplus") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 897 | print('extern "C" {') |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 898 | print("#endif") |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 899 | |
| 900 | print("#ifndef __vl_api_string_swap_fns_defined__") |
| 901 | print("#define __vl_api_string_swap_fns_defined__") |
| 902 | print("") |
| 903 | print("#include <vlibapi/api_types.h>") |
| 904 | print("") |
| 905 | function_attrs = "static inline " |
| 906 | o = parser.types["vl_api_string_t"] |
| 907 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 908 | print("") |
| 909 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
| 910 | print("") |
| 911 | print("#endif //__vl_api_string_swap_fns_defined__") |
| 912 | |
Filip Tehlar | f0e67d7 | 2021-07-23 22:03:05 +0000 | [diff] [blame] | 913 | if name == "memclnt.api.vapi.h": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 914 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 915 | print( |
| 916 | "static inline vapi_error_e vapi_send_with_control_ping " |
| 917 | "(vapi_ctx_t ctx, void * msg, u32 context);" |
| 918 | ) |
Dave Wallace | 6081dda | 2022-02-23 15:36:02 -0500 | [diff] [blame] | 919 | elif name == "vlib.api.vapi.h": |
| 920 | print("#include <vapi/memclnt.api.vapi.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 921 | else: |
Florin Coras | a1400ce | 2021-09-15 09:02:08 -0700 | [diff] [blame] | 922 | print("#include <vapi/vlib.api.vapi.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 923 | print("") |
| 924 | for m in parser.messages_by_json[j].values(): |
| 925 | print("extern vapi_msg_id_t %s;" % m.get_msg_id_name()) |
| 926 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 927 | print( |
| 928 | "#define DEFINE_VAPI_MSG_IDS_%s\\" |
| 929 | % f.replace(".", "_").replace("/", "_").replace("-", "_").upper() |
| 930 | ) |
| 931 | print( |
| 932 | "\\\n".join( |
| 933 | [ |
| 934 | " vapi_msg_id_t %s;" % m.get_msg_id_name() |
| 935 | for m in parser.messages_by_json[j].values() |
| 936 | ] |
| 937 | ) |
| 938 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 939 | print("") |
| 940 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 941 | emitted = [] |
| 942 | for e in parser.enums_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 943 | emit_definition(parser, j, emitted, e) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 944 | for u in parser.unions_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 945 | emit_definition(parser, j, emitted, u) |
Ole Troan | 52ca756 | 2018-03-06 17:45:32 +0100 | [diff] [blame] | 946 | for t in parser.types_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 947 | emit_definition(parser, j, emitted, t) |
Ole Troan | 75761b9 | 2019-09-11 17:49:08 +0200 | [diff] [blame] | 948 | for a in parser.aliases_by_json[j]: |
| 949 | emit_definition(parser, j, emitted, a) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 950 | for m in parser.messages_by_json[j].values(): |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 951 | emit_definition(parser, j, emitted, m) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 952 | |
| 953 | print("") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 954 | |
Florin Coras | a1400ce | 2021-09-15 09:02:08 -0700 | [diff] [blame] | 955 | if name == "vlib.api.vapi.h": |
Dave Wallace | 6081dda | 2022-02-23 15:36:02 -0500 | [diff] [blame] | 956 | vapi_send_with_control_ping_function = """ |
| 957 | static inline vapi_error_e |
| 958 | vapi_send_with_control_ping (vapi_ctx_t ctx, void *msg, u32 context) |
| 959 | { |
| 960 | vapi_msg_control_ping *ping = vapi_alloc_control_ping (ctx); |
| 961 | if (!ping) |
| 962 | { |
| 963 | return VAPI_ENOMEM; |
| 964 | } |
| 965 | ping->header.context = context; |
| 966 | vapi_msg_control_ping_hton (ping); |
| 967 | return vapi_send2 (ctx, msg, ping); |
| 968 | } |
| 969 | """ |
| 970 | print("%s" % vapi_send_with_control_ping_function) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 971 | print("") |
| 972 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 973 | print("#ifdef __cplusplus") |
| 974 | print("}") |
| 975 | print("#endif") |
| 976 | print("") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 977 | print("#endif") |
| 978 | sys.stdout = orig_stdout |
| 979 | |
| 980 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 981 | def json_to_c_header_name(json_name): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 982 | if json_name.endswith(".json"): |
| 983 | return "%s.vapi.h" % os.path.splitext(json_name)[0] |
| 984 | raise Exception("Unexpected json name `%s'!" % json_name) |
| 985 | |
| 986 | |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 987 | def gen_c_unified_headers(parser, logger, prefix, remove_path): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 988 | if prefix == "" or prefix is None: |
| 989 | prefix = "" |
| 990 | else: |
| 991 | prefix = "%s/" % prefix |
| 992 | for j in parser.json_files: |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 993 | if remove_path: |
| 994 | d, f = os.path.split(j) |
| 995 | else: |
| 996 | f = j |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 997 | with open("%s%s" % (prefix, json_to_c_header_name(f)), "w") as io: |
| 998 | gen_json_unified_header(parser, logger, j, io, json_to_c_header_name(f)) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 999 | |
| 1000 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1001 | if __name__ == "__main__": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1002 | try: |
| 1003 | verbose = int(os.getenv("V", 0)) |
| 1004 | except: |
| 1005 | verbose = 0 |
| 1006 | |
| 1007 | if verbose >= 2: |
| 1008 | log_level = 10 |
| 1009 | elif verbose == 1: |
| 1010 | log_level = 20 |
| 1011 | else: |
| 1012 | log_level = 40 |
| 1013 | |
| 1014 | logging.basicConfig(stream=sys.stdout, level=log_level) |
| 1015 | logger = logging.getLogger("VAPI C GEN") |
| 1016 | logger.setLevel(log_level) |
| 1017 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 1018 | argparser = argparse.ArgumentParser(description="VPP C API generator") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1019 | argparser.add_argument( |
| 1020 | "files", |
| 1021 | metavar="api-file", |
| 1022 | action="append", |
| 1023 | type=str, |
| 1024 | help="json api file" "(may be specified multiple times)", |
| 1025 | ) |
| 1026 | argparser.add_argument("--prefix", action="store", default=None, help="path prefix") |
| 1027 | argparser.add_argument( |
| 1028 | "--remove-path", action="store_true", help="remove path from filename" |
| 1029 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1030 | args = argparser.parse_args() |
| 1031 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1032 | jsonparser = JsonParser( |
| 1033 | logger, |
| 1034 | args.files, |
| 1035 | simple_type_class=CSimpleType, |
| 1036 | enum_class=CEnum, |
| 1037 | union_class=CUnion, |
| 1038 | struct_type_class=CStructType, |
| 1039 | field_class=CField, |
| 1040 | message_class=CMessage, |
| 1041 | alias_class=CAlias, |
| 1042 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1043 | |
| 1044 | # not using the model of having separate generated header and code files |
| 1045 | # with generated symbols present in shared library (per discussion with |
| 1046 | # Damjan), to avoid symbol version issues in .so |
| 1047 | # gen_c_headers_and_code(jsonparser, logger, args.prefix) |
| 1048 | |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1049 | gen_c_unified_headers(jsonparser, logger, args.prefix, args.remove_path) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1050 | |
| 1051 | for e in jsonparser.exceptions: |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1052 | logger.warning(e) |