blob: 4fb1422346fa3cc0968a9f6c4b44fab0905e4e96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "physicaldeviceproxy_p.h"
#include <Qt3DInput/qabstractphysicaldevice.h>
#include <QtCore/QCoreApplication>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
QT_BEGIN_NAMESPACE
namespace Qt3DInput {
namespace Input {
PhysicalDeviceProxy::PhysicalDeviceProxy()
: BackendNode(QBackendNode::ReadWrite)
, m_manager(nullptr)
{
}
void PhysicalDeviceProxy::cleanup()
{
QBackendNode::setEnabled(false);
m_deviceName.clear();
m_manager = nullptr;
m_physicalDeviceId = Qt3DCore::QNodeId();
}
QString PhysicalDeviceProxy::deviceName() const
{
return m_deviceName;
}
void PhysicalDeviceProxy::setManager(PhysicalDeviceProxyManager *manager)
{
m_manager = manager;
}
PhysicalDeviceProxyManager *PhysicalDeviceProxy::manager() const
{
return m_manager;
}
void PhysicalDeviceProxy::setDevice(QAbstractPhysicalDevice *device)
{
m_physicalDeviceId = Qt3DCore::QNodeId();
// Move the device to the main thread
if (device != nullptr) {
m_physicalDeviceId = device->id();
device->moveToThread(QCoreApplication::instance()->thread());
}
}
Qt3DCore::QNodeId PhysicalDeviceProxy::physicalDeviceId() const
{
return m_physicalDeviceId;
}
void PhysicalDeviceProxy::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
BackendNode::syncFromFrontEnd(frontEnd, firstTime);
if (firstTime) {
const QAbstractPhysicalDeviceProxy *node = qobject_cast<const QAbstractPhysicalDeviceProxy *>(frontEnd);
if (!node)
return;
m_deviceName = node->deviceName();
// Request to load the actual device
m_manager->addPendingProxyToLoad(peerId());
}
}
PhysicalDeviceProxyNodeFunctor::PhysicalDeviceProxyNodeFunctor(PhysicalDeviceProxyManager *manager)
: m_manager(manager)
{
}
Qt3DCore::QBackendNode *PhysicalDeviceProxyNodeFunctor::create(Qt3DCore::QNodeId id) const
{
HPhysicalDeviceProxy handle = m_manager->getOrAcquireHandle(id);
PhysicalDeviceProxy *backend = m_manager->data(handle);
backend->setManager(m_manager);
return backend;
}
Qt3DCore::QBackendNode *PhysicalDeviceProxyNodeFunctor::get(Qt3DCore::QNodeId id) const
{
return m_manager->lookupResource(id);
}
void PhysicalDeviceProxyNodeFunctor::destroy(Qt3DCore::QNodeId id) const
{
m_manager->releaseResource(id);
}
} // namespace Input
} // namespace Qt3DInput
QT_END_NAMESPACE
|