lbkit 0.8.0__tar.gz → 0.8.2__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.
- {lbkit-0.8.0/lbkit.egg-info → lbkit-0.8.2}/PKG-INFO +1 -1
- lbkit-0.8.2/lbkit/__init__.py +2 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/codegen.py +59 -9
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/idf_interface.py +3 -4
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/client.c.mako +54 -42
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/client.h.mako +35 -26
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/public.c.mako +89 -50
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/public.h.mako +53 -17
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/server.c.mako +67 -51
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/server.h.mako +24 -20
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/arg_parser.py +1 -1
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/build.py +13 -6
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/template/conanbase.mako +10 -6
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/template/deploy.mako +3 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/build_manifest.py +11 -5
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/config.py +7 -1
- {lbkit-0.8.0 → lbkit-0.8.2/lbkit.egg-info}/PKG-INFO +1 -1
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit.egg-info/SOURCES.txt +0 -1
- {lbkit-0.8.0 → lbkit-0.8.2}/test/test_codegen.py +1 -1
- lbkit-0.8.0/lbkit/__init__.py +0 -2
- lbkit-0.8.0/lbkit/utils/version.py +0 -38
- {lbkit-0.8.0 → lbkit-0.8.2}/AUTHORS +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/LICENSE +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/MANIFEST.in +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/README.md +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/build_conan_parallel.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/ci_robot/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/ci_robot/gitee.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/cli.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/ctype_defination.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/renderer.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/interface.c.mako +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/codegen/template/interface.introspect.xml.mako +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/component/test.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/errors.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/helper.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/build_image.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/build_prepare.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/build_rootfs.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/task.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/template/conanfile.py.mako +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/integration/template/rootfs.py.mako +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/lbkit.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/log.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/misc.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/tools.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/utils/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/utils/images/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit/utils/images/emmc.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit.egg-info/dependency_links.txt +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit.egg-info/entry_points.txt +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit.egg-info/requires.txt +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/lbkit.egg-info/top_level.txt +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/setup.cfg +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/setup.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/test/__init__.py +0 -0
- {lbkit-0.8.0 → lbkit-0.8.2}/test/test_helper.py +0 -0
|
@@ -8,7 +8,6 @@ import json
|
|
|
8
8
|
import yaml
|
|
9
9
|
import argparse
|
|
10
10
|
from lbkit.codegen.idf_interface import IdfInterface
|
|
11
|
-
from lbkit.utils.version import Version, X_VER
|
|
12
11
|
|
|
13
12
|
from mako.lookup import TemplateLookup
|
|
14
13
|
from lbkit.log import Logger
|
|
@@ -21,16 +20,54 @@ log = Logger("codegen")
|
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class CodeGenHistory():
|
|
24
|
-
def __init__(self, lb_base: str, description: str):
|
|
23
|
+
def __init__(self, lb_base: str, description: str, lb_base_compatible_required: str):
|
|
25
24
|
self.lb_base = lb_base
|
|
26
25
|
self.description = description
|
|
26
|
+
# lb_base兼容性配置项
|
|
27
|
+
self.lb_base_compatible_required = lb_base_compatible_required
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Version():
|
|
31
|
+
def __init__(self, ver_str):
|
|
32
|
+
if not re.match("^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$", ver_str):
|
|
33
|
+
raise Exception("Version string {ver_str} not match with regex ^([0-9]|([1-9][0-9]*))\\.([0-9]|([1-9][0-9]*))$")
|
|
34
|
+
self.info: CodeGenHistory = history_versions.get(ver_str)
|
|
35
|
+
chunks = ver_str.split(".")
|
|
36
|
+
self.major = int(chunks[0])
|
|
37
|
+
self.minor = int(chunks[1])
|
|
38
|
+
self.str = str(self.major) + "." + str(self.minor)
|
|
39
|
+
|
|
40
|
+
def bt(self, next_ver):
|
|
41
|
+
next = Version(next_ver)
|
|
42
|
+
if self.major > next.major or (self.major == next.major and self.minor > next.minor):
|
|
43
|
+
return True
|
|
44
|
+
return False
|
|
45
|
+
|
|
46
|
+
def be(self, next_ver):
|
|
47
|
+
next = Version(next_ver)
|
|
48
|
+
if self.major > next.major or (self.major == next.major and self.minor >= next.minor):
|
|
49
|
+
return True
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
def lt(self, next_ver):
|
|
53
|
+
next = Version(next_ver)
|
|
54
|
+
if self.major < next.major or (self.major == next.major and self.minor < next.minor):
|
|
55
|
+
return True
|
|
56
|
+
return False
|
|
57
|
+
|
|
58
|
+
def le(self, next_ver):
|
|
59
|
+
next = Version(next_ver)
|
|
60
|
+
if self.major < next.major or (self.major == next.major and self.minor <= next.minor):
|
|
61
|
+
return True
|
|
62
|
+
return False
|
|
27
63
|
|
|
28
64
|
# 历史自动生成版本号,计划用于用于生成代码稳定性测试
|
|
29
65
|
# TODO: 支持生成代码稳定性测试,确保生成的代码一致性
|
|
30
66
|
history_versions = {
|
|
31
|
-
"5.0": CodeGenHistory("lb_base/[>=0.8.1 <0.9.0]", "简化接口类名定义;简化枚举变量在接口间传递时的字符串定义")
|
|
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")
|
|
32
69
|
}
|
|
33
|
-
__version__=Version("5.
|
|
70
|
+
__version__=Version("5.1")
|
|
34
71
|
|
|
35
72
|
|
|
36
73
|
def version_check(ver_str: str):
|
|
@@ -44,10 +81,17 @@ def version_check(ver_str: str):
|
|
|
44
81
|
log.error(f" {ver}: {msg}")
|
|
45
82
|
raise Exception(f"Can't found the valid version for {ver_str}")
|
|
46
83
|
|
|
84
|
+
def codegen_version_max():
|
|
85
|
+
max_v = __version__
|
|
86
|
+
for ver_str, _ in history_versions.items():
|
|
87
|
+
next_ver = Version(ver_str)
|
|
88
|
+
if next_ver.bt(max_v.str):
|
|
89
|
+
max_v = next_ver
|
|
90
|
+
return max_v.str
|
|
47
91
|
|
|
48
92
|
def codegen_version_arg(parser: argparse.ArgumentParser, default=__version__.str, short_arg="-cv", full_arg="--codegen_version"):
|
|
49
93
|
# 默认的自动生成工具版本号为2
|
|
50
|
-
help=f'''must less than or equal to {
|
|
94
|
+
help=f'''must less than or equal to {codegen_version_max()}, default: {default}
|
|
51
95
|
|
|
52
96
|
codegen versions:
|
|
53
97
|
'''
|
|
@@ -67,6 +111,7 @@ class CodeGen(object):
|
|
|
67
111
|
code_types = ["server", "client", "public"]
|
|
68
112
|
if code_type != "all":
|
|
69
113
|
code_types = [code_type]
|
|
114
|
+
log.info(f"Codegen version: {self.codegen_version.str}")
|
|
70
115
|
for ct in code_types:
|
|
71
116
|
os.makedirs(os.path.join(directory, ct), exist_ok=True)
|
|
72
117
|
out_file = os.path.join(directory, ct, interface.name + ".xml")
|
|
@@ -118,7 +163,9 @@ class CodeGen(object):
|
|
|
118
163
|
raise ArgException(f"argument -c/--cdf_file: {args.cdf_file} not exist")
|
|
119
164
|
configs = Helper.read_yaml(args.cdf_file, "codegen", [])
|
|
120
165
|
# 为保障兼容,package.yml未指定版本号的,默认使用2,该版本配套lb_base/0.6.0版本,其LBProperty无set/get成员
|
|
121
|
-
ver_str =
|
|
166
|
+
ver_str = os.environ.get("CODEGEN_VERSION")
|
|
167
|
+
if ver_str is None:
|
|
168
|
+
ver_str = Helper.read_yaml(args.cdf_file, "codegen_version", args.codegen_version)
|
|
122
169
|
version_check(ver_str)
|
|
123
170
|
self.codegen_version = Version(ver_str)
|
|
124
171
|
for cfg in configs:
|
|
@@ -136,15 +183,18 @@ class CodeGen(object):
|
|
|
136
183
|
self._gen(file, outdir)
|
|
137
184
|
return
|
|
138
185
|
else:
|
|
139
|
-
|
|
140
|
-
|
|
186
|
+
ver_str = os.environ.get("CODEGEN_VERSION")
|
|
187
|
+
if ver_str is None:
|
|
188
|
+
ver_str = args.codegen_version
|
|
189
|
+
version_check(ver_str)
|
|
190
|
+
self.codegen_version = Version(ver_str)
|
|
141
191
|
|
|
142
192
|
intf_file = args.idf_file
|
|
143
193
|
if not intf_file:
|
|
144
194
|
raise ArgException(f"argument error, arguments -c/--cdf_file and -i/--idf_file are not set")
|
|
145
195
|
if not os.path.isfile(intf_file):
|
|
146
196
|
raise ArgException(f"argument -i/--idf_file: {args.idf_file} not exist")
|
|
147
|
-
if self.codegen_version.bt(
|
|
197
|
+
if self.codegen_version.bt(codegen_version_max()):
|
|
148
198
|
raise ArgException(f"argument -cv/--codegen_version: validate failed, must less than or equal to {__version__.str}")
|
|
149
199
|
out_dir = os.path.join(os.getcwd(), args.directory)
|
|
150
200
|
if not intf_file.endswith(".yaml"):
|
|
@@ -9,7 +9,6 @@ from lbkit.codegen.ctype_defination import CTYPE_OBJS, RefObjArrayValidator, Ref
|
|
|
9
9
|
from lbkit.misc import load_yml_with_json_schema_validate
|
|
10
10
|
from lbkit.errors import OdfValidateException, LiteBmcException
|
|
11
11
|
from lbkit.helper import SigInvalidException, validate_glib_signature
|
|
12
|
-
from lbkit.utils.version import Version
|
|
13
12
|
|
|
14
13
|
log = Logger("gen_interface")
|
|
15
14
|
|
|
@@ -36,7 +35,7 @@ class IdfInterfaceBase(Renderer):
|
|
|
36
35
|
self.description = None
|
|
37
36
|
self.version = None
|
|
38
37
|
self.alias = None
|
|
39
|
-
self.codegen_version
|
|
38
|
+
self.codegen_version = None
|
|
40
39
|
|
|
41
40
|
class IdfAnnotation():
|
|
42
41
|
def __init__(self, name, value):
|
|
@@ -914,9 +913,9 @@ class IdfStructure(IdfBase):
|
|
|
914
913
|
|
|
915
914
|
class IdfPluginAction(IdfMethod):
|
|
916
915
|
def __init__(self, intf: IdfInterfaceBase, method_data):
|
|
917
|
-
self.is_plugin = True
|
|
918
916
|
self.policy = method_data.get("policy", "continue_always")
|
|
919
917
|
super().__init__(intf, method_data)
|
|
918
|
+
self.is_plugin = True
|
|
920
919
|
|
|
921
920
|
|
|
922
921
|
class IdfEnumeration(IdfBase):
|
|
@@ -1035,7 +1034,7 @@ class IdfDictionary():
|
|
|
1035
1034
|
|
|
1036
1035
|
|
|
1037
1036
|
class IdfInterface(IdfInterfaceBase):
|
|
1038
|
-
def __init__(self, lookup, idf_file, codegen_version
|
|
1037
|
+
def __init__(self, lookup, idf_file, codegen_version):
|
|
1039
1038
|
if not idf_file.endswith(".yaml") and not idf_file.endswith(".yml"):
|
|
1040
1039
|
raise IDFException(f"IDF file {idf_file} neither endswith .yaml nor endswith .yml")
|
|
1041
1040
|
super().__init__()
|
|
@@ -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
|
-
|
|
17
|
+
__deprecated gint ${class_name}_set_${prop.name}(${class_name} obj,
|
|
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}(${class_name}
|
|
20
|
+
gint ${class_name}_set_${prop.name}(${class_name} obj,
|
|
21
21
|
${", ".join(prop.declare()).replace("<arg_name>", prop.name).replace("<const>", "const ")}, GError **error)
|
|
22
22
|
% endif
|
|
23
23
|
{
|
|
@@ -25,17 +25,17 @@ gint ${class_name}_set_${prop.name}(${class_name} object,
|
|
|
25
25
|
% for line in prop.encode_func():
|
|
26
26
|
${line.replace("<arg_out>", "tmp").replace("n_<arg_name>", "n_" + prop.name).replace("<arg_name>", prop.name)};
|
|
27
27
|
% endfor
|
|
28
|
-
return lb_impl.write_property((LBO *)
|
|
28
|
+
return lb_impl.write_property((LBO *)obj, &${properties}.${prop.name}, tmp, error);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
% endif
|
|
32
32
|
## 私有或只写属性不允许读
|
|
33
33
|
% if not prop.private and prop.access != "write":
|
|
34
34
|
% if prop.deprecated:
|
|
35
|
-
|
|
35
|
+
__deprecated gint ${class_name}_get_${prop.name}(${class_name} obj,
|
|
36
36
|
${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error)
|
|
37
37
|
% else:
|
|
38
|
-
gint ${class_name}_get_${prop.name}(${class_name}
|
|
38
|
+
gint ${class_name}_get_${prop.name}(${class_name} obj, ${", ".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]:
|
|
@@ -52,7 +52,7 @@ gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_d
|
|
|
52
52
|
% endfor
|
|
53
53
|
GVariant *out = NULL;
|
|
54
54
|
|
|
55
|
-
gint ret = lb_impl.read_property((LBO *)
|
|
55
|
+
gint ret = lb_impl.read_property((LBO *)obj, &${properties}.${prop.name}, &out, error);
|
|
56
56
|
if (ret == 0 && out) {
|
|
57
57
|
% for line in prop.decode_func():
|
|
58
58
|
${line.replace("<arg_in>", "tmp_value").replace("<arg_name>", "out")};
|
|
@@ -80,7 +80,7 @@ gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_d
|
|
|
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}(${class_name}
|
|
83
|
+
int ${class_name}_Call_${method.name}(${class_name} obj,
|
|
84
84
|
${REQ_PARA}${RSP_PARA}gint timeout,
|
|
85
85
|
GError **error)
|
|
86
86
|
{
|
|
@@ -88,8 +88,8 @@ int ${class_name}_Call_${method.name}(${class_name} object,
|
|
|
88
88
|
log_error("Emit method ${method.name} with parameter error, error is NULL");
|
|
89
89
|
return -1;
|
|
90
90
|
}
|
|
91
|
-
if (
|
|
92
|
-
*error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Call method ${method.name} with parameter error,
|
|
91
|
+
if (obj == NULL) {
|
|
92
|
+
*error = g_error_new(G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Call method ${method.name} with parameter error, obj is NULL");
|
|
93
93
|
return -1;
|
|
94
94
|
}
|
|
95
95
|
% if len(method.returns.parameters) == 0:
|
|
@@ -98,12 +98,12 @@ int ${class_name}_Call_${method.name}(${class_name} object,
|
|
|
98
98
|
% if len(method.parameters.parameters) == 0:
|
|
99
99
|
void *req = NULL;
|
|
100
100
|
% endif
|
|
101
|
-
return lb_impl.call_method((LBO *)
|
|
101
|
+
return lb_impl.call_method((LBO *)obj, (const LBMethod *)&${method_processer}->${method.name},
|
|
102
102
|
(void *)req, (void **)rsp, timeout, error);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
% endfor
|
|
106
|
-
static LBO *_${class_name}_create(const gchar *
|
|
106
|
+
static LBO *_${class_name}_create(const gchar *name, gpointer opaque);
|
|
107
107
|
static void _${class_name}_destroy(LBO *obj);
|
|
108
108
|
|
|
109
109
|
static LBInterface _${class_name}_interface = {
|
|
@@ -115,10 +115,10 @@ 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 *
|
|
118
|
+
static LBBase *_get_real_object(LBO *obj)
|
|
119
119
|
{
|
|
120
|
-
LBBase *real = (LBBase *)strstr((const char *)
|
|
121
|
-
if ((gconstpointer)real != (gconstpointer)
|
|
120
|
+
LBBase *real = (LBBase *)strstr((const char *)obj, LB_MAGIC);
|
|
121
|
+
if ((gconstpointer)real != (gconstpointer)obj) {
|
|
122
122
|
log_error("Get real object fail, Perhaps the memory has been freed, call abort() now");
|
|
123
123
|
abort();
|
|
124
124
|
}
|
|
@@ -128,31 +128,31 @@ static LBBase *_get_real_object(LBO *object)
|
|
|
128
128
|
/**
|
|
129
129
|
* @brief 销毁对象
|
|
130
130
|
*
|
|
131
|
-
* @param
|
|
131
|
+
* @param obj 待销毁的对象句柄
|
|
132
132
|
*/
|
|
133
|
-
static void _${class_name}_destroy(LBO *
|
|
133
|
+
static void _${class_name}_destroy(LBO *obj)
|
|
134
134
|
{
|
|
135
|
-
g_assert(
|
|
136
|
-
struct _${intf.alias} *
|
|
137
|
-
g_rec_mutex_clear(
|
|
138
|
-
g_free(
|
|
139
|
-
${intf.alias}_clean(
|
|
140
|
-
memset(
|
|
135
|
+
g_assert(obj);
|
|
136
|
+
struct _${intf.alias} *real_obj = (struct _${intf.alias} *)_get_real_object(obj);
|
|
137
|
+
g_rec_mutex_clear(real_obj->_base.lock);
|
|
138
|
+
g_free(real_obj->_base.lock);
|
|
139
|
+
${intf.alias}_clean(real_obj);
|
|
140
|
+
memset(real_obj, 0, sizeof(struct _${intf.alias}));
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* @brief 分配对象
|
|
145
145
|
*
|
|
146
|
-
* @param
|
|
146
|
+
* @param name 对象名,需要由调用者分配内存
|
|
147
147
|
* @param opaque 上层应用需要写入对象的用户数据,由上层应用使用
|
|
148
148
|
*/
|
|
149
|
-
static LBO *_${class_name}_create(const gchar *
|
|
149
|
+
static LBO *_${class_name}_create(const gchar *name, gpointer opaque)
|
|
150
150
|
{
|
|
151
151
|
struct _${intf.alias} *obj = g_new0(struct _${intf.alias}, 1);
|
|
152
152
|
memcpy(obj->_base.magic, LB_MAGIC, strlen(LB_MAGIC) + 1);
|
|
153
153
|
obj->_base.lock = g_new0(GRecMutex, 1);
|
|
154
154
|
g_rec_mutex_init(obj->_base.lock);
|
|
155
|
-
obj->_base.name =
|
|
155
|
+
obj->_base.name = name;
|
|
156
156
|
obj->_base.intf = &_${class_name}_interface;
|
|
157
157
|
obj->_base.opaque = opaque;
|
|
158
158
|
return (LBO *)obj;
|
|
@@ -160,10 +160,18 @@ static LBO *_${class_name}_create(const gchar *obj_name, gpointer opaque)
|
|
|
160
160
|
|
|
161
161
|
% for signal in intf.signals:
|
|
162
162
|
% if signal.deprecated:
|
|
163
|
-
|
|
163
|
+
% if codegen_version.be("5.1"):
|
|
164
|
+
__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
|
|
164
168
|
const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data)
|
|
165
169
|
% else:
|
|
170
|
+
% if codegen_version.be("5.1"):
|
|
171
|
+
guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
|
|
172
|
+
% else:
|
|
166
173
|
guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
|
|
174
|
+
% endif
|
|
167
175
|
const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data)
|
|
168
176
|
% endif
|
|
169
177
|
{
|
|
@@ -173,7 +181,7 @@ guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal
|
|
|
173
181
|
}
|
|
174
182
|
|
|
175
183
|
% if signal.deprecated:
|
|
176
|
-
|
|
184
|
+
__deprecated void ${class_name}_Unsubscribe_${signal.name}(guint *id)
|
|
177
185
|
% else:
|
|
178
186
|
void ${class_name}_Unsubscribe_${signal.name}(guint *id)
|
|
179
187
|
% endif
|
|
@@ -198,9 +206,9 @@ ${class_name} ${class_name}_get(const gchar *well_known, const gchar *name)
|
|
|
198
206
|
return lb_impl._cli_get(&_${class_name}_interface, well_known, name);
|
|
199
207
|
}
|
|
200
208
|
|
|
201
|
-
${class_name} ${class_name}_new(const gchar *well_known, const gchar *
|
|
209
|
+
${class_name} ${class_name}_new(const gchar *well_known, const gchar *name)
|
|
202
210
|
{
|
|
203
|
-
LBO *obj = lb_impl._cli_new(&_${class_name}_interface, well_known,
|
|
211
|
+
LBO *obj = lb_impl._cli_new(&_${class_name}_interface, well_known, name);
|
|
204
212
|
return (${class_name} )obj;
|
|
205
213
|
}
|
|
206
214
|
|
|
@@ -229,27 +237,27 @@ gboolean ${class_name}_present(${class_name} obj)
|
|
|
229
237
|
}
|
|
230
238
|
|
|
231
239
|
/* 绑定数据 */
|
|
232
|
-
void ${class_name}_bind(${class_name}
|
|
240
|
+
void ${class_name}_bind(${class_name} obj, gpointer data, GDestroyNotify destroy_func)
|
|
233
241
|
{
|
|
234
|
-
lb_impl._bind((LBO *)
|
|
242
|
+
lb_impl._bind((LBO *)obj, data, destroy_func);
|
|
235
243
|
}
|
|
236
244
|
|
|
237
245
|
/* 获取绑定数据 */
|
|
238
|
-
gpointer ${class_name}_data(${class_name}
|
|
246
|
+
gpointer ${class_name}_data(${class_name} obj)
|
|
239
247
|
{
|
|
240
|
-
return lb_impl._data((LBO *)
|
|
248
|
+
return lb_impl._data((LBO *)obj);
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
/* @notes 属性对象属性值变更(后)事件 */
|
|
244
|
-
gint ${class_name}_on_prop_changed(${class_name}
|
|
252
|
+
gint ${class_name}_on_prop_changed(${class_name} obj, const gchar *prop, ${class_name}_after_changed_hook pc, gpointer user_data, GDestroyNotify destroy)
|
|
245
253
|
{
|
|
246
|
-
return lb_impl._on_prop_changed((LBO *)
|
|
254
|
+
return lb_impl._on_prop_changed((LBO *)obj, prop, (lbo_after_changed_hook)pc, user_data, destroy);
|
|
247
255
|
}
|
|
248
256
|
|
|
249
257
|
/* 取消监听,成功取消监听时会调用监听时设置的destroy回调清除注册时的user_data */
|
|
250
|
-
void ${class_name}_on_prop_changed_cancel(${class_name}
|
|
258
|
+
void ${class_name}_on_prop_changed_cancel(${class_name} obj, const gchar *prop, ${class_name}_after_changed_hook pc, gconstpointer user_data)
|
|
251
259
|
{
|
|
252
|
-
lb_impl._on_prop_changed_cancel((LBO *)
|
|
260
|
+
lb_impl._on_prop_changed_cancel((LBO *)obj, prop, (lbo_after_changed_hook)pc, user_data);
|
|
253
261
|
}
|
|
254
262
|
|
|
255
263
|
/* 对象变更事件 */
|
|
@@ -259,9 +267,9 @@ void ${class_name}_on_changed(${class_name}_on_changed_hook cb, gpointer user_da
|
|
|
259
267
|
}
|
|
260
268
|
|
|
261
269
|
/* 注册对象释放回调 */
|
|
262
|
-
void ${class_name}_before_destroy(${class_name}
|
|
270
|
+
void ${class_name}_before_destroy(${class_name} obj, GHookFunc cb, gpointer user_data)
|
|
263
271
|
{
|
|
264
|
-
lb_impl._before_destroy((LBO *)
|
|
272
|
+
lb_impl._before_destroy((LBO *)obj, cb, user_data);
|
|
265
273
|
}
|
|
266
274
|
|
|
267
275
|
/* 查询第n个对象 */
|
|
@@ -296,14 +304,18 @@ GSList *${class_name}_list(void)
|
|
|
296
304
|
|
|
297
305
|
% for prop in intf.properties:
|
|
298
306
|
/* 监听属性${prop.name}变更 */
|
|
299
|
-
void ${class_name}_${prop.name}_hook(
|
|
307
|
+
void ${class_name}_${prop.name}_hook(${class_name}_after_changed_hook after, gpointer user_data)
|
|
300
308
|
{
|
|
301
|
-
|
|
309
|
+
LBPropertyHook hook = {
|
|
310
|
+
.after = (lbo_after_changed_hook)after,
|
|
311
|
+
.user_data = user_data
|
|
312
|
+
};
|
|
313
|
+
lb_impl._prop_hook(&${properties}.${prop.name}, &hook);
|
|
302
314
|
}
|
|
303
315
|
|
|
304
316
|
% endfor
|
|
305
317
|
% endif
|
|
306
|
-
static void
|
|
318
|
+
static void __constructor(150) ${class_name}_register(void)
|
|
307
319
|
{
|
|
308
320
|
// 从公共库中复制信号处理函数
|
|
309
321
|
${signal_processer} = ${intf.alias}_signals();
|
|
@@ -30,16 +30,16 @@ typedef ${intf.alias}_Properties ${class_name}_Properties;
|
|
|
30
30
|
## 私有属性或者只读属性不允许写
|
|
31
31
|
% if not prop.private and prop.access != "read":
|
|
32
32
|
% if prop.deprecated:
|
|
33
|
-
|
|
33
|
+
__deprecated gint ${class_name}_set_${prop.name}(${class_name} obj, ${", ".join(prop.declare()).replace("<arg_name>", "value").replace("<const>", "const ")}, GError **error);
|
|
34
34
|
% else:
|
|
35
|
-
gint ${class_name}_set_${prop.name}(${class_name}
|
|
35
|
+
gint ${class_name}_set_${prop.name}(${class_name} obj, ${", ".join(prop.declare()).replace("<arg_name>", "value").replace("<const>", "const ")}, GError **error);
|
|
36
36
|
% endif
|
|
37
37
|
% endif
|
|
38
38
|
% if not prop.private and prop.access != "write":
|
|
39
39
|
% if prop.deprecated:
|
|
40
|
-
|
|
40
|
+
__deprecated gint ${class_name}_get_${prop.name}(${class_name} obj, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error);
|
|
41
41
|
% else:
|
|
42
|
-
gint ${class_name}_get_${prop.name}(${class_name}
|
|
42
|
+
gint ${class_name}_get_${prop.name}(${class_name} obj, ${", ".join(prop.out_declare()).replace("<arg_name>", "value").replace("<const>", "")}, GError **error);
|
|
43
43
|
% endif
|
|
44
44
|
% endif
|
|
45
45
|
% endif
|
|
@@ -66,11 +66,11 @@ gint ${class_name}_get_${prop.name}(${class_name} object, ${", ".join(prop.out_d
|
|
|
66
66
|
% endif
|
|
67
67
|
*/
|
|
68
68
|
% if method.deprecated:
|
|
69
|
-
|
|
69
|
+
__deprecated int ${class_name}_Call_${method.name}(${class_name} obj,
|
|
70
70
|
${REQ_PARA}${RSP_PARA}gint timeout,
|
|
71
71
|
GError **error);
|
|
72
72
|
% else:
|
|
73
|
-
int ${class_name}_Call_${method.name}(${class_name}
|
|
73
|
+
int ${class_name}_Call_${method.name}(${class_name} obj,
|
|
74
74
|
${REQ_PARA}${RSP_PARA}gint timeout,
|
|
75
75
|
GError **error);
|
|
76
76
|
% endif
|
|
@@ -88,18 +88,33 @@ int ${class_name}_Call_${method.name}(${class_name} object,
|
|
|
88
88
|
% endfor
|
|
89
89
|
% endif
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
% if codegen_version.be("5.1"):
|
|
92
|
+
typedef void (*${class_name}_${signal.name}_Callback)(${class_name} obj, const gchar *destination,
|
|
93
|
+
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,
|
|
92
96
|
const ${intf.alias}_${signal.name}_Msg *req, gpointer user_data);
|
|
97
|
+
% endif
|
|
93
98
|
/**/
|
|
94
|
-
% if
|
|
95
|
-
|
|
99
|
+
% if codegen_version.be("5.1"):
|
|
100
|
+
% if signal.deprecated:
|
|
101
|
+
__deprecated guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
|
|
96
102
|
const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
|
|
103
|
+
% else:
|
|
104
|
+
guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Callback handler,
|
|
105
|
+
const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
|
|
106
|
+
% endif
|
|
97
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:
|
|
98
112
|
guint ${class_name}_Subscribe_${signal.name}(${class_name}_${signal.name}_Signal handler,
|
|
99
113
|
const gchar *bus_name, const gchar *object_path, const gchar *arg0, gpointer user_data);
|
|
114
|
+
% endif
|
|
100
115
|
% endif
|
|
101
116
|
% if signal.deprecated:
|
|
102
|
-
|
|
117
|
+
__deprecated void ${class_name}_Unsubscribe_${signal.name}(guint *id);
|
|
103
118
|
% else:
|
|
104
119
|
void ${class_name}_Unsubscribe_${signal.name}(guint *id);
|
|
105
120
|
% endif
|
|
@@ -112,22 +127,16 @@ LBInterface *${class_name}_interface(void);
|
|
|
112
127
|
|
|
113
128
|
% if codegen_version.be("4.0"):
|
|
114
129
|
/* notes: 对象变更加回调函数 */
|
|
115
|
-
typedef void (*${class_name}_on_changed_hook)(${class_name}
|
|
130
|
+
typedef void (*${class_name}_on_changed_hook)(${class_name} obj, gpointer user_data);
|
|
116
131
|
/* notes: 属性变更后回调,远程对象或本地对象变更后都会调用 */
|
|
117
|
-
typedef void (*${class_name}_after_changed_hook)(${class_name}
|
|
132
|
+
typedef void (*${class_name}_after_changed_hook)(${class_name} obj, const LBProperty *prop, GVariant *value, gpointer user_data);
|
|
118
133
|
/* notes: 属性变更前回调,返回-1表示阻止值变更,一般用于值合法性校验,只在被远程操作时才会生效,本地变更值不会回调 */
|
|
119
|
-
typedef gint (*${class_name}_before_change_hook)(${class_name}
|
|
134
|
+
typedef gint (*${class_name}_before_change_hook)(${class_name} obj, const LBProperty *prop, GVariant *value, gpointer user_data, GError **error);
|
|
120
135
|
|
|
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
136
|
/* 查询对象 */
|
|
128
137
|
${class_name} ${class_name}_get(const gchar *well_known, const gchar *name);
|
|
129
138
|
/* 创建对象 */
|
|
130
|
-
${class_name} ${class_name}_new(const gchar *well_known, const gchar *
|
|
139
|
+
${class_name} ${class_name}_new(const gchar *well_known, const gchar *name);
|
|
131
140
|
/* 减对象引用计数 */
|
|
132
141
|
void ${class_name}_unref(${class_name} *obj);
|
|
133
142
|
/* 加对象引用计数 */
|
|
@@ -137,17 +146,17 @@ void ${class_name}_present_set(${class_name} obj, gboolean present);
|
|
|
137
146
|
/* 获取在位状态 */
|
|
138
147
|
gboolean ${class_name}_present(${class_name} obj);
|
|
139
148
|
/* 绑定数据 */
|
|
140
|
-
void ${class_name}_bind(${class_name}
|
|
149
|
+
void ${class_name}_bind(${class_name} obj, gpointer data, GDestroyNotify destroy_func);
|
|
141
150
|
/* 获取绑定数据 */
|
|
142
|
-
gpointer ${class_name}_data(${class_name}
|
|
151
|
+
gpointer ${class_name}_data(${class_name} obj);
|
|
143
152
|
/* @notes 属性对象属性值变更(后)事件 */
|
|
144
|
-
gint ${class_name}_on_prop_changed(${class_name}
|
|
153
|
+
gint ${class_name}_on_prop_changed(${class_name} obj, const gchar *prop, ${class_name}_after_changed_hook pc, gpointer user_data, GDestroyNotify destroy);
|
|
145
154
|
/* 取消监听,成功取消监听时会调用监听时设置的destroy回调清除注册时的user_data */
|
|
146
|
-
void ${class_name}_on_prop_changed_cancel(${class_name}
|
|
155
|
+
void ${class_name}_on_prop_changed_cancel(${class_name} obj, const gchar *prop, ${class_name}_after_changed_hook pc, gconstpointer user_data);
|
|
147
156
|
/* 对象变更事件 */
|
|
148
157
|
void ${class_name}_on_changed(${class_name}_on_changed_hook cb, gpointer user_data, GDestroyNotify destroy);
|
|
149
158
|
/* 注册对象释放回调 */
|
|
150
|
-
void ${class_name}_before_destroy(${class_name}
|
|
159
|
+
void ${class_name}_before_destroy(${class_name} obj, GHookFunc cb, gpointer user_data);
|
|
151
160
|
/*
|
|
152
161
|
* 查询第n个对象
|
|
153
162
|
* @notes: 支持正逆向查询第n个对象,返回的对象需要使用lbo_unref减引用计数
|
|
@@ -165,7 +174,7 @@ void ${class_name}_unlock(${class_name} obj);
|
|
|
165
174
|
GSList *${class_name}_list(void);
|
|
166
175
|
/* 监听属性 */
|
|
167
176
|
% for prop in intf.properties:
|
|
168
|
-
void ${class_name}_${prop.name}_hook(
|
|
177
|
+
void ${class_name}_${prop.name}_hook(${class_name}_after_changed_hook after, gpointer user_data);
|
|
169
178
|
% endfor
|
|
170
179
|
|
|
171
180
|
static inline void ${class_name}_unref_p(${class_name} obj)
|