Skip to content

Add attribute values support to XML generation#1406

Open
999Marius wants to merge 5 commits intomainfrom
xml-attr-values
Open

Add attribute values support to XML generation#1406
999Marius wants to merge 5 commits intomainfrom
xml-attr-values

Conversation

@999Marius
Copy link
Collaborator

@999Marius 999Marius commented Mar 12, 2026

PR Description

This PR adds support for including attribute values in XML generation within libiio. The new functionality allows XML output to contain both attribute names and their values.

Currently, iio-emu has separate XML generation logic that duplicates functionality in libiio.
These commits add support for including attribute values in XML generation. This is the first step toward integrating iio-emu functionality into libiio.

Changes

  • Add attribute value storage arrays to iio_device, iio_channel and iio_buffer structures
  • Extend XML generation functions to optionally include attribute values
  • Add iio_context_get_xml_with_values() public API
  • Add -e flag to iio_genxml utility
  • Implement iio_context_refresh_attr_values() to populate value arrays
  • Implement iio_context_free_attr_values() to free value arrays

The existing XML generation functions are extended with an include_values parameter. When enabled, attribute values are refreshed from devices and serialized into the XML alongside their names.

How it works

  1. When iio_context_get_xml_with_values() is called, it invokes iio_context_generate_xml(ctx, true)
  2. iio_context_generate_xml(ctx, true) first calls iio_context_refresh_attr_values() to read current attribute values from the hardware
  3. The refresh function iterates through each device and:
    • Calls iio_refresh_device_attr_values() to read device and debug attributes, allocating storage arrays on first use
    • For each channel, calls iio_refresh_channel_attr_values() to read channel attributes, allocating storage arrays on first use
    • For each buffer, calls iio_refresh_buffer_attr_values() to read buffer attributes, allocating storage arrays on first use
  4. After values are refreshed, iio_snprintf_context_xml() generates the XML with the include_values flag, serializing stored
    values alongside attribute names
  5. Before returning, iio_context_generate_xml() frees all attribute values via iio_context_free_attr_values()
  6. The complete XML string with values is returned to the user

Usage

iio_genxml -e

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have commented new code, particularly complex or unclear areas
  • I have checked that I did not introduce new warnings or errors (CI output)
  • I have checked that components that use libiio did not get broken
  • I have updated the documentation accordingly (GitHub Pages, READMEs, etc)

@999Marius 999Marius marked this pull request as draft March 12, 2026 12:13
@999Marius
Copy link
Collaborator Author

999Marius commented Mar 12, 2026

Feedback Request

I wanted to get feedback on the -v short flag for --values. While it's distinct from -V (version), it may be confused with it.

Alternative options I thought of:

  • -a, --values (for "attribute values")
  • -w, --values (for "with values")
  • --values only

Open to other suggestions for better naming as well.

Note: I discovered that buffer attributes changed (thanks to the pre-allocated buffer changes in main). This means buffer attribute values could and will be added to XML generation as a follow-up push.

@999Marius 999Marius marked this pull request as ready for review March 12, 2026 13:29
@999Marius 999Marius marked this pull request as draft March 13, 2026 08:13
@999Marius 999Marius marked this pull request as ready for review March 16, 2026 13:02
@999Marius
Copy link
Collaborator Author

999Marius commented Mar 16, 2026

Update V2:

  • Added buffer attribute value support (all attribute types are now supported)
  • Ready for review

@rgetz
Copy link
Contributor

rgetz commented Mar 16, 2026

does -e --emulator make more sense?

@999Marius
Copy link
Collaborator Author

does -e --emulator make more sense?

Good point, -e, --emulator is more accurate since this is intended for iio-emu integration.
Will update.

…ructs

Add char **values fields to iio_device (per attr type), iio_channel,
and iio_buffer to store attribute values alongside names.
Update xml_header with optional value attribute (CDATA #IMPLIED)
for attribute, debug-attribute, and buffer-attribute elements.

Signed-off-by: Marius Lucacel <[email protected]>
Add include_values flag to XML generation functions so attribute
values can optionally be serialized into the XML.

Restructure leaf functions (iio_snprintf_xml_attr,
iio_snprintf_chan_attr_xml) to build attributes in XML:
name, optional filename, optional value

Extends to buffer attributes inside <buffer> blocks. The backward-compat
<buffer-attribute> tags intentionally omit values as they exist for
older clients.

iio_context_generate_xml() is now the helper instead of the older
iio_context_get_xml() which now wraps it with include_values = false

Signed-off-by: Marius Lucacel <[email protected]>
Add iio_context_refresh_attr_values() to read and cache all
attribute values from devices, channels, and buffers into the
context structures.
Add iio_context_free_attr_values() to free those cached values
after XML generation is complete.

iio_context_generate_xml() calls refresh when include_values is true
and always cleans up via iio_context_free_attr_values()

Attribute values are now serialized into the XML output when
include_values is true.

Signed-off-by: Marius Lucacel <[email protected]>
Add a public wrapper function that generates XML including current
attribute values.
The function wraps iio_context_generate_xml(ctx, true) which refreshes
all attribute values before serialization.

Signed-off-by: Marius Lucacel <[email protected]>
Add a new -e/--emulator command-line option to iio_genxml to generate
XML with device, channel and buffer attribute values.
This utilizes the new iio_context_get_xml_with_values().
Update man page.

Signed-off-by: Marius Lucacel <[email protected]>
@999Marius
Copy link
Collaborator Author

Update V3:

  • Renamed flag from -v (--values) to -e (--emulator)
  • Rebased on latest main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants