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 
11 namespace Explorer
12 {
13 class DeviceDocumentPlugin;
14 }
15 namespace Device
16 {
17 struct DeviceSettings;
18 class DeviceList;
19 class ProtocolFactory;
20 class DeviceEnumerator;
21 }
22 
23 namespace JS
24 {
25 struct DeviceIdentifier : public QObject
26 {
27  W_OBJECT(DeviceIdentifier)
28 public:
29  explicit DeviceIdentifier(
31  : name{std::move(a)}
32  , settings{std::move(b)}
33  , protocol{c}
34  {
35  }
36  QString name;
37  Device::DeviceSettings settings;
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 
45 class GlobalDeviceEnumerator : public QObject
46 {
47  W_OBJECT(GlobalDeviceEnumerator)
48 
49 public:
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 
71 private:
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 
87 Q_DECLARE_METATYPE(JS::GlobalDeviceEnumerator*)
88 W_REGISTER_ARGTYPE(Device::ProtocolFactory*)
Definition: ProtocolFactoryInterface.hpp:47
Definition: DeviceEnumerator.hpp:44
Manipulation of Devices from Qt.
Definition: AddressSettings.cpp:14
Definition: DeviceSettings.hpp:20
Definition: DeviceEnumerator.hpp:26
Definition: DocumentContext.hpp:18