ImagingTools Core SDK
CDeviceControllerCompBase.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#if QT_VERSION < 0x060000
7 #include <QtCore/QMutex>
8#else
9 #include <QtCore/QRecursiveMutex>
10#endif
11
12// ACF includes
13#include <imod/TModelWrap.h>
14#include <ilog/TLoggerCompWrap.h>
15
16// ImtCore includes
17#include <imtbase/CCollectionInfo.h>
18#include <imtbase/TModelUpdateBinder.h>
19#include <imtdev/IDeviceController.h>
20
21
22namespace imtdev
23{
24
25
73 public QObject,
74 public ilog::CLoggerComponentBase,
75 virtual public imtdev::IDeviceController
76{
77 Q_OBJECT
78public:
79 typedef ilog::CLoggerComponentBase BaseClass;
80
81 I_BEGIN_BASE_COMPONENT(CDeviceControllerCompBase)
82 I_REGISTER_SUBELEMENT(DeviceInfoList);
83 I_REGISTER_SUBELEMENT_INTERFACE(DeviceInfoList, imtbase::ICollectionInfo, ExtractDeviceInfoList);
84 I_REGISTER_SUBELEMENT_INTERFACE(DeviceInfoList, istd::IChangeable, ExtractDeviceInfoList);
85 I_REGISTER_SUBELEMENT_INTERFACE(DeviceInfoList, imod::IModel, ExtractDeviceInfoList);
86 I_REGISTER_SUBELEMENT(OverriddenDeviceInfo);
87 I_REGISTER_SUBELEMENT_INTERFACE(OverriddenDeviceInfo, imtbase::ICollectionInfo, ExtractOverriddenDeviceInfo);
88 I_REGISTER_SUBELEMENT_INTERFACE(OverriddenDeviceInfo, imod::IModel, ExtractOverriddenDeviceInfo);
89 I_REGISTER_SUBELEMENT_INTERFACE(OverriddenDeviceInfo, istd::IChangeable, ExtractOverriddenDeviceInfo);
90 I_REGISTER_INTERFACE(IDeviceController);
91 I_REGISTER_INTERFACE(IDeviceEnumerator);
92 I_ASSIGN(m_isAutoCloseEnabledAttrPtr, "AutoClose", "Automatically close an opened device if it is not found during the next enumeration", true, "true");
93 I_END_COMPONENT;
94
96
97 // reimplemented (IDeviceController)
98 virtual const imtbase::ICollectionInfo& GetDeviceInstanceList() const override;
99 virtual bool SetDeviceInstanceName(const QByteArray& deviceId, const QString& name) override;
100 virtual bool SetDeviceInstanceDescription(const QByteArray& deviceId, const QString& description) override;
101 virtual const IDeviceStateProvider& GetDeviceStateProvider() const override;
102
103protected:
104 struct EnumeratedDeviceInfo
105 {
106 QByteArray id;
107 QString name;
108 QString description;
109 };
110 typedef QVector<EnumeratedDeviceInfo> EnumeratedDeviceList;
111
112 class DeviceStateProvider : virtual public IDeviceStateProvider
113 {
114 public:
115 DeviceStateProvider();
116 void SetParent(CDeviceControllerCompBase& parent);
117
118 // reimplemented (IDeviceStateProvider)
119 virtual DeviceState GetDeviceState(const QByteArray& deviceId) const override;
120
121 private:
122 CDeviceControllerCompBase* m_parentPtr;
123 };
124
125protected:
126 // Must be called from the main thread!!!
127 void UpdateDeviceList(EnumeratedDeviceList& enumeratedDeviceList);
128 void UpdateDeviceList();
129 void AutoCloseDisconnectedDevices();
130
131 template <class InteraceType>
132 static InteraceType* ExtractDeviceInfoList(CDeviceControllerCompBase& parent)
133 {
134 return &parent.m_deviceList;
135 }
136
137 template <class InteraceType>
138 static InteraceType* ExtractOverriddenDeviceInfo(CDeviceControllerCompBase& parent)
139 {
140 return &parent.m_overriddenDeviceInfo;
141 }
142
143 // reimplemened (icomp::CComponentBase)
144 virtual void OnComponentCreated() override;
145 virtual void OnComponentDestroyed() override;
146
147protected:
148 I_ATTR(bool, m_isAutoCloseEnabledAttrPtr);
149
150 imod::TModelWrap<imtbase::CCollectionInfo> m_deviceList;
151 imod::TModelWrap<imtbase::CCollectionInfo> m_overriddenDeviceInfo;
152 imod::TModelWrap<DeviceStateProvider> m_deviceStateProvider;
153 QMap<QByteArray, DeviceAccessorPtr> m_openedDevices;
154
155#if QT_VERSION < 0x060000
156 mutable QMutex m_deviceListMutex;
157 mutable QMutex m_openedDevicesMutex;
158#else
159 mutable QRecursiveMutex m_deviceListMutex;
160 mutable QRecursiveMutex m_openedDevicesMutex;
161#endif
162
163private:
164 void OnOverriddenDeviceInfoUpdated(const istd::IChangeable::ChangeSet& changeset, const imtbase::ICollectionInfo* objectPtr);
165
166private:
168};
169
170
171} // namespace imtdev
172
173
Base controller component implementing IDeviceController interface.
Common interface for controlling devices.
Interface for asynchronous device enumeration.
Interface for tracking device connection states.
DeviceState
Runtime state of a device.