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(
31 : name{std::move(a)}
32 , settings{std::move(b)}
33 , protocol{c}
34 {
35 }
36 QString name;
38 Device::ProtocolFactory* protocol{};
39
40 W_PROPERTY(QString, name MEMBER name)
41 W_PROPERTY(Device::DeviceSettings, settings MEMBER settings)
42 W_PROPERTY(Device::ProtocolFactory*, protocol MEMBER protocol)
43};
44
45class GlobalDeviceEnumerator : public QObject
46{
48
49public:
50 explicit GlobalDeviceEnumerator();
52
53 void setContext(const score::DocumentContext* doc);
54 W_SLOT(setContext)
55
56 void deviceAdded(
57 Device::ProtocolFactory* factory, const QString& name,
58 Device::DeviceSettings settings) W_SIGNAL(deviceAdded, factory, name, settings)
59 void deviceRemoved(Device::ProtocolFactory* factory, const QString& name)
60 W_SIGNAL(deviceRemoved, factory, name)
61 // QList<Device::DeviceSettings> devices();
62 QQmlListProperty<JS::DeviceIdentifier> devices();
63
64 W_PROPERTY(QQmlListProperty<JS::DeviceIdentifier>, devices READ devices)
65
66 bool enumerate() { return m_enumerate; }
67 void setEnumerate(bool b);
68 void enumerateChanged(bool b) W_SIGNAL(enumerateChanged, b)
69 W_PROPERTY(bool, enumerate READ enumerate WRITE setEnumerate NOTIFY enumerateChanged)
70
71private:
72 void reprocess();
73 const score::DocumentContext* doc{};
74
75 std::unordered_map<
76 Device::ProtocolFactory*, std::vector<std::pair<QString, Device::DeviceSettings>>>
77 m_known_devices;
78 std::unordered_map<Device::ProtocolFactory*, Device::DeviceEnumerators>
79 m_current_enums;
80
81 std::vector<DeviceIdentifier*> m_raw_list;
82
83 bool m_enumerate{};
84};
85}
86
87Q_DECLARE_METATYPE(JS::GlobalDeviceEnumerator*)
88W_REGISTER_ARGTYPE(Device::ProtocolFactory*)
Definition ProtocolFactoryInterface.hpp:49
Definition DeviceEnumerator.hpp:46
GlobalDeviceEnumerator()
Definition DeviceEnumerator.cpp:21
Manipulation of Devices from Qt.
Definition AddressSettings.cpp:14
Definition DeviceSettings.hpp:20
Definition DeviceEnumerator.hpp:26
Definition DocumentContext.hpp:18