The gateway's product table already runs to 1009 ANSMIND and 1010 ANSGW. The licensing library stopped at 1008, so a real ANSMIND licence could not be named, deactivated or listed here, while every product name it did not recognise quietly became product 1009. With 1009 now a real product, that fallback would mint an ANSMIND trial for a typo. ANSPRODUCTS gains ANSMIND = 1009 and ANSGW = 1010, and both are added wherever the product table is spelled out: ActivateTrialLicense, DeactivateLicense, ActivateLicense, ActivateLicenseWithCustomHWID and ListLicenses, which now reports an ANSMIND and an ANSGW row like the gateway does. Unknown names no longer map to any id. ActivateTrialLicense returns 0, its existing failure value, instead of generating a key. ListLicenses skips the row. ActivateLicense and ActivateLicenseWithCustomHWID keep passing the name through as the registration name: they never assigned an id, the key's own validation data rejects a name it was not issued for, and the gateway resolves an unknown product the same way. The ANSVIS master-licence rule in LicenseVerification is untouched. Separately, the fallback loops in ANSUtilities, ANSAWSS3 and ANSLLM asked for product 1008 under the registration name "ANSSRT". The product is ANSTS, so a genuine ANSTS licence could never satisfy them. Only that string changes; the loops still stop at 1008. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
709 lines
32 KiB
C++
709 lines
32 KiB
C++
#ifndef ANSLICENSE_H
|
|
#define ANSLICENSE_H
|
|
|
|
#ifdef ANSLICENSE_EXPORTS
|
|
#define ANSLICENSE_API __declspec(dllexport)
|
|
#else
|
|
#define ANSLICENSE_API __declspec(dllimport)
|
|
#endif
|
|
|
|
// ============================================================================
|
|
// DebugView (DbgView) logging toggle.
|
|
//
|
|
// ANS_DBG is compiled into every build; visibility is chosen at runtime by
|
|
// ANSCENTER_IsDebugViewEnabled() — a cached check (~2 s) that reads:
|
|
// 1. env var ANSCENTER_DBGVIEW (="1" forces on, ="0" forces off), else
|
|
// 2. existence of C:\ProgramData\ANSCENTER\ansvisdebugview.txt (Windows) or
|
|
// /tmp/ansvisdebugview.txt (POSIX).
|
|
//
|
|
// Drop the sentinel file to turn logging on; delete it to turn it off. No
|
|
// rebuild, no restart — takes effect within ~2 s. ACLs on ProgramData are
|
|
// world-writable by default so any user can toggle.
|
|
//
|
|
// Hard kill-switch: compile with -DANSCORE_DEBUGVIEW=0 to strip ANS_DBG to
|
|
// ((void)0) — use only when even the atomic-load cost is unacceptable.
|
|
// ============================================================================
|
|
#ifndef ANSCORE_DEBUGVIEW
|
|
#define ANSCORE_DEBUGVIEW 1 // 1 = runtime-gated (default), 0 = hard-off (stripped)
|
|
#endif
|
|
|
|
// Runtime gate. Implemented in ANSLicense.cpp. Returns non-zero when logging
|
|
// should be emitted. Cheap on the hot path: one atomic load + branch; the
|
|
// filesystem check runs at most once per ~2 s.
|
|
extern "C" ANSLICENSE_API int ANSCENTER_IsDebugViewEnabled(void);
|
|
|
|
// C-linkage facade over SPDLogger so consumers can dynamic-load these via
|
|
// GetProcAddress without depending on the C++ class ABI. Each call routes to
|
|
// the process-wide SPDLogger singleton (thread-safe magic-static init).
|
|
extern "C" {
|
|
ANSLICENSE_API void ANSLogger_LogInfo (const char* src, const char* msg, const char* file, int line);
|
|
ANSLICENSE_API void ANSLogger_LogError(const char* src, const char* msg, const char* file, int line);
|
|
ANSLICENSE_API void ANSLogger_LogFatal(const char* src, const char* msg, const char* file, int line);
|
|
|
|
// DebugView choke point shared by ANS_DBG and ANSLIB_DBG. Strips noise
|
|
// path prefixes before emitting to OutputDebugStringA + stderr.
|
|
ANSLICENSE_API void ANSCENTER_DebugLog(const char* preformattedLine);
|
|
}
|
|
|
|
// ANS_DBG: Debug logging macro for DebugView (OutputDebugStringA on Windows).
|
|
// Usage: ANS_DBG("MyModule", "value=%d ptr=%p", val, ptr);
|
|
// Output: [MyModule] value=42 ptr=0x1234
|
|
//
|
|
// Routes through ANSCENTER_DebugLog so noise path prefixes (e.g. the
|
|
// ProgramData profile dir) are stripped centrally before emit. The macro just
|
|
// formats on the caller's stack and hands off the buffer.
|
|
#if ANSCORE_DEBUGVIEW
|
|
#define ANS_DBG(tag, fmt, ...) do { \
|
|
if (ANSCENTER_IsDebugViewEnabled()) { \
|
|
char _ans_dbg_buf[1024]; \
|
|
snprintf(_ans_dbg_buf, sizeof(_ans_dbg_buf), "[" tag "] " fmt "\n", ##__VA_ARGS__); \
|
|
ANSCENTER_DebugLog(_ans_dbg_buf); \
|
|
} \
|
|
} while(0)
|
|
#else
|
|
#define ANS_DBG(tag, fmt, ...) ((void)0)
|
|
#endif
|
|
|
|
|
|
#pragma once
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <exception>
|
|
#include <iostream>
|
|
#include "anslicensing.h"
|
|
#include "LabVIEWHeader/extcode.h"
|
|
#include <mutex>
|
|
#ifdef _UNICODE
|
|
#define _T(s) L##s
|
|
#define _tprintf wprintf
|
|
#define _tcscmp wcscmp
|
|
#define _tfopen fopen
|
|
#else
|
|
#define _T(s) (s)
|
|
#define _TL(s) L##s
|
|
#define _tprintf printf
|
|
#define _tcscmp strcmp
|
|
#define _tfopen fopen
|
|
#endif
|
|
|
|
enum LicenseKeyStatus {
|
|
SUCCESS = 0,
|
|
INVALID_LICENSE_KEY = 1,
|
|
INVALID_HARDWARE_ID = 2,
|
|
LICENSE_EXPIRED = 3,
|
|
INVALID_ACTIVATION_KEY = 4,
|
|
PAYMENT_REQUIRED = 5,
|
|
INVALID_PRODUCT = 6,
|
|
UNKNOWN = 7
|
|
};
|
|
|
|
typedef struct {
|
|
int32 cnt; /* number of bytes that follow */
|
|
double value[1]; /* value of double */
|
|
} LDbl, * LDblPtr, ** LDblHandle;
|
|
|
|
namespace ANSCENTER
|
|
{
|
|
|
|
// Precision used for GPU inference
|
|
|
|
enum OCRType {
|
|
SINGLETEXT = 0,
|
|
STRUCTURE = 1
|
|
};
|
|
|
|
enum OCRLanguage {
|
|
ENGLISH = 0,
|
|
CHINESE = 1,
|
|
FRENCH = 2,
|
|
GERMANY = 3,
|
|
JAPANESE= 4,
|
|
KOREAN = 5,
|
|
CUSTOM =6
|
|
};
|
|
// Precision used for GPU inference
|
|
enum class Precision {
|
|
// Full precision floating point value
|
|
FP32,
|
|
// Half prevision floating point value
|
|
FP16,
|
|
// Int8 quantization.
|
|
// Has reduced dynamic range, may result in slight loss in accuracy.
|
|
// If INT8 is selected, must provide path to calibration dataset directory.
|
|
INT8,
|
|
};
|
|
|
|
// Options for the network
|
|
struct Options {
|
|
// Precision to use for GPU inference.
|
|
Precision precision = Precision::FP16;
|
|
// If INT8 precision is selected, must provide path to calibration dataset
|
|
// directory.
|
|
std::string calibrationDataDirectoryPath;
|
|
// The batch size to be used when computing calibration data for INT8
|
|
// inference. Should be set to as large a batch number as your GPU will
|
|
// support.
|
|
int32_t calibrationBatchSize = 128;
|
|
// The batch size which should be optimized for.
|
|
int32_t optBatchSize = 1;
|
|
// Maximum allowable batch size
|
|
int32_t maxBatchSize = 16;
|
|
// GPU device index
|
|
int deviceIndex = 0;
|
|
// Directory where the engine file should be saved
|
|
std::string engineFileDir = ".";
|
|
|
|
// Maximum allowed input width
|
|
int32_t maxInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
// Minimum allowed input width
|
|
int32_t minInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
// Optimal input width
|
|
int32_t optInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
|
|
// Maximum allowed input height
|
|
int32_t maxInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
// Minimum allowed input height
|
|
int32_t minInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
// Optimal input height
|
|
int32_t optInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
|
|
// GPU clock lock frequency in MHz.
|
|
// -1 = auto (default) — query max supported clock and lock at ~80%
|
|
// 0 = disabled — let the driver manage clocks dynamically
|
|
// >0 = lock at this specific MHz value (e.g. 2400)
|
|
// Prevents GPU power throttling that causes TensorRT timing instability
|
|
// on laptop GPUs. Requires elevated privileges; fails gracefully if not.
|
|
int32_t gpuClockLockMHz = -1;
|
|
};
|
|
|
|
enum PrecisionType {
|
|
INT8 = 0,
|
|
FP16 = 1,
|
|
FP32 = 2,
|
|
};
|
|
enum EngineType {
|
|
CPU = 0,
|
|
NVIDIA_GPU = 1,
|
|
OPENVINO_GPU = 2,
|
|
AMD_GPU = 3,
|
|
AUTO_DETECT = 99 // default: hardware auto-detection
|
|
};
|
|
enum Country {
|
|
VIETNAM = 0,
|
|
CHINA = 1,
|
|
AUSTRALIA = 2,
|
|
USA = 3,
|
|
INDONESIA = 4,
|
|
JAPAN = 5
|
|
};
|
|
|
|
enum DetectionType {
|
|
CLASSIFICATION = 0,
|
|
DETECTION = 1,
|
|
SEGMENTATION = 2,
|
|
FACEDETECTOR = 3,
|
|
FACERECOGNIZER = 4,
|
|
LICENSEPLATE = 5,
|
|
TEXTSCENSE = 6,
|
|
KEYPOINT=7,
|
|
OBB = 8 // Oriented Bounding Box
|
|
};
|
|
enum ModelType {
|
|
TENSORFLOW = 0,
|
|
YOLOV4 = 1,
|
|
YOLOV5 = 2,
|
|
YOLOV8 = 3,
|
|
TENSORRT = 4,
|
|
OPENVINO = 5,
|
|
FACEDETECT = 6,
|
|
FACERECOGNIZE = 7,
|
|
ALPR = 8,
|
|
OCR = 9,
|
|
ANOMALIB = 10,
|
|
POSE=11,
|
|
SAM=12,
|
|
ODHUBMODEL = 13,
|
|
YOLOV10RTOD = 14, // TensorRT Object Detection for Yolov10
|
|
YOLOV10OVOD = 15, // OpenVINO Object Detection for Yolov10
|
|
CUSTOMDETECTOR = 16, // Custom Detector
|
|
YOLOV12 = 17, // YoloV12 standard for yolov12
|
|
CUSTOMPY = 18, // Custom Python script model
|
|
MOTIONDETECTOR = 19, // Motion Detector,
|
|
ONNXCL =20,
|
|
ONNXPOSE=21,
|
|
RTPOSE=22,
|
|
ONNXSEG = 23,
|
|
RTSEG = 24,
|
|
ONNXOBB = 25,
|
|
RTOBB = 26,
|
|
MOVIENET=27,
|
|
ONNXSAM3=28,
|
|
RTSAM3 = 29,
|
|
ONNXYOLO = 30,
|
|
RTYOLO = 31,
|
|
ONNXRTMPOSE=32,
|
|
RTRTMPOSE=33
|
|
};
|
|
enum TrackerType {
|
|
BYTETRACK = 0,
|
|
UCMC = 1,
|
|
OCSORT = 2
|
|
};
|
|
enum ANSPRODUCTS {
|
|
ANNHUB = 1000,
|
|
DLHUB = 1001,
|
|
ODHUB = 1002,
|
|
ANSVIS = 1003,
|
|
ANS_FACERECOGNIZE = 1004,
|
|
ANS_OCR = 1005,
|
|
ANS_ALPR =1006,
|
|
ANS_CV = 1007,
|
|
ANS_TS = 1008,
|
|
ANSMIND = 1009,
|
|
ANSGW = 1010
|
|
};
|
|
enum ANSLICENSESTATUS {
|
|
ACTIVE = 0,
|
|
EXPIRED = 1,
|
|
TRIAL=2,
|
|
UNLICENSE = 3
|
|
};
|
|
struct ModelConfig {
|
|
// All POD members default-initialized. Several callers (notably
|
|
// CreateANSODHandle in ANSODEngine/dllmain.cpp) declare a local
|
|
// ModelConfig and only set a subset of fields before passing it
|
|
// to ANSODBase::Initialize. Without these defaults inpWidth /
|
|
// inpHeight enter Initialize() as indeterminate stack values; the
|
|
// existing `<=0 → 640` guard in ANSONNXYOLO::Initialize only
|
|
// catches non-positive garbage, so a small positive stack value
|
|
// (e.g. 80) would slip through and end up driving the ORT
|
|
// session at 80x80 — which crashes YOLOv11 in /model.12/Concat
|
|
// because 2*ceil(80/32) ≠ ceil(80/16) in the FPN.
|
|
DetectionType detectionType{};
|
|
ModelType modelType{};
|
|
PrecisionType precisionType{};
|
|
int inpWidth = 0;
|
|
int inpHeight = 0;
|
|
float modelConfThreshold = 0.0f;
|
|
float modelMNSThreshold = 0.0f;
|
|
float detectionScoreThreshold = 0.0f;
|
|
int numKPS = 0; // Number of pose keypoint
|
|
float kpsThreshold = 0.0f;
|
|
bool autoGPUDetection = false;
|
|
float unknownPersonThreshold = 0.0f;
|
|
int gpuOptBatchSize = 1; // The batch size which should be optimized for.
|
|
int gpuMaxBatchSize = 1; // Maximum allowable batch size
|
|
int gpuDeviceIndex = 0; // GPU device index
|
|
|
|
// Maximum allowed input width
|
|
int32_t maxInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
// Minimum allowed input width
|
|
int32_t minInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
// Optimal input width
|
|
int32_t optInputWidth = -1; // Default to -1 --> expecting fixed input size
|
|
|
|
// Maximum allowed input height
|
|
int32_t maxInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
// Minimum allowed input height
|
|
int32_t minInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
// Optimal input height
|
|
int32_t optInputHeight = -1; // Default to -1 --> expecting fixed input size
|
|
};
|
|
|
|
struct ANSLicenseInfo {
|
|
std::string productName;
|
|
std::string licenseKey;
|
|
std::string activationKey;
|
|
std::string hardwareId;
|
|
ANSLICENSESTATUS licenseStatus;
|
|
int remainingDays;
|
|
int enableFeature;
|
|
};
|
|
|
|
// ------------------------------------------------------------------------
|
|
// Real-time system telemetry. Snapshot of CPU / GPU / RAM / disk / network
|
|
// usage at the time of the call.
|
|
//
|
|
// Cheap to call frequently — values are cached for ~500 ms via a process-
|
|
// wide PDH sampler held in ANSLicense.cpp. The first call after process
|
|
// start blocks for ~150 ms because PDH counters require two samples to
|
|
// produce a delta-rate reading; subsequent calls are sub-millisecond.
|
|
//
|
|
// Fields the platform could not provide are set to -1 (or -1.0). Common
|
|
// reasons:
|
|
// - cpuTempDegC: ACPI thermal zone is unavailable / blocked on most
|
|
// consumer hardware. Use a vendor SDK (NVML / ADL / IPMI) for real
|
|
// thermals if you need them.
|
|
// - netLoadPercent: no network adapter advertises a non-zero
|
|
// "Current Bandwidth" (e.g. all interfaces are loopback / virtual).
|
|
// - valIGPU_MB: Windows < 10 19H1 does not expose GPU Process Memory
|
|
// PDH counters.
|
|
//
|
|
// Memory / disk units use 1024 base (1 GB == 2^30 bytes); throughput uses
|
|
// MB == 2^20 bytes for parity with Task Manager.
|
|
// ------------------------------------------------------------------------
|
|
struct SystemHealthInfo {
|
|
// CPU
|
|
// cpuLoadPercent — 0..100 always. Source: PDH "% Processor Time".
|
|
// The right value for "what fraction of CPU time
|
|
// am I spending in non-idle threads?".
|
|
// cpuUtilizationPercent — turbo-aware. Source: PDH "% Processor
|
|
// Utility". Can exceed 100% during sustained turbo
|
|
// boost. This is what Task Manager displays.
|
|
// Pick one to bind to the LabVIEW indicator; cpuUtilizationPercent
|
|
// matches what users see in TM but breaks fixed-range UI scaling.
|
|
double cpuLoadPercent = -1.0;
|
|
double cpuUtilizationPercent = -1.0;
|
|
double cpuTempDegC = -1.0;
|
|
double cpuFreqGHz = -1.0; // current clock (turbo-aware)
|
|
std::string cpuModel; // e.g. "Intel(R) Core(TM) i9-..."
|
|
|
|
// System memory
|
|
double memTotalGB = -1.0;
|
|
double memoryUsedGB = -1.0;
|
|
double memoryFreeGB = -1.0;
|
|
double rssPercent = -1.0; // current process WS / total physical
|
|
double swapPercent = -1.0; // page file used / page file limit
|
|
|
|
// Current process
|
|
int64_t valIRSS_MB = -1; // working-set size (MB)
|
|
int64_t valSwap_MB = -1; // private commit / page-file usage (MB)
|
|
int64_t valIGPU_MB = -1; // dedicated GPU memory used by us (MB)
|
|
|
|
// GPU — values report the *primary* adapter only. On hybrid systems
|
|
// (e.g. Iris Xe + RTX 4090) the primary is picked deterministically:
|
|
// NVIDIA discrete > AMD discrete > whichever has the most VRAM. Per-
|
|
// adapter numbers are available in gpuAdaptersDetail below.
|
|
double gpuLoadPercent = -1.0; // 0..100 on the primary adapter only
|
|
std::string gpuName; // primary adapter model name
|
|
// Per-adapter rollup; one row per physical GPU, comma-separated.
|
|
// Row format: <name>|<vendor>|<load%>|<processMemMB>|<vramMB>
|
|
// Vendors: NVIDIA / AMD / Intel / Microsoft / Other
|
|
// Numbers use the C locale ('.' decimal, 2dp for load%).
|
|
std::string gpuAdaptersDetail;
|
|
|
|
// Disk (system drive — the volume holding %SystemRoot%)
|
|
double diskLoadPercent = -1.0;
|
|
double diskReadSpeedMBs = -1.0;
|
|
double diskWriteSpeedMBs = -1.0;
|
|
double diskUsedGB = -1.0;
|
|
double diskTotalGB = -1.0;
|
|
|
|
// Network (sum across all non-loopback interfaces)
|
|
double netLoadPercent = -1.0;
|
|
double netReceiveSpeedMBs = -1.0;
|
|
double netSendSpeedMBs = -1.0;
|
|
};
|
|
|
|
// ------------------------------------------------------------------------
|
|
// Public IP + IP-based geolocation, sourced from ipapi.co/json/.
|
|
//
|
|
// One HTTPS GET per refresh; results cached for 60 minutes (success) or
|
|
// 60 seconds (failure backoff). Never throws, never blocks more than 5 s.
|
|
//
|
|
// `ok == false` means the data could not be obtained — `error` carries
|
|
// the reason ("HTTP 429", "WinHttpConnect failed", "JSON parse: ...",
|
|
// etc.). Latitude/longitude are 0,0 when unknown.
|
|
//
|
|
// Privacy note: this performs an outbound HTTPS request to a third-party
|
|
// service (ipapi.co). Each request reveals the device's public IP to that
|
|
// service. Use the simpler GetPublicIPAddress() if you only need the IP
|
|
// and prefer no third-party HTTP hop.
|
|
// ------------------------------------------------------------------------
|
|
struct PublicNetworkInfo {
|
|
bool ok = false;
|
|
std::string publicIP; // e.g. "203.0.113.42"
|
|
std::string country; // full name, e.g. "Vietnam"
|
|
std::string countryCode; // ISO 2-letter, e.g. "VN"
|
|
std::string region; // state / province
|
|
std::string city;
|
|
std::string isp; // organization / provider name
|
|
std::string timezone; // IANA tz, e.g. "Asia/Ho_Chi_Minh"
|
|
double latitude = 0.0;
|
|
double longitude = 0.0;
|
|
std::string error; // empty on success
|
|
};
|
|
|
|
|
|
|
|
class ANSLICENSE_API SPDLogger
|
|
{// Singleton design pattern
|
|
protected:
|
|
SPDLogger(const std::string& loggerFileName, bool consoleLoggerEnable = false)
|
|
: _loggerFileName(loggerFileName), _consoleLoggerEnable(consoleLoggerEnable) {
|
|
Init();
|
|
}
|
|
void Init();
|
|
void ConfigureLogger();
|
|
std::string _loggerFileName{};
|
|
bool _consoleLoggerEnable{true};
|
|
// Deleting copy constructor and assignment operator to ensure singleton
|
|
SPDLogger(const SPDLogger&) = delete;
|
|
SPDLogger& operator=(const SPDLogger&) = delete;
|
|
|
|
public:
|
|
bool Release();
|
|
~SPDLogger();
|
|
// Static method to get the singleton instance
|
|
static SPDLogger& GetInstance(const std::string& loggerFileName, bool consoleLoggerEnable = false) {
|
|
static SPDLogger instance(loggerFileName, consoleLoggerEnable);
|
|
return instance;
|
|
}
|
|
void Disable();
|
|
void Enable();
|
|
void LogTrace(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
void LogDebug(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
void LogInfo(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
void LogWarn(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
void LogError(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
void LogFatal(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
|
};
|
|
|
|
class ANSLICENSE_API ANSLSHelper {
|
|
private:
|
|
LicenseTemplate* _licenseTemplate = nullptr;
|
|
License* _license = nullptr;
|
|
std::wstring _licenseFilePath = _T("");
|
|
std::wstring _licenseServiceURL = _T("");
|
|
std::wstring _sdkLicenseKey = _T("");
|
|
std::wstring _privateKey = _T("");
|
|
std::wstring _publicKey = _T("");
|
|
|
|
SPDLogger& _logger = SPDLogger::GetInstance("License");
|
|
std::string LoadLicenseContent();
|
|
void Setup5x5LicenseTemplate();// This is simple case
|
|
std::wstring GetProductId(std::string licenseKey);
|
|
|
|
public:
|
|
ANSLSHelper();
|
|
ANSLSHelper(std::string licenseServiceURL);
|
|
ANSLSHelper(std::string privateKey, std::string licenseServiceURL);
|
|
ANSLSHelper(std::string privateKey, std::string publicKey, std::string licenseServiceURL);
|
|
~ANSLSHelper();
|
|
|
|
void SetupLicenseTemplate();
|
|
|
|
[[nodiscard]] bool MatchCurrentHardwareId(std::string hwid);
|
|
[[nodiscard]] bool DectectClockmanipulation(int year, int month, int date);
|
|
|
|
[[nodiscard]] std::string GetLicenseData(std::string licenseKey);
|
|
[[nodiscard]] int ActivateLicense(std::string licenseKey, std::string registrationName, std::string& activationKey); // Always activate the license (need internet connection)
|
|
[[nodiscard]] int ActivateLicenseWithCustomHWID(std::string licenseKey, std::string registrationName, std::string hardwareId, std::string& activationKey); // Always activate the license (need internet connection)
|
|
|
|
[[nodiscard]] bool LoadLicenseTemplate(std::string templateFilePath);
|
|
[[nodiscard]] std::string SaveLicenseTemplate(std::string templateFilePath, bool savePrivateKey);
|
|
|
|
// These are the common methods to be used
|
|
void SetLicenseServiceURL(std::string licenseServiceURL);
|
|
[[nodiscard]] std::string GetCurrentHardwareId();
|
|
void LoadLicense(std::string licenseKey);
|
|
[[nodiscard]] std::string SaveLicense();
|
|
[[nodiscard]] std::string GenerateKey(int productId, std::string registrationName, int productFeature, bool trialLicense);
|
|
[[nodiscard]] std::string GenerateKey(int productId, std::string registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate);
|
|
[[nodiscard]] bool IsLicenseKeyValid(std::string licenseKey, std::string registrationName); // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
|
|
[[nodiscard]] bool CheckLicenseKey(std::string licenseKey, std::string registrationName, int productId, int& enabledFeatures); // Check if the license key is valid
|
|
[[nodiscard]] int ValidateLicense(std::string licenseKey, std::string registrationName, std::string& activationKey);
|
|
[[nodiscard]] int ValidateLicenseWithCustomHWID(std::string licenseKey, std::string registrationName, std::string customHWID, std::string& activationKey);
|
|
|
|
[[nodiscard]] int GenerateOfflineActivationData(std::string licenseKey, std::string registrationName, std::string& offlineActivationData);
|
|
[[nodiscard]] int InstallOfflineLicense(std::string licenseKey, std::string registrationName, std::string activationKey);
|
|
|
|
// Utilities
|
|
[[nodiscard]] static int ExtractModelZipFile(std::string modelZipFile, std::string password, std::string modelName, std::string& extractedOutputFolder);
|
|
[[nodiscard]] static bool ZipFolerWithPassword(std::string folderPath, std::string zipFilePath, std::string password);
|
|
[[nodiscard]] static int PrepareEdgeModel(std::string modelZipFile, std::string zipFilePassword, std::string edgePassword, std::string modelName, std::string edgeSerialNumber, std::string& configFilePathName, std::string& labelMapPathName, std::string& outputModelFolder);
|
|
[[nodiscard]] static std::string GetSystemHardwareInformation();
|
|
[[nodiscard]] static bool ReleaseLogger();
|
|
|
|
};
|
|
|
|
|
|
class ANSLICENSE_API ANSLicenseHelper {
|
|
private:
|
|
[[nodiscard]] static bool deleteRecursively(const std::string& pathStr, bool safeMode);
|
|
[[nodiscard]] static bool isPathSafe(const std::string& pathStr);
|
|
public:
|
|
[[nodiscard]] static bool LicenseVerification(std::string licenseKey, int productId, std::string registrationName);
|
|
// Returns this machine's hardware id (same value as ANSLSHelper::GetCurrentHardwareId)
|
|
// but as a static call requiring no handle/instance — convenient for LabVIEW and other
|
|
// callers that just need the HWID. Returns "" on failure.
|
|
[[nodiscard]] static std::string GetHardwareId();
|
|
[[nodiscard]] static EngineType CheckHardwareInformation();
|
|
[[nodiscard]] static SystemHealthInfo GetSystemHealthInformation();
|
|
|
|
// Returns the device's public IPv4 address as seen from the internet,
|
|
// or an empty string if it can't be resolved (no connectivity, DNS
|
|
// blocked, etc). Result is cached for 10 minutes — subsequent calls
|
|
// are a memory read.
|
|
//
|
|
// Implementation uses a single DNS query to OpenDNS's special name
|
|
// 'myip.opendns.com' (the resolver echoes back the client's seen IP
|
|
// in an A record). No HTTP, no third-party REST, no database — works
|
|
// on any network where outbound DNS to 208.67.222.222 is allowed
|
|
// (which is the vast majority, including most corporate firewalls).
|
|
[[nodiscard]] static std::string GetPublicIPAddress();
|
|
|
|
// Public IP + geolocation in one shot via ipapi.co/json/. See the
|
|
// PublicNetworkInfo doc-comment for caching, failure semantics, and
|
|
// privacy implications. If you only need the IP, prefer the simpler
|
|
// GetPublicIPAddress() above (no HTTP, no third-party REST).
|
|
[[nodiscard]] static PublicNetworkInfo GetPublicNetworkInformation();
|
|
[[nodiscard]] static std::string ListLicenses();
|
|
[[nodiscard]] static int ActivateTrialLicense(std::string productName);
|
|
[[nodiscard]] static int DeactivateLicense(std::string productName);
|
|
[[nodiscard]] static int ActivateLicense(std::string productName, std::string licenseKey);
|
|
[[nodiscard]] static int ActivateLicenseWithCustomHWID(std::string productName, std::string licenseKey, std::string hwid, std::string& activationKey);
|
|
[[nodiscard]] static std::string DecodeValidationData(const char* validationData);
|
|
[[nodiscard]] static std::string GenerateActivationDataFile(std::string activationKey,std::string licenseKey, std::string hardwareId, std::string validationData);
|
|
[[nodiscard]] static std::string DecodeBase64(std::string base64String);
|
|
[[nodiscard]] static bool RemoveTrialLicenseKeys(std::string registrationName);
|
|
[[nodiscard]] static bool DeleleteRecursively(const std::string& pathStr) {
|
|
return deleteRecursively(pathStr, true);
|
|
}
|
|
|
|
};
|
|
}
|
|
extern "C" __declspec(dllexport) int CreateANSLSHandle(ANSCENTER::ANSLSHelper * *Handle, const char* privateKey, const char* publicKey, const char* licenseServiceURL);
|
|
extern "C" __declspec(dllexport) int Release(ANSCENTER::ANSLSHelper * *Handle);
|
|
extern "C" __declspec(dllexport) void SetLicenseServiceURL(ANSCENTER::ANSLSHelper * *Handle, const char* licenseServiceURL);
|
|
extern "C" __declspec(dllexport) int GetLicenseData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, LStrHandle licenseData);
|
|
extern "C" __declspec(dllexport) int LoadLicenseTemplate(ANSCENTER::ANSLSHelper * *Handle, const char* templateFilePath);
|
|
extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper * *Handle, LStrHandle currentHwID);
|
|
// Handle-free static hardware id, two flavours:
|
|
// - GetHardwareId: LabVIEW native string handle (LStrHandle) output. Returns 1 on success, 0 on failure.
|
|
// - GetHardwareIdBuffer: caller-provided C buffer; works from plain C/C++ too (no LabVIEW manager).
|
|
// Writes a null-terminated string into 'buffer' (capacity 'bufferSize') and returns the number of
|
|
// characters written (excluding the null terminator), or 0 on failure / insufficient buffer.
|
|
extern "C" __declspec(dllexport) int GetHardwareId(LStrHandle currentHwID);
|
|
extern "C" __declspec(dllexport) int GetHardwareIdBuffer(char* buffer, int bufferSize);
|
|
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey);
|
|
extern "C" __declspec(dllexport) int GenerateKeyWithExpiredDate(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate, LStrHandle generatedKey);
|
|
extern "C" __declspec(dllexport) int CheckLicenseKey(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, int productId);// , LStrHandle strEnableFeature); // Check if the license key is valid
|
|
extern "C" __declspec(dllexport) int ValidateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* existingActivationKey, LStrHandle activationKey);
|
|
extern "C" __declspec(dllexport) int ActivateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle activationKey); // Always activate the license (need internet connection)
|
|
extern "C" __declspec(dllexport) int ActivateLicenseWithCustomHWID(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* hardwareId, LStrHandle activationKey); // Always activate the license (need internet connection)
|
|
extern "C" __declspec(dllexport) int IsLicenseKeyValid(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName); // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
|
|
extern "C" __declspec(dllexport) int GenerateOfflineActivationData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle offlineActivationData);
|
|
extern "C" __declspec(dllexport) int InstallOfflineLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* activationKey);
|
|
|
|
|
|
// Utilities
|
|
extern "C" __declspec(dllexport) int ExtractModelZipFile(const char* modelZipFile, const char* password, const char* modelName, LStrHandle extractedOutputFolder);
|
|
extern "C" __declspec(dllexport) int ZipFolderToZipFile(const char* modelFolderSource,const char* modelZipFileDes, const char* password);
|
|
extern "C" __declspec(dllexport) int PrepareEdgeModel(const char* modelZipFile, const char* zipFilePassword, const char* edgePassword, const char* modelName, const char* edgeSerialNumber, LStrHandle pathArray);
|
|
extern "C" __declspec(dllexport) int GetSystemHardwareInformation(LStrHandle systemHardwareInformation);
|
|
|
|
// SystemHealthParameters cluster, one scalar at a time. Pass nullptr for any
|
|
// field you do not care about. Returns 1 on success, 0 on failure. Cached
|
|
// internally so calling at LabVIEW UI rate (e.g. 1 Hz) is essentially free.
|
|
extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
|
double* cpuLoadPercent,
|
|
double* cpuTempDegC,
|
|
double* cpuFreqGHz,
|
|
LStrHandle cpuModel,
|
|
double* memTotalGB,
|
|
double* rssPercent,
|
|
double* swapPercent,
|
|
double* gpuLoadPercent,
|
|
int64_t* valIRSS_MB,
|
|
int64_t* valSwap_MB,
|
|
int64_t* valIGPU_MB,
|
|
double* memoryUsedGB,
|
|
double* memoryFreeGB,
|
|
double* diskLoadPercent,
|
|
double* diskReadSpeedMBs,
|
|
double* diskWriteSpeedMBs,
|
|
double* diskUsedGB,
|
|
double* diskTotalGB,
|
|
double* netLoadPercent,
|
|
double* netReceiveSpeedMBs,
|
|
double* netSendSpeedMBs,
|
|
LStrHandle gpuName, // primary adapter name (e.g. "NVIDIA RTX 4090"); pass nullptr to skip
|
|
LStrHandle gpuAdaptersDetail, // per-adapter rollup; pass nullptr to skip — see SystemHealthInfo for format
|
|
double* cpuUtilizationPercent); // turbo-aware "% Processor Utility"; matches Task Manager (may exceed 100)
|
|
|
|
// Same payload as GetSystemHealthParameters, packed into a single string with
|
|
// ';' separators in this exact order:
|
|
// 1 cpuLoadPercent (%; 0..100, "% Processor Time")
|
|
// 2 cpuTempDegC (°C, -1 if unavailable)
|
|
// 3 cpuFreqGHz (GHz)
|
|
// 4 cpuModel (string; any literal ';' is rewritten to ',')
|
|
// 5 memTotalGB
|
|
// 6 rssPercent (%)
|
|
// 7 swapPercent (%)
|
|
// 8 gpuLoadPercent (%)
|
|
// 9 valIRSS_MB (current process working set, MB)
|
|
// 10 valSwap_MB (current process page-file usage, MB)
|
|
// 11 valIGPU_MB (current process GPU dedicated memory, MB)
|
|
// 12 memoryUsedGB
|
|
// 13 memoryFreeGB
|
|
// 14 diskLoadPercent (%)
|
|
// 15 diskReadSpeedMBs
|
|
// 16 diskWriteSpeedMBs
|
|
// 17 diskUsedGB
|
|
// 18 diskTotalGB
|
|
// 19 netLoadPercent (%)
|
|
// 20 netReceiveSpeedMBs
|
|
// 21 netSendSpeedMBs
|
|
// 22 gpuName (primary adapter model, e.g. "NVIDIA RTX 4090")
|
|
// 23 gpuAdaptersDetail (per-adapter rollup — see SystemHealthInfo struct)
|
|
// 24 cpuUtilizationPercent (%; turbo-aware, may exceed 100; matches Task Manager)
|
|
//
|
|
// New fields are appended at the end so existing parsers stay valid. Fields
|
|
// 1..23 are stable.
|
|
// Numbers use the C locale ('.' decimal point) and 2-decimal fixed format.
|
|
// Any literal ';' in gpuName / gpuAdaptersDetail is rewritten to ',' so the
|
|
// outer separator is never ambiguous.
|
|
// Returns 1 on success, 0 on failure.
|
|
extern "C" __declspec(dllexport) int GetSystemHealthParametersString(LStrHandle outString);
|
|
|
|
// Writes the device's public IPv4 (e.g. "203.0.113.42") into the LStrHandle.
|
|
// Returns 1 on success, 0 if the IP could not be resolved. Cached for 10 min.
|
|
extern "C" __declspec(dllexport) int GetPublicIPAddress(LStrHandle ipv4);
|
|
|
|
// Public IP + IP-based geolocation via ipapi.co/json/. Each pointer is
|
|
// optional; pass nullptr to skip a field. `errorMsg` carries a human-readable
|
|
// reason when the call fails (no internet, rate limit, etc.). Returns 1 on
|
|
// success, 0 on failure. Cached for 1 hour on success; 1-minute back-off on
|
|
// failure so a flapping network doesn't get hammered.
|
|
extern "C" __declspec(dllexport) int GetPublicNetworkParameters(
|
|
LStrHandle publicIP,
|
|
LStrHandle country,
|
|
LStrHandle countryCode,
|
|
LStrHandle region,
|
|
LStrHandle city,
|
|
LStrHandle isp,
|
|
LStrHandle timeZone,
|
|
double* latitude,
|
|
double* longitude,
|
|
LStrHandle errorMsg);
|
|
|
|
// Same payload packed as a single ';'-separated string in this exact order:
|
|
// 1 publicIP
|
|
// 2 country (full name)
|
|
// 3 countryCode (ISO 2-letter)
|
|
// 4 region
|
|
// 5 city
|
|
// 6 isp
|
|
// 7 timezone (IANA, e.g. "Asia/Ho_Chi_Minh")
|
|
// 8 latitude (6dp, C locale)
|
|
// 9 longitude (6dp, C locale)
|
|
// Any literal ';' inside string fields is rewritten to ',' so the separator
|
|
// stays unambiguous. Returns 1 on success, 0 on failure (string still written
|
|
// — values just empty/0).
|
|
extern "C" __declspec(dllexport) int GetPublicNetworkParametersString(LStrHandle outString);
|
|
extern "C" __declspec(dllexport) int ReleaseLoggers();
|
|
extern "C" __declspec(dllexport) int ListANSLicenses(std::string &listLicense);
|
|
extern "C" __declspec(dllexport) int ListANSLicenses_LV(LStrHandle ansProductLicenses);
|
|
extern "C" __declspec(dllexport) int ActivateTrialLicense(const char* productName);
|
|
extern "C" __declspec(dllexport) int DeactivateLicense(const char* productName);
|
|
extern "C" __declspec(dllexport) int ActivateProductLicense(const char* productName, const char* licenseKey);
|
|
extern "C" __declspec(dllexport) int ActivateProductLicenseWithCustomHWID(const char* productName, const char* licenseKey, const char* hwid, LStrHandle lvActivationKey);
|
|
extern "C" __declspec(dllexport) int GetRegistrationName(const char* validationData, LStrHandle registrationName);
|
|
extern "C" __declspec(dllexport) int GenerateActivationKeyData(const char* activationKey, const char* licenseKey, const char* hardwareId, const char* validationData, LStrHandle activationData);
|
|
extern "C" __declspec(dllexport) int ANSLicenseVerification(const char* licenseKey, int productId, const char* registrationName);
|
|
extern "C" __declspec(dllexport) int ANSModelConversion(const char* zipModelFile, const char* zipModelPassword);
|
|
extern "C" __declspec(dllexport) int DeletePathRecursively(const char* pathTobeDeleted);
|
|
|
|
#endif |