From f357b1bf6ea39d8118e90f8a371974d29bd054e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 26 Jul 2022 02:36:38 +0300 Subject: ipa: raspberrypi: Return an error code from Algorithm::read() When encountering errors, the Algorithm::read() function either uses LOG(Fatal) or throws exceptions from the boost property_tree functions. To prepare for replacing boost JSON parse with the YamlParser class, give the Algorithm::read() function the ability to return an error code, and propagate it all the way to the IPA module init() function. All algorithm classes return a hardcoded 0 value for now, subsequent commits will change that. Signed-off-by: Laurent Pinchart Reviewed-by: Naushir Patuck Tested-by: Naushir Patuck --- src/ipa/raspberrypi/controller/rpi/ccm.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/ipa/raspberrypi/controller/rpi/ccm.cpp') diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp index cf0c85d2..f0110d38 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp @@ -39,7 +39,7 @@ Matrix::Matrix(double m0, double m1, double m2, double m3, double m4, double m5, m[0][0] = m0, m[0][1] = m1, m[0][2] = m2, m[1][0] = m3, m[1][1] = m4, m[1][2] = m5, m[2][0] = m6, m[2][1] = m7, m[2][2] = m8; } -void Matrix::read(boost::property_tree::ptree const ¶ms) +int Matrix::read(boost::property_tree::ptree const ¶ms) { double *ptr = (double *)m; int n = 0; @@ -50,6 +50,7 @@ void Matrix::read(boost::property_tree::ptree const ¶ms) } if (n < 9) LOG(RPiCcm, Fatal) << "Ccm: too few values in CCM"; + return 0; } Ccm::Ccm(Controller *controller) @@ -60,21 +61,32 @@ char const *Ccm::name() const return NAME; } -void Ccm::read(boost::property_tree::ptree const ¶ms) +int Ccm::read(boost::property_tree::ptree const ¶ms) { - if (params.get_child_optional("saturation")) - config_.saturation.read(params.get_child("saturation")); + int ret; + + if (params.get_child_optional("saturation")) { + ret = config_.saturation.read(params.get_child("saturation")); + if (ret) + return ret; + } + for (auto &p : params.get_child("ccms")) { CtCcm ctCcm; ctCcm.ct = p.second.get("ct"); - ctCcm.ccm.read(p.second.get_child("ccm")); + ret = ctCcm.ccm.read(p.second.get_child("ccm")); + if (ret) + return ret; if (!config_.ccms.empty() && ctCcm.ct <= config_.ccms.back().ct) LOG(RPiCcm, Fatal) << "Ccm: CCM not in increasing colour temperature order"; config_.ccms.push_back(std::move(ctCcm)); } + if (config_.ccms.empty()) LOG(RPiCcm, Fatal) << "Ccm: no CCMs specified"; + + return 0; } void Ccm::setSaturation(double saturation) -- cgit v1.2.1