lbkit 0.8.3__tar.gz → 0.8.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {lbkit-0.8.3/lbkit.egg-info → lbkit-0.8.4}/PKG-INFO +1 -1
  2. lbkit-0.8.4/lbkit/__init__.py +2 -0
  3. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/idf_interface.py +8 -6
  4. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/public.c.mako +247 -35
  5. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/public.h.mako +48 -0
  6. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/server.c.mako +9 -191
  7. {lbkit-0.8.3 → lbkit-0.8.4/lbkit.egg-info}/PKG-INFO +1 -1
  8. lbkit-0.8.3/lbkit/__init__.py +0 -2
  9. {lbkit-0.8.3 → lbkit-0.8.4}/AUTHORS +0 -0
  10. {lbkit-0.8.3 → lbkit-0.8.4}/LICENSE +0 -0
  11. {lbkit-0.8.3 → lbkit-0.8.4}/MANIFEST.in +0 -0
  12. {lbkit-0.8.3 → lbkit-0.8.4}/README.md +0 -0
  13. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/build_conan_parallel.py +0 -0
  14. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/ci_robot/__init__.py +0 -0
  15. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/ci_robot/gitee.py +0 -0
  16. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/cli.py +0 -0
  17. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/__init__.py +0 -0
  18. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/codegen.py +0 -0
  19. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/ctype_defination.py +0 -0
  20. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/renderer.py +0 -0
  21. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/client.c.mako +0 -0
  22. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/client.h.mako +0 -0
  23. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/interface.c.mako +0 -0
  24. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  25. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/codegen/template/server.h.mako +0 -0
  26. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/__init__.py +0 -0
  27. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/arg_parser.py +0 -0
  28. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/build.py +0 -0
  29. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/template/conanbase.mako +0 -0
  30. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/template/deploy.mako +0 -0
  31. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/component/test.py +0 -0
  32. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/errors.py +0 -0
  33. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/helper.py +0 -0
  34. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/__init__.py +0 -0
  35. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/build_image.py +0 -0
  36. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/build_manifest.py +0 -0
  37. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/build_prepare.py +0 -0
  38. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/build_rootfs.py +0 -0
  39. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/config.py +0 -0
  40. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/task.py +0 -0
  41. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/template/conanfile.py.mako +0 -0
  42. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/integration/template/rootfs.py.mako +0 -0
  43. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/lbkit.py +0 -0
  44. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/log.py +0 -0
  45. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/misc.py +0 -0
  46. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/tools.py +0 -0
  47. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/utils/__init__.py +0 -0
  48. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/utils/images/__init__.py +0 -0
  49. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit/utils/images/emmc.py +0 -0
  50. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit.egg-info/SOURCES.txt +0 -0
  51. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit.egg-info/dependency_links.txt +0 -0
  52. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit.egg-info/entry_points.txt +0 -0
  53. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit.egg-info/requires.txt +0 -0
  54. {lbkit-0.8.3 → lbkit-0.8.4}/lbkit.egg-info/top_level.txt +0 -0
  55. {lbkit-0.8.3 → lbkit-0.8.4}/setup.cfg +0 -0
  56. {lbkit-0.8.3 → lbkit-0.8.4}/setup.py +0 -0
  57. {lbkit-0.8.3 → lbkit-0.8.4}/test/__init__.py +0 -0
  58. {lbkit-0.8.3 → lbkit-0.8.4}/test/test_codegen.py +0 -0
  59. {lbkit-0.8.3 → lbkit-0.8.4}/test/test_helper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: lbkit
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: Tools provided by litebmc.com
5
5
  Home-page: https://www.litebmc.com
6
6
  Author: xuhj@litebmc.com
@@ -0,0 +1,2 @@
1
+
2
+ __version__ = '0.8.4'
@@ -19,6 +19,7 @@ class IDFException(Exception):
19
19
  class IdfInterfacePlugin(Renderer):
20
20
  def __init__(self):
21
21
  super().__init__()
22
+ self.install_dir = None
22
23
  self.actions = []
23
24
 
24
25
  class IdfInterfaceBase(Renderer):
@@ -215,9 +216,9 @@ class IdfCtypeRender():
215
216
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
216
217
  _, stru_name = get_intfname_and_ctype(match.group(2))
217
218
  if is_array:
218
- return [f"_validate_odf_as_{match.group(1)}_{stru_name}_v(doc, node, prop, error_list)"]
219
+ return [f"{stru_name}_validate_odf_v(doc, node, prop, error_list)"]
219
220
  else:
220
- return [f"_validate_odf_as_{match.group(1)}_{stru_name}(doc, node, prop, error_list)"]
221
+ return [f"{stru_name}_validate_odf(doc, node, prop, error_list)"]
221
222
 
