IDS peak genericC++ v1.9.0
Loading...
Searching...
No Matches
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
28namespace peak
29{
30namespace core
31{
32
33class PortURL;
34
41class Port
42 : public InitOnce
43 , public std::enable_shared_from_this<Port>
44{
45public:
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
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
226private:
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 */
242namespace peak
243{
244namespace core
245{
246
247inline Port::Port(PEAK_PORT_HANDLE portHandle)
248 : m_backendHandle(portHandle)
249{}
250
251inline 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
258inline 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
264inline 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
271inline 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
278inline 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
285inline 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
292inline 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
299inline 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
314inline 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
321inline 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
328inline 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
335inline 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
342inline 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
351inline 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
357inline std::vector<std::shared_ptr<PortURL>> Port::URLs() const
358{
359 InitializeIfNecessary();
360 return m_portURLs;
361}
362
363inline 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 */
Represents a GenTL port.
Definition peak_port.hpp:44
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition peak_port.hpp:251
Port(const class Port &other)=delete
std::vector< std::shared_ptr< PortURL > > URLs() const
Returns the URLs.
Definition peak_port.hpp:357
bool IsAvailable() const
Checks whether the port is available.
Definition peak_port.hpp:328
std::string Name() const
Returns the name.
Definition peak_port.hpp:264
std::string ModelName() const
Returns the model name.
Definition peak_port.hpp:278
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
std::string TLType() const
Returns the TL (transport layer) type.
Definition peak_port.hpp:292
std::string ID() const
Returns the ID.
Definition peak_port.hpp:258
std::string Version() const
Returns the version.
Definition peak_port.hpp:285
bool IsImplemented() const
Checks whether the port is implemented.
Definition peak_port.hpp:335
std::string ModuleName() const
Returns the module name.
Definition peak_port.hpp:299
Port & operator=(class Port &&other)=delete
bool IsWritable() const
Checks whether the port is writable.
Definition peak_port.hpp:321
std::string VendorName() const
Returns the vendor name.
Definition peak_port.hpp:271
Endianness DataEndianness() const
Returns the data endianness.
Definition peak_port.hpp:306
Port(class Port &&other)=delete
Port & operator=(const class Port &other)=delete
bool IsReadable() const
Checks whether the port is readable.
Definition peak_port.hpp:314
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
Endianness
Endianness of pixel data in a Buffer or the data in a Port.
Definition peak_common_enums.hpp:28
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33
PEAK_C_API PEAK_Port_GetDataEndianness(PEAK_PORT_HANDLE portHandle, PEAK_ENDIANNESS *dataEndianness)
Asks the given port for its data endianness.
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_GetName(PEAK_PORT_HANDLE portHandle, char *name, size_t *nameSize)
Asks the given port for its name.
PEAK_C_API PEAK_Port_GetID(PEAK_PORT_HANDLE portHandle, char *id, size_t *idSize)
Asks the given port for its ID.
struct PEAK_PORT_URL * PEAK_PORT_URL_HANDLE
Definition peak_backend.h:456
PEAK_C_API PEAK_Port_GetVersion(PEAK_PORT_HANDLE portHandle, char *version, size_t *versionSize)
Asks the given port for its version.
PEAK_C_API PEAK_Port_GetIsAvailable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isAvailable)
Asks the given port whether it is available.
struct PEAK_PORT * PEAK_PORT_HANDLE
Definition peak_backend.h:452
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_GetNumURLs(PEAK_PORT_HANDLE portHandle, size_t *numUrls)
Asks the given port for its number of URLs.
PEAK_C_API PEAK_Port_GetTLType(PEAK_PORT_HANDLE portHandle, char *tlType, size_t *tlTypeSize)
Asks the given port for its TL type.
PEAK_C_API PEAK_Port_GetIsReadable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isReadable)
Asks the given port whether it is readable.
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.
PEAK_C_API PEAK_Port_GetModelName(PEAK_PORT_HANDLE portHandle, char *modelName, size_t *modelNameSize)
Asks the given port for its model name.
int8_t PEAK_BOOL8
Definition peak_backend.h:26
int32_t PEAK_ENDIANNESS
Definition peak_backend.h:155
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_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_GetIsWritable(PEAK_PORT_HANDLE portHandle, PEAK_BOOL8 *isWritable)
Asks the given port whether it is writable.
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_GetModuleName(PEAK_PORT_HANDLE portHandle, char *moduleName, size_t *moduleNameSize)
Asks the given port for its module name.
#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