diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-03-18 15:20:09 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-03-18 15:20:09 +0100 |
commit | 5023b54ba76325bb0b5598d59714bdad2d55d81e (patch) | |
tree | 15cc639eff7dbfa12eeccaa52d7fd251f18969e6 /video/camera.cpp | |
parent | 3aababf6fd53a7b0312c2c1492bab6b43584b613 (diff) |
video: add support for camera modules
Issue: #910
Diffstat (limited to 'video/camera.cpp')
-rw-r--r-- | video/camera.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/video/camera.cpp b/video/camera.cpp new file mode 100644 index 00000000..c33ab13a --- /dev/null +++ b/video/camera.cpp @@ -0,0 +1,66 @@ +#include "camera.hpp" + +#include <algorithm> +#include <utility> +#include <QMutex> + +static std::vector<std::unique_ptr<video::impl::camera_>> metadata; +static QMutex mtx; + +namespace video::impl { + +camera_::camera_() = default; +camera_::~camera_() = default; + +camera::camera() = default; +camera::~camera() = default; + +void register_camera(std::unique_ptr<impl::camera_> camera) +{ + QMutexLocker l(&mtx); + metadata.push_back(std::move(camera)); +} + +} // ns video::impl + +namespace video { + +bool show_dialog(const QString& camera_name) +{ + QMutexLocker l(&mtx); + + for (auto& camera : metadata) + for (const QString& name : camera->camera_names()) + if (name == camera_name) + return camera->show_dialog(camera_name); + + return false; +} + +std::unique_ptr<camera_impl> make_camera(const QString& name) +{ + QMutexLocker l(&mtx); + + for (auto& camera : metadata) + for (const QString& name_ : camera->camera_names()) + if (name_ == name) + return camera->make_camera(name); + + return nullptr; +} + +std::vector<QString> camera_names() +{ + QMutexLocker l(&mtx); + std::vector<QString> names; names.reserve(32); + + for (auto& camera : metadata) + for (const QString& name : camera->camera_names()) + if (std::find(names.cbegin(), names.cend(), name) == names.cend()) + names.push_back(name); + + std::sort(names.begin(), names.end()); + return names; +} + +} // ns video |