222
223
  def odf_match_items(self):
223
224
  log.debug(f"Get odf validate info, name: {self.name}, ctype: {self.ctype}")
@@ -599,15 +600,15 @@ class IdfCtypeRender():
599
600
  if match.group(1) == "enum":
600
601
  if is_array:
601
602
  # 入参为二级指针
602
- return f"<arg_name> = _load_odf_as_{stru_name}_v(doc, <node>, &n_<arg_name>)"
603
+ return f"<arg_name> = {stru_name}_load_from_odf_v(doc, <node>, &n_<arg_name>)"
603
604
  else:
604
- return f"<arg_name> = _load_odf_as_{stru_name}(doc, <node>)"
605
+ return f"<arg_name> = {stru_name}_load_from_odf(doc, <node>)"
605
606
  else:
606
607
  if is_array:
607
608
  # 入参为二级指针
608
- return f"<arg_name> = _load_odf_as_{stru_name}_v(doc, <node>)"
609
+ return f"<arg_name> = {stru_name}_load_from_odf_v(doc, <node>)"
609
610
  else:
610
- return f"<arg_name> = _load_odf_as_{stru_name}(doc, <node>)"
611
+ return f"<arg_name> = {stru_name}_load_from_odf(doc, <node>)"
611
612
 
612
613
  @property
613
614
  def validator_cfg(self):
@@ -1288,6 +1289,7 @@ class IdfInterface(IdfInterfaceBase):
1288
1289
  self.plugin = IdfInterfacePlugin()
1289
1290
  if plugin is not None:
1290
1291
  items = plugin.get("actions", [])
1292
+ self.plugin.install_dir = plugin.get("install_dir")
1291
1293
  for item in items:
1292
1294
  obj = IdfPluginAction(self, item)
1293
1295
  self.plugin.actions.append(obj)
@@ -1,5 +1,6 @@
1
1
  #include "lb_base.h"
2
2
  #include "${intf.name}.h"
3
+ <% import re %>\
3
4
 
4
5
  <% class_name = intf.alias %>\
5
6
  ### 生成Errors错误 START
@@ -59,28 +60,7 @@ GError *${intf.alias}_Error_${name}_new(void)
59
60
  %endfor
60
61
 
61
62
  %endif
62
- ### 生成Errors错误 END
63
- ## 定义结构体ODF加载函数
64
- % for name, stru in intf.structures.items():
65
- /* ${name} structure object */
66
- /* START: 结构体${name}及其数组类型的ODF校验函数 */
67
- __unused static gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
68
- __unused static gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
69
-
70
- % endfor
71
- ## 定义枚举ODF加载函数
72
- % for name, enum in intf.enumerations.items():
73
- /* START: 枚举${name}及其数组类型的ODF校验函数 */
74
- __unused static gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
75
- __unused static gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
76
-
77
- % endfor
78
- ## 定义字典ODF加载函数
79
- % for name, dictionary in intf.dictionaries.items():
80
- __unused static gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
81
- __unused static gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
82
63
 
83
- % endfor
84
64
  % for name, stru in intf.structures.items():
85
65
  /* ${name}结构体类型序列化(struct转GVariant)函数 */
86
66
  GVariant *${name}_encode(const struct _${name} *value)
@@ -210,7 +190,7 @@ void ${name}_free_v(struct _${name} ***value)
210
190
  *value = NULL;
211
191
  }
212
192
 
213
- gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node,
193
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
214
194
  GString *prop, GSList **error_list)
215
195
  {
216
196
  g_assert(doc && node && prop && error_list);
@@ -241,7 +221,7 @@ gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node
241
221
  return valid;
242
222
  }
243
223
 
244
- gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node,
224
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node,
245
225
  GString *prop, GSList **error_list)
