summaryrefslogtreecommitdiffhomepage
path: root/video/camera.cpp
blob: 4232040208457538d1d3aaa399de592ccce3dc0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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::unique_ptr<camera_impl> make_camera(const QString& name)
{
    if (auto ret = make_camera_(name))
        return ret;

    for (auto& camera : metadata)
        for (const QString& name_ : camera->camera_names())
            if (auto ret = camera->make_camera(name_))
                return ret;

    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