blob: 2978ebd207744e90eb33975037f6b5de1ee1d10b [file] [log] [blame]
Ole Troan1b1ccad2019-10-25 18:30:40 +02001#!/usr/bin/env python3
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02002
3import argparse
Klement Sekeraa25ce962021-11-15 15:52:37 +01004import inspect
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02005import os
6import sys
7import logging
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02008from vapi_json_parser import (
9 Field,
10 Struct,
11 Enum,
12 Union,
13 Message,
14 JsonParser,
15 SimpleType,
16 StructType,
17 Alias,
18)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020019
20
21class CField(Field):
Ole Troan53fffa12018-11-13 12:36:56 +010022 def get_c_name(self):
Ole Troan8c8acc02018-11-27 10:05:23 +010023 return "vapi_type_%s" % self.name
Ole Troan53fffa12018-11-13 12:36:56 +010024
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020025 def get_c_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020026 if self.type.get_c_name() == "vl_api_string_t":
Ole Troane5ff5a32019-08-23 22:55:18 +020027 if self.len:
28 return "u8 %s[%d];" % (self.name, self.len)
29 else:
30 return "vl_api_string_t %s;" % (self.name)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020031 else:
Paul Vinciguerrad7a32eb2020-05-01 10:09:58 -040032 if self.len is not None and type(self.len) != dict:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 return "%s %s[%d];" % (self.type.get_c_name(), self.name, self.len)
Ole Troane5ff5a32019-08-23 22:55:18 +020034 else:
35 return "%s %s;" % (self.type.get_c_name(), self.name)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020036
37 def get_swap_to_be_code(self, struct, var):
Paul Vinciguerrad7a32eb2020-05-01 10:09:58 -040038 if self.len is not None and type(self.len) != dict:
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020039 if self.len > 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020040 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 Sekera8f2a4ea2017-05-04 06:15:18 +020045 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 Sekerad9b0c6f2022-04-26 19:02:15 +020049 struct,
50 self.nelem_field.name,
51 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020052 else:
53 nelem_field = "%s%s" % (struct, self.nelem_field.name)
54 return (
Klement Sekeradc15be22017-06-12 06:49:33 +020055 "do { unsigned i; for (i = 0; i < %s; ++i) { %s } }"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020056 " while(0);"
57 % (
58 nelem_field,
59 self.type.get_swap_to_be_code(struct, "%s[i]" % var),
60 )
61 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020062 return self.type.get_swap_to_be_code(struct, "%s" % var)
63
64 def get_swap_to_host_code(self, struct, var):
Paul Vinciguerrad7a32eb2020-05-01 10:09:58 -040065 if self.len is not None and type(self.len) != dict:
Klement Sekera8f2a4ea2017-05-04 06:15:18 +020066 if self.len > 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020067 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 Sekera8f2a4ea2017-05-04 06:15:18 +020072 else:
73 # nelem_field already swapped to host here...
74 return (
Klement Sekeradc15be22017-06-12 06:49:33 +020075 "do { unsigned i; for (i = 0; i < %s%s; ++i) { %s } }"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 " 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 Sekera8f2a4ea2017-05-04 06:15:18 +020083 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 Sekera34a962b2018-09-06 19:31:36 +020088 def get_vla_field_length_name(self, path):
89 return "%s_%s_array_size" % ("_".join(path), self.name)
90
91 def get_alloc_vla_param_names(self, path):
92 if self.is_vla():
93 result = [self.get_vla_field_length_name(path)]
94 else:
95 result = []
96 if self.type.has_vla():
97 t = self.type.get_alloc_vla_param_names(path + [self.name])
98 result.extend(t)
99 return result
100
101 def get_vla_calc_size_code(self, prefix, path):
102 if self.is_vla():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200103 result = [
104 "sizeof(%s.%s[0]) * %s"
105 % (
106 ".".join([prefix] + path),
107 self.name,
108 self.get_vla_field_length_name(path),
109 )
110 ]
Klement Sekera34a962b2018-09-06 19:31:36 +0200111 else:
112 result = []
113 if self.type.has_vla():
114 t = self.type.get_vla_calc_size_code(prefix, path + [self.name])
115 result.extend(t)
116 return result
117
118 def get_vla_assign_code(self, prefix, path):
119 result = []
120 if self.is_vla():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200121 result.append(
122 "%s.%s = %s"
123 % (
124 ".".join([prefix] + path),
125 self.nelem_field.name,
126 self.get_vla_field_length_name(path),
127 )
128 )
Klement Sekera34a962b2018-09-06 19:31:36 +0200129 if self.type.has_vla():
130 t = self.type.get_vla_assign_code(prefix, path + [self.name])
131 result.extend(t)
132 return result
133
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200134
Ole Troan53fffa12018-11-13 12:36:56 +0100135class CAlias(CField):
136 def get_c_name(self):
Ole Troan8c8acc02018-11-27 10:05:23 +0100137 return "vapi_type_%s" % self.name
Ole Troan53fffa12018-11-13 12:36:56 +0100138
139 def get_c_def(self):
Ole Troan8c8acc02018-11-27 10:05:23 +0100140 if self.len is not None:
Klement Sekera173e20c2018-12-12 12:57:32 +0100141 return "typedef %s vapi_type_%s[%d];" % (
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200142 self.type.get_c_name(),
143 self.name,
144 self.len,
145 )
Ole Troan8c8acc02018-11-27 10:05:23 +0100146 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200147 return "typedef %s vapi_type_%s;" % (self.type.get_c_name(), self.name)
Ole Troan53fffa12018-11-13 12:36:56 +0100148
149
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200150class CStruct(Struct):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200151 def get_c_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200152 return "\n".join(
153 [
154 "typedef struct __attribute__((__packed__)) {\n%s"
155 % ("\n".join([" %s" % x.get_c_def() for x in self.fields])),
156 "} %s;" % self.get_c_name(),
157 ]
158 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200159
Klement Sekera34a962b2018-09-06 19:31:36 +0200160 def get_vla_assign_code(self, prefix, path):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200161 return [
162 x
163 for f in self.fields
164 if f.has_vla()
165 for x in f.get_vla_assign_code(prefix, path)
166 ]
Klement Sekera34a962b2018-09-06 19:31:36 +0200167
168 def get_alloc_vla_param_names(self, path):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200169 return [
170 x
171 for f in self.fields
172 if f.has_vla()
173 for x in f.get_alloc_vla_param_names(path)
174 ]
Klement Sekera34a962b2018-09-06 19:31:36 +0200175
176 def get_vla_calc_size_code(self, prefix, path):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200177 return [
178 x
179 for f in self.fields
180 if f.has_vla()
181 for x in f.get_vla_calc_size_code(prefix, path)
182 ]
Klement Sekera34a962b2018-09-06 19:31:36 +0200183
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200184
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200185class CSimpleType(SimpleType):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200186
187 swap_to_be_dict = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200188 "i16": "htobe16",
189 "u16": "htobe16",
190 "i32": "htobe32",
191 "u32": "htobe32",
192 "i64": "htobe64",
193 "u64": "htobe64",
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200194 }
195
196 swap_to_host_dict = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200197 "i16": "be16toh",
198 "u16": "be16toh",
199 "i32": "be32toh",
200 "u32": "be32toh",
201 "i64": "be64toh",
202 "u64": "be64toh",
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200203 }
204
Neale Rannsb5c0d352020-04-22 16:06:45 +0000205 __packed = "__attribute__((packed))"
206 pack_dict = {
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200207 "i8": __packed,
208 "u8": __packed,
209 "i16": __packed,
210 "u16": __packed,
Neale Rannsb5c0d352020-04-22 16:06:45 +0000211 }
212
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200213 def get_c_name(self):
214 return self.name
215
216 def get_swap_to_be_func_name(self):
217 return self.swap_to_be_dict[self.name]
218
219 def get_swap_to_host_func_name(self):
220 return self.swap_to_host_dict[self.name]
221
Neale Rannsb5c0d352020-04-22 16:06:45 +0000222 def get_packed_string(self):
223 return self.pack_dict[self.name]
224
Klement Sekera2108c0c2018-08-24 11:43:20 +0200225 def get_swap_to_be_code(self, struct, var, cast=None):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200226 x = "%s%s" % (struct, var)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 return "%s = %s%s(%s);" % (
228 x,
229 "(%s)" % cast if cast else "",
230 self.get_swap_to_be_func_name(),
231 x,
232 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200233
Klement Sekera2108c0c2018-08-24 11:43:20 +0200234 def get_swap_to_host_code(self, struct, var, cast=None):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200235 x = "%s%s" % (struct, var)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200236 return "%s = %s%s(%s);" % (
237 x,
238 "(%s)" % cast if cast else "",
239 self.get_swap_to_host_func_name(),
240 x,
241 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200242
243 def needs_byte_swap(self):
244 try:
245 self.get_swap_to_host_func_name()
246 return True
Ole Troan53fffa12018-11-13 12:36:56 +0100247 except KeyError:
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200248 pass
249 return False
250
Neale Rannsb5c0d352020-04-22 16:06:45 +0000251 def get_packed(self):
252 return self.pack_dict.get(self.name, "")
253
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200254
Klement Sekera2108c0c2018-08-24 11:43:20 +0200255class CEnum(Enum):
256 def get_c_name(self):
257 return "vapi_enum_%s" % self.name
258
259 def get_c_def(self):
Neale Rannsb5c0d352020-04-22 16:06:45 +0000260 return "typedef enum {\n%s\n} %s %s;" % (
Klement Sekera2108c0c2018-08-24 11:43:20 +0200261 "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]),
Neale Rannsb5c0d352020-04-22 16:06:45 +0000262 self.type.get_packed(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200263 self.get_c_name(),
Klement Sekera2108c0c2018-08-24 11:43:20 +0200264 )
265
266 def needs_byte_swap(self):
267 return self.type.needs_byte_swap()
268
269 def get_swap_to_be_code(self, struct, var):
270 return self.type.get_swap_to_be_code(struct, var, self.get_c_name())
271
272 def get_swap_to_host_code(self, struct, var):
273 return self.type.get_swap_to_host_code(struct, var, self.get_c_name())
274
275
276class CUnion(Union):
277 def get_c_name(self):
278 return "vapi_union_%s" % self.name
279
280 def get_c_def(self):
281 return "typedef union {\n%s\n} %s;" % (
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200282 "\n".join([" %s %s;" % (i.get_c_name(), j) for i, j in self.type_pairs]),
283 self.get_c_name(),
Klement Sekera2108c0c2018-08-24 11:43:20 +0200284 )
285
286 def needs_byte_swap(self):
287 return False
288
289
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200290class CStructType(StructType, CStruct):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200291 def get_c_name(self):
292 return "vapi_type_%s" % self.name
293
294 def get_swap_to_be_func_name(self):
295 return "%s_hton" % self.get_c_name()
296
297 def get_swap_to_host_func_name(self):
298 return "%s_ntoh" % self.get_c_name()
299
300 def get_swap_to_be_func_decl(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200301 return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name())
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200302
303 def get_swap_to_be_func_def(self):
304 return "%s\n{\n%s\n}" % (
305 self.get_swap_to_be_func_decl(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200306 "\n".join(
307 [
308 " %s" % p.get_swap_to_be_code("msg->", "%s" % p.name)
309 for p in self.fields
310 if p.needs_byte_swap()
311 ]
312 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200313 )
314
315 def get_swap_to_host_func_decl(self):
316 return "void %s(%s *msg)" % (
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200317 self.get_swap_to_host_func_name(),
318 self.get_c_name(),
319 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200320
321 def get_swap_to_host_func_def(self):
322 return "%s\n{\n%s\n}" % (
323 self.get_swap_to_host_func_decl(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200324 "\n".join(
325 [
326 " %s" % p.get_swap_to_host_code("msg->", "%s" % p.name)
327 for p in self.fields
328 if p.needs_byte_swap()
329 ]
330 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200331 )
332
333 def get_swap_to_be_code(self, struct, var):
334 return "%s(&%s%s);" % (self.get_swap_to_be_func_name(), struct, var)
335
336 def get_swap_to_host_code(self, struct, var):
337 return "%s(&%s%s);" % (self.get_swap_to_host_func_name(), struct, var)
338
339 def needs_byte_swap(self):
340 for f in self.fields:
341 if f.needs_byte_swap():
342 return True
343 return False
344
345
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200346class CMessage(Message):
Klement Sekera2108c0c2018-08-24 11:43:20 +0200347 def __init__(self, logger, definition, json_parser):
348 super(CMessage, self).__init__(logger, definition, json_parser)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200349 self.payload_members = [
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200350 " %s" % p.get_c_def() for p in self.fields if p.type != self.header
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200351 ]
352
353 def has_payload(self):
354 return len(self.payload_members) > 0
355
356 def get_msg_id_name(self):
357 return "vapi_msg_id_%s" % self.name
358
359 def get_c_name(self):
360 return "vapi_msg_%s" % self.name
361
362 def get_payload_struct_name(self):
363 return "vapi_payload_%s" % self.name
364
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200365 def get_alloc_func_name(self):
366 return "vapi_alloc_%s" % self.name
367
Klement Sekeradc15be22017-06-12 06:49:33 +0200368 def get_alloc_vla_param_names(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200369 return [
370 x
371 for f in self.fields
372 if f.has_vla()
373 for x in f.get_alloc_vla_param_names([])
374 ]
Klement Sekeradc15be22017-06-12 06:49:33 +0200375
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200376 def get_alloc_func_decl(self):
377 return "%s* %s(struct vapi_ctx_s *ctx%s)" % (
378 self.get_c_name(),
379 self.get_alloc_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200380 "".join([", size_t %s" % n for n in self.get_alloc_vla_param_names()]),
381 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200382
383 def get_alloc_func_def(self):
384 extra = []
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200385 if self.header.has_field("client_index"):
386 extra.append(" msg->header.client_index = vapi_get_client_index(ctx);")
387 if self.header.has_field("context"):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200388 extra.append(" msg->header.context = 0;")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200389 return "\n".join(
390 [
391 "%s" % self.get_alloc_func_decl(),
392 "{",
393 " %s *msg = NULL;" % self.get_c_name(),
394 " const size_t size = sizeof(%s)%s;"
395 % (
396 self.get_c_name(),
397 "".join(
398 [
399 " + %s" % x
400 for f in self.fields
401 if f.has_vla()
402 for x in f.get_vla_calc_size_code("msg->payload", [])
403 ]
404 ),
405 ),
406 " /* cast here required to play nicely with C++ world ... */",
407 " msg = (%s*)vapi_msg_alloc(ctx, size);" % self.get_c_name(),
408 " if (!msg) {",
409 " return NULL;",
410 " }",
411 ]
412 + extra
413 + [
414 " msg->header._vl_msg_id = vapi_lookup_vl_msg_id(ctx, %s);"
415 % self.get_msg_id_name(),
416 "".join(
417 [
418 " %s;\n" % line
419 for f in self.fields
420 if f.has_vla()
421 for line in f.get_vla_assign_code("msg->payload", [])
422 ]
423 ),
424 " return msg;",
425 "}",
426 ]
427 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200428
429 def get_calc_msg_size_func_name(self):
430 return "vapi_calc_%s_msg_size" % self.name
431
432 def get_calc_msg_size_func_decl(self):
433 return "uword %s(%s *msg)" % (
434 self.get_calc_msg_size_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200435 self.get_c_name(),
436 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200437
438 def get_calc_msg_size_func_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200439 return "\n".join(
440 [
441 "%s" % self.get_calc_msg_size_func_decl(),
442 "{",
443 " return sizeof(*msg)%s;"
444 % "".join(
445 [
446 "+ msg->payload.%s * sizeof(msg->payload.%s[0])"
447 % (f.nelem_field.name, f.name)
448 for f in self.fields
449 if f.nelem_field is not None
450 ]
451 ),
452 "}",
453 ]
454 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200455
Klement Sekeraa25ce962021-11-15 15:52:37 +0100456 def get_verify_msg_size_func_name(self):
457 return f"vapi_verify_{self.name}_msg_size"
458
459 def get_verify_msg_size_func_decl(self):
460 return "int %s(%s *msg, uword buf_size)" % (
461 self.get_verify_msg_size_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200462 self.get_c_name(),
463 )
Klement Sekeraa25ce962021-11-15 15:52:37 +0100464
465 def get_verify_msg_size_func_def(self):
466 return inspect.cleandoc(
467 f"""
468 {self.get_verify_msg_size_func_decl()}
469 {{
470 if (sizeof({self.get_c_name()}) > buf_size)
471 {{
472 VAPI_ERR("Truncated '{self.name}' msg received, received %lu"
473 "bytes, expected %lu bytes.", buf_size,
474 sizeof({self.get_c_name()}));
475 return -1;
476 }}
477 if ({self.get_calc_msg_size_func_name()}(msg) > buf_size)
478 {{
479 VAPI_ERR("Truncated '{self.name}' msg received, received %lu"
480 "bytes, expected %lu bytes.", buf_size,
481 sizeof({self.get_calc_msg_size_func_name()}));
482 return -1;
483 }}
484 return 0;
485 }}
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200486 """
487 )
Klement Sekeraa25ce962021-11-15 15:52:37 +0100488
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200489 def get_c_def(self):
490 if self.has_payload():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200491 return "\n".join(
492 [
493 "typedef struct __attribute__ ((__packed__)) {",
494 "%s " % "\n".join(self.payload_members),
495 "} %s;" % self.get_payload_struct_name(),
496 "",
497 "typedef struct __attribute__ ((__packed__)) {",
498 (
499 " %s %s;" % (self.header.get_c_name(), self.fields[0].name)
500 if self.header is not None
501 else ""
502 ),
503 " %s payload;" % self.get_payload_struct_name(),
504 "} %s;" % self.get_c_name(),
505 ]
506 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200507 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200508 return "\n".join(
509 [
510 "typedef struct __attribute__ ((__packed__)) {",
511 (
512 " %s %s;" % (self.header.get_c_name(), self.fields[0].name)
513 if self.header is not None
514 else ""
515 ),
516 "} %s;" % self.get_c_name(),
517 ]
518 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200519
520 def get_swap_payload_to_host_func_name(self):
521 return "%s_payload_ntoh" % self.get_c_name()
522
523 def get_swap_payload_to_be_func_name(self):
524 return "%s_payload_hton" % self.get_c_name()
525
526 def get_swap_payload_to_host_func_decl(self):
527 return "void %s(%s *payload)" % (
528 self.get_swap_payload_to_host_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200529 self.get_payload_struct_name(),
530 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200531
532 def get_swap_payload_to_be_func_decl(self):
533 return "void %s(%s *payload)" % (
534 self.get_swap_payload_to_be_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200535 self.get_payload_struct_name(),
536 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200537
538 def get_swap_payload_to_be_func_def(self):
539 return "%s\n{\n%s\n}" % (
540 self.get_swap_payload_to_be_func_decl(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200541 "\n".join(
542 [
543 " %s" % p.get_swap_to_be_code("payload->", "%s" % p.name)
544 for p in self.fields
545 if p.needs_byte_swap() and p.type != self.header
546 ]
547 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200548 )
549
550 def get_swap_payload_to_host_func_def(self):
551 return "%s\n{\n%s\n}" % (
552 self.get_swap_payload_to_host_func_decl(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200553 "\n".join(
554 [
555 " %s" % p.get_swap_to_host_code("payload->", "%s" % p.name)
556 for p in self.fields
557 if p.needs_byte_swap() and p.type != self.header
558 ]
559 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200560 )
561
562 def get_swap_to_host_func_name(self):
563 return "%s_ntoh" % self.get_c_name()
564
565 def get_swap_to_be_func_name(self):
566 return "%s_hton" % self.get_c_name()
567
568 def get_swap_to_host_func_decl(self):
569 return "void %s(%s *msg)" % (
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200570 self.get_swap_to_host_func_name(),
571 self.get_c_name(),
572 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200573
574 def get_swap_to_be_func_decl(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200575 return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name())
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200576
577 def get_swap_to_be_func_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200578 return "\n".join(
579 [
580 "%s" % self.get_swap_to_be_func_decl(),
581 "{",
582 (
583 ' VAPI_DBG("Swapping `%s\'@%%p to big endian", msg);'
584 % self.get_c_name()
585 ),
586 " %s(&msg->header);" % self.header.get_swap_to_be_func_name()
587 if self.header is not None
588 else "",
589 " %s(&msg->payload);" % self.get_swap_payload_to_be_func_name()
590 if self.has_payload()
591 else "",
592 "}",
593 ]
594 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200595
596 def get_swap_to_host_func_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200597 return "\n".join(
598 [
599 "%s" % self.get_swap_to_host_func_decl(),
600 "{",
601 (
602 ' VAPI_DBG("Swapping `%s\'@%%p to host byte order", msg);'
603 % self.get_c_name()
604 ),
605 " %s(&msg->header);" % self.header.get_swap_to_host_func_name()
606 if self.header is not None
607 else "",
608 " %s(&msg->payload);" % self.get_swap_payload_to_host_func_name()
609 if self.has_payload()
610 else "",
611 "}",
612 ]
613 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200614
615 def get_op_func_name(self):
616 return "vapi_%s" % self.name
617
618 def get_op_func_decl(self):
619 if self.reply.has_payload():
620 return "vapi_error_e %s(%s)" % (
621 self.get_op_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200622 ",\n ".join(
623 [
624 "struct vapi_ctx_s *ctx",
625 "%s *msg" % self.get_c_name(),
626 "vapi_error_e (*callback)(struct vapi_ctx_s *ctx",
627 " void *callback_ctx",
628 " vapi_error_e rv",
629 " bool is_last",
630 " %s *reply)"
631 % self.reply.get_payload_struct_name(),
632 "void *callback_ctx",
633 ]
634 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200635 )
636 else:
637 return "vapi_error_e %s(%s)" % (
638 self.get_op_func_name(),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200639 ",\n ".join(
640 [
641 "struct vapi_ctx_s *ctx",
642 "%s *msg" % self.get_c_name(),
643 "vapi_error_e (*callback)(struct vapi_ctx_s *ctx",
644 " void *callback_ctx",
645 " vapi_error_e rv",
646 " bool is_last)",
647 "void *callback_ctx",
648 ]
649 ),
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200650 )
651
652 def get_op_func_def(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200653 return "\n".join(
654 [
655 "%s" % self.get_op_func_decl(),
656 "{",
657 " if (!msg || !callback) {",
658 " return VAPI_EINVAL;",
659 " }",
660 " if (vapi_is_nonblocking(ctx) && vapi_requests_full(ctx)) {",
661 " return VAPI_EAGAIN;",
662 " }",
663 " vapi_error_e rv;",
664 " if (VAPI_OK != (rv = vapi_producer_lock (ctx))) {",
665 " return rv;",
666 " }",
667 " u32 req_context = vapi_gen_req_context(ctx);",
668 " msg->header.context = req_context;",
669 " %s(msg);" % self.get_swap_to_be_func_name(),
670 (
671 " if (VAPI_OK == (rv = vapi_send_with_control_ping "
672 "(ctx, msg, req_context))) {"
673 if self.reply_is_stream
674 else " if (VAPI_OK == (rv = vapi_send (ctx, msg))) {"
675 ),
676 (
677 " vapi_store_request(ctx, req_context, %s, "
678 "(vapi_cb_t)callback, callback_ctx);"
679 % ("true" if self.reply_is_stream else "false")
680 ),
681 " if (VAPI_OK != vapi_producer_unlock (ctx)) {",
682 " abort (); /* this really shouldn't happen */",
683 " }",
684 " if (vapi_is_nonblocking(ctx)) {",
685 " rv = VAPI_OK;",
686 " } else {",
687 " rv = vapi_dispatch(ctx);",
688 " }",
689 " } else {",
690 " %s(msg);" % self.get_swap_to_host_func_name(),
691 " if (VAPI_OK != vapi_producer_unlock (ctx)) {",
692 " abort (); /* this really shouldn't happen */",
693 " }",
694 " }",
695 " return rv;",
696 "}",
697 "",
698 ]
699 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200700
701 def get_event_cb_func_decl(self):
Klement Sekera2108c0c2018-08-24 11:43:20 +0200702 if not self.is_reply and not self.is_event:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200703 raise Exception("Cannot register event callback for non-reply message")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200704 if self.has_payload():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200705 return "\n".join(
706 [
707 "void vapi_set_%s_event_cb (" % self.get_c_name(),
708 " struct vapi_ctx_s *ctx, ",
709 (
710 " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, "
711 "void *callback_ctx, %s *payload),"
712 % self.get_payload_struct_name()
713 ),
714 " void *callback_ctx)",
715 ]
716 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200717 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200718 return "\n".join(
719 [
720 "void vapi_set_%s_event_cb (" % self.get_c_name(),
721 " struct vapi_ctx_s *ctx, ",
722 " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, "
723 "void *callback_ctx),",
724 " void *callback_ctx)",
725 ]
726 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200727
728 def get_event_cb_func_def(self):
Klement Sekera2108c0c2018-08-24 11:43:20 +0200729 if not self.is_reply and not self.is_event:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200730 raise Exception("Cannot register event callback for non-reply function")
731 return "\n".join(
732 [
733 "%s" % self.get_event_cb_func_decl(),
734 "{",
735 (
736 " vapi_set_event_cb(ctx, %s, (vapi_event_cb)callback, "
737 "callback_ctx);" % self.get_msg_id_name()
738 ),
739 "}",
740 ]
741 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200742
743 def get_c_metadata_struct_name(self):
744 return "__vapi_metadata_%s" % self.name
745
746 def get_c_constructor(self):
747 has_context = False
748 if self.header is not None:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200749 has_context = self.header.has_field("context")
750 return "\n".join(
751 [
752 "static void __attribute__((constructor)) __vapi_constructor_%s()"
753 % self.name,
754 "{",
755 ' static const char name[] = "%s";' % self.name,
756 ' static const char name_with_crc[] = "%s_%s";'
757 % (self.name, self.crc[2:]),
758 " static vapi_message_desc_t %s = {"
759 % self.get_c_metadata_struct_name(),
760 " name,",
761 " sizeof(name) - 1,",
762 " name_with_crc,",
763 " sizeof(name_with_crc) - 1,",
764 " true," if has_context else " false,",
765 " offsetof(%s, context)," % self.header.get_c_name()
766 if has_context
767 else " 0,",
768 (" offsetof(%s, payload)," % self.get_c_name())
769 if self.has_payload()
770 else " VAPI_INVALID_MSG_ID,",
771 " (verify_msg_size_fn_t)%s," % self.get_verify_msg_size_func_name(),
772 " (generic_swap_fn_t)%s," % self.get_swap_to_be_func_name(),
773 " (generic_swap_fn_t)%s," % self.get_swap_to_host_func_name(),
774 " VAPI_INVALID_MSG_ID,",
775 " };",
776 "",
777 " %s = vapi_register_msg(&%s);"
778 % (self.get_msg_id_name(), self.get_c_metadata_struct_name()),
779 ' VAPI_DBG("Assigned msg id %%d to %s", %s);'
780 % (self.name, self.get_msg_id_name()),
781 "}",
782 ]
783 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200784
785
Klement Sekera1732e472018-08-28 17:23:18 +0200786def emit_definition(parser, json_file, emitted, o):
Klement Sekera2108c0c2018-08-24 11:43:20 +0200787 if o in emitted:
788 return
Klement Sekera2108c0c2018-08-24 11:43:20 +0200789 if o.name in ("msg_header1_t", "msg_header2_t"):
790 return
791 if hasattr(o, "depends"):
792 for x in o.depends:
Klement Sekera1732e472018-08-28 17:23:18 +0200793 emit_definition(parser, json_file, emitted, x)
Klement Sekera2108c0c2018-08-24 11:43:20 +0200794 if hasattr(o, "reply"):
Klement Sekera1732e472018-08-28 17:23:18 +0200795 emit_definition(parser, json_file, emitted, o.reply)
Klement Sekera2108c0c2018-08-24 11:43:20 +0200796 if hasattr(o, "get_c_def"):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200797 if (
798 o not in parser.enums_by_json[json_file]
799 and o not in parser.types_by_json[json_file]
800 and o not in parser.unions_by_json[json_file]
801 and o.name not in parser.messages_by_json[json_file]
802 and o not in parser.aliases_by_json[json_file]
803 ):
Klement Sekera2108c0c2018-08-24 11:43:20 +0200804 return
Klement Sekera2108c0c2018-08-24 11:43:20 +0200805 guard = "defined_%s" % o.get_c_name()
806 print("#ifndef %s" % guard)
807 print("#define %s" % guard)
808 print("%s" % o.get_c_def())
809 print("")
810 function_attrs = "static inline "
811 if o.name in parser.messages_by_json[json_file]:
Klement Sekera2108c0c2018-08-24 11:43:20 +0200812 if o.has_payload():
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200813 print("%s%s" % (function_attrs, o.get_swap_payload_to_be_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200814 print("")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200815 print("%s%s" % (function_attrs, o.get_swap_payload_to_host_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200816 print("")
817 print("%s%s" % (function_attrs, o.get_swap_to_be_func_def()))
818 print("")
819 print("%s%s" % (function_attrs, o.get_swap_to_host_func_def()))
820 print("")
821 print("%s%s" % (function_attrs, o.get_calc_msg_size_func_def()))
Klement Sekeraa25ce962021-11-15 15:52:37 +0100822 print("")
823 print("%s%s" % (function_attrs, o.get_verify_msg_size_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200824 if not o.is_reply and not o.is_event:
Klement Sekera34a962b2018-09-06 19:31:36 +0200825 print("")
Klement Sekera2108c0c2018-08-24 11:43:20 +0200826 print("%s%s" % (function_attrs, o.get_alloc_func_def()))
827 print("")
828 print("%s%s" % (function_attrs, o.get_op_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200829 print("")
Klement Sekera34a962b2018-09-06 19:31:36 +0200830 print("%s" % o.get_c_constructor())
Klement Sekera1732e472018-08-28 17:23:18 +0200831 if o.is_reply or o.is_event:
Klement Sekera2108c0c2018-08-24 11:43:20 +0200832 print("")
Klement Sekera34a962b2018-09-06 19:31:36 +0200833 print("%s%s;" % (function_attrs, o.get_event_cb_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200834 elif hasattr(o, "get_swap_to_be_func_def"):
835 print("%s%s" % (function_attrs, o.get_swap_to_be_func_def()))
836 print("")
837 print("%s%s" % (function_attrs, o.get_swap_to_host_func_def()))
Klement Sekera2108c0c2018-08-24 11:43:20 +0200838 print("#endif")
Klement Sekera34a962b2018-09-06 19:31:36 +0200839 print("")
Klement Sekera2108c0c2018-08-24 11:43:20 +0200840 emitted.append(o)
841
842
Klement Sekeradc15be22017-06-12 06:49:33 +0200843def gen_json_unified_header(parser, logger, j, io, name):
Damjan Marion4c64b6e2018-08-26 18:14:46 +0200844 d, f = os.path.split(j)
Klement Sekeradc15be22017-06-12 06:49:33 +0200845 logger.info("Generating header `%s'" % name)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200846 orig_stdout = sys.stdout
847 sys.stdout = io
848 include_guard = "__included_%s" % (
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200849 j.replace(".", "_")
850 .replace("/", "_")
851 .replace("-", "_")
852 .replace("+", "_")
853 .replace("@", "_")
854 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200855 print("#ifndef %s" % include_guard)
856 print("#define %s" % include_guard)
857 print("")
Klement Sekeradc15be22017-06-12 06:49:33 +0200858 print("#include <stdlib.h>")
859 print("#include <stddef.h>")
860 print("#include <arpa/inet.h>")
861 print("#include <vapi/vapi_internal.h>")
862 print("#include <vapi/vapi.h>")
863 print("#include <vapi/vapi_dbg.h>")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200864 print("")
Klement Sekeradc15be22017-06-12 06:49:33 +0200865 print("#ifdef __cplusplus")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200866 print('extern "C" {')
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200867 print("#endif")
Filip Tehlarf0e67d72021-07-23 22:03:05 +0000868 if name == "memclnt.api.vapi.h":
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200869 print("")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200870 print(
871 "static inline vapi_error_e vapi_send_with_control_ping "
872 "(vapi_ctx_t ctx, void * msg, u32 context);"
873 )
Dave Wallace6081dda2022-02-23 15:36:02 -0500874 elif name == "vlib.api.vapi.h":
875 print("#include <vapi/memclnt.api.vapi.h>")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200876 else:
Florin Corasa1400ce2021-09-15 09:02:08 -0700877 print("#include <vapi/vlib.api.vapi.h>")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200878 print("")
879 for m in parser.messages_by_json[j].values():
880 print("extern vapi_msg_id_t %s;" % m.get_msg_id_name())
881 print("")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200882 print(
883 "#define DEFINE_VAPI_MSG_IDS_%s\\"
884 % f.replace(".", "_").replace("/", "_").replace("-", "_").upper()
885 )
886 print(
887 "\\\n".join(
888 [
889 " vapi_msg_id_t %s;" % m.get_msg_id_name()
890 for m in parser.messages_by_json[j].values()
891 ]
892 )
893 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200894 print("")
895 print("")
Klement Sekera2108c0c2018-08-24 11:43:20 +0200896 emitted = []
897 for e in parser.enums_by_json[j]:
Klement Sekera1732e472018-08-28 17:23:18 +0200898 emit_definition(parser, j, emitted, e)
Klement Sekera2108c0c2018-08-24 11:43:20 +0200899 for u in parser.unions_by_json[j]:
Klement Sekera1732e472018-08-28 17:23:18 +0200900 emit_definition(parser, j, emitted, u)
Ole Troan52ca7562018-03-06 17:45:32 +0100901 for t in parser.types_by_json[j]:
Klement Sekera1732e472018-08-28 17:23:18 +0200902 emit_definition(parser, j, emitted, t)
Ole Troan75761b92019-09-11 17:49:08 +0200903 for a in parser.aliases_by_json[j]:
904 emit_definition(parser, j, emitted, a)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200905 for m in parser.messages_by_json[j].values():
Klement Sekera1732e472018-08-28 17:23:18 +0200906 emit_definition(parser, j, emitted, m)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200907
908 print("")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200909
Florin Corasa1400ce2021-09-15 09:02:08 -0700910 if name == "vlib.api.vapi.h":
Dave Wallace6081dda2022-02-23 15:36:02 -0500911 vapi_send_with_control_ping_function = """
912static inline vapi_error_e
913vapi_send_with_control_ping (vapi_ctx_t ctx, void *msg, u32 context)
914{
915 vapi_msg_control_ping *ping = vapi_alloc_control_ping (ctx);
916 if (!ping)
917 {
918 return VAPI_ENOMEM;
919 }
920 ping->header.context = context;
921 vapi_msg_control_ping_hton (ping);
922 return vapi_send2 (ctx, msg, ping);
923}
924"""
925 print("%s" % vapi_send_with_control_ping_function)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200926 print("")
927
Klement Sekeradc15be22017-06-12 06:49:33 +0200928 print("#ifdef __cplusplus")
929 print("}")
930 print("#endif")
931 print("")
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200932 print("#endif")
933 sys.stdout = orig_stdout
934
935
Klement Sekeradc15be22017-06-12 06:49:33 +0200936def json_to_c_header_name(json_name):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200937 if json_name.endswith(".json"):
938 return "%s.vapi.h" % os.path.splitext(json_name)[0]
939 raise Exception("Unexpected json name `%s'!" % json_name)
940
941
Damjan Marion4c64b6e2018-08-26 18:14:46 +0200942def gen_c_unified_headers(parser, logger, prefix, remove_path):
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200943 if prefix == "" or prefix is None:
944 prefix = ""
945 else:
946 prefix = "%s/" % prefix
947 for j in parser.json_files:
Damjan Marion4c64b6e2018-08-26 18:14:46 +0200948 if remove_path:
949 d, f = os.path.split(j)
950 else:
951 f = j
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200952 with open("%s%s" % (prefix, json_to_c_header_name(f)), "w") as io:
953 gen_json_unified_header(parser, logger, j, io, json_to_c_header_name(f))
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200954
955
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200956if __name__ == "__main__":
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200957 try:
958 verbose = int(os.getenv("V", 0))
959 except:
960 verbose = 0
961
962 if verbose >= 2:
963 log_level = 10
964 elif verbose == 1:
965 log_level = 20
966 else:
967 log_level = 40
968
969 logging.basicConfig(stream=sys.stdout, level=log_level)
970 logger = logging.getLogger("VAPI C GEN")
971 logger.setLevel(log_level)
972
Klement Sekeradc15be22017-06-12 06:49:33 +0200973 argparser = argparse.ArgumentParser(description="VPP C API generator")
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200974 argparser.add_argument(
975 "files",
976 metavar="api-file",
977 action="append",
978 type=str,
979 help="json api file" "(may be specified multiple times)",
980 )
981 argparser.add_argument("--prefix", action="store", default=None, help="path prefix")
982 argparser.add_argument(
983 "--remove-path", action="store_true", help="remove path from filename"
984 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200985 args = argparser.parse_args()
986
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200987 jsonparser = JsonParser(
988 logger,
989 args.files,
990 simple_type_class=CSimpleType,
991 enum_class=CEnum,
992 union_class=CUnion,
993 struct_type_class=CStructType,
994 field_class=CField,
995 message_class=CMessage,
996 alias_class=CAlias,
997 )
Klement Sekera8f2a4ea2017-05-04 06:15:18 +0200998
999 # not using the model of having separate generated header and code files
1000 # with generated symbols present in shared library (per discussion with
1001 # Damjan), to avoid symbol version issues in .so
1002 # gen_c_headers_and_code(jsonparser, logger, args.prefix)
1003
Damjan Marion4c64b6e2018-08-26 18:14:46 +02001004 gen_c_unified_headers(jsonparser, logger, args.prefix, args.remove_path)
Klement Sekera8f2a4ea2017-05-04 06:15:18 +02001005
1006 for e in jsonparser.exceptions:
Damjan Marion4c64b6e2018-08-26 18:14:46 +02001007 logger.warning(e)