lbkit 0.8.3__tar.gz → 0.8.5__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 (64) hide show
  1. lbkit-0.8.5/MANIFEST.in +3 -0
  2. {lbkit-0.8.3/lbkit.egg-info → lbkit-0.8.5}/PKG-INFO +1 -1
  3. lbkit-0.8.5/lbkit/__init__.py +2 -0
  4. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/cli.py +11 -26
  5. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/idf_interface.py +8 -6
  6. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/public.c.mako +247 -35
  7. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/public.h.mako +48 -0
  8. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/server.c.mako +9 -191
  9. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/log.py +1 -0
  10. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/misc.py +1 -0
  11. {lbkit-0.8.3/lbkit/integration → lbkit-0.8.5/lbkit/tasks}/config.py +40 -3
  12. lbkit-0.8.5/lbkit/tasks/executor.py +256 -0
  13. {lbkit-0.8.3/lbkit/integration → lbkit-0.8.5/lbkit/tasks}/task.py +18 -6
  14. lbkit-0.8.3/lbkit/integration/build_image.py → lbkit-0.8.5/lbkit/tasks/task_build_image.py +4 -6
  15. lbkit-0.8.3/lbkit/integration/build_manifest.py → lbkit-0.8.5/lbkit/tasks/task_build_manifest.py +4 -4
  16. lbkit-0.8.3/lbkit/integration/build_prepare.py → lbkit-0.8.5/lbkit/tasks/task_build_prepare.py +4 -4
  17. lbkit-0.8.3/lbkit/integration/build_rootfs.py → lbkit-0.8.5/lbkit/tasks/task_build_rootfs.py +4 -5
  18. lbkit-0.8.5/lbkit/tasks/task_test.py +29 -0
  19. lbkit-0.8.5/lbkit/tasks/test.py +40 -0
  20. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/tools.py +0 -1
  21. lbkit-0.8.5/lbkit/utils/env_detector.py +38 -0
  22. {lbkit-0.8.3 → lbkit-0.8.5/lbkit.egg-info}/PKG-INFO +1 -1
  23. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit.egg-info/SOURCES.txt +13 -9
  24. lbkit-0.8.3/MANIFEST.in +0 -3
  25. lbkit-0.8.3/lbkit/__init__.py +0 -2
  26. {lbkit-0.8.3 → lbkit-0.8.5}/AUTHORS +0 -0
  27. {lbkit-0.8.3 → lbkit-0.8.5}/LICENSE +0 -0
  28. {lbkit-0.8.3 → lbkit-0.8.5}/README.md +0 -0
  29. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/build_conan_parallel.py +0 -0
  30. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/ci_robot/__init__.py +0 -0
  31. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/ci_robot/gitee.py +0 -0
  32. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/__init__.py +0 -0
  33. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/codegen.py +0 -0
  34. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/ctype_defination.py +0 -0
  35. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/renderer.py +0 -0
  36. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/client.c.mako +0 -0
  37. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/client.h.mako +0 -0
  38. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/interface.c.mako +0 -0
  39. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  40. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/codegen/template/server.h.mako +0 -0
  41. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/__init__.py +0 -0
  42. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/arg_parser.py +0 -0
  43. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/build.py +0 -0
  44. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/template/conanbase.mako +0 -0
  45. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/template/deploy.mako +0 -0
  46. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/component/test.py +0 -0
  47. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/errors.py +0 -0
  48. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/helper.py +0 -0
  49. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/lbkit.py +0 -0
  50. {lbkit-0.8.3/lbkit/integration → lbkit-0.8.5/lbkit/tasks}/__init__.py +0 -0
  51. {lbkit-0.8.3/lbkit/integration → lbkit-0.8.5/lbkit/tasks}/template/conanfile.py.mako +0 -0
  52. {lbkit-0.8.3/lbkit/integration → lbkit-0.8.5/lbkit/tasks}/template/rootfs.py.mako +0 -0
  53. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/utils/__init__.py +0 -0
  54. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/utils/images/__init__.py +0 -0
  55. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit/utils/images/emmc.py +0 -0
  56. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit.egg-info/dependency_links.txt +0 -0
  57. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit.egg-info/entry_points.txt +0 -0
  58. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit.egg-info/requires.txt +0 -0
  59. {lbkit-0.8.3 → lbkit-0.8.5}/lbkit.egg-info/top_level.txt +0 -0
  60. {lbkit-0.8.3 → lbkit-0.8.5}/setup.cfg +0 -0
  61. {lbkit-0.8.3 → lbkit-0.8.5}/setup.py +0 -0
  62. {lbkit-0.8.3 → lbkit-0.8.5}/test/__init__.py +0 -0
  63. {lbkit-0.8.3 → lbkit-0.8.5}/test/test_codegen.py +0 -0
  64. {lbkit-0.8.3 → lbkit-0.8.5}/test/test_helper.py +0 -0
