ProtocolFactoryInterface.hpp
1 #pragma once
2 #include <Device/Protocol/DeviceSettings.hpp>
3 
4 #include <score/document/DocumentContext.hpp>
5 #include <score/plugins/Interface.hpp>
6 #include <score/plugins/UuidKeySerialization.hpp>
8 
9 #include <QString>
10 #include <QVariant>
11 
12 #include <score_lib_device_export.h>
13 
14 class QUrl;
15 struct VisitorVariant;
16 
17 namespace Explorer
18 {
19 class DeviceDocumentPlugin;
20 }
21 namespace Device
22 {
23 struct DeviceSettings;
24 struct AddressSettings;
25 class DeviceInterface;
26 class ProtocolSettingsWidget;
27 class AddressDialog;
28 class SCORE_LIB_DEVICE_EXPORT DeviceEnumerator : public QObject
29 {
30  W_OBJECT(DeviceEnumerator)
31 public:
32  virtual ~DeviceEnumerator();
33 
34  virtual void
35  enumerate(std::function<void(const QString&, const Device::DeviceSettings&)>) const
36  = 0;
37 
38  void deviceAdded(const QString& n, const Device::DeviceSettings& s)
39  E_SIGNAL(SCORE_LIB_DEVICE_EXPORT, deviceAdded, n, s)
40  void deviceRemoved(const QString& s)
41  E_SIGNAL(SCORE_LIB_DEVICE_EXPORT, deviceRemoved, s)
42 };
43 
44 using DeviceEnumerators = std::vector<std::pair<QString, Device::DeviceEnumerator*>>;
45 
46 class SCORE_LIB_DEVICE_EXPORT ProtocolFactory : public score::InterfaceBase
47 {
48  SCORE_INTERFACE(ProtocolFactory, "3f69d72e-318d-42dc-b48c-a806036592f1")
49 
50 public:
51  virtual ~ProtocolFactory();
53  {
54  static const constexpr auto osc = "Network";
55  static const constexpr auto audio = "Audio";
56  static const constexpr auto video = "Video";
57  static const constexpr auto web = "Web";
58  static const constexpr auto hardware = "Hardware";
59  static const constexpr auto software = "Software";
60  static const constexpr auto lights = "Lights";
61  static const constexpr auto util = "Utilities";
62  };
63 
64  enum Flags
65  {
66  EditingReloadsEverything = (1 << 0)
67  };
68 
69  virtual Flags flags() const noexcept;
70 
71  virtual QString prettyName() const noexcept = 0;
72  virtual QString category() const noexcept = 0;
73  virtual QUrl manual() const noexcept;
74 
77  virtual int visualPriority() const noexcept;
78 
79  virtual DeviceEnumerators getEnumerators(const score::DocumentContext& ctx) const;
80 
81  virtual DeviceInterface* makeDevice(
82  const Device::DeviceSettings& settings,
83  const Explorer::DeviceDocumentPlugin& plugin, const score::DocumentContext& ctx)
84  = 0;
85 
86  virtual ProtocolSettingsWidget* makeSettingsWidget() = 0;
87 
88  virtual AddressDialog* makeAddAddressDialog(
89  const Device::DeviceInterface& dev, const score::DocumentContext& ctx, QWidget*)
90  = 0;
91  virtual AddressDialog* makeEditAddressDialog(
92  const Device::AddressSettings&, const Device::DeviceInterface& dev,
93  const score::DocumentContext& ctx, QWidget*)
94  = 0;
95 
96  virtual const Device::DeviceSettings& defaultSettings() const noexcept = 0;
97 
98  // Save
99  virtual void serializeProtocolSpecificSettings(
100  const QVariant& data, const VisitorVariant& visitor) const
101  = 0;
102 
103  template <typename T>
104  void serializeProtocolSpecificSettings_T(
105  const QVariant& data, const VisitorVariant& visitor) const
106  {
107  score::serialize_dyn(visitor, data.value<T>());
108  }
109 
110  // Load
111  virtual QVariant makeProtocolSpecificSettings(const VisitorVariant& visitor) const = 0;
112 
113  template <typename T>
114  QVariant makeProtocolSpecificSettings_T(const VisitorVariant& vis) const
115  {
116  return QVariant::fromValue(score::deserialize_dyn<T>(vis));
117  }
118 
122  virtual bool checkResourcesAvailable(
123  const Device::DeviceSettings& a, const DeviceResourceMap&) const noexcept;
124 
125  // Returns true if the two devicesettings can coexist at the same time.
126  virtual bool checkCompatibility(
127  const Device::DeviceSettings& a, const Device::DeviceSettings& b) const noexcept
128  = 0;
129 };
130 }
131 
132 Q_DECLARE_METATYPE(UuidKey<Device::ProtocolFactory>)
133 W_REGISTER_ARGTYPE(UuidKey<Device::ProtocolFactory>)
Definition: ProtocolSettingsWidget.hpp:41
Definition: ProtocolFactoryInterface.hpp:29
Definition: DeviceInterface.hpp:66
Definition: ProtocolFactoryInterface.hpp:47
Definition: ProtocolSettingsWidget.hpp:22
Base class for plug-in interfaces.
Definition: Interface.hpp:52
Manipulation of Devices from Qt.
Definition: AddressSettings.cpp:14
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: AddressSettings.hpp:49
Definition: DeviceSettings.hpp:20
Definition: ProtocolFactoryInterface.hpp:53
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26