246
226
  {
247
227
  g_assert(doc && node && prop && error_list);
@@ -257,7 +237,7 @@ gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *no
257
237
  for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
258
238
  g_string_append_printf(prop, ".%d", i);
259
239
  val = yaml_document_get_node(doc, *item);
260
- if (!_validate_odf_as_struct_${name}(doc, val, prop, error_list)) {
240
+ if (!${name}_validate_odf(doc, val, prop, error_list)) {
261
241
  valid = FALSE;
262
242
  }
263
243
  g_string_truncate(prop, len);
@@ -320,7 +300,7 @@ static const gchar *_${name}StrMap[] = {
320
300
 
321
301
  const gchar *${name}_as_string(${name} value)
322
302
  {
323
- if (value >= _${name}Invalid) {
303
+ if (value >= _${name}_Invalid) {
324
304
  return "com.litebmc.Errors.Enum.Invalid";
325
305
  }
326
306
  return _${name}StrMap[value];
@@ -340,7 +320,7 @@ GVariant *${name}_encode(${name} value)
340
320
  ${name} ${name}_decode(GVariant *in)
341
321
  {
342
322
  if (!in) {
343
- return _${name}Invalid;
323
+ return _${name}_Invalid;
344
324
  }
345
325
 
346
326
  const gchar *in_val = g_variant_get_string(in, NULL);
@@ -349,7 +329,7 @@ ${name} ${name}_decode(GVariant *in)
349
329
  return (${name})i;
350
330
  }
351
331
  }
352
- return _${name}Invalid;
332
+ return _${name}_Invalid;
353
333
  }
354
334
 
355
335
  % endif
@@ -387,6 +367,7 @@ ${name} *${name}_decode_v(GVariant *in, gsize *n)
387
367
  }
388
368
  ${name} *output = g_new0(${name}, *n);
389
369
  while (g_variant_iter_loop(&iter, "s", &str_val)) {
370
+ output[id] = _${name}_Invalid;
390
371
  for (int i = 0; i < ${len(enum.values.parameters)}; i++) {
391
372
  if (g_strcmp0(str_val, _${name}StrMap[i]) == 0) {
392
373
  output[id++] = (${name})i;
@@ -396,7 +377,7 @@ ${name} *${name}_decode_v(GVariant *in, gsize *n)
396
377
  return output;
397
378
  }
398
379
 
399
- gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node,
380
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
400
381
  GString *prop, GSList **error_list)
401
382
  {
402
383
  gboolean valid = validate_odf_as_string(doc, node, prop, "^.*$", error_list);
@@ -410,12 +391,12 @@ gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node,
410
391
  }
411
392
  }
412
393
  *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
413
- "the value of property %s is is unsupportted, get %s", prop->str, value));
394
+ "the value of property %s is invalid, get %s", prop->str, value));
414
395
  return FALSE;
415
396
  return FALSE;
416
397
  }
417
398
 
418
- gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node,
399
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node,
419
400
  GString *prop, GSList **error_list)
420
401
  {
421
402
  g_assert(doc && node && prop && error_list);
@@ -431,7 +412,7 @@ gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node
431
412
  for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
432
413
  g_string_append_printf(prop, ".%d", i);
433
414
  val = yaml_document_get_node(doc, *item);
434
- if (!_validate_odf_as_enum_${name}(doc, val, prop, error_list)) {
415
+ if (!${name}_validate_odf(doc, val, prop, error_list)) {
435
416
  valid = FALSE;
436
417
  }
437
418
  g_string_truncate(prop, len);
@@ -440,6 +421,57 @@ gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node
440
421
  return valid;
441
422
  }
442
423
 
424
+ gboolean ${name}_check_enum_variant(LBO *obj, GVariant *value, GError **error)
425
+ {
426
+ if (!obj || !value) {
427
+ if (error)
428
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "parameter error");
429
+ return FALSE;
430
+ }
431
+ ${name} _valid = ${name}_decode(value);
432
+ if (_valid == _${name}_Invalid) {
433
+ if (error) {
434
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invlid enumeration value");
435
+ }
436
+ return FALSE;
437
+ }
438
+ return TRUE;
439
+ }
440
+
441
+ gboolean ${name}_check_enum_variant_v(LBO *obj, GVariant *value, GError **error)
442
+ {
443
+ if (!obj || !value) {
444
+ if (error)
445
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "parameter error");
446
+ return FALSE;
447
+ }
448
+ GVariantIter iter;
449
+ gchar *str_val = NULL;
450
+
451
+ (void)g_variant_iter_init(&iter, value);
452
+ while (g_variant_iter_loop(&iter, "s", &str_val)) {
453
+ gboolean valid = FALSE;
454
+ if (g_strcmp0(str_val, "_Invalid") == 0) {
455
+ if (error) {
456
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invlid enumeration value");
457
+ }
458
+ return FALSE;
459
+ }
460
+ for (int i = 0; i < ${len(enum.values.parameters)}; i++) {
461
+ if (g_strcmp0(str_val, _${name}StrMap[i]) == 0) {
462
+ valid = TRUE;
463
+ }
464
+ }
465
+ if (!valid) {
466
+ if (error) {
467
+ *error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invlid enumeration value");
468
+ }
469
+ return FALSE;
470
+ }
471
+ }
472
+ return TRUE;
473
+ }
474
+
443
475
  % endfor
444
476
  ## 生成字典处理函数
445
477
  % for name, dictionary in intf.dictionaries.items():
@@ -777,7 +809,7 @@ void ${name}_free_v(${name} ***value)
777
809
  *value = NULL;
778
810
  }
779
811
 
