IDS peak genericC++  v1.4.3
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;
74  std::string Name() const;
84  std::string VendorName() const;
94  std::string ModelName() const;
104  std::string Version() const;
106  std::string TLType() const;
116  std::string ModuleName() const;
126  Endianness DataEndianness() const;
137  bool IsReadable() const;
148  bool IsWritable() const;
159  bool IsAvailable() const;
170  bool IsImplemented() const;
171 
185  std::vector<uint8_t> Read(uint64_t address, size_t numBytes) const;
198  void Write(uint64_t address, const std::vector<uint8_t>& bytes) const;
208  std::vector<std::shared_ptr<PortURL>> URLs() const;
209 
210 private:
211  friend class ClassCreator<Port>;
212  explicit Port(PEAK_PORT_HANDLE portHandle);
213  PEAK_PORT_HANDLE m_backendHandle;
214 
215  void Initialize() const override;
216  mutable std::vector<std::shared_ptr<PortURL>> m_portURLs;
217 };
218 
219 } /* namespace core */
220 } /* namespace peak */
221 
223 
224 
225 /* Implementation */
226 namespace peak
227 {
228 namespace core
229 {
230 
231 inline Port::Port(PEAK_PORT_HANDLE portHandle)
232  : m_backendHandle(portHandle)
233 {}
234 
235 inline RawInformation Port::Info(int32_t infoCommand) const
236 {
237  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
238  return PEAK_C_ABI_PREFIX PEAK_Port_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
239  });
240 }
241 
242 inline std::string Port::ID() const
243 {
244  return QueryStringFromCInterfaceFunction(
245  [&](char* id, size_t* idSize) { return PEAK_C_ABI_PREFIX PEAK_Port_GetID(m_backendHandle, id, idSize); });
246 }
247 
248 inline std::string Port::Name() const
249 {
250  return QueryStringFromCInterfaceFunction([&](char* name, size_t* nameSize) {
251  return PEAK_C_ABI_PREFIX PEAK_Port_GetName(m_backendHandle, name, nameSize);
252  });
253 }
254 
255 inline std::string Port::VendorName() const
256 {
257  return QueryStringFromCInterfaceFunction([&](char* vendorName, size_t* vendorNameSize) {
258  return PEAK_C_ABI_PREFIX PEAK_Port_GetVendorName(m_backendHandle, vendorName, vendorNameSize);
259  });
260 }
261 
262 inline std::string Port::ModelName() const
263 {
264  return QueryStringFromCInterfaceFunction([&](char* modelName, size_t* modelNameSize) {
265  return PEAK_C_ABI_PREFIX PEAK_Port_GetModelName(m_backendHandle, modelName, modelNameSize);
266  });
267 }
268 
269 inline std::string Port::Version() const
270 {
271  return QueryStringFromCInterfaceFunction([&](char* version, size_t* versionSize) {
272  return PEAK_C_ABI_PREFIX PEAK_Port_GetVersion(m_backendHandle, version, versionSize);
273  });
274 }
275 
276 inline std::string Port::TLType() const
277 {
278  return QueryStringFromCInterfaceFunction([&](char* tlType, size_t* tlTypeSize) {
279  return PEAK_C_ABI_PREFIX PEAK_Port_GetTLType(m_backendHandle, tlType, tlTypeSize);
280  });
281 }
282 
283 inline std::string Port::ModuleName() const
284 {
285  return QueryStringFromCInterfaceFunction([&](char* moduleName, size_t* moduleNameSize) {
286  return PEAK_C_ABI_PREFIX PEAK_Port_GetModuleName(m_backendHandle, moduleName, moduleNameSize);
287  });
288 }
289 
291 {
292  return static_cast<Endianness>(
293  QueryNumericFromCInterfaceFunction<PEAK_ENDIANNESS>([&](PEAK_ENDIANNESS* dataEndianness) {
294  return PEAK_C_ABI_PREFIX PEAK_Port_GetDataEndianness(m_backendHandle, dataEndianness);
295  }));
296 }
297 
298 inline bool Port::IsReadable() const
299 {
300  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isReadable) {
301  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsReadable(m_backendHandle, isReadable);
302  }) > 0;
303 }
304 
305 inline bool Port::IsWritable() const
306 {
307  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isWritable) {
308  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsWritable(m_backendHandle, isWritable);
309  }) > 0;
310 }
311 
312 inline bool Port::IsAvailable() const
313 {
314  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isAvailable) {
315  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsAvailable(m_backendHandle, isAvailable);
316  }) > 0;
317 }
318 
319 inline bool Port::IsImplemented() const
320 {
321  return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](PEAK_BOOL8* isImplemented) {
322  return PEAK_C_ABI_PREFIX PEAK_Port_GetIsImplemented(m_backendHandle, isImplemented);
323  }) > 0;
324 }
325 
326 inline std::vector<uint8_t> Port::Read(uint64_t address, size_t numBytes) const
327 {
328  std::vector<uint8_t> bytes(numBytes);
329  ExecuteAndMapReturnCodes(
330  [&] { return PEAK_C_ABI_PREFIX PEAK_Port_Read(m_backendHandle, address, bytes.data(), bytes.size()); });
331 
332  return bytes;
333 }
334 
335 inline void Port::Write(uint64_t address, const std::vector<uint8_t>& bytes) const
336 {
337  ExecuteAndMapReturnCodes(
338  [&] { return PEAK_C_ABI_PREFIX PEAK_Port_Write(m_backendHandle, address, bytes.data(), bytes.size()); });
339 }
340 
341 inline std::vector<std::shared_ptr<PortURL>> Port::URLs() const
342 {
343  InitializeIfNecessary();
344  return m_portURLs;
345 }
346 
347 inline void Port::Initialize() const
348 {
349  auto numUrls = QueryNumericFromCInterfaceFunction<size_t>(
350  [&](size_t* _numUrls) { return PEAK_C_ABI_PREFIX PEAK_Port_GetNumURLs(m_backendHandle, _numUrls); });
351 
352  std::vector<std::shared_ptr<PortURL>> urls;
353  for (size_t x = 0; x < numUrls; ++x)
354  {
355  auto portUrlHandle = QueryNumericFromCInterfaceFunction<PEAK_PORT_URL_HANDLE>(
356  [&](PEAK_PORT_URL_HANDLE* _portUrlHandle) {
357  return PEAK_C_ABI_PREFIX PEAK_Port_GetURL(m_backendHandle, x, _portUrlHandle);
358  });
359 
360  urls.emplace_back(
361  std::make_shared<ClassCreator<PortURL>>(portUrlHandle, std::const_pointer_cast<Port>(shared_from_this())));
362  }
363 
364  m_portURLs = urls;
365 }
366 
367 } /* namespace core */
368 } /* namespace peak */
Endianness DataEndianness() const
Returns the data endianness.
Definition: peak_port.hpp:290
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:312
std::string Version() const
Returns the version.
Definition: peak_port.hpp:269
struct PEAK_PORT_URL * PEAK_PORT_URL_HANDLE
Definition: peak_backend.h:453
bool IsWritable() const
Checks whether the port is writable.
Definition: peak_port.hpp:305
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:341
std::string ModelName() const
Returns the model name.
Definition: peak_port.hpp:262
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:255
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:335
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:319
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:326
struct PEAK_PORT * PEAK_PORT_HANDLE
Definition: peak_backend.h:449
#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:283
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:248
bool IsReadable() const
Checks whether the port is readable.
Definition: peak_port.hpp:298
std::string ID() const
Returns the ID.
Definition: peak_port.hpp:242
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:276
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:235