lbkit 0.8.9__tar.gz → 0.9.0__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 (69) hide show
  1. {lbkit-0.8.9/lbkit.egg-info → lbkit-0.9.0}/PKG-INFO +1 -1
  2. lbkit-0.9.0/lbkit/__init__.py +2 -0
  3. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/codegen.py +7 -8
  4. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/idf_interface.py +51 -34
  5. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/client.c.mako +8 -11
  6. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/client.h.mako +1 -18
  7. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/public.c.mako +21 -82
  8. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/public.h.mako +7 -23
  9. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/server.c.mako +19 -21
  10. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/server.h.mako +1 -12
  11. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/build.py +1 -1
  12. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/template/deploy.mako +0 -2
  13. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/test.py +73 -2
  14. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/image_maker/make_qemu_image.py +2 -0
  15. {lbkit-0.8.9 → lbkit-0.9.0/lbkit.egg-info}/PKG-INFO +1 -1
  16. lbkit-0.8.9/lbkit/__init__.py +0 -2
  17. {lbkit-0.8.9 → lbkit-0.9.0}/AUTHORS +0 -0
  18. {lbkit-0.8.9 → lbkit-0.9.0}/LICENSE +0 -0
  19. {lbkit-0.8.9 → lbkit-0.9.0}/MANIFEST.in +0 -0
  20. {lbkit-0.8.9 → lbkit-0.9.0}/README.md +0 -0
  21. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/build_conan_parallel.py +0 -0
  22. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/ci_robot/__init__.py +0 -0
  23. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/ci_robot/gitee.py +0 -0
  24. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/cli.py +0 -0
  25. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/__init__.py +0 -0
  26. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/ctype_defination.py +0 -0
  27. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/renderer.py +0 -0
  28. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/interface.c.mako +0 -0
  29. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  30. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/__init__.py +0 -0
  31. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/arg_parser.py +0 -0
  32. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/component/template/conanbase.mako +0 -0
  33. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/errors.py +0 -0
  34. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/helper.py +0 -0
  35. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/lbkit.py +0 -0
  36. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/log.py +0 -0
  37. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/misc.py +0 -0
  38. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/__init__.py +0 -0
  39. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/config.py +0 -0
  40. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/executor.py +0 -0
  41. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/image_maker/__init__.py +0 -0
  42. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/image_maker/make_image.py +0 -0
  43. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/image_maker/make_rockchip_image.py +0 -0
  44. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task.py +0 -0
  45. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task_build_image.py +0 -0
  46. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task_build_manifest.py +0 -0
  47. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task_build_prepare.py +0 -0
  48. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task_build_rootfs.py +0 -0
  49. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/task_download.py +0 -0
  50. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/template/conanfile.py.mako +0 -0
  51. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tasks/template/rootfs.py.mako +0 -0
  52. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/tools.py +0 -0
  53. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/ukr/__init__.py +0 -0
  54. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/ukr/build.py +0 -0
  55. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/utils/__init__.py +0 -0
  56. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/utils/env_detector.py +0 -0
  57. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/utils/images/__init__.py +0 -0
  58. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit/utils/images/emmc.py +0 -0
  59. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit.egg-info/SOURCES.txt +0 -0
  60. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit.egg-info/dependency_links.txt +0 -0
  61. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit.egg-info/entry_points.txt +0 -0
  62. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit.egg-info/requires.txt +0 -0
  63. {lbkit-0.8.9 → lbkit-0.9.0}/lbkit.egg-info/top_level.txt +0 -0
  64. {lbkit-0.8.9 → lbkit-0.9.0}/setup.cfg +0 -0
  65. {lbkit-0.8.9 → lbkit-0.9.0}/setup.py +0 -0
  66. {lbkit-0.8.9 → lbkit-0.9.0}/test/__init__.py +0 -0
  67. {lbkit-0.8.9 → lbkit-0.9.0}/test/test_codegen.py +0 -0
  68. {lbkit-0.8.9 → lbkit-0.9.0}/test/test_config.py +0 -0
  69. {lbkit-0.8.9 → lbkit-0.9.0}/test/test_helper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lbkit
3
- Version: 0.8.9
3
+ Version: 0.9.0
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.9.0'
@@ -64,12 +64,10 @@ class Version():
64
64
  # 历史自动生成版本号,计划用于用于生成代码稳定性测试
65
65
  # TODO: 支持生成代码稳定性测试,确保生成的代码一致性
66
66
  history_versions = {
67
- "5.0": CodeGenHistory("lb_base/[>=0.8.1 <0.9.0]", "简化接口类名定义;简化枚举变量在接口间传递时的字符串定义", "0"),
68
- "5.1": CodeGenHistory("lb_base/[>=0.8.3 <0.9.0]", "方法和信号添加保留字段用于功能扩展,同时设置请求和响应为空标志位", "8002"),
69
- "5.2": CodeGenHistory("lb_base/[>=0.8.4 <0.9.0]", "支持校验数值边界、字符串正则以及数组匹配等规则", "8004"),
70
67
  "5.3": CodeGenHistory("lb_base/[>=0.8.5 <0.9.0]", "支持32位操作系统", "8004"),
68
+ "5.4": CodeGenHistory("lb_base/[>=0.9.0 <0.10.0]", "LBInterface增加alias", "9000"),
71
69
  }
