summaryrefslogtreecommitdiff
path: root/build-aux/qmi-codegen/Variable.py
blob: dc28f2194e5488e238c70d4b0c0ff7c3064bffba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2012 Lanedo GmbH
# Copyright (C) 2012-2022 Aleksander Morgado <aleksander@aleksander.es>
# Copyright (c) 2022 Qualcomm Innovation Center, Inc.
#

import string
import utils

"""
Base class for every variable type defined in the database
"""
class Variable:

    """
    Constructor with common variable handling
    """
    def __init__(self, service, dictionary):
        """
        The current QMI service
        """
        self.service = service

        """
        Variables can define specific public and private formats to be used.
        The public format will be that used in the generated interface file,
        while the private one will only be used internally.
        """
        self.format = dictionary['format']
        self.public_format = None
        self.private_format = None

        """
        Element type to be used in introspection annotations.
        """
        self.element_type = None

        """
        Whether the variable is visible in public API or is reserved
        """
        self.visible = False if ('visible' in dictionary and dictionary['visible'] == 'no') else True

        """
        Variables that get allocated in heap need to get properly disposed.
        """
        self.needs_dispose = False

        """
        Variables that get allocated in heap need to have a clear method so that it
        can be used as part of an array of this variable type.
        """
        self.clear_method = ''

        """
        Custom endianness configuration for a specific variable; if none given, defaults
        to host endian.
        """
        self.endian = "QMI_ENDIAN_LITTLE"
        if 'endian' in dictionary:
            endian = dictionary['endian']
            if endian == 'network' or endian == 'big':
                self.endian = "QMI_ENDIAN_BIG"
            elif endian == 'little':
                pass
            else:
                raise ValueError("Invalid endian value %s" % endian)

        """
        Initially all variables are flagged as not being public
        """
        self.public = False

        # -----------------------------------------------------------------------------
        # Variables to support the new GIR array/struct compat methods in 1.32

        """
        Flag specifying whether a given variable contains any kind of array, indicating
        the GIR array/struct compat methods in 1.32 are required. There is no need to
        flag structs independently, because it is ensured that structs are always array
        members.
        """
        self.needs_compat_gir = False

        """
        Formats and element types
        """
        self.public_format_gir = None
        self.private_format_gir = None
        self.element_type_gir = None

        """
        Types involved in GIR support may need additional free() and new() methods.
        """
        self.new_method_gir = ''
        self.free_method_gir = ''

        """
        Whether the variable is personal info or not
        """
        if 'personal-info' in dictionary:
            self.personal_info = True;
        else:
            self.personal_info = False;

        """
        Whether the variable contains personal info or not
        """
        self.contains_personal_info = self.personal_info

    """
    Emits the code to declare specific new types required by the variable.
    """
    def emit_types(self, hfile, cfile, since, static):
        pass

    """
    Emits the code involved in reading the variable from the raw byte stream
    into the specific private format.
    """
    def emit_buffer_read(self, f, line_prefix, tlv_out, error, variable_name):
        pass

    """
    Emits the code involved in writing the variable to the raw byte stream
    from the specific private format.
    """
    def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
        pass

    """
    Emits the code to get the contents of the given variable as a printable string.
    """
    def emit_get_printable(self, f, line_prefix, is_personal):
        pass

    """
    Builds the code to include the declaration of a variable of this kind,
    used when generating input/output bundles.
    """
    def build_variable_declaration(self, line_prefix, variable_name):
        return ''

    """
    Builds the code to include in the getter method declaration for this kind of variable.
    """
    def build_getter_declaration(self, line_prefix, variable_name):
        return ''

    """
    Builds the documentation of the getter code
    """
    def build_getter_documentation(self, line_prefix, variable_name):
        return ''

    """
    Builds the code to implement getting this kind of variable.
    """
    def build_getter_implementation(self, line_prefix, variable_name_from, variable_name_to):
        return ''

    """
    Builds the code to include in the setter method for this kind of variable.
    """
    def build_setter_declaration(self, line_prefix, variable_name):
        return ''

    """
    Builds the documentation of the setter code
    """
    def build_setter_documentation(self, line_prefix, variable_name):
        return ''

    """
    Builds the code to implement setting this kind of variable.
    """
    def build_setter_implementation(self, line_prefix, variable_name_from, variable_name_to):
        return ''

    """
    Builds the code to include the declaration of a variable of this kind
    as a field in a public struct
    """
    def build_struct_field_declaration(self, line_prefix, variable_name):
        return ''

    """
    Documentation for the struct field
    """
    def build_struct_field_documentation(self, line_prefix, variable_name):
        return ''

    """
    Emits the code to dispose the variable.
    """
    def build_dispose(self, line_prefix, variable_name):
        return ''

    """
    Add sections
    """
    def add_sections(self, sections):
        pass

    """
    Flag as being public
    """
    def flag_public(self):
        self.public = True

    # -----------------------------------------------------------------------------
    # Support for GIR array/struct compat methods in 1.32

    """
    Emits the code to declare specific new types required by the variable
    """
    def emit_types_gir(self, hfile, cfile, since):
        pass

    """
    Builds the code to include the declaration of a variable of this kind,
    used when generating input/output bundles
    """
    def build_variable_declaration_gir(self, line_prefix, variable_name):
        # By default, no extra variable is required in the input/output bundle
        # for GIR compat methods
        return ''

    """
    Builds the code to include in the getter method declaration for this kind of variable
    """
    def build_getter_declaration_gir(self, line_prefix, variable_name):
        return self.build_getter_declaration(line_prefix, variable_name)

    """
    Builds the documentation of the getter code
    """
    def build_getter_documentation_gir(self, line_prefix, variable_name):
        return self.build_getter_documentation(line_prefix, variable_name)

    """
    Builds the code to implement getting this kind of variable
    """
    def build_getter_implementation_gir(self, line_prefix, variable_name_from, variable_name_to):
        return self.build_getter_implementation(line_prefix, variable_name_from, variable_name_to)

    """
    Builds the code to include in the setter method declaration for this kind of variable
    """
    def build_setter_declaration_gir(self, line_prefix, variable_name):
        return self.build_setter_declaration(line_prefix, variable_name)

    """
    Builds the documentation of the setter code
    """
    def build_setter_documentation_gir(self, line_prefix, variable_name):
        return self.build_setter_documentation(line_prefix, variable_name)

    """
    Builds the code to implement setting this kind of variable
    """
    def build_setter_implementation_gir(self, line_prefix, variable_name_from, variable_name_to):
        return self.build_setter_implementation(line_prefix, variable_name_from, variable_name_to)

    """
    Declaration of the variable as a struct field
    """
    def build_struct_field_declaration_gir(self, line_prefix, variable_name):
        return self.build_struct_field_declaration(line_prefix, variable_name)

    """
    Documentation for the struct field
    """
    def build_struct_field_documentation_gir(self, line_prefix, variable_name):
        return self.build_struct_field_documentation(line_prefix, variable_name)

    """
    Emits the code to dispose the variable
    """
    def build_dispose_gir(self, line_prefix, variable_name):
        return self.build_dispose(line_prefix, variable_name)

    """
    Emits the code to copy a variable into its GIR specific format
    """
    def build_copy_to_gir(self, line_prefix, variable_name_from, variable_name_to):
        return ''

    """
    Emits the code to copy a variable from its GIR specific format
    """
    def build_copy_from_gir(self, line_prefix, variable_name_from, variable_name_to):
        return ''

    """
    Emits the code to copy a variable from its GIR specific format to another
    variable in the same format
    """
    def build_copy_gir(self, line_prefix, variable_name_from, variable_name_to):
        return ''