13#include "../_cexports/c_utilities.h"
14#include "../_cexports/c_core.h"
16#include "../exception.hpp"
17#include "../string.hpp"
65 LicenseInfo(
int serialNumber,
bool isFoundation) noexcept
66 : serialNumber_(serialNumber)
67 , isFoundation_(isFoundation)
72 int serialNumber_ = 0;
73 bool isFoundation_ =
false;
123 return serialNumber_;
129 : provider_(provider)
131 , magicNumber_(magicNumber)
132 , serialNumber_(serialNumber)
139 int serialNumber_ = 0;
151 CExports::cvbres_t code = 0;
153 auto res = CVB_CALL_CAPI(CVCGetLastErrorW(code,
nullptr, messageSize));
157 message.resize(messageSize);
158 res = CVB_CALL_CAPI(CVCGetLastErrorW(code, &message[0], messageSize));
161 errorCode =
static_cast<int>(code);
163 return Internal::WideCharStrToUTF8(message);
166 errorCode =
static_cast<int>(res);
198 return CvbException::FromCvbResult(errorCode, message);
202 inline void ThrowLastError(
int errorCode)
207 std::rethrow_exception(CvbException::FromCvbResult(errorCode,
"no specific message"));
208 std::rethrow_exception(exception);
211 inline void ThrowLastError()
218 CExports::cvbval_t defaultTimeout = 0;
219 if (!CExports::GetDefaultTimeout(defaultTimeout))
237 if (!CExports::TranslateFileNameTyped(path.c_str(), &buffer[0], CExports::CVB_MAX_PATH))
239 return String(&buffer[0]);
250 if (!CExports::GetCVBDirectoryTyped(&buffer[0], buffer.size()))
256 if (path.back() != CVB_LIT(
'/'))
257 path += CVB_LIT(
'/');
270 if (!CExports::GetCVBDataDirectoryTyped(&buffer[0], buffer.size()))
273 return String(&buffer[0]);
292 auto resultUpdate = CVB_CALL_CAPI(UpdateLicenses());
293 if (resultUpdate < 0)
294 std::rethrow_exception(CvbException::FromCvbResult(resultUpdate,
"failed to update licenses"));
296 auto licCount =
static_cast<int>(CExports::GetLicenseCount());
300 for (
int i = 0; i < licCount; ++i)
302 CExports::cvblicres_t serialNumber = 0;
303 CExports::cvbbool_t isFoundation =
false;
305 auto resultInfo = CVB_CALL_CAPI(GetLicenseInfoEx(
static_cast<CExports::cvbval_t
>(i), serialNumber, isFoundation));
307 ThrowLastError(resultInfo);
309 licenseList.push_back(
LicenseInfo(
static_cast<int>(serialNumber), (isFoundation) ?
true :
false));
328 template<
class Rep,
class Period>
335 auto result = CVB_CALL_CAPI(UpdateLicenses());
336 if (result >= 0 && CExports::GetLicenseCount() > 0)
343 if (end - start > timeSpan)
365 auto resultUpdate = CVB_CALL_CAPI(UpdateLicensesDeep());
366 if (resultUpdate < 0)
367 ThrowLastError(resultUpdate);
369 auto magicNumberCount =
static_cast<int>(CExports::GetMagicNumberCount());
373 for (
int i = 0; i < magicNumberCount; ++i)
378 CExports::cvblicres_t serialNumber = 0;
379 auto resultMnSize = CVB_CALL_CAPI(GetMagicNumber(
static_cast<std::size_t>(i),
380 nullptr, providerSize,
382 nullptr, magicNumberSize,
384 if (resultMnSize >= 0)
389 auto resultMn = CVB_CALL_CAPI(GetMagicNumber(
static_cast<std::size_t>(i),
390 &provider[0], providerSize,
391 &toolID[0], toolIDSize,
392 &magicNumber[0], magicNumberSize,
398 String(toolID.begin(), toolID.end()),
399 String(magicNumber.begin(), magicNumber.end()),
400 static_cast<int>(serialNumber)));
423 using Utilities::ExpandPath;
424 using Utilities::InstallPath;
425 using Utilities::DataPath;
426 using Utilities::GetLicenseInfo;
427 using Utilities::WaitForLicense;
428 using Utilities::GetMagicNumberEntries;
Information about CVB licenses.
Definition: system_info.hpp:38
int SerialNumber() const noexcept
The 32 bit CVB serial number of this license.
Definition: system_info.hpp:48
bool IsFoundation() const noexcept
Check if the license includes the Common Vision Blox Foundation package.
Definition: system_info.hpp:58
friend std::vector< LicenseInfo > GetLicenseInfo()
Get information about available licenses.
Definition: system_info.hpp:290
A single Magic Number entry.
Definition: system_info.hpp:80
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:110
String ToolID() const noexcept
The tool ID of the Magic Number entry.
Definition: system_info.hpp:100
String Provider() const noexcept
The friendly (= human-readable) name of the license provider, that reported this Magic Number entry.
Definition: system_info.hpp:90
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:121
friend std::vector< MagicNumberEntry > GetMagicNumberEntries()
Query the set of currently available Magic Numbers.
Definition: system_info.hpp:363
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:234
String DataPath()
Directory where Common Vision Blox stores its settings.
Definition: system_info.hpp:267
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:329
std::vector< MagicNumberEntry > GetMagicNumberEntries()
Query the set of currently available Magic Numbers.
Definition: system_info.hpp:363
std::string GetLastErrorMessage(int &errorCode)
Returns the last error message and its code.
Definition: system_info.hpp:149
std::exception_ptr GetLastError() noexcept
Returns a pointer that points at the exception.
Definition: system_info.hpp:191
String InstallPath()
Directory Common Vision Blox has been installed to.
Definition: system_info.hpp:247
std::vector< LicenseInfo > GetLicenseInfo()
Get information about available licenses.
Definition: system_info.hpp:290
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:376
@ Ok
Everything is fine, a new image arrived.
@ Timeout
A timeout occurred, no image buffer has been returned.