780
- gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node,
812
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
781
813
  GString *prop, GSList **error_list)
782
814
  {
783
815
  g_assert(doc && node && prop && error_list);
@@ -826,7 +858,7 @@ gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node,
826
858
  return valid;
827
859
  }
828
860
 
829
- gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node,
861
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node,
830
862
  GString *prop, GSList **error_list)
831
863
  {
832
864
  g_assert(doc && node && prop && error_list);
@@ -842,7 +874,7 @@ gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node
842
874
  for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
843
875
  g_string_append_printf(prop, ".%d", i);
844
876
  val = yaml_document_get_node(doc, *item);
845
- if (!_validate_odf_as_dict_${name}(doc, val, prop, error_list)) {
877
+ if (!${name}_validate_odf(doc, val, prop, error_list)) {
846
878
  valid = FALSE;
847
879
  }
848
880
  g_string_truncate(prop, len);
@@ -986,7 +1018,19 @@ static ${class_name}_Properties _${class_name}_properties =
986
1018
  % if (prop.signature in ["b", "y", "n", "q", "i", "u", "x", "t", "d", "o", "s", "g", "ab", "ay", "an", "aq", "ai", "au", "ax", "at", "ad", "as", "ao", "ag"] and prop.val_validate()):
987
1019
  .check = ${class_name}_check_${prop.name}_variant,
988
1020
  % else:
1021
+ <% match = re.match(f"^array\[enum\[(.*)\]\]$", prop.ctype) %>\
1022
+ % if match:
1023
+ <% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
1024
+ .check = ${match_enum[-1]}_check_enum_variant_v,
1025
+ % else:
1026
+ <% match = re.match(f"^enum\[(.*)\]$", prop.ctype) %>\
1027
+ % if match:
1028
+ <% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
1029
+ .check = ${match_enum[-1]}_check_enum_variant,
1030
+ % else:
989
1031
  .check = NULL,
1032
+ % endif
1033
+ % endif
990
1034
  % endif
991
1035
  #endif
992
1036
  % else:
@@ -1422,6 +1466,174 @@ static gboolean _validate_odf_prop_${prop.name}(yaml_document_t *doc, GHashTable
1422
1466
  }
1423
1467
 
1424
1468
  %endfor
1469
+ ## 定义结构体ODF加载函数
1470
+ % for name, stru in intf.structures.items():
1471
+ /* ${name} structure object */
1472
+ /* START: 结构体${name}及其数组类型的ODF加载函数 */
1473
+ struct _${name} *${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node)
1474
+ {
1475
+ <% cnt = 0 %>\
1476
+ % for prop in stru.values.parameters:
1477
+ % if prop.odf_load_func() is not None:
1478
+ <% cnt = cnt + 1 %>\
1479
+ % endif
1480
+ % endfor
1481
+ % if cnt == 0:
1482
+ return g_new0(struct _${name}, 1);
1483
+ % else:
1484
+ __unused yaml_node_t *val;
1485
+ struct _${name} *output = g_new0(struct _${name}, 1);
1486
+ GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
1487
+ % for prop in stru.values.parameters:
1488
+ % if prop.odf_load_func() is not None:
1489
+ /* process ${prop.name} */
1490
+ val = g_hash_table_lookup(prop_table, "${prop.name}");
1491
+ if (val)
1492
+ ${prop.odf_load_func().replace("n_<arg_name>", "output->n_" + prop.name).replace("<arg_name>", "output->" + prop.name).replace("<node>", "val")};
1493
+ % endif
1494
+ % endfor
1495
+
1496
+ g_hash_table_destroy(prop_table);
1497
+ return output;
1498
+ % endif
1499
+ }
1500
+
1501
+ struct _${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node)
1502
+ {
1503
+ yaml_node_t *val;
1504
+ gint i = 0;
1505
+ if (node->type != YAML_SEQUENCE_NODE) {
1506
+ log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
1507
+ return g_new0(struct _${name} *, 1);
1508
+ }
1509
+ yaml_node_item_t *top = node->data.sequence.items.top;
1510
+ yaml_node_item_t *start = node->data.sequence.items.start;
1511
+ gsize cnt = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
1512
+ struct _${name} **output = g_new0(struct _${name} *, cnt + 1);
1513
+
1514
+ for (yaml_node_item_t *item = start; item < top; item++) {
1515
+ val = yaml_document_get_node(doc, *item);
1516
+ output[i++] = ${name}_load_from_odf(doc, val);
1517
+ }
1518
+ return output;
1519
+ }
1520
+
1521
+ % endfor
1522
+ ## 定义枚举ODF加载函数
1523
+ % for name, enum in intf.enumerations.items():
1524
+ ${name} ${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node)
1525
+ {
1526
+ % if codegen_version.be("5.0"):
1527
+ g_assert(node->type == YAML_SCALAR_NODE);
1528
+ if (node->type != YAML_SCALAR_NODE) {
1529
+ return _${name}_Invalid;
1530
+ }
1531
+
1532
+ for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
1533
+ if (g_strcmp0((const gchar *)node->data.scalar.value, ${name}_as_string(i)) == 0) {
1534
+ return (${name})i;
1535
+ }
1536
+ }
1537
+ return _${name}_Invalid;
1538
+ % else:
1539
+ g_assert(node->type == YAML_SCALAR_NODE);
1540
+ if (node->type != YAML_SCALAR_NODE) {
1541
+ return _${name}Invalid;
1542
+ }
1543
+
1544
+ for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
1545
+ if (g_strcmp0((const gchar *)node->data.scalar.value, ${name}_as_string(i)) == 0) {
1546
+ return (${name})i;
1547
+ }
1548
+ }
1549
+ return _${name}Invalid;
1550
+ % endif
1551
+ }
1552
+
1553
+ ${name} *${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node, gsize *n)
1554
+ {
1555
+ g_assert(doc && node && n);
1556
+ yaml_node_t *val;
1557
+ gint i = 0;
1558
+ if (node->type != YAML_SEQUENCE_NODE) {
1559
+ log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
1560
+ return g_new0(${name}, 1);
1561
+ }
1562
+ yaml_node_item_t *top = node->data.sequence.items.top;
1563
+ yaml_node_item_t *start = node->data.sequence.items.start;
1564
+ *n = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
1565
+ ${name} *output = g_new0(${name}, *n);
1566
+
1567
+ for (yaml_node_item_t *item = start; item < top; item++) {
1568
+ val = yaml_document_get_node(doc, *item);
1569
+ output[i++] = ${name}_load_from_odf(doc, val);
1570
+ }
1571
+ return output;
1572
+ }
1573
+
1574
+ % endfor
1575
+ ## 定义字典ODF加载函数
1576
+ % for name, dictionary in intf.dictionaries.items():
1577
+ ${name} *${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node)
1578
+ {
1579
+ GHashTable *prop_table = NULL;
1580
+ yaml_node_t *val = NULL;
1581
+ ${name} *dict = ${name}_new();
1582
+ yaml_node_item_t *top = node->data.sequence.items.top;
1583
+ yaml_node_item_t *start = node->data.sequence.items.start;
1584
+ for (yaml_node_item_t *item = start; item < top; item++) {
1585
+ val = yaml_document_get_node(doc, *item);
1586
+ ## 转换成hash表以获取key和properties
1587
+ prop_table = load_yaml_mapping_to_hash_table(doc, val);
1588
+ yaml_node_t *key = g_hash_table_lookup(prop_table, "key");
1589
+ yaml_node_t *properties = g_hash_table_lookup(prop_table, "properties");
1590
+ g_hash_table_destroy(prop_table);
1591
+
1592
+ ${", ".join(dictionary.key_obj.declare()).replace("<arg_name>", "key_val").replace("<const>", "")};
1593
+ ${dictionary.key_obj.odf_load_func().replace("<arg_name>", "key_val").replace("<node>", "key")};
1594
+
1595
+ ## 创建一个新的字典成员
1596
+ ${name}${dictionary.key} *item = g_new0(${name}${dictionary.key}, 1);
1597
+ ## 转换成hash表
1598
+ prop_table = load_yaml_mapping_to_hash_table(doc, properties);
1599
+ ## 迭代所有成员并从odf中还原数据
1600
+ % for prop in dictionary.values.parameters:
1601
+ % if prop.odf_load_func() is not None:
1602
+ val = g_hash_table_lookup(prop_table, "${prop.name}");
1603
+ if (val)
1604
+ ${prop.odf_load_func().replace("n_<arg_name>", "item->n_" + prop.name).replace("<arg_name>", "item->" + prop.name).replace("<node>", "val")};
1605
+ % endif
1606
+ % endfor
1607
+ g_hash_table_destroy(prop_table);
1608
+ dict->insert(dict, key_val, &item);
1609
+ % for line in dictionary.key_obj.free_func():
1610
+ ${line.replace("<arg_name>", "key_val")};
1611
+ % endfor
1612
+ }
1613
+ return dict;
1614
+ }
1615
+
1616
+ ${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node)
1617
+ {
1618
+ yaml_node_t *val;
1619
+ gint i = 0;
1620
+ if (node->type != YAML_SEQUENCE_NODE) {
1621
+ log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
1622
+ return g_new0(${name} *, 1);
1623
+ }
1624
+ yaml_node_item_t *top = node->data.sequence.items.top;
1625
+ yaml_node_item_t *start = node->data.sequence.items.start;
1626
+ gsize cnt = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
1627
+ ${name} **output = g_new0(${name} *, cnt + 1);
1628
+
1629
+ for (yaml_node_item_t *item = start; item < top; item++) {
1630
+ val = yaml_document_get_node(doc, *item);
1631
+ output[i++] = ${name}_load_from_odf(doc, val);
1632
+ }
1633
+ return output;
1634
+ }
1635
+
1636
+ % endfor
1425
1637
  gboolean ${intf.name.replace(".", "_")}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