72
- __version__=Version("5.3")
70
+ __version__=Version("5.4")
73
71
 
74
72
 
75
73
  def version_check(ver_str: str):
@@ -119,13 +117,13 @@ class CodeGen(object):
119
117
  os.makedirs(os.path.join(directory, ct), exist_ok=True)
120
118
  out_file = os.path.join(directory, ct, interface.name + ".xml")
121
119
  interface.render_dbus_xml("interface.introspect.xml.mako", out_file)
122
- out_file = os.path.join(directory, ct, interface.name + ".h")
120
+ out_file = os.path.join(directory, ct, interface.alias + ".h")
123
121
  interface.render_c_source(ct + ".h.mako", out_file)
124
- out_file = os.path.join(directory, ct, interface.name + ".c")
122
+ out_file = os.path.join(directory, ct, interface.alias + ".c")
125
123
  interface.render_c_source(ct + ".c.mako", out_file)
126
124
  if "server" == ct:
127
125
  # 生成接口schema文件
128
- odf_file = os.path.join(directory, "server", "schema", f"{interface.name}.json")
126
+ odf_file = os.path.join(directory, "server", "schema", f"{interface.alias}.json")
129
127
  os.makedirs(os.path.dirname(odf_file), exist_ok=True)
130
128
  odf_data = interface.odf_schema
131
129
  with open(odf_file, "w", encoding="utf-8") as fp:
@@ -133,7 +131,8 @@ class CodeGen(object):
133
131
  json_file = os.path.join(directory, "package.yml")
134
132
  data = {
135
133
  "version": interface.version,
136
- "name": interface.name
134
+ "name": interface.name,
135
+ "alias": interface.alias
137
136
  }
138
137
  with open(json_file, "w", encoding="utf-8") as fp:
139
138
  yaml.dump(data, fp, encoding='utf-8', allow_unicode=True)
@@ -7,11 +7,12 @@ from functools import cached_property
7
7
  from lbkit.log import Logger
8
8
  from lbkit.codegen.renderer import Renderer
9
9
  from lbkit.codegen.ctype_defination import CTYPE_OBJS, RefObjArrayValidator, RefObjValidator
10
- from lbkit.misc import load_yml_with_json_schema_validate
10
+ from lbkit.misc import load_yml_with_json_schema_validate, get_json_schema_file
11
11
  from lbkit.errors import OdfValidateException, LiteBmcException
12
12
  from lbkit.helper import SigInvalidException, validate_glib_signature
13
13
 
14
14
  log = Logger("gen_interface")
15
+ alias = None
15
16
 
16
17
  class IDFException(Exception):
17
18
  pass
@@ -37,6 +38,8 @@ class IdfInterfaceBase(Renderer):
37
38
  self.description = None
38
39
  self.version = None
39
40
  self.alias = None
41
+ self.name = None
42
+ self.object_path = None
40
43
  self.codegen_version = None
41
44
 
42
45
  class IdfAnnotation():
@@ -120,9 +123,13 @@ CTYPE_SIGNATURE_MAP = {
120
123
  None: "s"
121
124
  }
122
125
 
123
- def get_intfname_and_ctype(ctype):
126
+ def get_intfname_and_ctype(class_alias: str, ctype: str):
124
127
  match = re.findall(r"([\w][\w\d]*)", ctype)
125
- return ".".join(match[:-1]), match[-1]
128
+ intf = ".".join(match[:-1])
129
+ ctype = match[-1]
130
+ if intf == "self":
131
+ return class_alias, class_alias + "_" + ctype
132
+ return intf, intf + "_" + ctype
126
133
 
127
134
  def ctype_to_variant_signature(intf: IdfInterfaceBase, ctype: str):
128
135
  sig_prefix = ""
@@ -135,8 +142,8 @@ def ctype_to_variant_signature(intf: IdfInterfaceBase, ctype: str):
135
142
  return sig_prefix + CTYPE_SIGNATURE_MAP.get(ctype)
136
143
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
137
144
 
138
- match_intf, match_ctype = get_intfname_and_ctype(match.group(2))
139
- if match_intf != "self":
145
+ match_intf, match_ctype = get_intfname_and_ctype(intf.alias, match.group(2))
146
+ if match_intf != intf.alias:
140
147
  intf = intf.dependency_idf_interface[match_intf]
141
148
  if match.group(1) == "struct":
142
149
  stru = intf.structures.get(match_ctype)
@@ -151,7 +158,7 @@ def ctype_to_variant_signature(intf: IdfInterfaceBase, ctype: str):
151
158
  raise IDFException(f"Unknown structure {match_ctype} get")
152
159
  return sig_prefix + dictionary.signature
153
160
 
154
- def ctype_to_dependency_interface(ctype: str):
161
+ def ctype_to_dependency_interface(class_alias: str, ctype: str):
155
162
  match = re.match(f"^array\[(.*)\]$", ctype)
156
163
  if match is not None:
157
164
  ctype = match.group(1)
@@ -160,8 +167,8 @@ def ctype_to_dependency_interface(ctype: str):
160
167
  return []
161
168
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
162
169
 
163
- match_intf, _ = get_intfname_and_ctype(match.group(2))
164
- if match_intf == "self":
170
+ match_intf, _ = get_intfname_and_ctype(class_alias, match.group(2))
171
+ if match_intf == class_alias:
165
172
  return []
166
173
  return [match_intf]
167
174
 
@@ -214,7 +221,7 @@ class IdfCtypeRender():
214
221
  is_array = True
215
222
  ctype = match.group(1)
216
223
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
217
- _, stru_name = get_intfname_and_ctype(match.group(2))
224
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
218
225
  if is_array:
219
226
  return [f"{stru_name}_validate_odf_v(doc, node, prop, error_list)"]
220
227
  else:
@@ -304,8 +311,8 @@ class IdfCtypeRender():
304
311
  is_array = True
305
312
  ctype = match.group(1)
306
313
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
307
- intf_name, stru_name = get_intfname_and_ctype(match.group(2))
308
- if intf_name == "self":
314
+ intf_name, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
315
+ if intf_name == self.intf.alias:
309
316
  intf = self.intf
310
317
  else:
311
318
  intf = self.intf.dependency_idf_interface[intf_name]
@@ -374,7 +381,7 @@ class IdfCtypeRender():
374
381
  is_array = True
375
382
  ctype = match.group(1)
376
383
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
377
- _, stru_name = get_intfname_and_ctype(match.group(2))
384
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
378
385
  if match.group(1) == "struct":
379
386
  if is_array:
380
387
  # 结构体数组初始化时为二级空指针,以空指针结束
@@ -414,7 +421,7 @@ class IdfCtypeRender():
414
421
  is_array = True
415
422
  ctype = match.group(1)
416
423
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
417
- _, stru_name = get_intfname_and_ctype(match.group(2))
424
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
418
425
  if match.group(1) == "struct":
419
426
  if is_array:
420
427
  # 结构体数组初始化时为二级空指针,以空指针结束
@@ -454,7 +461,7 @@ class IdfCtypeRender():
454
461
  is_array = True
455
462
  ctype = match.group(1)
456
463
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
457
- _, stru_name = get_intfname_and_ctype(match.group(2))
464
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
458
465
  if match.group(1) == "enum":
459
466
  if is_array:
460
467
  return [f"lb_free_p((void **)&<arg_name>)"]
@@ -483,7 +490,7 @@ class IdfCtypeRender():
483
490
  is_array = True
484
491
  ctype = match.group(1)
485
492
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
486
- _, stru_name = get_intfname_and_ctype(match.group(2))
493
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
487
494
  if match.group(1) == "enum":
488
495
  if is_array:
489
496
  # 入参为二级指针
@@ -516,7 +523,7 @@ class IdfCtypeRender():
516
523
  is_array = True
517
524
  ctype = match.group(1)
518
525
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
519
- _, stru_name = get_intfname_and_ctype(match.group(2))
526
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
520
527
  if match.group(1) == "enum":
521
528
  if is_array:
522
529
  # 入参为二级指针
@@ -596,7 +603,7 @@ class IdfCtypeRender():
596
603
  is_array = True
597
604
  ctype = match.group(1)
598
605
  match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
599
- _, stru_name = get_intfname_and_ctype(match.group(2))
606
+ _, stru_name = get_intfname_and_ctype(self.intf.alias, match.group(2))
600
607
  if match.group(1) == "enum":
601
608
  if is_array:
602
609
  # 入参为二级指针
@@ -835,7 +842,7 @@ class IdfProperty(IdfCtypeRender):
835
842
 
836
843
  @cached_property
837
844
  def dependency_interface(self):
838
- return ctype_to_dependency_interface(self.ctype)
845
+ return ctype_to_dependency_interface(self.intf.alias, self.ctype)
839
846
 
840
847
 
841
848
  class IdfParameter(IdfCtypeRender):
@@ -853,7 +860,7 @@ class IdfParameter(IdfCtypeRender):
853
860
 
854
861
  @cached_property
855
862
  def dependency_interface(self):
856
- return ctype_to_dependency_interface(self.ctype)
863
+ return ctype_to_dependency_interface(self.intf.alias, self.ctype)
857
864
 
858
865
 
859
866
  class IdfParameters():
@@ -994,10 +1001,7 @@ class IdfEnumeration(IdfBase):
994
1001
  def odf_schema(self):
995
1002
  values = []
996
1003
  for prop in self.values.parameters:
997
- if self.intf.codegen_version.lt("5.0"):
998
- val = self.intf.name + "." + self.name + "." + prop.name
999
- else:
1000
- val = prop.name
1004
+ val = prop.name
1001
1005
  values.append(val)
1002
1006
 
1003
1007
  odf = {
@@ -1104,7 +1108,6 @@ class IdfInterface(IdfInterfaceBase):
1104
1108
  super().__init__()
1105
1109
  self.lookup = lookup
1106
1110
  self.file = idf_file
1107
- self.name = os.path.basename(idf_file)[:-5]
1108
1111
  self.properties: list[IdfProperty] = []
1109
1112
  self.methods: list[IdfMethod] = []
1110
1113
  self.signals: list[IdfSignal] = []
@@ -1127,7 +1130,7 @@ class IdfInterface(IdfInterfaceBase):
1127
1130
  deps: dict[str, IdfInterface] = {}
1128
1131
  intfs = self.dependency_interface
1129
1132
  for intf in intfs:
1130
- intf_path = intf.replace(".", "/") + ".yaml"
1133
+ intf_path = intf + ".yaml"
1131
1134
  cwd = os.getcwd()
1132
1135
  realpath = None
1133
1136
  while cwd != "/":
@@ -1205,13 +1208,13 @@ class IdfInterface(IdfInterfaceBase):
1205
1208
  odf["$defs"] = {
1206
1209
  "ref_value": {
1207
1210
  "type": "string",
1208
- "description": "Property reference syntax. The format must be `\\$\\{([<]*|:)<interface>:<object_path>.<property name>\\}`",
1209
- "pattern": "^\\$\\{([<]*|:)(([a-zA-Z_][A-Za-z0-9_]*)(\\.[a-zA-Z_][A-Za-z0-9_]*)+:)[/]?[A-Z0-9a-z_]+(/[A-Z0-9a-z_]+)*\\.[A-Za-z][a-zA-Z0-9_-]*\\}$"
1211
+ "description": "Property reference syntax. The format must be `\\$\\{([<]*|:)<object>.<property name>\\}`, for example: Test_Obj.Prop",
1212
+ "pattern": "^\\$\\{([<]*|:)[a-zA-Z]([a-z0-9A-Z]*[a-z])?)_([a-z0-9A-Z]+)\\.[A-Za-z][a-zA-Z0-9_-]*\\}$"
1210
1213
  },
1211
1214
  "ref_obj": {
1212
1215
  "type": "string",
1213
- "description": "Property reference syntax. The format must be `\\$\\{([<]*|:)<interface>:<object_path>.<property name>\\}`",
1214
- "pattern": "^\\$\\{([<]*|:)(([a-zA-Z_][A-Za-z0-9_]*)(\\.[a-zA-Z_][A-Za-z0-9_]*)+:)[/]?[A-Z0-9a-z_]+(/[A-Z0-9a-z_]+)*\\}$"
1216
+ "description": "Property reference syntax. The format must be `\\$\\{([<]*|:)<object>.<property name>\\}`, for example: Test_Obj",
1217
+ "pattern": "^\\$\\{([<]*|:)[a-zA-Z]([a-z0-9A-Z]*[a-z])?)_([a-z0-9A-Z]+)\\}$"
1215
1218
  },
1216
1219
  "ref_obj_array": {
1217
1220
  "type": "array",
@@ -1220,8 +1223,8 @@ class IdfInterface(IdfInterfaceBase):
1220
1223
  "anyOf": [
1221
1224
  {
1222
1225
  "type": "string",
1223
- "description": "Object reference syntax. The format must be `\\$\\{([<]*|:)<interface>:<object_path>\\}`",
1224
- "pattern": "^\\$\\{([<]*|:)(([a-zA-Z_][A-Za-z0-9_]*)(\\.[a-zA-Z_][A-Za-z0-9_]*)+:)[/]?[A-Z0-9a-z_]+(/[A-Z0-9a-z_]+)*\\}$"
1226
+ "description": "Object reference syntax. The format must be `\\$\\{([<]*|:)<object>\\}`, for example: Test_Obj",
1227
+ "pattern": "^\\$\\{([<]*|:)[a-zA-Z]([a-z0-9A-Z]*[a-z])?)_([a-z0-9A-Z]+)\\}$"
1225
1228
  },
1226
1229
  {
1227
1230
  "type": "string",
@@ -1246,12 +1249,23 @@ class IdfInterface(IdfInterfaceBase):
1246
1249
  def load_elements(self):
1247
1250
  # 使用schema校验数据,确保IDF文件符合格式要求,减少程序处理过程中的异常处理
1248
1251
  # 验证失败时抛异常,此处不用处理,由外层处理
1249
- idf = load_yml_with_json_schema_validate(self.file, "/usr/share/litebmc/schema/idf.v1.json")
1252
+ idf = load_yml_with_json_schema_validate(self.file, "/usr/share/litebmc/schema/idf.v2.json")
1253
+ schema = get_json_schema_file(self.file, "/usr/share/litebmc/schema/idf.v2.json")
1254
+ if schema.endswith("idf.v1.json"):
1255
+ self.name = os.path.basename(self.file)[:-5]
1256
+ self.alias = idf.get("alias")
1257
+ self.object_path = ""
1258
+ else:
1259
+ self.alias = os.path.basename(self.file)[:-5]
1260
+ self.name = idf.get("interface")
1261
+ # 别名
1262
+ self.object_path = idf.get("object_path", "")
1263
+
1250
1264
  log.debug(f"validate {self.file} successfully")
1251
1265
  self.version = idf.get("version")
1252
1266
  self.description = idf.get("description", "")
1253
- # 别名
1254
- self.alias = idf.get("alias")
1267
+ global alias
1268
+ alias = self.alias
1255
1269
  # 注释
1256
1270
  flags = idf.get("flags", "").split(",")
1257
1271
  for k, v in ANNOTATION_MAP.items():
@@ -1271,6 +1285,7 @@ class IdfInterface(IdfInterfaceBase):
1271
1285
  items = idf.get("structures", [])
1272
1286
  for item in items:
1273
1287
  obj = IdfStructure(self, item)
1288
+ obj.name = alias + "_" + obj.name
1274
1289
  self.structures[obj.name] = obj
1275
1290
  items = idf.get("errors", [])
1276
1291
  for item in items:
@@ -1280,10 +1295,12 @@ class IdfInterface(IdfInterfaceBase):
1280
1295
  items = idf.get("dictionaries", [])
1281
1296
  for item in items:
1282
1297
  obj = IdfDictionary(self, item)
1298
+ obj.name = alias + "_" + obj.name
1283
1299
  self.dictionaries[obj.name] = obj
1284
1300
  items = idf.get("enumerations", [])
1285
1301
  for item in items:
1286
1302
  obj = IdfEnumeration(self, item)
1303
+ obj.name = alias + "_" + obj.name
1287
1304
  self.enumerations[obj.name] = obj
1288
1305
  plugin = idf.get("plugin", None)
1289
1306
  self.plugin = IdfInterfacePlugin()
@@ -1,5 +1,8 @@
1
+ <%
2
+ from inflection import underscore
3
+ %>\
1
4
  #include "lb_base.h"
2
- #include "${intf.name}.h"
5
+ #include "${intf.alias}.h"
3
6
 
4
7
  <% class_name = intf.alias + "_Cli"
5
8
  properties = "_" + class_name + "_properties"
@@ -113,6 +116,10 @@ static LBInterface _${class_name}_interface = {
113
116
  .name = "${intf.name}",
114
117
  .properties = (LBProperty *)&${properties},
115
118
  .interface = NULL, /* load from usr/share/dbus-1/interfaces/${intf.name}.xml by lb_init */
119
+ #ifdef LB_CODEGEN_BE_5_4
120
+ .alias = "${class_name}",
121
+ .object_template = "${intf.object_path}",
122
+ #endif
116
123
  };
117
124
 
118
125
  static LBBase *_get_real_object(LBO *obj)
@@ -160,18 +167,10 @@ static LBO *_${class_name}_create(const gchar *name, gpointer opaque)
160
167
 
161
168
  % for signal in intf.signals:
162
169
  % if signal.deprecated:
163
- % if codegen_version.be("5.1"):
164
170
  __deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
165
- % else:
166
- __deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
167
- % endif
168
171
  const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data)
169
172
  % else:
170
- % if codegen_version.be("5.1"):
171
173
  guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
172
- % else:
173
- guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
174
- % endif
175
174
  const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data)
176
175
  % endif
177
176
  {
@@ -200,7 +199,6 @@ ${class_name}_Properties *${class_name}_properties(void)
200
199
  return &${properties};
201
200
  }
202
201
 
203
- % if codegen_version.be("4.0"):
204
202
  ${class_name} ${class_name}_get(const gchar *well_known, const gchar *name)
205
203
  {
206
204
  return lb_impl._cli_get(&_${class_name}_interface, well_known, name);
@@ -314,7 +312,6 @@ void ${class_name}_${prop.name}_hook(${class_name}_after_changed_hook after, gpo
314
312
  }
315
313
 
316
314
  % endfor
317
- % endif
318
315
  static void __constructor(150) ${class_name}_register(void)
319
316
  {
320
317
  // 从公共库中复制信号处理函数
@@ -5,7 +5,7 @@
5
5
  #include <glib-2.0/glib.h>
6
6
  #include <glib-2.0/gio/gio.h>
7
7
  #include "lb_base.h"
8
- #include "public/${intf.name}.h"
8
+ #include "public/${intf.alias}.h"
9
9
 
10
10
  #ifdef __cplusplus
11
11
  extern "C" {
@@ -88,15 +88,9 @@ int ${class_name}_Call_${method.name}(${class_name} obj,
88
88
  % endfor
89
89
  % endif
90
90
  */
91
- % if codegen_version.be("5.1"):
92
91
  typedef void (*${class_name}_${signal.name}_Callback)(${class_name} obj, const gchar *destination,
93
92
  const ${intf.alias}_${signal.name}_Msg *req, gpointer user_data, const LBSignalExtData *ext_data);
94
- % else:
95
- typedef void (*${class_name}_${signal.name}_Signal)(${class_name} obj, const gchar *destination,
96
- const ${intf.alias}_${signal.name}_Msg *req, gpointer user_data);
97
- % endif
98
93
  /**/
99
- % if codegen_version.be("5.1"):
100
94
  % if signal.deprecated:
101
95
  __deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
102
96
  const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
@@ -104,15 +98,6 @@ __deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal
104
98
  guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
105
99
  const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
106
100
  % endif
107
- % else:
108
- % if signal.deprecated:
109
- __deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
110
- const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
111
- % else:
112
- guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
113
- const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
114
- % endif
115
- % endif
116
101
  % if signal.deprecated:
117
102
  __deprecated void ${class_name}_Unsubscribe_${signal.name}(guint *id);
118
103
  % else:
@@ -125,7 +110,6 @@ ${class_name}_Properties *${class_name}_properties(void);
125
110
  LBInterface *${class_name}_interface(void);
126
111
  #define ${hump2underline(class_name).upper()} ${class_name}_interface()
127
112
 
128
- % if codegen_version.be("4.0"):
129
113
  /* notes: 对象变更加回调函数 */
130
114
  typedef void (*${class_name}_on_changed_hook)(${class_name} obj, gpointer user_data);
131
115
  /* notes: 属性变更后回调,远程对象或本地对象变更后都会调用 */
@@ -205,7 +189,6 @@ static inline void _cleanup_${class_name}_list(GSList **ptr)
205
189
 
206
190
  #define cleanup_${class_name} __attribute__((cleanup(_cleanup_${class_name}_)))
207
191
  #define cleanup_${class_name}_list __attribute__((cleanup(_cleanup_${class_name}_list)))
208
- % endif
209
192
  #ifdef __cplusplus
210
193
  }
211
194
  #endif
@@ -1,5 +1,5 @@
1
1
  #include "lb_base.h"
2
- #include "${intf.name}.h"
2
+ #include "${intf.alias}.h"
3
3
  <% import re %>\
4
4
 
5
5
  <% class_name = intf.alias %>\
@@ -11,7 +11,7 @@ static const GDBusErrorEntry _dbus_error_entries[] =
11
11
  % for name, stru in intf.errors.items():
12
12
  {
13
13
  .error_code = ${class_name}_Error_${name},
14
- .dbus_error_name = "${intf.name}.Error.${name}"
14
+ .dbus_error_name = "${intf.alias}.Error.${name}"
15
15
  },
16
16
  % endfor
17
17
  };
@@ -20,7 +20,7 @@ static const GDBusErrorEntry _dbus_error_entries[] =
20
20
  static GQuark _dbus_error_quark(void)
21
21
  {
22
22
  static gsize quark = 0;
23
- g_dbus_error_register_error_domain("${intf.name.replace(".", "-")}-quark",
23
+ g_dbus_error_register_error_domain("${intf.alias.replace(".", "-")}-quark",
24
24
  &quark,
25
25
  _dbus_error_entries,
26
26
  G_N_ELEMENTS (_dbus_error_entries));
@@ -248,7 +248,6 @@ gboolean ${name}_validate_odf_v(yaml_document_t *doc, yaml_node_t *node,
248
248
 
249
249
  %endfor
250
250
  % for name, enum in intf.enumerations.items():
251
- % if codegen_version.be("5.0"):
252
251
  ## 枚举序列化和反序列化函数
253
252
  static const gchar *_${name}StrMap[] = {
254
253
  % for value in enum.values.parameters:
@@ -290,49 +289,6 @@ ${name} ${name}_decode(GVariant *in)
290
289
  return _${name}_Invalid;
291
290
  }
292
291
 
293
- % else:
294
- ## 枚举序列化和反序列化函数
295
- static const gchar *_${name}StrMap[] = {
296
- % for value in enum.values.parameters:
297
- "${intf.name}.${name}.${value.name}",
298
- % endfor
299
- };
300
-
301
- const gchar *${name}_as_string(${name} value)
302
- {
303
- if (value >= _${name}_Invalid) {
304
- return "com.litebmc.Errors.Enum.Invalid";
305
- }
306
- return _${name}StrMap[value];
307
- }
308
-
309
- /* ${name}枚举类型序列化(enum转string)函数 */
310
- GVariant *${name}_encode(${name} value)
311
- {
312
- ## 非法值返回com.litebmc.Errors.Enum.Invalid
313
- if (value > ${name}_${enum.values.parameters[len(enum.values.parameters) - 1].name}) {
314
- return g_variant_new_string("com.litebmc.Errors.Enum.Invalid");
315
- }
316
- return g_variant_new_string(_${name}StrMap[value]);
317
- }
318
-
319
- /* ${name}枚举类型反序列化(string转enum)函数 */
320
- ${name} ${name}_decode(GVariant *in)
321
- {
322
- if (!in) {
323
- return _${name}_Invalid;
324
- }
325
-
326
- const gchar *in_val = g_variant_get_string(in, NULL);
327
- for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
328
- if (g_strcmp0(in_val, _${name}StrMap[i]) == 0) {
329
- return (${name})i;
330
- }
331
- }
332
- return _${name}_Invalid;
333
- }
334
-
335
- % endif
336
292
  /* ${name}枚举类型序列化(enum转string)函数 */
337
293
  GVariant *${name}_encode_v(const ${name} *values, gsize n)
338
294
  {
@@ -923,7 +879,6 @@ static GDBusPropertyInfo ${class_name}_property_${prop.name} =
923
879
  % endif
924
880
  % endfor
925
881
  ## 只有自动生成工具版本号大于等于3的才会生成get和set方法
926
- % if codegen_version.be("3.0"):
927
882
  % if len(intf.properties):
928
883
  static LBBase *_get_real_object(${class_name} obj)
929
884
  {
@@ -996,7 +951,6 @@ static GVariant *${class_name}_get_${prop.name}_variant(LBO *obj)
996
951
  }
997
952
 
998
953
  %endfor
999
- %endif
1000
954
  static ${class_name}_Properties _${class_name}_properties =
1001
955
  {
1002
956
  <% id = 0 %>\
@@ -1010,7 +964,6 @@ static ${class_name}_Properties _${class_name}_properties =
1010
964
  .info = NULL, /* load from /usr/share/dbus-1/interfaces/${intf.name} by lb_init */
1011
965
  % endif
1012
966
  .offset = offsetof(struct _${class_name}, ${prop.name}),
1013
- % if codegen_version.be("3.0"):
1014
967
  .flags = ${prop.desc_flags},
1015
968
  .set = ${class_name}_set_${prop.name}_variant,
1016
969
  .get = ${class_name}_get_${prop.name}_variant,
@@ -1021,21 +974,26 @@ static ${class_name}_Properties _${class_name}_properties =
1021
974
  <% match = re.match(f"^array\[enum\[(.*)\]\]$", prop.ctype) %>\
1022
975
  % if match:
1023
976
  <% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
1024
- .check = ${match_enum[-1]}_check_enum_variant_v,
977
+ % if match_enum[0] == "self":
978
+ .check = ${class_name}_${match_enum[-1]}_check_enum_variant_v,
979
+ % else:
980
+ .check = ${match_enum[0]}_${match_enum[-1]}_check_enum_variant_v,
981
+ % endif
1025
982
  % else:
1026
983
  <% match = re.match(f"^enum\[(.*)\]$", prop.ctype) %>\
1027
984
  % if match:
1028
985
  <% match_enum = re.findall(r"([\w][\w\d]*)", match.group(1)) %>\
1029
- .check = ${match_enum[-1]}_check_enum_variant,
986
+ % if match_enum[0] == "self":
987
+ .check = ${class_name}_${match_enum[-1]}_check_enum_variant,
988
+ % else:
989
+ .check = ${match_enum[0]}_${match_enum[-1]}_check_enum_variant,
990
+ % endif
1030
991
  % else:
1031
992
  .check = NULL,
1032
993
  % endif
1033
994
  % endif
1034
995
  % endif
1035
996
  #endif
1036
- % else:
1037
- .flags = ${prop.desc_flags}
1038
- % endif
1039
997
  },
1040
998
  <% id = id + 1 %>\
1041
999
  % endfor
@@ -1054,19 +1012,14 @@ const ${class_name}_Properties *${class_name}_properties_const(void)
1054
1012
  % if not method.is_plugin:
1055
1013
  ## 方法${method.name}的默认实现
1056
1014
  /* 方法${class_name}_${method.name}的默认实现 */
1057
- % if codegen_version.be("5.1"):
1058
1015
  __weak int ${class_name}_${method.name}(${class_name} obj, const ${class_name}_${method.name}_Req *req,
1059
1016
  ${class_name}_${method.name}_Rsp **rsp, GError **error, LBMethodExtData *ext_data)
1060
- % else:
1061
- __weak int ${class_name}_${method.name}(${class_name} obj, const ${class_name}_${method.name}_Req *req,
1062
- ${class_name}_${method.name}_Rsp **rsp, GError **error, gpointer ext_data)
1063
- % endif
1064
1017
  {
1065
1018
  *error = LbError_MethodNotImplament_new("${method.name}");
1066
1019
  return -1;
1067
1020
  }
1068
1021
 
1069
- % if method.parameters.parameters or codegen_version.lt("5.1"):
1022
+ % if method.parameters.parameters:
1070
1023
  ## 方法${method.name}的请求体序列化函数
1071
1024
  /* ${class_name}_${method.name}_Req请求结构体类型序列化(struct转GVariant)函数 */
1072
1025
  static GVariant *${class_name}_${method.name}_Req_encode(${class_name}_${method.name}_Req *value)
@@ -1128,7 +1081,7 @@ static void ${class_name}_${method.name}_Req_free(${class_name}_${method.name}_R
1128
1081
  }
1129
1082
 
1130
1083
  % endif
1131
- % if method.returns.parameters or codegen_version.lt("5.1"):
1084
+ % if method.returns.parameters:
1132
1085
  /* ${class_name}_${method.name}_Rsp请求结构体类型序列化(struct转GVariant)函数 */
1133
1086
  static GVariant *${class_name}_${method.name}_Rsp_encode(${class_name}_${method.name}_Rsp *value)
1134
1087
  {
@@ -1174,7 +1127,7 @@ static ${class_name}_${method.name}_Rsp *${class_name}_${method.name}_Rsp_decode
1174
1127
 
1175
1128
  % endif
1176
1129
  % endif
1177
- % if method.returns.parameters or codegen_version.lt("5.1"):
1130
+ % if method.returns.parameters:
1178
1131
  ## 方法${method.name}的响应体释放函数
1179
1132
  /* ${class_name}_${method.name}_Rsp结构体指针释放 */
1180
1133
  void ${class_name}_${method.name}_Rsp_free(${class_name}_${method.name}_Rsp **value)
@@ -1199,7 +1152,7 @@ static ${class_name}_Methods _${class_name}_methods =
1199
1152
  .${method.name} = {
1200
1153
  .name = "${method.name}",
1201
1154
  .req_signature = "${method.in_signature}",
1202
- % if method.parameters.parameters or codegen_version.lt("5.1"):
1155
+ % if method.parameters.parameters:
1203
1156
  .req_decode = ${class_name}_${method.name}_Req_decode,
1204
1157
  .req_encode = ${class_name}_${method.name}_Req_encode,
1205
1158
  .req_free = ${class_name}_${method.name}_Req_free,
@@ -1209,7 +1162,7 @@ static ${class_name}_Methods _${class_name}_methods =
1209
1162
  .req_free = lb_message_free_empty,
1210
1163
  % endif
1211
1164
  .rsp_signature = "${method.out_signature}",
1212
- % if method.returns.parameters or codegen_version.lt("5.1"):
1165
+ % if method.returns.parameters:
1213
1166
  .rsp_decode = ${class_name}_${method.name}_Rsp_decode,
1214
1167
  .rsp_encode = ${class_name}_${method.name}_Rsp_encode,
1215
1168
  .rsp_free = ${class_name}_${method.name}_Rsp_free,
@@ -1336,7 +1289,7 @@ int ${class_name}_${action.name}_run(${class_name} obj${REQ_PARA}${RSP_PARA})
1336
1289
  % endfor
1337
1290
  % endif
1338
1291
  % for signal in intf.signals:
1339
- % if signal.properties.parameters or codegen_version.lt("5.1"):
1292
+ % if signal.properties.parameters:
1340
1293
  ## 方法${method.name}的响应体序列化函数
1341
1294
  /* ${class_name}_${signal.name}_Msg请求结构体类型序列化(struct转GVariant)函数 */
1342
1295
  static GVariant *${class_name}_${signal.name}_Msg_encode(${class_name}_${signal.name}_Msg *value)
@@ -1405,7 +1358,7 @@ static ${class_name}_Signals _${class_name}_signals = {
1405
1358
  .${signal.name} = {
1406
1359
  .name = "${signal.name}",
1407
1360
  .msg_signature = "${signal.signature}",
1408
- % if signal.properties.parameters or codegen_version.lt("5.1"):
1361
+ % if signal.properties.parameters:
1409
1362
  .msg_decode = ${class_name}_${signal.name}_Msg_decode,
1410
1363
  .msg_encode = ${class_name}_${signal.name}_Msg_encode,
1411
1364
  .msg_free = ${class_name}_${signal.name}_Msg_free,
@@ -1523,7 +1476,6 @@ struct _${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *nod
1523
1476
  % for name, enum in intf.enumerations.items():
1524
1477
  ${name} ${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node)
1525
1478
  {
1526
- % if codegen_version.be("5.0"):
1527
1479
  g_assert(node->type == YAML_SCALAR_NODE);
1528
1480
  if (node->type != YAML_SCALAR_NODE) {
1529
1481
  return _${name}_Invalid;
@@ -1535,19 +1487,6 @@ ${name} ${name}_load_from_odf(yaml_document_t *doc, yaml_node_t *node)
1535
1487
  }
1536
1488
  }
1537
1489
  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
1490
  }
1552
1491
 
1553
1492
  ${name} *${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node, gsize *n)
@@ -1634,7 +1573,7 @@ ${name} **${name}_load_from_odf_v(yaml_document_t *doc, yaml_node_t *node)
1634
1573
  }
1635
1574
 
1636
1575
  % endfor
1637
- gboolean ${intf.name.replace(".", "_")}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
1576
+ gboolean ${intf.alias}_validate_odf_file(yaml_document_t *doc, yaml_node_t *node,
1638
1577
  const gchar *object_name, GSList **error_list)
1639
1578
  {
1640
1579
  g_assert(doc && node && object_name && error_list);