IDS peak genericC++  v1.7.0
peak_port.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
17 #include <peak/dll_interface/peak_dll_interface_util.hpp>
18 #include <peak/error_handling/peak_error_handling.hpp>
20 
21 #include <cstddef>
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 
28 namespace peak
29 {
30 namespace core
31 {
32 
33 class PortURL;
34 
41 class Port
42  : public InitOnce
43  , public std::enable_shared_from_this<Port>
44 {
45 public:
46  Port() = delete;
47  ~Port() = default;
48  Port(const class Port& other) = delete;
49  Port& operator=(const class Port& other) = delete;
50  Port(class Port&& other) = delete;
51  Port& operator=(class Port&& other) = delete;
52 
54  RawInformation Info(int32_t infoCommand) const;
64  std::string ID() const;
65 
75  std::string Name() const;
76 
86  std::string VendorName() const;
87 
97  std::string ModelName() const;
98 
108  std::string Version() const;
109 
111  std::string TLType() const;
112 
122  std::string ModuleName() const;
123 
133  Endianness DataEndianness() const;
134 
145  bool IsReadable() const;
146 
157  bool IsWritable() const;
158 
169  bool IsAvailable() const;
170 
181  bool IsImplemented() const;
182 
197  std::vector<uint8_t> Read(uint64_t address, size_t numBytes) const;
198 
212  void Write(uint64_t address, const std::vector<uint8_t>& bytes) const;
213 
224  std::vector<std::shared_ptr<PortURL>> URLs() const;
225 
226 private:
227  friend class ClassCreator<Port>;
228  explicit Port(PEAK_PORT_HANDLE portHandle);
229  PEAK_PORT_HANDLE m_backendHandle;
230 
231  void Initialize() const override;
232  mutable std::vector<std::shared_ptr<PortURL>> m_portURLs;
233 };
234 
235 } /* namespace core */
236 } /* namespace peak */
237 
239 
240 
241 /* Implementation */
242 namespace peak
243 {
244 namespace core
245 {
246 
247 inline Port::Port(PEAK_PORT_HANDLE portHandle)
248  : m_backendHandle(portHandle)
249 {}
250 
251 inline RawInformation Port::Info(int32_t infoCommand) const
252 {
253  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
254  return PEAK_C_ABI_PREFIX PEAK_Port_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
255  });
256 }
257 
258 inline std::string Port::ID() const
259 {
260  return QueryStringFromCInterfaceFunction(
261  [&](char* id, size_t* idSize) { return PEAK_C_ABI_PREFIX PEAK_Port_GetID(m_backendHandle, id, idSize); });
262 }
263 
264 inline std::string Port::Name() const
265 {
266  return QueryStringFromCInterfaceFunction([&](char* name, size_t* nameSize) {
267  return PEAK_C_ABI_PREFIX PEAK_Port_GetName(m_backendHandle, name, nameSize);
268  });
269 }
270 
271 inline std::string Port::VendorName() const
272 {
273  return QueryStringFromCInterfaceFunction([&](char* vendorName, size_t* vendorNameSize) {
274  return PEAK_C_ABI_PREFIX PEAK_Port_GetVendorName(m_backendHandle, vendorName, vendorNameSize);
275  });
276 }
277 
278 inline std::string Port::ModelName() const
279 {
280  return QueryStringFromCInterfaceFunction([&](char* modelName, size_t* modelNameSize) {
281  return PEAK_C_ABI_PREFIX PEAK_Port_GetModelName(m_backendHandle, modelName, modelNameSize);
282  });
283 }
284 
285 inline std::string Port::Version() const
286 {
287  return QueryStringFromCInterfaceFunction([&](char* version, size_t* versionSize) {
288  return PEAK_C_ABI_PREFIX PEAK_Port_GetVersion(m_backendHandle, version, versionSize);
289  });
290 }
291 
292 inline std::string Port::TLType() const
293 {
294  return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
295  return PEAK_C_ABI_PREFIX PEAK_Port_GetTLType(m_backendHandle, tlType, tlTypeSize);
296  });
297 }
298 
299 inline std::string Port::ModuleName() const
300 {
301  return QueryStringFromCInterfaceFunction([&](char* moduleName, size_t* moduleNameSize) {
302  return PEAK_C_ABI_PREFIX PEAK_Port_GetModuleName(m_backendHandle, moduleName, moduleNameSize);
303  });
304 }
305 
307 {
308  return static_cast<Endianness>(
309  QueryNumericFromCInterfaceFunction<PEAK_ENDIANNESS>([&](PEAK_ENDIANNESS* dataEndianness) {
310  return PEAK_C_ABI_PREFIX PEAK_Port_GetDataEndianness(m_backendHandle, dataEndianness);
311  }));
312 }
313 
314 inline bool Port::IsReadable() const
315 {
316  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isReadable) {
317  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsReadable(m_backendHandle, isReadable);
318  }) > 0;
319 }
320 
321 inline bool Port::IsWritable() const
322 {
323  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isWritable) {
324  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsWritable(m_backendHandle, isWritable);
325  }) > 0;
326 }
327 
328 inline bool Port::IsAvailable() const
329 {
330  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isAvailable) {
331  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsAvailable(m_backendHandle, isAvailable);
332  }) > 0;
333 }
334 
335 inline bool Port::IsImplemented() const
336 {
337  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isImplemented) {
338  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsImplemented(m_backendHandle, isImplemented);
339  }) > 0;
340 }
341 
342 inline std::vector<uint8_t> Port::Read(uint64_t address, size_t numBytes) const
343 {
344  std::vector<uint8_t> bytes(numBytes);
345  ExecuteAndMapReturnCodes(
346  [&] { return PEAK_C_ABI_PREFIX PEAK_Port_Read(m_backendHandle, address, bytes.data(), bytes.size()); });
347 
348  return bytes;
349 }
350 
351 inline void Port::Write(uint64_t address, const std::vector<uint8_t>& bytes) const
352 {
353  ExecuteAndMapReturnCodes(
354  [&] { return PEAK_C_ABI_PREFIX PEAK_Port_Write(m_backendHandle, address, bytes.data(), bytes.size()); });
355 }
356 
357 inline std::vector<std::shared_ptr<PortURL>> Port::URLs() const
358 {
359  InitializeIfNecessary();
360  return m_portURLs;
361 }
362 
363 inline void Port::Initialize() const
364 {
365  auto numUrls = QueryNumericFromCInterfaceFunction<size_t>(
366  [&](size_t* _numUrls) { return PEAK_C_ABI_PREFIX PEAK_Port_GetNumURLs(m_backendHandle, _numUrls); });
367 
368  std::vector<std::shared_ptr<PortURL>> urls;
369  for (size_t x = 0; x < numUrls; ++x)
370  {
371  auto portUrlHandle = QueryNumericFromCInterfaceFunction<PEAK_PORT_URL_HANDLE>(
372  [&](PEAK_PORT_URL_HANDLE* _portUrlHandle) {
373  return PEAK_C_ABI_PREFIX PEAK_Port_GetURL(m_backendHandle, x, _portUrlHandle);
374  });
375 
376  urls.emplace_back(
377  std::make_shared<ClassCreator<PortURL>>(portUrlHandle, std::const_pointer_cast<Port>(shared_from_this())));
378  }
379 
380  m_portURLs = urls;
381 }
382 
383 } /* namespace core */
384 } /* namespace peak */
Endianness DataEndianness() const
Returns the data endianness.
Definition: peak_port.hpp:306
PEAK_C_API PEAK_Port_GetID(PEAK_PORT_HANDLE portHandle, char *id, size_t *idSize)
Asks the given port for its ID.
bool IsAvailable() const
Checks whether the port is available.
Definition: peak_port.hpp:328
std::string Version() const
Returns the version.
Definition: peak_port.hpp:285
struct PEAK_PORT_URL * PEAK_PORT_URL_HANDLE
Definition: peak_backend.h:455
bool IsWritable() const
Checks whether the port is writable.
Definition: peak_port.hpp:321
PEAK_C_API PEAK_Port_GetVersion(PEAK_PORT_HANDLE portHandle, char *version, size_t *versionSize)
Asks the given port for its version.
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
PEAK_C_API PEAK_Port_GetModelName(PEAK_PORT_HANDLE portHandle, char *modelName, size_t *modelNameSize)
Asks the given port for its model name.
std::vector< std::shared_ptr< PortURL > > URLs() const
Returns the URLs.
Definition: peak_port.hpp:357
std::string ModelName() const
Returns the model name.
Definition: peak_port.hpp:278
Endianness
Endianness of pixel data in a Buffer or the data in a Port.
Definition: peak_common_enums.hpp:27
std::string VendorName() const
Returns the vendor name.
Definition: peak_port.hpp:271
void Write(uint64_t address, const std::vector< uint8_t > &bytes) const
Writes a given amount of bytes at a given address.
Definition: peak_port.hpp:351
int32_t PEAK_ENDIANNESS
Definition: peak_backend.h:155
PEAK_C_API PEAK_Port_GetURL(PEAK_PORT_HANDLE portHandle, size_t index, PEAK_PORT_URL_HANDLE *portUrlHandle)
Asks the given port for the URL with the given index.
PEAK_C_API PEAK_Port_GetNumURLs(PEAK_PORT_HANDLE portHandle, size_t *numUrls)
Asks the given port for its number of URLs.
PEAK_C_API PEAK_Port_Write(PEAK_PORT_HANDLE portHandle, uint64_t address, const uint8_t *bytesToWrite, size_t bytesToWriteSize)
Tells the given port to write the given amount of bytes at the given address.
PEAK_C_API PEAK_Port_GetIsReadable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isReadable)
Asks the given port whether it is readable.
Represents a GenTL port.
Definition: peak_port.hpp:41
PEAK_C_API PEAK_Port_Read(PEAK_PORT_HANDLE portHandle, uint64_t address, uint8_t *bytesToRead, size_t bytesToReadSize)
Tells the given port to read the given amount of bytes at the given address.
PEAK_C_API PEAK_Port_GetDataEndianness(PEAK_PORT_HANDLE portHandle, PEAK_ENDIANNESS *dataEndianness)
Asks the given port for its data endianness.
bool IsImplemented() const
Checks whether the port is implemented.
Definition: peak_port.hpp:335
Port & operator=(const class Port &other)=delete
std::vector< uint8_t > Read(uint64_t address, size_t numBytes) const
Reads a given amount of bytes at a given address.
Definition: peak_port.hpp:342
struct PEAK_PORT * PEAK_PORT_HANDLE
Definition: peak_backend.h:451
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_Port_GetName(PEAK_PORT_HANDLE portHandle, char *name, size_t *nameSize)
Asks the given port for its name.
PEAK_C_API PEAK_Port_GetIsImplemented(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isImplemented)
Asks the given port whether it is implemented.
PEAK_C_API PEAK_Port_GetVendorName(PEAK_PORT_HANDLE portHandle, char *vendorName, size_t *vendorNameSize)
Asks the given port for its vendor name.
PEAK_C_API PEAK_Port_GetInfo(PEAK_PORT_HANDLE portHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given port for an information based on a specific command.
std::string ModuleName() const
Returns the module name.
Definition: peak_port.hpp:299
The struct returned by all raw information functions.
Definition: peak_common_structs.hpp:24
std::string Name() const
Returns the name.
Definition: peak_port.hpp:264
bool IsReadable() const
Checks whether the port is readable.
Definition: peak_port.hpp:314
std::string ID() const
Returns the ID.
Definition: peak_port.hpp:258
PEAK_C_API PEAK_Port_GetIsAvailable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isAvailable)
Asks the given port whether it is available.
PEAK_C_API PEAK_Port_GetIsWritable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isWritable)
Asks the given port whether it is writable.
std::string TLType() const
Returns the TL (transport layer) type.
Definition: peak_port.hpp:292
PEAK_C_API PEAK_Port_GetModuleName(PEAK_PORT_HANDLE portHandle, char *moduleName, size_t *moduleNameSize)
Asks the given port for its module name.
PEAK_C_API PEAK_Port_GetTLType(PEAK_PORT_HANDLE portHandle, char *tlType, size_t *tlTypeSize)
Asks the given port for its TL type.
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_port.hpp:251