Loading...
Searching...
No Matches
DeviceEnumerator.hpp
1#pragma once
2
3#include <Device/Protocol/DeviceSettings.hpp>
4#include <Device/Protocol/ProtocolFactoryInterface.hpp>
5
6#include <QQmlListProperty>
7
8#include <unordered_map>
9#include <verdigris>
10
11namespace Explorer
12{
13class DeviceDocumentPlugin;
14}
15namespace Device
16{
17struct DeviceSettings;
18class DeviceList;
19class ProtocolFactory;
20class DeviceEnumerator;
21}
22
23namespace JS
24{
25struct DeviceIdentifier : public QObject
26{
27 W_OBJECT(DeviceIdentifier)
28public:
29 explicit DeviceIdentifier(
30 QString cat, QString a, Device::DeviceSettings b, Device::ProtocolFactory* c)
31 : category{std::move(cat)}
32 , name{std::move(a)}
33 , settings{std::move(b)}
34 , protocol{c}
35 {
36 }
37 QString category;
38 QString name;
40 Device::ProtocolFactory* protocol{};
41
42 W_PROPERTY(QString, category MEMBER category)
43 W_PROPERTY(QString, name MEMBER name)
44 W_PROPERTY(Device::DeviceSettings, settings MEMBER settings)
45 W_PROPERTY(Device::ProtocolFactory*, protocol MEMBER protocol)
46};
47
48class GlobalDeviceEnumerator : public QObject
49{
51
52public:
53 explicit GlobalDeviceEnumerator();
54 explicit GlobalDeviceEnumerator(const QString& uuid);
56
57 void setContext(const score::DocumentContext* doc);
58 W_SLOT(setContext)
59
60 void deviceAdded(
61 Device::ProtocolFactory* factory, const QString& category, const QString& name,
63 W_SIGNAL(deviceAdded, factory, category, name, settings)
64 void deviceRemoved(Device::ProtocolFactory* factory, const QString& name)
65 W_SIGNAL(deviceRemoved, factory, name)
66 QQmlListProperty<JS::DeviceIdentifier> devices();
67
68 W_PROPERTY(QQmlListProperty<JS::DeviceIdentifier>, devices READ devices)
69
70 bool enumerate() { return m_enumerate; }
71 void setEnumerate(bool b);
72 void enumerateChanged(bool b) W_SIGNAL(enumerateChanged, b)
73 W_PROPERTY(bool, enumerate READ enumerate WRITE setEnumerate NOTIFY enumerateChanged)
74
75private:
76 void reprocess();
77 const score::DocumentContext* doc{};
78
79 std::unordered_map<
81 std::vector<std::tuple<QString, QString, Device::DeviceSettings>>>
82 m_known_devices;
83 std::unordered_map<Device::ProtocolFactory*, Device::DeviceEnumerators>
84 m_current_enums;
85
86 std::vector<DeviceIdentifier*> m_raw_list;
87 Device::ProtocolFactory::ConcreteKey m_filter{};
88
89 bool m_enumerate{};
90};
91}
92
93Q_DECLARE_METATYPE(JS::GlobalDeviceEnumerator*)
94W_REGISTER_ARGTYPE(Device::ProtocolFactory*)
Definition ProtocolFactoryInterface.hpp:49
Definition DeviceEnumerator.hpp:49
GlobalDeviceEnumerator()
Definition DeviceEnumerator.cpp:23
Manipulation of Devices from Qt.
Definition AddressSettings.cpp:14
Definition DeviceSettings.hpp:20
Definition DeviceEnumerator.hpp:26
Definition DocumentContext.hpp:18