12#include "../_cexports/c_utilities.h"
13#include "../_cexports/c_core.h"
15#include "../exception.hpp"
16#include "../string.hpp"
61 LicenseInfo(
int serialNumber,
bool isFoundation) noexcept
62 : serialNumber_(serialNumber)
63 , isFoundation_(isFoundation)
68 int serialNumber_ = 0;
69 bool isFoundation_ =
false;
119 return serialNumber_;
125 : provider_(provider)
127 , magicNumber_(magicNumber)
128 , serialNumber_(serialNumber)
135 int serialNumber_ = 0;
147 CExports::cvbres_t code = 0;
149 auto res = CVB_CALL_CAPI(CVCGetLastErrorW(code,
nullptr, messageSize));
153 res = CVB_CALL_CAPI(CVCGetLastErrorW(code, message.data(), messageSize));
157 errorCode =
static_cast<int>(code);
158 return converter.to_bytes(message.data());
161 errorCode =
static_cast<int>(res);
193 return CvbException::FromCvbResult(errorCode, message);
197inline void ThrowLastError(
int errorCode)
202 std::rethrow_exception(CvbException::FromCvbResult(errorCode,
"no specific message"));
203 std::rethrow_exception(exception);
206inline void ThrowLastError()
213 CExports::cvbval_t defaultTimeout;
214 if (!CExports::GetDefaultTimeout(defaultTimeout))
232 if (!CExports::TranslateFileNameTyped(path.c_str(), &buffer[0], CExports::CVB_MAX_PATH))
234 return String(&buffer[0]);
245 if (!CExports::GetCVBDirectoryTyped(&buffer[0], buffer.size()))
251 if (path.back() != CVB_LIT(
'/'))
252 path += CVB_LIT(
'/');
265 if (!CExports::GetCVBDataDirectoryTyped(&buffer[0], buffer.size()))
268 return String(&buffer[0]);
287 auto resultUpdate = CVB_CALL_CAPI(UpdateLicenses());
288 if (resultUpdate < 0)
289 std::rethrow_exception(CvbException::FromCvbResult(resultUpdate,
"failed to update licenses"));
291 auto licCount =
static_cast<int>(CExports::GetLicenseCount());
295 for (
int i = 0; i < licCount; ++i)
297 CExports::cvblicres_t serialNumber;
298 CExports::cvbbool_t isFoundation;
300 auto resultInfo = CVB_CALL_CAPI(GetLicenseInfoEx(
static_cast<CExports::cvbval_t
>(i), serialNumber, isFoundation));
302 ThrowLastError(resultInfo);
304 licenseList.push_back(
LicenseInfo(
static_cast<int>(serialNumber), (isFoundation) ?
true :
false));
323template<
class Rep,
class Period>
330 auto result = CVB_CALL_CAPI(UpdateLicenses());
331 if (result >= 0 && CExports::GetLicenseCount() > 0)
338 if (end - start > timeSpan)
360 auto resultUpdate = CVB_CALL_CAPI(UpdateLicensesDeep());
361 if (resultUpdate < 0)
362 ThrowLastError(resultUpdate);
364 auto magicNumberCount =
static_cast<int>(CExports::GetMagicNumberCount());
368 for (
int i = 0; i < magicNumberCount; ++i)
373 CExports::cvblicres_t serialNumber = 0;
374 auto resultMnSize = CVB_CALL_CAPI(GetMagicNumber(
static_cast<std::size_t>(i),
375 nullptr, providerSize,
377 nullptr, magicNumberSize,
379 if (resultMnSize >= 0)
384 auto resultMn = CVB_CALL_CAPI(GetMagicNumber(
static_cast<std::size_t>(i),
385 &provider[0], providerSize,
386 &toolID[0], toolIDSize,
387 &magicNumber[0], magicNumberSize,
393 String(toolID.begin(), toolID.end()),
394 String(magicNumber.begin(), magicNumber.end()),
395 static_cast<int>(serialNumber)));
418using Utilities::ExpandPath;
419using Utilities::InstallPath;
420using Utilities::DataPath;
421using Utilities::GetLicenseInfo;
422using Utilities::WaitForLicense;
423using Utilities::GetMagicNumberEntries;
Information about CVB licenses.
Definition: system_info.hpp:34
int SerialNumber() const noexcept
The 32 bit CVB serial number of this license.
Definition: system_info.hpp:44
bool IsFoundation() const noexcept
Check if the license includes the Common Vision Blox Foundation package.
Definition: system_info.hpp:54
friend std::vector< LicenseInfo > GetLicenseInfo()
Get information about available licenses.
Definition: system_info.hpp:285
A single Magic Number entry.
Definition: system_info.hpp:76
String MagicNumber() const noexcept
The Magic Number which is tool-specific and at the same time specific to the Common Vision Blox Seria...
Definition: system_info.hpp:106
String ToolID() const noexcept
The tool ID of the Magic Number entry.
Definition: system_info.hpp:96
String Provider() const noexcept
The friendly (= human-readable) name of the license provider, that reported this Magic Number entry.
Definition: system_info.hpp:86
int SerialNumber() const noexcept
The serial number assigned to this Magic Number entry (0 if it has no inherent link to a serial numbe...
Definition: system_info.hpp:117
friend std::vector< MagicNumberEntry > GetMagicNumberEntries()
Query the set of currently available Magic Numbers.
Definition: system_info.hpp:358
const int CVB_ERROR
Generic unspecified error.
Definition: exception.hpp:24
String ExpandPath(const String &path)
Expands a path containing an environment variable.
Definition: system_info.hpp:229
String DataPath()
Directory where Common Vision Blox stores its settings.
Definition: system_info.hpp:262
WaitStatus WaitForLicense(const std::chrono::duration< Rep, Period > &timeSpan) noexcept
Wait for a given time for the license to become available.
Definition: system_info.hpp:324
std::vector< MagicNumberEntry > GetMagicNumberEntries()
Query the set of currently available Magic Numbers.
Definition: system_info.hpp:358
std::string GetLastErrorMessage(int &errorCode)
Returns the last error message and its code.
Definition: system_info.hpp:145
std::exception_ptr GetLastError() noexcept
Returns a pointer that points at the exception.
Definition: system_info.hpp:186
String InstallPath()
Directory Common Vision Blox has been installed to.
Definition: system_info.hpp:242
std::vector< LicenseInfo > GetLicenseInfo()
Get information about available licenses.
Definition: system_info.hpp:285
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
WaitStatus
Status after waiting for an image to be returned.
Definition: global.hpp:351
@ Ok
Everything is fine, a new image arrived.
@ Timeout
A timeout occurred, no image buffer has been returned.