Loading...
Searching...
No Matches
DeviceDocumentPlugin.hpp
1#pragma once
2#include <Device/Node/DeviceNode.hpp>
3
4#include <Explorer/DeviceList.hpp>
5#include <Explorer/DocumentPlugin/NodeUpdateProxy.hpp>
6#include <Explorer/Explorer/DeviceExplorerModel.hpp>
7#include <Explorer/Listening/ListeningHandler.hpp>
8
9#include <score/plugins/documentdelegate/plugin/DocumentPlugin.hpp>
10
11#include <ossia/detail/hash_map.hpp>
12
13#include <score_plugin_deviceexplorer_export.h>
14
15#include <thread>
16#include <verdigris>
17
18namespace ossia::net
19{
20struct network_context;
21using network_context_ptr = std::shared_ptr<network_context>;
22}
23
24UUID_METADATA(
25 , score::DocumentPluginFactory, Explorer::DeviceDocumentPlugin,
26 "6e610e1f-9de2-4c36-90dd-0ef570002a21")
27
28namespace Explorer
29{
30class SCORE_PLUGIN_DEVICEEXPLORER_EXPORT DeviceDocumentPlugin final
32 , public Nano::Observer
33{
34 W_OBJECT(DeviceDocumentPlugin)
35 SCORE_SERIALIZE_FRIENDS
36
37 MODEL_METADATA_IMPL_HPP(DeviceDocumentPlugin)
38public:
39 explicit DeviceDocumentPlugin(const score::DocumentContext& ctx, QObject* parent);
40
41 virtual ~DeviceDocumentPlugin();
42 template <typename Impl>
43 DeviceDocumentPlugin(const score::DocumentContext& ctx, Impl& vis, QObject* parent)
44 : score::SerializableDocumentPlugin{ctx, vis, parent}
45 {
46 init();
47 vis.writeTo(*this);
48 }
49
50 void init();
51
52 void on_documentClosing() override;
53
54 Device::Node& rootNode() { return m_rootNode; }
55 const Device::Node& rootNode() const { return m_rootNode; }
56
57 Device::DeviceList& list() { return m_list; }
58
59 const Device::DeviceList& list() const { return m_list; }
60
61 // TODO make functions that take a parameter and call
62 // list().device(...).TheRelevantMethod
63
64 Device::Node createDeviceFromNode(const Device::Node&);
65
66 // If the output is different that the input,
67 // it means that the node has changes and the output should
68 // be used.
69 std::optional<Device::Node> loadDeviceFromNode(const Device::Node&);
70
71 void setConnection(bool);
72
73 Explorer::ListeningHandler& listening() const;
74
75 DeviceExplorerModel& explorer() const { return *m_explorer; }
76
77 void setupConnections(Device::DeviceInterface&, bool enabled);
78
79 void reconnect(const QString&);
80
90 bool refreshDeviceTree(Device::DeviceInterface& dev);
91
101 void refreshDeviceTreeOnReconnect(Device::DeviceInterface& dev);
102
103 const ossia::net::network_context_ptr& networkContext() const noexcept
104 {
105 return m_asioContext;
106 }
107
108private:
109 void initDevice(Device::DeviceInterface&);
110 void on_valueUpdated(const State::Address& addr, const ossia::value& v);
111
112 Device::Node m_rootNode;
113 Device::DeviceList m_list;
114 std::atomic_bool m_processMessages{};
115 std::thread m_asioThread;
116 ossia::net::network_context_ptr m_asioContext;
117
118 mutable std::unique_ptr<Explorer::ListeningHandler> m_listening;
119 DeviceExplorerModel* m_explorer{};
120 ossia::hash_map<Device::DeviceInterface*, std::vector<QMetaObject::Connection>>
121 m_connections;
122 // Devices with a refreshDeviceTreeOnReconnect() pending.
123 ossia::hash_set<Device::DeviceInterface*> m_pendingTreeRefresh;
124 // Devices with a deferred refreshDeviceTree() already queued.
125 ossia::hash_set<Device::DeviceInterface*> m_queuedTreeRefresh;
126
127 void asyncConnect(Device::DeviceInterface& newdev);
128 void timerEvent(QTimerEvent* event) override;
129
130public:
131 NodeUpdateProxy updateProxy{*this};
132};
133}
Definition DeviceInterface.hpp:107
The DeviceList class.
Definition DeviceList.hpp:26
Definition ListeningHandler.hpp:21
Reimplement to instantiate document plug-ins.
Definition DocumentPluginCreator.hpp:25
Document plug-in with serializable data.
Definition SerializableDocumentPlugin.hpp:28
Base toolkit upon which the software is built.
Definition Application.cpp:117
The Address struct.
Definition Address.hpp:58
Definition DocumentContext.hpp:18