IDS peak genericC++  v1.7.1
peak_port_url.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
16 #include <peak/dll_interface/peak_dll_interface_util.hpp>
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 
35 enum class PortURLScheme
36 {
37  Local,
38  HTTP,
39  File,
40 
41  Custom = 1000
42 };
43 
44 class Port;
45 
52 class PortURL
53 {
54 public:
55  PortURL() = delete;
56  ~PortURL() = default;
57  PortURL(const PortURL& other) = delete;
58  PortURL& operator=(const PortURL& other) = delete;
59  PortURL(PortURL&& other) = delete;
60  PortURL& operator=(PortURL&& other) = delete;
61 
63  RawInformation Info(int32_t infoCommand) const;
64 
74  std::string URL() const;
75 
85  PortURLScheme Scheme() const;
86 
96  std::string FileName() const;
97 
107  uint64_t FileRegisterAddress() const;
108 
118  uint64_t FileSize() const;
119 
129  std::vector<uint8_t> FileSHA1Hash() const;
130 
140  int32_t FileVersionMajor() const;
141 
151  int32_t FileVersionMinor() const;
152 
162  int32_t FileVersionSubminor() const;
163 
173  int32_t FileSchemaVersionMajor() const;
174 
184  int32_t FileSchemaVersionMinor() const;
185 
195  std::shared_ptr<class Port> ParentPort() const;
196 
197 private:
198  friend ClassCreator<PortURL>;
199  explicit PortURL(PEAK_PORT_URL_HANDLE portUrlHandle, const std::weak_ptr<Port>& parentPort);
200  PEAK_PORT_URL_HANDLE m_backendHandle;
201 
202  std::weak_ptr<Port> m_parentPort;
203 };
204 
205 } /* namespace core */
206 } /* namespace peak */
207 
208 #include <peak/port/peak_port.hpp>
209 
210 
211 /* Implementation */
212 namespace peak
213 {
214 namespace core
215 {
216 
217 inline PortURL::PortURL(PEAK_PORT_URL_HANDLE portUrlHandle, const std::weak_ptr<Port>& parentPort)
218  : m_backendHandle(portUrlHandle)
219  , m_parentPort(parentPort)
220 {}
221 
222 inline RawInformation PortURL::Info(int32_t infoCommand) const
223 {
224  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
225  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
226  });
227 }
228 
229 inline std::string PortURL::URL() const
230 {
231  return QueryStringFromCInterfaceFunction([&](char* url, size_t* urlSize) {
232  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetURL(m_backendHandle, url, urlSize);
233  });
234 }
235 
237 {
238  return static_cast<PortURLScheme>(
239  QueryNumericFromCInterfaceFunction<PEAK_PORT_URL_SCHEME>([&](PEAK_PORT_URL_SCHEME* scheme) {
240  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetScheme(m_backendHandle, scheme);
241  }));
242 }
243 
244 inline std::string PortURL::FileName() const
245 {
246  return QueryStringFromCInterfaceFunction([&](char* fileName, size_t* fileNameSize) {
247  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileName(m_backendHandle, fileName, fileNameSize);
248  });
249 }
250 
251 inline uint64_t PortURL::FileRegisterAddress() const
252 {
253  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* fileRegisterAddress) {
254  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileRegisterAddress(m_backendHandle, fileRegisterAddress);
255  });
256 }
257 
258 inline uint64_t PortURL::FileSize() const
259 {
260  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* fileSize) {
261  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileSize(m_backendHandle, fileSize);
262  });
263 }
264 
265 inline std::vector<uint8_t> PortURL::FileSHA1Hash() const
266 {
267  return QueryNumericArrayFromCInterfaceFunction<uint8_t>([&](uint8_t* fileSha1Hash, size_t* fileSha1HashSize) {
268  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileSHA1Hash(m_backendHandle, fileSha1Hash, fileSha1HashSize);
269  });
270 }
271 
272 inline int32_t PortURL::FileVersionMajor() const
273 {
274  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionMajor) {
275  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMajor(m_backendHandle, fileVersionMajor);
276  });
277 }
278 
279 inline int32_t PortURL::FileVersionMinor() const
280 {
281  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionMinor) {
282  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMinor(m_backendHandle, fileVersionMinor);
283  });
284 }
285 
286 inline int32_t PortURL::FileVersionSubminor() const
287 {
288  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionSubminor) {
289  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionSubminor(m_backendHandle, fileVersionSubminor);
290  });
291 }
292 
293 inline int32_t PortURL::FileSchemaVersionMajor() const
294 {
295  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileSchemaVersionMajor) {
296  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMajor(m_backendHandle, fileSchemaVersionMajor);
297  });
298 }
299 
300 inline int32_t PortURL::FileSchemaVersionMinor() const
301 {
302  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileSchemaVersionMinor) {
303  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMinor(m_backendHandle, fileSchemaVersionMinor);
304  });
305 }
306 
307 inline std::shared_ptr<Port> PortURL::ParentPort() const
308 {
309  return m_parentPort.lock();
310 }
311 
312 inline std::string ToString(PortURLScheme entry)
313 {
314  std::string entryString;
315 
316  if (entry == PortURLScheme::Local)
317  {
318  entryString = "Local";
319  }
320  else if (entry == PortURLScheme::HTTP)
321  {
322  entryString = "HTTP";
323  }
324  else if (entry == PortURLScheme::File)
325  {
326  entryString = "File";
327  }
328  else if (entry >= PortURLScheme::Custom)
329  {
330  entryString = "Custom";
331  }
332 
333  return entryString;
334 }
335 
336 } /* namespace core */
337 } /* namespace peak */
int32_t FileVersionMinor() const
Returns the file major version.
Definition: peak_port_url.hpp:279
PortURLScheme Scheme() const
Returns the scheme.
Definition: peak_port_url.hpp:236
Represents a GenTL port URL.
Definition: peak_port_url.hpp:52
int32_t PEAK_PORT_URL_SCHEME
Definition: peak_backend.h:312
PEAK_C_API PEAK_PortURL_GetFileSHA1Hash(PEAK_PORT_URL_HANDLE portUrlHandle, uint8_t *fileSha1Hash, size_t *fileSha1HashSize)
Asks the given port URL for its file SHA1 hash.
struct PEAK_PORT_URL * PEAK_PORT_URL_HANDLE
Definition: peak_backend.h:455
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
std::string ToString(BufferPayloadType entry)
Definition: peak_buffer.hpp:505
int32_t FileSchemaVersionMajor() const
Returns the file schema major version.
Definition: peak_port_url.hpp:293
PEAK_C_API PEAK_PortURL_GetInfo(PEAK_PORT_URL_HANDLE portUrlHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given port URL for an information based on a specific command.
PEAK_C_API PEAK_PortURL_GetScheme(PEAK_PORT_URL_HANDLE portUrlHandle, PEAK_PORT_URL_SCHEME *scheme)
Asks the given port URL for its scheme.
int32_t FileSchemaVersionMinor() const
Returns the file schema minor version.
Definition: peak_port_url.hpp:300
uint64_t FileRegisterAddress() const
Returns the file register address.
Definition: peak_port_url.hpp:251
uint64_t FileSize() const
Returns the file size.
Definition: peak_port_url.hpp:258
int32_t FileVersionSubminor() const
Returns the file subminor version.
Definition: peak_port_url.hpp:286
PEAK_C_API PEAK_PortURL_GetFileVersionMajor(PEAK_PORT_URL_HANDLE portUrlHandle, int32_t *fileVersionMajor)
Asks the given port URL for the major component of its file version.
Represents a GenTL port.
Definition: peak_port.hpp:41
std::vector< uint8_t > FileSHA1Hash() const
Returns the file SHA1 hash.
Definition: peak_port_url.hpp:265
PortURLScheme
Possible URL schemes for the port.
Definition: peak_port_url.hpp:35
std::string FileName() const
Returns the file name.
Definition: peak_port_url.hpp:244
PEAK_C_API PEAK_PortURL_GetFileVersionSubminor(PEAK_PORT_URL_HANDLE portUrlHandle, int32_t *fileVersionSubminor)
Asks the given port URL for the subminor component of its file version.
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_PortURL_GetFileSize(PEAK_PORT_URL_HANDLE portUrlHandle, uint64_t *fileSize)
Asks the given port URL for its file size.
PEAK_C_API PEAK_PortURL_GetURL(PEAK_PORT_URL_HANDLE portUrlHandle, char *url, size_t *urlSize)
Asks the given port URL for its URL string.
PEAK_C_API PEAK_PortURL_GetFileVersionMinor(PEAK_PORT_URL_HANDLE portUrlHandle, int32_t *fileVersionMinor)
Asks the given port URL for the minor component of its file version.
PEAK_C_API PEAK_PortURL_GetFileRegisterAddress(PEAK_PORT_URL_HANDLE portUrlHandle, uint64_t *fileRegisterAddress)
Asks the given port URL for its file register address.
The struct returned by all raw information functions.
Definition: peak_common_structs.hpp:24
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_port_url.hpp:222
PEAK_C_API PEAK_PortURL_GetFileName(PEAK_PORT_URL_HANDLE portUrlHandle, char *fileName, size_t *fileNameSize)
Asks the given port URL for its file name.
std::string URL() const
Returns the URL.
Definition: peak_port_url.hpp:229
int32_t FileVersionMajor() const
Returns the file major version.
Definition: peak_port_url.hpp:272
std::shared_ptr< class Port > ParentPort() const
Returns the parent port.
Definition: peak_port_url.hpp:307