1426
1638
  const gchar *object_name, GSList **error_list)
1427
1639
  {
@@ -1454,4 +1666,4 @@ static void __constructor(101) ${class_name}_public_register(void)
1454
1666
  % endfor
1455
1667
  }
1456
1668
 
1457
- % endif
1669
+ % endif
@@ -183,6 +183,10 @@ GVariant *${name}_encode_v(const ${name} *value, gsize n);
183
183
  ${name} *${name}_decode_v(GVariant *in, gsize *n);
184
184
  /* END: 枚举${name}及其数组类型的序列化、反序列化、释放函数 */
185
185
 
186
+ ## 校验枚举变量有效性
187
+ gboolean ${name}_check_enum_variant(LBO *obj, GVariant *value, GError **error);
188
+ gboolean ${name}_check_enum_variant_v(LBO *obj, GVariant *value, GError **error);
189
+
186
190
  % endfor
187
191
  ## 定义字典编解码和释放函数
188
192
  % for name, dictionary in intf.dictionaries.items():
@@ -196,6 +200,50 @@ ${name} **${name}_decode_v(GVariant *in);
196
200
  void ${name}_free_v(${name} ***value);
197
201
  /* END: 字典${name}及其数组类型的序列化、反序列化、释放函数 */
198
202
 
203
+ % endfor
204
+ ### 生成Errors错误 END
205
+ ## 定义结构体ODF加载函数
206
+ % for name, stru in intf.structures.items():
207
+ /* ${name} structure object */
208
+ /* START: 结构体${name}及其数组类型的ODF校验函数 */
209
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
210
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
211
+
212
+ % endfor
213
+ ## 定义枚举ODF加载函数
214
+ % for name, enum in intf.enumerations.items():
215
+ /* START: 枚举${name}及其数组类型的ODF校验函数 */
216
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
217
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
218
+
219
+ % endfor
220
+ ## 定义字典ODF加载函数
221
+ % for name, dictionary in intf.dictionaries.items():
222
+ gboolean ${name}_validate_odf(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
223
+ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
224
+
225
+ % endfor
226
+ ## 定义结构体ODF加载函数
227
+ % for name, stru in intf.structures.items():
228
+ /* ${name} structure object */
229
+ /* START: 结构体${name}及其数组类型的ODF加载函数 */
230
+ struct _${name} *${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node);
231
+ struct _${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node);
232
+
233
+ % endfor
234
+ ## 定义枚举ODF加载函数
235
+ % for name, enum in intf.enumerations.items():
236
+ /* START: 枚举${name}及其数组类型的ODF加载函数 */
237
+ ${name} ${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node);
238
+ ${name} *${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node, gsize *n);
239
+
240
+ % endfor
241
+ ## 定义字典ODF加载函数
242
+ % for name, dictionary in intf.dictionaries.items():
243
+ /* START: 字典${name}及其数组类型的ODF加载函数 */
244
+ ${name} *${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node);
245
+ ${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node);
246
+
199
247
  % endfor
200
248
  ### 开始生成方法的请求体、响应体和处理函数
201
249
  % for method in intf.fake_methods:
@@ -7,196 +7,7 @@ class_name = intf.alias
7
7
  properties = "_" + class_name + "_properties"
8
8
  signal_processer = "_" + class_name + "_signals"
9
9
  %>\
10
- ## 定义结构体ODF加载函数
11
- % for name, stru in intf.structures.items():
12
- /* ${name} structure object */
13
- /* START: 结构体${name}及其数组类型的ODF加载函数 */
14
- struct _${name} *_load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node);
15
- struct _${name} **_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node);
16
10
 
