Debian Codegraph @

build-aux/qmi-codegen/Variable.py

raw
1 # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 #
3 # This program is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; either version 2 of the License, or (at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 #
17 # Copyright (C) 2012 Lanedo GmbH
18 # Copyright (C) 2012-2022 Aleksander Morgado <[email protected]>
19 # Copyright (c) 2022 Qualcomm Innovation Center, Inc.
20 #
21
22 import string
23 import utils
24
25 """
26 Base class for every variable type defined in the database
27 """
28 class Variable:
29
30 """
31 Constructor with common variable handling
32 """
33 def __init__(self, service, dictionary):
34 """
35 The current QMI service
36 """
37 self.service = service
38
39 """
40 Variables can define specific public and private formats to be used.
41 The public format will be that used in the generated interface file,
42 while the private one will only be used internally.
43 """
44 self.format = dictionary['format']
45 self.public_format = None
46 self.private_format = None
47
48 """
49 Element type to be used in introspection annotations.
50 """
51 self.element_type = None
52
53 """
54 Whether the variable is visible in public API or is reserved
55 """
56 self.visible = False if ('visible' in dictionary and dictionary['visible'] == 'no') else True
57
58 """
59 Variables that get allocated in heap need to get properly disposed.
60 """
61 self.needs_dispose = False
62
63 """
64 Variables that get allocated in heap need to have a clear method so that it
65 can be used as part of an array of this variable type.
66 """
67 self.clear_method = ''
68
69 """
70 Custom endianness configuration for a specific variable; if none given, defaults
71 to host endian.
72 """
73 self.endian = "QMI_ENDIAN_LITTLE"
74 if 'endian' in dictionary:
75 endian = dictionary['endian']
76 if endian == 'network' or endian == 'big':
77 self.endian = "QMI_ENDIAN_BIG"
78 elif endian == 'little':
79 pass
80 else:
81 raise ValueError("Invalid endian value %s" % endian)
82
83 """
84 Initially all variables are flagged as not being public
85 """
86 self.public = False
87
88 # -----------------------------------------------------------------------------
89 # Variables to support the new GIR array/struct compat methods in 1.32
90
91 """
92 Flag specifying whether a given variable contains any kind of array, indicating
93 the GIR array/struct compat methods in 1.32 are required. There is no need to
94 flag structs independently, because it is ensured that structs are always array
95 members.
96 """
97 self.needs_compat_gir = False
98
99 """
100 Formats and element types
101 """
102 self.public_format_gir = None
103 self.private_format_gir = None
104 self.element_type_gir = None
105
106 """
107 Types involved in GIR support may need additional free() and new() methods.
108 """
109 self.new_method_gir = ''
110 self.free_method_gir = ''
111
112 """
113 Whether the variable is personal info or not
114 """
115 if 'personal-info' in dictionary:
116 self.personal_info = True;
117 else:
118 self.personal_info = False;
119
120 """
121 Whether the variable contains personal info or not
122 """
123 self.contains_personal_info = self.personal_info
124
125 """
126 Emits the code to declare specific new types required by the variable.
127 """
128 def emit_types(self, hfile, cfile, since, static):
129 pass
130
131 """
132 Emits the code involved in reading the variable from the raw byte stream
133 into the specific private format.
134 """
135 def emit_buffer_read(self, f, line_prefix, tlv_out, error, variable_name):
136 pass
137
138 """
139 Emits the code involved in writing the variable to the raw byte stream
140 from the specific private format.
141 """
142 def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
143 pass
144
145 """
146 Emits the code to get the contents of the given variable as a printable string.
147 """
148 def emit_get_printable(self, f, line_prefix, is_personal):
149 pass
150
151 """
152 Builds the code to include the declaration of a variable of this kind,
153 used when generating input/output bundles.
154 """
155 def build_variable_declaration(self, line_prefix, variable_name):
156 return ''
157
158 """
159 Builds the code to include in the getter method declaration for this kind of variable.
160 """
161 def build_getter_declaration(self, line_prefix, variable_name):
162 return ''
163
164 """
165 Builds the documentation of the getter code
166 """
167 def build_getter_documentation(self, line_prefix, variable_name):
168 return ''
169
170 """
171 Builds the code to implement getting this kind of variable.
172 """
173 def build_getter_implementation(self, line_prefix, variable_name_from, variable_name_to):
174 return ''
175
176 """
177 Builds the code to include in the setter method for this kind of variable.
178 """
179 def build_setter_declaration(self, line_prefix, variable_name):
180 return ''
181
182 """
183 Builds the documentation of the setter code
184 """
185 def build_setter_documentation(self, line_prefix, variable_name):
186 return ''
187
188 """
189 Builds the code to implement setting this kind of variable.
190 """
191 def build_setter_implementation(self, line_prefix, variable_name_from, variable_name_to):
192 return ''
193
194 """
195 Builds the code to include the declaration of a variable of this kind
196 as a field in a public struct
197 """
198 def build_struct_field_declaration(self, line_prefix, variable_name):
199 return ''
200
201 """
202 Documentation for the struct field
203 """
204 def build_struct_field_documentation(self, line_prefix, variable_name):
205 return ''
206
207 """
208 Emits the code to dispose the variable.
209 """
210 def build_dispose(self, line_prefix, variable_name):
211 return ''
212
213 """
214 Add sections
215 """
216 def add_sections(self, sections):
217 pass
218
219 """
220 Flag as being public
221 """
222 def flag_public(self):
223 self.public = True
224
225 # -----------------------------------------------------------------------------
226 # Support for GIR array/struct compat methods in 1.32
227
228 """
229 Emits the code to declare specific new types required by the variable
230 """
231 def emit_types_gir(self, hfile, cfile, since):
232 pass
233
234 """
235 Builds the code to include the declaration of a variable of this kind,
236 used when generating input/output bundles
237 """
238 def build_variable_declaration_gir(self, line_prefix, variable_name):
239 # By default, no extra variable is required in the input/output bundle
240 # for GIR compat methods
241 return ''
242
243 """
244 Builds the code to include in the getter method declaration for this kind of variable
245 """
246 def build_getter_declaration_gir(self, line_prefix, variable_name):
247 return self.build_getter_declaration(line_prefix, variable_name)
248
249 """
250 Builds the documentation of the getter code
251 """
252 def build_getter_documentation_gir(self, line_prefix, variable_name):
253 return self.build_getter_documentation(line_prefix, variable_name)
254
255 """
256 Builds the code to implement getting this kind of variable
257 """
258 def build_getter_implementation_gir(self, line_prefix, variable_name_from, variable_name_to):
259 return self.build_getter_implementation(line_prefix, variable_name_from, variable_name_to)
260
261 """
262 Builds the code to include in the setter method declaration for this kind of variable
263 """
264 def build_setter_declaration_gir(self, line_prefix, variable_name):
265 return self.build_setter_declaration(line_prefix, variable_name)
266
267 """
268 Builds the documentation of the setter code
269 """
270 def build_setter_documentation_gir(self, line_prefix, variable_name):
271 return self.build_setter_documentation(line_prefix, variable_name)
272
273 """
274 Builds the code to implement setting this kind of variable
275 """
276 def build_setter_implementation_gir(self, line_prefix, variable_name_from, variable_name_to):
277 return self.build_setter_implementation(line_prefix, variable_name_from, variable_name_to)
278
279 """
280 Declaration of the variable as a struct field
281 """
282 def build_struct_field_declaration_gir(self, line_prefix, variable_name):
283 return self.build_struct_field_declaration(line_prefix, variable_name)
284
285 """
286 Documentation for the struct field
287 """
288 def build_struct_field_documentation_gir(self, line_prefix, variable_name):
289 return self.build_struct_field_documentation(line_prefix, variable_name)
290
291 """
292 Emits the code to dispose the variable
293 """
294 def build_dispose_gir(self, line_prefix, variable_name):
295 return self.build_dispose(line_prefix, variable_name)
296
297 """
298 Emits the code to copy a variable into its GIR specific format
299 """
300 def build_copy_to_gir(self, line_prefix, variable_name_from, variable_name_to):
301 return ''
302
303 """
304 Emits the code to copy a variable from its GIR specific format
305 """
306 def build_copy_from_gir(self, line_prefix, variable_name_from, variable_name_to):
307 return ''
308
309 """
310 Emits the code to copy a variable from its GIR specific format to another
311 variable in the same format
312 """
313 def build_copy_gir(self, line_prefix, variable_name_from, variable_name_to):
314 return ''