IDS peak genericC++ v1.16.0
Loading...
Searching...
No Matches
peak_device.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
20#include <peak/dll_interface/peak_dll_interface_util.hpp>
21
22#include <cstddef>
23#include <cstdint>
24#include <memory>
25#include <string>
26#include <vector>
27
28
29namespace peak
30{
31namespace core
32{
33
34class Interface;
35
53class Device
55 , public std::enable_shared_from_this<Device>
56{
57public:
58 Device() = delete;
59 ~Device() override;
60 Device(const Device& other) = delete;
61 Device& operator=(const Device& other) = delete;
62 Device(Device&& other) = delete;
63 Device& operator=(Device&& other) = delete;
64
66 std::string Key() const;
67
69 RawInformation Info(int32_t infoCommand) const;
70
72 std::string ID() const;
73
75 std::string DisplayName() const;
76
78 std::string VendorName() const;
79
81 std::string ModelName() const;
82
84 std::string Version() const;
85
87 std::string TLType() const;
88
90 std::string UserDefinedName() const;
91
93 std::string SerialNumber() const;
94
97
99 uint64_t TimestampTickFrequency() const;
100
113 std::shared_ptr<class RemoteDevice> RemoteDevice() const;
114
124 std::vector<std::shared_ptr<DataStreamDescriptor>> DataStreams() const;
125
127 std::shared_ptr<Interface> ParentInterface() const;
128
139 {
140 return m_backendHandle;
141 }
142
143private:
144 PEAK_MODULE_HANDLE ModuleHandle() const override;
146
147 friend ClassCreator<Device>;
148 Device(PEAK_DEVICE_HANDLE deviceHandle, const std::weak_ptr<Interface>& parentInterface);
149 PEAK_DEVICE_HANDLE m_backendHandle;
150
151 std::weak_ptr<Interface> m_parentInterface;
152
153 void Initialize() const override;
154 mutable std::vector<std::shared_ptr<DataStreamDescriptor>> m_dataStreams;
155 mutable std::shared_ptr<class RemoteDevice> m_remoteDevice;
156
157 std::string m_key;
158};
159
160} /* namespace core */
161} /* namespace peak */
162
163/* Implementation */
164namespace peak
165{
166namespace core
167{
168
169inline Device::Device(PEAK_DEVICE_HANDLE deviceHandle, const std::weak_ptr<Interface>& parentInterface)
170 : m_backendHandle(deviceHandle)
171 , m_parentInterface(parentInterface)
172 , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
173 return PEAK_C_ABI_PREFIX PEAK_Device_GetKey(deviceHandle, key, keySize);
174 }))
175{}
176
178{
179 (void)PEAK_C_ABI_PREFIX PEAK_Device_Destruct(m_backendHandle);
180}
181
182inline std::string Device::Key() const
183{
184 return m_key;
185}
186
187inline RawInformation Device::Info(int32_t infoCommand) const
188{
189 return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
190 return PEAK_C_ABI_PREFIX PEAK_Device_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
191 });
192}
193
194inline std::string Device::ID() const
195{
196 return QueryStringFromCInterfaceFunction([&](char* id, size_t* idSize) {
197 return PEAK_C_ABI_PREFIX PEAK_Device_GetID(m_backendHandle, id, idSize);
198 });
199}
200
201inline std::string Device::DisplayName() const
202{
203 return QueryStringFromCInterfaceFunction([&](char* displayName, size_t* displayNameSize) {
204 return PEAK_C_ABI_PREFIX PEAK_Device_GetDisplayName(m_backendHandle, displayName, displayNameSize);
205 });
206}
207
208inline std::string Device::VendorName() const
209{
210 return QueryStringFromCInterfaceFunction([&](char* vendorName, size_t* vendorNameSize) {
211 return PEAK_C_ABI_PREFIX PEAK_Device_GetVendorName(m_backendHandle, vendorName, vendorNameSize);
212 });
213}
214
215inline std::string Device::ModelName() const
216{
217 return QueryStringFromCInterfaceFunction([&](char* modelName, size_t* modelNameSize) {
218 return PEAK_C_ABI_PREFIX PEAK_Device_GetModelName(m_backendHandle, modelName, modelNameSize);
219 });
220}
221
222inline std::string Device::Version() const
223{
224 return QueryStringFromCInterfaceFunction([&](char* version, size_t* versionSize) {
225 return PEAK_C_ABI_PREFIX PEAK_Device_GetVersion(m_backendHandle, version, versionSize);
226 });
227}
228
229inline std::string Device::TLType() const
230{
231 return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
232 return PEAK_C_ABI_PREFIX PEAK_Device_GetTLType(m_backendHandle, tlType, tlTypeSize);
233 });
234}
235
236inline std::string Device::UserDefinedName() const
237{
238 return QueryStringFromCInterfaceFunction([&](char* userDefinedName, size_t* userDefinedNameSize) {
240 m_backendHandle, userDefinedName, userDefinedNameSize);
241 });
242}
243
244inline std::string Device::SerialNumber() const
245{
246 return QueryStringFromCInterfaceFunction([&](char* serialNumber, size_t* serialNumberSize) {
247 return PEAK_C_ABI_PREFIX PEAK_Device_GetSerialNumber(m_backendHandle, serialNumber, serialNumberSize);
248 });
249}
250
252{
253 return static_cast<DeviceAccessStatus>(QueryNumericFromCInterfaceFunction<PEAK_DEVICE_ACCESS_STATUS>(
254 [&](PEAK_DEVICE_ACCESS_STATUS* accessStatus) {
255 return PEAK_C_ABI_PREFIX PEAK_Device_GetAccessStatus(m_backendHandle, accessStatus);
256 }));
257}
258
259inline uint64_t Device::TimestampTickFrequency() const
260{
261 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* timestampTickFrequency) {
262 return PEAK_C_ABI_PREFIX PEAK_Device_GetTimestampTickFrequency(m_backendHandle, timestampTickFrequency);
263 });
264}
265
266inline std::shared_ptr<class RemoteDevice> Device::RemoteDevice() const
267{
268 InitializeIfNecessary();
269
270 return m_remoteDevice;
271}
272
273inline std::vector<std::shared_ptr<DataStreamDescriptor>> Device::DataStreams() const
274{
275 InitializeIfNecessary();
276
277 return m_dataStreams;
278}
279
280inline std::shared_ptr<Interface> Device::ParentInterface() const
281{
282 return LockOrThrow(m_parentInterface);
283}
284
286{
287 auto moduleHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_HANDLE>(
288 [&](PEAK_MODULE_HANDLE* _moduleHandle) {
289 return PEAK_C_ABI_PREFIX PEAK_Device_ToModule(m_backendHandle, _moduleHandle);
290 });
291
292 return moduleHandle;
293}
294
296{
297 auto eventSupportingModuleHandle = QueryNumericFromCInterfaceFunction<PEAK_EVENT_SUPPORTING_MODULE_HANDLE>(
298 [&](PEAK_EVENT_SUPPORTING_MODULE_HANDLE* _eventSupportingModuleHandle) {
300 m_backendHandle, _eventSupportingModuleHandle);
301 });
302
303 return eventSupportingModuleHandle;
304}
305
306inline void Device::Initialize() const
307{
308 EventSupportingModule::Initialize(); // init data of parent classes (i.e. Module) as well
309
310 // init data streams
311 auto numDataStreams = QueryNumericFromCInterfaceFunction<size_t>([&](size_t* _numDataStreams) {
312 return PEAK_C_ABI_PREFIX PEAK_Device_GetNumDataStreams(m_backendHandle, _numDataStreams);
313 });
314
315 std::vector<std::shared_ptr<DataStreamDescriptor>> dataStreams;
316 for (size_t x = 0; x < numDataStreams; ++x)
317 {
318 auto dataStreamDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_DATA_STREAM_DESCRIPTOR_HANDLE>(
319 [&](PEAK_DATA_STREAM_DESCRIPTOR_HANDLE* _dataStreamDescriptorHandle) {
321 m_backendHandle, x, _dataStreamDescriptorHandle);
322 });
323
324 dataStreams.emplace_back(std::make_shared<ClassCreator<DataStreamDescriptor>>(
325 dataStreamDescriptorHandle, std::const_pointer_cast<Device>(shared_from_this())));
326 }
327
328 m_dataStreams = dataStreams;
329
330 // init remote device
331 auto remoteDeviceHandle = QueryNumericFromCInterfaceFunction<PEAK_REMOTE_DEVICE_HANDLE>(
332 [&](PEAK_REMOTE_DEVICE_HANDLE* _remoteDeviceHandle) {
333 return PEAK_C_ABI_PREFIX PEAK_Device_GetRemoteDevice(m_backendHandle, _remoteDeviceHandle);
334 });
335
336 m_remoteDevice = std::make_shared<ClassCreator<peak::core::RemoteDevice>>(
337 remoteDeviceHandle, std::const_pointer_cast<Device>(shared_from_this()));
338}
339
340} /* namespace core */
341} /* namespace peak */
std::string DisplayName() const
Returns the display name.
Definition peak_device.hpp:201
~Device() override
Definition peak_device.hpp:177
std::string VendorName() const
Returns the vendor name.
Definition peak_device.hpp:208
uint64_t TimestampTickFrequency() const
Returns the timestamp tick frequency.
Definition peak_device.hpp:259
PEAK_DEVICE_HANDLE Handle() const
Get the backend handle.
Definition peak_device.hpp:138
std::string SerialNumber() const
Returns the serial number.
Definition peak_device.hpp:244
std::string Version() const
Returns the version.
Definition peak_device.hpp:222
Device(Device &&other)=delete
std::vector< std::shared_ptr< DataStreamDescriptor > > DataStreams() const
Returns the data stream list of the device.
Definition peak_device.hpp:273
std::string TLType() const
Returns the TL (transport layer) type.
Definition peak_device.hpp:229
std::shared_ptr< Interface > ParentInterface() const
Returns the parent interface.
Definition peak_device.hpp:280
Device & operator=(const Device &other)=delete
std::string Key() const
Returns the unique key.
Definition peak_device.hpp:182
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition peak_device.hpp:187
DeviceAccessStatus AccessStatus() const
Returns the access status.
Definition peak_device.hpp:251
std::string UserDefinedName() const
Returns the user defined name.
Definition peak_device.hpp:236
Device(const Device &other)=delete
Device & operator=(Device &&other)=delete
std::string ID() const
Returns the ID.
Definition peak_device.hpp:194
std::string ModelName() const
Returns the model name.
Definition peak_device.hpp:215
std::shared_ptr< class RemoteDevice > RemoteDevice() const
Returns the remote device of the device.
Definition peak_device.hpp:266
virtual PEAK_EVENT_SUPPORTING_MODULE_HANDLE EventSupportingModuleHandle() const =0
Represents a GenTL Interface module.
Definition peak_interface.hpp:50
virtual PEAK_MODULE_HANDLE ModuleHandle() const =0
DeviceAccessStatus
Current accessibility of the device.
Definition peak_common_device_enums.hpp:26
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:35
PEAK_C_API PEAK_Device_ToModule(PEAK_DEVICE_HANDLE deviceHandle, PEAK_MODULE_HANDLE *moduleHandle)
Casts the given device to a module.
PEAK_C_API PEAK_Device_GetKey(PEAK_DEVICE_HANDLE deviceHandle, char *key, size_t *keySize)
Asks the given device for its key.
struct PEAK_MODULE * PEAK_MODULE_HANDLE
Definition peak_backend.h:421
PEAK_C_API PEAK_Device_GetVendorName(PEAK_DEVICE_HANDLE deviceHandle, char *vendorName, size_t *vendorNameSize)
Asks the given device for its vendor name.
struct PEAK_DATA_STREAM_DESCRIPTOR * PEAK_DATA_STREAM_DESCRIPTOR_HANDLE
Definition peak_backend.h:397
PEAK_C_API PEAK_Device_GetSerialNumber(PEAK_DEVICE_HANDLE deviceHandle, char *serialNumber, size_t *serialNumberSize)
Asks the given device for its serial number.
PEAK_C_API PEAK_Device_GetDisplayName(PEAK_DEVICE_HANDLE deviceHandle, char *displayName, size_t *displayNameSize)
Asks the given device for its display name.
PEAK_C_API PEAK_Device_GetModelName(PEAK_DEVICE_HANDLE deviceHandle, char *modelName, size_t *modelNameSize)
Asks the given device for its model name.
PEAK_C_API PEAK_Device_GetTimestampTickFrequency(PEAK_DEVICE_HANDLE deviceHandle, uint64_t *timestampTickFrequency)
Asks the given device for its timestamp tick frequency.
struct PEAK_EVENT_SUPPORTING_MODULE * PEAK_EVENT_SUPPORTING_MODULE_HANDLE
Definition peak_backend.h:477
struct PEAK_REMOTE_DEVICE * PEAK_REMOTE_DEVICE_HANDLE
Definition peak_backend.h:393
PEAK_C_API PEAK_Device_GetRemoteDevice(PEAK_DEVICE_HANDLE deviceHandle, PEAK_REMOTE_DEVICE_HANDLE *remoteDeviceHandle)
Asks the given device for its remote device.
PEAK_C_API PEAK_Device_GetNumDataStreams(PEAK_DEVICE_HANDLE deviceHandle, size_t *numDataStreams)
Asks the given device for its number of data streams.
PEAK_C_API PEAK_Device_Destruct(PEAK_DEVICE_HANDLE deviceHandle)
Delete the given device.
PEAK_C_API PEAK_Device_GetUserDefinedName(PEAK_DEVICE_HANDLE deviceHandle, char *userDefinedName, size_t *userDefinedNameSize)
Asks the given device for its user-defined name.
PEAK_C_API PEAK_Device_GetAccessStatus(PEAK_DEVICE_HANDLE deviceHandle, PEAK_DEVICE_ACCESS_STATUS *accessStatus)
Asks the given device for its access status.
PEAK_C_API PEAK_Device_GetInfo(PEAK_DEVICE_HANDLE deviceHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given device for an information based on a specific command.
PEAK_C_API PEAK_Device_ToEventSupportingModule(PEAK_DEVICE_HANDLE deviceHandle, PEAK_EVENT_SUPPORTING_MODULE_HANDLE *eventSupportingModuleHandle)
Casts the given device to an event-supporting module.
PEAK_C_API PEAK_Device_GetDataStream(PEAK_DEVICE_HANDLE deviceHandle, size_t index, PEAK_DATA_STREAM_DESCRIPTOR_HANDLE *dataStreamDescriptorHandle)
Asks the given device for the data stream descriptor with the given index.
PEAK_C_API PEAK_Device_GetVersion(PEAK_DEVICE_HANDLE deviceHandle, char *version, size_t *versionSize)
Asks the given device for its version.
PEAK_C_API PEAK_Device_GetTLType(PEAK_DEVICE_HANDLE deviceHandle, char *tlType, size_t *tlTypeSize)
Asks the given device for its TL type.
struct PEAK_DEVICE * PEAK_DEVICE_HANDLE
Definition peak_backend.h:389
int32_t PEAK_DEVICE_ACCESS_STATUS
Definition peak_backend.h:134
PEAK_C_API PEAK_Device_GetID(PEAK_DEVICE_HANDLE deviceHandle, char *id, size_t *idSize)
Asks the given device for its ID.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16
The struct returned by all raw information functions.
Definition peak_common_structs.hpp:25