17
- % endfor
18
- ## 定义枚举ODF加载函数
19
- % for name, enum in intf.enumerations.items():
20
- /* START: 枚举${name}及其数组类型的ODF加载函数 */
21
- ${name} _load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node);
22
- ${name} *_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node, gsize *n);
23
-
24
- % endfor
25
- ## 定义字典ODF加载函数
26
- % for name, dictionary in intf.dictionaries.items():
27
- /* START: 字典${name}及其数组类型的ODF加载函数 */
28
- ${name} *_load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node);
29
- ${name} **_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node);
30
-
31
- % endfor
32
- ## 定义结构体ODF加载函数
33
- % for name, stru in intf.structures.items():
34
- /* ${name} structure object */
35
- /* START: 结构体${name}及其数组类型的ODF加载函数 */
36
- struct _${name} *_load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node)
37
- {
38
- <% cnt = 0 %>\
39
- % for prop in stru.values.parameters:
40
- % if prop.odf_load_func() is not None:
41
- <% cnt = cnt + 1 %>\
42
- % endif
43
- % endfor
44
- % if cnt == 0:
45
- return g_new0(struct _${name}, 1);
46
- % else:
47
- __unused yaml_node_t *val;
48
- struct _${name} *output = g_new0(struct _${name}, 1);
49
- GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
50
- % for prop in stru.values.parameters:
51
- % if prop.odf_load_func() is not None:
52
- /* process ${prop.name} */
53
- val = g_hash_table_lookup(prop_table, "${prop.name}");
54
- if (val)
55
- ${prop.odf_load_func().replace("n_<arg_name>", "output->n_" + prop.name).replace("<arg_name>", "output->" + prop.name).replace("<node>", "val")};
56
- % endif
57
- % endfor
58
-
59
- g_hash_table_destroy(prop_table);
60
- return output;
61
- % endif
62
- }
63
-
64
- struct _${name} **_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node)
65
- {
66
- yaml_node_t *val;
67
- gint i = 0;
68
- if (node->type != YAML_SEQUENCE_NODE) {
69
- log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
70
- return g_new0(struct _${name} *, 1);
71
- }
72
- yaml_node_item_t *top = node->data.sequence.items.top;
73
- yaml_node_item_t *start = node->data.sequence.items.start;
74
- gsize cnt = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
75
- struct _${name} **output = g_new0(struct _${name} *, cnt + 1);
76
-
77
- for (yaml_node_item_t *item = start; item < top; item++) {
78
- val = yaml_document_get_node(doc, *item);
79
- output[i++] = _load_odf_as_${name}(doc, val);
80
- }
81
- return output;
82
- }
83
-
84
- % endfor
85
- ## 定义枚举ODF加载函数
86
- % for name, enum in intf.enumerations.items():
87
- ${name} _load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node)
88
- {
89
- % if codegen_version.be("5.0"):
90
- g_assert(node->type == YAML_SCALAR_NODE);
91
- if (node->type != YAML_SCALAR_NODE) {
92
- return _${name}_Invalid;
93
- }
94
-
95
- for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
96
- if (g_strcmp0((const gchar *)node->data.scalar.value, ${name}_as_string(i)) == 0) {
97
- return (${name})i;
98
- }
99
- }
100
- return _${name}_Invalid;
101
- % else:
102
- g_assert(node->type == YAML_SCALAR_NODE);
103
- if (node->type != YAML_SCALAR_NODE) {
104
- return _${name}Invalid;
105
- }
106
-
107
- for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
108
- if (g_strcmp0((const gchar *)node->data.scalar.value, ${name}_as_string(i)) == 0) {
109
- return (${name})i;
110
- }
111
- }
112
- return _${name}Invalid;
113
- % endif
114
- }
115
-
116
- ${name} *_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node, gsize *n)
117
- {
118
- g_assert(doc && node && n);
119
- yaml_node_t *val;
120
- gint i = 0;
121
- if (node->type != YAML_SEQUENCE_NODE) {
122
- log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
123
- return g_new0(${name}, 1);
124
- }
125
- yaml_node_item_t *top = node->data.sequence.items.top;
126
- yaml_node_item_t *start = node->data.sequence.items.start;
127
- *n = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
128
- ${name} *output = g_new0(${name}, *n);
129
-
130
- for (yaml_node_item_t *item = start; item < top; item++) {
131
- val = yaml_document_get_node(doc, *item);
132
- output[i++] = _load_odf_as_${name}(doc, val);
133
- }
134
- return output;
135
- }
136
-
137
- % endfor
138
- ## 定义字典ODF加载函数
139
- % for name, dictionary in intf.dictionaries.items():
140
- ${name} *_load_odf_as_${name}(yaml_document_t *doc, yaml_node_t *node)
141
- {
142
- GHashTable *prop_table = NULL;
143
- yaml_node_t *val = NULL;
144
- ${name} *dict = ${name}_new();
145
- yaml_node_item_t *top = node->data.sequence.items.top;
146
- yaml_node_item_t *start = node->data.sequence.items.start;
147
- for (yaml_node_item_t *item = start; item < top; item++) {
148
- val = yaml_document_get_node(doc, *item);
149
- ## 转换成hash表以获取key和properties
150
- prop_table = load_yaml_mapping_to_hash_table(doc, val);
151
- yaml_node_t *key = g_hash_table_lookup(prop_table, "key");
152
- yaml_node_t *properties = g_hash_table_lookup(prop_table, "properties");
153
- g_hash_table_destroy(prop_table);
154
-
155
- ${", ".join(dictionary.key_obj.declare()).replace("<arg_name>", "key_val").replace("<const>", "")};
156
- ${dictionary.key_obj.odf_load_func().replace("<arg_name>", "key_val").replace("<node>", "key")};
157
-
158
- ## 创建一个新的字典成员
159
- ${name}${dictionary.key} *item = g_new0(${name}${dictionary.key}, 1);
160
- ## 转换成hash表
161
- prop_table = load_yaml_mapping_to_hash_table(doc, properties);
162
- ## 迭代所有成员并从odf中还原数据
163
- % for prop in dictionary.values.parameters:
164
- % if prop.odf_load_func() is not None:
165
- val = g_hash_table_lookup(prop_table, "${prop.name}");
166
- if (val)
167
- ${prop.odf_load_func().replace("n_<arg_name>", "item->n_" + prop.name).replace("<arg_name>", "item->" + prop.name).replace("<node>", "val")};
168
- % endif
169
- % endfor
170
- g_hash_table_destroy(prop_table);
171
- dict->insert(dict, key_val, &item);
172
- % for line in dictionary.key_obj.free_func():
173
- ${line.replace("<arg_name>", "key_val")};
174
- % endfor
175
- }
176
- return dict;
177
- }
178
-
179
- ${name} **_load_odf_as_${name}_v(yaml_document_t *doc, yaml_node_t *node)
180
- {
181
- yaml_node_t *val;
182
- gint i = 0;
183
- if (node->type != YAML_SEQUENCE_NODE) {
184
- log_warn("Load array ${name} failed because node type error, need type 1(sequence), get type %d", node->type);
185
- return g_new0(${name} *, 1);
186
- }
187
- yaml_node_item_t *top = node->data.sequence.items.top;
188
- yaml_node_item_t *start = node->data.sequence.items.start;
189
- gsize cnt = ((gsize)top - (gsize)start) / sizeof(yaml_node_item_t);
190
- ${name} **output = g_new0(${name} *, cnt + 1);
191
-
192
- for (yaml_node_item_t *item = start; item < top; item++) {
193
- val = yaml_document_get_node(doc, *item);
194
- output[i++] = _load_odf_as_${name}(doc, val);
195
- }
196
- return output;
197
- }
198
-
199
- % endfor
200
11
  static ${class_name}_Properties ${properties};
