2021-10-17 15:35:30 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "qt_camera_error_handler.h"
|
|
|
|
|
|
|
|
|
|
LOG_CHANNEL(camera_log, "Camera");
|
|
|
|
|
|
2021-05-22 10:42:05 +02:00
|
|
|
qt_camera_error_handler::qt_camera_error_handler(std::shared_ptr<QCamera> camera, std::function<void(bool)> status_callback)
|
2021-10-17 15:35:30 +02:00
|
|
|
: m_camera(std::move(camera))
|
|
|
|
|
, m_status_callback(std::move(status_callback))
|
|
|
|
|
{
|
|
|
|
|
if (m_camera)
|
|
|
|
|
{
|
2021-05-22 10:42:05 +02:00
|
|
|
connect(m_camera.get(), &QCamera::activeChanged, this, &qt_camera_error_handler::handle_camera_active);
|
2021-10-17 15:35:30 +02:00
|
|
|
connect(m_camera.get(), &QCamera::errorOccurred, this, &qt_camera_error_handler::handle_camera_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qt_camera_error_handler::~qt_camera_error_handler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 10:42:05 +02:00
|
|
|
void qt_camera_error_handler::handle_camera_active(bool is_active)
|
2021-10-17 15:35:30 +02:00
|
|
|
{
|
2021-05-22 10:42:05 +02:00
|
|
|
camera_log.notice("Camera active status changed to %d", is_active);
|
2021-10-17 15:35:30 +02:00
|
|
|
|
|
|
|
|
if (m_status_callback)
|
|
|
|
|
{
|
2021-05-22 10:42:05 +02:00
|
|
|
m_status_callback(is_active);
|
2021-10-17 15:35:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 10:42:05 +02:00
|
|
|
void qt_camera_error_handler::handle_camera_error(QCamera::Error error, const QString& errorString)
|
2021-10-17 15:35:30 +02:00
|
|
|
{
|
2021-05-22 10:42:05 +02:00
|
|
|
camera_log.error("Error event: \"%s\" (error=%d)", errorString, static_cast<int>(error));
|
2021-10-17 15:35:30 +02:00
|
|
|
}
|