summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-24 18:29:32 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-06-16 02:43:47 +0300
commitd6d0a675bfe27420d14394ef6b0da5247ea63d87 (patch)
treeff4e62ad8017165de3bb76925cc7baa0cf97b9c1 /src/android
parent27fb47f70b55000fbd793c40377c20d915216f70 (diff)
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>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/camera_hal_config.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/android/camera_hal_config.cpp b/src/android/camera_hal_config.cpp
index 8ba8738c..ac484b8d 100644
--- a/src/android/camera_hal_config.cpp
+++ b/src/android/camera_hal_config.cpp
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string>
+#include <libcamera/base/file.h>
#include <libcamera/base/log.h>
#include "libcamera/internal/yaml_parser.h"
@@ -27,7 +28,7 @@ class CameraHalConfig::Private : public Extensible::Private
public:
Private();
- int parseConfigFile(FILE *fh, std::map<std::string, CameraConfigData> *cameras);
+ int parseConfigFile(File &file, std::map<std::string, CameraConfigData> *cameras);
private:
int parseCameraConfigData(const std::string &cameraId, const YamlObject &);
@@ -41,7 +42,7 @@ CameraHalConfig::Private::Private()
{
}
-int CameraHalConfig::Private::parseConfigFile(FILE *fh,
+int CameraHalConfig::Private::parseConfigFile(File &file,
std::map<std::string, CameraConfigData> *cameras)
{
/*
@@ -65,7 +66,7 @@ int CameraHalConfig::Private::parseConfigFile(FILE *fh,
cameras_ = cameras;
- std::unique_ptr<YamlObject> root = YamlParser::parse(fh);
+ std::unique_ptr<YamlObject> root = YamlParser::parse(file);
if (!root)
return -EINVAL;
@@ -169,9 +170,9 @@ int CameraHalConfig::parseConfigurationFile()
return -ENOENT;
}
- FILE *fh = fopen(filePath.c_str(), "r");
- if (!fh) {
- int ret = -errno;
+ File file(filePath);
+ if (!file.open(File::OpenModeFlag::ReadOnly)) {
+ int ret = file.error();
LOG(HALConfig, Error) << "Failed to open configuration file "
<< filePath << ": " << strerror(-ret);
return ret;
@@ -179,8 +180,7 @@ int CameraHalConfig::parseConfigurationFile()
exists_ = true;
- int ret = _d()->parseConfigFile(fh, &cameras_);
- fclose(fh);
+ int ret = _d()->parseConfigFile(file, &cameras_);
if (ret)
return -EINVAL;