201
12
  static const ${class_name}_Signals *${signal_processer} = NULL;
202
13
 
@@ -271,10 +82,17 @@ static LBInterface _${class_name}_interface = {
271
82
  .name = "${intf.name}",
272
83
  .properties = (LBProperty *)&${properties},
273
84
  .interface = NULL, /* load from usr/share/dbus-1/interfaces/${intf.name} by lb_init */
85
+ #ifdef LB_CODEGEN_BE_5_2
86
+ % if intf.plugin.install_dir:
87
+ .plugin_dir = "${intf.plugin.install_dir}",
88
+ % else:
89
+ .plugin_dir = NULL,
90
+ % endif
91
+ #endif
274
92
  };
275
93
 
276
94
  % for prop in intf.properties:
277
- static void _load_odf_as_prop_${prop.name}(yaml_document_t *doc, GHashTable *prop_table,
95
+ static void ${class_name}_load_odf_as_prop_${prop.name}(yaml_document_t *doc, GHashTable *prop_table,
278
96
  struct _${class_name} *obj, lbo_property_reference_loaded_handler ref_loaded, gpointer user_data)
279
97
  {
280
98
  __unused gint i = 0;
@@ -391,7 +209,7 @@ static void _load_from_odf(yaml_document_t *doc, yaml_node_t *node, LBO *obj,
391
209
  ${class_name}_clean(real_obj);
392
210
  GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
393
211
  % for prop in intf.properties:
394
- _load_odf_as_prop_${prop.name}(doc, prop_table, real_obj, ref_loaded, user_data);
212
+ ${class_name}_load_odf_as_prop_${prop.name}(doc, prop_table, real_obj, ref_loaded, user_data);
395
213
  % endfor
396
214
 
397
215
  g_hash_table_destroy(prop_table);
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: lbkit
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: Tools provided by litebmc.com
5
5
  Home-page: https://www.litebmc.com
6
6
  Author: xuhj@litebmc.com
@@ -1,2 +0,0 @@
1
-
2
- __version__ = '0.8.3'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes