lbkit 0.6.8__tar.gz → 0.7.1__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 (61) hide show
  1. {lbkit-0.6.8/lbkit.egg-info → lbkit-0.7.1}/PKG-INFO +1 -1
  2. lbkit-0.7.1/lbkit/__init__.py +2 -0
  3. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/codegen.py +1 -1
  4. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/client.c.mako +129 -8
  5. lbkit-0.7.1/lbkit/codegen/template/client.h.mako +204 -0
  6. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/public.c.mako +18 -18
  7. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/public.h.mako +15 -11
  8. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/server.c.mako +138 -18
  9. lbkit-0.7.1/lbkit/codegen/template/server.h.mako +153 -0
  10. {lbkit-0.6.8 → lbkit-0.7.1/lbkit.egg-info}/PKG-INFO +1 -1
  11. lbkit-0.6.8/lbkit/__init__.py +0 -2
  12. lbkit-0.6.8/lbkit/codegen/template/client.h.mako +0 -117
  13. lbkit-0.6.8/lbkit/codegen/template/server.h.mako +0 -63
  14. {lbkit-0.6.8 → lbkit-0.7.1}/AUTHORS +0 -0
  15. {lbkit-0.6.8 → lbkit-0.7.1}/LICENSE +0 -0
  16. {lbkit-0.6.8 → lbkit-0.7.1}/MANIFEST.in +0 -0
  17. {lbkit-0.6.8 → lbkit-0.7.1}/README.md +0 -0
  18. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/build_conan_parallel.py +0 -0
  19. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/ci_robot/__init__.py +0 -0
  20. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/ci_robot/gitee.py +0 -0
  21. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/cli.py +0 -0
  22. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/__init__.py +0 -0
  23. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/ctype_defination.py +0 -0
  24. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/idf_interface.py +0 -0
  25. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/renderer.py +0 -0
  26. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/interface.c.mako +0 -0
  27. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
  28. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/__init__.py +0 -0
  29. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/arg_parser.py +0 -0
  30. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/build.py +0 -0
  31. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/template/conanbase.mako +0 -0
  32. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/template/deploy.mako +0 -0
  33. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/component/test.py +0 -0
  34. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/errors.py +0 -0
  35. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/helper.py +0 -0
  36. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/__init__.py +0 -0
  37. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/build_image.py +0 -0
  38. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/build_manifest.py +0 -0
  39. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/build_prepare.py +0 -0
  40. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/build_rootfs.py +0 -0
  41. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/config.py +0 -0
  42. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/task.py +0 -0
  43. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/template/conanfile.py.mako +0 -0
  44. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/integration/template/rootfs.py.mako +0 -0
  45. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/lbkit.py +0 -0
  46. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/log.py +0 -0
  47. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/misc.py +0 -0
  48. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/tools.py +0 -0
  49. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/utils/__init__.py +0 -0
  50. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/utils/images/__init__.py +0 -0
  51. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit/utils/images/emmc.py +0 -0
  52. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit.egg-info/SOURCES.txt +0 -0
  53. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit.egg-info/dependency_links.txt +0 -0
  54. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit.egg-info/entry_points.txt +0 -0
  55. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit.egg-info/requires.txt +0 -0
  56. {lbkit-0.6.8 → lbkit-0.7.1}/lbkit.egg-info/top_level.txt +0 -0
  57. {lbkit-0.6.8 → lbkit-0.7.1}/setup.cfg +0 -0
  58. {lbkit-0.6.8 → lbkit-0.7.1}/setup.py +0 -0
  59. {lbkit-0.6.8 → lbkit-0.7.1}/test/__init__.py +0 -0
  60. {lbkit-0.6.8 → lbkit-0.7.1}/test/test_codegen.py +0 -0
  61. {lbkit-0.6.8 → lbkit-0.7.1}/test/test_helper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: lbkit
3
- Version: 0.6.8
3
+ Version: 0.7.1
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.7.1'
@@ -17,7 +17,7 @@ from lbkit.misc import SmartFormatter
17
17
  lb_cwd = os.path.split(os.path.realpath(__file__))[0]
18
18
  log = Logger("codegen")
19
19
 
20
- __version__=3
20
+ __version__=4
21
21
 
22
22
  class CodeGen(object):
23
23
  def __init__(self, args):
@@ -14,10 +14,10 @@ static const ${intf.alias}_Signals *${signal_processer} = NULL;
14
14
  ## 私有属性或者只读属性
15
15
  % if not prop.private and prop.access != "read":
16
16
  % if prop.deprecated:
17
- __attribute__((__deprecated__)) gint ${class_name}_set_${prop.name}(const ${class_name} *object,
17
+ __attribute__((__deprecated__)) gint ${class_name}_set_${prop.name}(${class_name} object,
18
18
  ${", ".join(prop.declare()).replace("<arg_name>", prop.name).replace("<const>", "const ")}, GError **error)
19
19
  % else:
20
- gint ${class_name}_set_${prop.name}(const ${class_name} *object,
20
+ gint ${class_name}_set_${prop.name}(${class_name} object,
21
21
  ${", ".join(prop.declare()).replace("<arg_name>", prop.name).replace("<const>", "const ")}, GError **error)
22
22
  % endif
23
23
  {
@@ -32,10 +32,10 @@ gint ${class_name}_set_${prop.name}(const ${class_name} *object,
32
32
  ## 私有或只写属性不允许读
33
33
  % if not prop.private and prop.access != "write":
34
34
  % if prop.deprecated:
35
- __attribute__((__deprecated__)) gint ${class_name}_get_${prop.name}(const ${class_name} *object,
35
+ __attribute__((__deprecated__)) gint ${class_name}_get_${prop.name}(${class_name} object,
36
36
  ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
37
37
  % else:
38
- gint ${class_name}_get_${prop.name}(const ${class_name} *object, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
38
+ gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
39
39
  % endif
40
40
  {
41
41
  % if "gsize n_" in prop.declare()[0]:
@@ -80,7 +80,7 @@ gint ${class_name}_get_${prop.name}(const ${class_name} *object, ${", ".join(pro
80
80
  % if len(method.parameters.parameters) > 0:
81
81
  <% REQ_PARA = f'const {intf.alias}_{method.name}_Req *req, ' %>\
82
82
  % endif
83
- int ${class_name}_Call_${method.name}(const ${class_name} *object,
83
+ int ${class_name}_Call_${method.name}(${class_name} object,
84
84
  ${REQ_PARA}${RSP_PARA}gint timeout,
85
85
  GError **error)
86
86
  {
@@ -115,6 +115,16 @@ static LBInterface _${class_name}_interface = {
115
115
  .interface = NULL, /* load from usr/share/dbus-1/interfaces/${intf.name}.xml by lb_init */
116
116
  };
117
117
 
118
+ static LBBase *_get_real_object(LBO *object)
119
+ {
120
+ LBBase *real = (LBBase *)strstr((const char *)object, LB_MAGIC);
121
+ if ((gconstpointer)real != (gconstpointer)object) {
122
+ log_error("Get real object fail, Perhaps the memory has been freed, call abort() now");
123
+ abort();
124
+ }
125
+ return real;
126
+ }
127
+
118
128
  /**
119
129
  * @brief 销毁对象
120
130
  *
@@ -123,11 +133,11 @@ static LBInterface _${class_name}_interface = {
123
133
  static void _${class_name}_destroy(LBO *lb_obj)
124
134
  {
125
135
  g_assert(lb_obj);
126
- ${class_name} *obj = (${class_name} *)lb_obj;
136
+ struct _${intf.alias} *obj = (struct _${intf.alias} *)_get_real_object(lb_obj);
127
137
  g_rec_mutex_clear(obj->_base.lock);
128
138
  g_free(obj->_base.lock);
129
139
  ${intf.alias}_clean(obj);
130
- memset(obj, 0, sizeof(${class_name}));
140
+ memset(obj, 0, sizeof(struct _${intf.alias}));
131
141
  }
132
142
 
133
143
  /**
@@ -138,7 +148,7 @@ static void _${class_name}_destroy(LBO *lb_obj)
138
148
  */
139
149
  static LBO *_${class_name}_create(const gchar *obj_name, gpointer opaque)
140
150
  {
141
- ${class_name} *obj = g_new0(${class_name}, 1);
151
+ struct _${intf.alias} *obj = g_new0(struct _${intf.alias}, 1);
142
152
  memcpy(obj->_base.magic, LB_MAGIC, strlen(LB_MAGIC) + 1);
143
153
  obj->_base.lock = g_new0(GRecMutex, 1);
144
154
  g_rec_mutex_init(obj->_base.lock);
@@ -182,6 +192,117 @@ ${class_name}_Properties *${class_name}_properties(void)
182
192
  return &${properties};
183
193
  }
184
194
 
195
+ % if codegen_version >= 4:
196
+ ${class_name} ${class_name}_get(const gchar *well_known, const gchar *name)
197
+ {
198
+ return lb_impl._cli_get(&_${class_name}_interface, well_known, name);
199
+ }
200
+
201
+ ${class_name} ${class_name}_new(const gchar *well_known, const gchar *obj_name)
202
+ {
203
+ LBO *obj = lb_impl._cli_new(&_${class_name}_interface, well_known, obj_name);
204
+ return (${class_name} )obj;
205
+ }
206
+
207
+ /* 减对象引用计数 */
208
+ void ${class_name}_unref(${class_name} *obj)
209
+ {
210
+ lb_impl._unref((LBO **)obj);
211
+ }
212
+
213
+ /* 加对象引用计数 */
214
+ ${class_name} ${class_name}_ref(${class_name} obj)
215
+ {
216
+ return (${class_name} )lb_impl._ref((LBO *)obj);
217
+ }
218
+
219
+ /* 设置在位状态 */
220
+ void ${class_name}_present_set(${class_name} obj, gboolean present)
221
+ {
222
+ lb_impl._present_set((LBO *)obj, present);
223
+ }
224
+
225
+ /* 获取在位状态 */
226
+ gboolean ${class_name}_present(${class_name} obj)
227
+ {
228
+ return lb_impl._present((LBO *)obj);
229
+ }
230
+
231
+ /* 绑定数据 */
232
+ void ${class_name}_bind(${class_name} lb_obj, gpointer data, GDestroyNotify destroy_func)
233
+ {
234
+ lb_impl._bind((LBO *)lb_obj, data, destroy_func);
235
+ }
236
+
237
+ /* 获取绑定数据 */
238
+ gpointer ${class_name}_data(${class_name} lb_obj)
239
+ {
240
+ return lb_impl._data((LBO *)lb_obj);
241
+ }
242
+
243
+ /* @notes 属性对象属性值变更(后)事件 */
244
+ gint ${class_name}_on_prop_changed(${class_name} lb_obj, const gchar *prop, ${class_name}_after_changed_hook pc, gpointer user_data, GDestroyNotify destroy)
245
+ {
246
+ return lb_impl._on_prop_changed((LBO *)lb_obj, prop, (lbo_after_changed_hook)pc, user_data, destroy);
247
+ }
248
+
249
+ /* 取消监听,成功取消监听时会调用监听时设置的destroy回调清除注册时的user_data */
250
+ void ${class_name}_on_prop_changed_cancel(${class_name} lb_obj, const gchar *prop, ${class_name}_after_changed_hook pc, gconstpointer user_data)
251
+ {
252
+ lb_impl._on_prop_changed_cancel((LBO *)lb_obj, prop, (lbo_after_changed_hook)pc, user_data);
253
+ }
254
+
255
+ /* 对象变更事件 */
256
+ void ${class_name}_on_changed(${class_name}_on_changed_hook cb, gpointer user_data, GDestroyNotify destroy)
257
+ {
258
+ lb_impl._on_changed(&_${class_name}_interface, (LbObjectHook)cb, user_data, destroy);
259
+ }
260
+
261
+ /* 注册对象释放回调 */
262
+ void ${class_name}_before_destroy(${class_name} lb_obj, GHookFunc cb, gpointer user_data)
263
+ {
264
+ lb_impl._before_destroy((LBO *)lb_obj, cb, user_data);
265
+ }
266
+
267
+ /* 查询第n个对象 */
268
+ ${class_name} ${class_name}_nth(int nth)
269
+ {
270
+ return (${class_name} )lb_impl._nth(&_${class_name}_interface, nth);
271
+ }
272
+
273
+ /* 查询对象名称 */
274
+ const gchar *${class_name}_name(${class_name} obj)
275
+ {
276
+ return lbo_name((LBO *)obj);
277
+ }
278
+
279
+ /* 对象加锁 */
280
+ void ${class_name}_lock(${class_name} obj)
281
+ {
282
+ lbo_lock((LBO *)obj);
283
+ }
284
+
285
+ /* 对象解锁 */
286
+ void ${class_name}_unlock(${class_name} obj)
287
+ {
288
+ lbo_unlock((LBO *)obj);
289
+ }
290
+
291
+ /* 对象列表查询接口 */
292
+ GSList *${class_name}_list(void)
293
+ {
294
+ return lb_impl._list(&_${class_name}_interface);
295
+ }
296
+
297
+ % for prop in intf.properties:
298
+ /* 监听属性${prop.name}变更 */
299
+ void ${class_name}_${prop.name}_hook(const ${class_name}_property_hook *hook)
300
+ {
301
+ lb_impl._prop_hook(&${properties}.${prop.name}, (const LBPropertyHook *)hook);
302
+ }
303
+
304
+ % endfor
305
+ % endif
185
306
  static void __attribute__((constructor(150))) ${class_name}_register(void)
186
307
  {
187
308
  // 从公共库中复制信号处理函数
@@ -0,0 +1,204 @@
1
+ <% from lbkit.tools import hump2underline %>\
2
+ #ifndef __${"_".join(intf.name.upper().split(".", -1))}_CLI_H__
3
+ #define __${"_".join(intf.name.upper().split(".", -1))}_CLI_H__
4
+
5
+ #include <glib-2.0/glib.h>
6
+ #include <glib-2.0/gio/gio.h>
7
+ #include "lb_base.h"
8
+ #include "public/${intf.name}.h"
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+ <% class_name = intf.alias + "_Cli"%>
14
+ typedef ${intf.alias} ${class_name};
15
+ typedef ${intf.alias}_Properties ${class_name}_Properties;
16
+
17
+ % for prop in intf.properties:
18
+ % if not prop.private:
19
+ /*
20
+ * property: ${prop.name}
21
+ % if len(prop.description.strip()) > 0:
22
+ *
23
+ % for line in prop.description.split("\n"):
24
+ % if len(line.strip()) > 0:
25
+ * ${line.strip()}
26
+ % endif
27
+ % endfor
28
+ % endif
29
+ */
30
+ ## 私有属性或者只读属性不允许写
31
+ % if not prop.private and prop.access != "read":
32
+ % if prop.deprecated:
33
+ __attribute__((__deprecated__)) gint ${class_name}_set_${prop.name}(${class_name} object, ${", ".join(prop.declare()).replace("<arg_name>", "value").replace("<const>", "const ")}, GError **error);
34
+ % else:
35
+ gint ${class_name}_set_${prop.name}(${class_name} object, ${", ".join(prop.declare()).replace("<arg_name>", "value").replace("<const>", "const ")}, GError **error);
36
+ % endif
37
+ % endif
38
+ % if not prop.private and prop.access != "write":
39
+ % if prop.deprecated:
40
+ __attribute__((__deprecated__)) gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error);
41
+ % else:
42
+ gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error);
43
+ % endif
44
+ % endif
45
+ % endif
46
+ % endfor
47
+
48
+ % for method in intf.methods:
49
+ <% RSP_PARA = f'' %>\
50
+ <% REQ_PARA = f'' %>\
51
+ % if len(method.returns.parameters) > 0:
52
+ <% RSP_PARA = f'{intf.alias}_{method.name}_Rsp **rsp, ' %>\
53
+ % endif
54
+ % if len(method.parameters.parameters) > 0:
55
+ <% REQ_PARA = f'const {intf.alias}_{method.name}_Req *req, ' %>\
56
+ % endif
57
+ /*
58
+ * method: ${method.name}
59
+ % if len(method.description.strip()) > 0:
60
+ *
61
+ % for line in method.description.split("\n"):
62
+ % if len(line.strip()) > 0:
63
+ * ${line.strip()}
64
+ % endif
65
+ % endfor
66
+ % endif
67
+ */
68
+ % if method.deprecated:
69
+ __attribute__((__deprecated__)) int ${class_name}_Call_${method.name}(${class_name} object,
70
+ ${REQ_PARA}${RSP_PARA}gint timeout,
71
+ GError **error);
72
+ % else:
73
+ int ${class_name}_Call_${method.name}(${class_name} object,
74
+ ${REQ_PARA}${RSP_PARA}gint timeout,
75
+ GError **error);
76
+ % endif
77
+ % endfor
78
+
79
+ % for signal in intf.signals:
80
+ /*
81
+ * signal: ${signal.name}
82
+ % if len(signal.description.strip()) > 0:
83
+ *
84
+ % for line in signal.description.split("\n"):
85
+ % if len(line.strip()) > 0:
86
+ * ${line.strip()}
87
+ % endif
88
+ % endfor
89
+ % endif
90
+ */
91
+ typedef void (*${class_name}_${signal.name}_Signal)(${class_name} object, const gchar *destination,
92
+ const ${intf.alias}_${signal.name}_Msg *req, gpointer user_data);
93
+ /**/
94
+ % if signal.deprecated:
95
+ __attribute__((__deprecated__)) guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
96
+ const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
97
+ % else:
98
+ guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
99
+ const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
100
+ % endif
101
+ % if signal.deprecated:
102
+ __attribute__((__deprecated__)) void ${class_name}_Unsubscribe_${signal.name}(guint *id);
103
+ % else:
104
+ void ${class_name}_Unsubscribe_${signal.name}(guint *id);
105
+ % endif
106
+
107
+ % endfor
108
+
109
+ ${class_name}_Properties *${class_name}_properties(void);
110
+ LBInterface *${class_name}_interface(void);
111
+ #define ${hump2underline(class_name).upper()} ${class_name}_interface()
112
+
113
+ % if codegen_version >= 4:
114
+ /* notes: 对象变更加回调函数 */
115
+ typedef void (*${class_name}_on_changed_hook)(${class_name} lb_obj, gpointer user_data);
116
+ /* notes: 属性变更后回调,远程对象或本地对象变更后都会调用 */
117
+ typedef void (*${class_name}_after_changed_hook)(${class_name} object, const LBProperty *prop, GVariant *value, gpointer user_data);
118
+ /* notes: 属性变更前回调,返回-1表示阻止值变更,一般用于值合法性校验,只在被远程操作时才会生效,本地变更值不会回调 */
119
+ typedef gint (*${class_name}_before_change_hook)(${class_name} object, const LBProperty *prop, GVariant *value, gpointer user_data, GError **error);
120
+
121
+ /* 属性值变更回调钩子 */
122
+ typedef struct {
123
+ ${class_name}_after_changed_hook after; /* 属性变更(写入对象数据区后)后回调函数 */
124
+ ${class_name}_before_change_hook before; /* 属性变更前回调函数,返回0后继续调用,返回非0时中止,所有before都成功时执行属性变更 */
125
+ gpointer user_data;
126
+ } ${class_name}_property_hook;
127
+ /* 查询对象 */
128
+ ${class_name} ${class_name}_get(const gchar *well_known, const gchar *name);
129
+ /* 创建对象 */
130
+ ${class_name} ${class_name}_new(const gchar *well_known, const gchar *obj_name);
131
+ /* 减对象引用计数 */
132
+ void ${class_name}_unref(${class_name} *obj);
133
+ /* 加对象引用计数 */
134
+ ${class_name} ${class_name}_ref(${class_name} obj);
135
+ /* 设置在位状态 */
136
+ void ${class_name}_present_set(${class_name} obj, gboolean present);
137
+ /* 获取在位状态 */
138
+ gboolean ${class_name}_present(${class_name} obj);
139
+ /* 绑定数据 */
140
+ void ${class_name}_bind(${class_name} lb_obj, gpointer data, GDestroyNotify destroy_func);
141
+ /* 获取绑定数据 */
142
+ gpointer ${class_name}_data(${class_name} lb_obj);
143
+ /* @notes 属性对象属性值变更(后)事件 */
144
+ gint ${class_name}_on_prop_changed(${class_name} lb_obj, const gchar *prop, ${class_name}_after_changed_hook pc, gpointer user_data, GDestroyNotify destroy);
145
+ /* 取消监听,成功取消监听时会调用监听时设置的destroy回调清除注册时的user_data */
146
+ void ${class_name}_on_prop_changed_cancel(${class_name} lb_obj, const gchar *prop, ${class_name}_after_changed_hook pc, gconstpointer user_data);
147
+ /* 对象变更事件 */
148
+ void ${class_name}_on_changed(${class_name}_on_changed_hook cb, gpointer user_data, GDestroyNotify destroy);
149
+ /* 注册对象释放回调 */
150
+ void ${class_name}_before_destroy(${class_name} lb_obj, GHookFunc cb, gpointer user_data);
151
+ /*
152
+ * 查询第n个对象
153
+ * @notes: 支持正逆向查询第n个对象,返回的对象需要使用lbo_unref减引用计数
154
+ * 正向查找传入非负n,以0开始计数,表示查找最早创建的第n个对象;
155
+ * 逆向查找传入负数n,以-1开始计数,依次为-2、-3等,表示查找最后创建的第n个对象。
156
+ */
157
+ ${class_name} ${class_name}_nth(int nth);
158
+ /* 查询对象名称 */
159
+ const gchar *${class_name}_name(${class_name} obj);
160
+ /* 对象加锁 */
161
+ void ${class_name}_lock(${class_name} obj);
162
+ /* 对象解锁 */
163
+ void ${class_name}_unlock(${class_name} obj);
164
+ /* 对象列表查询接口 */
165
+ GSList *${class_name}_list(void);
166
+ /* 监听属性 */
167
+ % for prop in intf.properties:
168
+ void ${class_name}_${prop.name}_hook(const ${class_name}_property_hook *hook);
169
+ % endfor
170
+
171
+ static inline void ${class_name}_unref_p(${class_name} obj)
172
+ {
173
+ ${class_name}_unref(&obj);
174
+ }
175
+
176
+ static inline void _cleanup_${class_name}_(${class_name} *ptr)
177
+ {
178
+ if (ptr && *ptr) {
179
+ ${class_name}_unref(ptr);
180
+ }
181
+ }
182
+
183
+ static inline void ${class_name}_list_free(GSList **list)
184
+ {
185
+ g_assert(list);
186
+ g_slist_free_full(*list, (GDestroyNotify)${class_name}_unref_p);
187
+ *list = NULL;
188
+ }
189
+
190
+ static inline void _cleanup_${class_name}_list(GSList **ptr)
191
+ {
192
+ if (ptr && *ptr) {
193
+ ${class_name}_list_free(ptr);
194
+ }
195
+ }
196
+
197
+ #define cleanup_${class_name} __attribute__((cleanup(_cleanup_${class_name}_)))
198
+ #define cleanup_${class_name}_list __attribute__((cleanup(_cleanup_${class_name}_list)))
199
+ % endif
200
+ #ifdef __cplusplus
201
+ }
202
+ #endif
203
+
204
+ #endif /* __${"_".join(intf.name.upper().split(".", -1))}_CLI_H__ */
@@ -83,13 +83,13 @@ static gboolean __attribute__((unused)) _validate_odf_as_dict_${name}_v(yaml_doc
83
83
  % endfor
84
84
  % for name, stru in intf.structures.items():
85
85
  /* ${name}结构体类型序列化(struct转GVariant)函数 */
86
- GVariant *${name}_encode(const ${name} *value)
86
+ GVariant *${name}_encode(const struct _${name} *value)
87
87
  {
88
88
  % if stru.values.has_variant_value:
89
89
  g_assert(value);
90
90
 
91
91
  % else:
92
- static ${name} default_val;
92
+ static struct _${name} default_val;
93
93
  if (value == NULL) {
94
94
  value = &default_val;
95
95
  }
@@ -111,11 +111,11 @@ GVariant *${name}_encode(const ${name} *value)
111
111
  * ${name}结构体类型反序列化(GVariant转struct)函数,返回以NULL结束的指针数组
112
112
  * Note: return an EMPTY ${name} object when `in` is NULL
113
113
  */
114
- ${name} *${name}_decode(GVariant *in)
114
+ struct _${name} *${name}_decode(GVariant *in)
115
115
  {
116
116
  GVariantIter iter;
117
117
  __attribute__((unused)) GVariant *tmp = NULL;
118
- ${name} *output = g_new0(${name}, 1);
118
+ struct _${name} *output = g_new0(struct _${name}, 1);
119
119
  if (!in) {
120
120
  return output;
121
121
  }
@@ -133,7 +133,7 @@ ${name} *${name}_decode(GVariant *in)
133
133
  }
134
134
 
135
135
  /* ${name}结构体指针释放 */
136
- void ${name}_free(${name} **value)
136
+ void ${name}_free(struct _${name} **value)
137
137
  {
138
138
  if (!value || !(*value)) {
139
139
  return;
@@ -145,7 +145,7 @@ void ${name}_free(${name} **value)
145
145
  }
146
146
 
147
147
  /* ${name}结构体指针释放 */
148
- void ${name}_clean(${name} *value)
148
+ void ${name}_clean(struct _${name} *value)
149
149
  {
150
150
  if (!value) {
151
151
  return;
@@ -159,7 +159,7 @@ void ${name}_clean(${name} *value)
159
159
  }
160
160
 
161
161
  /* ${name}结构体组件类型序列化(struct转GVariant)函数,values以NULL结束的数组 */
162
- GVariant *${name}_encode_v(${name} * const *values)
162
+ GVariant *${name}_encode_v(struct _${name} * const *values)
163
163
  {
164
164
  GVariantBuilder builder;
165
165
  GVariant *tmp = NULL;
@@ -173,7 +173,7 @@ GVariant *${name}_encode_v(${name} * const *values)
173
173
  }
174
174
 
175
175
  /* ${name}结构体数组类型反序列化(GVariant转struct)函数,返回以NULL结束的指针数组 */
176
- ${name} **${name}_decode_v(GVariant *in)
176
+ struct _${name} **${name}_decode_v(GVariant *in)
177
177
  {
178
178
  if (!in) {
179
179
  return NULL;
@@ -187,7 +187,7 @@ ${name} **${name}_decode_v(GVariant *in)
187
187
  if (n == 0) {
188
188
  return NULL;
189
189
  }
190
- ${name} **output = g_new0(${name} *, n + 1);
190
+ struct _${name} **output = g_new0(struct _${name} *, n + 1);
191
191
  for (gsize i = 0; i < n; i++) {
192
192
  tmp = g_variant_iter_next_value(&iter);
193
193
  output[i] = ${name}_decode(tmp);
@@ -197,7 +197,7 @@ ${name} **${name}_decode_v(GVariant *in)
197
197
  }
198
198
 
199
199
  /* ${name}结构体指针数组释放 */
200
- void ${name}_free_v(${name} ***value)
200
+ void ${name}_free_v(struct _${name} ***value)
201
201
  {
202
202
  if(!value || !(*value)) {
203
203
  return;
@@ -356,7 +356,7 @@ gboolean _validate_odf_as_enum_${name}(yaml_document_t *doc, yaml_node_t *node,
356
356
  if (!valid) {
357
357
  return FALSE;
358
358
  }
359
- const gchar *value = node->data.scalar.value;
359
+ const gchar *value = (const gchar *)node->data.scalar.value;
360
360
  for (int i = 0; i <= ${len(enum.values.parameters)}; i++) {
361
361
  if (g_strcmp0(value, ${name}_as_string(i)) == 0) {
362
362
  return TRUE;
@@ -843,8 +843,10 @@ static GDBusPropertyInfo ${class_name}_property_${prop.name} =
843
843
 
844
844
  % endif
845
845
  % endfor
846
+ ## 只有自动生成工具版本号大于等于3的才会生成get和set方法
847
+ % if codegen_version >= 3:
846
848
  % if len(intf.properties):
847
- LBBase *_get_real_object(const ${class_name} *object)
849
+ static LBBase *_get_real_object(${class_name} object)
848
850
  {
849
851
  LBBase *real = (LBBase *)strstr((const char *)object, LB_MAGIC);
850
852
  if ((gconstpointer)real != (gconstpointer)object) {
@@ -854,13 +856,11 @@ LBBase *_get_real_object(const ${class_name} *object)
854
856
  return real;
855
857
  }
856
858
  % endif
857
- ## 只有自动生成工具版本号大于等于3的才会生成get和set方法
858
- % if codegen_version >= 3:
859
859
  % for prop in intf.properties:
860
860
  static void ${class_name}_set_${prop.name}_variant(LBO *object, GVariant *value)
861
861
  {
862
862
  g_assert(value && object);
863
- ${class_name} *real_obj = (${class_name} *)_get_real_object(object);
863
+ struct _${class_name} *real_obj = (struct _${class_name} *)_get_real_object(object);
864
864
  % for line in prop.free_func():
865
865
  ${line.replace("<arg_name>", "real_obj->" + prop.name)};
866
866
  % endfor
@@ -873,7 +873,7 @@ static GVariant *${class_name}_get_${prop.name}_variant(LBO *object)
873
873
  {
874
874
  g_assert(object);
875
875
  GVariant *out = NULL;
876
- ${class_name} *real_obj = (${class_name} *)_get_real_object(object);
876
+ struct _${class_name} *real_obj = (struct _${class_name} *)_get_real_object(object);
877
877
  % for line in prop.encode_func():
878
878
  ${line.replace("<arg_out>", "out").replace("n_<arg_name>", "real_obj->n_" + prop.name).replace("<arg_name>", "real_obj->" + prop.name)};
879
879
  % endfor
@@ -894,7 +894,7 @@ static ${class_name}_Properties _${class_name}_properties =
894
894
  % else:
895
895
  .info = NULL, /* load from /usr/share/dbus-1/interfaces/${intf.name} by lb_init */
896
896
  % endif
897
- .offset = offsetof(${class_name}, ${prop.name}),
897
+ .offset = offsetof(struct _${class_name}, ${prop.name}),
898
898
  % if codegen_version >= 3:
899
899
  .flags = ${prop.desc_flags},
900
900
  .set = ${class_name}_set_${prop.name}_variant,
@@ -1138,7 +1138,7 @@ void ${class_name}_${action.name}_unregister(${class_name}_${action.name}_action
1138
1138
  <% REQ_PARA = f', const {class_name}_{action.name}_Req *req' %>\
1139
1139
  <% REQ_NAME = f', req' %>\
1140
1140
  % endif
1141
- int ${class_name}_${action.name}_run(const ${class_name} *object${REQ_PARA}${RSP_PARA})
1141
+ int ${class_name}_${action.name}_run(${class_name} object${REQ_PARA}${RSP_PARA})
1142
1142
  {
1143
1143
  gint result = 0;
1144
1144
  g_mutex_lock(&_${class_name}_${action.name}_lock);
@@ -38,7 +38,11 @@ typedef enum {
38
38
  % endfor
39
39
  % endif
40
40
  */
41
+ % if name != class_name:
41
42
  typedef struct _${name} ${name};
43
+ % else:
44
+ typedef const struct _${name} * ${name};
45
+ % endif
42
46
  % endfor
43
47
  % for name, enum in intf.enumerations.items():
44
48
  /*
@@ -151,18 +155,18 @@ ${name} *${name}_new(void);
151
155
  % for name, stru in intf.structures.items():
152
156
  /* ${name} structure object */
153
157
  /* START: 结构体${name}及其数组类型的序列化、反序列化、释放函数 */
154
- GVariant *${name}_encode(const ${name} *value);
155
- ${name} *${name}_decode(GVariant *in);
158
+ GVariant *${name}_encode(const struct _${name} *value);
159
+ struct _${name} *${name}_decode(GVariant *in);
156
160
  // Clean up the memory of structure and it's all members, `*value` will to NULL
157
- void ${name}_free(${name} **value);
161
+ void ${name}_free(struct _${name} **value);
158
162
  // Clean up the memory of members managed by structure ${name}
159
- void ${name}_clean(${name} *value);
163
+ void ${name}_clean(struct _${name} *value);
160
164
 
161
- ${name} **${name}_decode_v(GVariant *in);
162
- GVariant *${name}_encode_v(${name} * const *value);
165
+ struct _${name} **${name}_decode_v(GVariant *in);
166
+ GVariant *${name}_encode_v(struct _${name} * const *value);
163
167
  // Clean up the memory of structure array and it's all members, `*value` will to NULL
164
- void ${name}_free_v(${name} ***value);
165
- /* END: 结构体${name}及其数组类型的序列化、反序列化、释放函数 */
168
+ void ${name}_free_v(struct _${name} ***value);
169
+ /* END: 结构体struct _${name}及其数组类型的序列化、反序列化、释放函数 */
166
170
 
167
171
  % endfor
168
172
  ## 定义枚举编解码函数
@@ -210,7 +214,7 @@ typedef struct {
210
214
  } ${class_name}_${method.name}_Rsp;
211
215
 
212
216
  % if not method.is_plugin:
213
- typedef int (*${class_name}_${method.name}_Method)(const ${class_name} *object,
217
+ typedef int (*${class_name}_${method.name}_Method)(${class_name} object,
214
218
  const ${class_name}_${method.name}_Req *req,
215
219
  ${class_name}_${method.name}_Rsp **rsp,
216
220
  GError **error, gpointer ext_data);
@@ -252,13 +256,13 @@ typedef struct {
252
256
  % if len(action.parameters.parameters) > 0:
253
257
  <% REQ_PARA = f', const {class_name}_{action.name}_Req *req' %>\
254
258
  % endif
255
- typedef int (*${class_name}_${action.name}_action)(const ${class_name} *object${REQ_PARA}${RSP_PARA}, gpointer user_data);
259
+ typedef int (*${class_name}_${action.name}_action)(${class_name} object${REQ_PARA}${RSP_PARA}, gpointer user_data);
256
260
 
257
261
  /* Register a new plugin action, can't register repeated with same action and user_data */
258
262
  int ${class_name}_${action.name}_register(const gchar *req_signature, const gchar *rsp_signature,
259
263
  ${class_name}_${action.name}_action action, gpointer user_data);
260
264
  void ${class_name}_${action.name}_unregister(${class_name}_${action.name}_action action);
261
- int ${class_name}_${action.name}_run(const ${class_name} *object${REQ_PARA}${RSP_PARA});
265
+ int ${class_name}_${action.name}_run(${class_name} object${REQ_PARA}${RSP_PARA});
262
266
 
263
267
  % endfor
264
268
  % endif