@@ -0,0 +1,3 @@
1
+ recursive-include lbkit/codegen/template *.mako
2
+ recursive-include lbkit/tasks/template *.mako
3
+ recursive-include lbkit/component/template *.mako
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: lbkit
3
- Version: 0.8.3
3
+ Version: 0.8.5
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.5'
@@ -10,16 +10,13 @@ from lbkit import __version__ as client_version
10
10
  from lbkit.codegen.codegen import CodeGen
11
11
  from lbkit.component.build import BuildComponent
12
12
  from lbkit.component.test import TestComponent
13
- from lbkit.integration.build_manifest import BuildManifest
14
- from lbkit.integration.build_rootfs import BuildRootfs
15
- from lbkit.integration.build_prepare import BuildPrepare
16
- from lbkit.integration.build_image import BuildImage
13
+ from lbkit.tasks.executor import Executor
17
14
  from lbkit.component.arg_parser import ArgParser
18
- from lbkit.integration.config import Config
19
15
  from lbkit.ci_robot.gitee import Gitee
20
16
  from lbkit.log import Logger
21
17
  from lbkit import misc
22
18
  from lbkit import errors
19
+ from lbkit.utils.env_detector import EnvDetector
23
20
 
24
21
  log = Logger("cli")
25
22
 
@@ -80,26 +77,14 @@ class Command(object):
80
77
 
81
78
  组件需要支持多种跨平台构建场景,典型的包括DT(X86-64)、交叉编译(arm64)
82
79
  """
83
- arg_parser = ArgParser.new()
84
- build = BuildComponent(arg_parser, sys.argv[2:])
85
- build.run()
86
-
87
- # create product package
88
- def create(self, *args):
89
- """
90
- 构建组件.
91
-
92
- 组件需要支持多种跨平台构建场景,典型的包括DT(X86-64)、交叉编译(arm64)
93
- """
94
- cfg = Config(sys.argv[2:])
95
- build = BuildPrepare(cfg, "create_pre")
96
- build.run()
97
- build = BuildManifest(cfg, "create_run")
98
- build.run()
99
- build = BuildRootfs(cfg, "create_rootfs")
100
- build.run()
101
- build = BuildImage(cfg, "create_image")
102
- build.run()
80
+ env = EnvDetector()
81
+ if env.component:
82
+ arg_parser = ArgParser.new()
83
+ build = BuildComponent(arg_parser, sys.argv[2:])
84
+ build.run()
85
+ elif env.manifest:
86
+ exe = Executor(env)
87
+ exe.run()
103
88
 
104
89
  def gitee(self, *args):
105
90
  """
@@ -126,7 +111,7 @@ class Command(object):
126
111
  """
127
112
  grps = [("Code Generate commands", ["gen"]),
128
113
  ("Build Component commands", ["new", "build", "test"]),
129
- ("Build Product commands", ["create"]),
114
+ ("Build Product commands", ["build"]),
130
115
  ("Misc commands", ["help"]),
131
116
  ("CI Robot commands", ["gitee"])
132
117
  ]
@@ -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: