lbkit 0.5.6__tar.gz → 0.5.7__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 (50) hide show
  1. {lbkit-0.5.6/lbkit.egg-info → lbkit-0.5.7}/PKG-INFO +1 -1
  2. lbkit-0.5.7/lbkit/__init__.py +2 -0
  3. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/ctype_defination.py +198 -65
  4. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/idf_interface.py +67 -5
  5. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/public.c.mako +352 -5
  6. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/public.h.mako +18 -1
  7. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/server.c.mako +5 -1
  8. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/server.h.mako +0 -1
  9. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/misc.py +1 -1
  10. {lbkit-0.5.6 → lbkit-0.5.7/lbkit.egg-info}/PKG-INFO +1 -1
  11. lbkit-0.5.6/lbkit/__init__.py +0 -2
  12. {lbkit-0.5.6 → lbkit-0.5.7}/AUTHORS +0 -0
  13. {lbkit-0.5.6 → lbkit-0.5.7}/LICENSE +0 -0
  14. {lbkit-0.5.6 → lbkit-0.5.7}/MANIFEST.in +0 -0
  15. {lbkit-0.5.6 → lbkit-0.5.7}/README.md +0 -0
  16. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/ci_robot/__init__.py +0 -0
  17. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/ci_robot/gitee.py +0 -0
  18. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/cli.py +0 -0
  19. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/__init__.py +0 -0
  20. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/codegen.py +0 -0
  21. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/renderer.py +0 -0
  22. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/client.c.mako +0 -0
  23. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/client.h.mako +0 -0
  24. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/interface.c.mako +0 -0
  25. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  26. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/__init__.py +0 -0
  27. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/arg_parser.py +0 -0
  28. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/build.py +0 -0
  29. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/template/conanbase.mako +0 -0
  30. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/template/deploy.mako +0 -0
  31. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/component/test.py +0 -0
  32. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/errors.py +0 -0
  33. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/helper.py +0 -0
  34. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/__init__.py +0 -0
  35. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/build_manifest.py +0 -0
  36. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/build_prepare.py +0 -0
  37. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/build_rootfs.py +0 -0
  38. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/config.py +0 -0
  39. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/task.py +0 -0
  40. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/integration/template/conanfile.py.mako +0 -0
  41. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/lbkit.py +0 -0
  42. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/log.py +0 -0
  43. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit/tools.py +0 -0
  44. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit.egg-info/SOURCES.txt +0 -0
  45. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit.egg-info/dependency_links.txt +0 -0
  46. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit.egg-info/entry_points.txt +0 -0
  47. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit.egg-info/requires.txt +0 -0
  48. {lbkit-0.5.6 → lbkit-0.5.7}/lbkit.egg-info/top_level.txt +0 -0
  49. {lbkit-0.5.6 → lbkit-0.5.7}/setup.cfg +0 -0
  50. {lbkit-0.5.6 → lbkit-0.5.7}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lbkit
3
- Version: 0.5.6
3
+ Version: 0.5.7
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.5.7'
@@ -1,14 +1,30 @@
1
1
  """语言相关类型定义"""
2
2
  import sys
3
+ from lbkit.errors import OdfValidateException
3
4
 
4
5
 
5
6
  class IdfValidator():
6
- def odf_schema(self, allow_ref, idf_validator):
7
+ validator = {}
8
+
9
+ def set_validator(self, value):
10
+ self.validator = value
11
+
12
+ def odf_validate(self):
13
+ idf_validator = idf_validator
14
+ return []
15
+
16
+ def odf_schema(self, allow_ref):
17
+ allow_ref = allow_ref
18
+ idf_validator = idf_validator
7
19
  return None
8
20
 
9
21
 
10
22
  class BoolValidator(IdfValidator):
11
- def odf_schema(self, allow_ref, idf_validator):
23
+ def odf_validate(self):
24
+ func = ["validate_odf_as_boolean(doc, node, prop, error_list)"]
25
+ return func
26
+
27
+ def odf_schema(self, allow_ref):
12
28
  if allow_ref:
13
29
  return {
14
30
  "anyOf": [
@@ -27,8 +43,12 @@ class BoolValidator(IdfValidator):
27
43
 
28
44
 
29
45
  class BoolArrayValidator(BoolValidator):
30
- def odf_schema(self, allow_ref, idf_validator):
31
- parent_schema = super().odf_schema(False, idf_validator)
46
+ def odf_validate(self):
47
+ func = ["validate_odf_as_boolean_v(doc, node, prop, error_list)"]
48
+ return func
49
+
50
+ def odf_schema(self, allow_ref):
51
+ parent_schema = super().odf_schema(False)
32
52
  if allow_ref:
33
53
  schema = {
34
54
  "anyOf": [
@@ -54,29 +74,57 @@ class IntegerValidator(IdfValidator):
54
74
  maximum = sys.maxsize * 2
55
75
  minimum = -(sys.maxsize + 1) * 2
56
76
 
57
- def __init__(self, max, min):
77
+ def __init__(self, max, min, signed=False):
58
78
  self.maximum = max
59
79
  self.minimum = min
80
+ self.signed = signed
81
+ if not self.signed and self.minimum < 0:
82
+ self.minimum = 0
83
+ if self.maximum < self.minimum:
84
+ raise OdfValidateException(f"The max value {self.maximum} less than or equal to {self.minimum}")
60
85
  super().__init__()
61
86
 
62
- def odf_schema(self, allow_ref, idf_validator):
63
- """
64
- 返回整数类型成员的ODF schema
65
- idf_validator为IDF模型中加载的数据验证器的对象
66
- """
67
- max = idf_validator.get("max", self.maximum)
87
+ def set_validator(self, value):
88
+ super().set_validator(value)
89
+ max = self.validator.get("max", self.maximum)
68
90
  if max > self.maximum:
69
91
  max = self.maximum
70
- min = idf_validator.get("min", self.minimum)
92
+ min = self.validator.get("min", self.minimum)
71
93
  if min < self.minimum:
72
94
  min = self.minimum
95
+ self.maximum = max
96
+ self.minimum = min
97
+ if not self.signed and self.minimum < 0:
98
+ self.minimum = 0
99
+ if self.maximum < self.minimum:
100
+ raise OdfValidateException(f"The max value {self.maximum} less than or equal to {self.minimum}")
101
+
102
+ def odf_validate(self):
103
+ func = []
104
+ if self.signed:
105
+ if self.minimum == -9223372036854775808:
106
+ func.append(f"validate_odf_as_signed(doc, node, prop, {self.maximum}, G_MININT64, error_list)")
107
+ else:
108
+ func.append(f"validate_odf_as_signed(doc, node, prop, {self.maximum}, {self.minimum}, error_list)")
109
+ else:
110
+ if self.maximum == 18446744073709551615:
111
+ func.append(f"validate_odf_as_unsigned(doc, node, prop, G_MAXUINT64, {self.minimum}, error_list)")
112
+ else:
113
+ func.append(f"validate_odf_as_unsigned(doc, node, prop, {self.maximum}, {self.minimum}, error_list)")
114
+ return func
115
+
116
+ def odf_schema(self, allow_ref):
117
+ """
118
+ 返回整数类型成员的ODF schema
119
+ idf_validator为IDF模型中加载的数据验证器的对象
120
+ """
73
121
  if allow_ref:
74
122
  return {
75
123
  "anyOf": [
76
124
  {
77
125
  "type": "integer",
78
- "maximum": max,
79
- "minimum": min
126
+ "maximum": self.maximum,
127
+ "minimum": self.minimum
80
128
  },
81
129
  {
82
130
  "$ref": "#/$defs/ref_value"
@@ -86,14 +134,33 @@ class IntegerValidator(IdfValidator):
86
134
  else:
87
135
  return {
88
136
  "type": "integer",
89
- "maximum": max,
90
- "minimum": min
137
+ "maximum": self.maximum,
138
+ "minimum": self.minimum
91
139
  }
92
140
 
93
141
 
94
142
  class IntegerArrayValidator(IntegerValidator):
95
- def odf_schema(self, allow_ref, idf_validator):
96
- parent_schema = super().odf_schema(False, idf_validator)
143
+ def odf_validate(self):
144
+ func = []
145
+ min = self.minimum
146
+ max = self.maximum
147
+ if self.signed:
148
+ if self.minimum <= -0x8000_0000_0000_0000:
149
+ min = "G_MININT64"
150
+ if self.maximum >= 0x7fff_ffff_ffff_ffff:
151
+ max = "G_MAXINT64"
152
+ else:
153
+ if self.maximum >= 0xffff_ffff_ffff_ffff:
154
+ max = "G_MAXUINT64"
155
+
156
+ if self.signed:
157
+ func.append(f"validate_odf_as_signed_v(doc, node, prop, {max}, {min}, error_list)")
158
+ else:
159
+ func.append(f"validate_odf_as_unsigned_v(doc, node, prop, {max}, {min}, error_list)")
160
+ return func
161
+
162
+ def odf_schema(self, allow_ref):
163
+ parent_schema = super().odf_schema(False)
97
164
  if allow_ref:
98
165
  schema = {
99
166
  "anyOf": [
@@ -119,35 +186,58 @@ class FloatValidator(IdfValidator):
119
186
  maximum = sys.float_info.max
120
187
  minimum = -sys.float_info.max
121
188
 
189
+ exclusive_max = None
190
+ exclusive_min = None
191
+
122
192
  def __init__(self):
193
+ self.max_key = "maximum"
194
+ self.max_val = self.maximum
195
+ self.min_key = "minimum"
196
+ self.min_val = self.minimum
123
197
  super().__init__()
124
198
 
125
- def odf_schema(self, allow_ref, idf_validator):
199
+ def odf_validate(self):
200
+ func = ["validate_odf_as_double(doc, node, prop, error_list)"]
201
+ if self.exclusive_max is not None:
202
+ func.append(f"validate_odf_as_float_exclusive_max(doc, node, prop, {self.exclusive_max}, error_list)")
203
+ elif self.maximum != sys.float_info.max:
204
+ func.append(f"validate_odf_as_float_max(doc, node, prop, {self.maximum}, error_list)")
205
+
206
+ if self.exclusive_min is not None:
207
+ func.append(f"validate_odf_as_float_exclusive_min(doc, node, prop, {self.exclusive_min}, error_list)")
208
+ elif self.minimum != (-sys.float_info.max):
209
+ func.append(f"validate_odf_as_float_min(doc, node, prop, {self.minimum}, error_list)")
210
+ return func
211
+
212
+ def set_validator(self, value):
213
+ super().set_validator(value)
214
+ self.maximum = self.validator.get("max", self.maximum)
215
+ self.minimum = self.validator.get("min", self.minimum)
216
+ self.exclusive_max = self.validator.get("exclusive_max", None)
217
+ self.exclusive_min = self.validator.get("exclusive_min", None)
218
+ self.max_key = "maximum"
219
+ self.min_key = "minimum"
220
+ self.max_val = self.maximum
221
+ self.min_val = self.minimum
222
+ if self.exclusive_max is not None:
223
+ self.max_key = "exclusiveMaximum"
224
+ self.max_val = self.exclusive_max
225
+ if self.exclusive_min is not None:
226
+ self.max_key = "exclusiveMinimum"
227
+ self.min_val = self.exclusive_min
228
+
229
+ def odf_schema(self, allow_ref):
126
230
  """
127
231
  返回整数类型成员的ODF schema
128
232
  idf_validator为IDF模型中加载的数据验证器的对象
129
233
  """
130
- max = idf_validator.get("max", self.maximum)
131
- min = idf_validator.get("min", self.minimum)
132
- exclusive_max = idf_validator.get("exclusive_max", None)
133
- exclusive_min = idf_validator.get("exclusive_min", None)
134
- max_key = "maximum"
135
- max_val = max
136
- min_key = "minimum"
137
- min_val = min
138
- if exclusive_max is not None:
139
- max_key = "exclusiveMaximum"
140
- max_val = exclusive_max
141
- if exclusive_min is not None:
142
- max_key = "exclusiveMinimum"
143
- min_val = exclusive_min
144
234
  if allow_ref:
145
235
  return {
146
236
  "anyOf": [
147
237
  {
148
238
  "type": "number",
149
- max_key: max_val,
150
- min_key: min_val
239
+ self.max_key: self.max_val,
240
+ self.min_key: self.min_val
151
241
  },
152
242
  {
153
243
  "$ref": "#/$defs/ref_value"
@@ -157,14 +247,27 @@ class FloatValidator(IdfValidator):
157
247
  else:
158
248
  return {
159
249
  "type": "number",
160
- max_key: max_val,
161
- min_key: min_val
250
+ self.max_key: self.max_val,
251
+ self.min_key: self.min_val
162
252
  }
163
253
 
164
254
 
165
255
  class FloatArrayValidator(FloatValidator):
166
- def odf_schema(self, allow_ref, idf_validator):
167
- parent_schema = super().odf_schema(False, idf_validator)
256
+ def odf_validate(self):
257
+ func = ["validate_odf_as_double_v(doc, node, prop, error_list)"]
258
+ if self.exclusive_max is not None:
259
+ func.append(f"validate_odf_as_float_exclusive_max_v(doc, node, prop, {self.exclusive_max}, error_list)")
260
+ elif self.maximum != sys.float_info.max:
261
+ func.append(f"validate_odf_as_float_max_v(doc, node, prop, {self.maximum}, error_list)")
262
+
263
+ if self.exclusive_min is not None:
264
+ func.append(f"validate_odf_as_float_exclusive_min_v(doc, node, prop, {self.exclusive_min}, error_list)")
265
+ elif self.minimum != (-sys.float_info.max):
266
+ func.append(f"validate_odf_as_float_min_v(doc, node, prop, {self.minimum}, error_list)")
267
+ return func
268
+
269
+ def odf_schema(self, allow_ref):
270
+ parent_schema = super().odf_schema(False)
168
271
  if allow_ref:
169
272
  schema = {
170
273
  "anyOf": [
@@ -191,32 +294,54 @@ class StringValidator(IdfValidator):
191
294
  self.pattern = pattern
192
295
  super().__init__()
193
296
 
194
- def odf_schema(self, allow_ref, idf_validator):
195
- pattern = idf_validator.get("pattern", self.pattern)
297
+ def set_validator(self, value):
298
+ self.pattern = self.validator.get("pattern", self.pattern)
299
+ super().set_validator(value)
300
+
301
+ def odf_validate(self):
302
+ func = []
303
+ if self.pattern is not None:
304
+ func.append(f"validate_odf_as_string(doc, node, prop, \"{self.pattern}\", error_list)")
305
+ else:
306
+ pattern = "^()|(((\\\\$)|[^$]).*)$"
307
+ func.append(f"validate_odf_as_string(doc, node, prop, \"{pattern}\", error_list)")
308
+ return func
309
+
310
+ def odf_schema(self, allow_ref):
196
311
  if allow_ref:
197
312
  schema = {
198
313
  "anyOf": [
199
314
  {
200
- "type": "string"
315
+ "type": "string",
316
+ "pattern": "^()|(((\\\\$)|[^$]).*)$"
201
317
  },
202
318
  {
203
319
  "$ref": "#/$defs/ref_value"
204
320
  }
205
321
  ]
206
322
  }
207
- if pattern is not None:
208
- schema["anyOf"][0]["pattern"] = pattern
323
+ if self.pattern is not None:
324
+ schema["anyOf"][0]["pattern"] = self.pattern
209
325
  else:
210
326
  schema = {
211
327
  "type": "string",
212
- "pattern": pattern
328
+ "pattern": self.pattern
213
329
  }
214
330
  return schema
215
331
 
216
332
 
217
333
  class StringArrayValidator(StringValidator):
218
- def odf_schema(self, allow_ref, idf_validator):
219
- parent_schema = super().odf_schema(False, idf_validator)
334
+ def odf_validate(self):
335
+ func = []
336
+ if self.pattern is not None:
337
+ func.append(f"validate_odf_as_string_v(doc, node, prop, \"{self.pattern}\", error_list)")
338
+ else:
339
+ pattern = "^()|(((\\\\$)|[^$]).*)$"
340
+ func.append(f"validate_odf_as_string_v(doc, node, prop, \"{pattern}\", error_list)")
341
+ return func
342
+
343
+ def odf_schema(self, allow_ref):
344
+ parent_schema = super().odf_schema(False)
220
345
  if allow_ref:
221
346
  schema = {
222
347
  "anyOf": [
@@ -240,7 +365,11 @@ class RefObjValidator(IdfValidator):
240
365
  def __init__(self):
241
366
  super().__init__()
242
367
 
243
- def odf_schema(self, allow_ref, idf_validator):
368
+ def odf_validate(self):
369
+ func = ["validate_odf_as_ref_obj(doc, node, prop, error_list)"]
370
+ return func
371
+
372
+ def odf_schema(self, allow_ref):
244
373
  if allow_ref:
245
374
  schema = {
246
375
  "anyOf": [
@@ -260,7 +389,11 @@ class RefObjValidator(IdfValidator):
260
389
 
261
390
 
262
391
  class RefObjArrayValidator(RefObjValidator):
263
- def odf_schema(self, allow_ref, idf_validator):
392
+ def odf_validate(self):
393
+ func = ["validate_odf_as_ref_obj_v(doc, node, prop, error_list)"]
394
+ return func
395
+
396
+ def odf_schema(self, allow_ref):
264
397
  if allow_ref:
265
398
  schema = {
266
399
  "anyOf": [
@@ -310,7 +443,7 @@ CTYPE_OBJS = {
310
443
  [],
311
444
  ["<arg_out> = g_variant_new_int16(<arg_name>)"],
312
445
  ["<arg_in> = g_variant_get_int16(<arg_name>)"],
313
- IntegerValidator(0x7fff, -(0x8000))
446
+ IntegerValidator(0x7fff, -(0x8000), True)
314
447
  ),
315
448
  "uint16": CTypeBase(
316
449
  ["guint16 <arg_name>"],
@@ -324,7 +457,7 @@ CTYPE_OBJS = {
324
457
  [],
325
458
  ["<arg_out> = g_variant_new_int32(<arg_name>)"],
326
459
  ["<arg_in> = g_variant_get_int32(<arg_name>)"],
327
- IntegerValidator(0x7fff_ffff, -(0x8000_0000))
460
+ IntegerValidator(0x7fff_ffff, -(0x8000_0000), True)
328
461
  ),
329
462
  "uint32": CTypeBase(
330
463
  ["guint32 <arg_name>"],
@@ -338,7 +471,7 @@ CTYPE_OBJS = {
338
471
  [],
339
472
  ["<arg_out> = g_variant_new_int64(<arg_name>)"],
340
473
  ["<arg_in> = g_variant_get_int64(<arg_name>)"],
341
- IntegerValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000))
474
+ IntegerValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
342
475
  ),
343
476
  "uint64": CTypeBase(
344
477
  ["guint64 <arg_name>"],
@@ -359,7 +492,7 @@ CTYPE_OBJS = {
359
492
  [],
360
493
  ["<arg_out> = g_variant_new_int64(<arg_name>)"],
361
494
  ["<arg_in> = g_variant_get_int64(<arg_name>)"],
362
- IntegerValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000))
495
+ IntegerValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
363
496
  ),
364
497
  "double": CTypeBase(
365
498
  ["gdouble <arg_name>"],
@@ -373,7 +506,7 @@ CTYPE_OBJS = {
373
506
  [],
374
507
  ["<arg_out> = g_variant_new_handle(<arg_name>)"],
375
508
  ["<arg_in> = g_variant_get_handle(<arg_name>)"],
376
- IntegerValidator(0x7fff_ffff_ffff_ffff, 0)
509
+ IntegerValidator(0x7fff_ffff_ffff_ffff, 0, True)
377
510
  ),
378
511
  "string": CTypeBase(
379
512
  ["<const>gchar *<arg_name>"],
@@ -394,7 +527,7 @@ CTYPE_OBJS = {
394
527
  ["gcl_free_p((void **)&<arg_name>)"],
395
528
  ["<arg_out> = gcl_signature_encode(<arg_name>)"],
396
529
  ["<arg_in> = g_strdup(g_variant_get_string(<arg_name>, NULL))"],
397
- StringValidator("^([abynqiuxtdsogv\\{\\}\\(\\)])+$")
530
+ StringValidator("^([abynqiuxtdsogv\\\\{\\\\}\\\\(\\\\)])+$")
398
531
  ),
399
532
  "variant": CTypeBase(
400
533
  ["GVariant *<arg_name>"],
@@ -422,7 +555,7 @@ CTYPE_OBJS = {
422
555
  ["gcl_free_p((void **)&<arg_name>)"],
423
556
  ["<arg_out> = gcl_array_int16_encode(<arg_name>, n_<arg_name>)"],
424
557
  ["<arg_in> = gcl_array_int16_decode(<arg_name>, &n_<arg_in>)"],
425
- IntegerArrayValidator(0x7fff, -(0x8000))
558
+ IntegerArrayValidator(0x7fff, -(0x8000), True)
426
559
  ),
427
560
  "array[uint16]": CTypeBase(
428
561
  ["gsize n_<arg_name>" ,"<const>guint16 *<arg_name>"],
@@ -436,7 +569,7 @@ CTYPE_OBJS = {
436
569
  ["gcl_free_p((void **)&<arg_name>)"],
437
570
  ["<arg_out> = gcl_array_int32_encode(<arg_name>, n_<arg_name>)"],
438
571
  ["<arg_in> = gcl_array_int32_decode(<arg_name>, &n_<arg_in>)"],
439
- IntegerArrayValidator(0x7fff_ffff, -(0x80000000))
572
+ IntegerArrayValidator(0x7fff_ffff, -(0x80000000), True)
440
573
  ),
441
574
  "array[uint32]": CTypeBase(
442
575
  ["gsize n_<arg_name>" ,"<const>guint32 *<arg_name>"],
@@ -450,7 +583,7 @@ CTYPE_OBJS = {
450
583
  ["gcl_free_p((void **)&<arg_name>)"],
451
584
  ["<arg_out> = gcl_array_int64_encode(<arg_name>, n_<arg_name>)"],
452
585
  ["<arg_in> = gcl_array_int64_decode(<arg_name>, &n_<arg_in>)"],
453
- IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000))
586
+ IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
454
587
  ),
455
588
  "array[uint64]": CTypeBase(
456
589
  ["gsize n_<arg_name>" ,"<const>guint64 *<arg_name>"],
@@ -464,14 +597,14 @@ CTYPE_OBJS = {
464
597
  ["gcl_free_p((void **)&<arg_name>)"],
465
598
  ["<arg_out> = gcl_array_int64_encode(<arg_name>, n_<arg_name>)"],
466
599
  ["<arg_in> = gcl_array_int64_decode(<arg_name>, &n_<arg_in>)"],
467
- IntegerArrayValidator(0xffff_ffff_ffff_ffff, 0)
600
+ IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000), True)
468
601
  ),
469
602
  "array[size]": CTypeBase(
470
603
  ["gsize n_<arg_name>" ,"<const>gsize *<arg_name>"],
471
604
  ["gcl_free_p((void **)&<arg_name>)"],
472
605
  ["<arg_out> = gcl_array_uint64_encode(<arg_name>, n_<arg_name>)"],
473
606
  ["<arg_in> = gcl_array_uint64_decode(<arg_name>, &n_<arg_in>)"],
474
- IntegerArrayValidator(0x7fff_ffff_ffff_ffff, -(0x8000_0000_0000_0000))
607
+ IntegerArrayValidator(0xffff_ffff_ffff_ffff, 0)
475
608
  ),
476
609
  "array[double]": CTypeBase(
477
610
  ["gsize n_<arg_name>" ,"<const>gdouble *<arg_name>"],
@@ -485,27 +618,27 @@ CTYPE_OBJS = {
485
618
  ["gcl_free_p((void **)&<arg_name>)"],
486
619
  ["<arg_out> = gcl_array_handle_encode(<arg_name>, n_<arg_name>)"],
487
620
  ["<arg_in> = gcl_array_handle_decode(<arg_name>, &n_<arg_in>)"],
488
- IntegerArrayValidator(0x7fff_ffff_ffff_ffff, 0)
621
+ IntegerArrayValidator(0x7fff_ffff_ffff_ffff, 0, True)
489
622
  ),
490
623
  "array[string]": CTypeBase(
491
- ["gchar * <const>*<arg_name>"],
624
+ ["gchar *<const>*<arg_name>"],
492
625
  ["gcl_strfreev_p(&<arg_name>)"],
493
626
  ["<arg_out> = gcl_array_string_encode(<arg_name>)"],
494
627
  ["<arg_in> = gcl_array_string_decode(<arg_name>)"],
495
628
  StringArrayValidator("^.*$")
496
629
  ),
497
630
  "array[object_path]": CTypeBase(
498
- ["gchar * <const>*<arg_name>"],
631
+ ["gchar *<const>*<arg_name>"],
499
632
  ["gcl_strfreev_p(&<arg_name>)"],
500
633
  ["<arg_out> = gcl_array_object_path_encode(<arg_name>)"],
501
634
  ["<arg_in> = gcl_array_object_path_decode(<arg_name>)"],
502
635
  StringArrayValidator("^(/[A-Z0-9a-z_]+)*$")
503
636
  ),
504
637
  "array[signature]": CTypeBase(
505
- ["gchar * <const>*<arg_name>"],
638
+ ["gchar *<const>*<arg_name>"],
506
639
  ["gcl_strfreev_p(&<arg_name>)"],
507
640
  ["<arg_out> = gcl_array_signature_encode(<arg_name>)"],
508
641
  ["<arg_in> = gcl_array_signature_decode(<arg_name>)"],
509
- StringArrayValidator("^([abynqiuxtdsogv\\{\\}\\(\\)])+$")
642
+ StringArrayValidator("^([abynqiuxtdsogv\\\\{\\\\}\\\\(\\\\)])+$")
510
643
  )
511
644
  }
@@ -12,6 +12,8 @@ log = Logger("gen_interface")
12
12
  class IDFException(Exception):
13
13
  pass
14
14
 
15
+ class IdfInterfacePlugin(Renderer):
16
+ actions = []
15
17
 
16
18
  class IdfInterfaceBase(Renderer):
17
19
  def __init__(self) -> None:
@@ -24,6 +26,7 @@ class IdfInterfaceBase(Renderer):
24
26
  self.dictionaries = {}
25
27
  self.enumerations = {}
26
28
  self.annotations = []
29
+ self.plugin: IdfInterfacePlugin = None
27
30
  self.description = None
28
31
  self.version = None
29
32
  self.alias = None
@@ -135,6 +138,39 @@ class IdfCtypeRender():
135
138
  if match:
136
139
  self.ctype = f"array[enum[{match.group(1)}]]"
137
140
 
141
+ def odf_validate(self, allow_ref):
142
+ log.debug(f"Get odf validate info, name: {self.name}, ctype: {self.ctype}")
143
+ if "variant" == self.ctype:
144
+ return []
145
+ match = re.match(f"^array\[({CTYPE_BASE_REG})\]$", self.ctype)
146
+ if match:
147
+ if "refobj" in self.flags:
148
+ valiator = RefObjArrayValidator()
149
+ return valiator.odf_validate()
150
+ ctype_obj = CTYPE_OBJS.get(self.ctype)
151
+ return ctype_obj.validator.odf_validate()
152
+ match = re.match(f"^({CTYPE_BASE_REG})$", self.ctype)
153
+ if match:
154
+ if "refobj" in self.flags:
155
+ valiator = RefObjValidator()
156
+ return valiator.odf_validate()
157
+ ctype_obj = CTYPE_OBJS.get(self.ctype)
158
+ return ctype_obj.validator.odf_validate()
159
+ # 非基础类型
160
+ is_array = False
161
+ ctype = self.ctype
162
+ match = re.match(f"^array\[(.*)\]$", ctype)
163
+ if match:
164
+ is_array = True
165
+ ctype = match.group(1)
166
+ match = re.match(f"^(struct|enum|dict)\[(.*)\]$", ctype)
167
+ _, stru_name = get_intfname_and_ctype(match.group(2))
168
+ if is_array:
169
+ return [f"_validate_odf_as_{match.group(1)}_{stru_name}_v(doc, node, prop, error_list)"]
170
+ else:
171
+ return [f"_validate_odf_as_{match.group(1)}_{stru_name}(doc, node, prop, error_list)"]
172
+
173
+
138
174
  def odf_schema(self, allow_ref):
139
175
  log.debug(f"Get odf schema info, name: {self.name}, ctype: {self.ctype}")
140
176
  if "variant" == self.ctype:
@@ -143,16 +179,16 @@ class IdfCtypeRender():
143
179
  if match:
144
180
  if "refobj" in self.flags:
145
181
  valiator = RefObjArrayValidator()
146
- return valiator.odf_schema(allow_ref, {})
182
+ return valiator.odf_schema(allow_ref)
147
183
  ctype_obj = CTYPE_OBJS.get(self.ctype)
148
- return ctype_obj.validator.odf_schema(allow_ref, {})
184
+ return ctype_obj.validator.odf_schema(allow_ref)
149
185
  match = re.match(f"^({CTYPE_BASE_REG})$", self.ctype)
150
186
  if match:
151
187
  if "refobj" in self.flags:
152
188
  valiator = RefObjValidator()
153
- return valiator.odf_schema(allow_ref, {})
189
+ return valiator.odf_schema(allow_ref)
154
190
  ctype_obj = CTYPE_OBJS.get(self.ctype)
155
- return ctype_obj.validator.odf_schema(allow_ref, {})
191
+ return ctype_obj.validator.odf_schema(allow_ref)
156
192
  # 非基础类型
157
193
  is_array = False
158
194
  ctype = self.ctype
@@ -231,7 +267,7 @@ class IdfCtypeRender():
231
267
  if match.group(1) == "struct":
232
268
  if is_array:
233
269
  # 结构体数组初始化时为二级空指针,以空指针结束
234
- return [f"{stru_name} * <const>*<arg_name>"]
270
+ return [f"{stru_name} *<const>*<arg_name>"]
235
271
  else:
236
272
  # 结构体成员初始化时为空结构体,由反序列化时填充内容
237
273
  return [f"<const>{stru_name} *<arg_name>"]
@@ -482,6 +518,7 @@ class IdfBase():
482
518
 
483
519
 
484
520
  class IdfMethod(IdfBase):
521
+ is_plugin = False
485
522
  def __init__(self, intf: IdfInterfaceBase, method_data):
486
523
  super().__init__(intf, method_data)
487
524
  self.parameters: IdfParameters = IdfParameters(intf, method_data.get("parameters", []))
@@ -529,6 +566,15 @@ class IdfStructure(IdfBase):
529
566
  }
530
567
  return odf
531
568
 
569
+
570
+ class IdfPluginAction(IdfMethod):
571
+ is_plugin = True
572
+
573
+ def __init__(self, intf: IdfInterfaceBase, method_data):
574
+ self.policy = method_data.get("policy", "continue_always")
575
+ super().__init__(intf, method_data)
576
+
577
+
532
578
  class IdfEnumeration(IdfBase):
533
579
  def __init__(self, intf: IdfInterfaceBase, enum_data):
534
580
  super().__init__(intf, enum_data)
@@ -652,6 +698,7 @@ class IdfInterface(IdfInterfaceBase):
652
698
  self.dictionaries: dict[str, IdfDictionary] = {}
653
699
  self.enumerations: dict[str, IdfEnumeration] = {}
654
700
  self.annotations: list[IdfAnnotation] = []
701
+ self.plugin: IdfInterfacePlugin = IdfInterfacePlugin()
655
702
  self.description = None
656
703
  self.version = None
657
704
  self.alias = None
@@ -721,6 +768,15 @@ class IdfInterface(IdfInterfaceBase):
721
768
  }
722
769
  return odf
723
770
 
771
+ @property
772
+ def fake_methods(self):
773
+ methods = []
774
+ for method in self.methods:
775
+ methods.append(method)
776
+ for action in self.plugin.actions:
777
+ methods.append(action)
778
+ return methods
779
+
724
780
  def load_elements(self):
725
781
  # 使用schema校验数据,确保IDF文件符合格式要求,减少程序处理过程中的异常处理
726
782
  # 验证失败时抛异常,此处不用处理,由外层处理
@@ -759,6 +815,12 @@ class IdfInterface(IdfInterfaceBase):
759
815
  for item in items:
760
816
  obj = IdfEnumeration(self, item)
761
817
  self.enumerations[obj.name] = obj
818
+ plugin = idf.get("plugin", None)
819
+ if plugin is not None:
820
+ items = plugin.get("actions", [])
821
+ for item in items:
822
+ obj = IdfPluginAction(self, item)
823
+ self.plugin.actions.append(obj)
762
824
  log.debug("interface signature: " + self.signature)
763
825
  for signal in self.signals:
764
826
  log.debug(f"{signal.name} signature: " + signal.signature)
@@ -2,6 +2,27 @@
2
2
  #include "${intf.name}.h"
3
3
 
4
4
  <% class_name = intf.alias %>\
5
+ ## 定义结构体ODF加载函数
6
+ % for name, stru in intf.structures.items():
7
+ /* ${name} structure object */
8
+ /* START: 结构体${name}及其数组类型的ODF校验函数 */
9
+ static gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
10
+ static gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
11
+
12
+ % endfor
13
+ ## 定义枚举ODF加载函数
14
+ % for name, enum in intf.enumerations.items():
15
+ /* START: 枚举${name}及其数组类型的ODF校验函数 */
16
+ static gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
17
+ static gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
18
+
19
+ % endfor
20
+ ## 定义字典ODF加载函数
21
+ % for name, dictionary in intf.dictionaries.items():
22
+ static gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
23
+ static gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node, GString *prop, GSList **error_list);
24
+
25
+ % endfor
5
26
  % for name, stru in intf.structures.items():
6
27
  /* ${name}结构体类型序列化(struct转GVariant)函数 */
7
28
  GVariant *${name}_encode(const ${name} *value)
@@ -131,6 +152,58 @@ void ${name}_free_v(${name} ***value)
131
152
  *value = NULL;
132
153
  }
133
154
 
155
+ gboolean _validate_odf_as_struct_${name}(yaml_document_t *doc, yaml_node_t *node,
156
+ GString *prop, GSList **error_list)
157
+ {
158
+ g_assert(doc && node && prop && error_list);
159
+ if (node->type != YAML_MAPPING_NODE) {
160
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
161
+ "the node type of property %s is not a mapping, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
162
+ return FALSE;
163
+ }
164
+ gsize len = prop->len;
165
+ gboolean valid = TRUE;
166
+ yaml_node_t *val;
167
+ GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
168
+ % for prop in stru.values.parameters:
169
+ val = g_hash_table_lookup(prop_table, "${prop.name}");
170
+ if (val) {
171
+ g_string_append(prop, ".${prop.name}");
172
+ % for func in prop.odf_validate(False):
173
+ if (!${func.replace("node,", "val,")})
174
+ valid = FALSE;
175
+ % endfor
176
+ g_string_truncate(prop, len);
177
+ }
178
+ % endfor
179
+ return valid;
180
+ }
181
+
182
+ gboolean _validate_odf_as_struct_${name}_v(yaml_document_t *doc, yaml_node_t *node,
183
+ GString *prop, GSList **error_list)
184
+ {
185
+ g_assert(doc && node && prop && error_list);
186
+ if (node->type != YAML_SEQUENCE_NODE) {
187
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
188
+ "the node type of property %s is not a sequence, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
189
+ return FALSE;
190
+ }
191
+ gsize len = prop->len;
192
+ gint i = 0;
193
+ yaml_node_t *val = NULL;
194
+ gboolean valid = TRUE;
195
+ for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
196
+ g_string_append_printf(prop, ".%d", i);
197
+ val = yaml_document_get_node(doc, *item);
198
+ if (!_validate_odf_as_struct_${name}(doc, val, prop, error_list)) {
199
+ valid = FALSE;
200
+ }
201
+ g_string_truncate(prop, len);
202
+ i++;
203
+ }
204
+ return valid;
205
+ }
206
+
134
207
  %endfor
135
208
  % for name, enum in intf.enumerations.items():
136
209
  ## 枚举序列化和反序列化函数
@@ -217,6 +290,50 @@ ${name} *${name}_decode_v(GVariant *in, gsize *n)
217
290
  return output;
218
291
  }
219
292
 
293
+ gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node,
294
+ GString *prop, GSList **error_list)
295
+ {
296
+ gboolean valid = validate_odf_as_string(doc, node, prop, "^.*$", error_list);
297
+ if (!valid) {
298
+ return FALSE;
299
+ }
300
+ const gchar *value = node->data.scalar.value;
301
+ for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
302
+ if (g_strcmp0(value, ${name}_as_string(i)) == 0) {
303
+ return TRUE;
304
+ }
305
+ }
306
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
307
+ "the value of property %s is is unsupportted, get %s", prop->str, value));
308
+ return FALSE;
309
+ return FALSE;
310
+ }
311
+
312
+ gboolean _validate_odf_as_enum_${name}_v(yaml_document_t *doc, yaml_node_t *node,
313
+ GString *prop, GSList **error_list)
314
+ {
315
+ g_assert(doc && node && prop && error_list);
316
+ if (node->type != YAML_SEQUENCE_NODE) {
317
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
318
+ "the node type of property %s is not a sequence, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
319
+ return FALSE;
320
+ }
321
+ gsize len = prop->len;
322
+ gint i = 0;
323
+ yaml_node_t *val = NULL;
324
+ gboolean valid = TRUE;
325
+ for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
326
+ g_string_append_printf(prop, ".%d", i);
327
+ val = yaml_document_get_node(doc, *item);
328
+ if (!_validate_odf_as_enum_${name}(doc, val, prop, error_list)) {
329
+ valid = FALSE;
330
+ }
331
+ g_string_truncate(prop, len);
332
+ i++;
333
+ }
334
+ return valid;
335
+ }
336
+
220
337
  % endfor
221
338
  ## 生成字典处理函数
222
339
  % for name, dictionary in intf.dictionaries.items():
@@ -555,6 +672,80 @@ void ${name}_free_v(${name} ***value)
555
672
  *value = NULL;
556
673
  }
557
674
 
675
+ gboolean _validate_odf_as_dict_${name}(yaml_document_t *doc, yaml_node_t *node,
676
+ GString *prop, GSList **error_list)
677
+ {
678
+ g_assert(doc && node && prop && error_list);
679
+ if (node->type != YAML_SEQUENCE_NODE) {
680
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
681
+ "the node type of property %s is not a sequence, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
682
+ return FALSE;
683
+ }
684
+
685
+ gboolean valid = TRUE;
686
+ GHashTable *prop_table = NULL;
687
+ yaml_node_t *val = NULL;
688
+ gsize len = prop->len;
689
+ yaml_node_item_t *top = node->data.sequence.items.top;
690
+ yaml_node_item_t *start = node->data.sequence.items.start;
691
+ for (yaml_node_item_t *item = start; item < top; item++) {
692
+ val = yaml_document_get_node(doc, *item);
693
+ ## 转换成hash表以获取key和properties
694
+ prop_table = load_yaml_mapping_to_hash_table(doc, val);
695
+ yaml_node_t *key = g_hash_table_lookup(prop_table, "key");
696
+ yaml_node_t *properties = g_hash_table_lookup(prop_table, "properties");
697
+ g_hash_table_destroy(prop_table);
698
+ g_string_append_printf(prop, ".key");
699
+ % for func in dictionary.key_obj.odf_validate(False):
700
+ if (!${func.replace("node,", "key,")})
701
+ valid = FALSE;
702
+ % endfor
703
+ g_string_truncate(prop, len);
704
+
705
+ ## 转换成hash表
706
+ prop_table = load_yaml_mapping_to_hash_table(doc, properties);
707
+ ## 迭代所有成员并从odf中还原数据
708
+ % for prop in dictionary.values.parameters:
709
+ val = g_hash_table_lookup(prop_table, "${prop.name}");
710
+ if (val) {
711
+ g_string_append(prop, ".properties.${prop.name}");
712
+ % for func in prop.odf_validate(False):
713
+ if (!${func.replace("node,", "val,")})
714
+ valid = FALSE;
715
+ % endfor
716
+ g_string_truncate(prop, len);
717
+ }
718
+ % endfor
719
+ g_hash_table_destroy(prop_table);
720
+ }
721
+ return valid;
722
+ }
723
+
724
+ gboolean _validate_odf_as_dict_${name}_v(yaml_document_t *doc, yaml_node_t *node,
725
+ GString *prop, GSList **error_list)
726
+ {
727
+ g_assert(doc && node && prop && error_list);
728
+ if (node->type != YAML_SEQUENCE_NODE) {
729
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
730
+ "the node type of property %s is not a sequence, get %s", prop->str, gcl_yaml_node_type_str(node->type)));
731
+ return FALSE;
732
+ }
733
+ gsize len = prop->len;
734
+ gint i = 0;
735
+ yaml_node_t *val = NULL;
736
+ gboolean valid = TRUE;
737
+ for (yaml_node_item_t *item = node->data.sequence.items.start; item < node->data.sequence.items.top; item++) {
738
+ g_string_append_printf(prop, ".%d", i);
739
+ val = yaml_document_get_node(doc, *item);
740
+ if (!_validate_odf_as_dict_${name}(doc, val, prop, error_list)) {
741
+ valid = FALSE;
742
+ }
743
+ g_string_truncate(prop, len);
744
+ i++;
745
+ }
746
+ return valid;
747
+ }
748
+
558
749
  % endfor
559
750
  ## 生成每个属性的GDBus属性GDBusPropertyInfo对象name}
560
751
  % for prop in intf.properties:
@@ -625,7 +816,8 @@ const ${class_name}_Properties *${class_name}_properties_const(void)
625
816
  return &_${class_name}_properties;
626
817
  }
627
818
 
628
- % for method in intf.methods:
819
+ % for method in intf.fake_methods:
820
+ % if not method.is_plugin:
629
821
  ## 方法${method.name}的请求体序列化函数
630
822
  /* ${class_name}_${method.name}_Req请求结构体类型序列化(struct转GVariant)函数 */
631
823
  static GVariant *${class_name}_${method.name}_Req_encode(${class_name}_${method.name}_Req *value)
@@ -669,6 +861,7 @@ static ${class_name}_${method.name}_Req *${class_name}_${method.name}_Req_decode
669
861
  % endfor
670
862
  return output;
671
863
  }
864
+ % endif
672
865
 
673
866
  ## 方法${method.name}的请求体释放函数
674
867
  /* ${class_name}_${method.name}_Req结构体指针释放 */
@@ -686,6 +879,7 @@ void ${class_name}_${method.name}_Req_free(${class_name}_${method.name}_Req **va
686
879
  *value = NULL;
687
880
  }
688
881
 
882
+ % if not method.is_plugin:
689
883
  /* ${class_name}_${method.name}_Rsp请求结构体类型序列化(struct转GVariant)函数 */
690
884
  static GVariant *${class_name}_${method.name}_Rsp_encode(${class_name}_${method.name}_Rsp *value)
691
885
  {
@@ -728,6 +922,7 @@ static ${class_name}_${method.name}_Rsp *${class_name}_${method.name}_Rsp_decode
728
922
  % endfor
729
923
  return output;
730
924
  }
925
+ % endif
731
926
 
732
927
  ## 方法${method.name}的响应体释放函数
733
928
  /* ${class_name}_${method.name}_Rsp结构体指针释放 */
@@ -749,8 +944,7 @@ void ${class_name}_${method.name}_Rsp_free(${class_name}_${method.name}_Rsp **va
749
944
  static ${class_name}_Methods _${class_name}_methods =
750
945
  {
751
946
  % for method in intf.methods:
752
- .${method.name} =
753
- {
947
+ .${method.name} = {
754
948
  .name = "${method.name}",
755
949
  .req_signature = "${method.in_signature}",
756
950
  .req_decode = (gcl_message_decode)${class_name}_${method.name}_Req_decode,
@@ -762,8 +956,7 @@ static ${class_name}_Methods _${class_name}_methods =
762
956
  .rsp_free = (gcl_message_free)${class_name}_${method.name}_Rsp_free,
763
957
  },
764
958
  % endfor
765
- .__reserved__ =
766
- {
959
+ .__reserved__ = {
767
960
  .name = NULL,
768
961
  }
769
962
  };
@@ -773,6 +966,96 @@ ${class_name}_Methods *${class_name}_methods(void)
773
966
  return &_${class_name}_methods;
774
967
  }
775
968
 
969
+ % if len(intf.plugin.actions) > 0:
970
+ % for action in intf.plugin.actions:
971
+ typedef struct {
972
+ gpointer user_data;
973
+ ${class_name}_${action.name}_action action;
974
+ } _${class_name}_${action.name}_PluginAction;
975
+ static GSList *_${class_name}_${action.name}_actions = NULL;
976
+ static GMutex _${class_name}_${action.name}_lock;
977
+
978
+ /* Register a new plugin action, can't register repeated with same action */
979
+ int ${class_name}_${action.name}_register(const gchar *req_signature, const gchar *rsp_signature,
980
+ ${class_name}_${action.name}_action action, gpointer user_data)
981
+ {
982
+ if (!req_signature) {
983
+ log_error("Register ${action.name} failed because parameter req_signature is NULL");
984
+ return -1;
985
+ }
986
+ if (!rsp_signature) {
987
+ log_error("Register ${action.name} failed because parameter rsp_signature is NULL");
988
+ return -1;
989
+ }
990
+ if (g_strcmp0(req_signature, "${action.in_signature}") != 0) {
991
+ log_error("Register ${action.name} failed because parameter "
992
+ "req_signature not match with \"{action.in_signature}\", get \"%s\"", req_signature);
993
+ return -1;
994
+ }
995
+ if (g_strcmp0(rsp_signature, "${action.out_signature}") != 0) {
996
+ log_error("Register ${action.name} failed because parameter "
997
+ "rsp_signature not match with \"{action.out_signature}\", get \"%s\"", rsp_signature);
998
+ return -1;
999
+ }
1000
+ g_mutex_lock(&_${class_name}_${action.name}_lock);
1001
+ for (GSList *item = _${class_name}_${action.name}_actions; item; item = item->next) {
1002
+ _${class_name}_${action.name}_PluginAction *old_handler = (_${class_name}_${action.name}_PluginAction *)item->data;
1003
+ if (action == old_handler->action || user_data == old_handler->user_data) {
1004
+ g_mutex_unlock(&_${class_name}_${action.name}_lock);
1005
+ return 0;
1006
+ }
1007
+ }
1008
+ _${class_name}_${action.name}_PluginAction *handler = g_new0(_${class_name}_${action.name}_PluginAction, 1);
1009
+ handler->user_data = user_data;
1010
+ handler->action = action;
1011
+ _${class_name}_${action.name}_actions = g_slist_append(_${class_name}_${action.name}_actions, handler);
1012
+ g_mutex_unlock(&_${class_name}_${action.name}_lock);
1013
+ return 0;
1014
+ }
1015
+
1016
+ void ${class_name}_${action.name}_unregister(${class_name}_${action.name}_action action)
1017
+ {
1018
+ g_mutex_lock(&_${class_name}_${action.name}_lock);
1019
+ for (GSList *item = _${class_name}_${action.name}_actions; item; item = item->next) {
1020
+ _${class_name}_${action.name}_PluginAction *old_handler = (_${class_name}_${action.name}_PluginAction *)item->data;
1021
+ if (action == old_handler->action) {
1022
+ _${class_name}_${action.name}_actions = g_slist_remove(_${class_name}_${action.name}_actions, old_handler);
1023
+ g_free(old_handler);
1024
+ break;
1025
+ }
1026
+ old_handler = NULL;
1027
+ }
1028
+ g_mutex_unlock(&_${class_name}_${action.name}_lock);
1029
+ }
1030
+
1031
+ int ${class_name}_${action.name}_run(const ${class_name} *object, const ${class_name}_${action.name}_Req *req, ${class_name}_${action.name}_Rsp **rsp)
1032
+ {
1033
+ gint result = 0;
1034
+ g_mutex_lock(&_${class_name}_${action.name}_lock);
1035
+ for (GSList *item = _${class_name}_${action.name}_actions; item; item = item->next) {
1036
+ if (rsp && *rsp) {
1037
+ ${class_name}_${action.name}_Rsp_free(rsp);
1038
+ }
1039
+ _${class_name}_${action.name}_PluginAction *handler = (_${class_name}_${action.name}_PluginAction *)item->data;
1040
+ gint ret = handler->action(object, req, rsp, handler->user_data);
1041
+ if (ret != 0)
1042
+ result = ret;
1043
+ % if action.policy == "return_any_success":
1044
+ /* return when any action success(ret == 0) */
1045
+ if (ret == 0)
1046
+ break;
1047
+ % elif action.policy == "return_any_fail":
1048
+ /* return when any action failed(ret != 0) */
1049
+ if (ret != 0)
1050
+ break;
1051
+ % endif
1052
+ }
1053
+ g_mutex_unlock(&_${class_name}_${action.name}_lock);
1054
+ return result;
1055
+ }
1056
+
1057
+ % endfor
1058
+ % endif
776
1059
  % for signal in intf.signals:
777
1060
  ## 方法${method.name}的响应体序列化函数
778
1061
  /* ${class_name}_${signal.name}_Msg请求结构体类型序列化(struct转GVariant)函数 */
@@ -855,3 +1138,67 @@ ${class_name}_Signals *${class_name}_signals(void)
855
1138
  {
856
1139
  return &_${class_name}_signals;
857
1140
  }
1141
+
1142
+ % for prop in intf.properties:
1143
+ static gboolean _validate_odf_prop_${prop.name}(yaml_document_t *doc, GHashTable *prop_table,
1144
+ GString *prop, GSList **error_list)
1145
+ {
1146
+ gboolean valid = TRUE;
1147
+ gsize len = prop->len;
1148
+ yaml_node_t *node = g_hash_table_lookup(prop_table, "${prop.name}");
1149
+ do {
1150
+ if (!node)
1151
+ break;
1152
+ g_string_append(prop, ".${prop.name}");
1153
+ % if "refobj" not in prop.flags:
1154
+ if (validate_odf_as_ref_prop(doc, node, prop))
1155
+ break;
1156
+ % endif
1157
+ % if len(prop.odf_validate(True)) > 1:
1158
+ % for func in prop.odf_validate(True):
1159
+ if (valid && !${func})
1160
+ valid = FALSE;
1161
+ % endfor
1162
+ % else:
1163
+ % for func in prop.odf_validate(True):
1164
+ valid = ${func};
1165
+ % endfor
1166
+ % endif
1167
+ } while (0);
1168
+ g_string_truncate(prop, len);
1169
+ return valid;
1170
+ }
1171
+
1172
+ %endfor
1173
+ gboolean ${intf.name.replace(".", "_")}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
1174
+ const gchar *object_name, GSList **error_list)
1175
+ {
1176
+ g_assert(doc && node && object_name && error_list);
1177
+ if (!doc || !node || !object_name || !error_list) {
1178
+ return FALSE;
1179
+ }
1180
+
1181
+ if (node->type != YAML_MAPPING_NODE) {
1182
+ *error_list = g_slist_append(*error_list, g_error_new(ODF_ERROR, ODF_ERROR_PROP_VALIDATE_TYPE_ERROR,
1183
+ "the node type of object %s is not a mapping, get %s", object_name, gcl_yaml_node_type_str(node->type)));
1184
+ return FALSE;
1185
+ }
1186
+ GString *prop = g_string_sized_new(128);
1187
+ g_string_printf(prop, "%s", object_name);
1188
+ gboolean valid = TRUE;
1189
+ GHashTable *prop_table = load_yaml_mapping_to_hash_table(doc, node);
1190
+ % for prop in stru.values.parameters:
1191
+ valid = _validate_odf_prop_${prop.name}(doc, prop_table, prop, error_list) && valid;
1192
+ % endfor
1193
+ return valid;
1194
+ }
1195
+
1196
+ % if len(intf.plugin.actions) > 0:
1197
+ static void __attribute__((constructor(101))) ${class_name}_public_register(void)
1198
+ {
1199
+ % for action in intf.plugin.actions:
1200
+ g_mutex_init(&_${class_name}_${action.name}_lock);
1201
+ % endfor
1202
+ }
1203
+
1204
+ % endif
@@ -129,7 +129,7 @@ void ${name}_free_v(${name} ***value);
129
129
  % endfor
130
130
 
131
131
  ### 开始生成方法的请求体、响应体和处理函数
132
- % for method in intf.methods:
132
+ % for method in intf.fake_methods:
133
133
  /* ${method.name}方法的请求体 */
134
134
  typedef struct {
135
135
  % for arg in method.parameters.parameters:
@@ -148,7 +148,9 @@ typedef struct {
148
148
  % endfor
149
149
  } ${class_name}_${method.name}_Rsp;
150
150
 
151
+ % if not method.is_plugin:
151
152
  typedef int (*${class_name}_${method.name}_Method)(const ${class_name} *object, const ${class_name}_${method.name}_Req *req, ${class_name}_${method.name}_Rsp **rsp, GError **error);
153
+ % endif
152
154
  void ${class_name}_${method.name}_Req_free(${class_name}_${method.name}_Req **value);
153
155
  void ${class_name}_${method.name}_Rsp_free(${class_name}_${method.name}_Rsp **value);
154
156
  %endfor
@@ -172,6 +174,18 @@ typedef struct {
172
174
  GclMethod __reserved__;
173
175
  } ${class_name}_Methods;
174
176
 
177
+ % if len(intf.plugin.actions) > 0:
178
+ % for action in intf.plugin.actions:
179
+ typedef int (*${class_name}_${action.name}_action)(const ${class_name} *object, const ${class_name}_${action.name}_Req *req, ${class_name}_${action.name}_Rsp **rsp, gpointer user_data);
180
+
181
+ /* Register a new plugin action, can't register repeated with same action and user_data */
182
+ int ${class_name}_${action.name}_register(const gchar *req_signature, const gchar *rsp_signature,
183
+ ${class_name}_${action.name}_action action, gpointer user_data);
184
+ void ${class_name}_${action.name}_unregister(${class_name}_${action.name}_action action);
185
+ int ${class_name}_${action.name}_run(const ${class_name} *object, const ${class_name}_${action.name}_Req *req, ${class_name}_${action.name}_Rsp **rsp);
186
+
187
+ % endfor
188
+ % endif
175
189
  ### 开始生成方法的请求体、响应体和处理函数
176
190
  % for signal in intf.signals:
177
191
  /* ${signal.name}信号的消息体 */
@@ -220,6 +234,9 @@ typedef struct {
220
234
  GclProperty __reserved__;
221
235
  } ${class_name}_Properties;
222
236
 
237
+
238
+ gboolean ${intf.name.replace(".", "_")}_validate_odf(yaml_document_t *doc, yaml_node_t *node,
239
+ const gchar *object_name, GSList **error_list);
223
240
  // 不要使用此函数返回的对象,需要使用${class_name}_properties() 或${class_name}_Cli_properties()
224
241
  const ${class_name}_Properties *${class_name}_properties_const(void);
225
242
  // 同时加载客户端和服务端时Processer是共享的,因此可以直接调用Processer定义的handler函数
@@ -1,3 +1,4 @@
1
+ <% from lbkit.codegen.ctype_defination import StringValidator %>\
1
2
  #include "gcl_base.h"
2
3
  #include "${intf.name}.h"
3
4
 
@@ -236,6 +237,8 @@ gboolean ${class_name}_${signal.name}_Signal(const ${class_name} *object, const
236
237
  static GclObject *_${class_name}_create(const gchar *obj_name, gpointer opaque);
237
238
  static void _load_from_odf(yaml_document_t *doc, yaml_node_t *node, GclObject *gcl_obj,
238
239
  property_reference_loaded ref_loaded, gpointer user_data);
240
+ static void _valid_from_odf(yaml_document_t *doc, yaml_node_t *node, const gchar *object_name);
241
+
239
242
  /*
240
243
  * interface: ${intf.name}
241
244
  % for c in intf.description.split("\n"):
@@ -244,7 +247,8 @@ static void _load_from_odf(yaml_document_t *doc, yaml_node_t *node, GclObject *g
244
247
  */
245
248
  static GclInterface _${class_name}_interface = {
246
249
  .create = _${intf.alias}_create,
247
- .load_from_odf = (object_load_from_odf)_load_from_odf,
250
+ .validate_odf = ${intf.name.replace(".", "_")}_validate_odf,
251
+ .load_from_odf = _load_from_odf,
248
252
  .is_remote = 0,
249
253
  .name = "${intf.name}",
250
254
  .properties = (GclProperty *)&${properties},
@@ -37,7 +37,6 @@ gboolean ${class_name}_${signal.name}_Signal(const ${class_name} *object, const
37
37
  GclInterface *${class_name}_interface(void);
38
38
  #define ${class_name.upper()}_INTERFACE ${class_name}_interface()
39
39
  ${class_name}_Properties *${class_name}_properties(void);
40
- ${class_name}_Methods *${class_name}_methods(void);
41
40
 
42
41
  #ifdef __cplusplus
43
42
  }
@@ -88,4 +88,4 @@ def validate_yml_with_json_schema(yml_file, default_json_schema_file):
88
88
  except ValidationError as exc:
89
89
  raise PackageConfigException(f"validate {yml_file} failed, schema file is {schema_file}, "
90
90
  f"message: {exc.message}\n"
91
- "installing redhat.vscode-yaml plugin in vscode will help you write odf files") from exec
91
+ "installing redhat.vscode-yaml plugin in vscode will help you write odf files")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lbkit
3
- Version: 0.5.6
3
+ Version: 0.5.7
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.5.6'
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