def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name': self.name, 'tlv_id': self.id_enum_name, 'underscore': utils.build_underscore_name(self.fullname) } template = ( '\n' 'static gboolean\n' '${underscore}_validate (\n' ' const guint8 *buffer,\n' ' guint16 buffer_len)\n' '{\n' ' static const guint expected_len = 4;\n' '\n' ' if (buffer_len < expected_len) {\n' ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return FALSE;\n' ' }\n' '\n' ' return TRUE;\n' '}\n') f.write(string.Template(template).substitute(translations)) template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *self,\n' ' const gchar *line_prefix)\n' '{\n' ' gsize offset = 0;\n' ' gsize init_offset;\n' ' guint16 error_status;\n' ' guint16 error_code;\n' '\n' ' if ((init_offset = qmi_message_tlv_read_init (self, ${tlv_id}, NULL, NULL)) == 0)\n' ' return NULL;\n' ' if (!qmi_message_tlv_read_guint16 (self, init_offset, &offset, QMI_ENDIAN_LITTLE, &error_status, NULL))\n' ' return NULL;\n' ' if (!qmi_message_tlv_read_guint16 (self, init_offset, &offset, QMI_ENDIAN_LITTLE, &error_code, NULL))\n' ' return NULL;\n' ' g_warn_if_fail (__qmi_message_tlv_read_remaining_size (self, init_offset, offset) == 0);\n' '\n' ' if (error_status == QMI_STATUS_SUCCESS)\n' ' return g_strdup ("SUCCESS");\n' '\n' ' return g_strdup_printf ("FAILURE: %s", qmi_protocol_error_get_string ((QmiProtocolError) error_code));\n' '}\n') f.write(string.Template(template).substitute(translations))
def add_sections(self, sections): translations = { 'underscore' : utils.build_underscore_name(self.name), 'prefix_camelcase' : utils.build_camelcase_name(self.prefix), 'prefix_underscore' : utils.build_underscore_name(self.prefix) } if TypeFactory.is_section_emitted(self.fullname) is False: TypeFactory.set_section_emitted(self.fullname) self.variable.add_sections(sections) # Public methods template = ( '${prefix_underscore}_get_${underscore}\n') if self.container_type == 'Input': template += ( '${prefix_underscore}_set_${underscore}\n') sections['public-methods'] += string.Template(template).substitute(translations)
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name': self.name, 'tlv_id': self.id_enum_name, 'underscore': utils.build_underscore_name(self.fullname) } template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *message,\n' ' const gchar *line_prefix)\n' '{\n' ' gsize offset = 0;\n' ' gsize init_offset;\n' ' GString *printable;\n' ' GError *error = NULL;\n' '\n' ' if ((init_offset = qmi_message_tlv_read_init (message, ${tlv_id}, NULL, NULL)) == 0)\n' ' return NULL;\n' '\n' ' printable = g_string_new ("");\n') f.write(string.Template(template).substitute(translations)) # Now, read the contents of the buffer into the printable representation self.variable.emit_get_printable(f, ' ') template = ( '\n' ' if ((offset = qmi_message_tlv_read_remaining_size (message, init_offset, offset)) > 0)\n' ' g_string_append_printf (printable, "Additional unexpected \'%" G_GSIZE_FORMAT "\' bytes", offset);\n' '\n' 'out:\n' ' if (error) {\n' ' g_string_append_printf (printable, " ERROR: %s", error->message);\n' ' g_error_free (error);\n' ' }\n' ' return g_string_free (printable, FALSE);\n' '}\n') f.write(string.Template(template).substitute(translations))
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name' : self.name, 'tlv_id' : self.id_enum_name, 'underscore' : utils.build_underscore_name (self.fullname) } template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *message,\n' ' const gchar *line_prefix)\n' '{\n' ' gsize offset = 0;\n' ' gsize init_offset;\n' ' GString *printable;\n' ' GError *error = NULL;\n' '\n' ' if ((init_offset = qmi_message_tlv_read_init (message, ${tlv_id}, NULL, NULL)) == 0)\n' ' return NULL;\n' '\n' ' printable = g_string_new ("");\n') f.write(string.Template(template).substitute(translations)) # Now, read the contents of the buffer into the printable representation self.variable.emit_get_printable(f, ' ') template = ( '\n' ' if ((offset = __qmi_message_tlv_read_remaining_size (message, init_offset, offset)) > 0)\n' ' g_string_append_printf (printable, "Additional unexpected \'%" G_GSIZE_FORMAT "\' bytes", offset);\n' '\n' 'out:\n' ' if (error)\n' ' g_string_append_printf (printable, " ERROR: %s", error->message);\n' ' return g_string_free (printable, FALSE);\n' '}\n') f.write(string.Template(template).substitute(translations))
def emit_types(self, hfile, cfile): if TypeFactory.is_type_emitted(self.fullname) is False: TypeFactory.set_type_emitted(self.fullname) self.variable.emit_types(cfile, self.since, True)
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name': self.name, 'tlv_id': self.id_enum_name, 'underscore': utils.build_underscore_name(self.fullname) } template = ( '\n' 'static gboolean\n' '${underscore}_validate (\n' ' const guint8 *buffer,\n' ' guint16 buffer_len)\n' '{\n' ' static const guint expected_len = 4;\n' '\n' ' if (buffer_len < expected_len) {\n' ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return FALSE;\n' ' }\n' '\n' ' return TRUE;\n' '}\n') f.write(string.Template(template).substitute(translations)) template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *self,\n' ' const gchar *line_prefix)\n' '{\n' ' const guint8 *buffer;\n' ' guint16 buffer_len;\n' '\n' ' buffer = qmi_message_get_raw_tlv (self,\n' ' ${tlv_id},\n' ' &buffer_len);\n' ' if (buffer) {\n' ' GString *printable;\n' ' guint16 error_status;\n' ' guint16 error_code;\n' '\n' ' printable = g_string_new ("");\n' ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' ' QMI_ENDIAN_LITTLE,\n' ' &error_status);\n' ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' ' QMI_ENDIAN_LITTLE,\n' ' &error_code);\n' '\n' ' g_warn_if_fail (buffer_len == 0);\n' '\n' ' if (error_status == QMI_STATUS_SUCCESS)\n' ' g_string_append (printable, "SUCCESS");\n' ' else\n' ' g_string_append_printf (printable,\n' ' "FAILURE: %s",\n' ' qmi_protocol_error_get_string ((QmiProtocolError) error_code));\n' '\n' ' return g_string_free (printable, FALSE);\n' ' }\n' '\n' ' return NULL;\n' '}\n') f.write(string.Template(template).substitute(translations))
def emit_types(self, hfile, cfile): if TypeFactory.is_type_emitted(self.fullname) is False: TypeFactory.set_type_emitted(self.fullname) self.variable.emit_types(hfile, self.since) self.variable.emit_helper_methods(hfile, cfile)
def emit_types(self, hfile, cfile): if TypeFactory.is_type_emitted(self.fullname) is False: TypeFactory.set_type_emitted(self.fullname) self.variable.emit_types(hfile) self.variable.emit_helper_methods(hfile, cfile)
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name' : self.name, 'tlv_id' : self.id_enum_name, 'underscore' : utils.build_underscore_name (self.fullname) } template = ( '\n' 'static gboolean\n' '${underscore}_validate (\n' ' const guint8 *buffer,\n' ' guint16 buffer_len)\n' '{\n' ' static const guint expected_len = 4;\n' '\n' ' if (buffer_len < expected_len) {\n' ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return FALSE;\n' ' }\n' '\n' ' return TRUE;\n' '}\n') f.write(string.Template(template).substitute(translations)) template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *self,\n' ' const gchar *line_prefix)\n' '{\n' ' const guint8 *buffer;\n' ' guint16 buffer_len;\n' '\n' ' buffer = qmi_message_get_raw_tlv (self,\n' ' ${tlv_id},\n' ' &buffer_len);\n' ' if (buffer) {\n' ' GString *printable;\n' ' guint16 error_status;\n' ' guint16 error_code;\n' '\n' ' printable = g_string_new ("");\n' ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' ' QMI_ENDIAN_LITTLE,\n' ' &error_status);\n' ' qmi_utils_read_guint16_from_buffer (\n' ' &buffer,\n' ' &buffer_len,\n' ' QMI_ENDIAN_LITTLE,\n' ' &error_code);\n' '\n' ' g_warn_if_fail (buffer_len == 0);\n' '\n' ' if (error_status == QMI_STATUS_SUCCESS)\n' ' g_string_append (printable, "SUCCESS");\n' ' else\n' ' g_string_append_printf (printable,\n' ' "FAILURE: %s",\n' ' qmi_protocol_error_get_string ((QmiProtocolError) error_code));\n' '\n' ' return g_string_free (printable, FALSE);\n' ' }\n' '\n' ' return NULL;\n' '}\n') f.write(string.Template(template).substitute(translations))
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name' : self.name, 'tlv_id' : self.id_enum_name, 'underscore' : utils.build_underscore_name (self.fullname) } template = ( '\n' 'static gboolean\n' '${underscore}_validate (\n' ' const guint8 *buffer,\n' ' guint16 buffer_len)\n' '{\n' ' guint expected_len = 0;\n' '\n') f.write(string.Template(template).substitute(translations)) # Now, read the size of the expected TLV self.variable.emit_size_read(f, ' ', 'expected_len', 'buffer', 'buffer_len') template = ( '\n' ' if (buffer_len < expected_len) {\n' ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return FALSE;\n' ' }\n' '\n' ' if (buffer_len > expected_len) {\n' ' g_debug ("Reading the \'${name}\' TLV: expected \'%u\' bytes, but got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return TRUE;\n' ' }\n' '\n' ' return TRUE;\n' '}\n' '\n') f.write(string.Template(template).substitute(translations)) template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *message,\n' ' const gchar *line_prefix)\n' '{\n' ' const guint8 *buffer;\n' ' guint16 buffer_len;\n' '\n' ' buffer = qmi_message_get_raw_tlv (message,\n' ' ${tlv_id},\n' ' &buffer_len);\n' ' if (buffer && ${underscore}_validate (buffer, buffer_len)) {\n' ' GString *printable;\n' '\n' ' printable = g_string_new ("");\n') f.write(string.Template(template).substitute(translations)) # Now, read the contents of the buffer into the printable representation self.variable.emit_get_printable(f, ' ', 'printable', 'buffer', 'buffer_len') template = ( '\n' ' /* The remaining size of the buffer needs to be 0 if we successfully read the TLV */\n' ' if (buffer_len > 0) {\n' ' g_warning ("Left \'%u\' bytes unread when getting the \'${name}\' TLV as printable", buffer_len);\n' ' }\n' '\n' ' return g_string_free (printable, FALSE);\n' ' }\n' '\n' ' return NULL;\n' '}\n') f.write(string.Template(template).substitute(translations))
def emit_tlv_helpers(self, f): if TypeFactory.helpers_emitted(self.fullname): return TypeFactory.set_helpers_emitted(self.fullname) translations = { 'name': self.name, 'tlv_id': self.id_enum_name, 'underscore': utils.build_underscore_name(self.fullname) } template = ('\n' 'static gboolean\n' '${underscore}_validate (\n' ' const guint8 *buffer,\n' ' guint16 buffer_len)\n' '{\n' ' guint expected_len = 0;\n' '\n') f.write(string.Template(template).substitute(translations)) # Now, read the size of the expected TLV self.variable.emit_size_read(f, ' ', 'expected_len', 'buffer', 'buffer_len') template = ( '\n' ' if (buffer_len < expected_len) {\n' ' g_warning ("Cannot read the \'${name}\' TLV: expected \'%u\' bytes, but only got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return FALSE;\n' ' }\n' '\n' ' if (buffer_len > expected_len) {\n' ' g_debug ("Reading the \'${name}\' TLV: expected \'%u\' bytes, but got \'%u\' bytes",\n' ' expected_len, buffer_len);\n' ' return TRUE;\n' ' }\n' '\n' ' return TRUE;\n' '}\n' '\n') f.write(string.Template(template).substitute(translations)) template = ( '\n' 'static gchar *\n' '${underscore}_get_printable (\n' ' QmiMessage *message,\n' ' const gchar *line_prefix)\n' '{\n' ' const guint8 *buffer;\n' ' guint16 buffer_len;\n' '\n' ' buffer = qmi_message_get_raw_tlv (message,\n' ' ${tlv_id},\n' ' &buffer_len);\n' ' if (buffer && ${underscore}_validate (buffer, buffer_len)) {\n' ' GString *printable;\n' '\n' ' printable = g_string_new ("");\n') f.write(string.Template(template).substitute(translations)) # Now, read the contents of the buffer into the printable representation self.variable.emit_get_printable(f, ' ', 'printable', 'buffer', 'buffer_len') template = ( '\n' ' /* The remaining size of the buffer needs to be 0 if we successfully read the TLV */\n' ' if (buffer_len > 0) {\n' ' g_warning ("Left \'%u\' bytes unread when getting the \'${name}\' TLV as printable", buffer_len);\n' ' }\n' '\n' ' return g_string_free (printable, FALSE);\n' ' }\n' '\n' ' return NULL;\n' '}\n') f.write(string.Template(template).substitute(translations))