IDS peak genericC++  v1.4.0
peak_device.hpp
Go to the documentation of this file.
1 
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 
29 namespace peak
30 {
31 namespace core
32 {
33 
34 class Interface;
35 
52 class Device
53  : public EventSupportingModule
54  , public std::enable_shared_from_this<Device>
55 {
56 public:
57  Device() = delete;
58  ~Device() override;
59  Device(const Device& other) = delete;
60  Device& operator=(const Device& other) = delete;
61  Device(Device&& other) = delete;
62  Device& operator=(Device&& other) = delete;
63 
65  std::string Key() const;
66 
68  RawInformation Info(int32_t infoCommand) const;
70  std::string ID() const;
72  std::string DisplayName() const;
74  std::string VendorName() const;
76  std::string ModelName() const;
78  std::string Version() const;
80  std::string TLType() const;
82  std::string UserDefinedName() const;
84  std::string SerialNumber() const;
88  uint64_t TimestampTickFrequency() const;
89 
102  std::shared_ptr<class RemoteDevice> RemoteDevice() const;
112  std::vector<std::shared_ptr<DataStreamDescriptor>> DataStreams() const;
114  std::shared_ptr<Interface> ParentInterface() const;
115 
116 private:
117  PEAK_MODULE_HANDLE ModuleHandle() const override;
118  PEAK_EVENT_SUPPORTING_MODULE_HANDLE EventSupportingModuleHandle() const override;
119 
120  friend ClassCreator<Device>;
121  Device(PEAK_DEVICE_HANDLE deviceHandle, const std::weak_ptr<Interface>& parentInterface);
122  PEAK_DEVICE_HANDLE m_backendHandle;
123 
124  std::weak_ptr<Interface> m_parentInterface;
125 
126  void Initialize() const override;
127  mutable std::vector<std::shared_ptr<DataStreamDescriptor>> m_dataStreams;
128  mutable std::shared_ptr<class RemoteDevice> m_remoteDevice;
129 
130  std::string m_key;
131 };
132 
133 } /* namespace core */
134 } /* namespace peak */
135 
136 /* Implementation */
137 namespace peak
138 {
139 namespace core
140 {
141 
142 inline Device::Device(PEAK_DEVICE_HANDLE deviceHandle, const std::weak_ptr<Interface>& parentInterface)
143  : m_backendHandle(deviceHandle)
144  , m_parentInterface(parentInterface)
145  , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
146  return PEAK_C_ABI_PREFIX PEAK_Device_GetKey(deviceHandle, key, keySize);
147  }))
148 {}
149 
151 {
152  (void)PEAK_C_ABI_PREFIX PEAK_Device_Destruct(m_backendHandle);
153 }
154 
155 inline std::string Device::Key() const
156 {
157  return m_key;
158 }
159 
160 inline RawInformation Device::Info(int32_t infoCommand) const
161 {
162  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
163  return PEAK_C_ABI_PREFIX PEAK_Device_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
164  });
165 }
166 
167 inline std::string Device::ID() const
168 {
169  return QueryStringFromCInterfaceFunction([&](char* id, size_t* idSize) {
170  return PEAK_C_ABI_PREFIX PEAK_Device_GetID(m_backendHandle, id, idSize);
171  });
172 }
173 
174 inline std::string Device::DisplayName() const
175 {
176  return QueryStringFromCInterfaceFunction([&](char* displayName, size_t* displayNameSize) {
177  return PEAK_C_ABI_PREFIX PEAK_Device_GetDisplayName(m_backendHandle, displayName, displayNameSize);
178  });
179 }
180 
181 inline std::string Device::VendorName() const
182 {
183  return QueryStringFromCInterfaceFunction([&](char* vendorName, size_t* vendorNameSize) {
184  return PEAK_C_ABI_PREFIX PEAK_Device_GetVendorName(m_backendHandle, vendorName, vendorNameSize);
185  });
186 }
187 
188 inline std::string Device::ModelName() const
189 {
190  return QueryStringFromCInterfaceFunction([&](char* modelName, size_t* modelNameSize) {
191  return PEAK_C_ABI_PREFIX PEAK_Device_GetModelName(m_backendHandle, modelName, modelNameSize);
192  });
193 }
194 
195 inline std::string Device::Version() const
196 {
197  return QueryStringFromCInterfaceFunction([&](char* version, size_t* versionSize) {
198  return PEAK_C_ABI_PREFIX PEAK_Device_GetVersion(m_backendHandle, version, versionSize);
199  });
200 }
201 
202 inline std::string Device::TLType() const
203 {
204  return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
205  return PEAK_C_ABI_PREFIX PEAK_Device_GetTLType(m_backendHandle, tlType, tlTypeSize);
206  });
207 }
208 
209 inline std::string Device::UserDefinedName() const
210 {
211  return QueryStringFromCInterfaceFunction([&](char* userDefinedName, size_t* userDefinedNameSize) {
213  m_backendHandle, userDefinedName, userDefinedNameSize);
214  });
215 }
216 
217 inline std::string Device::SerialNumber() const
218 {
219  return QueryStringFromCInterfaceFunction([&](char* serialNumber, size_t* serialNumberSize) {
220  return PEAK_C_ABI_PREFIX PEAK_Device_GetSerialNumber(m_backendHandle, serialNumber, serialNumberSize);
221  });
222 }
223 
225 {
226  return static_cast<DeviceAccessStatus>(QueryNumericFromCInterfaceFunction<PEAK_DEVICE_ACCESS_STATUS>(
227  [&](PEAK_DEVICE_ACCESS_STATUS* accessStatus) {
228  return PEAK_C_ABI_PREFIX PEAK_Device_GetAccessStatus(m_backendHandle, accessStatus);
229  }));
230 }
231 
232 inline uint64_t Device::TimestampTickFrequency() const
233 {
234  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* timestampTickFrequency) {
235  return PEAK_C_ABI_PREFIX PEAK_Device_GetTimestampTickFrequency(m_backendHandle, timestampTickFrequency);
236  });
237 }
238 
239 inline std::shared_ptr<class RemoteDevice> Device::RemoteDevice() const
240 {
241  InitializeIfNecessary();
242 
243  return m_remoteDevice;
244 }
245 
246 inline std::vector<std::shared_ptr<DataStreamDescriptor>> Device::DataStreams() const
247 {
248  InitializeIfNecessary();
249 
250  return m_dataStreams;
251 }
252 
253 inline std::shared_ptr<Interface> Device::ParentInterface() const
254 {
255  return LockOrThrow(m_parentInterface);
256 }
257 
258 inline PEAK_MODULE_HANDLE Device::ModuleHandle() const
259 {
260  auto moduleHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_HANDLE>(
261  [&](PEAK_MODULE_HANDLE* _moduleHandle) {
262  return PEAK_C_ABI_PREFIX PEAK_Device_ToModule(m_backendHandle, _moduleHandle);
263  });
264 
265  return moduleHandle;
266 }
267 
268 inline PEAK_EVENT_SUPPORTING_MODULE_HANDLE Device::EventSupportingModuleHandle() const
269 {
270  auto eventSupportingModuleHandle = QueryNumericFromCInterfaceFunction<PEAK_EVENT_SUPPORTING_MODULE_HANDLE>(
271  [&](PEAK_EVENT_SUPPORTING_MODULE_HANDLE* _eventSupportingModuleHandle) {
273  m_backendHandle, _eventSupportingModuleHandle);
274  });
275 
276  return eventSupportingModuleHandle;
277 }
278 
279 inline void Device::Initialize() const
280 {
281  EventSupportingModule::Initialize(); // init data of parent classes (i.e. Module) as well
282 
283  // init data streams
284  auto numDataStreams = QueryNumericFromCInterfaceFunction<size_t>([&](size_t* _numDataStreams) {
285  return PEAK_C_ABI_PREFIX PEAK_Device_GetNumDataStreams(m_backendHandle, _numDataStreams);
286  });
287 
288  std::vector<std::shared_ptr<DataStreamDescriptor>> dataStreams;
289  for (size_t x = 0; x < numDataStreams; ++x)
290  {
291  auto dataStreamDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_DATA_STREAM_DESCRIPTOR_HANDLE>(
292  [&](PEAK_DATA_STREAM_DESCRIPTOR_HANDLE* _dataStreamDescriptorHandle) {
294  m_backendHandle, x, _dataStreamDescriptorHandle);
295  });
296 
297  dataStreams.emplace_back(std::make_shared<ClassCreator<DataStreamDescriptor>>(
298  dataStreamDescriptorHandle, std::const_pointer_cast<Device>(shared_from_this())));
299  }
300 
301  m_dataStreams = dataStreams;
302 
303  // init remote device
304  auto remoteDeviceHandle = QueryNumericFromCInterfaceFunction<PEAK_REMOTE_DEVICE_HANDLE>(
305  [&](PEAK_REMOTE_DEVICE_HANDLE* _remoteDeviceHandle) {
306  return PEAK_C_ABI_PREFIX PEAK_Device_GetRemoteDevice(m_backendHandle, _remoteDeviceHandle);
307  });
308 
309  m_remoteDevice = std::make_shared<ClassCreator<peak::core::RemoteDevice>>(
310  remoteDeviceHandle, std::const_pointer_cast<Device>(shared_from_this()));
311 }
312 
313 } /* namespace core */
314 } /* namespace peak */
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_GetAccessStatus(PEAK_DEVICE_HANDLE deviceHandle, PEAK_DEVICE_ACCESS_STATUS *accessStatus)
Asks the given device for its access status.
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_GetModelName(PEAK_DEVICE_HANDLE deviceHandle, char *modelName, size_t *modelNameSize)
Asks the given device for its model name.
std::string UserDefinedName() const
Returns the user defined name.
Definition: peak_device.hpp:209
std::string ModelName() const
Returns the model name.
Definition: peak_device.hpp:188
PEAK_C_API PEAK_Device_GetKey(PEAK_DEVICE_HANDLE deviceHandle, char *key, size_t *keySize)
Asks the given device for its key.
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
struct PEAK_EVENT_SUPPORTING_MODULE * PEAK_EVENT_SUPPORTING_MODULE_HANDLE
Definition: peak_backend.h:457
DeviceAccessStatus AccessStatus() const
Returns the access status.
Definition: peak_device.hpp:224
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_GetUserDefinedName(PEAK_DEVICE_HANDLE deviceHandle, char *userDefinedName, size_t *userDefinedNameSize)
Asks the given device for its user-defined name.
DeviceAccessStatus
Current accessibility of the device.
Definition: peak_common_device_enums.hpp:24
~Device() override
Definition: peak_device.hpp:150
PEAK_C_API PEAK_Device_GetVersion(PEAK_DEVICE_HANDLE deviceHandle, char *version, size_t *versionSize)
Asks the given device for its version.
std::string ID() const
Returns the ID.
Definition: peak_device.hpp:167
std::string Key() const
Returns the unique key.
Definition: peak_device.hpp:155
Represents a GenTL Device module, i.e. a local virtual Device proxy for the actual hardware RemoteDev...
Definition: peak_device.hpp:52
PEAK_C_API PEAK_Device_GetRemoteDevice(PEAK_DEVICE_HANDLE deviceHandle, PEAK_REMOTE_DEVICE_HANDLE *remoteDeviceHandle)
Asks the given device for its remote device.
std::string Version() const
Returns the version.
Definition: peak_device.hpp:195
struct PEAK_REMOTE_DEVICE * PEAK_REMOTE_DEVICE_HANDLE
Definition: peak_backend.h:373
PEAK_C_API PEAK_Device_Destruct(PEAK_DEVICE_HANDLE deviceHandle)
Delete the given device.
std::string DisplayName() const
Returns the display name.
Definition: peak_device.hpp:174
PEAK_C_API PEAK_Device_GetID(PEAK_DEVICE_HANDLE deviceHandle, char *id, size_t *idSize)
Asks the given device for its ID.
PEAK_C_API PEAK_Device_GetNumDataStreams(PEAK_DEVICE_HANDLE deviceHandle, size_t *numDataStreams)
Asks the given device for its number of data streams.
std::string TLType() const
Returns the TL (transport layer) type.
Definition: peak_device.hpp:202
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_GetTimestampTickFrequency(PEAK_DEVICE_HANDLE deviceHandle, uint64_t *timestampTickFrequency)
Asks the given device for its timestamp tick frequency.
std::string SerialNumber() const
Returns the serial number.
Definition: peak_device.hpp:217
std::shared_ptr< class RemoteDevice > RemoteDevice() const
Returns the remote device of the device.
Definition: peak_device.hpp:239
std::shared_ptr< Interface > ParentInterface() const
Returns the parent interface.
Definition: peak_device.hpp:253
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
std::string VendorName() const
Returns the vendor name.
Definition: peak_device.hpp:181
int32_t PEAK_DEVICE_ACCESS_STATUS
Definition: peak_backend.h:117
uint64_t TimestampTickFrequency() const
Returns the timestamp tick frequency.
Definition: peak_device.hpp:232
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_GetTLType(PEAK_DEVICE_HANDLE deviceHandle, char *tlType, size_t *tlTypeSize)
Asks the given device for its TL type.
The struct returned by all raw information functions.
Definition: peak_common_structs.hpp:24
std::vector< std::shared_ptr< DataStreamDescriptor > > DataStreams() const
Returns the data stream list of the device.
Definition: peak_device.hpp:246
struct PEAK_MODULE * PEAK_MODULE_HANDLE
Definition: peak_backend.h:401
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.
struct PEAK_DEVICE * PEAK_DEVICE_HANDLE
Definition: peak_backend.h:369
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:377
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_device.hpp:160
The base class for all modules being able to raise events.
Definition: peak_event_supporting_module.hpp:33
Device & operator=(const Device &other)=delete