IDS peak genericC++  v1.4.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;
73  std::string URL() const;
83  PortURLScheme Scheme() const;
93  std::string FileName() const;
103  uint64_t FileRegisterAddress() const;
113  uint64_t FileSize() const;
123  std::vector<uint8_t> FileSHA1Hash() const;
133  int32_t FileVersionMajor() const;
143  int32_t FileVersionMinor() const;
153  int32_t FileVersionSubminor() const;
163  int32_t FileSchemaVersionMajor() const;
173  int32_t FileSchemaVersionMinor() const;
174 
184  std::shared_ptr<class Port> ParentPort() const;
185 
186 private:
187  friend ClassCreator<PortURL>;
188  explicit PortURL(PEAK_PORT_URL_HANDLE portUrlHandle, const std::weak_ptr<Port>& parentPort);
189  PEAK_PORT_URL_HANDLE m_backendHandle;
190 
191  std::weak_ptr<Port> m_parentPort;
192 };
193 
194 } /* namespace core */
195 } /* namespace peak */
196 
197 #include <peak/port/peak_port.hpp>
198 
199 
200 /* Implementation */
201 namespace peak
202 {
203 namespace core
204 {
205 
206 inline PortURL::PortURL(PEAK_PORT_URL_HANDLE portUrlHandle, const std::weak_ptr<Port>& parentPort)
207  : m_backendHandle(portUrlHandle)
208  , m_parentPort(parentPort)
209 {}
210 
211 inline RawInformation PortURL::Info(int32_t infoCommand) const
212 {
213  return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer, size_t* bufferSize) {
214  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetInfo(m_backendHandle, infoCommand, dataType, buffer, bufferSize);
215  });
216 }
217 
218 inline std::string PortURL::URL() const
219 {
220  return QueryStringFromCInterfaceFunction([&](char* url, size_t* urlSize) {
221  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetURL(m_backendHandle, url, urlSize);
222  });
223 }
224 
226 {
227  return static_cast<PortURLScheme>(
228  QueryNumericFromCInterfaceFunction<PEAK_PORT_URL_SCHEME>([&](PEAK_PORT_URL_SCHEME* scheme) {
229  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetScheme(m_backendHandle, scheme);
230  }));
231 }
232 
233 inline std::string PortURL::FileName() const
234 {
235  return QueryStringFromCInterfaceFunction([&](char* fileName, size_t* fileNameSize) {
236  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileName(m_backendHandle, fileName, fileNameSize);
237  });
238 }
239 
240 inline uint64_t PortURL::FileRegisterAddress() const
241 {
242  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* fileRegisterAddress) {
243  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileRegisterAddress(m_backendHandle, fileRegisterAddress);
244  });
245 }
246 
247 inline uint64_t PortURL::FileSize() const
248 {
249  return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* fileSize) {
250  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileSize(m_backendHandle, fileSize);
251  });
252 }
253 
254 inline std::vector<uint8_t> PortURL::FileSHA1Hash() const
255 {
256  return QueryNumericArrayFromCInterfaceFunction<uint8_t>([&](uint8_t* fileSha1Hash, size_t* fileSha1HashSize) {
257  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileSHA1Hash(m_backendHandle, fileSha1Hash, fileSha1HashSize);
258  });
259 }
260 
261 inline int32_t PortURL::FileVersionMajor() const
262 {
263  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionMajor) {
264  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMajor(m_backendHandle, fileVersionMajor);
265  });
266 }
267 
268 inline int32_t PortURL::FileVersionMinor() const
269 {
270  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionMinor) {
271  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMinor(m_backendHandle, fileVersionMinor);
272  });
273 }
274 
275 inline int32_t PortURL::FileVersionSubminor() const
276 {
277  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileVersionSubminor) {
278  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionSubminor(m_backendHandle, fileVersionSubminor);
279  });
280 }
281 
282 inline int32_t PortURL::FileSchemaVersionMajor() const
283 {
284  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileSchemaVersionMajor) {
285  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMajor(m_backendHandle, fileSchemaVersionMajor);
286  });
287 }
288 
289 inline int32_t PortURL::FileSchemaVersionMinor() const
290 {
291  return QueryNumericFromCInterfaceFunction<int32_t>([&](int32_t* fileSchemaVersionMinor) {
292  return PEAK_C_ABI_PREFIX PEAK_PortURL_GetFileVersionMinor(m_backendHandle, fileSchemaVersionMinor);
293  });
294 }
295 
296 inline std::shared_ptr<Port> PortURL::ParentPort() const
297 {
298  return m_parentPort.lock();
299 }
300 
301 inline std::string ToString(PortURLScheme entry)
302 {
303  std::string entryString;
304 
305  if (entry == PortURLScheme::Local)
306  {
307  entryString = "Local";
308  }
309  else if (entry == PortURLScheme::HTTP)
310  {
311  entryString = "HTTP";
312  }
313  else if (entry == PortURLScheme::File)
314  {
315  entryString = "File";
316  }
317  else if (entry >= PortURLScheme::Custom)
318  {
319  entryString = "Custom";
320  }
321 
322  return entryString;
323 }
324 
325 } /* namespace core */
326 } /* namespace peak */
int32_t FileVersionMinor() const
Returns the file major version.
Definition: peak_port_url.hpp:268
PortURLScheme Scheme() const
Returns the scheme.
Definition: peak_port_url.hpp:225
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:453
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:472
int32_t FileSchemaVersionMajor() const
Returns the file schema major version.
Definition: peak_port_url.hpp:282
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:289
uint64_t FileRegisterAddress() const
Returns the file register address.
Definition: peak_port_url.hpp:240
uint64_t FileSize() const
Returns the file size.
Definition: peak_port_url.hpp:247
int32_t FileVersionSubminor() const
Returns the file subminor version.
Definition: peak_port_url.hpp:275
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:254
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:233
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:211
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:218
int32_t FileVersionMajor() const
Returns the file major version.
Definition: peak_port_url.hpp:261
std::shared_ptr< class Port > ParentPort() const
Returns the parent port.
Definition: peak_port_url.hpp:296