Commit graph

8 commits

Author SHA1 Message Date
Laurent Pinchart
feb8c9be78 libcamera: yaml_parser: Replace ok flag to get() with std::optional
The YamlObject::get() function takes a default value and an optional
bool ok flag to handle parsing errors. This ad-hoc mechanism complicates
error handling in callers.

A better API is possible by dropping the default value and ok flag and
returning an std::optional. Not only does it simplify the calls, it also
lets callers handle errors through the standard std::optional class
instead of the current ad-hoc mechanism.

Provide a get() wrapper around std::optional::value_or() to further
simplify callers that don't need any specific error handling.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-07-28 13:47:13 +03:00
Laurent Pinchart
9dacead615 libcamera: yaml_parser: Remove memberNames() function
Now that YamlObject supports iteration, the memberNames() function isn't
useful anymore as it can be implemented using utils::map_keys() if
really needed. Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>
2022-06-20 15:12:26 +03:00
Laurent Pinchart
90577226aa test: yaml_parser: Extend tests to cover the iterator API
Test iteration over lists and dictionaries to test the YamlObject
iterator API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org>
2022-06-20 15:12:12 +03:00
Laurent Pinchart
1657106b0c test: yaml-parser: Use write() instead of fwrite()
There's no point in wrapping a fd into a FILE to then only call fwrite()
and fclose(). Use write() and close() directly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
d6d0a675bf libcamera: yaml_parser: Switch from FILE to File
THe FILE object isn't very user-friendly as it requires manual close.
Replace it with File to provide RAII-style resource management in the
YamlParser API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
27fb47f70b libcamera: yaml_parser: Extend YamlObject::size() to dictionaries
Dictionaries have a size too, extend the size() function to support
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-16 02:43:47 +03:00
Laurent Pinchart
5517ffbff6 libcamera: Use "..." instead of <...> consistently for internal headers
libcamera uses double quotes for #include directives for internal
headers. A few <...> have found their way in the code base over time.
Fix them.

While at it, move an Android header include to the right location.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-01 12:08:36 +03:00
Han-Lin Chen
c4c4ff92b4 test: Add YamlParser test
Add a unit test to exercise the API of the YamlParser class.

Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-10 00:22:36 +03:00