Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore support for reading/writing all attributes and improve compat layer #1088

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 61 additions & 12 deletions compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ ssize_t iio_device_attr_read(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_attr)(dev, name);
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);
if (attr)
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);

return -ENOENT;
}

int iio_device_attr_read_bool(const struct iio_device *dev,
Expand All @@ -981,7 +984,10 @@ int iio_device_attr_read_bool(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_attr)(dev, name);
return IIO_CALL(iio_attr_read_bool)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_bool)(attr, val);

return -ENOENT;
}

int iio_device_attr_read_longlong(const struct iio_device *dev,
Expand All @@ -990,7 +996,10 @@ int iio_device_attr_read_longlong(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_attr)(dev, name);
return IIO_CALL(iio_attr_read_longlong)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_longlong)(attr, val);

return -ENOENT;
}

int iio_device_attr_read_double(const struct iio_device *dev,
Expand All @@ -999,7 +1008,10 @@ int iio_device_attr_read_double(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_attr)(dev, name);
return IIO_CALL(iio_attr_read_double)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_double)(attr, val);

return -ENOENT;
}

int iio_device_attr_read_all(struct iio_device *dev,
Expand Down Expand Up @@ -1159,7 +1171,10 @@ ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_debug_attr)(dev, name);
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);
if (attr)
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);

return -ENOENT;
}

int iio_device_debug_attr_read_bool(const struct iio_device *dev,
Expand All @@ -1168,7 +1183,10 @@ int iio_device_debug_attr_read_bool(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_debug_attr)(dev, name);
return IIO_CALL(iio_attr_read_bool)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_bool)(attr, val);

return -ENOENT;
}

int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
Expand All @@ -1177,7 +1195,10 @@ int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_debug_attr)(dev, name);
return IIO_CALL(iio_attr_read_longlong)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_longlong)(attr, val);

return -ENOENT;
}

int iio_device_debug_attr_read_double(const struct iio_device *dev,
Expand All @@ -1186,7 +1207,10 @@ int iio_device_debug_attr_read_double(const struct iio_device *dev,
const struct iio_attr *attr;

attr = IIO_CALL(iio_device_find_debug_attr)(dev, name);
return IIO_CALL(iio_attr_read_double)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_double)(attr, val);

return -ENOENT;
}

int iio_device_debug_attr_read_all(struct iio_device *dev,
Expand Down Expand Up @@ -1661,13 +1685,29 @@ const char * iio_channel_find_attr(const struct iio_channel *chn,
return IIO_CALL(iio_attr_get_name)(attr);
}

const char * iio_channel_attr_get_filename(const struct iio_channel *chn,
const char *name)
{
const struct iio_attr *attr;

attr = IIO_CALL(iio_channel_find_attr)(chn, name);
if (!attr)
return NULL;

return IIO_CALL(iio_attr_get_filename)(attr);
}


ssize_t iio_channel_attr_read(const struct iio_channel *chn,
const char *name, char *dst, size_t len)
{
const struct iio_attr *attr;

attr = IIO_CALL(iio_channel_find_attr)(chn, name);
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);
if (attr)
return IIO_CALL(iio_attr_read_raw)(attr, dst, len);

return -ENOENT;
}

int iio_channel_attr_read_bool(const struct iio_channel *chn,
Expand All @@ -1676,7 +1716,10 @@ int iio_channel_attr_read_bool(const struct iio_channel *chn,
const struct iio_attr *attr;

attr = IIO_CALL(iio_channel_find_attr)(chn, name);
return IIO_CALL(iio_attr_read_bool)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_bool)(attr, val);

return -ENOENT;
}

int iio_channel_attr_read_longlong(const struct iio_channel *chn,
Expand All @@ -1685,7 +1728,10 @@ int iio_channel_attr_read_longlong(const struct iio_channel *chn,
const struct iio_attr *attr;

attr = IIO_CALL(iio_channel_find_attr)(chn, name);
return IIO_CALL(iio_attr_read_longlong)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_longlong)(attr, val);

return -ENOENT;
}

int iio_channel_attr_read_double(const struct iio_channel *chn,
Expand All @@ -1694,7 +1740,10 @@ int iio_channel_attr_read_double(const struct iio_channel *chn,
const struct iio_attr *attr;

attr = IIO_CALL(iio_channel_find_attr)(chn, name);
return IIO_CALL(iio_attr_read_double)(attr, val);
if (attr)
return IIO_CALL(iio_attr_read_double)(attr, val);

return -ENOENT;
}

int iio_channel_attr_read_all(struct iio_channel *chn,
Expand Down
Loading