Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da9d922498 | ||
|
|
6939775960 | ||
|
|
86b520d85c | ||
|
|
6f1d069d14 | ||
|
|
4f392ce95e | ||
|
|
60a8b39d24 | ||
|
|
d2479b9b07 | ||
|
|
ac79e51d17 | ||
|
|
7909c8db2b | ||
|
|
b341392e0f | ||
|
|
273dd44a6d | ||
|
|
6344062179 | ||
|
|
044fedd344 | ||
|
|
005f3bc3d5 | ||
|
|
13180921c9 | ||
|
|
a4ea532f36 | ||
|
|
43ebd25d07 | ||
|
|
eb29945cb7 | ||
|
|
cb3a32cdfb | ||
|
|
b3436a61ee | ||
|
|
bc1517598d | ||
|
|
ebba70b9d9 | ||
|
|
47b80102a8 | ||
|
|
a2fa2c8ceb | ||
|
|
4678d87e33 |
@@ -232,7 +232,98 @@
|
||||
"Bash(cmd /c \"call \\\\\"C:\\\\\\\\Program Files\\\\\\\\Microsoft Visual Studio\\\\\\\\2022\\\\\\\\Community\\\\\\\\VC\\\\\\\\Auxiliary\\\\\\\\Build\\\\\\\\vcvars64.bat\\\\\" && cmake --build C:\\\\\\\\Projects\\\\\\\\CLionProjects\\\\\\\\ANSCORE\\\\\\\\cmake-build-release --target ANSLicensingSystem\")",
|
||||
"PowerShell($vcvars = \"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Auxiliary\\\\Build\\\\vcvars64.bat\"; cmd /c \"`\"$vcvars`\" && cmake --build C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release --target ANSLicensingSystem 2>&1\" 2>&1 | Select-Object -Last 120)",
|
||||
"Bash(grep -rn \"^using namespace std\" \"C:/ANSLibs/anslicensing/\" 2>/dev/null | head -5; grep -rn \"^using namespace std\" \"C:/Projects/CLionProjects/ANSCORE/core/anslicensing/\" 2>/dev/null | head -5)",
|
||||
"PowerShell(Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile','-Command',\"try { Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace root\\\\wmi | Select-Object InstanceName,CurrentTemperature | Out-File C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt } catch { '$_' | Out-File C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt }\" -Wait; Get-Content C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt)"
|
||||
"PowerShell(Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile','-Command',\"try { Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace root\\\\wmi | Select-Object InstanceName,CurrentTemperature | Out-File C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt } catch { '$_' | Out-File C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt }\" -Wait; Get-Content C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release\\\\_smoke\\\\thermal.txt)",
|
||||
"Bash(ls \"C:/Projects/AIVISION/RTM_POSE\")",
|
||||
"Bash(ls C:/Projects/AIVISION/ANSLittering 2>&1 | head -50)",
|
||||
"WebFetch(domain:www.example-code.com)",
|
||||
"Bash(find / -name \"CkHttp.h\" 2>/dev/null | head; echo \"---\"; find / -name \"CkRest.h\" 2>/dev/null | head)",
|
||||
"Bash(ls cmake-build-* build out)",
|
||||
"Bash(ls CMakePresets.json)",
|
||||
"Bash(cmake --build . --target ANSUtilities)",
|
||||
"Bash(cmd /c '\"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Auxiliary\\\\Build\\\\vcvars64.bat\" && cmake --build . --target ANSUtilities')",
|
||||
"Bash(ls \"C:/Projects/CLionProjects/AIBOX\" 2>&1 | head -30)",
|
||||
"mcp__desktop-commander__list_directory",
|
||||
"mcp__desktop-commander__read_file",
|
||||
"PowerShell(& \"C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\build_ansutil.bat\" 2>&1)",
|
||||
"Bash(ls -la /c/Projects/ANSVIS 2>/dev/null || echo \"ANSVIS directory does not exist\")",
|
||||
"PowerShell($cmake = \"C:\\\\Users\\\\nghia\\\\AppData\\\\Local\\\\Programs\\\\CLion 2026.1\\\\bin\\\\cmake\\\\win\\\\x64\\\\bin\\\\cmake.exe\"; & $cmake --build \"C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release-clangcl\" --target ANSUtilities -j 8 2>&1 | Select-Object -Last 40)",
|
||||
"Bash(cmake --build C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\cmake-build-release-clangcl --target ANSODEngine -j 8)",
|
||||
"Bash(cmake --build \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release-clangcl\" --target ANSODEngine -j 8)",
|
||||
"Bash(cmake --build \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release-clangcl\" --target all -j 8)",
|
||||
"Bash(cmake --build \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release\" --target ANSODEngine -j 8)",
|
||||
"Bash(cmd.exe /c 'call \"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Auxiliary\\\\Build\\\\vcvarsall.bat\" x64 >nul && cmake --build \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release\" --target ANSODEngine -j 8')",
|
||||
"PowerShell($ErrorActionPreference = 'Continue'; cmd /c '\"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Auxiliary\\\\Build\\\\vcvarsall.bat\" x64 >nul 2>&1 && set' | Where-Object { $_ -match '^\\(PATH|INCLUDE|LIB|LIBPATH|VC|WindowsSdk|UCRT|VSCMD_\\)' } | ForEach-Object { $name, $value = $_ -split '=', 2; [Environment]::SetEnvironmentVariable\\($name, $value\\) }; cmake --build \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release\" --target ANSODEngine -j 8 2>&1 | Select-Object -Last 30)",
|
||||
"Bash(sleep 20 && cat \"C:/Users/nghia/AppData/Local/Temp/clear-elevated.txt\" 2>&1 | grep -E \"\\(clear-flag|before clear|with clear|after clear|RESULT|EvtClearLog\\)\" | head -20)",
|
||||
"Bash(ls \"C:\\\\Projects\\\\SharedCore\")",
|
||||
"Bash(ls \"C:\\\\Projects\\\\SharedCore\\\\ep\")",
|
||||
"PowerShell(Get-ChildItem \"C:\\\\Projects\\\\SharedCore\\\\ep\\\\directml\" | Select-Object Name, Length, @{n='Ver';e={$_.VersionInfo.FileVersion}})",
|
||||
"PowerShell(& \"C:\\\\Projects\\\\CLionProjects\\\\ANSCORE\\\\tools\\\\Check-SharedCoreVersions.ps1\" -Root \"C:\\\\Projects\\\\SharedCore\" -CompareWith \"C:\\\\ProgramData\\\\ANSCENTER\\\\Shared\")",
|
||||
"PowerShell(Write-Output \"=== SSH dir contents ===\"; if \\(Test-Path \"$env:USERPROFILE\\\\.ssh\"\\) { Get-ChildItem \"$env:USERPROFILE\\\\.ssh\" -Force | Select-Object Name, Length } else { Write-Output \"No .ssh directory\" }; Write-Output \"=== ssh-agent service ===\"; Get-Service ssh-agent | Select-Object Name, Status, StartType; Write-Output \"=== git remote ===\"; git -C C:\\\\Projects\\\\CLionProjects\\\\ANSCORE remote -v)",
|
||||
"Read(//c/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/**)",
|
||||
"Read(//c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/**)",
|
||||
"Bash(tasklist)",
|
||||
"Bash(echo \"=== Removing stale CMake caches \\(safe: regenerated by CLion\\) ===\" *)",
|
||||
"Read(//c/ANSLibs/cudnn/**)",
|
||||
"Read(//c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/include/**)",
|
||||
"Read(//c/Program Files \\(x86\\)/Intel/oneAPI/**)",
|
||||
"Read(//c/Program Files \\(x86\\)/**)",
|
||||
"Bash('C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/dumpbin.exe' /SYMBOLS C:/ANSLibs/faiss/lib/faiss.lib)",
|
||||
"Bash(winget --version)",
|
||||
"Bash(winget search *)",
|
||||
"Bash(winget install *)",
|
||||
"Bash('C:/Program Files \\(x86\\)/Microsoft Visual Studio/Installer/vswhere.exe' -latest -property installationVersion)",
|
||||
"Bash('C:/Program Files \\(x86\\)/Microsoft Visual Studio/Installer/vswhere.exe' -latest -property displayName)",
|
||||
"Bash('C:/Program Files \\(x86\\)/Microsoft Visual Studio/Installer/vswhere.exe' -latest -property catalog_productDisplayVersion)",
|
||||
"Bash(winget list *)",
|
||||
"Bash(\"C:/Program Files \\(x86\\)/Microsoft Visual Studio/Installer/vswhere.exe\" -latest -property channelId)",
|
||||
"Bash(./vs_installer.exe update *)",
|
||||
"Bash(echo \"launch exit: $?\")",
|
||||
"Bash('C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/dumpbin.exe' /ARCHIVEMEMBERS C:/ANSLibs/ODHUBYOLODarknet/lib/odhublib.lib)",
|
||||
"Bash('C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/dumpbin.exe' /HEADERS C:/ANSLibs/ODHUBYOLODarknet/lib/odhublib.lib)",
|
||||
"Read(//c/ANSLibs/TensorRT/lib/**)",
|
||||
"Read(//c/ANSLibs/TensorRT/include/**)",
|
||||
"Bash(ls -la --block-size=M nvinfer*.dll nvonnx*.dll)",
|
||||
"Bash(stat -c '%n %s bytes' nvinfer*.dll nvonnx*.dll)",
|
||||
"Bash(cd \"C:/Projects/SharedCore\" *)",
|
||||
"Bash(cd \"C:/Projects/CLionProjects/ANSCORE\" *)",
|
||||
"Read(//c/ANSLibs/**)",
|
||||
"Read(//c/Windows/System32/**)",
|
||||
"Bash(grep -niE \"ep/|ep\\\\\\\\\\\\\\\\|libraryDir|AddDllDirectory|SetDllDirectory|LoadLibrary|directml|openvino|cuda|cpu|subdir|\\\\\\\\\\\\\"ep\\\\\\\\\\\\\"|selectEP|chooseEP|provider\" EPLoader.cpp)",
|
||||
"Bash(grep -viE \"^\\\\s*//|comment\")",
|
||||
"Bash(echo \"=== Search for a 1.24 ONNX Runtime SDK \\(headers/lib\\) anywhere on disk ===\" *)",
|
||||
"WebSearch",
|
||||
"WebFetch(domain:github.com)",
|
||||
"WebFetch(domain:raw.githubusercontent.com)",
|
||||
"WebFetch(domain:onnxruntime.ai)",
|
||||
"Bash([ -f \"$CM/OpenVINOTargets-debug.cmake\" ])",
|
||||
"Bash(mv C:/ANSLibs/OpenVINO/runtime/cmake/OpenVINOTargets-debug.cmake C:/ANSLibs/OpenVINO/runtime/cmake/OpenVINOTargets-debug.cmake.disabled)",
|
||||
"Bash(xargs -n1 basename)",
|
||||
"PowerShell(cmd /c 'set \"PATH=C:\\\\ANSLibs\\\\Python311;C:\\\\ANSLibs\\\\Python311\\\\Scripts;%PATH%\" && call \"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Auxiliary\\\\Build\\\\vcvars64.bat\" >nul && call \"C:\\\\ANSLibs\\\\OpenVINO\\\\setupvars.bat\" >nul && cd /d C:\\\\Projects\\\\onnxruntime-ov && build.bat --update --config Release --use_openvino GPU --build_shared_lib --skip_tests --cmake_generator \"Visual Studio 17 2022\" 2>&1')",
|
||||
"Bash(ls \"C:/Program *)",
|
||||
"Bash(\"C:/Program Files/CMake/bin/cmake.exe\" --version)",
|
||||
"Read(//c/Program Files/JetBrains/CLion 2026.1.3/bin/ninja/win/x64/**)",
|
||||
"Bash(\"C:/Program Files/JetBrains/CLion 2026.1.3/bin/ninja/win/x64/ninja.exe\" -C \"C:/Projects/CLionProjects/ANSCORE/cmake-build-release\" -n)",
|
||||
"Bash(sed -n '462,466p' core/ANSLibsLoader/EPLoader.cpp)",
|
||||
"Bash(sed -n '576,581p' engines/ONNXEngine/ONNXEngine.cpp)",
|
||||
"Bash(sed -n '63,66p' modules/ANSODEngine/ANSONNXCL.cpp)",
|
||||
"Bash(awk 'NR>=1240 && NR<=1322 && /::|void |int |bool |Initialize|Detect|Run|LoadModel|Inference/{last=NR\": \"$0} END{}' modules/ANSODEngine/ANSFaceDetectorEngine.cpp)",
|
||||
"Bash(grep -viE \"//|comment\")",
|
||||
"Bash(sed -n '1,40p' tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp)",
|
||||
"Bash(awk '/int main[ ]*\\\\\\(/{f=1} f{print NR\": \"$0} f&&/^}/{exit}' tests/ANSFR-UnitTest/ANSFR-UnitTest.cpp)",
|
||||
"Bash(cmd /c \"C:\\\\\\\\Projects\\\\\\\\CLionProjects\\\\\\\\ANSCORE\\\\\\\\tools\\\\\\\\_run_frtest.bat\")",
|
||||
"Bash(mv __TRACKED_VAR__/ANSFR.dll.working __TRACKED_VAR__/ANSFR.dll)",
|
||||
"Bash(md5sum __TRACKED_VAR__/ANSFR.dll)",
|
||||
"Bash(BIN=\"C:/Projects/CLionProjects/ANSCORE/cmake-build-release/bin\" *)",
|
||||
"Bash(echo \"=== first 30 lines \\(structure\\) ===\")",
|
||||
"Read(//c/Users/Neo/Downloads/**)",
|
||||
"Bash(echo \"\")",
|
||||
"Bash(echo \"=== key error markers ===\")",
|
||||
"Bash(sed -n '695,725p' modules/ANSODEngine/SCRFDFaceDetector.cpp)",
|
||||
"Bash(sed -n '160,210p' modules/ANSODEngine/NV12PreprocessHelper.cpp)",
|
||||
"Bash(sed -n '1,12p' modules/ANSODEngine/SCRFDFaceDetector.cpp)",
|
||||
"Bash(sed -n '1,12p' modules/ANSODEngine/NV12PreprocessHelper.cpp)",
|
||||
"Bash(sed -n '188,205p' modules/ANSODEngine/NV12PreprocessHelper.cpp)",
|
||||
"Bash('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/cuobjdump.exe' C:/Projects/ANSTrainingTools/ODHUB/darknet/build/darknet/x64/odhublib.dll)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,14 @@ if(CMAKE_CUDA_COMPILER)
|
||||
set(ANSCORE_HAS_CUDA ON)
|
||||
set(CMAKE_CUDA_STANDARD 20)
|
||||
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CUDA_ARCHITECTURES 75 80 86 87 88 89 90 100)
|
||||
# SASS (-real) for each shipping arch from Turing (sm_75) through Blackwell
|
||||
# consumer (sm_120), plus compute_75 PTX (-virtual) so any newer/unlisted GPU
|
||||
# JIT-compiles at first run (forward compatibility). NOTE: this only governs
|
||||
# this project's own .cu files; prebuilt deps (odhublib, TensorRT, ORT, cuBLAS)
|
||||
# carry their own arch coverage independently.
|
||||
set(CMAKE_CUDA_ARCHITECTURES
|
||||
75-real 80-real 86-real 87-real 88-real 89-real 90-real 100-real 120-real
|
||||
75-virtual)
|
||||
if(MSVC)
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --use-fast-math -Xcompiler=/utf-8")
|
||||
else()
|
||||
@@ -36,6 +43,12 @@ set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# ANSCORE uses no C++20 modules. CMake auto-enables module dependency scanning
|
||||
# for C++20 + Ninja, which adds a fragile per-TU scan/dyndep (.ddi/.modmap) step
|
||||
# that can fail (empty .ddi -> "cannot open ...modmap" / dyndep parse errors),
|
||||
# especially after an interrupted build. Disable it: faster builds, no dyndep.
|
||||
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
|
||||
|
||||
# Output all binaries to a single directory
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
@@ -9,10 +9,76 @@
|
||||
|
||||
#include "ANSLicense.h" // ANS_DBG macro (gated by ANSCORE_DEBUGVIEW)
|
||||
|
||||
#include <cstdarg>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
extern "C" {
|
||||
#include "libavutil/imgutils.h"
|
||||
#include "libavutil/buffer.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/log.h"
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// FFmpeg error-log bridge — corruption detection for hwaccel decode.
|
||||
//
|
||||
// On slice loss the HEVC decoder logs "First slice in a frame missing" /
|
||||
// "Could not find ref with POC n" at AV_LOG_ERROR, but with hwaccel (NVDEC)
|
||||
// it does NOT set AVFrame::decode_error_flags — verified empirically — so
|
||||
// frame-level inspection cannot see the corruption. This bridge installs a
|
||||
// process-wide av_log callback that maps the logging AVCodecContext back to
|
||||
// its CVideoDecoder and latches a per-decoder corruption flag, which
|
||||
// readFrame() consumes to re-arm the keyframe gate.
|
||||
//
|
||||
// Notes: with hwaccel the decoder runs single-threaded, so the logging ctx
|
||||
// is exactly our AVCodecContext (SW frame-threading logs from per-thread
|
||||
// clones and would not match — those paths set decode_error_flags instead).
|
||||
// The callback chains to av_log_default_callback so console output remains.
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace {
|
||||
std::mutex s_logBridgeMutex;
|
||||
std::unordered_map<void*, std::atomic<bool>*> s_logBridgeMap; // AVCodecContext* → corrupt flag
|
||||
|
||||
void ansAvLogBridge(void* ptr, int level, const char* fmt, va_list vl)
|
||||
{
|
||||
if (ptr && level <= AV_LOG_ERROR) {
|
||||
bool latched = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_logBridgeMutex);
|
||||
auto it = s_logBridgeMap.find(ptr);
|
||||
if (it != s_logBridgeMap.end()) {
|
||||
it->second->store(true, std::memory_order_relaxed);
|
||||
latched = true;
|
||||
}
|
||||
}
|
||||
if (latched) {
|
||||
// Show exactly which decoder-context error latched the corrupt
|
||||
// flag — av_log_default_callback may filter it out (global log
|
||||
// level), which would otherwise make gate arms look causeless.
|
||||
va_list vc;
|
||||
va_copy(vc, vl);
|
||||
fprintf(stderr, "[FFmpeg-latch] ");
|
||||
vfprintf(stderr, fmt, vc);
|
||||
va_end(vc);
|
||||
}
|
||||
}
|
||||
av_log_default_callback(ptr, level, fmt, vl);
|
||||
}
|
||||
|
||||
void registerLogBridge(void* codecCtx, std::atomic<bool>* corruptFlag)
|
||||
{
|
||||
static std::once_flag s_installOnce;
|
||||
std::call_once(s_installOnce, []() { av_log_set_callback(ansAvLogBridge); });
|
||||
std::lock_guard<std::mutex> lk(s_logBridgeMutex);
|
||||
s_logBridgeMap[codecCtx] = corruptFlag;
|
||||
}
|
||||
|
||||
void unregisterLogBridge(void* codecCtx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_logBridgeMutex);
|
||||
s_logBridgeMap.erase(codecCtx);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -428,6 +494,10 @@ void CVideoDecoder::uninit()
|
||||
m_pContext->hw_device_ctx = NULL;
|
||||
}
|
||||
|
||||
// Stop the av_log bridge from touching this decoder's flag BEFORE the
|
||||
// context is destroyed (the map key is the context pointer).
|
||||
unregisterLogBridge(m_pContext);
|
||||
|
||||
// FIXED: Close codec before freeing context
|
||||
avcodec_close(m_pContext);
|
||||
avcodec_free_context(&m_pContext);
|
||||
@@ -602,6 +672,13 @@ BOOL CVideoDecoder::init(enum AVCodecID codec, uint8* extradata, int extradata_s
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Route this context's FFmpeg error logs to our corruption flag so the
|
||||
// keyframe gate can react to slice loss on the hwaccel path (which never
|
||||
// sets decode_error_flags). Unregistered in uninit() before the context
|
||||
// is freed.
|
||||
m_bCorruptSeen.store(false, std::memory_order_relaxed);
|
||||
registerLogBridge(m_pContext, &m_bCorruptSeen);
|
||||
|
||||
// Debug: one-shot visibility into which decoder actually got opened.
|
||||
// m_bHardwareDecoderEnabled is set by hwDecoderInit() on success; when
|
||||
// hwMode == HW_DECODING_DISABLE or hwDecoderInit failed, it stays FALSE
|
||||
@@ -761,6 +838,10 @@ void CVideoDecoder::Start() {
|
||||
if (m_pContext) {
|
||||
avcodec_flush_buffers(m_pContext);
|
||||
}
|
||||
// Re-arm keyframe gating: after a flush the DPB is empty, so wait for the
|
||||
// next IDR before delivering frames again (avoids post-restart green/blocky).
|
||||
m_bWaitKeyframe = true;
|
||||
m_nKeyframeWaitCount = 0;
|
||||
m_bRunning = TRUE;
|
||||
log_print(HT_LOG_INFO, "%s, Video decoder started\r\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1093,6 +1174,99 @@ BOOL CVideoDecoder::readFrame()
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mid-stream corruption gating — re-arm the keyframe gate on decode errors.
|
||||
//
|
||||
// Packet loss on lossy links (Wi-Fi cameras) drops slices mid-GOP:
|
||||
// FFmpeg logs "First slice in a frame missing" / "Could not find ref
|
||||
// with POC n" and conceals the damage. Every subsequent frame in the
|
||||
// GOP references the concealed one, so rather than display green/
|
||||
// blocky garbage until the next IDR, drop the frame and re-arm the
|
||||
// keyframe gate — the display holds the last clean frame and resumes
|
||||
// on the next clean keyframe.
|
||||
//
|
||||
// Two detection signals, both required:
|
||||
// • decode_error_flags — set by SW decode paths (H.264 always,
|
||||
// HEVC frame-threaded).
|
||||
// • m_bCorruptSeen — latched by the av_log bridge; the ONLY signal
|
||||
// on the hwaccel (NVDEC) path, which logs the error but leaves
|
||||
// decode_error_flags at 0 (verified empirically).
|
||||
const bool corruptByFlags = (m_pFrame->decode_error_flags != 0);
|
||||
const bool corruptByBridge = m_bCorruptSeen.exchange(false, std::memory_order_relaxed);
|
||||
const bool frameCorrupt = corruptByFlags || corruptByBridge;
|
||||
if (frameCorrupt) {
|
||||
if (!m_bWaitKeyframe.load(std::memory_order_relaxed)) {
|
||||
m_bWaitKeyframe.store(true, std::memory_order_relaxed);
|
||||
m_nKeyframeWaitCount = 0;
|
||||
log_print(HT_LOG_WARN,
|
||||
"%s, corrupt frame (decode_error_flags=0x%x) -- gating until next keyframe\r\n",
|
||||
__FUNCTION__, m_pFrame->decode_error_flags);
|
||||
// Also to stderr so it appears next to FFmpeg's own [hevc @ ...]
|
||||
// error lines (log_print goes to the log file, which unit tests
|
||||
// and field debugging sessions usually don't have open).
|
||||
fprintf(stderr, "[MediaClient] corrupt frame detected (flags=0x%x bridge=%d) -- gating until next keyframe\n",
|
||||
m_pFrame->decode_error_flags, (int)corruptByBridge);
|
||||
ANS_DBG("MEDIA_Decode",
|
||||
"corrupt frame (decode_error_flags=0x%x) — re-arming keyframe gate",
|
||||
m_pFrame->decode_error_flags);
|
||||
} else {
|
||||
// Count corrupt drops toward the safety valve so a stream that
|
||||
// is corrupt for a long stretch eventually shows *something*
|
||||
// (concealed frames) instead of freezing indefinitely.
|
||||
++m_nKeyframeWaitCount;
|
||||
}
|
||||
if (m_nKeyframeWaitCount < 300) {
|
||||
av_frame_unref(m_pFrame);
|
||||
continue;
|
||||
}
|
||||
// Safety valve tripped: fall through and let the frame pass
|
||||
// (concealment artifacts beat a permanently frozen display).
|
||||
m_bWaitKeyframe.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// Startup keyframe gating — discard everything until the first IDR.
|
||||
//
|
||||
// On (re)connect we join the stream mid-GOP. Until a keyframe arrives,
|
||||
// every frame references pictures we never received; the decoder (and
|
||||
// NVDEC especially) conceals them into green / blocky garbage and reports
|
||||
// success, so there is no error flag to test. Waiting for the first
|
||||
// keyframe gives a clean intra reference, after which inter frames decode
|
||||
// correctly. This is the standard RTSP "wait for IDR" behaviour.
|
||||
//
|
||||
// Keyframe flag is set from the bitstream parse and is reliable for both
|
||||
// SW and HW decode (it does not depend on the HW surface). pict_type is a
|
||||
// fallback. The counter is a safety valve: if a stream never advertises a
|
||||
// keyframe within ~300 frames (~10 s @30fps) we stop gating rather than
|
||||
// blank the display forever.
|
||||
if (m_bWaitKeyframe.load(std::memory_order_relaxed)) {
|
||||
// pict_type==I is version-independent and set for HEVC IDR/I frames
|
||||
// on both SW and HW decode. AV_FRAME_FLAG_KEY (FFmpeg 5.1+) is added
|
||||
// when available for robustness; guarded so it also builds against
|
||||
// the older vendored headers that predate that flag.
|
||||
bool isKey = (m_pFrame->pict_type == AV_PICTURE_TYPE_I);
|
||||
#if defined(AV_FRAME_FLAG_KEY)
|
||||
isKey = isKey || ((m_pFrame->flags & AV_FRAME_FLAG_KEY) != 0);
|
||||
#endif
|
||||
if (isKey) {
|
||||
m_bWaitKeyframe.store(false, std::memory_order_relaxed);
|
||||
ANS_DBG("MEDIA_Decode",
|
||||
"keyframe acquired after %d dropped frame(s) — resuming output",
|
||||
m_nKeyframeWaitCount);
|
||||
if (m_nKeyframeWaitCount > 0) {
|
||||
fprintf(stderr, "[MediaClient] keyframe acquired after %d dropped frame(s) -- resuming\n",
|
||||
m_nKeyframeWaitCount);
|
||||
}
|
||||
} else if (++m_nKeyframeWaitCount >= 300) {
|
||||
m_bWaitKeyframe.store(false, std::memory_order_relaxed);
|
||||
ANS_DBG("MEDIA_Decode",
|
||||
"no keyframe after %d frames — releasing gate (safety valve)",
|
||||
m_nKeyframeWaitCount);
|
||||
} else {
|
||||
// Pre-IDR frame: drop it (would render as green/blocky garbage).
|
||||
av_frame_unref(m_pFrame);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pFrame->format == m_hwPixFmt)
|
||||
{
|
||||
// CUDA HW accel: clone the HW frame BEFORE transfer so inference
|
||||
|
||||
@@ -165,6 +165,19 @@ private:
|
||||
std::atomic<BOOL> m_bRunning;
|
||||
BOOL m_bHardwareDecoderEnabled; // Track if hardware decoder is enabled
|
||||
bool m_bCudaHWAccel; // true when using AV_HWDEVICE_TYPE_CUDA
|
||||
// Startup keyframe gating. On connect/reconnect we join the stream mid-GOP,
|
||||
// before the first IDR, so early frames reference data we never received and
|
||||
// the decoder conceals them (green / blocky macroblocks). We drop everything
|
||||
// until the first keyframe (clean reference point), then deliver normally.
|
||||
// The frame counter is a safety valve so a stream that never advertises a
|
||||
// keyframe can't blank the display forever.
|
||||
std::atomic<bool> m_bWaitKeyframe{ true }; // true until first IDR after (re)start
|
||||
int m_nKeyframeWaitCount{ 0 }; // frames dropped while waiting
|
||||
// Latched by the av_log bridge (video_decoder.cpp) when FFmpeg logs a decode
|
||||
// error for this decoder's AVCodecContext. Needed because hwaccel (NVDEC)
|
||||
// decode does NOT set AVFrame::decode_error_flags on slice loss — the log
|
||||
// is the only corruption signal on that path. Consumed by readFrame().
|
||||
std::atomic<bool> m_bCorruptSeen{ false };
|
||||
int m_hwGpuIndex; // GPU index assigned by HWDecoderPool (-1 = legacy)
|
||||
AVFrame* m_pCudaHWFrame; // Cloned CUDA HW frame (device ptrs) for inference
|
||||
const AVCodec* m_pCodec;
|
||||
|
||||
@@ -1405,6 +1405,80 @@ cv::Mat CVideoPlayer::avframeNV12ToCvMat(const AVFrame* frame)
|
||||
m_nv12OrigWidth = width;
|
||||
m_nv12OrigHeight = height;
|
||||
|
||||
// Preferred path: libyuv NV12→RGB24 (BGR in memory, matches cv::Mat).
|
||||
// SIMD (SSSE3/AVX2) and ~3-5x faster than sws_scale's quality config.
|
||||
// Crucially it honors src_stride_uv, so the padded strides/height that
|
||||
// NVDEC and D3D11VA emit (e.g. 1080→1088 rows, aligned strides) convert
|
||||
// correctly — that padding is what cv::cvtColorTwoPlane mishandled,
|
||||
// reading the chroma plane at the wrong offset and rendering a green
|
||||
// cast with striped noise toward the bottom of the frame.
|
||||
// Coefficients are chosen from the frame's signalled colorspace/range,
|
||||
// mirroring initNV12SwsContext() (BT.709 for HD/4K, BT.601 for SD,
|
||||
// BT.2020 if tagged). The constants map studio-range YUV to full-range
|
||||
// BGR, so the result is display-ready — no manual range expansion.
|
||||
#if defined(ANSCORE_HAS_LIBYUV) && ANSCORE_HAS_LIBYUV
|
||||
{
|
||||
const bool fullRange = (frame->color_range == AVCOL_RANGE_JPEG);
|
||||
const libyuv::YuvConstants* yuvc;
|
||||
switch (frame->colorspace) {
|
||||
case AVCOL_SPC_BT470BG:
|
||||
case AVCOL_SPC_SMPTE170M:
|
||||
yuvc = fullRange ? &libyuv::kYuvJPEGConstants : &libyuv::kYuvI601Constants;
|
||||
break;
|
||||
case AVCOL_SPC_BT2020_NCL:
|
||||
case AVCOL_SPC_BT2020_CL:
|
||||
yuvc = fullRange ? &libyuv::kYuvV2020Constants : &libyuv::kYuv2020Constants;
|
||||
break;
|
||||
case AVCOL_SPC_BT709:
|
||||
yuvc = fullRange ? &libyuv::kYuvF709Constants : &libyuv::kYuvH709Constants;
|
||||
break;
|
||||
default:
|
||||
// Auto-detect by resolution (matches initNV12SwsContext()).
|
||||
if (width >= 1280 || height >= 720)
|
||||
yuvc = fullRange ? &libyuv::kYuvF709Constants : &libyuv::kYuvH709Constants;
|
||||
else
|
||||
yuvc = fullRange ? &libyuv::kYuvJPEGConstants : &libyuv::kYuvI601Constants;
|
||||
break;
|
||||
}
|
||||
cv::Mat bgrImage(height, width, CV_8UC3);
|
||||
int ret = libyuv::NV12ToRGB24Matrix(
|
||||
frame->data[0], frame->linesize[0],
|
||||
frame->data[1], frame->linesize[1],
|
||||
bgrImage.data, static_cast<int>(bgrImage.step),
|
||||
yuvc, width, height);
|
||||
if (ret == 0) {
|
||||
return bgrImage;
|
||||
}
|
||||
ANS_DBG("MEDIA_Convert",
|
||||
"libyuv NV12ToRGB24 failed (ret=%d) — falling back to sws_scale", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Fallback path: sws_scale via the dedicated NV12→BGR24 context. Also
|
||||
// stride-safe (honors frame->linesize[]) and colorspace/range-correct;
|
||||
// used on non-libyuv builds or if libyuv ever reports an error.
|
||||
{
|
||||
// Dedicated lock (not _mutex) so close()/dtor cannot free the context
|
||||
// mid-scale, while still keeping onVideoFrame off the hot _mutex.
|
||||
std::lock_guard<std::mutex> nv12Lock(m_nv12SwsMutex);
|
||||
initNV12SwsContext(frame);
|
||||
if (m_nv12SwsCtx) {
|
||||
cv::Mat bgrImage(height, width, CV_8UC3);
|
||||
uint8_t* dst[1] = { bgrImage.data };
|
||||
int dstStride[1] = { static_cast<int>(bgrImage.step[0]) };
|
||||
int ret = sws_scale(m_nv12SwsCtx, frame->data, frame->linesize, 0,
|
||||
height, dst, dstStride);
|
||||
if (ret > 0) {
|
||||
return bgrImage;
|
||||
}
|
||||
ANS_DBG("MEDIA_Convert",
|
||||
"NV12 sws_scale failed (ret=%d) — falling back to cvtColorTwoPlane", ret);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: OpenCV two-plane conversion. Correct only when the planes
|
||||
// are unpadded (linesize == width); kept for builds/inputs where the
|
||||
// sws context could not be created.
|
||||
cv::Mat yPlane(height, width, CV_8UC1, frame->data[0], frame->linesize[0]);
|
||||
cv::Mat uvPlane(height / 2, width / 2, CV_8UC2, frame->data[1], frame->linesize[1]);
|
||||
|
||||
@@ -2200,9 +2274,14 @@ CVideoPlayer::~CVideoPlayer()
|
||||
sws_freeContext(swsCtx);
|
||||
swsCtx = nullptr;
|
||||
}
|
||||
if (m_nv12SwsCtx != nullptr) {
|
||||
sws_freeContext(m_nv12SwsCtx);
|
||||
m_nv12SwsCtx = nullptr;
|
||||
{
|
||||
// Lock order: _mutex (held) → m_nv12SwsMutex. Protects against a
|
||||
// consumer thread still inside avframeNV12ToCvMat's sws_scale.
|
||||
std::lock_guard<std::mutex> nv12Lock(m_nv12SwsMutex);
|
||||
if (m_nv12SwsCtx != nullptr) {
|
||||
sws_freeContext(m_nv12SwsCtx);
|
||||
m_nv12SwsCtx = nullptr;
|
||||
}
|
||||
}
|
||||
if (this->_tjInstance) {
|
||||
tjDestroy(this->_tjInstance);
|
||||
|
||||
@@ -428,6 +428,13 @@ protected:
|
||||
int m_nv12LastWidth = 0, m_nv12LastHeight = 0;
|
||||
int m_nv12LastColorspace = -1;
|
||||
int m_nv12LastRange = -1;
|
||||
// Guards m_nv12SwsCtx create/use/free. The NV12→BGR conversion deliberately
|
||||
// runs WITHOUT _mutex (see avframeToCvMat, commit "Fix RTSP stall by
|
||||
// releasing _mutex during BGR conversion"), so this dedicated lock protects
|
||||
// the context against close()/dtor freeing it mid-sws_scale without
|
||||
// reintroducing contention with onVideoFrame. Lock order: _mutex → this
|
||||
// (close()/dtor hold _mutex first); avframeNV12ToCvMat takes only this lock.
|
||||
std::mutex m_nv12SwsMutex;
|
||||
|
||||
void initSwsContext(int width, int height, AVPixelFormat pixFmt, AVPixelFormat outputPixFmt = AV_PIX_FMT_YUVJ420P);
|
||||
void initNV12SwsContext(const AVFrame* frame);
|
||||
|
||||
@@ -197,16 +197,31 @@ BOOL h264_data_rx(H264RXI * p_rxi, uint8 * p_data, int len)
|
||||
|
||||
if (p_rxi->rtprxi.rxf_loss)
|
||||
{
|
||||
// Packet loss, until the next start packet
|
||||
|
||||
if (!beginPacket)
|
||||
// Packet loss — resume ONLY at an access-unit boundary (see the
|
||||
// H.265 counterpart in h265_rtp_rx.cpp for the full rationale).
|
||||
// Resuming at a mere NAL/FU start delivers frames missing their
|
||||
// leading slices on multi-slice streams. An AU boundary is a
|
||||
// non-VCL NAL (SEI/SPS/PPS/AUD, type >= 6) or a VCL slice whose
|
||||
// first_mb_in_slice == 0 — ue(v)-coded, so value 0 is a single
|
||||
// '1' bit: MSB of the byte after the 1-byte NAL header.
|
||||
BOOL auStart = FALSE;
|
||||
if (beginPacket)
|
||||
{
|
||||
uint8* payload = headerStart + numBytesToSkip;
|
||||
int payloadLen = (int)packetSize - (int)numBytesToSkip;
|
||||
if (payloadLen >= 2)
|
||||
{
|
||||
uint8 nt = payload[0] & 0x1F;
|
||||
if (nt >= 6) auStart = TRUE; // non-VCL
|
||||
else if (payload[1] & 0x80) auStart = TRUE; // first_mb_in_slice == 0
|
||||
}
|
||||
}
|
||||
if (!auStart)
|
||||
{
|
||||
p_rxi->d_offset = 0;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_rxi->rtprxi.rxf_loss = 0;
|
||||
}
|
||||
p_rxi->rtprxi.rxf_loss = 0;
|
||||
}
|
||||
|
||||
// save the H264 parameter sets
|
||||
|
||||
@@ -265,16 +265,35 @@ BOOL h265_data_rx(H265RXI * p_rxi, uint8 * p_data, int len)
|
||||
|
||||
if (p_rxi->rtprxi.rxf_loss)
|
||||
{
|
||||
// Packet loss, until the next start packet
|
||||
|
||||
if (!beginPacket)
|
||||
// Packet loss — resume ONLY at an access-unit boundary.
|
||||
//
|
||||
// The old behaviour resumed at the next NAL/FU start, but with
|
||||
// multi-slice frames every slice starts a NAL, so reassembly resumed
|
||||
// MID-FRAME and delivered access units missing their leading slices.
|
||||
// The decoder then logs "First slice in a frame missing" / "Ignoring
|
||||
// POC change between slices" and conceals the damage as green/blocky
|
||||
// garbage. An AU boundary is either a non-VCL NAL (VPS/SPS/PPS/SEI,
|
||||
// type >= 32, which precede an IDR) or a VCL slice with
|
||||
// first_slice_segment_in_pic_flag set — the first bit after the
|
||||
// 2-byte NAL header (H.265 spec 7.3.6.1).
|
||||
BOOL auStart = FALSE;
|
||||
if (beginPacket)
|
||||
{
|
||||
uint8* payload = headerStart + numBytesToSkip;
|
||||
int payloadLen = (int)packetSize - (int)numBytesToSkip;
|
||||
if (payloadLen >= 3)
|
||||
{
|
||||
uint8 nt = (payload[0] >> 1) & 0x3F;
|
||||
if (nt >= 32) auStart = TRUE; // non-VCL (param sets/SEI)
|
||||
else if (payload[2] & 0x80) auStart = TRUE; // first slice in picture
|
||||
}
|
||||
}
|
||||
if (!auStart)
|
||||
{
|
||||
p_rxi->d_offset = 0;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_rxi->rtprxi.rxf_loss = 0;
|
||||
}
|
||||
p_rxi->rtprxi.rxf_loss = 0;
|
||||
}
|
||||
|
||||
// save the H265 parameter sets
|
||||
|
||||
@@ -106,6 +106,11 @@ BOOL rtp_data_rx(RTPRXI * p_rxi, uint8 * p_data, int len)
|
||||
{
|
||||
p_rxi->rxf_loss = 1;
|
||||
log_print(HT_LOG_WARN, "%s, prev seq[%u], cur seq[%u]!!!\r\n", __FUNCTION__, p_rxi->seq, rtpSeq);
|
||||
// stderr too (log_print goes to the log file): over TCP transport a
|
||||
// sequence gap means the SENDER (camera) skipped packets — usually
|
||||
// backpressure from a slow receiver. Gap size shows how much vanished.
|
||||
fprintf(stderr, "[RTP] seq gap: prev=%u cur=%u (lost ~%u pkt)\n",
|
||||
p_rxi->seq, rtpSeq, (uint16)(rtpSeq - p_rxi->seq - 1));
|
||||
}
|
||||
p_rxi->seq = rtpSeq;
|
||||
|
||||
|
||||
@@ -78,6 +78,30 @@ else()
|
||||
endif()
|
||||
target_compile_definitions(onnxruntime INTERFACE ORT_API_MANUAL_INIT)
|
||||
|
||||
# ── cuDNN ───────────────────────────────────────────────────────
|
||||
# TensorRT API headers (engines/TensorRTAPI) include <cudnn_version.h>, so
|
||||
# cuDNN's include dir must be on the path. cuDNN ships separately from the
|
||||
# CUDA toolkit, so wire it explicitly rather than relying on it being copied
|
||||
# into the CUDA install.
|
||||
if(NOT APPLE)
|
||||
if(WIN32)
|
||||
set(CUDNN_INCLUDE_DIR "${ANSLIBS_DIR}/cudnn/include")
|
||||
set(CUDNN_LIB_DIR "${ANSLIBS_DIR}/cudnn/lib/x64")
|
||||
else()
|
||||
set(CUDNN_INCLUDE_DIR "${ANSLIBS_DIR}/cudnn/include")
|
||||
set(CUDNN_LIB_DIR "${ANSLIBS_DIR}/cudnn/lib")
|
||||
endif()
|
||||
add_library(cudnn INTERFACE)
|
||||
target_include_directories(cudnn INTERFACE ${CUDNN_INCLUDE_DIR})
|
||||
target_link_directories(cudnn INTERFACE ${CUDNN_LIB_DIR})
|
||||
if(WIN32)
|
||||
target_link_libraries(cudnn INTERFACE cudnn.lib)
|
||||
else()
|
||||
target_link_libraries(cudnn INTERFACE cudnn)
|
||||
endif()
|
||||
message(STATUS "cuDNN: using ANSLibs at ${CUDNN_INCLUDE_DIR}")
|
||||
endif()
|
||||
|
||||
# ── TensorRT (Windows + Linux only) ────────────────────────────
|
||||
if(NOT APPLE)
|
||||
set(TENSORRT_INCLUDE_DIR "${ANSLIBS_DIR}/TensorRT/include")
|
||||
@@ -86,6 +110,9 @@ if(NOT APPLE)
|
||||
add_library(tensorrt INTERFACE)
|
||||
target_include_directories(tensorrt INTERFACE ${TENSORRT_INCLUDE_DIR})
|
||||
target_link_directories(tensorrt INTERFACE ${TENSORRT_LIB_DIR})
|
||||
# cuDNN is a transitive dependency of the TensorRT API headers/engine,
|
||||
# so anything linking `tensorrt` also gets cuDNN's headers and import lib.
|
||||
target_link_libraries(tensorrt INTERFACE cudnn)
|
||||
if(WIN32)
|
||||
target_link_libraries(tensorrt INTERFACE nvinfer_plugin_10.lib)
|
||||
else()
|
||||
@@ -211,9 +238,34 @@ endif()
|
||||
# ── Intel MKL ───────────────────────────────────────────────────
|
||||
add_library(mkl INTERFACE)
|
||||
if(WIN32)
|
||||
set(MKL_LIB_DIR "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/lib")
|
||||
target_link_directories(mkl INTERFACE "${MKL_LIB_DIR}")
|
||||
target_link_libraries(mkl INTERFACE mkl_rt.lib)
|
||||
# oneAPI installs under .../oneAPI/mkl/<version>/ where <version> varies
|
||||
# by install (e.g. 2025.0, 2025.3, or a "latest" junction) and the import
|
||||
# lib lives in either lib/ (newer flat layout) or lib/intel64/ (older).
|
||||
# Auto-detect rather than hardcoding so it survives MKL version bumps.
|
||||
set(MKL_LIB_DIR "")
|
||||
file(GLOB _mkl_versions "C:/Program Files (x86)/Intel/oneAPI/mkl/*")
|
||||
list(SORT _mkl_versions)
|
||||
list(REVERSE _mkl_versions) # prefer the newest version dir
|
||||
foreach(_mkl_root IN LISTS _mkl_versions)
|
||||
foreach(_sub "lib" "lib/intel64")
|
||||
if(EXISTS "${_mkl_root}/${_sub}/mkl_rt.lib")
|
||||
set(MKL_LIB_DIR "${_mkl_root}/${_sub}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
if(MKL_LIB_DIR)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
if(MKL_LIB_DIR)
|
||||
target_link_directories(mkl INTERFACE "${MKL_LIB_DIR}")
|
||||
target_link_libraries(mkl INTERFACE mkl_rt.lib)
|
||||
message(STATUS "Intel MKL: using ${MKL_LIB_DIR}")
|
||||
else()
|
||||
message(WARNING "Intel MKL not found under C:/Program Files (x86)/Intel/oneAPI/mkl. "
|
||||
"ANSFR (and ANSLIB/ANSFR-UnitTest that link it) will fail to link. "
|
||||
"Install Intel oneMKL or adjust MKL_LIB_DIR in cmake/Dependencies.cmake.")
|
||||
endif()
|
||||
else()
|
||||
# Try system MKL on Linux
|
||||
find_library(MKL_RT_LIB mkl_rt PATHS /opt/intel/oneapi/mkl/latest/lib/intel64)
|
||||
|
||||
@@ -461,7 +461,7 @@ namespace ANSCENTER {
|
||||
") returned null — the DLL may be corrupt.");
|
||||
|
||||
s_ort_api = api;
|
||||
Ort::Global<void>::api_ = api;
|
||||
Ort::InitApi(api);
|
||||
|
||||
std::cout << "[EPLoader] ORT loaded successfully." << std::endl;
|
||||
std::cout << "[EPLoader] ORT DLL version : " << base->GetVersionString() << std::endl;
|
||||
|
||||
@@ -98,6 +98,16 @@ namespace {
|
||||
return s.substr(0, 4) + std::string(s.size() - 8, '*') + s.substr(s.size() - 4);
|
||||
}
|
||||
|
||||
// The HWID emitted when WMI returns no hardware components at all (every
|
||||
// hash field is the "absent" marker). Every PC with broken WMI produces
|
||||
// this exact string, so it identifies "WMI broken" in customer logs.
|
||||
constexpr const char* kEmptyFingerprintHWID = "ESWJJ-LEEFC-CCTBB-JSSWJ-JLEEF";
|
||||
|
||||
constexpr const char* kEmptyFingerprintWarning =
|
||||
"Hardware fingerprint is EMPTY - WMI returned no hardware components on this PC. "
|
||||
"Licensing proceeds but the license is weakly bound to this machine. "
|
||||
"Repair WMI: run 'winmgmt /verifyrepository' (then 'winmgmt /salvagerepository' if inconsistent).";
|
||||
|
||||
// SDK identifier passed to ANSLSHelper for licensing-service auth. Despite
|
||||
// the variable name "privateKey" used at call sites, this is an 11-byte
|
||||
// SDK token that identifies the ANSCENTER product to the licensing
|
||||
@@ -1427,6 +1437,27 @@ namespace ANSCENTER
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
// Static, handle-free hardware id. Mirrors ANSLSHelper::GetCurrentHardwareId but has no
|
||||
// instance/_logger, so diagnostics go to DebugView via ANS_DBG. Returns "" on failure.
|
||||
std::string ANSLicenseHelper::GetHardwareId() {
|
||||
try {
|
||||
const wchar_t* hwid = KeyHelper::GetCurrentHardwareId();
|
||||
std::wstring result_t = std::wstring(hwid);
|
||||
std::string result = WString2String(result_t);
|
||||
ANS_DBG("ANSLicenseHelper", "GetHardwareId -> '%s'", result.c_str());
|
||||
return result;
|
||||
}
|
||||
catch (ANSCENTER::Licensing::Exception* ex) {
|
||||
ANS_DBG("ANSLicenseHelper", "GetHardwareId failed: %s", ex->GetExceptionMessage());
|
||||
ex->Destroy();
|
||||
return "";
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSLicenseHelper", "GetHardwareId failed: unknown exception");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool ANSLicenseHelper::isPathSafe(const std::string& pathStr) {
|
||||
// Basic safety checks - customize as needed
|
||||
if (pathStr.empty()) return false;
|
||||
@@ -2145,7 +2176,7 @@ namespace ANSCENTER
|
||||
}
|
||||
void ANSLSHelper::LoadLicense(std::string licenseKey) {
|
||||
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
std::string licenseFileName = Dash2Underscore(licenseKey)+".json";
|
||||
std::string licenseFolder = GetLicenseDir();
|
||||
@@ -2791,6 +2822,9 @@ namespace ANSCENTER
|
||||
std::wstring _registrationName = String2WString(registrationName);
|
||||
std::wstring hardwareId = KeyHelper::GetCurrentHardwareId();
|
||||
std::string _hardwareId = WString2String(hardwareId);
|
||||
if (_hardwareId == kEmptyFingerprintHWID) {
|
||||
this->_logger.LogWarn("ANSLSHelper::ValidateLicenseKey", kEmptyFingerprintWarning, __FILE__, __LINE__);
|
||||
}
|
||||
bool _overrideLicenseFile = false;
|
||||
if (activationKey.empty()) {
|
||||
if (this->_license != NULL) {// get it from there
|
||||
@@ -2867,14 +2901,13 @@ namespace ANSCENTER
|
||||
|
||||
case STATUS_INVALID_HARDWARE_ID:
|
||||
_licenseKeyStatus = INVALID_HARDWARE_ID;
|
||||
activationStatusStr = "Hardware id does not match this computer. current HWID is " + _hardwareId +
|
||||
"; client HWID is " + WString2String(licensingClient.GetHardwareId()) +
|
||||
"; Current activation key is " + WString2String(_activationKey) +
|
||||
"; client Activation key is " + WString2String(licensingClient.GetActivationKey()) +
|
||||
activationStatusStr = "Local hardware fingerprint check rejected this computer (hardware changed, or WMI returned no components). Current HWID is " + _hardwareId +
|
||||
"; stored activation key is " + mask_secret(WString2String(_activationKey)) +
|
||||
"; server activation key is " + mask_secret(WString2String(licensingClient.GetActivationKey())) +
|
||||
"; URL is " + WString2String(this->_licenseServiceURL.c_str())+
|
||||
"; ProductId is " + WString2String(wProductId) +
|
||||
"; RegistrationName is " + WString2String(_registrationName) +
|
||||
"; Status is" + std::to_string(activationStatus);
|
||||
"; Status is " + std::to_string(activationStatus);
|
||||
break;
|
||||
|
||||
case STATUS_LICENSE_EXPIRED:
|
||||
@@ -2948,7 +2981,7 @@ namespace ANSCENTER
|
||||
|
||||
if (_overrideLicenseFile) {
|
||||
this->_logger.LogDebug("ANSLSHelper::ValidateLicenseKey", "Override license key.", __FILE__, __LINE__);
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
this->_license->SetLicenseKey(_licenseKey.c_str());
|
||||
this->_license->SetLicenseKeyValidationData(validationData, validationDataLen);
|
||||
@@ -2975,7 +3008,7 @@ namespace ANSCENTER
|
||||
if (_overrideLicenseFile) {
|
||||
// Save license
|
||||
this->_logger.LogDebug("ANSLSHelper::ValidateLicenseKey", "Override license key.", __FILE__, __LINE__);
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
this->_license->SetLicenseKey(_licenseKey.c_str());
|
||||
this->_license->SetLicenseKeyValidationData(validationData, validationDataLen);
|
||||
@@ -3005,6 +3038,9 @@ namespace ANSCENTER
|
||||
std::wstring _registrationName = String2WString(registrationName);
|
||||
std::string _hardwareId = customHWID;
|
||||
std::wstring hardwareId = String2WString(customHWID);
|
||||
if (_hardwareId == kEmptyFingerprintHWID) {
|
||||
this->_logger.LogWarn("ANSLSHelper::ValidateLicenseWithCustomHWID", kEmptyFingerprintWarning, __FILE__, __LINE__);
|
||||
}
|
||||
bool _overrideLicenseFile = false;
|
||||
if (activationKey.empty()) {
|
||||
if (this->_license != NULL) {// get it from there
|
||||
@@ -3081,14 +3117,13 @@ namespace ANSCENTER
|
||||
|
||||
case STATUS_INVALID_HARDWARE_ID:
|
||||
_licenseKeyStatus = INVALID_HARDWARE_ID;
|
||||
activationStatusStr = "Hardware id does not match this computer. current HWID is " + _hardwareId +
|
||||
"; client HWID is " + WString2String(licensingClient.GetHardwareId()) +
|
||||
"; Current activation key is " + WString2String(_activationKey) +
|
||||
"; client Activation key is " + WString2String(licensingClient.GetActivationKey()) +
|
||||
activationStatusStr = "Local hardware fingerprint check rejected this computer (hardware changed, or WMI returned no components). Current HWID is " + _hardwareId +
|
||||
"; stored activation key is " + mask_secret(WString2String(_activationKey)) +
|
||||
"; server activation key is " + mask_secret(WString2String(licensingClient.GetActivationKey())) +
|
||||
"; URL is " + WString2String(this->_licenseServiceURL.c_str()) +
|
||||
"; ProductId is " + WString2String(wProductId) +
|
||||
"; RegistrationName is " + WString2String(_registrationName) +
|
||||
"; Status is" + std::to_string(activationStatus);
|
||||
"; Status is " + std::to_string(activationStatus);
|
||||
break;
|
||||
|
||||
case STATUS_LICENSE_EXPIRED:
|
||||
@@ -3162,7 +3197,7 @@ namespace ANSCENTER
|
||||
|
||||
if (_overrideLicenseFile) {
|
||||
this->_logger.LogDebug("ANSLSHelper::ValidateLicenseKey", "Override license key.", __FILE__, __LINE__);
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
this->_license->SetLicenseKey(_licenseKey.c_str());
|
||||
this->_license->SetLicenseKeyValidationData(validationData, validationDataLen);
|
||||
@@ -3189,7 +3224,7 @@ namespace ANSCENTER
|
||||
if (_overrideLicenseFile) {
|
||||
// Save license
|
||||
this->_logger.LogDebug("ANSLSHelper::ValidateLicenseKey", "Override license key.", __FILE__, __LINE__);
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
this->_license->SetLicenseKey(_licenseKey.c_str());
|
||||
this->_license->SetLicenseKeyValidationData(validationData, validationDataLen);
|
||||
@@ -3475,7 +3510,7 @@ namespace ANSCENTER
|
||||
return 0; // invalid
|
||||
}
|
||||
else {
|
||||
if (!this->_license != NULL) delete this->_license;
|
||||
if (this->_license != NULL) delete this->_license;
|
||||
this->_license = new License();
|
||||
this->_license->SetLicenseKey(_licenseKey.c_str());
|
||||
this->_license->SetLicenseKeyValidationData(validationData, validationDataLen);
|
||||
|
||||
@@ -523,6 +523,10 @@ namespace ANSCENTER
|
||||
[[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();
|
||||
|
||||
@@ -564,6 +568,13 @@ extern "C" __declspec(dllexport) void SetLicenseServiceURL(ANSCENTER::ANSLSHelpe
|
||||
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
|
||||
|
||||
@@ -109,6 +109,43 @@ extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetHardwareId(LStrHandle currentHwID) {
|
||||
try {
|
||||
std::string st = ANSCENTER::ANSLicenseHelper::GetHardwareId();
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(currentHwID, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*currentHwID)->cnt = size;
|
||||
memcpy((*currentHwID)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetHardwareIdBuffer(char* buffer, int bufferSize) {
|
||||
try {
|
||||
if (!buffer || bufferSize <= 0) return 0;
|
||||
std::string st = ANSCENTER::ANSLicenseHelper::GetHardwareId();
|
||||
int size = (int)st.length();
|
||||
if (size <= 0) return 0;
|
||||
// Need room for the string plus the null terminator.
|
||||
if (size + 1 > bufferSize) return 0;
|
||||
memcpy(buffer, st.c_str(), size);
|
||||
buffer[size] = '\0';
|
||||
return size;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !registrationName) return 0;
|
||||
|
||||
@@ -8,9 +8,11 @@ const unsigned char BitStream3::hiMask[] = { 0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0x
|
||||
|
||||
BitStream3::BitStream3() :
|
||||
ownMemory(false),
|
||||
buffer(NULL),
|
||||
bufSize(0),
|
||||
bitSize(0),
|
||||
currentBit(0),
|
||||
currentByte(0),
|
||||
buffer(NULL)
|
||||
currentByte(0)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -41,6 +43,7 @@ void BitStream3::Attach(void * buf, int bitCount)
|
||||
{
|
||||
buffer = (unsigned char *)buf;
|
||||
bitSize = bitCount;
|
||||
bufSize = (bitCount + 7) >> 3;
|
||||
currentBit = 0;
|
||||
currentByte = 0;
|
||||
}
|
||||
@@ -53,20 +56,20 @@ int BitStream3::Write(const unsigned char * buf, int bitCount)
|
||||
{
|
||||
if ((gap & 7) != 0)
|
||||
{
|
||||
buffer[currentByte] = (unsigned char)((buffer[currentByte] << gap) | (buf[0] >> (bitCount < 8 ? bitCount - gap : 8 - gap)));
|
||||
setByte(currentByte, (unsigned char)((byteAt(currentByte) << gap) | (buf[0] >> (bitCount < 8 ? bitCount - gap : 8 - gap))));
|
||||
currentBit += gap; bitCount -= gap; currentByte++;
|
||||
|
||||
for (; bitCount >= 8; i++, currentByte++, currentBit += 8, bitCount -= 8)
|
||||
buffer[currentByte] = (unsigned char)((buf[i] << gap) | (buf[i + 1] >> (8 - gap)));
|
||||
setByte(currentByte, (unsigned char)((buf[i] << gap) | (buf[i + 1] >> (8 - gap))));
|
||||
}
|
||||
else
|
||||
for (; bitCount >= 8; currentByte++, i++, currentBit += 8, bitCount -= 8)
|
||||
buffer[currentByte] = buf[i];
|
||||
setByte(currentByte, buf[i]);
|
||||
}
|
||||
|
||||
if (bitCount > 0)
|
||||
{
|
||||
buffer[currentByte] = (unsigned char)((buffer[currentByte] << bitCount) | (buf[i] & ((1 << bitCount) - 1)));
|
||||
setByte(currentByte, (unsigned char)((byteAt(currentByte) << bitCount) | (buf[i] & ((1 << bitCount) - 1))));
|
||||
currentBit += bitCount;
|
||||
}
|
||||
|
||||
@@ -86,20 +89,20 @@ int BitStream3::Read(unsigned char * readBuf, int bitCount)
|
||||
if ((gap & 7) != 0)
|
||||
{
|
||||
for (; bitCount >= 8 + 8 - gap; bitCount -= 8, currentByte++, currentBit += 8, i++)
|
||||
readBuf[i] = (unsigned char)((buffer[currentByte] << gap) | (buffer[currentByte + 1] >> (8 - gap)));
|
||||
readBuf[i] = (unsigned char)((byteAt(currentByte) << gap) | (byteAt(currentByte + 1) >> (8 - gap)));
|
||||
|
||||
// byte align
|
||||
if (bitCount > 0)
|
||||
{
|
||||
if (bitCount < 8 - gap)
|
||||
{
|
||||
readBuf[i] = (unsigned char)((buffer[currentByte] >> (8 - gap - bitCount)) & ((1 << bitCount) - 1));
|
||||
readBuf[i] = (unsigned char)((byteAt(currentByte) >> (8 - gap - bitCount)) & ((1 << bitCount) - 1));
|
||||
currentBit += bitCount;
|
||||
bitCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
readBuf[i] = (unsigned char)(buffer[currentByte] & ((1 << (8 - gap)) - 1));
|
||||
readBuf[i] = (unsigned char)(byteAt(currentByte) & ((1 << (8 - gap)) - 1));
|
||||
|
||||
bitCount -= (8 - gap);
|
||||
currentBit += (8 - gap);
|
||||
@@ -111,15 +114,15 @@ int BitStream3::Read(unsigned char * readBuf, int bitCount)
|
||||
}
|
||||
else
|
||||
for (; bitCount >= 8; bitCount -= 8, currentByte++, currentBit += 8, i++)
|
||||
readBuf[i] = buffer[currentByte];
|
||||
readBuf[i] = byteAt(currentByte);
|
||||
|
||||
// already aligned
|
||||
if (bitCount > 0)
|
||||
{
|
||||
if (currentBit + 8 <= bitSize) // not last byte
|
||||
readBuf[i] |= (unsigned char)((buffer[currentByte] >> (8 - bitCount)) & ((1 << bitCount) - 1));
|
||||
readBuf[i] |= (unsigned char)((byteAt(currentByte) >> (8 - bitCount)) & ((1 << bitCount) - 1));
|
||||
else // last byte
|
||||
readBuf[i] = (unsigned char)((buffer[currentByte] >> ((bitSize & 7) - bitCount)) & ((1 << bitCount) - 1));
|
||||
readBuf[i] = (unsigned char)((byteAt(currentByte) >> ((bitSize & 7) - bitCount)) & ((1 << bitCount) - 1));
|
||||
|
||||
currentBit += bitCount;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,20 @@ public:
|
||||
unsigned char * GetBuffer();
|
||||
|
||||
protected:
|
||||
// Bounds-safe accessors: every Write/Read goes through these so a caller
|
||||
// that under-sizes the stream can no longer corrupt the heap (the 125-vs-147
|
||||
// bug in GetCurrentHardwareId overflowed 3 bytes for years). Out-of-range
|
||||
// reads return 0 — identical to the base32 padding zeros the hardware-id
|
||||
// Match path has always effectively read there.
|
||||
unsigned char byteAt(int i) const
|
||||
{
|
||||
return (buffer && i >= 0 && i < bufSize) ? buffer[i] : 0;
|
||||
}
|
||||
void setByte(int i, unsigned char v)
|
||||
{
|
||||
if (buffer && i >= 0 && i < bufSize) buffer[i] = v;
|
||||
}
|
||||
|
||||
bool ownMemory;
|
||||
unsigned char * buffer;
|
||||
int bufSize, bitSize;
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
#include <net/if.h>
|
||||
#ifdef __linux__
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/stat.h> // stat() — physical-NIC test in linuxIsPhysicalNic
|
||||
# include <netinet/in.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <string.h> // strncmp/strlen (same test)
|
||||
|
||||
// Match Linux to FreeBSD
|
||||
# define AF_LINK AF_PACKET
|
||||
@@ -82,6 +83,47 @@ void GetCPUIDPropertyList(std::list<std::string>* propList)
|
||||
propList->push_back(buf);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
// A PHYSICAL network interface, i.e. one backed by a real hardware device.
|
||||
//
|
||||
// Why this exists: the hardware id is built from up to 6 enumerated MACs, and
|
||||
// on Linux getifaddrs() also returns VIRTUAL interfaces — docker0 and the
|
||||
// veth* pairs a container creates, tun*/wg* from a VPN, br-*/virbr* bridges.
|
||||
// Container veths get RANDOM MACs and come and go with the containers, so an
|
||||
// unfiltered enumeration can hand back a different set on every call: the id
|
||||
// changes and an activated licence silently stops matching its machine. Boxes
|
||||
// running Docker (the Coder feature) hit this routinely.
|
||||
//
|
||||
// The test mirrors what the Windows branch already does via WMI ("PNPDeviceId
|
||||
// LIKE %PCI%" — physical adapters only). /sys/class/net/<name>/device is a
|
||||
// symlink to the backing device and exists ONLY for hardware-backed
|
||||
// interfaces; virtual ones have no such link. That is the kernel's own answer,
|
||||
// so it stays correct as new virtual-interface flavours appear — unlike a name
|
||||
// denylist, which is kept only as a cheap second line of defence.
|
||||
static bool linuxIsPhysicalNic(const char* ifname)
|
||||
{
|
||||
if (ifname == NULL || ifname[0] == '\0') return false;
|
||||
|
||||
// Names that are virtual by construction. Not exhaustive on purpose — the
|
||||
// /sys check below is the real test; this only catches oddities where /sys
|
||||
// is unavailable (unusual containers, minimal namespaces).
|
||||
static const char* kVirtualPrefixes[] = {
|
||||
"lo", "docker", "veth", "br-", "virbr", "tun", "tap", "wg",
|
||||
"vmnet", "vboxnet", "zt", "ppp", "dummy", "kube", "cni", "flannel",
|
||||
"lxc", "lxd", "nerdctl", "podman", "cali", "weave"
|
||||
};
|
||||
for (const char* prefix : kVirtualPrefixes) {
|
||||
if (strncmp(ifname, prefix, strlen(prefix)) == 0) return false;
|
||||
}
|
||||
|
||||
std::string path = std::string("/sys/class/net/") + ifname + "/device";
|
||||
struct stat st;
|
||||
// stat() (not lstat) so the symlink is followed — we want "the target
|
||||
// exists", i.e. a real backing device.
|
||||
return stat(path.c_str(), &st) == 0;
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
|
||||
{
|
||||
// Head of the interface address linked list
|
||||
@@ -99,6 +141,14 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
// Collected separately so physical NICs can be preferred wholesale. Taking
|
||||
// them inline would let a veth that merely appears EARLIER in the list
|
||||
// consume one of the maxCount slots and push a real NIC out.
|
||||
std::list<std::string> physical;
|
||||
std::list<std::string> fallback;
|
||||
#endif
|
||||
|
||||
while (current != NULL && maxCount > 0) {
|
||||
|
||||
const sockaddr_in* interfaceAddress = castToIP4(current->ifa_addr);
|
||||
@@ -127,8 +177,18 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
|
||||
{
|
||||
char buf[18];
|
||||
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
|
||||
#ifdef __linux__
|
||||
// Bucket now, choose after the walk (see the lists above).
|
||||
// maxCount is NOT decremented here: the cap applies to the
|
||||
// SELECTED set, not to whatever happened to be enumerated.
|
||||
if (linuxIsPhysicalNic(current->ifa_name))
|
||||
physical.push_back(buf);
|
||||
else
|
||||
fallback.push_back(buf);
|
||||
#else
|
||||
propList->push_back(buf);
|
||||
maxCount--;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +197,21 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
|
||||
|
||||
freeifaddrs(ifap);
|
||||
ifap = NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
// Physical NICs only — that is the whole point. FAIL-SAFE: if the filter
|
||||
// found none (no /sys, an exotic NIC driver, a network namespace with only
|
||||
// virtual links) fall back to the unfiltered set rather than returning
|
||||
// nothing. An empty list would drop ALL MAC entropy from the id, and with
|
||||
// the system-UUID and disk-serial slots already constant on Linux that
|
||||
// would leave near-identical ids across different machines — far worse
|
||||
// than an id that occasionally drifts.
|
||||
std::list<std::string>& chosen = physical.empty() ? fallback : physical;
|
||||
for (std::list<std::string>::const_iterator it = chosen.begin();
|
||||
it != chosen.end() && maxCount > 0; ++it, --maxCount) {
|
||||
propList->push_back(*it);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GetHDDPropertyList(std::list<std::string>* propList, int maxCount)
|
||||
@@ -220,7 +295,13 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
WmiHelper wmi;
|
||||
#endif
|
||||
|
||||
BitStream3 bits(125);
|
||||
// 147 bits are actually written below (3 version + 9 x 16-bit hashes). The
|
||||
// previous size of 125 allocated only 16 bytes and the last two hash slots
|
||||
// overflowed the heap block by 3 bytes (asymptomatic on the Windows heap,
|
||||
// SIGSEGV under macOS malloc — found when ANSGateway enabled this code on
|
||||
// POSIX). Only the first 16 bytes feed the base32 encode, so sizing the
|
||||
// stream correctly changes no id on any platform.
|
||||
BitStream3 bits(147);
|
||||
list<string> propList;
|
||||
unsigned char version = 1;
|
||||
unsigned short hash1, hash2, hash3, hash4;
|
||||
@@ -256,6 +337,8 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
|
||||
bits.WriteUInt16(hash1);
|
||||
|
||||
bool uuidFound = (hash1 != h0);
|
||||
|
||||
// CPU IDs - get up to 4 for better resilience
|
||||
propList.clear();
|
||||
|
||||
@@ -270,6 +353,8 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
cpu = NormalizeHardwareString(cpu);
|
||||
}
|
||||
|
||||
int cpuCount = (int)propList.size();
|
||||
|
||||
hash1 = (propList.size() > 0) ? HashString(propList.front().c_str()) : h0;
|
||||
hash2 = (propList.size() > 1) ? HashString(propList.back().c_str()) : h0;
|
||||
|
||||
@@ -298,6 +383,8 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
}
|
||||
propList.sort();
|
||||
|
||||
int macCount = (int)propList.size();
|
||||
|
||||
// Store up to 4 MAC hashes
|
||||
auto macIter = propList.begin();
|
||||
hash1 = (propList.size() > 0 && macIter != propList.end()) ? HashString((macIter++)->c_str()) : h0;
|
||||
@@ -325,6 +412,8 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
}
|
||||
propList.sort();
|
||||
|
||||
int hddCount = (int)propList.size();
|
||||
|
||||
auto hddIter = propList.begin();
|
||||
hash1 = (propList.size() > 0 && hddIter != propList.end()) ? HashString((hddIter++)->c_str()) : h0;
|
||||
hash2 = (propList.size() > 1 && hddIter != propList.end()) ? HashString((hddIter++)->c_str()) : h0;
|
||||
@@ -351,11 +440,34 @@ const char* HardwareId::GetCurrentHardwareId()
|
||||
insertPos += 6;
|
||||
}
|
||||
|
||||
// Field-diagnosability: log the component availability once per distinct
|
||||
// result so support can tell a weak fingerprint from a healthy one
|
||||
static string lastLoggedHwid;
|
||||
if (hardwareId != lastLoggedHwid)
|
||||
{
|
||||
lastLoggedHwid = hardwareId;
|
||||
fprintf(stderr, "[anslicensing] hardware id %s (components: uuid=%s cpu=%d mac=%d hdd=%d)\n",
|
||||
hardwareId.c_str(), uuidFound ? "ok" : "none", cpuCount, macCount, hddCount);
|
||||
|
||||
if (!uuidFound && cpuCount == 0 && macCount == 0)
|
||||
fprintf(stderr, "[anslicensing] WARNING: no hardware components readable via WMI - hardware id is NOT machine-specific. "
|
||||
"Check WMI health: winmgmt /verifyrepository (then winmgmt /salvagerepository if inconsistent)\n");
|
||||
}
|
||||
|
||||
return hardwareId.c_str();
|
||||
}
|
||||
|
||||
bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
{
|
||||
// An HWID identical to the one this machine generates right now is by
|
||||
// definition this computer. The points-based matching below can score
|
||||
// under REQUIRED_POINTS on machines with an invalid SMBIOS UUID and few
|
||||
// fingerprintable components (no PCI NIC, no readable disk serial), which
|
||||
// would reject even a freshly generated local HWID.
|
||||
const char* currentHwid = GetCurrentHardwareId();
|
||||
if (currentHwid != NULL && strcmp(hwid, currentHwid) == 0)
|
||||
return true;
|
||||
|
||||
#ifdef _WIN32
|
||||
WmiHelper wmi;
|
||||
#endif
|
||||
@@ -383,8 +495,14 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
|
||||
auto buf = base32.decode(hardwareId.c_str(), hardwareId.length(), &bufLen);
|
||||
|
||||
// The field layout is 147 bits but the HWID only encodes 16 bytes; zero-pad
|
||||
// the buffer so reading the trailing (truncated) HDD fields stays in bounds
|
||||
// and yields deterministic values instead of an out-of-bounds read.
|
||||
if (buf.size() < 20)
|
||||
buf.resize(20, 0);
|
||||
|
||||
BitStream3 bits;
|
||||
bits.Attach(buf.data(), 125);
|
||||
bits.Attach(buf.data(), 160);
|
||||
unsigned char version = 0;
|
||||
|
||||
bits.Read(&version, 3);
|
||||
@@ -398,6 +516,7 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
|
||||
// Use a points-based matching system for resilience
|
||||
int matchPoints = 0;
|
||||
bool uuidMatched = false;
|
||||
const int REQUIRED_POINTS = 2; // Need at least 2 components to match
|
||||
|
||||
// Read UUID hash
|
||||
@@ -430,6 +549,7 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
}
|
||||
}
|
||||
matchPoints += 2; // UUID/Memory match gives 2 points
|
||||
uuidMatched = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -437,9 +557,11 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
#ifdef _WIN32
|
||||
wmi.GetPropertyList("SELECT * FROM Win32_ComputerSystemProduct", "UUID", &propList);
|
||||
#endif
|
||||
if (propList.size() > 0)
|
||||
// The generator hashes the last valid UUID entry, so accept a match
|
||||
// against any entry rather than only the first one
|
||||
for (list<string>::iterator iter = propList.begin(); iter != propList.end(); iter++)
|
||||
{
|
||||
string s = NormalizeHardwareString(propList.front());
|
||||
string s = NormalizeHardwareString(*iter);
|
||||
|
||||
if ((s.length() > 1)
|
||||
&& (s != "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
|
||||
@@ -448,6 +570,8 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
if (hash1 != h0 && hash1 == HashString(s.c_str()))
|
||||
{
|
||||
matchPoints += 2; // UUID match is worth 2 points (most stable)
|
||||
uuidMatched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -558,5 +682,14 @@ bool HardwareId::MatchCurrentHardwareId(const char* hwid)
|
||||
// - UUID (2) + MAC (1) = 3 points ✓
|
||||
// - UUID (2) + HDD (1) = 3 points ✓
|
||||
// - CPU (1) + MAC (1) + HDD (1) = 3 points ✓ (if UUID changed but hardware same)
|
||||
return matchPoints >= REQUIRED_POINTS;
|
||||
bool accepted = (matchPoints >= REQUIRED_POINTS);
|
||||
|
||||
// Only reached when the exact-string precheck missed, i.e. the stored HWID
|
||||
// differs from the one this machine generates now. Log the breakdown so a
|
||||
// status-12 rejection in the field is diagnosable from the console output.
|
||||
fprintf(stderr, "[anslicensing] hardware id fuzzy match for %s: uuid=%s cpuMatches=%d macMatches=%d hddMatches=%d -> %d point(s), %d required -> %s\n",
|
||||
hwid, uuidMatched ? "match" : "no-match", cpuMatches, macMatches, hddMatches,
|
||||
matchPoints, REQUIRED_POINTS, accepted ? "accepted" : "REJECTED");
|
||||
|
||||
return accepted;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
#include "except.h"
|
||||
#include "template.h"
|
||||
@@ -179,6 +180,8 @@ public:
|
||||
catch (Exception * ex)
|
||||
{
|
||||
ex->Destroy();
|
||||
fprintf(stderr, "[anslicensing] activation key is %s (SetKey failed) - product needs (re)activation\n",
|
||||
activationKey.empty() ? "empty" : "malformed");
|
||||
activationStatus = STATUS_INVALID_ACTIVATION_KEY;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -186,6 +189,7 @@ public:
|
||||
|
||||
if (!validator.IsKeyValid())
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation key does not validate against this license key + hardware id\n");
|
||||
activationStatus = STATUS_INVALID_ACTIVATION_KEY;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -222,6 +226,7 @@ public:
|
||||
{
|
||||
if (timeValidationMethod == USE_INTERNET_TIME) // internet time was mandatory
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] could not obtain internet time (NTP) and internet time is mandatory - check network/firewall\n");
|
||||
activationStatus = STATUS_NET_ERROR;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -243,6 +248,10 @@ public:
|
||||
if (m_licenseValidityDays < 0)
|
||||
m_licenseValidityDays = 0;
|
||||
|
||||
fprintf(stderr, "[anslicensing] license expired on %04d-%02d-%02d (grace days remaining: %d)\n",
|
||||
1900 + licenseExpirationTime.tm_year, 1 + licenseExpirationTime.tm_mon, licenseExpirationTime.tm_mday,
|
||||
m_licenseValidityDays);
|
||||
|
||||
activationStatus = STATUS_LICENSE_EXPIRED;
|
||||
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
@@ -465,6 +474,9 @@ public:
|
||||
generator.SetValidationData("LicenseKeyValidationData", licenseKeyValidationData.data(), licenseKeyValidationDataLen * 8);
|
||||
}
|
||||
|
||||
fprintf(stderr, "[anslicensing] requesting activation key from licensing service: %s (hwid %s)\n",
|
||||
activationTemplate->GetLicensingServiceUrl(), hardwareId.c_str());
|
||||
|
||||
try {
|
||||
activationKey = generator.GenerateKey();
|
||||
}
|
||||
@@ -472,19 +484,29 @@ public:
|
||||
{
|
||||
if ((ex->GetCode() == STATUS_NET_ERROR) && (generator.GetSigningServiceStatusCode() == 406))
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] licensing service returned HTTP 406 - payment required\n");
|
||||
m_licenseValidationResult.SetPaymentRequired(true);
|
||||
ex->Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation request failed (service HTTP status %d) - check network access to the licensing service\n",
|
||||
generator.GetSigningServiceStatusCode());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (ValidateActivationKey(activationTemplate.get(), false))
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation key acquired and validated (service HTTP status %d)\n",
|
||||
generator.GetSigningServiceStatusCode());
|
||||
activationStatus = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] licensing service returned an activation key that does not validate for this hardware id\n");
|
||||
throw new LicensingException(STATUS_GENERIC_ERROR, "internal error - invalid returned activation key");
|
||||
}
|
||||
|
||||
m_licenseValidationResult.m_license = std::make_unique<LicenseImpl>();
|
||||
|
||||
@@ -533,8 +555,10 @@ public:
|
||||
{
|
||||
if (parentUsesWideChar)
|
||||
{
|
||||
static string hwid = w2s(GetCurrentHardwareIdW(parentLicensingClient));
|
||||
return hwid.c_str();
|
||||
// per-instance storage: a function-local static would freeze the
|
||||
// first client's HWID for the lifetime of the process
|
||||
currentHwidCache = w2s(GetCurrentHardwareIdW(parentLicensingClient));
|
||||
return currentHwidCache.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -587,6 +611,7 @@ private:
|
||||
string licenseKey;
|
||||
string activationKey;
|
||||
string hardwareId;
|
||||
string currentHwidCache;
|
||||
string licensingServiceUrl;
|
||||
|
||||
vector<unsigned char> licenseKeyValidationData;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#define _WIN32_DCOM
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <comdef.h>
|
||||
#include <Wbemidl.h>
|
||||
#include <list>
|
||||
@@ -52,10 +53,12 @@ public:
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
if (ownCoInitialize)
|
||||
CoUninitialize();
|
||||
|
||||
throw new exception("failed to create IWbemLocator", hres);
|
||||
// Fail soft: leave wbemServices NULL so queries return empty results.
|
||||
// Throwing here would escape callers (e.g. hardware id generation)
|
||||
// that have no exception handling and crash the host application.
|
||||
ReportFailure("CoCreateInstance(IWbemLocator)", hres);
|
||||
wbemLocator = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// Connect to the root\cimv2 namespace with the
|
||||
@@ -76,12 +79,11 @@ public:
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
ReportFailure("ConnectServer(ROOT\\CIMV2)", hres);
|
||||
wbemLocator->Release();
|
||||
|
||||
if (ownCoInitialize)
|
||||
CoUninitialize();
|
||||
|
||||
throw new exception("could not connect to WMI", hres);
|
||||
wbemLocator = NULL;
|
||||
wbemServices = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the IWbemServices proxy so that impersonation
|
||||
@@ -99,10 +101,12 @@ public:
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
ReportFailure("CoSetProxyBlanket", hres);
|
||||
wbemServices->Release();
|
||||
wbemLocator->Release();
|
||||
if (ownCoInitialize) CoUninitialize();
|
||||
throw new exception("could not connecto to WMI", hres);
|
||||
wbemServices = NULL;
|
||||
wbemLocator = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +119,9 @@ public:
|
||||
|
||||
void GetPropertyList(const char * wqlQuery, const char * propertyName, list<string> * propList, int maxElements = 0x7FFFFFFF)
|
||||
{
|
||||
if (wbemServices == NULL)
|
||||
return; // WMI unavailable; already reported by the constructor
|
||||
|
||||
HRESULT hres;
|
||||
|
||||
// For example, query for all the running processes
|
||||
@@ -128,7 +135,8 @@ public:
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
throw new exception("WMI query failed");
|
||||
ReportFailure(wqlQuery, hres);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -141,6 +149,14 @@ public:
|
||||
hres = pEnumerator->Next(WBEM_INFINITE, 1,
|
||||
&pclsObj, &uReturn);
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
// An enumeration error is not "no more rows" — report it,
|
||||
// otherwise a broken WMI silently yields an empty fingerprint
|
||||
ReportFailure(wqlQuery, hres);
|
||||
break;
|
||||
}
|
||||
|
||||
if(0 == uReturn)
|
||||
{
|
||||
break;
|
||||
@@ -203,6 +219,12 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static void ReportFailure(const char * what, HRESULT hres)
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] WMI failure (hr=0x%08lX): %s — hardware fingerprint will be degraded\n",
|
||||
(unsigned long)hres, what);
|
||||
}
|
||||
|
||||
bool ownCoInitialize;
|
||||
IWbemServices * wbemServices;
|
||||
IWbemLocator * wbemLocator;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# ANSAWSS3 — return codes and retry behaviour
|
||||
|
||||
Reference for callers of the `*ANSAWSHandle` exports in `ANSUtilities.dll`
|
||||
(LabVIEW, C++, .NET). Source of truth: `modules/ANSUtilities/ANSUtilities.h`
|
||||
(`kCall*` constants) and `modules/ANSUtilities/dllmain.cpp`.
|
||||
|
||||
## The one rule
|
||||
|
||||
**`rc == 1` means success. Everything else is a failure.** Success is the only
|
||||
positive value, so `rc == 1` and `rc != 1` are both always correct tests. The
|
||||
negative values exist so a caller can tell *why* it failed, and therefore
|
||||
whether retrying is worthwhile.
|
||||
|
||||
## Upload functions
|
||||
|
||||
Applies to every `Upload*ANSAWSHandle`, `Upload*ANSAWSHandle_CPP` and
|
||||
`Upload*ANSAWSHandle_V2` export (JPEG, binary, text, file-stream, multipart,
|
||||
with or without prefix).
|
||||
|
||||
| Code | Meaning | Retry? |
|
||||
|-----:|---------|--------|
|
||||
| `1` | Uploaded. `uploadedFilePath` holds the object URL. | — |
|
||||
| `0` | A required pointer argument was `NULL`. | **No** — caller bug |
|
||||
| `-1` | Handle is not in the registry: never created, already released, or a stale value. | **No** — re-create the handle |
|
||||
| `-2` | Failed, reason not classified. Should not occur; kept as a fallback. | Yes |
|
||||
| `-3` | A `std::exception` escaped. | Yes |
|
||||
| `-4` | An unknown exception escaped. | Yes |
|
||||
| `-20` | **Permanent.** Bad argument (empty bucket/filename, part size < 5 MB, unreadable file), invalid licence or unlock code, or S3 answered with a 4xx — wrong bucket, no permission, bad key. | **No** — fix the configuration; retrying burns time and changes nothing |
|
||||
| `-21` | **Not connected.** `Connect()` has not succeeded yet, or the link went down and the background retry thread is still working on it. | **Yes, later** — back off a few seconds |
|
||||
| `-22` | **Transient.** Network error, timeout, or HTTP 5xx, still failing after the DLL's own internal retries. | **Yes** |
|
||||
|
||||
A practical LabVIEW policy:
|
||||
|
||||
* `rc = 1` → done.
|
||||
* `rc = -20` or `0` → log it and stop; it will never succeed as-is.
|
||||
* `rc = -21` → queue the image and try again in a few seconds.
|
||||
* anything else negative → retry, with backoff.
|
||||
|
||||
Note that `-22` already means the DLL retried internally (up to 20 attempts
|
||||
within a 30 s budget) before giving up, so an outer retry should not be tight.
|
||||
|
||||
## Connect
|
||||
|
||||
`ConnectANSAWSHandle` / `_V2`:
|
||||
|
||||
| Code | Meaning |
|
||||
|-----:|---------|
|
||||
| `1` | Connected; ready for uploads once `SetAuthentication` is called. |
|
||||
| `0` | A required argument was `NULL`, the handle is unknown, the licence is invalid, or the endpoint resolves but refuses the connection. |
|
||||
| `2` | The endpoint could not be resolved at all (no internet). A background thread keeps retrying — 3 s, doubling to a 30 s ceiling — until it connects or the handle is released. **You do not need to call `Connect` again.** Uploads return `-21` in the meantime. |
|
||||
|
||||
## Other functions
|
||||
|
||||
`CreateANSAWSHandle`, `ReleaseANSAWSHandle`, `SetAuthenticationANSAWSHandle`,
|
||||
`SetProxyANSAWSHandle`, the `ListBucket*` / `CreateBucket*` / `DeleteBucket*`
|
||||
family, `DownloadFileStreamANSAWSHandle` and `GeneratePresignedURLANSAWSHandle`
|
||||
return `1` on success and `0` on failure. `GeneratePresignedURLANSAWSHandle`
|
||||
(the `LStrHandle` variant) additionally uses `-1`, `-2`, `-3`, `-4` with the
|
||||
same meanings as the table above.
|
||||
|
||||
## How connections behave
|
||||
|
||||
* `SetAuthentication` opens and keeps 8 pooled HTTPS connections; uploads borrow
|
||||
and return them, so the TLS handshake is not repeated per image.
|
||||
* A connection whose **transport** failed is closed, never returned to the pool.
|
||||
A connection that merely received an HTTP error status is healthy and is kept.
|
||||
* A pooled connection idle longer than 15 s is closed and replaced rather than
|
||||
handed out, since middleboxes silently drop idle flows.
|
||||
* The first request on a reused connection uses a short idle timeout (a quarter
|
||||
of the configured one, 5 s by default); a fresh connection gets the full
|
||||
timeout. This bounds what a dead socket costs.
|
||||
* One upload call is capped at 30 s of wall clock across all internal retries.
|
||||
|
||||
## Diagnostics
|
||||
|
||||
`ANSAWSS3.log` and DebugView (`AWSS3` / `ANSAWS` tags) record the decision
|
||||
points: pool evictions, discarded connections, the permanent/transient
|
||||
classification with the S3 error code, deadline expiry, and background
|
||||
reconnect attempts.
|
||||
@@ -0,0 +1,699 @@
|
||||
---
|
||||
title: "ANSCORE — System Architecture (L2 + L3)"
|
||||
subtitle: "Developer reference for the ANSVIS Communication Layer (CL) backend and the Qt/QML cross-platform desktop UI"
|
||||
author: "ANSCENTER"
|
||||
date: "2026-05-26"
|
||||
---
|
||||
|
||||
# Executive summary
|
||||
|
||||
ANSCORE is a Vision-AI Video Management System split into three layers:
|
||||
|
||||
- **Layer 1 — Edge runtime** (per target). Owns cameras, AI inference, trackers, rules, triggers. Built into the existing `ANSCORE/modules/*` C++ tree (ANSCV, ANSODEngine, ANSFR, ANSLPR, ANSOCR, ANSMOT). For this document L1 is *abstract*: we describe only the interface it exposes upward to L2.
|
||||
- **Layer 2 — ANSVIS CL** (one per customer). Aggregates targets, persists configuration, ingests events, brokers live media. Exposes a single REST contract (`/api/v1`) to L3. In v1 it is built as an **adapter layer in front of the existing ANSVIS server** — no rewrite required.
|
||||
- **Layer 3 — Qt/QML desktop UI** (Win / macOS / Linux). The operator-facing application. Talks to L2 exclusively.
|
||||
|
||||
**Build assignment:**
|
||||
|
||||
- L1 and L2 are built by the **core team** under architect-level review.
|
||||
- L3 is built by a **6-engineer team**.
|
||||
- L2 ↔ L3 is **REST + SSE + (HLS / RTSP / WebRTC)** — defined by `contracts/openapi.v1.json` (67 paths, 102 operations, 91 schemas).
|
||||
|
||||
The contract is the only artifact both sides block on. Once published, UI engineers develop against a Prism mock; the backend **core team** implements adapters per resource in parallel. Integration is the joining point.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part I — System overview
|
||||
|
||||
## The three layers
|
||||
|
||||
{ width=100% }
|
||||
|
||||
L3 only ever talks to L2. L2 brokers everything else: configuration push down to edges, event upload from edges, media relay. This keeps the UI team fully decoupled from L1 velocity.
|
||||
|
||||
## Three transports between L3 and L2
|
||||
|
||||
| # | Transport | Purpose | Carries |
|
||||
|---|---|---|---|
|
||||
| 1 | REST over HTTPS | Control plane: all CRUD, configuration, deploy commands | JSON request/response, RFC 7807 errors |
|
||||
| 2 | Server-Sent Events (SSE) over HTTPS | Live event tail (push of detections, target status) | `text/event-stream`, JSON per event |
|
||||
| 3 | HLS / RTSP / WebRTC | Live video | Media segments; transport chosen per stream |
|
||||
|
||||
The REST API brokers the other two: the UI calls REST to obtain a stream descriptor or SSE endpoint URL.
|
||||
|
||||
## Why this split
|
||||
|
||||
The earlier proposal of using gRPC end-to-end was reversed because the existing ANSVIS server already exposes a REST API. Pragmatic v1: **reuse what exists**, adapt it into a standards-compliant `/api/v1` surface, ship faster. gRPC remains an option for a future v2 if needed.
|
||||
|
||||
## Build ownership at a glance
|
||||
|
||||
| Layer | Pace |
|
||||
|---|---|
|
||||
| L1 (edge runtime) | Slower — high complexity (frame bus, inference batching, plugin SDK) |
|
||||
| L2 (CL) | Faster — modular per-resource adapters |
|
||||
| L3 (Qt/QML UI) | Independent — mock-first development |
|
||||
|
||||
\newpage
|
||||
|
||||
# Part II — Layer 1 (abstract overview)
|
||||
|
||||
L1 is the **edge runtime** that runs on each target. From L2's perspective it is a black box that:
|
||||
|
||||
- Receives **configuration** (cameras, AI models, AI tasks, rules, triggers) from L2 and persists it locally.
|
||||
- Captures frames from cameras (RTSP / RTMP / SRT / ONVIF / simulated).
|
||||
- Runs **AI pipelines** (object detection, FR, LPR, OCR, MOT, custom plugins).
|
||||
- Evaluates **rules** and emits **events** with evidence (snapshot frame, optional clip).
|
||||
- Dispatches **triggers** (HTTP, MQTT, email, push, broker integrations).
|
||||
- Exposes **liveview** streams (RTSP / SRT / future WebRTC).
|
||||
- Reports **health / metrics / logs** upward.
|
||||
|
||||
L1 ↔ L2 protocol is out of scope for this document. For v1, L2's adapter calls into the legacy ANSVIS server's existing protocol with edges (this is what currently works in production).
|
||||
|
||||
For L2 and L3 developers, L1 is treated as a remote service:
|
||||
|
||||
- Configuration changes go: **L3 (UI) → L2 (REST) → L1 (legacy protocol) → target reconciles**.
|
||||
- Events flow: **target → L1 → L2 (legacy uplink) → L2 event store → L2 SSE → L3**.
|
||||
- Liveview: **L3 asks L2 for a stream descriptor → L2 media relay pulls from L1 → L3 plays from L2's relay URL**.
|
||||
|
||||
The detailed L1 architecture (camera pool, inference server, frame bus, plugin SDK, etc.) is documented separately and does not affect L2 / L3 work.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part III — Layer 2 (ANSVIS CL)
|
||||
|
||||
## Architecture
|
||||
|
||||
{ width=100% }
|
||||
|
||||
L2 is composed of four logical groups:
|
||||
|
||||
1. **`/api/v1` surface** — REST router, auth middleware, OpenAPI request validation, RFC 7807 error mapper, rate limiter, SSE broadcaster.
|
||||
2. **v1 adapter layer** — one module per resource (cameras, models, edges, deployment-groups, ai-tasks, events, fr, alpr, notifications, system, jobs). Each adapter translates v1 requests to one or more legacy ANSVIS calls.
|
||||
3. **Legacy ANSVIS core** — reused as-is. Hosts the existing config store, AI task engine, FR engine, ALPR engine. The adapter is the only layer that calls into it.
|
||||
4. **Infrastructure** — auth + token store, async job queue, event metadata DB, clip / image object store (S3 / MinIO / FS), logs + metrics, media relay.
|
||||
|
||||
## Ownership inside L2
|
||||
|
||||
{ width=100% }
|
||||
|
||||
- **Architect (human)** keeps direct review on the cross-cutting concerns: REST router, auth, validation pipeline, RFC 7807 errors, RBAC, L2 ↔ L1 tunnel security.
|
||||
- The **core team** builds the per-resource adapters and infrastructure helpers (job queue, media relay). Each module has a sharp boundary so the team can work in parallel without colliding.
|
||||
- **Existing ANSVIS** is reused as-is. The adapter is the only entry point.
|
||||
|
||||
## REST API surface — `/api/v1`
|
||||
|
||||
The full contract is `contracts/openapi.v1.json` (OpenAPI 3.1, 67 paths, 102 operations, 91 typed schemas). Summary by resource group:
|
||||
|
||||
| Tag | Operations | Purpose |
|
||||
|---|---:|---|
|
||||
| `auth` | 3 | Login, logout, refresh |
|
||||
| `users` | 5 | System users CRUD |
|
||||
| `cameras` | 10 | CRUD + snapshot + liveview + ONVIF scan + probe |
|
||||
| `models` | 7 | CRUD + multipart upload + initiate/complete large upload |
|
||||
| `edges` | 7 | CRUD + health + status |
|
||||
| `deployment-groups` | 8 | CRUD + status + start/stop |
|
||||
| `ai-tasks` | 11 | CRUD + status + start/stop + liveview + catalog |
|
||||
| `events` | 6 | List + summary + SSE stream + image + clip + single |
|
||||
| `fr` | 14 | Persons + faces + groups + detection config |
|
||||
| `fr-recording` | 7 | Face-recording tasks + read/assign |
|
||||
| `alpr` | 8 | Plate + plate-group CRUD |
|
||||
| `notifications` | 5 | Recipients + groups |
|
||||
| `triggers` | 2 | Type catalog + test dispatch |
|
||||
| `system` | 7 | Status, health, info, logs, version, update |
|
||||
| `jobs` | 1 | Async job polling |
|
||||
| `composite` | 1 | Convenience endpoint (camera + tasks in one call) |
|
||||
| **Total** | **102** | |
|
||||
|
||||
## Conventions enforced by `openapi.v1.json`
|
||||
|
||||
- Plural kebab-case resource paths (`/cameras`, `/ai-tasks`, `/deployment-groups`).
|
||||
- `snake_case` field names. Units in the field name (`time_interval_seconds`, not `time_interval` with `(s)` suffix).
|
||||
- IDs in the path, never as query-string keys (replaces legacy `?867560018`).
|
||||
- `GET / POST / PUT / PATCH / DELETE` used semantically.
|
||||
- State changes via `POST /resource/{id}/start` and `POST /resource/{id}/stop` (pragmatic exception).
|
||||
- All errors as RFC 7807 problem+json with the matching HTTP status code.
|
||||
- List responses use a uniform pagination wrapper: `{items, page, page_size, total, next_cursor}`.
|
||||
- Auth: `Authorization: Bearer <token>` header, never in URL.
|
||||
- File uploads up to 10 MB use `multipart/form-data`; larger uploads use the initiate / complete pattern with a presigned PUT URL.
|
||||
- Live events as SSE; live media via HLS / RTSP / WebRTC behind a descriptor RPC.
|
||||
- All previously stringified-JSON fields (`Parameters(json)`, `RuleConfig`, `TriggerConfig`, `ModelConfigJson`) are now fully typed nested objects, validated against the schema.
|
||||
|
||||
## Migration from legacy ANSVIS endpoints
|
||||
|
||||
Every v1 endpoint description in the OpenAPI spec ends with `Replaces:` listing the legacy ANSVIS path(s) it supersedes. Examples:
|
||||
|
||||
| Legacy | v1 |
|
||||
|---|---|
|
||||
| `GET /Camera` (list mode) | `GET /api/v1/cameras` |
|
||||
| `GET /Camera?{id}` | `GET /api/v1/cameras/{id}` |
|
||||
| `DELETE /Camera?{id}` + `POST /delete/Camera?{id}` | `DELETE /api/v1/cameras/{id}` |
|
||||
| `GET /ControlAITask?ID=&State=true` | `POST /api/v1/ai-tasks/{id}/start` |
|
||||
| `POST /event/Get` (filter in body) | `GET /api/v1/events?task_id=&from=&to=&...` |
|
||||
| `POST /FR/AddFace` (base64 in JSON) | `POST /api/v1/fr/persons/{id}/faces` (multipart) |
|
||||
| `GET /SW/GetSoftwareVersion`, etc. | `GET /api/v1/system/version`, `/health`, `/info`, `/logs`, `/update` |
|
||||
|
||||
Legacy endpoints remain available during one release cycle with `Deprecation:` + `Sunset:` headers (RFC 8594).
|
||||
|
||||
\newpage
|
||||
|
||||
# Part IV — Layer 3 (Qt / QML desktop UI)
|
||||
|
||||
## Architecture
|
||||
|
||||
{ width=100% }
|
||||
|
||||
L3 is organized in four layers inside the Qt app:
|
||||
|
||||
1. **App Shell** — main window, navigation router, design system / theme, i18n, auth state + token store, global error toast / dialog.
|
||||
2. **Network layer** — generated REST client (from `openapi.v1.json`), SSE subscriber (chunked `QNetworkReply`), media client (QtMultimedia or GStreamer), bbox overlay renderer (custom `QQuickItem` with `QSGGeometryNode`), multipart + presigned uploader.
|
||||
3. **Domain state** — `QObject` + `Q_PROPERTY` + signals models per resource (CamerasModel, ModelsModel, EdgesModel, DeploymentGroupsModel, AITasksModel, EventsModel + LiveBuffer, FRPersonsModel, ALPRPlatesModel, RecipientsModel, SystemHealthModel).
|
||||
4. **Screens (QML)** — the operator surface: Login, Dashboard, Camera management, Pipeline editor, AI task config, Rules / triggers, Liveview grid, Eventview timeline, FR persons + faces, ALPR plates, Model registry, Users / admin, Settings.
|
||||
|
||||
## Screen → endpoint map
|
||||
|
||||
| Screen | Reads | Mutates | Notes |
|
||||
|---|---|---|---|
|
||||
| Login | — | `POST /auth/login` | Stores token in `AuthState` |
|
||||
| Dashboard | `GET /edges`, `GET /edges/{id}/health`, `GET /system/health` | — | Auto-refresh every 5 s |
|
||||
| Camera management | `GET /cameras`, `GET /cameras/{id}/snapshot`, `POST /cameras/probe` | `POST/PATCH/DELETE /cameras`, `POST /cameras/scan` (async job) | ONVIF discovery + calibration |
|
||||
| Pipeline editor | `GET /deployment-groups/{id}`, `GET /ai-tasks/catalog`, `GET /models` | `PUT /deployment-groups/{id}` | Highest-risk feature; QGraphicsView |
|
||||
| AI task config | `GET /ai-tasks/{id}`, `GET /ai-tasks/catalog` | `POST/PATCH/DELETE /ai-tasks`, `POST /ai-tasks/{id}/{start,stop}` | Schema-driven forms |
|
||||
| Rules / triggers | `GET /triggers/types` | Embedded in DG / task body | `POST /triggers/test` |
|
||||
| Liveview | `GET /cameras/{id}/liveview` | — | HLS v1, WebRTC v2; overlay sync to PTS |
|
||||
| Eventview | `GET /events?...`, `GET /events/stream` (SSE), `/events/{id}/{image,clip}` | — | Virtualized list for 100k+ events |
|
||||
| FR persons + faces | `GET /fr/persons`, `GET /fr/persons/{id}/faces` | `POST/PATCH/DELETE /fr/persons`, `POST /fr/persons/{id}/faces` (multipart) | Image upload |
|
||||
| ALPR plates | `GET /alpr/plates`, `GET /alpr/plate-groups` | `POST/DELETE /alpr/plates`, `PATCH /alpr/plate-groups/{id}` | Bulk register / deregister |
|
||||
| Model registry | `GET /models` | `POST /models` (multipart) or initiate / complete pattern for >100 MB | Upload progress |
|
||||
| Users / admin | `GET /users` | `POST/PATCH/DELETE /users/{id}` | Admin role only |
|
||||
| Settings | `GET /system/info`, `GET /system/version`, `GET /system/update` | `POST /system/update` | |
|
||||
|
||||
## Engineer ownership
|
||||
|
||||
{ width=100% }
|
||||
|
||||
\
|
||||
|
||||
Six engineers, each owning a vertical slice:
|
||||
|
||||
| # | Role | Owns |
|
||||
|---|---|---|
|
||||
| **E1** | UI Lead / Shell Architect | Qt 6 + CMake monorepo, generated REST client, auth state, design system, navigation router, packaging (Win/Mac/Linux signing, notarize, auto-update), CI matrix |
|
||||
| **E2** | Pipeline Editor Specialist | Visual DAG editor (`QGraphicsView` in `QQuickWidget`), node library, connection validation, schema-driven param panels, undo / redo, save / version |
|
||||
| **E3** | Liveview / Media | QtMultimedia HLS player (v1), multi-stream grid, bbox overlay (`QQuickItem` + `QSGGeometryNode`), clip player, WebRTC via GStreamer (v2) |
|
||||
| **E4** | Config Forms | Schema-driven QML forms from `openapi.v1.json`, camera + ONVIF discovery flow, camera calibration UI (ROI / zones / homography), model + plugin + trigger forms |
|
||||
| **E5** | Dashboard / Eventview | Target dashboard cards + charts, virtualized event timeline, SSE subscriber + LiveBuffer, filter / search / evidence viewer, multi-target monitoring |
|
||||
| **E6** | UX / Cross-platform QA | Design polish, accessibility, i18n, install / upgrade testing on Win / Mac / Linux, crash reporting, QML Profiler perf passes, user docs surface |
|
||||
|
||||
**Critical-path order for week 1–2:** E1 alone delivers the shell that unblocks E2–E6. E2 runs a node-editor spike in parallel to de-risk the hardest feature early. Once E1's shell lands, E3 / E4 / E5 work in parallel against the mock CL; E6 starts cross-platform validation.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part V — L2 ↔ L3 communication
|
||||
|
||||
## 1. REST control plane
|
||||
|
||||
Every CRUD operation, every state change, every configuration push. JSON in, JSON out, RFC 7807 problem+json on error.
|
||||
|
||||
### Request envelope
|
||||
|
||||
```http
|
||||
GET /api/v1/cameras?page=1&page_size=50 HTTP/1.1
|
||||
Host: cms.example.com
|
||||
Authorization: Bearer eyJhbGc…
|
||||
Accept: application/json
|
||||
```
|
||||
|
||||
### Success list response
|
||||
|
||||
```json
|
||||
{
|
||||
"items": [
|
||||
{ "id": 123, "name": "Front gate", "driver": "rtsp", "active": true, ... }
|
||||
],
|
||||
"page": 1,
|
||||
"page_size": 50,
|
||||
"total": 247,
|
||||
"next_cursor": null
|
||||
}
|
||||
```
|
||||
|
||||
### Error response
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "https://anscenter.com/errors/validation",
|
||||
"title": "Validation failed",
|
||||
"status": 422,
|
||||
"detail": "One or more fields are invalid",
|
||||
"instance": "/api/v1/cameras",
|
||||
"errors": [
|
||||
{ "field": "address", "message": "Must be a valid RTSP URL" },
|
||||
{ "field": "capturing.time_interval_seconds", "message": "Must be > 0" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Camera create — body example (clean v1)
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Front gate",
|
||||
"driver": "rtsp",
|
||||
"address": "rtsp://192.168.1.87:554/h264Preview_01_main",
|
||||
"credentials": { "username": "root", "password": "admin123" },
|
||||
"capturing": { "mode": "timer", "time_interval_seconds": 0.1 },
|
||||
"active": true,
|
||||
"logging_enabled": false,
|
||||
"edge_id": null,
|
||||
"deployment_group_ids": []
|
||||
}
|
||||
```
|
||||
|
||||
Note: no more stringified `Parameters(json)`. No more keys with parentheses or apostrophes. Credentials are nested. Units are in the field name.
|
||||
|
||||
## 2. SSE event stream
|
||||
|
||||
For live event tail:
|
||||
|
||||
```http
|
||||
GET /api/v1/events/stream?task_id=456 HTTP/1.1
|
||||
Host: cms.example.com
|
||||
Authorization: Bearer eyJhbGc…
|
||||
Accept: text/event-stream
|
||||
```
|
||||
|
||||
Each event:
|
||||
|
||||
```
|
||||
event: detection
|
||||
data: {"id":"20260526_181023-3","task_id":456,"camera_id":123,
|
||||
"timestamp":"2026-05-26T18:10:23Z","object":"car","score":0.91,
|
||||
"bbox":{"x":340,"y":210,"w":120,"h":80}}
|
||||
```
|
||||
|
||||
Qt side: `QNetworkAccessManager` with chunked reads, parse newline-delimited frames, drive `EventsModel.LiveBuffer`.
|
||||
|
||||
## 3. Live media
|
||||
|
||||
`GET /api/v1/cameras/{id}/liveview?transport=hls` returns a stream descriptor:
|
||||
|
||||
```json
|
||||
{
|
||||
"url": "https://cms.example.com/relay/cam123.m3u8",
|
||||
"transport": "hls",
|
||||
"auth_token": "tkn_short_lived_…",
|
||||
"expires_at": "2026-05-26T18:15:00Z",
|
||||
"overlay_stream": "/api/v1/events/stream?task_id=456"
|
||||
}
|
||||
```
|
||||
|
||||
Qt side: hand the URL to QtMultimedia for HLS playback (v1). For sub-second latency in v2, switch transport to `webrtc` and use GStreamer `webrtcbin`.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part VI — Key sequence flows
|
||||
|
||||
## 6.1 Operator configures a camera + AI task and deploys
|
||||
|
||||
{ width=92% }
|
||||
|
||||
Walk-through:
|
||||
|
||||
1. UI lists cameras via `GET /cameras?page=1`.
|
||||
2. Operator submits the new-camera form. UI sends `POST /cameras` with the *clean* body (nested credentials, capturing, image_size — no stringified JSON).
|
||||
3. UI creates an AI task for the new camera via `POST /ai-tasks`.
|
||||
4. Operator clicks "Start". UI calls `POST /ai-tasks/{id}/start` — returns `202 Accepted` with `{state: starting}`.
|
||||
5. UI polls `GET /ai-tasks/{id}/status` until `state=running`. (Will be replaced by SSE in a later iteration so polling is optional.)
|
||||
|
||||
## 6.2 Live event tail with evidence
|
||||
|
||||
{ width=92% }
|
||||
|
||||
Walk-through:
|
||||
|
||||
1. UI fetches historical events via `GET /events?task_id=&page=1` and renders the timeline.
|
||||
2. UI opens an SSE stream `GET /events/stream?task_id=` for live tail.
|
||||
3. Edge produces an event → L2 ingests → SSE broadcaster pushes the `EventRecord` to all subscribed UIs (filtered by their query).
|
||||
4. Operator clicks an event. UI fetches `GET /events/{id}/image?width=640` for the snapshot.
|
||||
5. Operator plays the clip. UI fetches `GET /events/{id}/clip` to get a presigned URL, then GETs the MP4 directly from the object store. The CL process never touches the video bytes — they flow client ↔ S3/MinIO.
|
||||
|
||||
## 6.3 Liveview with bbox overlay
|
||||
|
||||
{ width=92% }
|
||||
|
||||
Walk-through:
|
||||
|
||||
1. UI requests a liveview descriptor for camera 123: `GET /cameras/123/liveview?transport=hls`.
|
||||
2. L2's media relay ensures an HLS endpoint is running for that camera (pulling RTSP from the edge in the background).
|
||||
3. L2 returns `{url, transport:hls, auth_token, expires_at}`.
|
||||
4. UI plays the HLS URL in QtMultimedia.
|
||||
5. Simultaneously the UI subscribes to `/events/stream?task_id=456` (SSE) for the AI task's detections.
|
||||
6. The Qt overlay layer (custom `QQuickItem`) renders bounding boxes synced to the video PTS.
|
||||
|
||||
For v2 with WebRTC, the descriptor returns `transport:webrtc` and a signaling URL; GStreamer's `webrtcbin` handles negotiation.
|
||||
|
||||
## 6.4 Async camera scan via job queue
|
||||
|
||||
{ width=92% }
|
||||
|
||||
Walk-through:
|
||||
|
||||
1. Operator triggers an ONVIF scan of a subnet. UI calls `POST /cameras/scan` with `{ip_range, credentials, timeout_seconds}`.
|
||||
2. L2 enqueues the work and immediately returns `202 Accepted` with `{job_id, status:queued, links:{self:"/jobs/j1"}}`.
|
||||
3. The job worker performs the scan asynchronously.
|
||||
4. UI polls `GET /jobs/{id}` until `status` becomes `succeeded` or `failed`. The terminal response includes `result` with the discovered cameras.
|
||||
|
||||
This pattern is used for every potentially-long operation: ONVIF scan, large model upload, deploy-to-many-targets, software update.
|
||||
|
||||
## 6.5 Large model upload (presigned URL)
|
||||
|
||||
{ width=92% }
|
||||
|
||||
Walk-through:
|
||||
|
||||
1. UI calls `POST /models:initiate-upload` with `{filename, size_bytes, checksum}`. L2 returns `{upload_id, presigned_url, expires_at}`.
|
||||
2. UI PUTs the bytes directly to the object store using the presigned URL. The CL process never sees the bytes — saves CPU and avoids HTTP-body-size limits.
|
||||
3. UI calls `POST /models:complete-upload` with `{upload_id, metadata}`. L2 verifies the checksum and registers the model.
|
||||
|
||||
For files under 10 MB, the simple `POST /models` multipart endpoint can be used instead.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part VII — Deployment topology
|
||||
|
||||
{ width=100% }
|
||||
|
||||
## Hosts
|
||||
|
||||
| Host | Runs | Notes |
|
||||
|---|---|---|
|
||||
| Operator workstation (Win / Mac / Linux) | Qt UI application | One per concurrent operator |
|
||||
| ANSVIS server host | Reverse proxy (nginx / caddy) + ANSVIS app (adapter + legacy core) + Media relay + Object store + Config / Event DBs | One per customer site (can be HA later) |
|
||||
| Edge target | L1 runtime | One per physical capture site |
|
||||
|
||||
## Customer network rules
|
||||
|
||||
| Direction | Port | Purpose |
|
||||
|---|---|---|
|
||||
| Workstation → ANSVIS server | TCP 443 | REST + SSE + HLS over TLS |
|
||||
| ANSVIS server → workstation | — (response only) | |
|
||||
| ANSVIS server ↔ edges | TBD per deployment | Existing ANSVIS protocol |
|
||||
| Workstation → edges | **None** | Workstations never reach edges directly. Media relay proxies. |
|
||||
|
||||
## Why workstations don't reach edges
|
||||
|
||||
- Edges typically sit behind customer firewalls / NAT.
|
||||
- One TLS endpoint (ANSVIS) is easier to firewall, monitor, and authenticate against than dozens of edges.
|
||||
- Token rotation happens centrally.
|
||||
- The media relay can transcode, cache, or split streams.
|
||||
|
||||
\newpage
|
||||
|
||||
# Part VIII — Delivery plan
|
||||
|
||||
## Mock-first development
|
||||
|
||||
The contract `openapi.v1.json` is the only artifact both teams block on. Once it is published:
|
||||
|
||||
- **UI team** runs Stoplight Prism (`prism mock contracts/openapi.v1.json`) as a local mock CL and develops against it from day 1. No need to wait for the real adapter.
|
||||
- The **backend core team** implements the adapter resource-by-resource in parallel, validating each endpoint against the same OpenAPI schema.
|
||||
- **Integration** is the joining point. UI tests run against both mock and real to detect drift.
|
||||
|
||||
## Critical path
|
||||
|
||||
{ width=100% }
|
||||
|
||||
## Sequencing
|
||||
|
||||
| Phase | Week | Activities |
|
||||
|---|---|---|
|
||||
| **Contract freeze** | 1 | Lock `openapi.v1.json` v1.0.0 (3 small decisions outstanding — see Part IX) |
|
||||
| **Foundations** | 1–2 | E1: Qt 6 + CMake monorepo, generated REST client, Prism mock wired up, design system stub, app shell. <br/> E2: node-editor spike (de-risk). <br/> Core team: cameras / models / edges / system adapters in parallel. |
|
||||
| **Vertical slices** | 3–6 | E3 (Liveview), E4 (Config forms), E5 (Dashboard / Eventview) build full features against the mock. <br/> Core team: ai-tasks / deployment-groups / events / fr / alpr / notifications adapters. |
|
||||
| **Real integration** | 7–8 | UI cuts over from mock to real `/api/v1` per screen as adapters land. E6 runs cross-platform install / upgrade testing on Win / Mac / Linux. |
|
||||
| **Hardening** | 9–10 | Performance passes (QML Profiler, REST tracing), security review (architect-led), crash reporting, packaging signing / notarization. |
|
||||
| **Ship v1** | 11–12 | Pilot deployment, customer training, feedback loop. |
|
||||
|
||||
\newpage
|
||||
|
||||
# Part IX — Open decisions
|
||||
|
||||
These need to be locked before contract v1.0.0 publishes.
|
||||
|
||||
| # | Decision | Default in spec | Notes |
|
||||
|---|---|---|---|
|
||||
| 1 | Field naming | `snake_case` | Could switch to `camelCase` — match Qt/C++ style. One find-replace pass on `openapi.v1.json` either way. |
|
||||
| 2 | Auth scheme | Bearer (existing ANSVIS token) | v1 keeps Bearer; OAuth2/OIDC for v2. |
|
||||
| 3 | Mock server tool | Stoplight Prism (free) | Alternative: build a richer custom mock with scenarios. Recommend Prism. |
|
||||
| 4 | Liveview transport for v1 | HLS via QtMultimedia | Easiest. Add WebRTC in v2 if sub-second latency is needed. |
|
||||
| 5 | Object store | S3 / MinIO / local FS | Choose per deployment; behind a generic `ObjectStore` interface. |
|
||||
| 6 | Auto-update mechanism | Sparkle (Mac), MSIX / custom (Win), AppImage (Linux) | Confirm budget for code signing per platform. |
|
||||
| 7 | Contract repo location | `ANSCORE/contracts/` (current) | Separate `anscore-contracts` repo if teams diverge. |
|
||||
|
||||
\newpage
|
||||
|
||||
# Appendix A — Full endpoint catalog
|
||||
|
||||
Complete list of v1 operations. See `contracts/openapi.v1.json` for full request / response schemas.
|
||||
|
||||
## auth
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| POST | `/auth/login` | Log in (returns `access_token`, `expires_at`, `user`) |
|
||||
| POST | `/auth/logout` | Invalidate token |
|
||||
| POST | `/auth/refresh` | Exchange refresh token for new access token |
|
||||
|
||||
## users
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/users` | List users (paginated) |
|
||||
| POST | `/users` | Create user |
|
||||
| GET | `/users/{id}` | Get user |
|
||||
| PATCH | `/users/{id}` | Update user |
|
||||
| DELETE | `/users/{id}` | Delete user |
|
||||
|
||||
## cameras
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/cameras` | List cameras (filters: driver, active, edge_id, deployment_group_id) |
|
||||
| POST | `/cameras` | Create camera |
|
||||
| GET | `/cameras/{id}` | Get camera |
|
||||
| PUT | `/cameras/{id}` | Replace camera |
|
||||
| PATCH | `/cameras/{id}` | Patch camera |
|
||||
| DELETE | `/cameras/{id}` | Delete camera |
|
||||
| GET | `/cameras/{id}/snapshot` | Get JPEG snapshot (or presigned URL) |
|
||||
| GET | `/cameras/{id}/liveview` | Get liveview descriptor (`{url, transport, token, expires_at}`) |
|
||||
| POST | `/cameras/scan` | Async ONVIF scan (returns job) |
|
||||
| POST | `/cameras/probe` | Probe single IP for ONVIF profiles |
|
||||
|
||||
## models
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/models` | List models (filter by type) |
|
||||
| POST | `/models` | Upload + register (multipart, ≤10 MB) |
|
||||
| GET | `/models/{id}` | Get model |
|
||||
| PATCH | `/models/{id}` | Update model metadata |
|
||||
| DELETE | `/models/{id}` | Delete model |
|
||||
| POST | `/models:initiate-upload` | Begin large upload (returns presigned PUT URL) |
|
||||
| POST | `/models:complete-upload` | Finalize large upload |
|
||||
|
||||
## edges
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/edges` | List edges |
|
||||
| POST | `/edges` | Register edge |
|
||||
| GET | `/edges/{id}` | Get edge |
|
||||
| PATCH | `/edges/{id}` | Update edge |
|
||||
| DELETE | `/edges/{id}` | Delete edge |
|
||||
| GET | `/edges/{id}/health` | Resource / temp / uptime |
|
||||
| GET | `/edges/{id}/status` | State (online/offline/degraded) + counts |
|
||||
|
||||
## deployment-groups
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/deployment-groups` | List groups |
|
||||
| POST | `/deployment-groups` | Create group |
|
||||
| GET | `/deployment-groups/{id}` | Get group |
|
||||
| PUT | `/deployment-groups/{id}` | Replace group |
|
||||
| DELETE | `/deployment-groups/{id}` | Delete group |
|
||||
| GET | `/deployment-groups/{id}/status` | Runtime status |
|
||||
| POST | `/deployment-groups/{id}/start` | Start group |
|
||||
| POST | `/deployment-groups/{id}/stop` | Stop group |
|
||||
|
||||
## ai-tasks
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/ai-tasks` | List tasks |
|
||||
| POST | `/ai-tasks` | Create task |
|
||||
| GET | `/ai-tasks/{id}` | Get task |
|
||||
| PUT | `/ai-tasks/{id}` | Replace task |
|
||||
| PATCH | `/ai-tasks/{id}` | Patch task |
|
||||
| DELETE | `/ai-tasks/{id}` | Delete task |
|
||||
| GET | `/ai-tasks/{id}/status` | Get task runtime status |
|
||||
| POST | `/ai-tasks/{id}/start` | Start task |
|
||||
| POST | `/ai-tasks/{id}/stop` | Stop task |
|
||||
| GET | `/ai-tasks/{id}/liveview` | Liveview descriptor for annotated stream |
|
||||
| GET | `/ai-tasks/catalog` | List supported task types |
|
||||
|
||||
## events
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/events` | List events (filters: task_id, camera_id, object, from, to) |
|
||||
| GET | `/events/summary` | Analytics rollup |
|
||||
| GET | `/events/stream` | Live event tail (Server-Sent Events) |
|
||||
| GET | `/events/{id}` | Get one event |
|
||||
| GET | `/events/{id}/image` | JPEG snapshot |
|
||||
| GET | `/events/{id}/clip` | Presigned URL for evidence clip |
|
||||
|
||||
## fr (face recognition)
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/fr/persons` | List persons |
|
||||
| POST | `/fr/persons` | Create person |
|
||||
| GET | `/fr/persons/{id}` | Get person |
|
||||
| PATCH | `/fr/persons/{id}` | Update person |
|
||||
| DELETE | `/fr/persons/{id}` | Delete person |
|
||||
| GET | `/fr/persons/{id}/faces` | List faces for person |
|
||||
| POST | `/fr/persons/{id}/faces` | Add face (multipart, no base64) |
|
||||
| DELETE | `/fr/faces/{face_id}` | Delete face |
|
||||
| GET | `/fr/person-groups` | List person groups |
|
||||
| POST | `/fr/person-groups` | Create group |
|
||||
| PATCH | `/fr/person-groups/{id}` | Update group |
|
||||
| DELETE | `/fr/person-groups/{id}` | Delete group |
|
||||
| GET | `/fr/config` | Get FR detection config |
|
||||
| PATCH | `/fr/config` | Update FR detection config |
|
||||
|
||||
## fr-recording
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/fr/recording-tasks` | List tasks |
|
||||
| POST | `/fr/recording-tasks` | Create task |
|
||||
| DELETE | `/fr/recording-tasks/{id}` | Delete task |
|
||||
| POST | `/fr/recording-tasks/{id}/start` | Start task |
|
||||
| POST | `/fr/recording-tasks/{id}/stop` | Stop task |
|
||||
| GET | `/fr/recording-tasks/{id}/faces` | Read recorded faces |
|
||||
| PATCH | `/fr/recording-tasks/{id}/faces` | Assign recorded faces to a person (bulk) |
|
||||
|
||||
## alpr
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/alpr/plates` | List plates |
|
||||
| POST | `/alpr/plates` | Register plates (bulk) |
|
||||
| DELETE | `/alpr/plates/{plate}` | Deregister single plate |
|
||||
| POST | `/alpr/plates:bulk-delete` | Deregister bulk |
|
||||
| GET | `/alpr/plate-groups` | List plate groups |
|
||||
| POST | `/alpr/plate-groups` | Create group |
|
||||
| PATCH | `/alpr/plate-groups/{id}` | Update group |
|
||||
| DELETE | `/alpr/plate-groups/{id}` | Delete group |
|
||||
|
||||
## notifications
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/notifications/recipients` | List recipients |
|
||||
| POST | `/notifications/recipients` | Create recipient |
|
||||
| PATCH | `/notifications/recipients/{id}` | Update recipient |
|
||||
| DELETE | `/notifications/recipients/{id}` | Delete recipient |
|
||||
| GET | `/notifications/recipient-groups` | List recipient groups |
|
||||
|
||||
## triggers
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/triggers/types` | List supported trigger types + config schemas |
|
||||
| POST | `/triggers/test` | Dispatch a test trigger (HTTP / MQTT / Email / etc.) |
|
||||
|
||||
## system
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/system/status` | Liveness probe |
|
||||
| GET | `/system/health` | Resources + counts |
|
||||
| GET | `/system/info` | Hostname / OS / hardware |
|
||||
| GET | `/system/logs` | Paginated logs |
|
||||
| GET | `/system/version` | Version + build date + commit |
|
||||
| GET | `/system/update` | Update status |
|
||||
| POST | `/system/update` | Trigger update (async job) |
|
||||
|
||||
## jobs
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| GET | `/jobs/{id}` | Get async job status / result |
|
||||
|
||||
## composite
|
||||
|
||||
| Method | Path | Purpose |
|
||||
|---|---|---|
|
||||
| POST | `/composite/camera-with-tasks` | Create camera + deployment groups in one call |
|
||||
|
||||
\newpage
|
||||
|
||||
# Appendix B — Artifacts in the repository
|
||||
|
||||
```
|
||||
ANSCORE/
|
||||
├── contracts/
|
||||
│ └── openapi.v1.json # The single source of truth for L2 ↔ L3
|
||||
│
|
||||
├── docs/
|
||||
│ ├── ANSCORE-system-architecture.md # This document (source)
|
||||
│ ├── ANSCORE-system-architecture.pdf # This document (rendered)
|
||||
│ ├── L2-L3-architecture.md # Same content with Mermaid diagrams
|
||||
│ └── diagrams/
|
||||
│ ├── 01-system-context.puml # PlantUML sources
|
||||
│ ├── 02-l2-internals.puml
|
||||
│ ├── 03-l2-ownership.puml
|
||||
│ ├── 04-l3-internals.puml
|
||||
│ ├── 05-seq-configure-deploy.puml
|
||||
│ ├── 06-seq-live-events.puml
|
||||
│ ├── 07-seq-liveview.puml
|
||||
│ ├── 08-seq-async-scan.puml
|
||||
│ ├── 09-seq-large-upload.puml
|
||||
│ ├── 10-deployment-topology.puml
|
||||
│ ├── 11-l3-engineer-ownership.puml
|
||||
│ ├── 12-dependency-chain.puml
|
||||
│ ├── README.md
|
||||
│ ├── PREVIEW.md # Clickable plantuml.com URLs
|
||||
│ └── png/ # Pre-rendered PNGs (used in this PDF)
|
||||
│
|
||||
└── modules/ # Existing C++ building blocks (L1 ingredients)
|
||||
├── ANSCV/ ANSODEngine/ ANSFR/ ANSLPR/ ANSOCR/
|
||||
├── ANSMOT/ ANSPulsar/ ANSRabbitMQ/ ANSONVIF/
|
||||
└── ...
|
||||
```
|
||||
|
||||
# Appendix C — Glossary
|
||||
|
||||
| Term | Meaning |
|
||||
|---|---|
|
||||
| **L1** | Layer 1 — edge runtime (per target) |
|
||||
| **L2** | Layer 2 — ANSVIS CL (per customer) |
|
||||
| **L3** | Layer 3 — Qt/QML desktop UI (per operator workstation) |
|
||||
| **Adapter (v1)** | The L2 module that translates `/api/v1` requests to legacy ANSVIS calls |
|
||||
| **Edge / target** | A physical device running L1 (Windows/Linux on x86 or NVIDIA Jetson) |
|
||||
| **Deployment group** | A bundle of cameras + models + rules + triggers deployed to a target |
|
||||
| **AI task** | A configured pipeline (camera + model + rules + triggers) ready to run |
|
||||
| **Event** | A detection emitted by an AI task, with evidence (snapshot + optional clip) |
|
||||
| **Liveview** | Real-time video from a camera, with optional bbox overlay |
|
||||
| **Trigger** | An outbound action when a rule fires (HTTP, MQTT, email, push, broker) |
|
||||
| **ONVIF** | Camera-discovery and control protocol used by IP cameras |
|
||||
| **SSE** | Server-Sent Events — one-way push from server to client over HTTPS |
|
||||
| **RFC 7807** | The `application/problem+json` standard error format |
|
||||
| **Prism** | Stoplight's CLI for spinning up a mock REST server from an OpenAPI spec |
|
||||
| **OpenAPI 3.1** | The contract format used in `openapi.v1.json` |
|
||||
|
||||
---
|
||||
|
||||
*End of document.*
|
||||
@@ -0,0 +1,600 @@
|
||||
# ANSCORE — Layer 2 & Layer 3 Architecture
|
||||
|
||||
> Scope: Layer 2 (ANSVIS Communication Layer (CL), REST `/api/v1` surface, supporting services) and Layer 3 (Qt/QML cross-platform desktop UI). Layer 1 is summarized only where it interacts.
|
||||
>
|
||||
> Contract of record: [`contracts/openapi.v1.json`](../contracts/openapi.v1.json). All UI ↔ CL communication conforms to it.
|
||||
>
|
||||
> Transports:
|
||||
> 1. **REST / HTTPS** — control, CRUD, configuration, deploy
|
||||
> 2. **SSE (`text/event-stream`)** — live event tail
|
||||
> 3. **HLS / RTSP / WebRTC** — live video (descriptor obtained via REST)
|
||||
|
||||
---
|
||||
|
||||
## 1. System context — L1 / L2 / L3
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph L3["Layer 3 — Qt/QML Desktop UI (Win / Mac / Linux)"]
|
||||
UI[Qt/QML application]
|
||||
end
|
||||
|
||||
subgraph L2["Layer 2 — ANSVIS CL"]
|
||||
APIV1["/api/v1 REST surface"]
|
||||
LEGACY["Legacy ANSVIS core<br/>(reused as-is)"]
|
||||
RELAY["Media relay<br/>HLS / RTSP / WebRTC"]
|
||||
SSE["SSE event broadcaster"]
|
||||
STORE["Event DB<br/>+ clip object store"]
|
||||
JOBS["Async job queue"]
|
||||
AUTH["Auth + RBAC"]
|
||||
end
|
||||
|
||||
subgraph L1["Layer 1 — ANSCORE Edge Runtime<br/>(one per target)"]
|
||||
EDGE["Camera + Inference + Triggers"]
|
||||
end
|
||||
|
||||
UI -- "① REST / HTTPS<br/>control + CRUD" --> APIV1
|
||||
UI -- "② SSE / HTTPS<br/>live event tail" --> SSE
|
||||
UI -- "③ HLS / RTSP / WebRTC<br/>live video" --> RELAY
|
||||
|
||||
APIV1 --> AUTH
|
||||
APIV1 --> LEGACY
|
||||
APIV1 --> JOBS
|
||||
APIV1 --> STORE
|
||||
LEGACY --> STORE
|
||||
STORE --> SSE
|
||||
RELAY <--> EDGE
|
||||
LEGACY <--> EDGE
|
||||
```
|
||||
|
||||
**Key idea:** L3 only ever talks to L2. L1 ↔ L2 is a separate protocol (existing ANSVIS behavior, plus new edge work later). The UI team is fully decoupled from L1 velocity.
|
||||
|
||||
---
|
||||
|
||||
## 2. Layer 2 — internal architecture
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph CLIENTS["Clients"]
|
||||
QT["Qt/QML UI"]
|
||||
EXT["3rd-party integrations<br/>(optional)"]
|
||||
end
|
||||
|
||||
subgraph EDGE_API["L2 / api / v1 surface"]
|
||||
ROUTER["REST router"]
|
||||
AUTHMW["Auth middleware<br/>(Bearer)"]
|
||||
VALID["Request validation<br/>(OpenAPI schemas)"]
|
||||
ERR["Error mapper<br/>→ RFC 7807"]
|
||||
RATE["Rate limiter"]
|
||||
SSE_HUB["SSE broadcaster<br/>(per-subscription filter)"]
|
||||
end
|
||||
|
||||
subgraph ADAPTER["v1 Adapter Layer<br/>(per-resource modules)"]
|
||||
CAM_AD["cameras"]
|
||||
MOD_AD["models"]
|
||||
EDGE_AD["edges"]
|
||||
DG_AD["deployment-groups"]
|
||||
TASK_AD["ai-tasks"]
|
||||
EV_AD["events"]
|
||||
FR_AD["fr"]
|
||||
ALPR_AD["alpr"]
|
||||
NOTIF_AD["notifications"]
|
||||
SYS_AD["system"]
|
||||
JOB_AD["jobs"]
|
||||
end
|
||||
|
||||
subgraph LEGACY["Legacy ANSVIS server<br/>(reused as-is)"]
|
||||
LEG_CFG["Config store"]
|
||||
LEG_TASKS["AI task engine"]
|
||||
LEG_FR["FR engine"]
|
||||
LEG_ALPR["ALPR engine"]
|
||||
end
|
||||
|
||||
subgraph INFRA["Infrastructure"]
|
||||
AUTH_SVC["Auth + token store"]
|
||||
JOBS_Q["Job queue<br/>(scans, uploads, deploys, updates)"]
|
||||
EVENTS_DB["Event metadata DB"]
|
||||
CLIPS["Clip / image object store<br/>(S3 / MinIO / FS)"]
|
||||
LOGS["Logs + metrics + health"]
|
||||
RELAY["Media relay<br/>HLS / RTSP / WebRTC"]
|
||||
end
|
||||
|
||||
subgraph L1["Layer 1 edges"]
|
||||
E1["Edge target(s)"]
|
||||
end
|
||||
|
||||
QT --> ROUTER
|
||||
EXT --> ROUTER
|
||||
ROUTER --> AUTHMW --> VALID --> RATE
|
||||
RATE --> ADAPTER
|
||||
ADAPTER --> ERR
|
||||
ADAPTER -.-> ROUTER
|
||||
|
||||
AUTHMW --> AUTH_SVC
|
||||
|
||||
CAM_AD --> LEG_CFG
|
||||
MOD_AD --> LEG_CFG
|
||||
MOD_AD --> CLIPS
|
||||
EDGE_AD --> LEG_CFG
|
||||
DG_AD --> LEG_TASKS
|
||||
TASK_AD --> LEG_TASKS
|
||||
EV_AD --> EVENTS_DB
|
||||
EV_AD --> CLIPS
|
||||
FR_AD --> LEG_FR
|
||||
ALPR_AD --> LEG_ALPR
|
||||
SYS_AD --> LOGS
|
||||
JOB_AD --> JOBS_Q
|
||||
CAM_AD -. "scan / probe" .-> JOBS_Q
|
||||
MOD_AD -. "large upload" .-> JOBS_Q
|
||||
|
||||
LEG_TASKS --> EVENTS_DB
|
||||
EVENTS_DB --> SSE_HUB
|
||||
SSE_HUB --> ROUTER
|
||||
|
||||
LEGACY <--> E1
|
||||
RELAY <--> E1
|
||||
```
|
||||
|
||||
**Responsibilities by module:**
|
||||
|
||||
| Module | Owns |
|
||||
|---|---|
|
||||
| REST router | URL → handler, content negotiation |
|
||||
| Auth middleware | Bearer validation, principal injection, RBAC checks |
|
||||
| Request validation | OpenAPI schema-based body/query validation |
|
||||
| Error mapper | Translates legacy errors / exceptions to `application/problem+json` |
|
||||
| Rate limiter | Per-token / per-IP throttling |
|
||||
| SSE broadcaster | Subscribes to event bus, fans out to UI clients with filter + auth |
|
||||
| v1 adapter (per resource) | Translates v1 request → legacy call(s), reshapes response |
|
||||
| Job queue | Async ops (camera scan, model upload, software update, large deploy) |
|
||||
| Event DB | Indexed event metadata for `/events?...` queries |
|
||||
| Clip / object store | Snapshots and evidence video (presigned URLs) |
|
||||
| Media relay | Brokers live video from edge to UI (HLS now, WebRTC later) |
|
||||
| Auth + token store | Login, refresh, RBAC |
|
||||
|
||||
**Build ownership inside L2** (AI coders managed by you):
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph HUMAN["Human-owned (architect — you)"]
|
||||
H1["REST router + auth middleware"]
|
||||
H2["RFC 7807 error mapper"]
|
||||
H3["OpenAPI validation pipeline"]
|
||||
H4["Auth flow + token store"]
|
||||
H5["RBAC + security review"]
|
||||
H6["L2 ↔ L1 tunnel + signing"]
|
||||
end
|
||||
|
||||
subgraph AI["AI-coder-built (modular adapters)"]
|
||||
A1["cameras adapter"]
|
||||
A2["models adapter + upload pipeline"]
|
||||
A3["edges adapter"]
|
||||
A4["deployment-groups adapter"]
|
||||
A5["ai-tasks adapter"]
|
||||
A6["events adapter + SSE broadcaster"]
|
||||
A7["fr adapter"]
|
||||
A8["alpr adapter"]
|
||||
A9["notifications adapter"]
|
||||
A10["system / health / logs adapter"]
|
||||
A11["job queue + workers"]
|
||||
A12["media relay"]
|
||||
end
|
||||
|
||||
subgraph EXIST["Existing ANSVIS (reused as-is)"]
|
||||
L1["Task engine"]
|
||||
L2["FR engine"]
|
||||
L3["ALPR engine"]
|
||||
L4["Config store"]
|
||||
end
|
||||
|
||||
HUMAN --> AI
|
||||
AI --> EXIST
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Layer 3 — Qt/QML internal architecture
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph QT["Qt 6 + QML — Layer 3"]
|
||||
subgraph SHELL["App Shell"]
|
||||
MAIN["Main window"]
|
||||
ROUTE["Navigation router"]
|
||||
THEME["Design system / theme"]
|
||||
I18N["i18n (qsTr / Linguist)"]
|
||||
AUTH_ST["Auth state + token store"]
|
||||
ERR_UI["Error toast / dialog"]
|
||||
end
|
||||
|
||||
subgraph NET["Network layer"]
|
||||
REST["Generated REST client<br/>(openapi.v1.json → C++/Qt)"]
|
||||
SSE_CL["SSE subscriber<br/>(QNetworkReply chunked)"]
|
||||
MEDIA["Media client<br/>QtMultimedia / GStreamer"]
|
||||
OVERLAY["Bbox overlay renderer<br/>(custom QQuickItem)"]
|
||||
UPLOAD["Multipart + presigned uploader"]
|
||||
end
|
||||
|
||||
subgraph STATE["Domain state (QObject + Q_PROPERTY + signals)"]
|
||||
ST_CAM["CamerasModel"]
|
||||
ST_MOD["ModelsModel"]
|
||||
ST_EDGE["EdgesModel"]
|
||||
ST_DG["DeploymentGroupsModel"]
|
||||
ST_TASK["AITasksModel"]
|
||||
ST_EV["EventsModel + LiveBuffer"]
|
||||
ST_FR["FRPersonsModel"]
|
||||
ST_ALPR["ALPRPlatesModel"]
|
||||
ST_NOTIF["RecipientsModel"]
|
||||
ST_SYS["SystemHealthModel"]
|
||||
end
|
||||
|
||||
subgraph SCREENS["Screens (QML)"]
|
||||
LOGIN["Login"]
|
||||
DASH["Dashboard / targets overview"]
|
||||
CAM_S["Camera management<br/>+ ONVIF discovery<br/>+ calibration"]
|
||||
DG_EDIT["Pipeline editor<br/>(visual DAG)"]
|
||||
TASK_EDIT["AI Task config"]
|
||||
RULE_S["Rules / triggers"]
|
||||
LIVE["Liveview grid"]
|
||||
EV_S["Eventview timeline"]
|
||||
FR_S["FR persons + faces"]
|
||||
ALPR_S["ALPR plates"]
|
||||
MODEL_S["Model registry"]
|
||||
USERS["Users / admin"]
|
||||
SETTINGS["Settings"]
|
||||
end
|
||||
end
|
||||
|
||||
subgraph L2["ANSVIS / api / v1"]
|
||||
BACKEND["REST + SSE + media"]
|
||||
end
|
||||
|
||||
SCREENS --> STATE
|
||||
STATE --> NET
|
||||
NET <--> BACKEND
|
||||
OVERLAY -.-> MEDIA
|
||||
AUTH_ST -.-> REST
|
||||
AUTH_ST -.-> SSE_CL
|
||||
```
|
||||
|
||||
**Module → screen map** (for tasking):
|
||||
|
||||
| Screen | Reads from | Writes via | Notes |
|
||||
|---|---|---|---|
|
||||
| Login | — | `POST /auth/login` | Stores token in `AuthState` |
|
||||
| Dashboard | `GET /edges`, `GET /edges/{id}/health`, `GET /system/health` | — | Auto-refresh every 5s |
|
||||
| Camera management | `GET /cameras`, `GET /cameras/{id}/snapshot`, `POST /cameras/probe` | `POST/PATCH/DELETE /cameras`, `POST /cameras/scan` (async job) | ONVIF discovery + calibration overlay |
|
||||
| Pipeline editor | `GET /deployment-groups/{id}`, `GET /ai-tasks/catalog`, `GET /models` | `PUT /deployment-groups/{id}` | Highest-risk feature; QGraphicsView |
|
||||
| AI Task config | `GET /ai-tasks/{id}`, `GET /ai-tasks/catalog` | `POST/PATCH/DELETE /ai-tasks`, `POST /ai-tasks/{id}/start|stop` | Schema-driven forms |
|
||||
| Rules / triggers | `GET /triggers/types` | embedded in deployment-group / task body | `POST /triggers/test` |
|
||||
| Liveview | `GET /cameras/{id}/liveview` | — | HLS in v1, WebRTC later; overlay sync to PTS |
|
||||
| Eventview | `GET /events?filters`, `GET /events/stream` (SSE), `GET /events/{id}/image`, `GET /events/{id}/clip` | — | Virtualized list for 100k+ events |
|
||||
| FR persons + faces | `GET /fr/persons`, `GET /fr/persons/{id}/faces` | `POST/PATCH/DELETE /fr/persons`, `POST /fr/persons/{id}/faces` (multipart) | Multipart image upload |
|
||||
| ALPR plates | `GET /alpr/plates`, `GET /alpr/plate-groups` | `POST/DELETE /alpr/plates`, `PATCH /alpr/plate-groups/{id}` | Bulk register/deregister |
|
||||
| Model registry | `GET /models` | `POST /models` (multipart), `POST /models:initiate-upload` for big files | Upload progress UI |
|
||||
| Users / admin | `GET /users` | `POST/PATCH/DELETE /users/{id}` | Admin role only |
|
||||
| Settings | `GET /system/info`, `GET /system/version`, `GET /system/update` | `POST /system/update` | |
|
||||
|
||||
---
|
||||
|
||||
## 4. Sequence flows
|
||||
|
||||
### 4.1 Configure & deploy — typical operator workflow
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor User as Operator
|
||||
participant UI as Qt UI
|
||||
participant API as ANSVIS /api/v1
|
||||
participant LEG as ANSVIS core
|
||||
participant EDGE as L1 edge
|
||||
|
||||
User->>UI: Open Cameras screen
|
||||
UI->>API: GET /cameras?page=1
|
||||
API->>LEG: legacy list
|
||||
LEG-->>API: cameras
|
||||
API-->>UI: 200 {items, page, total}
|
||||
|
||||
User->>UI: Add RTSP camera (form)
|
||||
UI->>API: POST /cameras
|
||||
Note right of UI: body has nested credentials,<br/>capturing, image_size — no<br/>stringified JSON
|
||||
API->>LEG: legacy add
|
||||
LEG-->>API: id=123
|
||||
API-->>UI: 201 Location: /cameras/123
|
||||
|
||||
User->>UI: Configure AI task
|
||||
UI->>API: POST /ai-tasks {camera_id:123, ...}
|
||||
API->>LEG: legacy create
|
||||
LEG-->>API: id=456
|
||||
API-->>UI: 201 {id:456}
|
||||
|
||||
User->>UI: Start task
|
||||
UI->>API: POST /ai-tasks/456/start
|
||||
API->>LEG: dispatch
|
||||
LEG->>EDGE: config + start
|
||||
EDGE-->>LEG: running
|
||||
API-->>UI: 202 {state:starting}
|
||||
|
||||
loop status poll (or SSE later)
|
||||
UI->>API: GET /ai-tasks/456/status
|
||||
API-->>UI: 200 {state:running, fps:14.2}
|
||||
end
|
||||
```
|
||||
|
||||
### 4.2 Live event tail + clicking into evidence
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor User
|
||||
participant UI
|
||||
participant API as /api/v1
|
||||
participant SSE as SSE broadcaster
|
||||
participant CLIPS as Clip store
|
||||
participant EDGE
|
||||
|
||||
User->>UI: Open Eventview (task=456)
|
||||
UI->>API: GET /events?task_id=456&page=1
|
||||
API-->>UI: 200 historical events
|
||||
UI->>API: GET /events/stream?task_id=456
|
||||
API-->>UI: text/event-stream (open)
|
||||
|
||||
EDGE->>API: event arrives (via L1↔L2)
|
||||
API->>SSE: push EventRecord
|
||||
SSE-->>UI: data: {id:E1, ts, object:car, bbox, ...}
|
||||
|
||||
User->>UI: Click event E1
|
||||
UI->>API: GET /events/E1
|
||||
API-->>UI: 200 EventRecord (full)
|
||||
UI->>API: GET /events/E1/image?width=640
|
||||
API-->>UI: image/jpeg bytes
|
||||
|
||||
User->>UI: Play clip
|
||||
UI->>API: GET /events/E1/clip
|
||||
API->>CLIPS: presign GET
|
||||
CLIPS-->>API: presigned URL
|
||||
API-->>UI: 200 {url, expires_at}
|
||||
UI->>CLIPS: GET <presigned URL>
|
||||
CLIPS-->>UI: MP4 bytes
|
||||
UI->>UI: play in QtMultimedia
|
||||
```
|
||||
|
||||
### 4.3 Liveview with bbox overlay
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor User
|
||||
participant UI
|
||||
participant API
|
||||
participant RELAY as Media relay
|
||||
participant EDGE
|
||||
participant SSE
|
||||
|
||||
User->>UI: Open Liveview (cam 123, task 456)
|
||||
UI->>API: GET /cameras/123/liveview?transport=hls
|
||||
API->>RELAY: ensure HLS for cam 123
|
||||
RELAY->>EDGE: pull RTSP
|
||||
RELAY-->>API: hls_url + short-lived token
|
||||
API-->>UI: 200 {url, transport:hls, auth_token, expires_at}
|
||||
|
||||
UI->>RELAY: GET hls_url (token)
|
||||
RELAY-->>UI: m3u8 + segments
|
||||
UI->>UI: Render video (QtMultimedia)
|
||||
|
||||
UI->>API: GET /events/stream?task_id=456 (SSE)
|
||||
API-->>UI: text/event-stream
|
||||
loop per event
|
||||
SSE-->>UI: bbox + ts
|
||||
UI->>UI: overlay synced to PTS
|
||||
end
|
||||
```
|
||||
|
||||
### 4.4 Async job — camera network scan
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor User
|
||||
participant UI
|
||||
participant API
|
||||
participant JOBS as Job queue
|
||||
participant SCAN as ONVIF scanner
|
||||
|
||||
User->>UI: Scan 192.168.1.0/24
|
||||
UI->>API: POST /cameras/scan
|
||||
API->>JOBS: enqueue
|
||||
JOBS-->>API: job_id=j1
|
||||
API-->>UI: 202 {job_id:j1, status:queued, links:{self:/jobs/j1}}
|
||||
|
||||
JOBS->>SCAN: run
|
||||
loop poll until terminal
|
||||
UI->>API: GET /jobs/j1
|
||||
API-->>UI: 200 {status:running, progress:0.4}
|
||||
end
|
||||
SCAN-->>JOBS: results
|
||||
UI->>API: GET /jobs/j1
|
||||
API-->>UI: 200 {status:succeeded, result:{discovered:[...]}}
|
||||
```
|
||||
|
||||
### 4.5 Large model upload — initiate / complete pattern
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
actor User
|
||||
participant UI
|
||||
participant API
|
||||
participant OBJ as Object store
|
||||
|
||||
User->>UI: Pick model.zip (500 MB)
|
||||
UI->>API: POST /models:initiate-upload {filename, size_bytes, checksum}
|
||||
API->>OBJ: presign PUT
|
||||
OBJ-->>API: presigned_url
|
||||
API-->>UI: 200 {upload_id, presigned_url, expires_at}
|
||||
|
||||
UI->>OBJ: PUT <presigned_url> (binary stream, with progress)
|
||||
OBJ-->>UI: 200 OK
|
||||
|
||||
UI->>API: POST /models:complete-upload {upload_id, metadata}
|
||||
API->>OBJ: verify checksum
|
||||
OBJ-->>API: ok
|
||||
API-->>UI: 201 Model
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Deployment topology
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
subgraph CUSTOMER["Customer site / cloud"]
|
||||
subgraph DESKTOPS["Operator workstations"]
|
||||
D1["Win desktop<br/>Qt UI"]
|
||||
D2["Mac desktop<br/>Qt UI"]
|
||||
D3["Linux desktop<br/>Qt UI"]
|
||||
end
|
||||
|
||||
subgraph SERVER["ANSVIS server host"]
|
||||
NGINX["Reverse proxy<br/>TLS terminator"]
|
||||
APP["ANSVIS app<br/>(adapter + legacy core)"]
|
||||
RELAY["Media relay"]
|
||||
OBJ["Object store<br/>(S3/MinIO/FS)"]
|
||||
DB["DBs<br/>(config / events)"]
|
||||
end
|
||||
|
||||
subgraph EDGES["Edge targets"]
|
||||
E1["Linux x86 + NV"]
|
||||
E2["Win x86 + NV"]
|
||||
E3["Jetson Orin"]
|
||||
end
|
||||
end
|
||||
|
||||
D1 -- "TLS 443<br/>REST + SSE + HLS" --> NGINX
|
||||
D2 -- "TLS 443" --> NGINX
|
||||
D3 -- "TLS 443" --> NGINX
|
||||
NGINX --> APP
|
||||
NGINX --> RELAY
|
||||
APP --> DB
|
||||
APP --> OBJ
|
||||
RELAY <--> EDGES
|
||||
APP <--> EDGES
|
||||
```
|
||||
|
||||
**Network rules to communicate to the customer:**
|
||||
- Outbound TCP 443 from each operator workstation to ANSVIS server.
|
||||
- Inbound 443 on ANSVIS server.
|
||||
- Whatever protocol L1 ↔ L2 needs (TCP 443 if everything tunneled; or per-edge ports if direct).
|
||||
- No need for the workstation to reach edges directly — Media relay proxies.
|
||||
|
||||
---
|
||||
|
||||
## 6. L3 — engineer ownership (6 engineers)
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph E1["E1 — UI Lead / Shell Architect"]
|
||||
E1A["Qt 6 + CMake monorepo"]
|
||||
E1B["Generated REST client from openapi.v1.json"]
|
||||
E1C["Auth state + token store"]
|
||||
E1D["Design system / theme"]
|
||||
E1E["Navigation router"]
|
||||
E1F["Packaging Win/Mac/Linux<br/>signing, notarize, auto-update"]
|
||||
E1G["CI matrix"]
|
||||
end
|
||||
|
||||
subgraph E2["E2 — Pipeline Editor Specialist"]
|
||||
E2A["Visual DAG editor<br/>QGraphicsView in QQuickWidget"]
|
||||
E2B["Node library + connections"]
|
||||
E2C["Schema-driven param panels"]
|
||||
E2D["Undo / redo, save / version"]
|
||||
end
|
||||
|
||||
subgraph E3["E3 — Liveview / Media"]
|
||||
E3A["QtMultimedia HLS player<br/>(v1)"]
|
||||
E3B["Multi-stream grid"]
|
||||
E3C["Bbox overlay (QQuickItem + QSGGeometryNode)"]
|
||||
E3D["Clip player (evidence)"]
|
||||
E3E["WebRTC via GStreamer (v2)"]
|
||||
end
|
||||
|
||||
subgraph E4["E4 — Config Forms"]
|
||||
E4A["Schema-driven QML forms<br/>(from openapi.v1.json)"]
|
||||
E4B["Camera + ONVIF discovery flow"]
|
||||
E4C["Camera calibration UI<br/>(ROI / zones / homography)"]
|
||||
E4D["Model + plugin + trigger forms"]
|
||||
end
|
||||
|
||||
subgraph E5["E5 — Dashboard / Eventview"]
|
||||
E5A["Target dashboard cards + charts"]
|
||||
E5B["Event timeline (virtualized)"]
|
||||
E5C["SSE subscriber + LiveBuffer"]
|
||||
E5D["Filter / search / evidence viewer"]
|
||||
E5E["Multi-target monitoring"]
|
||||
end
|
||||
|
||||
subgraph E6["E6 — UX / Cross-platform QA"]
|
||||
E6A["Design polish, a11y, i18n"]
|
||||
E6B["Install / upgrade testing<br/>Win + Mac + Linux"]
|
||||
E6C["Crash reporting (Sentry/Crashpad)"]
|
||||
E6D["QML Profiler perf passes"]
|
||||
E6E["User docs surface"]
|
||||
end
|
||||
|
||||
CONTRACT[(openapi.v1.json<br/>frozen contract)]
|
||||
E1 -.-> CONTRACT
|
||||
E2 -.-> CONTRACT
|
||||
E3 -.-> CONTRACT
|
||||
E4 -.-> CONTRACT
|
||||
E5 -.-> CONTRACT
|
||||
```
|
||||
|
||||
**Critical-path order:**
|
||||
|
||||
1. **Week 1–2 (E1 only)**: monorepo, generated REST client, auth, design system stub, `make dev` brings up Prism mock. This unblocks everyone else.
|
||||
2. **Week 1–2 (E2 in parallel)**: node-editor spike. Highest schedule risk → de-risk early.
|
||||
3. **Week 2+ (E3, E4, E5 in parallel)**: each owns a vertical against the mock CL. E6 starts integration testing.
|
||||
4. **Week 4+**: cut from mock CL to real ANSVIS `/api/v1` as adapter endpoints land.
|
||||
|
||||
---
|
||||
|
||||
## 7. What gates what (dependency chain)
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
CONTRACT["openapi.v1.json<br/>(frozen)"]
|
||||
MOCK["Prism mock server"]
|
||||
ADAPT["ANSVIS /api/v1 adapter<br/>(AI coders, per-resource)"]
|
||||
LEGACY["Legacy ANSVIS"]
|
||||
UI_SHELL["L3 shell + REST client (E1)"]
|
||||
UI_FEAT["L3 screens (E2-E6)"]
|
||||
REAL["Real backend integration"]
|
||||
SHIP["Ship v1"]
|
||||
|
||||
CONTRACT --> MOCK
|
||||
CONTRACT --> ADAPT
|
||||
ADAPT --> LEGACY
|
||||
MOCK --> UI_SHELL --> UI_FEAT
|
||||
UI_FEAT --> REAL
|
||||
ADAPT --> REAL
|
||||
REAL --> SHIP
|
||||
```
|
||||
|
||||
- The contract is the *only* thing both sides block on.
|
||||
- UI does not wait for the adapter — develops against Prism.
|
||||
- Adapter team does not wait for UI — implements per-resource modules in parallel.
|
||||
- Integration is the joining point.
|
||||
|
||||
---
|
||||
|
||||
## 8. Open decisions that affect this architecture
|
||||
|
||||
These are unchanged from earlier conversations; capturing here so the team has them in one place:
|
||||
|
||||
1. **Field naming** — `snake_case` (current default in `openapi.v1.json`) or `camelCase`?
|
||||
2. **Auth scheme** — keep Bearer (current) or move to OAuth2/OIDC for v1?
|
||||
3. **Mock-server pinning** — Prism for free, or build a richer custom mock?
|
||||
4. **Liveview transport for v1** — HLS only (recommended), or RTSP-direct on LAN, or jump straight to WebRTC?
|
||||
5. **Object store choice** — local FS (single host), MinIO (single host scalable), or S3 (cloud)?
|
||||
6. **Auto-update** for the Qt client — Sparkle on Mac, Squirrel/MSIX on Windows, AppImage on Linux. Confirm budget for each.
|
||||
7. **Contract repo** — co-located in `ANSCORE/contracts/` (current) or split into a separate `anscore-contracts` repo?
|
||||
|
||||
---
|
||||
|
||||
*Last updated: 2026-05-26 — diagrams reflect `openapi.v1.json` v1.0.0 draft.*
|
||||
@@ -0,0 +1,573 @@
|
||||
# PLAN — Port ANSCORE Licensing Core to Linux (x86_64 + Jetson aarch64)
|
||||
|
||||
**Status:** Draft, awaiting product-side decisions before execution
|
||||
**Target platforms:** Ubuntu 22.04 x86_64, JetPack 6.x (Ubuntu 22.04 aarch64)
|
||||
**Components in scope:** `core/anslicensing`, `core/ANSLicensingSystem`, `core/ANSLibsLoader`
|
||||
**Estimated effort:** ~6–7 focused weeks for one engineer
|
||||
**Risk:** Medium (HWID compatibility with license server is the dominant risk)
|
||||
**Owner:** Tuan Nghia Nguyen
|
||||
**Branch to create:** `linux-licensing-port`
|
||||
|
||||
---
|
||||
|
||||
## Decisions already made (do not re-litigate)
|
||||
|
||||
1. **Three components are in scope, in this order**: `ANSLibsLoader` (easiest), `anslicensing` (medium), `ANSLicensingSystem` (hardest). Engine modules (`ANSODEngine`, `ANSCV`, etc.) are NOT part of this plan — they come after licensing is up.
|
||||
2. **No LabVIEW support on Linux.** The `_LV` exports and `LabVIEWHeader/extcode.h` includes are stripped from the Linux build via `#ifdef _WIN32`. The C++ and C-string (`_CS`) entry points become the only Linux surface.
|
||||
3. **`lfreist/hwinfo` stays.** It is already vendored at `C:/ANSLibs/ANS-HWiNFO/` and is cross-platform (verified — its `platform.h` defines `HWINFO_UNIX` on Linux). All 8 `hwinfo::` call sites in `ANSLicense.cpp` are portable as-is. No replacement library needed.
|
||||
4. **HWID gains real signals on Linux.** Today `hwid.cpp` Linux branches stub the SMBIOS UUID slot with `"4294967296"` and leave `GetHDDPropertyList` empty (2-point HWID strength vs Windows 4-point). We will fill those slots using `hwinfo::MainBoard::serialNumber()` and `hwinfo::RAM::serialNumber()` for parity.
|
||||
5. **`rand.cpp` Linux path is replaced with `getrandom(2)`**. The current `srand(time(NULL)) + rand()` path is cryptographically broken and a security-correctness issue, not just a portability one.
|
||||
6. **`DetectClockManipulation` on Linux ships as a best-effort stub.** Reading `journalctl` history is expensive and not always available (containers, no systemd). It will log a warning and return `false`. Acceptable anti-tamper degradation; flagged for follow-up.
|
||||
7. **MediaClient and other non-licensing Windows surface stays Windows-only.** This plan does not touch them.
|
||||
8. **HWiNFO is NOT the commercial HWiNFO64.** It's the open-source MIT-licensed [`lfreist/hwinfo`](https://github.com/lfreist/hwinfo) C++ library. No commercial license concern.
|
||||
|
||||
## Pre-work already completed (discovery, not code)
|
||||
|
||||
- ✅ Confirmed `core/anslicensing/` already has Linux scaffolding: `CMakeLists.txt` branches on `WIN32` and links `curl ssl crypto`; `precomp.h` has POSIX shims; `download.cpp` has a complete libcurl path; `hwid.cpp` has Linux CPU-ID and MAC code.
|
||||
- ✅ Inventoried Windows API surface in `ANSLicensingSystem/ANSLicense.cpp` (4,021 LOC):
|
||||
- Only 2 `#ifdef _WIN32` blocks — the file assumes Windows top-to-bottom
|
||||
- 8 × `hwinfo::` calls — **portable as-is**
|
||||
- 12 × PDH counter sites — need `/proc` rewrite (Phase 3.3)
|
||||
- 7 × DXGI sites — need NVML/libdrm rewrite (Phase 3.4)
|
||||
- 1 × WMI `MSAcpi_ThermalZoneTemperature` query — Linux `/sys/class/thermal/` (Phase 3.2)
|
||||
- 1 × WinHTTP block — replace with libcurl already in `anslicensing/download.cpp` (Phase 3.5)
|
||||
- 1 × `DnsQuery_A` — replace with `getaddrinfo` (Phase 3.6)
|
||||
- Misc: `GlobalMemoryStatusEx`, `GetProcessMemoryInfo`, `GetSystemDirectoryW + GetDiskFreeSpaceExW`, `GetCurrentProcessId` (Phase 3.7)
|
||||
- ✅ Confirmed `lfreist/hwinfo` cross-platform support via its `platform.h` and the header set at `C:/ANSLibs/ANS-HWiNFO/include/hwinfo/`.
|
||||
|
||||
---
|
||||
|
||||
## Open product decisions (BLOCK Phase 0)
|
||||
|
||||
These must be resolved with the licensing-backend team before any code is written. They determine the shape of Phase 1.
|
||||
|
||||
### Decision 1 — HWID format compatibility with the license server
|
||||
|
||||
The license server validates a HWID hash that's currently produced from Windows WMI data (`Win32_ComputerSystemProduct.UUID`, `Win32_NetworkAdapter.MACAddress`, `Win32_PhysicalMedia.SerialNumber`, `Win32_Processor.ProcessorId`). On Linux we will produce hashes from different data sources (SMBIOS via `/sys/class/dmi/id/`, NIC MACs via `getifaddrs`, RAM serial via DMI, CPU ID via `__get_cpuid`). The hash format (the bit-packed 125-bit `BitStream3` in `hwid.cpp`) stays identical, but the **values being hashed differ**. Three options:
|
||||
|
||||
- **A. Unified HWID, same algorithm**: server treats Windows and Linux licenses identically; admin has to physically activate each device once and the hash is opaque. **Simplest. Recommended.**
|
||||
- **B. Separate Linux license pool**: server tracks platform field; Linux activations come from a dedicated key range. More work backend-side.
|
||||
- **C. Backward-compat dance**: keep some Windows-specific fields empty on Linux (status quo) — license matching weakens. **Reject.**
|
||||
|
||||
**Owner to confirm with backend team before Phase 0.**
|
||||
|
||||
### Decision 2 — HWiNFO `MainBoard::serialNumber()` availability on Jetson
|
||||
|
||||
`lfreist/hwinfo` reads `/sys/class/dmi/id/board_serial` on Linux. **On Jetson this file may not exist** — ARM SBCs use device-tree, not DMI. We need to:
|
||||
|
||||
- Test on a real Jetson Orin/AGX board early.
|
||||
- Define fallback signal: `/proc/device-tree/serial-number` (Jetson exposes this) or eMMC CID (`/sys/block/mmcblk*/device/cid`).
|
||||
|
||||
**Owner needs a Jetson devkit available before Phase 1.**
|
||||
|
||||
### Decision 3 — Boost dependencies on Jetson
|
||||
|
||||
`ANSLicensingSystem` currently links `libboost_log-vc143-mt-x64-1_82.lib` and uses `boost::property_tree::ptree` and `boost::date_time`. Ubuntu 22.04 ships Boost 1.74 by default (`libboost-all-dev`). Choices:
|
||||
|
||||
- **A. Use system Boost on Linux** (1.74). Accept minor API differences; pin via `find_package(Boost 1.74 REQUIRED)`.
|
||||
- **B. Vendor Boost 1.82**. Painful build but exact parity.
|
||||
- **C. Drop Boost.PropertyTree on Linux** and use `nlohmann/json` (already a project dep via `ANSLIBS_DIR/nlohmann`). Smaller dep surface but a code change in `ANSLicense.cpp` JSON output paths.
|
||||
|
||||
**Recommendation: A.** Defer until Phase 0.5 spike confirms it builds.
|
||||
|
||||
---
|
||||
|
||||
## Quick Start for a new session
|
||||
|
||||
If you're a fresh Claude session and the user has asked you to execute this plan:
|
||||
|
||||
1. **Read this entire document end-to-end** before editing anything. The per-file checklist in Appendix A is the source of truth for what changes.
|
||||
2. **Confirm prerequisites are in place**:
|
||||
```bash
|
||||
ls "C:/ANSLibs/ANS-HWiNFO/include/hwinfo/platform.h" # cross-platform lib present
|
||||
git status # clean working tree
|
||||
git branch --show-current # should be linux-licensing-port
|
||||
```
|
||||
3. **Verify the three product decisions above are resolved.** Ask the user to paste the answers if they're not in this doc. Do NOT start Phase 1 without Decision 1 (HWID format) answered.
|
||||
4. **Ask the user which phase to start with.** Default to Phase 0.1.
|
||||
5. **Use TaskCreate** to track progress through the phases — the seven-phase structure (0 through 4 plus per-3.x sub-phases) is the natural top-level task list.
|
||||
6. **Work in small commits.** One file, one logical change, verify build on Windows AND Linux before the next change. The Windows build must stay green at every step.
|
||||
7. **Never modify a `*_LV` function signature.** Even on Linux where we don't compile it, the source still exists on the Windows-shared file. Touch only what's gated by `#ifdef _WIN32`.
|
||||
|
||||
### How to invoke this plan
|
||||
|
||||
The user can paste any of these to start:
|
||||
|
||||
> "Read `docs/PLAN_Linux_Licensing_Port.md` and walk me through Phase 0."
|
||||
|
||||
> "Continue the Linux licensing port. Read `docs/PLAN_Linux_Licensing_Port.md` and ask what's done."
|
||||
|
||||
> "Execute Phase 1.1 from `docs/PLAN_Linux_Licensing_Port.md`."
|
||||
|
||||
### Context the new session might need that isn't in this plan
|
||||
|
||||
- **Build system on Linux**: CMake 3.28+, Ninja, GCC 11+ on Ubuntu 22.04. Cross-compile to Jetson via JetPack 6.x SDK Manager + sysroot.
|
||||
- **CUDA on Linux**: CUDA 12.x, cuDNN, TensorRT 10.x from `apt` or NVIDIA's repo.
|
||||
- **Licensing server endpoint**: ask the user for the staging URL — it is NOT in source control.
|
||||
- **Test hardware**: x86 Ubuntu box AND a Jetson Orin Nano/AGX devkit are both required. Do not declare Phase 1 done from x86 testing alone.
|
||||
|
||||
---
|
||||
|
||||
## 1. Background
|
||||
|
||||
ANSCORE targets Linux (Jetson + industrial x86) per the product roadmap. The Flutter mobile app will be replaced by a Qt QML UI talking to ANSCORE over gRPC + RTSP. Licensing is the blocking dependency: **no module can be loaded without `ANSLicensingSystem` validating the license**, so it must come first.
|
||||
|
||||
The three components are layered:
|
||||
|
||||
```
|
||||
┌──────────────────────────────┐
|
||||
│ Module DLLs (ANSCV, ANSOD,…) │ ← consumers, NOT part of this plan
|
||||
├──────────────────────────────┤
|
||||
│ ANSLicensingSystem (façade) │ ← Phase 3 (4–5 weeks)
|
||||
├──────────────────────────────┤
|
||||
│ anslicensing (SDK) │ ← Phase 1 (2–3 weeks)
|
||||
│ ANSLibsLoader (dynload) │ ← Phase 2 (1 week)
|
||||
└──────────────────────────────┘
|
||||
```
|
||||
|
||||
`ANSLicensingSystem` depends on `anslicensing`; `ANSLibsLoader` is independent of both but consumed by `ANSCV` later. Phase ordering keeps the build green at every step.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
- All three components build on Ubuntu 22.04 x86_64 and JetPack 6.x aarch64.
|
||||
- `libANSLicensingSystem.so` exports the same C++ symbols and C ABI as the Windows DLL (less LabVIEW exports).
|
||||
- Linux HWID is a 4-signal hash, equivalent strength to Windows.
|
||||
- License validation works against the existing license server.
|
||||
- All Windows behavior preserved unchanged. Zero behavioral regressions on Windows builds.
|
||||
- `rand.cpp` on Linux uses `getrandom(2)` instead of insecure `rand()`.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- LabVIEW support on Linux.
|
||||
- macOS port (separate effort).
|
||||
- `DetectClockManipulation` feature parity on Linux (acceptable degradation, logged).
|
||||
- Re-architecting the licensing protocol (wire compat preserved).
|
||||
- Engine modules (`ANSODEngine`, `ANSCV`, etc.) — separate plans.
|
||||
- Build infra changes (Conan/vcpkg adoption, etc.).
|
||||
|
||||
## 4. Phases
|
||||
|
||||
### Phase 0 — Windows-side prep (1 week, zero behavioral change)
|
||||
|
||||
Done on Windows. No Linux changes yet. Each step must keep the Windows build green and tests passing.
|
||||
|
||||
- **0.1** Add `ANSCORE_API` visibility macro to all three components' public headers:
|
||||
```cpp
|
||||
#if defined(_WIN32)
|
||||
#if defined(ANSCORE_EXPORTS)
|
||||
#define ANSCORE_API __declspec(dllexport)
|
||||
#else
|
||||
#define ANSCORE_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#define ANSCORE_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define ANSCORE_API
|
||||
#endif
|
||||
```
|
||||
Replace `__declspec(dllexport)` / `__declspec(dllimport)` site-by-site. Test on Windows that the resulting DLL exports the same symbol set (`dumpbin /exports`).
|
||||
- **0.2** Split LabVIEW exports out of `ANSLicense.h` into a new `ANSLicense_LV.h` that includes the LabVIEW header and declares only the `_LV` functions. Update Windows-side `ANSLicense.cpp` to include `ANSLicense_LV.h`. **Result: `ANSLicense.h` has zero LabVIEW types**, so Linux consumers don't drag in `extcode.h`.
|
||||
- **0.3** Strip `<windows.h>`, `<winhttp.h>`, etc. from public headers (`ANSLIB.h:6 #include <windows.h>` line is the worst offender). Use forward declarations or guard with `#ifdef _WIN32` where needed in implementation files only.
|
||||
- **0.4** Vendor `lfreist/hwinfo` as a git submodule at `3rdparty/hwinfo` (or confirm `C:/ANSLibs/ANS-HWiNFO/` is the canonical copy and update CMake to point at it consistently). Add a top-level CMake option `ANSCORE_USE_VENDORED_HWINFO` that defaults to ON.
|
||||
- **0.5** Stand up an Ubuntu 22.04 build environment (CI runner or local VM). Install: `build-essential cmake ninja-build libboost-all-dev libcurl4-openssl-dev libssl-dev libzip-dev zlib1g-dev libnvidia-ml-dev libdrm-dev libsensors4-dev`. Verify CUDA 12.x + TensorRT 10.x are reachable. Smoke test: `cmake -B build && ninja -C build core/anslicensing` should currently fail — but it should fail with **predictable errors** (missing hwinfo Linux build, etc.), not config errors.
|
||||
|
||||
**Acceptance for Phase 0**:
|
||||
- Windows build green, all existing tests pass.
|
||||
- `dumpbin /exports ANSLicensingSystem.dll` symbol set is byte-identical to baseline.
|
||||
- `ANSLicense.h` does not include `LabVIEWHeader/extcode.h`.
|
||||
- Ubuntu environment is reproducible.
|
||||
- Decision 1, 2, 3 above are answered in writing.
|
||||
|
||||
### Phase 1 — Port `core/anslicensing` (2–3 weeks)
|
||||
|
||||
This is the lowest-level SDK. Already 80% portable.
|
||||
|
||||
- **1.1** **Strengthen Linux HWID** in `hwid.cpp`:
|
||||
- Replace the `propList.push_back("4294967296")` stub at line 254 with `hwinfo::MainBoard board; propList.push_back(board.serialNumber());`. Falls back to `/proc/device-tree/serial-number` on aarch64 if board_serial is missing.
|
||||
- Implement `GetHDDPropertyList` on Linux at line 142: enumerate block devices via `/sys/block/*/device/wwid` or `/sys/block/*/device/serial`. Filter to non-removable (skip `/sys/block/*/removable == 1`).
|
||||
- Add the same source to the `MatchCurrentHardwareId` Linux branches (lines 416, 538).
|
||||
- Cross-test: HWID produced on Ubuntu must validate on the same machine across reboots.
|
||||
- **1.2** **Replace `rand.cpp` Linux RNG** with `getrandom(2)`:
|
||||
```cpp
|
||||
#include <sys/random.h>
|
||||
// ::srand(time(NULL)); ← DELETE
|
||||
// rnd = ::rand(); ← DELETE
|
||||
ssize_t n = getrandom(&rnd, sizeof(rnd), 0);
|
||||
if (n != sizeof(rnd)) {
|
||||
// fallback: open /dev/urandom directly
|
||||
}
|
||||
```
|
||||
Keep `random::random()` constructor cheap (no kernel call); make `random::rand()` the syscall site. Document the change in a header comment.
|
||||
- **1.3** **`DetectClockManipulation` Linux stub** in `helper.cpp` — return `false` with `ANS_DBG("ClockTamper", "skipped on Linux — no-op fallback")`. Document as a known degradation.
|
||||
- **1.4** **Wire CMake on Linux**. The CMakeLists already has the Linux branch; verify:
|
||||
- `find_package(CURL REQUIRED)` resolves
|
||||
- `target_link_libraries(... curl ssl crypto)` links cleanly
|
||||
- Add `find_package(hwinfo REQUIRED)` or use the submodule
|
||||
- **1.5** **Round-trip test**: a small test binary that calls `HardwareId::GetCurrentHardwareId()`, persists the string, then calls `HardwareId::MatchCurrentHardwareId(saved)` and asserts true. Run on Ubuntu x86 AND a Jetson devkit.
|
||||
|
||||
**Acceptance for Phase 1**:
|
||||
- `libanslicensing.so` builds on Ubuntu 22.04 x86_64 and Jetson aarch64.
|
||||
- Round-trip HWID test passes on both targets across at least 3 reboots.
|
||||
- `strings libanslicensing.so | grep -c '4294967296'` returns 0.
|
||||
- Static analysis (cppcheck or clang-tidy) shows no new warnings on Linux build.
|
||||
|
||||
### Phase 2 — Port `core/ANSLibsLoader` (1 week)
|
||||
|
||||
Mechanical port from `LoadLibrary`/`GetProcAddress` to `dlopen`/`dlsym`. Independent of Phase 1 and Phase 3 — can be done in parallel.
|
||||
|
||||
- **2.1** Port `DynLibUtils.cpp` core helpers:
|
||||
```cpp
|
||||
#ifdef _WIN32
|
||||
HMODULE LoadLib(const char* p) { return LoadLibraryA(p); }
|
||||
void* GetSym(HMODULE h, const char* s) { return GetProcAddress(h, s); }
|
||||
void UnloadLib(HMODULE h) { FreeLibrary(h); }
|
||||
#else
|
||||
void* LoadLib(const char* p) { return dlopen(p, RTLD_NOW | RTLD_LOCAL); }
|
||||
void* GetSym(void* h, const char* s) { return dlsym(h, s); }
|
||||
void UnloadLib(void* h) { dlclose(h); }
|
||||
#endif
|
||||
```
|
||||
Wrap the handle type behind an opaque `DynLibHandle` typedef so callers don't see the difference.
|
||||
- **2.2** Update `CvLoader.cpp`, `NvDynLoader.cpp`, `OvLoader.cpp`, `EPLoader.cpp` to use the cross-platform helpers. Most logic is search-path discovery — that needs branching too:
|
||||
- Windows: `C:/ANSLibs/...` paths
|
||||
- Linux: `/opt/ANSLibs/...`, `/usr/lib/x86_64-linux-gnu/`, `/usr/local/cuda/lib64/`, and `${LD_LIBRARY_PATH}`
|
||||
- **2.3** Naming convention: Windows `.dll`, Linux `.so` with `lib` prefix. Centralize in a `PLATFORM_DLL_NAME("opencv_world")` macro that expands to `"opencv_world.dll"` on Windows and `"libopencv_world.so"` on Linux.
|
||||
- **2.4** Symbol visibility: Linux `.so` exports everything by default unless built with `-fvisibility=hidden`. Apply `-fvisibility=hidden` globally in the top-level CMakeLists and use the `ANSCORE_API` macro to opt in to exports.
|
||||
- **2.5** Smoke test: `ANSLibsLoader` opens `libopencv_world.so` on Ubuntu and returns valid handles for a known set of OpenCV symbols.
|
||||
|
||||
**Acceptance for Phase 2**:
|
||||
- `libANSLibsLoader.so` builds and runs.
|
||||
- All four sub-loaders (CV/OV/NV/EP) load their respective libraries successfully on Linux.
|
||||
- No symbol-visibility regressions on Windows (verify with `dumpbin /exports`).
|
||||
|
||||
### Phase 3 — Port `core/ANSLicensingSystem` (4–5 weeks)
|
||||
|
||||
The big one. Split into independently mergeable PRs.
|
||||
|
||||
#### 3.1 — Misc Win32 cleanup (1 day)
|
||||
|
||||
- `GlobalMemoryStatusEx` → read `/proc/meminfo` MemTotal / MemAvailable
|
||||
- `GetProcessMemoryInfo` → read `/proc/self/status` VmRSS, VmSwap, VmPeak
|
||||
- `GetSystemDirectoryW + GetDiskFreeSpaceExW` (line 1056-1064) → `statvfs("/")`
|
||||
- `GetCurrentProcessId` → `getpid()`
|
||||
- `WideCharToMultiByte` / `WideToUtf8` → `std::wstring_convert` or just use `std::string` throughout the Linux path (no wide chars needed without WMI)
|
||||
|
||||
#### 3.2 — CPU thermal (1 day)
|
||||
|
||||
Replace `ReadCpuTempCelsiusViaWmi()` (line 603) with a Linux reader:
|
||||
|
||||
```cpp
|
||||
double ReadCpuTempCelsiusLinux() {
|
||||
// Scan /sys/class/thermal/thermal_zone*/type for "x86_pkg_temp" (x86)
|
||||
// or "CPU-therm" / "thermal-fan-est" (Jetson)
|
||||
// Read corresponding /sys/class/thermal/thermal_zone*/temp (milli-Celsius)
|
||||
// Return max across all CPU zones, or -1 if none found
|
||||
}
|
||||
```
|
||||
|
||||
Keep the Windows function intact behind `#ifdef _WIN32`. Dispatch through a single `ReadCpuTempCelsius()` wrapper.
|
||||
|
||||
#### 3.3 — System health sampler / PDH rewrite (1 week)
|
||||
|
||||
The `HealthSampler` class (lines 906–1089) is the largest single port. Build a Linux `HealthSamplerLinux` class with the same public API as the Windows one. Then dispatch at instantiation:
|
||||
|
||||
```cpp
|
||||
#ifdef _WIN32
|
||||
using HealthSampler = HealthSamplerWin;
|
||||
#else
|
||||
using HealthSampler = HealthSamplerLinux;
|
||||
#endif
|
||||
```
|
||||
|
||||
PDH counter → Linux source mapping:
|
||||
|
||||
| PDH counter | Linux source |
|
||||
|---|---|
|
||||
| `\Processor Information(_Total)\% Processor Time` | `/proc/stat` delta of (user+nice+system) vs idle |
|
||||
| `\Processor Information(_Total)\% Processor Performance` | `/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq` / base freq |
|
||||
| `\Processor Information(_Total)\% Processor Utility` | Same as Processor Time on Linux (no MS-specific util concept) |
|
||||
| `\PhysicalDisk(_Total)\% Disk Time` | `/proc/diskstats` field 13 (io_time ms / interval ms) |
|
||||
| `\PhysicalDisk(_Total)\Disk Read Bytes/sec` | `/proc/diskstats` field 6 × 512 / interval |
|
||||
| `\PhysicalDisk(_Total)\Disk Write Bytes/sec` | `/proc/diskstats` field 10 × 512 / interval |
|
||||
| `\Network Interface(*)\Bytes Received/Sent/sec` | `/proc/net/dev` rx_bytes / tx_bytes deltas |
|
||||
| `\Network Interface(*)\Current Bandwidth` | `/sys/class/net/*/speed` (Mbit/s) |
|
||||
| `\GPU Engine(*)\Utilization Percentage` | NVML `nvmlDeviceGetUtilizationRates` |
|
||||
| `\GPU Process Memory(*)\Dedicated Usage` | NVML `nvmlDeviceGetMemoryInfo` |
|
||||
|
||||
The sampler keeps a `prev_*` snapshot for delta computation (no PDH built-in differencing on Linux). Sample interval: same 2-second cadence as Windows.
|
||||
|
||||
Acceptance: the populated `ANSCENTER::SystemHealthInfo` struct has all the same fields filled on Linux as on Windows (allowing -1 / empty for fields that genuinely don't exist).
|
||||
|
||||
#### 3.4 — GPU adapter enumeration (1 week)
|
||||
|
||||
Replace `EnumerateGpuAdapters` (line 721) with NVML on systems with NVIDIA drivers, falling back to libdrm:
|
||||
|
||||
```cpp
|
||||
std::vector<GpuAdapter> EnumerateGpuAdaptersLinux() {
|
||||
std::vector<GpuAdapter> out;
|
||||
|
||||
// Try NVML first (covers Jetson + dGPU x86)
|
||||
if (nvmlInit_v2() == NVML_SUCCESS) {
|
||||
unsigned int count = 0;
|
||||
nvmlDeviceGetCount_v2(&count);
|
||||
for (unsigned int i = 0; i < count; ++i) {
|
||||
nvmlDevice_t dev;
|
||||
nvmlDeviceGetHandleByIndex_v2(i, &dev);
|
||||
GpuAdapter a;
|
||||
// populate a.name, a.vendorId=0x10DE, a.dedicatedVramMB...
|
||||
out.push_back(a);
|
||||
}
|
||||
nvmlShutdown();
|
||||
}
|
||||
|
||||
// Then enumerate non-NVIDIA via libdrm (/dev/dri/card*)
|
||||
// for Intel/AMD users on x86 Linux
|
||||
// ...
|
||||
|
||||
return out;
|
||||
}
|
||||
```
|
||||
|
||||
`AggregateGpuCounter` (line 773) — the LUID-based attribution machinery — collapses on Linux because NVML hands you per-device handles directly. Replace with a simpler `for (auto& dev : nvmlDevices)` loop.
|
||||
|
||||
Caveat: `nvmlDeviceGetUtilizationRates` returns whole-device utilization, not per-process. Per-process GPU memory needs `nvmlDeviceGetProcessUtilization` (where supported) or `nvmlDeviceGetComputeRunningProcesses`. On Jetson, NVML support is partial — test early.
|
||||
|
||||
#### 3.5 — License-server HTTP (1 day)
|
||||
|
||||
Delete the `WinHttpHandle` block (lines 1101–1166) on Linux. Reuse `anslicensing/download.cpp`'s `UrlDownloadToString` libcurl path. The function signature is already compatible. One small wrinkle: `UrlDownloadToString` is in `anslicensing.dll`, so `ANSLicensingSystem` must link against it — it already does.
|
||||
|
||||
#### 3.6 — DNS public-IP probe (0.5 day)
|
||||
|
||||
Replace `DnsQuery_A` (line 1228) with `getaddrinfo`:
|
||||
|
||||
```cpp
|
||||
struct addrinfo hints{}, *res = nullptr;
|
||||
hints.ai_family = AF_INET;
|
||||
if (getaddrinfo("myip.opendns.com", nullptr, &hints, &res) == 0 && res) {
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &((sockaddr_in*)res->ai_addr)->sin_addr, buf, sizeof(buf));
|
||||
publicIp = buf;
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
```
|
||||
|
||||
If the existing Windows query uses a TXT record specifically, fall back to `libresolv res_query` for parity. Verify with the user which probe is in use.
|
||||
|
||||
#### 3.7 — CMake + linking (3 days)
|
||||
|
||||
Rewrite `ANSLicensingSystem/CMakeLists.txt` Linux branch:
|
||||
|
||||
```cmake
|
||||
if(WIN32)
|
||||
target_link_libraries(ANSLicensingSystem PRIVATE
|
||||
HWiNFO.lib OpenCL.lib OpenCLExt.lib
|
||||
bz2.lib zip.lib
|
||||
libboost_log-vc143-mt-x64-1_82.lib
|
||||
shlwapi.lib winhttp.lib pdh.lib psapi.lib
|
||||
wbemuuid.lib oleaut32.lib ole32.lib dxgi.lib dnsapi.lib
|
||||
${WIN_COMMON_LIBS}
|
||||
)
|
||||
else()
|
||||
find_package(Boost REQUIRED COMPONENTS log date_time)
|
||||
find_package(CURL REQUIRED)
|
||||
target_link_libraries(ANSLicensingSystem PRIVATE
|
||||
hwinfo::hwinfo # vendored or apt
|
||||
Boost::log Boost::date_time
|
||||
CURL::libcurl
|
||||
zip # libzip-dev
|
||||
z # zlib1g-dev
|
||||
nvidia-ml # libnvidia-ml-dev (NVML)
|
||||
drm # libdrm-dev (optional, for non-NVIDIA)
|
||||
pthread dl
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(ANSLicensingSystem PRIVATE
|
||||
ANSLICENSE_EXPORTS
|
||||
ANSLICENSINGSYSTEM_EXPORTS
|
||||
$<$<PLATFORM_ID:Windows>:UNICODE _UNICODE>
|
||||
)
|
||||
```
|
||||
|
||||
Drop `ANSLIBS_DIR/ANS-HWiNFO/lib` and `ANSLIBS_DIR/boost/lib` from `target_link_directories` on Linux.
|
||||
|
||||
#### 3.8 — End-to-end license activation (3 days)
|
||||
|
||||
Run the full activation flow from a Linux client against the staging license server:
|
||||
|
||||
1. `GenerateHardwareId()` returns a string
|
||||
2. Operator pastes it into the activation portal
|
||||
3. Server returns license blob
|
||||
4. Linux client `ValidateLicense(blob)` returns `SUCCESS`
|
||||
5. Subsequent `IsLicenseValid()` calls return true
|
||||
6. Restart process — license still valid
|
||||
7. Move drive to second machine — license **invalid** (HWID mismatch detected)
|
||||
|
||||
The last item is the critical anti-piracy check. If it fails (license validates on second machine), the HWID is too lax — go back to Phase 1.1.
|
||||
|
||||
**Acceptance for Phase 3 overall**:
|
||||
- `libANSLicensingSystem.so` builds and links cleanly.
|
||||
- All public symbols (less `_LV` set) match Windows-side exports.
|
||||
- Full activation round-trip succeeds against staging server.
|
||||
- `SystemHealthInfo` struct populates all fields with real (non -1) data on Jetson and on x86 Ubuntu.
|
||||
- Anti-piracy test passes (HWID mismatch is detected).
|
||||
|
||||
### Phase 4 — Integration & Hardening (1 week)
|
||||
|
||||
- **4.1** **Cross-arch CI**: add an `aarch64` build matrix entry. Cross-compile from x86 host using JetPack 6.x sysroot, or natively on a Jetson runner. Both options work; pick whichever the team prefers.
|
||||
- **4.2** **Soak test**: run an ANSLicensingSystem-based test harness on a Jetson for 24 hours. Watch for memory leaks (`valgrind --leak-check=full` for a short run, then `top` / smaps tracking long-term). NVML on Jetson has known leak patterns — defend against them.
|
||||
- **4.3** **Documentation**: write `docs/LINUX_BUILD_GUIDE.md` covering apt deps, Boost version notes, Jetson cross-compile, and the HWID format change (so support knows licenses don't transfer Windows↔Linux without re-issuance).
|
||||
- **4.4** **Top-level CMake gating**: in the root `CMakeLists.txt`, remove `if(WIN32)` gates around the three components — they now build everywhere. Engine modules stay Windows-only for now since this plan doesn't cover them.
|
||||
|
||||
**Acceptance for Phase 4**:
|
||||
- CI green on Windows, Ubuntu x86, Jetson aarch64.
|
||||
- 24h soak shows stable memory profile.
|
||||
- LINUX_BUILD_GUIDE.md merged and reviewed.
|
||||
|
||||
---
|
||||
|
||||
## 5. Risks & mitigations
|
||||
|
||||
| Risk | Likelihood | Impact | Mitigation |
|
||||
|---|---|---|---|
|
||||
| License server rejects Linux HWID format | Medium | **Blocks Phase 1 acceptance** | Resolve Decision 1 before Phase 0; coordinate with backend team early |
|
||||
| Jetson `/sys/class/dmi/id/board_serial` missing | High | Phase 1 HWID is weak on Jetson | Decision 2: validate on real Jetson hardware; fall back to device-tree serial |
|
||||
| NVML on Jetson missing some APIs | Medium | GPU telemetry sparse on Jetson | Test `nvmlDeviceGetUtilizationRates` early; gracefully degrade fields that aren't available |
|
||||
| Boost version mismatch (1.74 system vs 1.82 vendored) | Medium | Subtle behavioral differences | Phase 0.5 spike build; switch to nlohmann/json if PropertyTree breaks |
|
||||
| `lfreist/hwinfo` ARM support gaps | Low | HWID source incomplete on Jetson | Read its `cpuid.h` Linux branch; have device-tree fallback ready |
|
||||
| Symbol visibility differences cause ABI breakage | Low | Linker errors at integration time | `-fvisibility=hidden` from day one; `ANSCORE_API` discipline |
|
||||
| WMI thermal-zone has no Linux semantic equivalent | Low | `cpuTempDegC` field is less accurate | Document field as "best-effort, may be -1 on hardware without thermal zones" |
|
||||
| `libnvidia-ml` not present on dev-only x86 box | Low | Build fails on developer machines | dynamic-load NVML via dlopen with weak symbol; fallback to "no GPU" state |
|
||||
|
||||
---
|
||||
|
||||
## 6. Dependencies for Ubuntu / Jetson development
|
||||
|
||||
```bash
|
||||
# Build essentials
|
||||
sudo apt install -y \
|
||||
build-essential cmake ninja-build pkg-config git \
|
||||
libboost-all-dev libcurl4-openssl-dev libssl-dev \
|
||||
libzip-dev zlib1g-dev \
|
||||
libnvidia-ml-dev libdrm-dev libsensors4-dev \
|
||||
libgtest-dev cppcheck clang-tidy
|
||||
|
||||
# CUDA 12.x + cuDNN + TensorRT 10.x — from NVIDIA's apt repo (separate setup)
|
||||
# JetPack 6.x — flash via SDK Manager onto target board
|
||||
```
|
||||
|
||||
For Jetson cross-compile: install JetPack 6.x SDK on host, point CMake at `/opt/nvidia/jetson-linux-sysroot/aarch64-ubuntu22.04`.
|
||||
|
||||
---
|
||||
|
||||
## 7. Testing strategy
|
||||
|
||||
- **Unit tests** (`tests/anslicensing-unittest`): exercise each platform-specific helper with known synthetic data. New tests: HWID-determinism, getrandom-fallback, /proc/meminfo parser, /proc/stat delta computation.
|
||||
- **Integration tests** (`tests/anslicensingsystem-integration`): in-process activation round-trip against a mock license server. Run on Windows + Linux + Jetson.
|
||||
- **E2E tests**: real staging server. Run **once per phase acceptance**, not on every commit (slow + flaky over real network).
|
||||
- **Anti-piracy regression test**: documented in Phase 3.8. **Must run before merging Phase 3 to main.**
|
||||
- **Determinism test**: generate HWID 10× across reboots on the same machine; assert all identical. Generate on two physically different Jetsons; assert different.
|
||||
|
||||
---
|
||||
|
||||
## Appendix A — Per-file change checklist
|
||||
|
||||
Files marked **NEW** are created; **MOD** is modified; **DELETE** is removed.
|
||||
|
||||
### `core/anslicensing/`
|
||||
|
||||
| File | Action | Phase | Change |
|
||||
|---|---|---|---|
|
||||
| `hwid.cpp` | MOD | 1.1 | Linux branches: use `hwinfo::MainBoard::serialNumber()` for UUID slot; implement `GetHDDPropertyList` reading `/sys/block/*/device/wwid` |
|
||||
| `rand.cpp` | MOD | 1.2 | Replace `srand`/`rand` with `getrandom(2)` + `/dev/urandom` fallback |
|
||||
| `helper.cpp` | MOD | 1.3 | `DetectClockManipulation` Linux stub with ANS_DBG warning |
|
||||
| `download.cpp` | — | — | Already done — libcurl path exists |
|
||||
| `precomp.h` | — | — | Already done — POSIX shims exist |
|
||||
| `CMakeLists.txt` | MOD | 1.4 | Add `find_package(hwinfo)` on non-Windows |
|
||||
|
||||
### `core/ANSLicensingSystem/`
|
||||
|
||||
| File | Action | Phase | Change |
|
||||
|---|---|---|---|
|
||||
| `ANSLicense.h` | MOD | 0.2 | Remove `#include "LabVIEWHeader/extcode.h"`; remove `LDbl`/`LDblPtr`/`LDblHandle` (moved to `ANSLicense_LV.h`) |
|
||||
| `ANSLicense_LV.h` | NEW | 0.2 | Windows-only header with all `_LV` exports, includes `extcode.h` |
|
||||
| `ANSLicense.cpp` | MOD | 3.1–3.6 | Replace each Win32 call site with `#ifdef _WIN32` / `#else` branch |
|
||||
| `HealthSamplerLinux.cpp` | NEW | 3.3 | New file: `/proc`-based sampler |
|
||||
| `HealthSamplerLinux.h` | NEW | 3.3 | Class declaration matching `HealthSampler`'s public API |
|
||||
| `Utility.h` | MOD | 0.3 | Strip any Windows-specific types from declarations |
|
||||
| `Utility.cpp` | MOD | 3.1 | Verify std::filesystem path operations work on Linux |
|
||||
| `CMakeLists.txt` | MOD | 3.7 | Add Linux branch with curl/boost/hwinfo/nvml |
|
||||
|
||||
### `core/ANSLibsLoader/`
|
||||
|
||||
| File | Action | Phase | Change |
|
||||
|---|---|---|---|
|
||||
| `DynLibUtils.cpp` | MOD | 2.1 | dlopen/dlsym/dlclose Linux branches |
|
||||
| `CvLoader.cpp` | MOD | 2.2 | Linux search paths + `.so` naming |
|
||||
| `NvDynLoader.cpp` | MOD | 2.2 | Linux search paths |
|
||||
| `OvLoader.cpp` | MOD | 2.2 | Linux search paths |
|
||||
| `EPLoader.cpp` | MOD | 2.2 | Linux search paths |
|
||||
| `ANSLibsLoader.def` | — | — | Windows-only `.def`; leave alone, use `__attribute__((visibility))` on Linux |
|
||||
| `CMakeLists.txt` | MOD | 2.4 | `-fvisibility=hidden`; link `dl` on Linux |
|
||||
|
||||
### Top-level
|
||||
|
||||
| File | Action | Phase | Change |
|
||||
|---|---|---|---|
|
||||
| `CMakeLists.txt` | MOD | 0.4, 4.4 | `ANSCORE_USE_VENDORED_HWINFO` option; ungate three core components from `if(WIN32)` |
|
||||
| `cmake/Dependencies.cmake` | MOD | 0.4, 3.7 | Add `hwinfo`, `NVML` (`CUDA::nvml`), `libdrm` resolution |
|
||||
| `3rdparty/hwinfo/` | NEW (submodule) | 0.4 | `git submodule add https://github.com/lfreist/hwinfo 3rdparty/hwinfo` |
|
||||
| `docs/LINUX_BUILD_GUIDE.md` | NEW | 4.3 | Developer onboarding |
|
||||
|
||||
---
|
||||
|
||||
## Appendix B — Symbol map (Win32 → Linux)
|
||||
|
||||
Reference table for the engineer porting `ANSLicense.cpp`:
|
||||
|
||||
| Win32 symbol / API | File:line | Linux replacement |
|
||||
|---|---|---|
|
||||
| `PdhOpenQueryW` / `PdhAddEnglishCounterW` / `PdhCollectQueryData` | ANSLicense.cpp:906–928 | Custom `/proc/stat`, `/proc/diskstats`, `/proc/net/dev` delta sampler (Phase 3.3) |
|
||||
| `IWbemLocator::ConnectServer("ROOT\\WMI")` + `MSAcpi_ThermalZoneTemperature` | ANSLicense.cpp:618–663 | `/sys/class/thermal/thermal_zone*/temp` (Phase 3.2) |
|
||||
| `CreateDXGIFactory1` / `IDXGIAdapter1::GetDesc1` | ANSLicense.cpp:721–747 | `nvmlDeviceGetCount_v2` + per-device queries; libdrm for non-NVIDIA (Phase 3.4) |
|
||||
| `WinHttpOpen` / `WinHttpSendRequest` / etc. | ANSLicense.cpp:1101–1166 | Reuse `anslicensing/download.cpp` libcurl path (Phase 3.5) |
|
||||
| `DnsQuery_A` | ANSLicense.cpp:1228 | `getaddrinfo` or `res_query` (Phase 3.6) |
|
||||
| `GlobalMemoryStatusEx` | ANSLicense.cpp:1036 | `/proc/meminfo` parser (Phase 3.1) |
|
||||
| `GetProcessMemoryInfo` | ANSLicense.cpp:1048 | `/proc/self/status` parser (Phase 3.1) |
|
||||
| `GetSystemDirectoryW` + `GetDiskFreeSpaceExW` | ANSLicense.cpp:1056–1064 | `statvfs("/")` (Phase 3.1) |
|
||||
| `GetCurrentProcessId` | ANSLicense.cpp:993, 1026 | `getpid()` (Phase 3.1) |
|
||||
| `WideCharToMultiByte` / `WideToUtf8` | ANSLicense.cpp:712 | drop on Linux — no wide chars needed without WMI |
|
||||
| `CoInitializeEx` / `CoSetProxyBlanket` / `CoUninitialize` | ANSLicense.cpp:604, 611, 669 | delete on Linux — COM not needed |
|
||||
| `__declspec(dllexport)` | (everywhere) | `__attribute__((visibility("default")))` via `ANSCORE_API` macro (Phase 0.1) |
|
||||
| `LStrHandle`, `LDbl`, `extcode.h` | ANSLicense.h:75 + many | move to `ANSLicense_LV.h`, Windows-only (Phase 0.2) |
|
||||
|
||||
---
|
||||
|
||||
## Appendix C — License-server coordination checklist
|
||||
|
||||
Before Phase 1 starts, the license-server team confirms in writing:
|
||||
|
||||
- [ ] Server accepts HWID format generated by the new Linux `hwid.cpp` path
|
||||
- [ ] Server's HWID validation algorithm matches the new client-side hash inputs
|
||||
- [ ] Decision on license-pool separation: unified vs. Linux-only pool
|
||||
- [ ] Staging environment endpoint available for E2E testing in Phase 3.8
|
||||
- [ ] Activation portal supports pasting a Linux-generated HWID
|
||||
|
||||
---
|
||||
|
||||
## Appendix D — What this plan deliberately does NOT cover
|
||||
|
||||
So a future session doesn't accidentally scope-creep:
|
||||
|
||||
- **MediaClient port to Linux** — separate plan; ANSCV depends on this but licensing does not
|
||||
- **GStreamer backend for ANSCV** — separate plan
|
||||
- **Engine modules** (ANSODEngine, ANSFR, ANSLPR, ANSOCR, etc.) — separate plans, post-licensing
|
||||
- **gRPC service layer** (ANSService) — planned after engine modules are up
|
||||
- **Qt QML UI** — separate repo, depends on gRPC layer
|
||||
- **macOS support** — not in roadmap currently
|
||||
- **Dropping LabVIEW on Windows** — `_LV` exports stay on Windows builds untouched
|
||||
- **License protocol changes** — wire compatibility preserved; only the input data to the HWID hash changes on Linux
|
||||
|
||||
---
|
||||
|
||||
*End of plan.*
|
||||
@@ -0,0 +1,48 @@
|
||||
@startuml 01-system-context
|
||||
title ANSCORE — System Context (L1 / L2 / L3)
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
skinparam packageStyle rectangle
|
||||
|
||||
package "Layer 3 — Qt/QML Desktop UI\n(Windows / macOS / Linux)" as L3 {
|
||||
component "Qt/QML application" as UI
|
||||
}
|
||||
|
||||
package "Layer 2 — ANSVIS Communication Layer (CL)" as L2 {
|
||||
component "/api/v1\nREST surface" as APIV1
|
||||
component "Legacy ANSVIS core\n(reused as-is)" as LEGACY
|
||||
component "Media relay\nHLS / RTSP / WebRTC" as RELAY
|
||||
component "SSE event\nbroadcaster" as SSEHUB
|
||||
database "Event DB\n+ clip object store" as STORE
|
||||
queue "Async job queue" as JOBS
|
||||
component "Auth + RBAC" as AUTH
|
||||
}
|
||||
|
||||
package "Layer 1 — ANSCORE Edge Runtime\n(one per target)" as L1 {
|
||||
component "Camera + Inference\n+ Triggers" as EDGE
|
||||
}
|
||||
|
||||
UI --> APIV1 : (1) REST / HTTPS\ncontrol + CRUD
|
||||
UI --> SSEHUB : (2) SSE / HTTPS\nlive event tail
|
||||
UI --> RELAY : (3) HLS / RTSP / WebRTC\nlive video
|
||||
|
||||
APIV1 --> AUTH
|
||||
APIV1 --> LEGACY
|
||||
APIV1 --> JOBS
|
||||
APIV1 --> STORE
|
||||
LEGACY --> STORE
|
||||
STORE --> SSEHUB
|
||||
RELAY <--> EDGE
|
||||
LEGACY <--> EDGE
|
||||
|
||||
note bottom of L3
|
||||
L3 only talks to L2 — never directly to edges.
|
||||
end note
|
||||
|
||||
note bottom of L2
|
||||
All three UI transports are brokered by the REST API:
|
||||
the URL + token for live media and the SSE filter for
|
||||
events are obtained via REST calls first.
|
||||
end note
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,84 @@
|
||||
@startuml 02-l2-internals
|
||||
title Layer 2 — ANSVIS internal architecture
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
skinparam packageStyle rectangle
|
||||
|
||||
actor "Qt / QML UI" as QT
|
||||
actor "3rd-party\nintegrations" as EXT
|
||||
|
||||
package "L2 /api/v1 surface" as EDGE_API {
|
||||
component "REST router" as ROUTER
|
||||
component "Auth middleware\n(Bearer)" as AUTHMW
|
||||
component "Request validation\n(OpenAPI schemas)" as VALID
|
||||
component "Error mapper\n(RFC 7807)" as ERR
|
||||
component "Rate limiter" as RATE
|
||||
component "SSE broadcaster\n(per-subscription filter)" as SSEHUB
|
||||
}
|
||||
|
||||
package "v1 Adapter Layer\n(per-resource modules)" as ADAPTER {
|
||||
component "cameras" as CAM_AD
|
||||
component "models" as MOD_AD
|
||||
component "edges" as EDGE_AD
|
||||
component "deployment-groups" as DG_AD
|
||||
component "ai-tasks" as TASK_AD
|
||||
component "events" as EV_AD
|
||||
component "fr" as FR_AD
|
||||
component "alpr" as ALPR_AD
|
||||
component "notifications" as NOTIF_AD
|
||||
component "system" as SYS_AD
|
||||
component "jobs" as JOB_AD
|
||||
}
|
||||
|
||||
package "Legacy ANSVIS server\n(reused as-is)" as LEGACY {
|
||||
component "Config store" as LEG_CFG
|
||||
component "AI task engine" as LEG_TASKS
|
||||
component "FR engine" as LEG_FR
|
||||
component "ALPR engine" as LEG_ALPR
|
||||
}
|
||||
|
||||
package "Infrastructure" as INFRA {
|
||||
component "Auth + token store" as AUTH_SVC
|
||||
queue "Job queue\n(scans, uploads, deploys, updates)" as JOBS_Q
|
||||
database "Event metadata DB" as EVENTS_DB
|
||||
database "Clip / image object store\n(S3 / MinIO / FS)" as CLIPS
|
||||
component "Logs + metrics + health" as LOGS
|
||||
component "Media relay\nHLS / RTSP / WebRTC" as RELAY
|
||||
}
|
||||
|
||||
actor "L1 edge target(s)" as E1
|
||||
|
||||
QT --> ROUTER
|
||||
EXT --> ROUTER
|
||||
ROUTER --> AUTHMW
|
||||
AUTHMW --> VALID
|
||||
VALID --> RATE
|
||||
RATE --> ADAPTER
|
||||
ADAPTER --> ERR
|
||||
ADAPTER ..> ROUTER : response
|
||||
|
||||
AUTHMW --> AUTH_SVC
|
||||
|
||||
CAM_AD --> LEG_CFG
|
||||
MOD_AD --> LEG_CFG
|
||||
MOD_AD --> CLIPS
|
||||
EDGE_AD --> LEG_CFG
|
||||
DG_AD --> LEG_TASKS
|
||||
TASK_AD --> LEG_TASKS
|
||||
EV_AD --> EVENTS_DB
|
||||
EV_AD --> CLIPS
|
||||
FR_AD --> LEG_FR
|
||||
ALPR_AD --> LEG_ALPR
|
||||
SYS_AD --> LOGS
|
||||
JOB_AD --> JOBS_Q
|
||||
CAM_AD ..> JOBS_Q : scan / probe
|
||||
MOD_AD ..> JOBS_Q : large upload
|
||||
|
||||
LEG_TASKS --> EVENTS_DB
|
||||
EVENTS_DB --> SSEHUB
|
||||
SSEHUB --> ROUTER
|
||||
|
||||
LEGACY <--> E1
|
||||
RELAY <--> E1
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,51 @@
|
||||
@startuml 03-l2-ownership
|
||||
title Layer 2 — Build ownership
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
skinparam packageStyle rectangle
|
||||
|
||||
package "Architect-owned\n(lead review)" as HUMAN #LightYellow {
|
||||
component "REST router\n+ auth middleware" as H1
|
||||
component "RFC 7807\nerror mapper" as H2
|
||||
component "OpenAPI validation\npipeline" as H3
|
||||
component "Auth flow\n+ token store" as H4
|
||||
component "RBAC\n+ security review" as H5
|
||||
component "L2 ↔ L1 tunnel\n+ signing" as H6
|
||||
}
|
||||
|
||||
package "Core team\n(modular adapters)" as AI #LightBlue {
|
||||
component "cameras adapter" as A1
|
||||
component "models adapter\n+ upload pipeline" as A2
|
||||
component "edges adapter" as A3
|
||||
component "deployment-groups\nadapter" as A4
|
||||
component "ai-tasks adapter" as A5
|
||||
component "events adapter\n+ SSE broadcaster" as A6
|
||||
component "fr adapter" as A7
|
||||
component "alpr adapter" as A8
|
||||
component "notifications adapter" as A9
|
||||
component "system / health /\nlogs adapter" as A10
|
||||
component "job queue + workers" as A11
|
||||
component "media relay" as A12
|
||||
}
|
||||
|
||||
package "Existing ANSVIS\n(reused as-is)" as EXIST #LightGray {
|
||||
component "Task engine" as L_TASKS
|
||||
component "FR engine" as L_FR
|
||||
component "ALPR engine" as L_ALPR
|
||||
component "Config store" as L_CFG
|
||||
}
|
||||
|
||||
HUMAN --> AI
|
||||
AI --> EXIST
|
||||
|
||||
note bottom of HUMAN
|
||||
Cross-cutting concerns kept under direct architect review:
|
||||
request validation, errors, auth, RBAC, tunnel security.
|
||||
end note
|
||||
|
||||
note bottom of AI
|
||||
Highly modular by resource — the core team works in parallel
|
||||
on independent adapters without colliding.
|
||||
end note
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,65 @@
|
||||
@startuml 04-l3-internals
|
||||
title Layer 3 — Qt 6 / QML internal architecture
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
skinparam packageStyle rectangle
|
||||
|
||||
package "Qt 6 + QML — Layer 3" as QT {
|
||||
|
||||
package "App Shell" as SHELL {
|
||||
component "Main window" as MAIN
|
||||
component "Navigation router" as ROUTE
|
||||
component "Design system / theme" as THEME
|
||||
component "i18n (qsTr / Linguist)" as I18N
|
||||
component "Auth state + token store" as AUTH_ST
|
||||
component "Error toast / dialog" as ERR_UI
|
||||
}
|
||||
|
||||
package "Network layer" as NET {
|
||||
component "Generated REST client\n(openapi.v1.json → C++/Qt)" as REST
|
||||
component "SSE subscriber\n(QNetworkReply chunked)" as SSE_CL
|
||||
component "Media client\nQtMultimedia / GStreamer" as MEDIA
|
||||
component "Bbox overlay renderer\n(custom QQuickItem)" as OVERLAY
|
||||
component "Multipart + presigned\nuploader" as UPLOAD
|
||||
}
|
||||
|
||||
package "Domain state (QObject + signals)" as STATE {
|
||||
component "CamerasModel" as ST_CAM
|
||||
component "ModelsModel" as ST_MOD
|
||||
component "EdgesModel" as ST_EDGE
|
||||
component "DeploymentGroupsModel" as ST_DG
|
||||
component "AITasksModel" as ST_TASK
|
||||
component "EventsModel + LiveBuffer" as ST_EV
|
||||
component "FRPersonsModel" as ST_FR
|
||||
component "ALPRPlatesModel" as ST_ALPR
|
||||
component "RecipientsModel" as ST_NOTIF
|
||||
component "SystemHealthModel" as ST_SYS
|
||||
}
|
||||
|
||||
package "Screens (QML)" as SCREENS {
|
||||
component "Login" as LOGIN
|
||||
component "Dashboard /\ntargets overview" as DASH
|
||||
component "Camera management\n+ ONVIF discovery\n+ calibration" as CAM_S
|
||||
component "Pipeline editor\n(visual DAG)" as DG_EDIT
|
||||
component "AI Task config" as TASK_EDIT
|
||||
component "Rules / triggers" as RULE_S
|
||||
component "Liveview grid" as LIVE
|
||||
component "Eventview timeline" as EV_S
|
||||
component "FR persons + faces" as FR_S
|
||||
component "ALPR plates" as ALPR_S
|
||||
component "Model registry" as MODEL_S
|
||||
component "Users / admin" as USERS
|
||||
component "Settings" as SETTINGS
|
||||
}
|
||||
}
|
||||
|
||||
actor "ANSVIS /api/v1" as BACKEND
|
||||
|
||||
SCREENS --> STATE : reads / mutates
|
||||
STATE --> NET : calls
|
||||
NET <--> BACKEND
|
||||
OVERLAY ..> MEDIA : sync to PTS
|
||||
AUTH_ST ..> REST : injects Bearer
|
||||
AUTH_ST ..> SSE_CL : injects Bearer
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,45 @@
|
||||
@startuml 05-seq-configure-deploy
|
||||
title Sequence — Operator configures camera + AI task and deploys
|
||||
|
||||
actor "Operator" as User
|
||||
participant "Qt UI" as UI
|
||||
participant "ANSVIS\n/api/v1" as API
|
||||
participant "ANSVIS core" as LEG
|
||||
participant "L1 edge" as EDGE
|
||||
|
||||
User -> UI : Open Cameras screen
|
||||
UI -> API : GET /cameras?page=1
|
||||
API -> LEG : legacy list
|
||||
LEG --> API : cameras
|
||||
API --> UI : 200 {items, page, total}
|
||||
|
||||
User -> UI : Add RTSP camera (form)
|
||||
UI -> API : POST /cameras
|
||||
note right of UI
|
||||
body has nested credentials,
|
||||
capturing, image_size —
|
||||
no stringified JSON
|
||||
end note
|
||||
API -> LEG : legacy add
|
||||
LEG --> API : id=123
|
||||
API --> UI : 201 Location: /cameras/123
|
||||
|
||||
User -> UI : Configure AI task
|
||||
UI -> API : POST /ai-tasks\n{camera_id:123, ...}
|
||||
API -> LEG : legacy create
|
||||
LEG --> API : id=456
|
||||
API --> UI : 201 {id:456}
|
||||
|
||||
User -> UI : Start task
|
||||
UI -> API : POST /ai-tasks/456/start
|
||||
API -> LEG : dispatch
|
||||
LEG -> EDGE : config + start
|
||||
EDGE --> LEG : running
|
||||
API --> UI : 202 {state:starting}
|
||||
|
||||
loop status poll (or SSE later)
|
||||
UI -> API : GET /ai-tasks/456/status
|
||||
API --> UI : 200 {state:running, fps:14.2}
|
||||
end
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,36 @@
|
||||
@startuml 06-seq-live-events
|
||||
title Sequence — Live event tail + clicking into evidence
|
||||
|
||||
actor "Operator" as User
|
||||
participant "Qt UI" as UI
|
||||
participant "ANSVIS\n/api/v1" as API
|
||||
participant "SSE broadcaster" as SSE
|
||||
participant "Clip store\n(S3 / MinIO / FS)" as CLIPS
|
||||
participant "L1 edge" as EDGE
|
||||
|
||||
User -> UI : Open Eventview (task=456)
|
||||
UI -> API : GET /events?task_id=456&page=1
|
||||
API --> UI : 200 historical events
|
||||
UI -> API : GET /events/stream?task_id=456
|
||||
API --> UI : text/event-stream (open)
|
||||
|
||||
EDGE -> API : event arrives (via L1↔L2)
|
||||
API -> SSE : push EventRecord
|
||||
SSE --> UI : data: {id:E1, ts, object:car, bbox, ...}
|
||||
|
||||
User -> UI : Click event E1
|
||||
UI -> API : GET /events/E1
|
||||
API --> UI : 200 EventRecord (full)
|
||||
UI -> API : GET /events/E1/image?width=640
|
||||
API --> UI : image/jpeg bytes
|
||||
|
||||
User -> UI : Play clip
|
||||
UI -> API : GET /events/E1/clip
|
||||
API -> CLIPS : presign GET
|
||||
CLIPS --> API : presigned URL
|
||||
API --> UI : 200 {url, expires_at}
|
||||
UI -> CLIPS : GET <presigned URL>
|
||||
CLIPS --> UI : MP4 bytes
|
||||
UI -> UI : play in QtMultimedia
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,30 @@
|
||||
@startuml 07-seq-liveview
|
||||
title Sequence — Liveview with bbox overlay
|
||||
|
||||
actor "Operator" as User
|
||||
participant "Qt UI" as UI
|
||||
participant "ANSVIS\n/api/v1" as API
|
||||
participant "Media relay" as RELAY
|
||||
participant "L1 edge" as EDGE
|
||||
participant "SSE broadcaster" as SSE
|
||||
|
||||
User -> UI : Open Liveview (cam 123, task 456)
|
||||
UI -> API : GET /cameras/123/liveview?transport=hls
|
||||
API -> RELAY : ensure HLS for cam 123
|
||||
RELAY -> EDGE : pull RTSP
|
||||
RELAY --> API : hls_url + short-lived token
|
||||
API --> UI : 200 {url, transport:hls,\nauth_token, expires_at}
|
||||
|
||||
UI -> RELAY : GET hls_url (token)
|
||||
RELAY --> UI : m3u8 + segments
|
||||
UI -> UI : Render video\n(QtMultimedia)
|
||||
|
||||
UI -> API : GET /events/stream?task_id=456 (SSE)
|
||||
API --> UI : text/event-stream
|
||||
|
||||
loop per event
|
||||
SSE --> UI : bbox + ts
|
||||
UI -> UI : overlay synced to PTS
|
||||
end
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,27 @@
|
||||
@startuml 08-seq-async-scan
|
||||
title Sequence — Async camera network scan (job pattern)
|
||||
|
||||
actor "Operator" as User
|
||||
participant "Qt UI" as UI
|
||||
participant "ANSVIS\n/api/v1" as API
|
||||
participant "Job queue" as JOBS
|
||||
participant "ONVIF scanner" as SCAN
|
||||
|
||||
User -> UI : Scan 192.168.1.0/24
|
||||
UI -> API : POST /cameras/scan
|
||||
API -> JOBS : enqueue
|
||||
JOBS --> API : job_id=j1
|
||||
API --> UI : 202 {job_id:j1,\n status:queued,\n links:{self:/jobs/j1}}
|
||||
|
||||
JOBS -> SCAN : run
|
||||
|
||||
loop poll until terminal
|
||||
UI -> API : GET /jobs/j1
|
||||
API --> UI : 200 {status:running, progress:0.4}
|
||||
end
|
||||
|
||||
SCAN --> JOBS : results
|
||||
UI -> API : GET /jobs/j1
|
||||
API --> UI : 200 {status:succeeded,\n result:{discovered:[...]}}
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,23 @@
|
||||
@startuml 09-seq-large-upload
|
||||
title Sequence — Large model upload (initiate / complete pattern)
|
||||
|
||||
actor "Operator" as User
|
||||
participant "Qt UI" as UI
|
||||
participant "ANSVIS\n/api/v1" as API
|
||||
participant "Object store\n(S3 / MinIO / FS)" as OBJ
|
||||
|
||||
User -> UI : Pick model.zip (500 MB)
|
||||
UI -> API : POST /models:initiate-upload\n{filename, size_bytes, checksum}
|
||||
API -> OBJ : presign PUT
|
||||
OBJ --> API : presigned_url
|
||||
API --> UI : 200 {upload_id, presigned_url, expires_at}
|
||||
|
||||
UI -> OBJ : PUT <presigned_url>\n(binary stream, with progress)
|
||||
OBJ --> UI : 200 OK
|
||||
|
||||
UI -> API : POST /models:complete-upload\n{upload_id, metadata}
|
||||
API -> OBJ : verify checksum
|
||||
OBJ --> API : ok
|
||||
API --> UI : 201 Model
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,51 @@
|
||||
@startuml 10-deployment-topology
|
||||
title Deployment Topology
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
|
||||
node "Customer site / cloud" {
|
||||
|
||||
node "Operator workstations" {
|
||||
component "Windows desktop\nQt UI" as D1
|
||||
component "macOS desktop\nQt UI" as D2
|
||||
component "Linux desktop\nQt UI" as D3
|
||||
}
|
||||
|
||||
node "ANSVIS server host" {
|
||||
component "Reverse proxy\nTLS terminator\n(nginx / caddy)" as NGINX
|
||||
component "ANSVIS app\n(adapter + legacy core)" as APP
|
||||
component "Media relay" as RELAY
|
||||
database "Object store\n(S3 / MinIO / FS)" as OBJ
|
||||
database "Config + Event DBs" as DB
|
||||
}
|
||||
|
||||
node "Edge targets" {
|
||||
node "Linux x86 + NVIDIA" as E1
|
||||
node "Windows x86 + NVIDIA" as E2
|
||||
node "Jetson Orin" as E3
|
||||
}
|
||||
}
|
||||
|
||||
D1 --> NGINX : TLS 443\nREST + SSE + HLS
|
||||
D2 --> NGINX : TLS 443
|
||||
D3 --> NGINX : TLS 443
|
||||
NGINX --> APP
|
||||
NGINX --> RELAY
|
||||
APP --> DB
|
||||
APP --> OBJ
|
||||
RELAY <--> E1
|
||||
RELAY <--> E2
|
||||
RELAY <--> E3
|
||||
APP <--> E1
|
||||
APP <--> E2
|
||||
APP <--> E3
|
||||
|
||||
note bottom
|
||||
Network rules for the customer:
|
||||
- Outbound TCP 443 from each workstation → ANSVIS host
|
||||
- Inbound TCP 443 on ANSVIS host
|
||||
- L2 ↔ L1 protocol per edge (port + tunnel TBD)
|
||||
- Workstations never reach edges directly — Media relay proxies
|
||||
end note
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,71 @@
|
||||
@startuml 11-l3-engineer-ownership
|
||||
title Layer 3 — Engineer ownership (6 engineers)
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
skinparam packageStyle rectangle
|
||||
|
||||
package "E1 — UI Lead / Shell Architect" as E1 #LightYellow {
|
||||
component "Qt 6 + CMake monorepo" as E1A
|
||||
component "Generated REST client\nfrom openapi.v1.json" as E1B
|
||||
component "Auth state + token store" as E1C
|
||||
component "Design system / theme" as E1D
|
||||
component "Navigation router" as E1E
|
||||
component "Packaging Win/Mac/Linux\nsigning, notarize,\nauto-update" as E1F
|
||||
component "CI matrix" as E1G
|
||||
}
|
||||
|
||||
package "E2 — Pipeline Editor Specialist" as E2 #LightBlue {
|
||||
component "Visual DAG editor\n(QGraphicsView in QQuickWidget)" as E2A
|
||||
component "Node library +\nconnection validation" as E2B
|
||||
component "Schema-driven param panels" as E2C
|
||||
component "Undo / redo,\nsave / version" as E2D
|
||||
}
|
||||
|
||||
package "E3 — Liveview / Media" as E3 #LightGreen {
|
||||
component "QtMultimedia HLS player\n(v1)" as E3A
|
||||
component "Multi-stream grid" as E3B
|
||||
component "Bbox overlay\n(QQuickItem + QSGGeometryNode)" as E3C
|
||||
component "Clip player (evidence)" as E3D
|
||||
component "WebRTC via GStreamer\n(v2)" as E3E
|
||||
}
|
||||
|
||||
package "E4 — Config Forms" as E4 #LightPink {
|
||||
component "Schema-driven QML forms\n(from openapi.v1.json)" as E4A
|
||||
component "Camera + ONVIF discovery flow" as E4B
|
||||
component "Camera calibration UI\n(ROI / zones / homography)" as E4C
|
||||
component "Model + plugin +\ntrigger forms" as E4D
|
||||
}
|
||||
|
||||
package "E5 — Dashboard / Eventview" as E5 #LightCoral {
|
||||
component "Target dashboard\ncards + charts" as E5A
|
||||
component "Event timeline\n(virtualized)" as E5B
|
||||
component "SSE subscriber + LiveBuffer" as E5C
|
||||
component "Filter / search /\nevidence viewer" as E5D
|
||||
component "Multi-target monitoring" as E5E
|
||||
}
|
||||
|
||||
package "E6 — UX / Cross-platform QA" as E6 #Lavender {
|
||||
component "Design polish,\na11y, i18n" as E6A
|
||||
component "Install / upgrade testing\nWin + Mac + Linux" as E6B
|
||||
component "Crash reporting\n(Sentry / Crashpad)" as E6C
|
||||
component "QML Profiler perf passes" as E6D
|
||||
component "User docs surface" as E6E
|
||||
}
|
||||
|
||||
artifact "openapi.v1.json\n(frozen contract)" as CONTRACT
|
||||
|
||||
E1 ..> CONTRACT
|
||||
E2 ..> CONTRACT
|
||||
E3 ..> CONTRACT
|
||||
E4 ..> CONTRACT
|
||||
E5 ..> CONTRACT
|
||||
|
||||
note bottom of E1
|
||||
Week 1–2: E1 alone delivers the shell that unblocks E2–E6.
|
||||
end note
|
||||
|
||||
note bottom of E2
|
||||
Week 1–2 spike in parallel — de-risks the hardest UI feature.
|
||||
end note
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,43 @@
|
||||
@startuml 12-dependency-chain
|
||||
title Dependency chain — what gates what
|
||||
|
||||
skinparam componentStyle rectangle
|
||||
|
||||
artifact "openapi.v1.json\n(frozen)" as CONTRACT
|
||||
component "Prism mock server" as MOCK
|
||||
component "ANSVIS /api/v1 adapter\n(core team, per-resource)" as ADAPT
|
||||
component "Legacy ANSVIS" as LEGACY
|
||||
component "L3 shell + REST client\n(E1)" as UI_SHELL
|
||||
component "L3 screens\n(E2 – E6)" as UI_FEAT
|
||||
component "Real backend integration" as REAL
|
||||
component "Ship v1" as SHIP
|
||||
|
||||
CONTRACT --> MOCK
|
||||
CONTRACT --> ADAPT
|
||||
ADAPT --> LEGACY
|
||||
MOCK --> UI_SHELL
|
||||
UI_SHELL --> UI_FEAT
|
||||
UI_FEAT --> REAL
|
||||
ADAPT --> REAL
|
||||
REAL --> SHIP
|
||||
|
||||
note bottom of CONTRACT
|
||||
Only artifact that BOTH sides block on.
|
||||
Frozen once published; additive changes only.
|
||||
end note
|
||||
|
||||
note bottom of MOCK
|
||||
UI develops here from day 1.
|
||||
end note
|
||||
|
||||
note bottom of ADAPT
|
||||
Built in parallel by the core team.
|
||||
Per-resource modularity = independent progress.
|
||||
end note
|
||||
|
||||
note bottom of REAL
|
||||
Joining point. UI tests run against both mock and real
|
||||
to detect drift.
|
||||
end note
|
||||
|
||||
@enduml
|
||||
@@ -0,0 +1,19 @@
|
||||
# ANSCORE — L2 & L3 diagrams (preview)
|
||||
|
||||
Click each PNG link to view the rendered diagram in your browser.
|
||||
SVG links are higher-quality (vector). Both come from plantuml.com.
|
||||
|
||||
| # | Diagram | What it shows | PNG | SVG |
|
||||
|---|---|---|---|---|
|
||||
| 01 | **system context** | L1 / L2 / L3 with the 3 transports (REST / SSE / HLS-RTSP-WebRTC). | [PNG](https://www.plantuml.com/plantuml/png/RLJRRjf047ttLupo51HH2dchgYe6h43bD8alYIhnihO7ic6zw-wkQL1LgH_HB-oNT7ODWf2y6E_ud3ENiyELiKpRjXRmSTWtMsEnxfTAMdonWULM88JVqibj4i6_FtyXzG2OT00uZuSmW7Za7fUz831hBXkcMGsbgXibKThKRab3OscPN0ayWZIiNBCLdWA2NHpEOhP53PS-yRqTtD_4C4Mpjgg1VBwGvuzSLkgdeUGrAszJLmINxKll39YXUk1N08Swu6mdmPf6y99PhgG7vlFWzvka8v-KEd-Ofp2vIJl9qQdaW3Lyi1akP1Ab6PXMBrc97XlUpH-6hy4nhbYvtOkMIYFreB4rM16ZpyskyEWwd7n_JRt1YZEQaM3RXPp5hjKaI-_evn6B99juOXB5uGalJIF03RqkPA4Lgqf6zccFfa-pV4pmYbbMC4EjHmu9q_52Na0fU0EgU2PRm5YgjIDbT168ywF5bWYXsSeIdbNH1Jpaw-quVLr4sDedk81a77PrXdasUsVam_t8_MMBAlgIjDBoses9fA0X4DtL5ThTe8QdTanOZPfHhhbSeaPPecibqtorGcqyAPfUHovvFeT-_qjd4to2ys4Fl8S3c6NPNRgGRWUq4YGsIVBf7jzDpH56FNSuu0NVO3ThAfABFS6Rul2NFNZ7k1rlmojKGT1Lu-joCpeSTtVY4F1JFXmxNphKKS0_Z-eEkce-kuWVn8vn20HIMOH2MQjgK4lQ8femhPAIOajzYRK1gzmYEAyajQkXucvttMS5IAwP3m7A2fpGMxaHoOL2W7tIYBHwO3MJfb7Q6c2Qe5gjoRaA2j9xmiuJwlCJyTmvJs9on198mb9fyDEh_NOmIkeWpfKb5tJF7O9utfHENXNaZIJv3H6yTic4C8JNnXxNVKMlz9yO_0S0) | [SVG](https://www.plantuml.com/plantuml/svg/RLJRRjf047ttLupo51HH2dchgYe6h43bD8alYIhnihO7ic6zw-wkQL1LgH_HB-oNT7ODWf2y6E_ud3ENiyELiKpRjXRmSTWtMsEnxfTAMdonWULM88JVqibj4i6_FtyXzG2OT00uZuSmW7Za7fUz831hBXkcMGsbgXibKThKRab3OscPN0ayWZIiNBCLdWA2NHpEOhP53PS-yRqTtD_4C4Mpjgg1VBwGvuzSLkgdeUGrAszJLmINxKll39YXUk1N08Swu6mdmPf6y99PhgG7vlFWzvka8v-KEd-Ofp2vIJl9qQdaW3Lyi1akP1Ab6PXMBrc97XlUpH-6hy4nhbYvtOkMIYFreB4rM16ZpyskyEWwd7n_JRt1YZEQaM3RXPp5hjKaI-_evn6B99juOXB5uGalJIF03RqkPA4Lgqf6zccFfa-pV4pmYbbMC4EjHmu9q_52Na0fU0EgU2PRm5YgjIDbT168ywF5bWYXsSeIdbNH1Jpaw-quVLr4sDedk81a77PrXdasUsVam_t8_MMBAlgIjDBoses9fA0X4DtL5ThTe8QdTanOZPfHhhbSeaPPecibqtorGcqyAPfUHovvFeT-_qjd4to2ys4Fl8S3c6NPNRgGRWUq4YGsIVBf7jzDpH56FNSuu0NVO3ThAfABFS6Rul2NFNZ7k1rlmojKGT1Lu-joCpeSTtVY4F1JFXmxNphKKS0_Z-eEkce-kuWVn8vn20HIMOH2MQjgK4lQ8femhPAIOajzYRK1gzmYEAyajQkXucvttMS5IAwP3m7A2fpGMxaHoOL2W7tIYBHwO3MJfb7Q6c2Qe5gjoRaA2j9xmiuJwlCJyTmvJs9on198mb9fyDEh_NOmIkeWpfKb5tJF7O9utfHENXNaZIJv3H6yTic4C8JNnXxNVKMlz9yO_0S0) |
|
||||
| 02 | **l2 internals** | L2 adapter modules in front of legacy ANSVIS + infrastructure. | [PNG](https://www.plantuml.com/plantuml/png/TLPVRzis47_NfpZagSFcfaaVEWp3KDcM7NLoR4jAkW0535ewosmaIYEf34PHO1zYdt2VP4TIScmPUp6fkzyTx-yl-QWqaxgjIdXtEoflHrneb8ALojDSbmWHEw24M_Ztxt_0lqyUmmHw232PxRd6JBSIFKyzSz4moIh8wggf1GgTw0Eva8HWeYZn1DAmx9aLE0HuBDErXAkrXcjOBo9u2A-0ALYdlUQzp4VaGX--21D78PdcjL0M5VoHUbxd6QwYMxXc3Rz-kG7LoXtBq86cys3ZhqBuvi5hf70L1qaAicufDukBbmzf49zZ_5RleU9vNk9VJE8NyMQCTCeVh8N_aDujFW-yufyjAWqlhEIv3PMCbWqA4u7AzbWnvQmV_IYSdXi7KbBA5MiQb6GMpoRmuUTt7nm-Y0V1nKmZbBpYnmpyD3Y794a0MrcpF6DAMv_aUQJQhSeaRqnqiEEbxXCY-Dt3sFj-KbGgff-pXY1kCZeN4bNToWoXglEsn2ubV-glg8R3IcUiGibSooR-OkCFqYOVM3hrOZczK6DUe3ffvK2TOrFMXuhkeuBQsJZeT7u1P7oacNfs-jHFVhzywOMExgd72-tELNaMNtek6wVpezMbLjIQxtXsChVtopISNU3KWNfKkKOy9HVgh_NMMNzQZetoj4iH5YmxzFkgKBxOJabi5UPaC-9TXw9Wxa-UXWsQr6B72r2qSDZ3DfFPVB0C8PZw0Og2YrUSgMHoZfp5Gz1ik5XKg276oCwo2iMEnaRBrXAEnONtizWVXc-tz4VGzJEAaoJCUcwInmc1QITRSlYfthehrKPbJAYVeANXOJbTt1XP2UrjFz5KwsIp9WyaOrkco4bWXWGgrCp8O3hkvYMuJvFDT7o6dPIy8MBZbScdtdubtdC1KW39Uz8ik0YNTCuIzzua2bU3OaPreIWxUb3opDpso4gzTsLRpWVe1UQS4S6MZ0ZpBah8TvmcApe-upPE9uueWiX_CgNkE3Qw0RDar5vPe7xJvHxSUDuwXT7ejvuRYMzFFzrX9HqLkiDA7BtPNsTZoCdyEBnZ2gzd32Cp1DT_lttRlmA_K3QAqbFqr-B4_x6xdgCKA-pdrj78_ubSaJioEGDPrZXAt6HtJ36GMdvmOHyx_ofpBrYcEDhH2dJqS1JPYNUxxcIcdMwzxNStVLs2fYPEGZKnuqjDRMIznJwtCq1fUjcDj-ST0xy8kRjPUSV_xZZjjDVnng_M-iQp0tJyyZwYoEa_2ky_) | [SVG](https://www.plantuml.com/plantuml/svg/TLPVRzis47_NfpZagSFcfaaVEWp3KDcM7NLoR4jAkW0535ewosmaIYEf34PHO1zYdt2VP4TIScmPUp6fkzyTx-yl-QWqaxgjIdXtEoflHrneb8ALojDSbmWHEw24M_Ztxt_0lqyUmmHw232PxRd6JBSIFKyzSz4moIh8wggf1GgTw0Eva8HWeYZn1DAmx9aLE0HuBDErXAkrXcjOBo9u2A-0ALYdlUQzp4VaGX--21D78PdcjL0M5VoHUbxd6QwYMxXc3Rz-kG7LoXtBq86cys3ZhqBuvi5hf70L1qaAicufDukBbmzf49zZ_5RleU9vNk9VJE8NyMQCTCeVh8N_aDujFW-yufyjAWqlhEIv3PMCbWqA4u7AzbWnvQmV_IYSdXi7KbBA5MiQb6GMpoRmuUTt7nm-Y0V1nKmZbBpYnmpyD3Y794a0MrcpF6DAMv_aUQJQhSeaRqnqiEEbxXCY-Dt3sFj-KbGgff-pXY1kCZeN4bNToWoXglEsn2ubV-glg8R3IcUiGibSooR-OkCFqYOVM3hrOZczK6DUe3ffvK2TOrFMXuhkeuBQsJZeT7u1P7oacNfs-jHFVhzywOMExgd72-tELNaMNtek6wVpezMbLjIQxtXsChVtopISNU3KWNfKkKOy9HVgh_NMMNzQZetoj4iH5YmxzFkgKBxOJabi5UPaC-9TXw9Wxa-UXWsQr6B72r2qSDZ3DfFPVB0C8PZw0Og2YrUSgMHoZfp5Gz1ik5XKg276oCwo2iMEnaRBrXAEnONtizWVXc-tz4VGzJEAaoJCUcwInmc1QITRSlYfthehrKPbJAYVeANXOJbTt1XP2UrjFz5KwsIp9WyaOrkco4bWXWGgrCp8O3hkvYMuJvFDT7o6dPIy8MBZbScdtdubtdC1KW39Uz8ik0YNTCuIzzua2bU3OaPreIWxUb3opDpso4gzTsLRpWVe1UQS4S6MZ0ZpBah8TvmcApe-upPE9uueWiX_CgNkE3Qw0RDar5vPe7xJvHxSUDuwXT7ejvuRYMzFFzrX9HqLkiDA7BtPNsTZoCdyEBnZ2gzd32Cp1DT_lttRlmA_K3QAqbFqr-B4_x6xdgCKA-pdrj78_ubSaJioEGDPrZXAt6HtJ36GMdvmOHyx_ofpBrYcEDhH2dJqS1JPYNUxxcIcdMwzxNStVLs2fYPEGZKnuqjDRMIznJwtCq1fUjcDj-ST0xy8kRjPUSV_xZZjjDVnng_M-iQp0tJyyZwYoEa_2ky_) |
|
||||
| 03 | **l2 ownership** | Human-owned vs AI-coder-built vs reused legacy modules in L2. | [PNG](https://www.plantuml.com/plantuml/png/PLNRRXCn47tVhnYL5r2xj0tG5XvGjo5f8qAfkWM15AborfEDYTTUR6_32Y7nn1Vq2_aIPYzfO_CKQtNE-FZCcScfTSougf1my2AMWrYl5Hgx56NaX9C8KrQZWG7y_NqFPvMG71uHaLq9LJB32iXqKMg5ogMk9fR1p36LIzo2b2nRiHn3GDH_XvsBgc2g5S1dwYapsL8uWZtR0MRXujE7v1AUJ4M-T5zHIhs6dn4ytWixrwFq1eok79gPsWLMkIKKWdE9QsQmAt8OKCP3E3uvE9xHYumsKB2oHDD11pxqOuagkPh07PE2CoUqcgbIb2Y5wck_y0b9S_-2T3PYd5wX0klqHiZBGCXPCcnm5hFA25UJFtS2rntsbO-TKZF-tCFq45ob5CgM9t8bLDxXZw9VMwucapZJ74qyf-uvChRGl9BC0EEi9AzivsyowSqzanM6rcQiG4EWdj8H0Y-fBCe7I2EgAgLc73oNai1Mv3a6TGCVELAPkg1pd5DtIpjJ7ZnmaedOCRiAQWOMuXtzU5hJT0HpGt8pPXzOHpvhOVoYny7DiWm09pv0QISM8cl34-XxxIDjJI8As8SbCaansfyfgVFG_mEVz4tFuNk5rBrTM6kpejRsmB1Jo0MZX4bMzu21bvZH3s4TfGcIo_Jp9AN86AmiSiB6ee_BwCk4fgrBpBbXTPYO6-e1eCetVP_UtYJf-zG7ZQzzoFWw6A7fLO1ellYOeLOBaM-DrlHsE3vltjDjZ3X-IzcEADxDgPKTHTG9XBbsJXUW5zrkeRBlQ2CXPSp2N50yt1A1tcrWXLXQg1HD4N3HhAv-FjyGoI2PRjtMOjY3TflOlNO7xK5cjBLnLhdMrCs8FuzGSMYK_AU7z09SaBMoXisqpfkTO7LbCcntCJse7MiB6LDjlq4eQ3Qjb2Y9hnLzeE6XMngZDjCEQ-6Mj2I9BKamATeMSaf7-Y-8_W40) | [SVG](https://www.plantuml.com/plantuml/svg/PLNRRXCn47tVhnYL5r2xj0tG5XvGjo5f8qAfkWM15AborfEDYTTUR6_32Y7nn1Vq2_aIPYzfO_CKQtNE-FZCcScfTSougf1my2AMWrYl5Hgx56NaX9C8KrQZWG7y_NqFPvMG71uHaLq9LJB32iXqKMg5ogMk9fR1p36LIzo2b2nRiHn3GDH_XvsBgc2g5S1dwYapsL8uWZtR0MRXujE7v1AUJ4M-T5zHIhs6dn4ytWixrwFq1eok79gPsWLMkIKKWdE9QsQmAt8OKCP3E3uvE9xHYumsKB2oHDD11pxqOuagkPh07PE2CoUqcgbIb2Y5wck_y0b9S_-2T3PYd5wX0klqHiZBGCXPCcnm5hFA25UJFtS2rntsbO-TKZF-tCFq45ob5CgM9t8bLDxXZw9VMwucapZJ74qyf-uvChRGl9BC0EEi9AzivsyowSqzanM6rcQiG4EWdj8H0Y-fBCe7I2EgAgLc73oNai1Mv3a6TGCVELAPkg1pd5DtIpjJ7ZnmaedOCRiAQWOMuXtzU5hJT0HpGt8pPXzOHpvhOVoYny7DiWm09pv0QISM8cl34-XxxIDjJI8As8SbCaansfyfgVFG_mEVz4tFuNk5rBrTM6kpejRsmB1Jo0MZX4bMzu21bvZH3s4TfGcIo_Jp9AN86AmiSiB6ee_BwCk4fgrBpBbXTPYO6-e1eCetVP_UtYJf-zG7ZQzzoFWw6A7fLO1ellYOeLOBaM-DrlHsE3vltjDjZ3X-IzcEADxDgPKTHTG9XBbsJXUW5zrkeRBlQ2CXPSp2N50yt1A1tcrWXLXQg1HD4N3HhAv-FjyGoI2PRjtMOjY3TflOlNO7xK5cjBLnLhdMrCs8FuzGSMYK_AU7z09SaBMoXisqpfkTO7LbCcntCJse7MiB6LDjlq4eQ3Qjb2Y9hnLzeE6XMngZDjCEQ-6Mj2I9BKamATeMSaf7-Y-8_W40) |
|
||||
| 04 | **l3 internals** | Qt/QML layers: app shell, network, domain state, screens. | [PNG](https://www.plantuml.com/plantuml/png/RPRTQkD65CVlzHI7NAM4n0rRoXBAieebEsBbBqasB0J2M3gHPosDr9cHiwOKUjK7A7t2VPAU6IcXzYGtiSU_cVFrdx_qMMacTLTNyFClrzM7QouqIi4gvMckAuIO7L721_Znrx-mql0hZ60rY-4L0oRp7TUOwqwYvwaz5osJh8QygTj6eD2fFj8naWWcoWh_XxGitxCIpm5lM8SB6-_AnZFXXrGkW2bOPV27vm6yiNxRGhh3gh8_fmzX71C1zFUM2LpC61VmmaNHl5XivaVpSsRE3hnacZS2PDDHbPPC5kiiF4S3LBmKe8vAOqsDqJkiqUBPGpXpS7xxKS3bxogJnCPSb1rN-YVBHxSVdKJyJk-0fgEHUg2RFL8atSW-WB_E7fxIx7nFA6KZ2MPAKuo2iwefBHycoTCw8lpFawxDKRyqSW-LQQq5vs7czcsA0YKbKa0IfXda5QVbHt7Pj2XOosyEjpVV53Ninz__mFZgQhGQoZBq-Lbf6eBgjYgNV8kI3baDIIJOLaV8TvtOOz7l9_Pf73jJH2hiBOcLddMLvhLT7C4qrH9PFLGp2uF8Fzz_lss-GtD0ILMJxaI1qYQITzJV6bQhZkVxY4RQ9x7OX4diVtMoC559o9gcqqgh12mUHTTM3Ik6yEjblF03f-j1KniXzhEzN2sstqZyT8mvWsxUK7lcPw4xYh6fZQbPK-0WzUnfxC-SxCplfzHi4JXoAKeyXS9W-exCgQPZJP-dT2FQqmt1rD5jb36rFwKoF_tY13_GlnwZscD-mFlk-Nded4bbSxvZaYnHaivEpvuaJWRnCbbMrDnJq2oVemdclELlYRoYyqKMJHpbsdl-WApIknCw_PewCqvpYIWKZNSM3mCT9s4uJzsHnat9XKNYnTGrf82ftRPXie3Heo2pBb4hAzy3nzx60ZzzU5ydK3D1wTJsfbp1Ohw99cGBAZVxZsOfPnNVIkjtzYpIqbDwVjYIjrXnWK2NZ2o8xig1guxSF_2dVN71bAGJEPVTZy28WPR4C--To4ZXNJRfAbJ6HIKlIvfpxo3hE7JpCM8nrKCfUT5tBjeukhK2ivYn1vD_RuKRzy190cqlBPBYCyknZpv9NDIe25ghhjw9wRjBzRAMM9B5osFlHOiWZ5rohIWmbSsAUb31EWqJ1qjHQtfaz37JCCkY-RHN7UcEvJGLIcsURg8KHcJ9eyEj9U_zyPTm7dZUg_gkhpyDrd97wR72XAuxuqJAwzSDOPu2TqORz1vWFlzc5b_F6WmHRcu-zGPBg3gAd9uxiCnIRtWssT_jy-AENXUCnL4woCXhJuZUurt6-qpEJEybtdy0) | [SVG](https://www.plantuml.com/plantuml/svg/RPRTQkD65CVlzHI7NAM4n0rRoXBAieebEsBbBqasB0J2M3gHPosDr9cHiwOKUjK7A7t2VPAU6IcXzYGtiSU_cVFrdx_qMMacTLTNyFClrzM7QouqIi4gvMckAuIO7L721_Znrx-mql0hZ60rY-4L0oRp7TUOwqwYvwaz5osJh8QygTj6eD2fFj8naWWcoWh_XxGitxCIpm5lM8SB6-_AnZFXXrGkW2bOPV27vm6yiNxRGhh3gh8_fmzX71C1zFUM2LpC61VmmaNHl5XivaVpSsRE3hnacZS2PDDHbPPC5kiiF4S3LBmKe8vAOqsDqJkiqUBPGpXpS7xxKS3bxogJnCPSb1rN-YVBHxSVdKJyJk-0fgEHUg2RFL8atSW-WB_E7fxIx7nFA6KZ2MPAKuo2iwefBHycoTCw8lpFawxDKRyqSW-LQQq5vs7czcsA0YKbKa0IfXda5QVbHt7Pj2XOosyEjpVV53Ninz__mFZgQhGQoZBq-Lbf6eBgjYgNV8kI3baDIIJOLaV8TvtOOz7l9_Pf73jJH2hiBOcLddMLvhLT7C4qrH9PFLGp2uF8Fzz_lss-GtD0ILMJxaI1qYQITzJV6bQhZkVxY4RQ9x7OX4diVtMoC559o9gcqqgh12mUHTTM3Ik6yEjblF03f-j1KniXzhEzN2sstqZyT8mvWsxUK7lcPw4xYh6fZQbPK-0WzUnfxC-SxCplfzHi4JXoAKeyXS9W-exCgQPZJP-dT2FQqmt1rD5jb36rFwKoF_tY13_GlnwZscD-mFlk-Nded4bbSxvZaYnHaivEpvuaJWRnCbbMrDnJq2oVemdclELlYRoYyqKMJHpbsdl-WApIknCw_PewCqvpYIWKZNSM3mCT9s4uJzsHnat9XKNYnTGrf82ftRPXie3Heo2pBb4hAzy3nzx60ZzzU5ydK3D1wTJsfbp1Ohw99cGBAZVxZsOfPnNVIkjtzYpIqbDwVjYIjrXnWK2NZ2o8xig1guxSF_2dVN71bAGJEPVTZy28WPR4C--To4ZXNJRfAbJ6HIKlIvfpxo3hE7JpCM8nrKCfUT5tBjeukhK2ivYn1vD_RuKRzy190cqlBPBYCyknZpv9NDIe25ghhjw9wRjBzRAMM9B5osFlHOiWZ5rohIWmbSsAUb31EWqJ1qjHQtfaz37JCCkY-RHN7UcEvJGLIcsURg8KHcJ9eyEj9U_zyPTm7dZUg_gkhpyDrd97wR72XAuxuqJAwzSDOPu2TqORz1vWFlzc5b_F6WmHRcu-zGPBg3gAd9uxiCnIRtWssT_jy-AENXUCnL4woCXhJuZUurt6-qpEJEybtdy0) |
|
||||
| 05 | **seq configure deploy** | Operator workflow: add camera → AI task → deploy → start. | [PNG](https://www.plantuml.com/plantuml/png/XLJHRjem57ttLrpnr6e98QpT0rAxeWuX9bHOq-wfKkN59bWpTchVJA88QH-nBzoNz3efJ0IalUJ1vvnxp_6zper7xh1QQUXTnbw-nBar2rLKJiP2bjgk6IhK4ZBvKacJI_Zx-m_CIkauMWTxieUSh-WGFi1m0iZzJ-16G5F2CyRpGE_iX1tW7XwzTAoaxYfN9JS8dMy8ZvC6cnmYmxli-oHxCWalLV8hhJd3-KaIcNAo9an7uqF2D0KfYWOSVHcF60iU8BwcVZ08iGpSrZay-Dn9QHW115ChmiUZ1qYQdFvpoGjvbRA0485Q4K7BWkThqCeZ2oVnNlgkQkYxVlrU3pOAvSf74Cf5W1QvthPi3OM0-uTilhlYiuLrg_C3P_DPziyQCnObE5Ki4UmYN2N03olMiAHOHdgK0YYSa0OLrpuYEESbLawP8WAr8YVFNhtMeoRCMF0OCBLGfFoQpUwOfDc6BYVZSo5QwPMuIliVs-5JcDgSex9ciFUU1DvX_DlTZkqswqHohkA0-2UpQGezAp6WKX5qkztjIPTq0vm271czkFnqR7H3vGXeJoOBR-T_dX8I9lKhE_GXb2yvvil6mdMza65JwhZqZXf9VHhlHQuoXaRHTjY73T5H3ceH4SYfjhOCHR3oK5gjuOnUO9QDG1FHdTDaZtQxRPcaH3lUsQRNkvS85gKVf1VT_ZRi1MCtzAKV2di3) | [SVG](https://www.plantuml.com/plantuml/svg/XLJHRjem57ttLrpnr6e98QpT0rAxeWuX9bHOq-wfKkN59bWpTchVJA88QH-nBzoNz3efJ0IalUJ1vvnxp_6zper7xh1QQUXTnbw-nBar2rLKJiP2bjgk6IhK4ZBvKacJI_Zx-m_CIkauMWTxieUSh-WGFi1m0iZzJ-16G5F2CyRpGE_iX1tW7XwzTAoaxYfN9JS8dMy8ZvC6cnmYmxli-oHxCWalLV8hhJd3-KaIcNAo9an7uqF2D0KfYWOSVHcF60iU8BwcVZ08iGpSrZay-Dn9QHW115ChmiUZ1qYQdFvpoGjvbRA0485Q4K7BWkThqCeZ2oVnNlgkQkYxVlrU3pOAvSf74Cf5W1QvthPi3OM0-uTilhlYiuLrg_C3P_DPziyQCnObE5Ki4UmYN2N03olMiAHOHdgK0YYSa0OLrpuYEESbLawP8WAr8YVFNhtMeoRCMF0OCBLGfFoQpUwOfDc6BYVZSo5QwPMuIliVs-5JcDgSex9ciFUU1DvX_DlTZkqswqHohkA0-2UpQGezAp6WKX5qkztjIPTq0vm271czkFnqR7H3vGXeJoOBR-T_dX8I9lKhE_GXb2yvvil6mdMza65JwhZqZXf9VHhlHQuoXaRHTjY73T5H3ceH4SYfjhOCHR3oK5gjuOnUO9QDG1FHdTDaZtQxRPcaH3lUsQRNkvS85gKVf1VT_ZRi1MCtzAKV2di3) |
|
||||
| 06 | **seq live events** | Eventview: SSE event tail + click into evidence (image + clip). | [PNG](https://www.plantuml.com/plantuml/png/VLJ1Rjf04BtlLumuLA1YZ5FA0HMIYBeHacb8N7gA52ts52PPR6TtJOYYI3tr2_A5-PBksawAQUd9gtblthnvk_A9qbpgV2sWstSKtZc2DkZW1XEjc2Oj44Ayop6945v-FaDWO2XWq9m4l8T8K7HBoH8eqQc1ABPandYaKmcDymmbDwS6S0LpXP9bPY15b76ZqRZGC9-KsAIEd7uDlq_2gyJb6RaRh-2SplP8OUZ3GgOyZhZIM0unjJffB2W3PJpWLT8CFu0BKqecv-Rx9MmLBUDWCWlhJO4762-nWFtFPpvZrZmu8sCK1c3MIi2tEMm8xw6fkReTzZxsMyp0XcIS6jQP_mtSCinZoxYcs9BUPNo9GuzPalEgUDJjmegiJOguWEeA3gYvIalawrtHkfh6hIwvJac5PceijnYpo_pHBA-IIsdkLK5pGnm2x-NNSt3KAWL7Daz3p7ArAXU-n2YLCRFbjt4nrtm0ZnGFVAyDMhKXNTnWf0SHbsrOBD9j6pgTpjDUYcFxTYeFldTmMVyVKUrOWUQFN8Y3oPjsbzOcyUDxYlLgsEzrwt85wDvak8J5WqQrPt8c-8DzvTd_1XHu5LZnccna4XKj4qjbPSrvQwymZ65-6VoztMCkHHjmcv7XNNFzLCr-bRRJFzKqHZiZ2fdfh5UjKxOMnSpkGWbSw6akDAqn9ixO2IQn-GMmtm00) | [SVG](https://www.plantuml.com/plantuml/svg/VLJ1Rjf04BtlLumuLA1YZ5FA0HMIYBeHacb8N7gA52ts52PPR6TtJOYYI3tr2_A5-PBksawAQUd9gtblthnvk_A9qbpgV2sWstSKtZc2DkZW1XEjc2Oj44Ayop6945v-FaDWO2XWq9m4l8T8K7HBoH8eqQc1ABPandYaKmcDymmbDwS6S0LpXP9bPY15b76ZqRZGC9-KsAIEd7uDlq_2gyJb6RaRh-2SplP8OUZ3GgOyZhZIM0unjJffB2W3PJpWLT8CFu0BKqecv-Rx9MmLBUDWCWlhJO4762-nWFtFPpvZrZmu8sCK1c3MIi2tEMm8xw6fkReTzZxsMyp0XcIS6jQP_mtSCinZoxYcs9BUPNo9GuzPalEgUDJjmegiJOguWEeA3gYvIalawrtHkfh6hIwvJac5PceijnYpo_pHBA-IIsdkLK5pGnm2x-NNSt3KAWL7Daz3p7ArAXU-n2YLCRFbjt4nrtm0ZnGFVAyDMhKXNTnWf0SHbsrOBD9j6pgTpjDUYcFxTYeFldTmMVyVKUrOWUQFN8Y3oPjsbzOcyUDxYlLgsEzrwt85wDvak8J5WqQrPt8c-8DzvTd_1XHu5LZnccna4XKj4qjbPSrvQwymZ65-6VoztMCkHHjmcv7XNNFzLCr-bRRJFzKqHZiZ2fdfh5UjKxOMnSpkGWbSw6akDAqn9ixO2IQn-GMmtm00) |
|
||||
| 07 | **seq liveview** | Liveview: HLS player + bbox overlay synced to PTS. | [PNG](https://www.plantuml.com/plantuml/png/PLFHQjj047o_hrZyP1CRsKdRb42Q62fIWzCwbbCe6CnPsiP7JYVbRgKub48_8b_OB-dUIMhYzaK8pUpEpExgqf6qLEKQngSZXmyZhMgi5JuAKgGH4doeqAG8ltyzmxp5u57H3hRROWz5ZLRB9o5aIeM5tfSIhUIt7aW7jmwjABc_IbKf3K7lXk1src2pGsJwEVawIzOcagMAwadWJ1V_aAunKn8iic8WBEFvzDiXPJu1pEummF77g_WGJP8OjhQGMIeTOUEIlmdXhSBe0zk2C-0GvYLiFvKvJ8vFXa3ItSERj-y6WcbCPd_ClefN4367Wxk8UL4tmWkoqhYoi7I-qqvuDXS5pro6nbKMuTCyWUyykLP4D33pl7ccbPNMi5mbYmxvgyizDvNLS0HknnfXSnbGSO-cqUhY78_7y8EP7A0pTCR5mxMH5UqseM88k2-LHRUHz5Eq-JghFc6drW_qmIitGIC_gTvx9tYNeo7NDWZG4at6mwrLXiNQz6_ekjAaSh_AWVX_abZx1f4ZYpA_y2FVgEoSfmvztjJWC1hXdfgAKLCWX2wA4lWA8NmMuFVxKX2EzWZO8S0hZ-qPWtlYM_T3XCKg4MnSY4j-ylyX_W00) | [SVG](https://www.plantuml.com/plantuml/svg/PLFHQjj047o_hrZyP1CRsKdRb42Q62fIWzCwbbCe6CnPsiP7JYVbRgKub48_8b_OB-dUIMhYzaK8pUpEpExgqf6qLEKQngSZXmyZhMgi5JuAKgGH4doeqAG8ltyzmxp5u57H3hRROWz5ZLRB9o5aIeM5tfSIhUIt7aW7jmwjABc_IbKf3K7lXk1src2pGsJwEVawIzOcagMAwadWJ1V_aAunKn8iic8WBEFvzDiXPJu1pEummF77g_WGJP8OjhQGMIeTOUEIlmdXhSBe0zk2C-0GvYLiFvKvJ8vFXa3ItSERj-y6WcbCPd_ClefN4367Wxk8UL4tmWkoqhYoi7I-qqvuDXS5pro6nbKMuTCyWUyykLP4D33pl7ccbPNMi5mbYmxvgyizDvNLS0HknnfXSnbGSO-cqUhY78_7y8EP7A0pTCR5mxMH5UqseM88k2-LHRUHz5Eq-JghFc6drW_qmIitGIC_gTvx9tYNeo7NDWZG4at6mwrLXiNQz6_ekjAaSh_AWVX_abZx1f4ZYpA_y2FVgEoSfmvztjJWC1hXdfgAKLCWX2wA4lWA8NmMuFVxKX2EzWZO8S0hZ-qPWtlYM_T3XCKg4MnSY4j-ylyX_W00) |
|
||||
| 08 | **seq async scan** | ONVIF camera scan via async job queue (poll /jobs/{id}). | [PNG](https://www.plantuml.com/plantuml/png/TPBTJjj048Nlvob6kMeb_1UXYbe24Qgs2XS9oC0DL6XP3sZ3PcnsrrHL58c7u0dx98pNuLVYRktlUCuvuzttGRdGBItcEucdkqJvVwmJhnL3CC4ILdJN4Ml2_m-FEEafQhKafv0f_6tSBVPY_B9ehh1L8P3Zhm1AXyRXQDwAK4uZL1vFFJbenSveqoeEE3eEU3eTsFGzcSogisbrmPbgJNPVHCtaw8FeK2mbN4SH7yuFglTyFZkR_ehnc8O8rO_93A0FWicUc6A9LP---3vEYsyxQP7csNWR10WMF-57y-e4iw6op-9YUY2yDnG1SSm0yJ5v-KxsSMdgtKKno9_jnlaOLmCh5yNM1QFyWT3vCWwf-nVMyAqlLvxiTPc9r6UBOhs6ZS5UB26JNCS0jcbQR1jhiUDWBChwbuQL1SIt9Nx_b0wRKO8-9CfnjGaXCzdmpHQshhbnv7sPfzjh8Au1ectosbjmPuE7Jtq-TV6TraJrq7OOKwvgutLpJuxgyZnDqpzzutqnbhi9Jm00) | [SVG](https://www.plantuml.com/plantuml/svg/TPBTJjj048Nlvob6kMeb_1UXYbe24Qgs2XS9oC0DL6XP3sZ3PcnsrrHL58c7u0dx98pNuLVYRktlUCuvuzttGRdGBItcEucdkqJvVwmJhnL3CC4ILdJN4Ml2_m-FEEafQhKafv0f_6tSBVPY_B9ehh1L8P3Zhm1AXyRXQDwAK4uZL1vFFJbenSveqoeEE3eEU3eTsFGzcSogisbrmPbgJNPVHCtaw8FeK2mbN4SH7yuFglTyFZkR_ehnc8O8rO_93A0FWicUc6A9LP---3vEYsyxQP7csNWR10WMF-57y-e4iw6op-9YUY2yDnG1SSm0yJ5v-KxsSMdgtKKno9_jnlaOLmCh5yNM1QFyWT3vCWwf-nVMyAqlLvxiTPc9r6UBOhs6ZS5UB26JNCS0jcbQR1jhiUDWBChwbuQL1SIt9Nx_b0wRKO8-9CfnjGaXCzdmpHQshhbnv7sPfzjh8Au1ectosbjmPuE7Jtq-TV6TraJrq7OOKwvgutLpJuxgyZnDqpzzutqnbhi9Jm00) |
|
||||
| 09 | **seq large upload** | Large model upload: initiate → presigned PUT → complete. | [PNG](https://www.plantuml.com/plantuml/png/TPB1Jjj048Rl-nIZd1B9RWA80wX2mA5I2i519Zr5YYRs4AQnrylkc3OW91wYJzWdwJXEqYPIJxlQ-NU-V_xToo3efIuB69p5WPxZ0ls2ujeL5UP6M0g2b9vhiXd1xuzVSDlKeQnoAg1LGPSj2wCGz26hIbUGRXsAaBSzOp2JoaCdSUHHTnt009D0tZWbSyOEhK3dNc0oR6l3_ShLNVfjc4vj7nttNuxMcglnWIYPVwTC82Y0fhQRdgYN4TjXekkNjBU-b5n_DQOXGtoX53Y7CMVBTfPFh-oWUpeOmEYwPxIe4eKqcYHzWFvQ5Cwtasu2cjgtHox8OaaH17wbsNmb52B8dYXRXhfyDqqJxQLixUKy1LvO64yUJ7CIxoYR2kMpsXVjfQt9OpNrrl9cd4VxqWZefsCzcQ6ycutn5gOG-Bmdlj1avcpHhpGeJrX6y8FbIJjM2zM5tixK3fpScF-diNtilsdyOxCamHm53o9u8S-Fgrr01p5KoyFPZs3Km8ov99lhFpL_0000) | [SVG](https://www.plantuml.com/plantuml/svg/TPB1Jjj048Rl-nIZd1B9RWA80wX2mA5I2i519Zr5YYRs4AQnrylkc3OW91wYJzWdwJXEqYPIJxlQ-NU-V_xToo3efIuB69p5WPxZ0ls2ujeL5UP6M0g2b9vhiXd1xuzVSDlKeQnoAg1LGPSj2wCGz26hIbUGRXsAaBSzOp2JoaCdSUHHTnt009D0tZWbSyOEhK3dNc0oR6l3_ShLNVfjc4vj7nttNuxMcglnWIYPVwTC82Y0fhQRdgYN4TjXekkNjBU-b5n_DQOXGtoX53Y7CMVBTfPFh-oWUpeOmEYwPxIe4eKqcYHzWFvQ5Cwtasu2cjgtHox8OaaH17wbsNmb52B8dYXRXhfyDqqJxQLixUKy1LvO64yUJ7CIxoYR2kMpsXVjfQt9OpNrrl9cd4VxqWZefsCzcQ6ycutn5gOG-Bmdlj1avcpHhpGeJrX6y8FbIJjM2zM5tixK3fpScF-diNtilsdyOxCamHm53o9u8S-Fgrr01p5KoyFPZs3Km8ov99lhFpL_0000) |
|
||||
| 10 | **deployment topology** | Workstations / ANSVIS server / edges + ports + customer network. | [PNG](https://www.plantuml.com/plantuml/png/RLJ1Rjf04BtxAqQSY2hKWgEgYgeg4Bkj8m8qfaahSLdiYREDlMljhXEig59F_O0gNvWlwQmtW25mC3kUDxCpR-RvL1kcJ5Naq7_NIx7CPLsWC3qZIvdBhFOCDpb2iF70VEtnz1qN9LEiW4GMfHJaZKrDQ8M9OIBBqVE4J14wPvKsia05cXk4jv3aiaexyEXv00unBL4n8nKyI7L7DHakXRO8eDycFNIkkKZbWuOKzHtLk13V37oFEi0q1FrzSC6IQNmGEjY7ZhceLWUXFa5_RmiTJkAhA0QDwfxwkPNQ7AZo4icf4KebL_L2pCSn65G55xR5XUYAZ8kLvO6bQNtKt3Fv4ar-xETvkOoLL5ANfQoaBF06SinOKXDGeGiUpcRxeHUOSaQJo5dTG2x3yV1d0qgPOKkcBUdBNpGfeDaef0jYdqgwu2AQql_dsAMUZixteiwakE4PbH7Usvk2aNP4ZNQ92jCCWPOhGxCPfFCuhbSVtbEEoLKKHCCcGTXlOTPpVeqQj53db5iAc2ekdDCDYwe8-j3hVNAimWdO2HmV-mjn6SPpIXZ78Js_ZcCl61m2Ue5_yBMphSTIlhKSk_IkiOYAzT7IrpZXepMfnxOrsB7y9cgDsvu7hRDl9KKQMaf3Yg9k9sYiP41LEMgu8GMPMuJaHN0dbgmUJ2kpb9L8ONusitt0ZP8584jkstg3vx__u6Nbx6Axs4ZiXXBk5MOyeDWd6FVjnXkPo1n8pu1s1RgbL8R8DfKGcCDy51oveEkMqa5OnT2wsf9i62cSsyz8NiFpdoTeRNCZAexQGohASk5vftIaJvZt7m00) | [SVG](https://www.plantuml.com/plantuml/svg/RLJ1Rjf04BtxAqQSY2hKWgEgYgeg4Bkj8m8qfaahSLdiYREDlMljhXEig59F_O0gNvWlwQmtW25mC3kUDxCpR-RvL1kcJ5Naq7_NIx7CPLsWC3qZIvdBhFOCDpb2iF70VEtnz1qN9LEiW4GMfHJaZKrDQ8M9OIBBqVE4J14wPvKsia05cXk4jv3aiaexyEXv00unBL4n8nKyI7L7DHakXRO8eDycFNIkkKZbWuOKzHtLk13V37oFEi0q1FrzSC6IQNmGEjY7ZhceLWUXFa5_RmiTJkAhA0QDwfxwkPNQ7AZo4icf4KebL_L2pCSn65G55xR5XUYAZ8kLvO6bQNtKt3Fv4ar-xETvkOoLL5ANfQoaBF06SinOKXDGeGiUpcRxeHUOSaQJo5dTG2x3yV1d0qgPOKkcBUdBNpGfeDaef0jYdqgwu2AQql_dsAMUZixteiwakE4PbH7Usvk2aNP4ZNQ92jCCWPOhGxCPfFCuhbSVtbEEoLKKHCCcGTXlOTPpVeqQj53db5iAc2ekdDCDYwe8-j3hVNAimWdO2HmV-mjn6SPpIXZ78Js_ZcCl61m2Ue5_yBMphSTIlhKSk_IkiOYAzT7IrpZXepMfnxOrsB7y9cgDsvu7hRDl9KKQMaf3Yg9k9sYiP41LEMgu8GMPMuJaHN0dbgmUJ2kpb9L8ONusitt0ZP8584jkstg3vx__u6Nbx6Axs4ZiXXBk5MOyeDWd6FVjnXkPo1n8pu1s1RgbL8R8DfKGcCDy51oveEkMqa5OnT2wsf9i62cSsyz8NiFpdoTeRNCZAexQGohASk5vftIaJvZt7m00) |
|
||||
| 11 | **l3 engineer ownership** | L3 engineers 1–6 and the components each owns. | [PNG](https://www.plantuml.com/plantuml/png/RLRRRYet57tdAxRIbnmb194BglfG7K88HI8NGYwjn8kPsGmkWpsoFIJagDBvX_OBpvTqUSOamISl8VQiVLlxvg_M2UFALKxjTZC_QRBAf68sJVsisDY5B1fEkfnf93Piw8H-VF-F-W54Ro3Qxz1Mr7vfDEnIga8OiQ94hmgjMBc9sq2DuSG9bUNy0LA8P2aoZW6DS4zx_NPbzc588nOfjMYou3odhaaMqW6_Hy8IGB-CPBPmV-6RVgPl3NetJdjZHnqweDwLM3AjjDA62nq4kxlG0ICguJYbk_xadf9SudggvaQlI1UiH26FrksZlwrMGS7vhe9kwHO4OXt3ejDBLZZ1O43tTj4NR6K6nCOwNY4uj-3L5dgn2xqMQva99xKYeql79i3wkx3RYZYfCdgIgdKbajP8gl9bghmXN1-IqaYxVEN3gHAbqysoIE5jq7Qvgwqtf9LmHhw4puF6FnzpSrpbvbOMd2Fzr4ybGgL9mOaKkRGXESSXEUTvoN5g7gKjHKuNtG5n9JrL--E14SL29lPHyZD9HUDnAPFbaqmpTb-2pYXlrpfbokNC2BEXWwbAj5Ae3i_M6gwa5N51DChO907fefaQkKQojcMfEBS17-NiGQKQgJASQb1enPfnMgFstorSxD9KTyu8-jS-eXPT8LPHOqy2EGF3iFvJuLwLkPCh3wS_HXCgSj-Au6ZT3aISH4HK0ath32ECpCWqmAAWpsVwXJIyXa9FUSNmq1VX0OqdWm7h5JkpyRHk3KKqz7AqVkqFxIEmb5NoXergzubdT_SzMYEAmQHohGxYU8llxn9sMX7MqsekCxhKPXLISHh8kfLg6NErcyRnrOZcNX1cFclUOFWqOg_dFHFWuERwSNX9gRI99sb3SuoL87B-gKWYgkghAkvX2AjtDqDa-XKeYz-5NkdCb_LcQpcYymfCvp1Sv2MwrvSmsYxBGExyG_nHOPrLF5q8kvXfOVnqx2Duvwki5ZWBXFMqGPT5ZDqBWuQYT2kEhi5V2oUI1HP3i7aMKLHP85-KlkTz5YMM2A9_vJJ4TXPtsAHFjfpPnCWP0ZgeMk6ydC-tG-mi8kDIvXXm2CUomA2drbHjAunyS6zo5vyLlwlZmg3t0mKpBu2Z8klKY-LFcEaPRMqJnUmysJJkrX8Ti8VsLYby-VRfu2uqnjp2Jz9sUtD8ilrh606TYBMXmax0tcfHMQ0ECAmSMmVVfkh9fvimgIjYCAk3XhZE3F94VdEPMcv_WdkKfdSVdmgnfRyJiUbxuTRekSmHHy5cZl5cBOVyTY8E7onGgKuiKcRc8WcReLEnXxAGk0CiwgUwpLxHUPYypW1IEzExkRw_w_Rk6mtiwAEZtzyli1PspoVH-JGwd-sU6zXZJ3FjdE_kEPOJudXYNbBxn_T_Zt_pZmAH8oX2Oqa_d_rs9Liz7zn2E2hLBDV9qWziIFGxHmsasgz7_bdvyOvoieN4KqBMwoBFqRc-bb9k6ccNjI6qK8eK-vVBd8Kh3N_K_nN_ukNL-1y0) | [SVG](https://www.plantuml.com/plantuml/svg/RLRRRYet57tdAxRIbnmb194BglfG7K88HI8NGYwjn8kPsGmkWpsoFIJagDBvX_OBpvTqUSOamISl8VQiVLlxvg_M2UFALKxjTZC_QRBAf68sJVsisDY5B1fEkfnf93Piw8H-VF-F-W54Ro3Qxz1Mr7vfDEnIga8OiQ94hmgjMBc9sq2DuSG9bUNy0LA8P2aoZW6DS4zx_NPbzc588nOfjMYou3odhaaMqW6_Hy8IGB-CPBPmV-6RVgPl3NetJdjZHnqweDwLM3AjjDA62nq4kxlG0ICguJYbk_xadf9SudggvaQlI1UiH26FrksZlwrMGS7vhe9kwHO4OXt3ejDBLZZ1O43tTj4NR6K6nCOwNY4uj-3L5dgn2xqMQva99xKYeql79i3wkx3RYZYfCdgIgdKbajP8gl9bghmXN1-IqaYxVEN3gHAbqysoIE5jq7Qvgwqtf9LmHhw4puF6FnzpSrpbvbOMd2Fzr4ybGgL9mOaKkRGXESSXEUTvoN5g7gKjHKuNtG5n9JrL--E14SL29lPHyZD9HUDnAPFbaqmpTb-2pYXlrpfbokNC2BEXWwbAj5Ae3i_M6gwa5N51DChO907fefaQkKQojcMfEBS17-NiGQKQgJASQb1enPfnMgFstorSxD9KTyu8-jS-eXPT8LPHOqy2EGF3iFvJuLwLkPCh3wS_HXCgSj-Au6ZT3aISH4HK0ath32ECpCWqmAAWpsVwXJIyXa9FUSNmq1VX0OqdWm7h5JkpyRHk3KKqz7AqVkqFxIEmb5NoXergzubdT_SzMYEAmQHohGxYU8llxn9sMX7MqsekCxhKPXLISHh8kfLg6NErcyRnrOZcNX1cFclUOFWqOg_dFHFWuERwSNX9gRI99sb3SuoL87B-gKWYgkghAkvX2AjtDqDa-XKeYz-5NkdCb_LcQpcYymfCvp1Sv2MwrvSmsYxBGExyG_nHOPrLF5q8kvXfOVnqx2Duvwki5ZWBXFMqGPT5ZDqBWuQYT2kEhi5V2oUI1HP3i7aMKLHP85-KlkTz5YMM2A9_vJJ4TXPtsAHFjfpPnCWP0ZgeMk6ydC-tG-mi8kDIvXXm2CUomA2drbHjAunyS6zo5vyLlwlZmg3t0mKpBu2Z8klKY-LFcEaPRMqJnUmysJJkrX8Ti8VsLYby-VRfu2uqnjp2Jz9sUtD8ilrh606TYBMXmax0tcfHMQ0ECAmSMmVVfkh9fvimgIjYCAk3XhZE3F94VdEPMcv_WdkKfdSVdmgnfRyJiUbxuTRekSmHHy5cZl5cBOVyTY8E7onGgKuiKcRc8WcReLEnXxAGk0CiwgUwpLxHUPYypW1IEzExkRw_w_Rk6mtiwAEZtzyli1PspoVH-JGwd-sU6zXZJ3FjdE_kEPOJudXYNbBxn_T_Zt_pZmAH8oX2Oqa_d_rs9Liz7zn2E2hLBDV9qWziIFGxHmsasgz7_bdvyOvoieN4KqBMwoBFqRc-bb9k6ccNjI6qK8eK-vVBd8Kh3N_K_nN_ukNL-1y0) |
|
||||
| 12 | **dependency chain** | Critical path: contract → mock → UI + adapter → integration → ship. | [PNG](https://www.plantuml.com/plantuml/png/VLFRRjD047ttLnpb2GH9bIBnWa1rKvS6GXF50Ga92MtiYRDqlMljJeB24_y0NyYNC5utQG9INxoxupDdRcSk0YlFczfWUDulgI5RaYrs_MAjj4rOio5S7So8Plpv-HlVrufHAQOGhqaIxhHjb5Sr2bStpfBbd7VYxgbWPIj3IIAXz4eLZ9uJIjNemNOu-1QS_MAVhBpxGVPf3ofWDBrTpDFH8ZbGeJVpEjIeNN67G7vBFY8_J4VlZr7fRVvfdEDCkC-sGwXIDKnUwDEnv5MI3y_HaEzx2cxZ2-hYfLVfx2JOX2ebvNPi4JB9tgQZpoUO5mXhCWRFCC_o1GgZnIwXic77-d7yDR_99fD_dGfFP4CBF9TM_aBsye2_pjAJFEQa39Qgk9C1G5kcoYlMpaRyF4jFkFErRh0Tnd_vpNYM9Fi-ejz_qxNgnDAL7R_nVLzZ2uplGm7xozuQqxm_eoscya0Kd-qdlhfSh6F2qZ6x6cxrC69WQiqE1sbmAwpBwU86GPUYhgLfH-xiG93NKIFoA0ZDPccq3A1y9LCkDUijjVAqbVWuOHmaRS_QgF_5Zfs058AIjcHS4x0cJn09rYZL3iD7dBkc0PSRRLXcWbRqnf3CIGIpLrcRxUn8PoBSScEKrxp3Q_7QhngZyQuIL7WaP6mdyCvfgss5HauUjEdBzd60trYeIXOpSEkqxfP42PiN-OWZEocKPGrHUhtYuqWNSfNjJ_u2) | [SVG](https://www.plantuml.com/plantuml/svg/VLFRRjD047ttLnpb2GH9bIBnWa1rKvS6GXF50Ga92MtiYRDqlMljJeB24_y0NyYNC5utQG9INxoxupDdRcSk0YlFczfWUDulgI5RaYrs_MAjj4rOio5S7So8Plpv-HlVrufHAQOGhqaIxhHjb5Sr2bStpfBbd7VYxgbWPIj3IIAXz4eLZ9uJIjNemNOu-1QS_MAVhBpxGVPf3ofWDBrTpDFH8ZbGeJVpEjIeNN67G7vBFY8_J4VlZr7fRVvfdEDCkC-sGwXIDKnUwDEnv5MI3y_HaEzx2cxZ2-hYfLVfx2JOX2ebvNPi4JB9tgQZpoUO5mXhCWRFCC_o1GgZnIwXic77-d7yDR_99fD_dGfFP4CBF9TM_aBsye2_pjAJFEQa39Qgk9C1G5kcoYlMpaRyF4jFkFErRh0Tnd_vpNYM9Fi-ejz_qxNgnDAL7R_nVLzZ2uplGm7xozuQqxm_eoscya0Kd-qdlhfSh6F2qZ6x6cxrC69WQiqE1sbmAwpBwU86GPUYhgLfH-xiG93NKIFoA0ZDPccq3A1y9LCkDUijjVAqbVWuOHmaRS_QgF_5Zfs058AIjcHS4x0cJn09rYZL3iD7dBkc0PSRRLXcWbRqnf3CIGIpLrcRxUn8PoBSScEKrxp3Q_7QhngZyQuIL7WaP6mdyCvfgss5HauUjEdBzd60trYeIXOpSEkqxfP42PiN-OWZEocKPGrHUhtYuqWNSfNjJ_u2) |
|
||||
@@ -0,0 +1,78 @@
|
||||
# ANSCORE — L2 & L3 Architecture Diagrams (PlantUML)
|
||||
|
||||
12 PlantUML diagrams covering Layer 2 (ANSVIS Communication Layer (CL)) and Layer 3 (Qt/QML UI).
|
||||
|
||||
## Files
|
||||
|
||||
| # | File | Type | Purpose |
|
||||
|---|---|---|---|
|
||||
| 01 | `01-system-context.puml` | Component | L1 / L2 / L3 overview with the 3 transports |
|
||||
| 02 | `02-l2-internals.puml` | Component | L2 adapter layer + legacy + infrastructure |
|
||||
| 03 | `03-l2-ownership.puml` | Component | Human-owned vs AI-coder vs reused legacy modules |
|
||||
| 04 | `04-l3-internals.puml` | Component | Qt/QML shell / network / state / screens |
|
||||
| 05 | `05-seq-configure-deploy.puml` | Sequence | Operator adds camera → AI task → deploys |
|
||||
| 06 | `06-seq-live-events.puml` | Sequence | SSE event tail + evidence image/clip |
|
||||
| 07 | `07-seq-liveview.puml` | Sequence | Liveview with bbox overlay sync |
|
||||
| 08 | `08-seq-async-scan.puml` | Sequence | Async ONVIF scan via job queue |
|
||||
| 09 | `09-seq-large-upload.puml` | Sequence | Large model upload via presigned URL |
|
||||
| 10 | `10-deployment-topology.puml` | Deployment | Workstations / server / edges + ports |
|
||||
| 11 | `11-l3-engineer-ownership.puml` | Component | 6-engineer L3 task allocation |
|
||||
| 12 | `12-dependency-chain.puml` | Component | What gates what, critical path |
|
||||
|
||||
---
|
||||
|
||||
## How to view these in StarUML
|
||||
|
||||
StarUML doesn't render `.puml` natively, but the official **PlantUML extension** does:
|
||||
|
||||
1. In StarUML: `Tools → Extension Manager → search "PlantUML" → Install`
|
||||
2. Restart StarUML.
|
||||
3. `File → Open` → pick any `.puml` file from this folder, **or** use `Tools → PlantUML → Preview Diagram`.
|
||||
4. To get an editable StarUML diagram (`.mdj`), use the extension's "Generate Diagram from PlantUML" feature, then save as `.mdj`.
|
||||
|
||||
Caveat: the extension renders accurately but the auto-generated StarUML elements may need light layout cleanup. If you want fully native StarUML diagrams, use these `.puml` files as the specification and recreate in StarUML — they're small enough that this takes ~10 min each.
|
||||
|
||||
---
|
||||
|
||||
## Alternative viewers (no install needed)
|
||||
|
||||
| Tool | How |
|
||||
|---|---|
|
||||
| **PlantUML web server** | <https://www.plantuml.com/plantuml> → paste any `.puml` content → get PNG/SVG/PDF |
|
||||
| **VS Code** | Install the "PlantUML" extension by jebbs → `Alt+D` to preview |
|
||||
| **JetBrains (CLion / IntelliJ / Rider)** | Install the "PlantUML Integration" plugin → preview on the side panel |
|
||||
| **PlantUML CLI** (batch export) | `brew install plantuml` then `plantuml -tpng docs/diagrams/*.puml -o ../out/` |
|
||||
| **PlantUML CLI** (SVG for slides) | `plantuml -tsvg docs/diagrams/*.puml -o ../out/` |
|
||||
|
||||
The web server is the fastest path if you just want to grab images for a slide deck or PDF.
|
||||
|
||||
---
|
||||
|
||||
## Render all to PNG in one shot
|
||||
|
||||
```bash
|
||||
# from the repo root
|
||||
brew install plantuml # macOS; or: apt install plantuml
|
||||
mkdir -p out/diagrams
|
||||
plantuml -tpng -o "$(pwd)/out/diagrams" docs/diagrams/*.puml
|
||||
```
|
||||
|
||||
Output: one PNG per diagram in `out/diagrams/`.
|
||||
|
||||
For high-DPI presentations use `-tsvg` instead of `-tpng`.
|
||||
|
||||
---
|
||||
|
||||
## Editing tips
|
||||
|
||||
- Diagrams use only stable PlantUML features — should render in any PlantUML version ≥ 1.2022.0.
|
||||
- Colors used: `#LightYellow` (human/lead), `#LightBlue` (AI/E2), `#LightGreen` (E3), `#LightPink` (E4), `#LightCoral` (E5), `#Lavender` (E6), `#LightGray` (reused legacy). Change consistently if you want a different palette.
|
||||
- Each file declares its own `@startuml NAME` so multiple files can render to predictable filenames.
|
||||
- Notes (`note bottom of ...`) are intentional — leave them in; they explain non-obvious decisions.
|
||||
|
||||
---
|
||||
|
||||
## Related
|
||||
|
||||
- `docs/L2-L3-architecture.md` — same diagrams in Mermaid + accompanying prose.
|
||||
- `contracts/openapi.v1.json` — the REST contract these diagrams reference.
|
||||
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 27 KiB |
@@ -0,0 +1,191 @@
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 22mm 18mm 22mm 18mm;
|
||||
@top-right {
|
||||
content: "ANSCORE — System Architecture (L2 + L3)";
|
||||
font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 8.5pt;
|
||||
color: #888;
|
||||
}
|
||||
@bottom-right {
|
||||
content: "Page " counter(page) " / " counter(pages);
|
||||
font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 8.5pt;
|
||||
color: #888;
|
||||
}
|
||||
@bottom-left {
|
||||
content: "v1.0 • 2026-05-26 • ANSCENTER";
|
||||
font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 8.5pt;
|
||||
color: #888;
|
||||
}
|
||||
}
|
||||
|
||||
@page :first {
|
||||
@top-right { content: ""; }
|
||||
@bottom-right { content: ""; }
|
||||
@bottom-left { content: ""; }
|
||||
}
|
||||
|
||||
html, body {
|
||||
font-family: -apple-system, "Helvetica Neue", "Segoe UI", Arial, "Apple Symbols", "STIXGeneral", "Lucida Grande", sans-serif;
|
||||
font-size: 10.5pt;
|
||||
line-height: 1.45;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 22pt;
|
||||
color: #102a55;
|
||||
border-bottom: 2px solid #102a55;
|
||||
padding-bottom: 4pt;
|
||||
margin-top: 0;
|
||||
page-break-before: always;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
h1:first-of-type {
|
||||
page-break-before: avoid;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 15pt;
|
||||
color: #1a4080;
|
||||
margin-top: 1.4em;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 12.5pt;
|
||||
color: #1a4080;
|
||||
margin-top: 1.1em;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 11pt;
|
||||
color: #333;
|
||||
margin-top: 0.9em;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
p, ul, ol {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
ul, ol {
|
||||
padding-left: 1.4em;
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0.15em 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #1a4080;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "SF Mono", "Menlo", Consolas, monospace;
|
||||
font-size: 9pt;
|
||||
background: #f4f4f6;
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
color: #2c2c2c;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family: "SF Mono", "Menlo", Consolas, monospace;
|
||||
font-size: 9pt;
|
||||
background: #f6f8fa;
|
||||
border: 1px solid #e1e4e8;
|
||||
border-radius: 4px;
|
||||
padding: 10pt 12pt;
|
||||
line-height: 1.4;
|
||||
overflow-x: auto;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
pre code {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
font-size: 9pt;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 0.8em 0;
|
||||
font-size: 9.5pt;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid #d0d4dc;
|
||||
padding: 5pt 7pt;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
th {
|
||||
background: #eef2f8;
|
||||
color: #102a55;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
tr:nth-child(even) td {
|
||||
background: #fafbfd;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
display: block;
|
||||
margin: 0.6em auto;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
border-top: 1px solid #d0d4dc;
|
||||
margin: 1.5em 0;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border-left: 3px solid #c3cad6;
|
||||
margin: 0.6em 0;
|
||||
padding: 0.2em 0.9em;
|
||||
color: #555;
|
||||
background: #f7f8fa;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Title block (pandoc emits a header div) */
|
||||
header#title-block-header {
|
||||
text-align: center;
|
||||
margin-top: 18%;
|
||||
padding-bottom: 35%;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
header#title-block-header h1.title {
|
||||
font-size: 30pt;
|
||||
color: #102a55;
|
||||
border-bottom: none;
|
||||
page-break-before: avoid;
|
||||
margin-bottom: 12pt;
|
||||
}
|
||||
|
||||
header#title-block-header p.subtitle {
|
||||
font-size: 14pt;
|
||||
color: #555;
|
||||
font-style: italic;
|
||||
margin: 6pt 0;
|
||||
}
|
||||
|
||||
header#title-block-header p.author,
|
||||
header#title-block-header p.date {
|
||||
font-size: 11pt;
|
||||
color: #777;
|
||||
margin: 4pt 0;
|
||||
}
|
||||
@@ -540,7 +540,7 @@ namespace ANSCENTER {
|
||||
") returned null — the DLL may be corrupt.");
|
||||
|
||||
s_ort_api = api;
|
||||
Ort::Global<void>::api_ = api;
|
||||
Ort::InitApi(api);
|
||||
|
||||
std::cout << "[EPLoader] ORT loaded successfully." << std::endl;
|
||||
std::cout << "[EPLoader] ORT DLL version : " << base->GetVersionString() << std::endl;
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace ANSCENTER {
|
||||
{
|
||||
try {
|
||||
// Make sure the Ort API pointer is initialised in THIS DLL.
|
||||
if (Ort::Global<void>::api_ == nullptr) {
|
||||
if (Ort::detail::Global::Api() == nullptr) {
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
}
|
||||
|
||||
@@ -574,10 +574,10 @@ namespace ANSCENTER {
|
||||
const auto& epInfo = EPLoader::Current();
|
||||
ANS_DBG("OrtHandler", "initialize_handler: EPLoader type=%d dir=%s",
|
||||
static_cast<int>(epInfo.type), epInfo.libraryDir.c_str());
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
|
||||
std::cout << "[ORT] api_ = " << (void*)Ort::Global<void>::api_ << std::endl;
|
||||
std::cout << "[ORT] api_ = " << (void*)Ort::detail::Global::Api() << std::endl;
|
||||
|
||||
EngineType engine = (static_cast<int>(m_engineType) == -1)
|
||||
? epInfo.type : m_engineType;
|
||||
@@ -1900,4 +1900,12 @@ namespace ANSCENTER {
|
||||
return std::fabs(width() * height());
|
||||
}
|
||||
|
||||
// Explicit instantiations of every BoundingBoxType member must live
|
||||
// AFTER the template definitions above so the compiler actually emits
|
||||
// symbols (the directives in ONNXEngine.h sit before the definitions
|
||||
// and ClangCL, unlike MSVC, refuses to emit symbols from there).
|
||||
template struct ANSCENTER::types::BoundingBoxType<int, float>;
|
||||
template struct ANSCENTER::types::BoundingBoxType<float, float>;
|
||||
template struct ANSCENTER::types::BoundingBoxType<double, double>;
|
||||
|
||||
} // namespace ANSCENTER
|
||||
@@ -73,9 +73,10 @@ namespace ANSCENTER {
|
||||
}
|
||||
};
|
||||
|
||||
template class BoundingBoxType<int, float>;
|
||||
template class BoundingBoxType<float, float>;
|
||||
template class BoundingBoxType<double, double>;
|
||||
// Explicit instantiations now live at the end of ONNXEngine.cpp
|
||||
// (after the template member definitions) so the compiler actually
|
||||
// emits symbols. ClangCL refuses to emit them from a directive that
|
||||
// precedes the definitions, whereas MSVC silently tolerated it.
|
||||
|
||||
typedef BoundingBoxType<int, float> Boxi;
|
||||
typedef BoundingBoxType<float, float> Boxf;
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace ANSCENTER
|
||||
{
|
||||
// Initialize ORT API
|
||||
const auto& epInfo = EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
|
||||
m_env = new Ort::Env(ORT_LOGGING_LEVEL_ERROR, "ONNXSAM3");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <sstream>
|
||||
#include "Utility.h"
|
||||
#include "TRTCompat.h"
|
||||
#include "GpuMemoryGuard.h"
|
||||
|
||||
// ============================================================================
|
||||
// Crash-safe wrappers for TensorRT operations that can crash the process.
|
||||
@@ -805,13 +806,23 @@ bool Engine<T>::loadNetwork(std::string trtModelPath, const std::array<float, 3>
|
||||
// (cudaMalloc failure during inference) when too many tasks are loaded.
|
||||
{
|
||||
size_t freeVRAM = 0, totalVRAM = 0;
|
||||
cudaError_t memErr = cudaMemGetInfo(&freeVRAM, &totalVRAM);
|
||||
constexpr size_t kMinFreeBytes = 256ULL * 1024 * 1024; // 256 MiB minimum
|
||||
if (memErr != cudaSuccess) {
|
||||
// cudaMemGetInfo failed — CUDA context may not be initialized on this thread.
|
||||
// Don't reject: let TRT try to deserialize (it may succeed).
|
||||
} else if (freeVRAM < kMinFreeBytes) {
|
||||
m_lastLoadFailedVRAM = true; // signal to buildLoadNetwork: engine file is NOT corrupt
|
||||
bool haveMem = ANSCENTER::GpuMemoryGuard::Query(freeVRAM, totalVRAM);
|
||||
// (1) Admission control: refuse to load this engine on the GPU if it
|
||||
// does not fit while keeping the GpuMemoryGuard safety margin free.
|
||||
// Prevents VRAM over-subscription across concurrent engines (FR/OD/LPR/
|
||||
// liveness) that would otherwise OOM and permanently poison the CUDA
|
||||
// context. The engine file is valid — m_lastLoadFailedVRAM tells the
|
||||
// caller to preserve it (no rebuild) and just skip GPU load for now.
|
||||
if (haveMem && !ANSCENTER::GpuMemoryGuard::CanLoad(buffer.size())) {
|
||||
m_lastLoadFailedVRAM = true;
|
||||
std::cerr << "[GpuMemGuard] REFUSING engine load on GPU "
|
||||
<< m_options.deviceIndex << ": need ~"
|
||||
<< (buffer.size() / (1024 * 1024)) << " MiB + "
|
||||
<< (ANSCENTER::GpuMemoryGuard::MarginFor(totalVRAM) / (1024 * 1024))
|
||||
<< " MiB margin, only " << (freeVRAM / (1024 * 1024))
|
||||
<< " MiB free of " << (totalVRAM / (1024 * 1024))
|
||||
<< " MiB total. Reduce concurrent engines/cameras or batch size."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if (m_verbose) {
|
||||
@@ -1425,7 +1436,15 @@ trt_cache_create_context:
|
||||
// ============================================================================
|
||||
|
||||
if (m_verbose) std::cout << "\nInfo: Starting warm-up inference..." << std::endl;
|
||||
warmUp(m_verbose ? 10 : 1);
|
||||
if (!warmUp(m_verbose ? 10 : 1)) {
|
||||
// A failed warmup means this engine cannot run inference (wrong-device
|
||||
// buffers, poisoned context, ...). Report failure so pool creation
|
||||
// rejects the slot instead of silently adding a broken engine that
|
||||
// corrupts every subsequent inference dispatched to it.
|
||||
std::cout << "Error: Warm-up inference FAILED on GPU[" << m_options.deviceIndex
|
||||
<< "] -- engine rejected (loadNetwork returns false)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (m_verbose) std::cout << "Info: Warm-up complete" << std::endl;
|
||||
|
||||
} // end of trt_cache_create_context scope
|
||||
@@ -1798,6 +1817,25 @@ bool Engine<T>::build(std::string onnxModelPath, const std::array<float, 3>& sub
|
||||
// Set hardware compatibility
|
||||
config->setHardwareCompatibilityLevel(nvinfer1::HardwareCompatibilityLevel::kNONE);
|
||||
|
||||
// -- Blackwell (SM 12.x) aux-stream workaround ----------------------------
|
||||
// On sm_120 (RTX 50-series), TRT 10.15's Myelin runtime faults when a second
|
||||
// concurrent execution context runs with auto-selected aux streams:
|
||||
// "Internal Error: MyelinCheckException ... l2cm_layer_internal.cpp:174"
|
||||
// followed by CUDA error 700 (illegal memory access) poisoning the context.
|
||||
// Aux streams only provide intra-inference parallelism (irrelevant for the
|
||||
// small per-slot models we run); throughput comes from the engine pool's
|
||||
// one-context-per-slot design, which is unaffected. Force 0 aux streams on
|
||||
// Blackwell until NVIDIA fixes the Myelin multi-stream path.
|
||||
// NOTE: baked in at build time -- stale cached .engine files must be deleted
|
||||
// for this to take effect.
|
||||
#if NV_TENSORRT_MAJOR >= 10
|
||||
if (prop.major >= 12) {
|
||||
config->setMaxAuxStreams(0);
|
||||
std::cout << "Aux streams disabled on SM " << prop.major << "." << prop.minor
|
||||
<< " (Blackwell Myelin multi-stream workaround)" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
// -- TensorRT 10+ tactic DRAM pool ----------------------------------------
|
||||
// Separate scratch pool for kernel-selection during build. Without this,
|
||||
// tactic evaluation competes with the workspace allocation and tactics
|
||||
|
||||
@@ -606,6 +606,25 @@ bool Engine<T>::runInferenceFromPool(
|
||||
bool kickedGrowth = false;
|
||||
auto _poolAcquireStart = std::chrono::steady_clock::now();
|
||||
|
||||
// -- DEVICE AFFINITY: find which GPU the caller's inputs live on ------
|
||||
// Dispatching to a slot on the same GPU avoids the pinned-host migration
|
||||
// copy (~1 ms per 1080p frame) that runInference performs for foreign
|
||||
// inputs. Queried outside the slot mutex — it's a cheap driver lookup.
|
||||
int inputDevice = -1;
|
||||
for (const auto& batch : inputs) {
|
||||
for (const auto& img : batch) {
|
||||
if (!img.data) continue;
|
||||
cudaPointerAttributes attr{};
|
||||
if (cudaPointerGetAttributes(&attr, img.data) == cudaSuccess &&
|
||||
attr.type == cudaMemoryTypeDevice) {
|
||||
inputDevice = attr.device;
|
||||
}
|
||||
cudaGetLastError(); // clear any error the query left behind
|
||||
break; // first image is representative
|
||||
}
|
||||
if (inputDevice >= 0) break;
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_slotMutex);
|
||||
|
||||
@@ -616,13 +635,31 @@ bool Engine<T>::runInferenceFromPool(
|
||||
const size_t n = m_slots.size();
|
||||
if (n > 0) {
|
||||
const size_t start = m_nextSlotHint.load() % n;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
auto& s = m_slots[(start + i) % n];
|
||||
if (!s.busy && s.engine) { // alive and idle
|
||||
s.busy = true;
|
||||
slot = &s;
|
||||
m_nextSlotHint = (start + i + 1) % n;
|
||||
break;
|
||||
|
||||
// Pass A: idle slot on the inputs' own GPU (zero-copy dispatch)
|
||||
if (inputDevice >= 0) {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
auto& s = m_slots[(start + i) % n];
|
||||
if (!s.busy && s.engine && s.deviceIndex == inputDevice) {
|
||||
s.busy = true;
|
||||
slot = &s;
|
||||
m_nextSlotHint = (start + i + 1) % n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pass B: any idle slot (round-robin) — runInference migrates
|
||||
// the inputs across GPUs when needed.
|
||||
if (!slot) {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
auto& s = m_slots[(start + i) % n];
|
||||
if (!s.busy && s.engine) { // alive and idle
|
||||
s.busy = true;
|
||||
slot = &s;
|
||||
m_nextSlotHint = (start + i + 1) % n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,13 +130,31 @@ static inline cudaError_t cudaStreamSynchronize_Safe(cudaStream_t stream) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Engine<T>::warmUp(int iterations) {
|
||||
bool Engine<T>::warmUp(int iterations) {
|
||||
if (m_verbose) {
|
||||
std::cout << "\n========================================" << std::endl;
|
||||
std::cout << "Engine Warmup" << std::endl;
|
||||
std::cout << "========================================" << std::endl;
|
||||
}
|
||||
|
||||
// Ensure this thread's CUDA device matches the engine BEFORE the dummy-input
|
||||
// uploads below. warmUp() does GPU work (GpuMat uploads) ahead of
|
||||
// runInference()'s own device guard, so it must not rely on the caller
|
||||
// having left the right device current (multi-GPU pool creation touches
|
||||
// several devices on one thread).
|
||||
{
|
||||
int currentDev = -1;
|
||||
cudaGetDevice(¤tDev);
|
||||
if (currentDev != m_options.deviceIndex) {
|
||||
std::cout << "Warning [Warmup]: thread was on GPU[" << currentDev
|
||||
<< "], engine expects GPU[" << m_options.deviceIndex
|
||||
<< "] -- switching device" << std::endl;
|
||||
cudaSetDevice(m_options.deviceIndex);
|
||||
}
|
||||
}
|
||||
|
||||
bool allBatchesOk = true;
|
||||
|
||||
// Determine batch sizes to warm up
|
||||
std::vector<int> batchSizes;
|
||||
|
||||
@@ -212,7 +230,9 @@ void Engine<T>::warmUp(int iterations) {
|
||||
auto firstTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||
|
||||
if (!firstSuccess) {
|
||||
if (m_verbose) std::cout << " ✗ ERROR: First iteration failed for batch=" << batchSize << std::endl;
|
||||
std::cout << " ✗ ERROR: Warmup first iteration failed for batch=" << batchSize
|
||||
<< " on GPU[" << m_options.deviceIndex << "]" << std::endl;
|
||||
allBatchesOk = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -231,7 +251,9 @@ void Engine<T>::warmUp(int iterations) {
|
||||
for (int i = 1; i < iters; ++i) {
|
||||
bool success = runInference(dummyInputs, dummyOutputs);
|
||||
if (!success) {
|
||||
if (m_verbose) std::cout << " ✗ ERROR: Iteration " << i << " failed" << std::endl;
|
||||
std::cout << " ✗ ERROR: Warmup iteration " << i << " failed for batch="
|
||||
<< batchSize << " on GPU[" << m_options.deviceIndex << "]" << std::endl;
|
||||
allBatchesOk = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -262,6 +284,7 @@ void Engine<T>::warmUp(int iterations) {
|
||||
std::cout << "Kernels pre-compiled for all batch sizes." << std::endl;
|
||||
std::cout << "========================================\n" << std::endl;
|
||||
}
|
||||
return allBatchesOk;
|
||||
}
|
||||
template <typename T>
|
||||
bool Engine<T>::runInference(const std::vector<std::vector<cv::cuda::GpuMat>>& inputs,std::vector<std::vector<std::vector<T>>>& featureVectors) {
|
||||
@@ -778,6 +801,118 @@ bool Engine<T>::runInference(const std::vector<std::vector<cv::cuda::GpuMat>>& i
|
||||
}
|
||||
}
|
||||
|
||||
// Pass 1.5: INPUT DEVICE MIGRATION (multi-GPU pool dispatch).
|
||||
//
|
||||
// The caller prepares input GpuMats on ITS device (e.g. camera preprocessing
|
||||
// on GPU 0), but round-robin dispatch may select a slot on another GPU.
|
||||
// Kernels cannot touch cross-device memory without peer access: preprocessing
|
||||
// a device-A GpuMat with a device-B stream raises an async illegal memory
|
||||
// access that permanently poisons every CUDA context in the process
|
||||
// (sticky error 700). Detect foreign inputs and migrate them onto this
|
||||
// engine's device via a UVA copy (cudaMemcpyDefault routes over PCIe).
|
||||
std::vector<std::vector<cv::cuda::GpuMat>> migratedInputs;
|
||||
const std::vector<std::vector<cv::cuda::GpuMat>>* activeInputs = &inputs;
|
||||
{
|
||||
bool anyForeign = false;
|
||||
for (size_t i = 0; i < numInputs && !anyForeign; ++i) {
|
||||
for (const auto& img : inputs[i]) {
|
||||
if (!img.data) continue;
|
||||
cudaPointerAttributes attr{};
|
||||
if (cudaPointerGetAttributes(&attr, img.data) == cudaSuccess &&
|
||||
attr.type == cudaMemoryTypeDevice &&
|
||||
attr.device != m_options.deviceIndex) {
|
||||
anyForeign = true;
|
||||
}
|
||||
cudaGetLastError(); // clear any error the attribute query left behind
|
||||
break; // first image per tensor is representative
|
||||
}
|
||||
}
|
||||
|
||||
if (anyForeign) {
|
||||
migratedInputs.resize(numInputs);
|
||||
for (size_t i = 0; i < numInputs; ++i) {
|
||||
migratedInputs[i].reserve(inputs[i].size());
|
||||
for (const auto& src : inputs[i]) {
|
||||
cudaPointerAttributes attr{};
|
||||
const bool foreign = src.data &&
|
||||
cudaPointerGetAttributes(&attr, src.data) == cudaSuccess &&
|
||||
attr.type == cudaMemoryTypeDevice &&
|
||||
attr.device != m_options.deviceIndex;
|
||||
cudaGetLastError();
|
||||
if (!foreign) { migratedInputs[i].push_back(src); continue; }
|
||||
|
||||
// Two-hop copy through pinned host staging. A direct
|
||||
// device-to-device cudaMemcpy2D across GPUs is not supported
|
||||
// (2D copies have no peer path, and GeForce has no P2P), so:
|
||||
// hop 1: strided D2H from the foreign GPU into pinned host
|
||||
// hop 2: strided H2D onto this engine's GPU
|
||||
// Synchronous copies keep the single staging buffer safe to
|
||||
// reuse across images; ~1 ms per 1080p frame over PCIe 4.
|
||||
struct PinnedStaging { // thread-local, grow-only
|
||||
void* ptr = nullptr;
|
||||
size_t cap = 0;
|
||||
~PinnedStaging() { if (ptr) cudaFreeHost(ptr); }
|
||||
};
|
||||
thread_local PinnedStaging tl_staging;
|
||||
|
||||
const size_t rowBytes = static_cast<size_t>(src.cols) * src.elemSize();
|
||||
const size_t needed = rowBytes * static_cast<size_t>(src.rows);
|
||||
if (needed > tl_staging.cap) {
|
||||
if (tl_staging.ptr) cudaFreeHost(tl_staging.ptr);
|
||||
tl_staging.ptr = nullptr; tl_staging.cap = 0;
|
||||
if (cudaMallocHost(&tl_staging.ptr, needed) != cudaSuccess) {
|
||||
std::cout << "Error [MultiGPU]: pinned staging alloc failed ("
|
||||
<< needed << " bytes)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
tl_staging.cap = needed;
|
||||
}
|
||||
|
||||
// Hop 1: D2H. UVA lets us read the foreign pointer from this
|
||||
// device's context; if the runtime rejects it, retry with the
|
||||
// source device current.
|
||||
cudaError_t mErr = cudaMemcpy2D(
|
||||
tl_staging.ptr, rowBytes, src.data, src.step,
|
||||
rowBytes, src.rows, cudaMemcpyDeviceToHost);
|
||||
if (mErr != cudaSuccess) {
|
||||
cudaGetLastError();
|
||||
cudaSetDevice(attr.device);
|
||||
mErr = cudaMemcpy2D(
|
||||
tl_staging.ptr, rowBytes, src.data, src.step,
|
||||
rowBytes, src.rows, cudaMemcpyDeviceToHost);
|
||||
cudaSetDevice(m_options.deviceIndex);
|
||||
}
|
||||
if (mErr != cudaSuccess) {
|
||||
std::cout << "Error [MultiGPU]: migration hop1 (D2H from GPU["
|
||||
<< attr.device << "]) failed: " << cudaGetErrorString(mErr) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Hop 2: H2D onto this engine's GPU.
|
||||
cv::cuda::GpuMat dst(src.rows, src.cols, src.type());
|
||||
mErr = cudaMemcpy2D(
|
||||
dst.data, dst.step, tl_staging.ptr, rowBytes,
|
||||
rowBytes, src.rows, cudaMemcpyHostToDevice);
|
||||
if (mErr != cudaSuccess) {
|
||||
std::cout << "Error [MultiGPU]: migration hop2 (H2D to GPU["
|
||||
<< m_options.deviceIndex << "]) failed: "
|
||||
<< cudaGetErrorString(mErr) << std::endl;
|
||||
return false;
|
||||
}
|
||||
migratedInputs[i].push_back(dst);
|
||||
}
|
||||
}
|
||||
activeInputs = &migratedInputs;
|
||||
|
||||
static std::atomic<bool> s_migrationLogged{false};
|
||||
if (!s_migrationLogged.exchange(true)) {
|
||||
std::cout << "Info [MultiGPU]: inputs resided on another GPU -- migrated to GPU["
|
||||
<< m_options.deviceIndex << "] via UVA copy (logged once; recurs per"
|
||||
<< " cross-device dispatch)" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pass 2: Preprocess + D2D copies — all on m_inferenceStream (no null stream).
|
||||
//
|
||||
// All OpenCV CUDA ops (convertTo, subtract, divide, split) in blobFromGpuMats
|
||||
@@ -794,7 +929,7 @@ bool Engine<T>::runInference(const std::vector<std::vector<cv::cuda::GpuMat>>& i
|
||||
preprocessedBuffers.reserve(numInputs);
|
||||
|
||||
for (size_t i = 0; i < numInputs; ++i) {
|
||||
const auto& batchInput = inputs[i];
|
||||
const auto& batchInput = (*activeInputs)[i];
|
||||
|
||||
// Preprocess on m_inferenceStream (not the null stream).
|
||||
preprocessedBuffers.push_back(
|
||||
@@ -811,8 +946,23 @@ bool Engine<T>::runInference(const std::vector<std::vector<cv::cuda::GpuMat>>& i
|
||||
m_inferenceStream);
|
||||
|
||||
if (copyErr != cudaSuccess) {
|
||||
// Rich diagnostics — this fires on multi-GPU slot warmup failures
|
||||
// (Blackwell debugging). Identify WHICH precondition broke:
|
||||
// wrong current device, empty blob (failed allocation), null dest
|
||||
// buffer, or a pre-existing sticky async error.
|
||||
int curDev = -1; cudaGetDevice(&curDev);
|
||||
std::cout << "Error: Failed to copy input " << i
|
||||
<< " to inference buffer: " << cudaGetErrorString(copyErr) << std::endl;
|
||||
<< " to inference buffer: " << cudaGetErrorString(copyErr) << "\n"
|
||||
<< " [diag] engine deviceIndex = " << m_options.deviceIndex
|
||||
<< ", thread current device = " << curDev << "\n"
|
||||
<< " [diag] src blob ptr = " << static_cast<const void*>(blobMat.data)
|
||||
<< " (" << blobMat.rows << "x" << blobMat.cols
|
||||
<< ", elemSize " << blobMat.elemSize() << ")\n"
|
||||
<< " [diag] dst buffer ptr = " << m_buffers[i]
|
||||
<< ", copySize = " << copySize << " bytes\n"
|
||||
<< " [diag] inference stream = " << static_cast<const void*>(m_inferenceStream)
|
||||
<< ", pending lastError = " << cudaGetErrorString(cudaGetLastError())
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +207,21 @@ std::string Engine<T>::serializeEngineOptions(const ANSCENTER::Options& options,
|
||||
+ std::to_string(CUDNN_MAJOR) + "."
|
||||
+ std::to_string(CUDNN_MINOR);
|
||||
|
||||
// -- Blackwell aux-stream workaround marker --------------------------------
|
||||
// On SM 12.x the builder forces maxAuxStreams=0 (see EngineBuildLoadNetwork.inl:
|
||||
// TRT 10.15 Myelin faults with concurrent contexts + aux streams). Tag those
|
||||
// engines so caches built *before* the workaround (with aux streams baked in)
|
||||
// miss and rebuild automatically instead of loading and crashing.
|
||||
#if NV_TENSORRT_MAJOR >= 10
|
||||
{
|
||||
cudaDeviceProp prop{};
|
||||
if (cudaGetDeviceProperties(&prop, options.deviceIndex) == cudaSuccess
|
||||
&& prop.major >= 12) {
|
||||
engineName += ".aux0";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return engineName;
|
||||
}
|
||||
|
||||
@@ -231,6 +246,32 @@ cv::cuda::GpuMat Engine<T>::blobFromGpuMats(const std::vector<cv::cuda::GpuMat>
|
||||
thread_local cv::cuda::GpuMat tl_blob;
|
||||
thread_local cv::cuda::GpuMat tl_floatImg;
|
||||
thread_local int tl_blobMaxElems = 0;
|
||||
thread_local int tl_blobDevice = -1;
|
||||
|
||||
// DEVICE AFFINITY: the cached GpuMats live on ONE device. When the same
|
||||
// thread serves engines on different GPUs (multi-GPU pool creation warms
|
||||
// probe on GPU A, then slots on GPU B), reusing a device-A blob with a
|
||||
// device-B stream causes invalid-argument launches and an async illegal
|
||||
// memory access that permanently poisons both CUDA contexts (sticky 700).
|
||||
// Detect the device switch and rebuild the cache on the current device.
|
||||
{
|
||||
int curDev = -1;
|
||||
cudaGetDevice(&curDev);
|
||||
if (curDev != tl_blobDevice) {
|
||||
if (tl_blobDevice >= 0) {
|
||||
// Free on the owning device — the async allocator frees via the
|
||||
// CURRENT device's null-stream pool, so switch, release, switch back.
|
||||
cudaSetDevice(tl_blobDevice);
|
||||
tl_blob.release();
|
||||
tl_floatImg.release();
|
||||
cudaSetDevice(curDev);
|
||||
ANS_DBG("TRT_Preproc", "blobFromGpuMats: device switch GPU[%d]->GPU[%d], preproc cache rebuilt",
|
||||
tl_blobDevice, curDev);
|
||||
}
|
||||
tl_blobMaxElems = 0;
|
||||
tl_blobDevice = curDev;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalElems > tl_blobMaxElems) {
|
||||
tl_blob = cv::cuda::GpuMat(1, totalElems, CV_32FC1);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// GpuMemoryGuard — process-wide GPU VRAM safeguard.
|
||||
//
|
||||
// Purpose: prevent the out-of-memory cascade that happens when many TensorRT /
|
||||
// CUDA engines (FR-SCRFD, OD-YOLO, LPR, liveness, ORT-CUDA, OpenCV-CUDA) share
|
||||
// one GPU and collectively exhaust VRAM. The first cudaMalloc/stream OOM
|
||||
// poisons the CUDA context ("permanently corrupted after N failures"), after
|
||||
// which every GPU op fails and the service appears dead until restart.
|
||||
//
|
||||
// Three coordinated layers (all process-wide, thread-safe, lock-free):
|
||||
// (1) CanLoad(need) — admission control: refuse to load an engine on GPU
|
||||
// if it won't fit while keeping a safety margin free.
|
||||
// (2) UnderPressure() — pressure guard: skip a frame's GPU work when free
|
||||
// VRAM is below the margin (or breaker is open).
|
||||
// (3) NoteOom()/Breaker— circuit breaker: after a caught OOM, open a short
|
||||
// cooldown so callers back off instead of hammering
|
||||
// the fragile context (which is what corrupts it).
|
||||
//
|
||||
// The margin scales with the device: total/8, clamped to [192 MiB, 768 MiB].
|
||||
// A fixed margin cannot work across the fleet — 768 MiB is 3% of a 24 GiB
|
||||
// compute card but 19% of a 4 GiB display card (RTX A400), where the desktop
|
||||
// plus the ORT CUDA arena never leave that much free and admission control can
|
||||
// therefore never pass. The 768 MiB ceiling keeps every card >= 6 GiB on
|
||||
// exactly the previous margin, so only small cards change behaviour.
|
||||
// Override at runtime with env ANSCENTER_GPU_MARGIN_MB (or SetMargin); an
|
||||
// explicit override wins over scaling. All queries operate on the CURRENT CUDA
|
||||
// device (callers cudaSetDevice first).
|
||||
// ============================================================================
|
||||
#include <cuda_runtime.h>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace ANSCENTER {
|
||||
|
||||
class GpuMemoryGuard {
|
||||
public:
|
||||
// ---- configuration ----------------------------------------------------
|
||||
// Effective margin for a device with 'totalB' VRAM. An explicit override
|
||||
// (env or SetMargin) wins; otherwise scale to the card.
|
||||
static size_t MarginFor(size_t totalB) {
|
||||
if (size_t ov = s_marginOverride.load(std::memory_order_relaxed)) return ov;
|
||||
size_t m = totalB / kMarginDivisor;
|
||||
if (m < kMarginMin) m = kMarginMin;
|
||||
if (m > kMarginMax) m = kMarginMax;
|
||||
return m;
|
||||
}
|
||||
// Effective margin for the CURRENT device. Prefer MarginFor() where the
|
||||
// caller already has a total from Query() — this re-queries.
|
||||
static size_t Margin() {
|
||||
size_t freeB = 0, totalB = 0;
|
||||
if (!Query(freeB, totalB)) return kMarginMax;
|
||||
return MarginFor(totalB);
|
||||
}
|
||||
// b == 0 restores device-scaled margins.
|
||||
static void SetMargin(size_t b) { s_marginOverride.store(b, std::memory_order_relaxed); }
|
||||
|
||||
// ---- (1) admission control at load ------------------------------------
|
||||
// True if 'needBytes' can be committed on the current device while keeping
|
||||
// the safety margin free. If VRAM can't be queried, returns true (never
|
||||
// block on a failed query — let the normal path handle it).
|
||||
static bool CanLoad(size_t needBytes) {
|
||||
size_t freeB = 0, totalB = 0;
|
||||
if (!Query(freeB, totalB)) return true;
|
||||
return freeB >= needBytes + MarginFor(totalB);
|
||||
}
|
||||
|
||||
// ---- (2) pressure guard at inference ----------------------------------
|
||||
// True if this frame should SKIP GPU work: free VRAM below margin, or the
|
||||
// circuit breaker is currently open.
|
||||
static bool UnderPressure() {
|
||||
if (BreakerOpen()) return true;
|
||||
size_t freeB = 0, totalB = 0;
|
||||
if (!Query(freeB, totalB)) return false;
|
||||
return freeB < MarginFor(totalB);
|
||||
}
|
||||
|
||||
// ---- (3) OOM-safe alloc + circuit breaker -----------------------------
|
||||
static bool IsOom(cudaError_t e) { return e == cudaErrorMemoryAllocation; }
|
||||
|
||||
// Open the breaker for a short cooldown after a (recoverable) OOM so all
|
||||
// callers back off together instead of repeatedly faulting the context.
|
||||
static void NoteOom() {
|
||||
s_breakerUntilMs.store(NowMs() + kCooldownMs, std::memory_order_relaxed);
|
||||
}
|
||||
static bool BreakerOpen() {
|
||||
return NowMs() < s_breakerUntilMs.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// Lightweight current-device VRAM query. Clears the non-fatal sticky error
|
||||
// that a failed query can leave on the context.
|
||||
static bool Query(size_t& freeB, size_t& totalB) {
|
||||
cudaError_t e = cudaMemGetInfo(&freeB, &totalB);
|
||||
cudaGetLastError();
|
||||
return e == cudaSuccess;
|
||||
}
|
||||
|
||||
private:
|
||||
static int64_t NowMs() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
// 0 = no override, use device-scaled margin.
|
||||
static size_t InitMarginOverride() {
|
||||
if (const char* e = std::getenv("ANSCENTER_GPU_MARGIN_MB")) {
|
||||
long mb = std::atol(e);
|
||||
if (mb > 0) return static_cast<size_t>(mb) * 1024ULL * 1024ULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static constexpr int64_t kCooldownMs = 1500; // breaker cooldown after OOM
|
||||
static constexpr size_t kMarginDivisor = 8; // margin = total/8 ...
|
||||
static constexpr size_t kMarginMin = 192ULL * 1024 * 1024; // ... clamped
|
||||
static constexpr size_t kMarginMax = 768ULL * 1024 * 1024; // (prev. fixed value)
|
||||
inline static std::atomic<size_t> s_marginOverride{ InitMarginOverride() };
|
||||
inline static std::atomic<int64_t> s_breakerUntilMs{ 0 };
|
||||
};
|
||||
|
||||
} // namespace ANSCENTER
|
||||
@@ -17,6 +17,24 @@
|
||||
#define FR_END_TIMER(name, label)
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
// Batch >1 only helps when several faces arrive in one frame, but the TRT
|
||||
// workspace grows ~linearly with maxBatchSize (~54 MiB per batch unit for
|
||||
// this model). The batch-4 profile was tuned for 8 GB GPUs; on smaller
|
||||
// cards (e.g. 4 GB RTX A400) that workspace crowds out the other engines
|
||||
// sharing the card. Below the 8 GB class, fall back to single-face
|
||||
// batches — results are identical, multi-face frames just run
|
||||
// sequentially. Threshold is 7.5 GiB because 8 GB cards report slightly
|
||||
// under 8192 MiB (~8188).
|
||||
int VramCappedBatch(int desiredBatch, int deviceIndex) {
|
||||
cudaDeviceProp prop{};
|
||||
if (cudaGetDeviceProperties(&prop, deviceIndex >= 0 ? deviceIndex : 0) != cudaSuccess)
|
||||
return desiredBatch; // can't query — keep the configured profile
|
||||
const size_t totalMiB = prop.totalGlobalMem / (1024ULL * 1024ULL);
|
||||
return (totalMiB >= 7680) ? desiredBatch : 1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ANSCENTER {
|
||||
std::string ANSFaceRecognizer::GetOpenVINODevice() {
|
||||
ov::Core core;
|
||||
@@ -97,8 +115,10 @@ namespace ANSCENTER {
|
||||
// comfortably on 8 GB GPUs while freeing ~1.5 GB VRAM vs max=32
|
||||
// — most scenes have ≤4 faces visible, so throughput cost is
|
||||
// near-zero (amortized per-face latency drops too at lower batch).
|
||||
m_options.optBatchSize = 4;
|
||||
m_options.maxBatchSize = 4;
|
||||
// VramCappedBatch drops this to 1 on sub-8 GB cards.
|
||||
const int frBatch = VramCappedBatch(4, _modelConfig.gpuDeviceIndex);
|
||||
m_options.optBatchSize = frBatch;
|
||||
m_options.maxBatchSize = frBatch;
|
||||
|
||||
m_options.maxInputHeight = GPU_FACE_HEIGHT;
|
||||
m_options.minInputHeight = GPU_FACE_HEIGHT;
|
||||
@@ -259,9 +279,10 @@ namespace ANSCENTER {
|
||||
// engine built/looked-up here has a different profile than the one
|
||||
// Initialize() expects, causing either a stale `.b32` rebuild every
|
||||
// launch (wasting 30-60s) or a load-time profile mismatch.
|
||||
// Keep in sync with lines 100-114.
|
||||
m_options.optBatchSize = 4;
|
||||
m_options.maxBatchSize = 4;
|
||||
// Keep in sync with the Initialize() block (same VramCappedBatch call).
|
||||
const int frBatch = VramCappedBatch(4, _modelConfig.gpuDeviceIndex);
|
||||
m_options.optBatchSize = frBatch;
|
||||
m_options.maxBatchSize = frBatch;
|
||||
|
||||
m_options.maxInputHeight = GPU_FACE_HEIGHT;
|
||||
m_options.minInputHeight = GPU_FACE_HEIGHT;
|
||||
@@ -490,8 +511,12 @@ namespace ANSCENTER {
|
||||
if (engineType == EngineType::NVIDIA_GPU) {
|
||||
// Initialize TensorRT engine via shared pool
|
||||
if (!m_trtEngine) {
|
||||
m_options.optBatchSize = 8;
|
||||
m_options.maxBatchSize = 32;
|
||||
// Note this path still uses the legacy 8/32 profile on 8 GB+
|
||||
// cards (a .b32 engine costs ~1.5 GB more workspace than .b4).
|
||||
// The VRAM cap only stops it from being fatal on small cards.
|
||||
const int frMaxBatch = VramCappedBatch(32, _modelConfig.gpuDeviceIndex);
|
||||
m_options.optBatchSize = (frMaxBatch < 8) ? frMaxBatch : 8;
|
||||
m_options.maxBatchSize = frMaxBatch;
|
||||
m_options.calibrationBatchSize = 8;
|
||||
m_options.deviceIndex = _modelConfig.gpuDeviceIndex;
|
||||
m_options.engineFileDir = _modelFolder;
|
||||
|
||||
@@ -162,7 +162,7 @@ bool PaddleOCRV5Engine::Initialize(const std::string& detModelPath,
|
||||
// Ensure this DLL's copy of Ort::Global<void>::api_ is initialized.
|
||||
// BasicOrtHandler sets it in ONNXEngine.dll, but each DLL has its own
|
||||
// inline-static copy. Without this, inference calls from ANSOCR.dll crash.
|
||||
if (Ort::Global<void>::api_ == nullptr) {
|
||||
if (Ort::detail::Global::Api() == nullptr) {
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
}
|
||||
|
||||
|
||||
@@ -761,6 +761,16 @@ namespace ANSCENTER
|
||||
float CosineSimilarity(const std::vector<float>& a, const std::vector<float>& b, bool normalized);
|
||||
};
|
||||
class ANSENGINE_API ANSODBase {
|
||||
public:
|
||||
// Explicit non-copy/non-move: _modelLoading (std::atomic) deletes the
|
||||
// implicit copy ops; spelling them out here gives ClangCL a clean
|
||||
// anchor and documents that subclasses are never copied/moved (they
|
||||
// are heap-allocated and passed by shared_ptr<...>).
|
||||
ANSODBase(const ANSODBase&) = delete;
|
||||
ANSODBase& operator=(const ANSODBase&) = delete;
|
||||
ANSODBase(ANSODBase&&) = delete;
|
||||
ANSODBase& operator=(ANSODBase&&) = delete;
|
||||
ANSODBase() = default;
|
||||
protected:
|
||||
bool _licenseValid{ false };
|
||||
bool _isInitialized{ false };
|
||||
@@ -1085,6 +1095,13 @@ namespace ANSCENTER
|
||||
std::vector<Object> RunInferenceInTrackingMode(const cv::Mat& input, const std::string& camera_id, std::vector<int> trackingObjectIds);// Get detected objects
|
||||
};
|
||||
class ANSENGINE_API ANSFDBase {
|
||||
public:
|
||||
// Explicit non-copy/non-move (see ANSODBase for rationale).
|
||||
ANSFDBase(const ANSFDBase&) = delete;
|
||||
ANSFDBase& operator=(const ANSFDBase&) = delete;
|
||||
ANSFDBase(ANSFDBase&&) = delete;
|
||||
ANSFDBase& operator=(ANSFDBase&&) = delete;
|
||||
ANSFDBase() = default;
|
||||
protected:
|
||||
bool _licenseValid{ false };
|
||||
bool _isInitialized{ false };
|
||||
|
||||
@@ -1316,7 +1316,7 @@ namespace ANSCENTER
|
||||
{
|
||||
try {
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(ANSCENTER::EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[ANSFDBase] EP ready: "<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace ANSCENTER
|
||||
inputImageShape_ = targetInputShape;
|
||||
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[ANSONNXCL] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -25,6 +25,13 @@ namespace ANSCENTER {
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
class ANSENGINE_API ANSONNXCL :public ANSODBase {
|
||||
public:
|
||||
// Explicit non-copy/non-move (see ANSONNXYOLO for dllexport rationale).
|
||||
ANSONNXCL(const ANSONNXCL&) = delete;
|
||||
ANSONNXCL& operator=(const ANSONNXCL&) = delete;
|
||||
ANSONNXCL(ANSONNXCL&&) = delete;
|
||||
ANSONNXCL& operator=(ANSONNXCL&&) = delete;
|
||||
ANSONNXCL() = default;
|
||||
|
||||
virtual bool Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) override;
|
||||
virtual bool LoadModel(const std::string& modelZipFilePath, const std::string& modelZipPassword)override;
|
||||
virtual bool LoadModelFromFolder(std::string licenseKey, ModelConfig modelConfig, std::string modelName, std::string className, const std::string& modelFolder, std::string& labelMap)override;
|
||||
|
||||
@@ -692,7 +692,7 @@ namespace ANSCENTER {
|
||||
deviceId_ = deviceId;
|
||||
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[ANSONNXOBB] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace ANSCENTER {
|
||||
deviceId_ = deviceId;
|
||||
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[ANSONNXPOSE] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -108,6 +108,13 @@ namespace ANSCENTER {
|
||||
// ====================================================================
|
||||
class ANSENGINE_API ANSONNXRTMPOSE : public ANSODBase {
|
||||
public:
|
||||
// Explicit non-copy/non-move (see ANSONNXYOLO for dllexport rationale).
|
||||
ANSONNXRTMPOSE(const ANSONNXRTMPOSE&) = delete;
|
||||
ANSONNXRTMPOSE& operator=(const ANSONNXRTMPOSE&) = delete;
|
||||
ANSONNXRTMPOSE(ANSONNXRTMPOSE&&) = delete;
|
||||
ANSONNXRTMPOSE& operator=(ANSONNXRTMPOSE&&) = delete;
|
||||
ANSONNXRTMPOSE() = default;
|
||||
|
||||
bool Initialize(std::string licenseKey, ModelConfig modelConfig,
|
||||
const std::string& modelZipFilePath,
|
||||
const std::string& modelZipPassword,
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace ANSCENTER
|
||||
}
|
||||
|
||||
try {
|
||||
m_engine = std::make_unique<ONNXSAM3>(modelFolder, EngineType::NVIDIA_GPU);
|
||||
m_engine = std::make_unique<class ONNXSAM3>(modelFolder, EngineType::NVIDIA_GPU);
|
||||
m_tokenLength = m_engine->getTokenLength();
|
||||
|
||||
_logger.LogDebug("ANSONNXSAM3::InitEngine",
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace ANSCENTER
|
||||
class ANSENGINE_API ANSONNXSAM3 : public ANSODBase
|
||||
{
|
||||
public:
|
||||
// Explicit non-copy/non-move (see ANSONNXYOLO for dllexport rationale).
|
||||
ANSONNXSAM3(const ANSONNXSAM3&) = delete;
|
||||
ANSONNXSAM3& operator=(const ANSONNXSAM3&) = delete;
|
||||
ANSONNXSAM3(ANSONNXSAM3&&) = delete;
|
||||
ANSONNXSAM3& operator=(ANSONNXSAM3&&) = delete;
|
||||
ANSONNXSAM3() = default;
|
||||
|
||||
virtual bool Initialize(std::string licenseKey, ModelConfig modelConfig,
|
||||
const std::string& modelZipFilePath, const std::string& modelZipPassword,
|
||||
std::string& labelMap) override;
|
||||
@@ -45,7 +52,10 @@ namespace ANSCENTER
|
||||
bool _fp16 = false;
|
||||
|
||||
// ONNX Runtime engine
|
||||
std::unique_ptr<ONNXSAM3> m_engine;
|
||||
// Elaborated `class ONNXSAM3` disambiguates from the
|
||||
// ANSCENTER::ModelType::ONNXSAM3 enumerator (ANSLicense.h) which
|
||||
// shares the same unqualified name in this namespace.
|
||||
std::unique_ptr<class ONNXSAM3> m_engine;
|
||||
|
||||
// Tokenizer (loaded from merges.txt)
|
||||
std::unique_ptr<ANSCLIPTokenizer> m_tokenizer;
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace ANSCENTER {
|
||||
deviceId_ = deviceId;
|
||||
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[ANSONNXSEG] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace ANSCENTER {
|
||||
// future ORT shape-mismatch failure (e.g. /model.12/Concat for
|
||||
// non-stride-32 inputs) points at the offending HxW directly.
|
||||
// One line per session — does not flood DebugView.
|
||||
static thread_local const ONNXYOLO* s_loggedFirst = nullptr;
|
||||
static thread_local const class ONNXYOLO* s_loggedFirst = nullptr;
|
||||
if (s_loggedFirst != this) {
|
||||
s_loggedFirst = this;
|
||||
ANS_DBG("ONNXYOLO",
|
||||
@@ -1680,7 +1680,7 @@ namespace ANSCENTER {
|
||||
"Model file does not exist: " + _modelFilePath, __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
m_ortEngine = std::make_shared<ONNXYOLO>(_modelFilePath);
|
||||
m_ortEngine = std::make_shared<class ONNXYOLO>(_modelFilePath);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
@@ -1696,7 +1696,7 @@ namespace ANSCENTER {
|
||||
"Model file does not exist: " + _modelFilePath, __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
m_ortEngine = std::make_shared<ONNXYOLO>(_modelFilePath, engineType);
|
||||
m_ortEngine = std::make_shared<class ONNXYOLO>(_modelFilePath, engineType);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
@@ -2244,7 +2244,7 @@ namespace ANSCENTER {
|
||||
int numKps;
|
||||
std::vector<std::string> classes;
|
||||
bool trackerEnabled, stabilizationEnabled;
|
||||
std::shared_ptr<ONNXYOLO> engine;
|
||||
std::shared_ptr<class ONNXYOLO> engine;
|
||||
{
|
||||
ANS_DBG("ONNXYOLO", "DetectObjects: cam=%s acquiring mutex...", camera_id.c_str());
|
||||
auto lk = TryLockWithTimeout("ANSONNXYOLO::DetectObjects");
|
||||
@@ -2446,7 +2446,7 @@ namespace ANSCENTER {
|
||||
int numKps;
|
||||
std::vector<std::string> classes;
|
||||
bool trackerEnabled, stabilizationEnabled;
|
||||
std::shared_ptr<ONNXYOLO> engine;
|
||||
std::shared_ptr<class ONNXYOLO> engine;
|
||||
{
|
||||
auto lk = TryLockWithTimeout("ANSONNXYOLO::DetectObjectsBatch");
|
||||
if (!lk.owns_lock()) return {};
|
||||
|
||||
@@ -205,6 +205,16 @@ namespace ANSCENTER {
|
||||
// ====================================================================
|
||||
class ANSENGINE_API ANSONNXYOLO : public ANSODBase {
|
||||
public:
|
||||
// Explicit non-copy/non-move. The class has atomic + shared_ptr members
|
||||
// that already implicitly delete these, but __declspec(dllexport)
|
||||
// makes ClangCL eagerly instantiate the implicit copy/move ctor
|
||||
// bodies; an explicit user-declared =delete short-circuits that.
|
||||
ANSONNXYOLO(const ANSONNXYOLO&) = delete;
|
||||
ANSONNXYOLO& operator=(const ANSONNXYOLO&) = delete;
|
||||
ANSONNXYOLO(ANSONNXYOLO&&) = delete;
|
||||
ANSONNXYOLO& operator=(ANSONNXYOLO&&) = delete;
|
||||
ANSONNXYOLO() = default;
|
||||
|
||||
bool Initialize(std::string licenseKey, ModelConfig modelConfig,
|
||||
const std::string& modelZipFilePath,
|
||||
const std::string& modelZipPassword,
|
||||
@@ -254,7 +264,10 @@ namespace ANSCENTER {
|
||||
// caught a DML E_FAIL and rebuilt the session — that was the
|
||||
// 0xc0000005 access violation observed in ANSODEngine.dll under
|
||||
// AMD/DirectML when multiple AI tasks ran in parallel.
|
||||
std::shared_ptr<ONNXYOLO> m_ortEngine;
|
||||
// Elaborated `class ONNXYOLO` disambiguates from the
|
||||
// ANSCENTER::ModelType::ONNXYOLO enumerator (ANSLicense.h) which
|
||||
// shares the same unqualified name in this namespace.
|
||||
std::shared_ptr<class ONNXYOLO> m_ortEngine;
|
||||
|
||||
// ────────────────────────────────────────────────────────────────
|
||||
// DML stay-on-GPU recovery state.
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace ANSCENTER {
|
||||
{
|
||||
try {
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[YOLO12OD] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace ANSCENTER
|
||||
{
|
||||
try {
|
||||
const auto& ep = ANSCENTER::EPLoader::Current();
|
||||
if (Ort::Global<void>::api_ == nullptr)
|
||||
if (Ort::detail::Global::Api() == nullptr)
|
||||
Ort::InitApi(static_cast<const OrtApi*>(EPLoader::GetOrtApiRaw()));
|
||||
std::cout << "[YOLOOD] EP ready: "
|
||||
<< ANSCENTER::EPLoader::EngineTypeName(ep.type) << std::endl;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ANSGpuFrameRegistry.h"
|
||||
#include "ANSEngineCommon.h"
|
||||
#include "ANSLicense.h" // ANS_DBG macro
|
||||
#include "GpuMemoryGuard.h"
|
||||
#include <opencv2/cudaimgproc.hpp>
|
||||
#include <opencv2/cudawarping.hpp>
|
||||
#include <opencv2/core/cuda_stream_accessor.hpp>
|
||||
@@ -168,6 +169,12 @@ namespace ANSCENTER {
|
||||
}
|
||||
|
||||
++m_cudaFailStreak;
|
||||
// (3) If this failure is a GPU OOM, open the process-wide circuit
|
||||
// breaker so every engine (FR/OD/OCR/LPR) backs off via UnderPressure()
|
||||
// before the streak reaches CUDA_FAIL_LIMIT and the context is lost.
|
||||
if (GpuMemoryGuard::IsOom(err) || GpuMemoryGuard::IsOom(pending)) {
|
||||
GpuMemoryGuard::NoteOom();
|
||||
}
|
||||
if (m_cudaFailStreak >= CUDA_FAIL_LIMIT && !m_cudaContextDead) {
|
||||
m_cudaContextDead = true;
|
||||
logger.LogFatal(std::string(tag) + "::NV12Helper",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ANSGpuFrameRegistry.h"
|
||||
#include "NV12PreprocessHelper.h" // tl_currentGpuFrame()
|
||||
#include "Utility.h"
|
||||
#include "GpuMemoryGuard.h"
|
||||
#include <chrono>
|
||||
//#define FNS_DEBUG
|
||||
namespace ANSCENTER {
|
||||
@@ -638,6 +639,17 @@ namespace ANSCENTER {
|
||||
// Phase 2: CUDA preprocessing + inference (mutex released — pool dispatches to idle GPU slot)
|
||||
std::vector<std::vector<cv::cuda::GpuMat>> inputs;
|
||||
bool usedNV12 = false;
|
||||
|
||||
// (2) Pressure guard: if free GPU VRAM is below the safety margin (or the
|
||||
// OOM circuit breaker is open), SKIP this frame's GPU work instead of
|
||||
// allocating and triggering an OOM that permanently poisons the context.
|
||||
if (ANSCENTER::GpuMemoryGuard::UnderPressure()) {
|
||||
this->_logger.LogWarn("ANSSCRFDFD::Detect",
|
||||
"GPU under memory pressure — skipping SCRFD frame to avoid OOM",
|
||||
__FILE__, __LINE__);
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
// Clear any sticky CUDA error from transient graph-capture failures
|
||||
cudaError_t priorErr = cudaGetLastError();
|
||||
@@ -706,6 +718,14 @@ namespace ANSCENTER {
|
||||
m_nv12Helper.tickInference();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
// (3) On a GPU OOM, open the circuit breaker so subsequent frames
|
||||
// back off (UnderPressure) instead of repeatedly faulting the
|
||||
// already-fragile CUDA context — that repetition is what corrupts it.
|
||||
const std::string msg = e.what();
|
||||
if (msg.find("out of memory") != std::string::npos ||
|
||||
msg.find("Gpu API call") != std::string::npos) {
|
||||
ANSCENTER::GpuMemoryGuard::NoteOom();
|
||||
}
|
||||
this->_logger.LogError(
|
||||
"ANSSCRFDFD::Detect",
|
||||
std::string("CUDA preprocessing failed: ") + e.what(),
|
||||
|
||||
@@ -240,7 +240,9 @@ public:
|
||||
void clearGpuBuffers();
|
||||
int getBindingIndexByName(const std::string& name);
|
||||
void UpdateOptions(const ANSCENTER::Options& options) { m_options = options; }
|
||||
void warmUp(int iterations = 5);
|
||||
// Returns false if any warmup inference failed — callers must treat the
|
||||
// engine as unusable (a slot that fails warmup must NOT join the pool).
|
||||
bool warmUp(int iterations = 5);
|
||||
void setVerbose(bool v) { m_verbose = v; }
|
||||
void setDisableGraphs(bool v) { m_disableGraphs = v; }
|
||||
|
||||
|
||||
@@ -168,6 +168,78 @@ namespace ANSCENTER
|
||||
return out.str();
|
||||
}
|
||||
|
||||
// ── Per-thread call status ───────────────────────────────────────────────
|
||||
// Written by every upload entry point, read by the C exports in dllmain so
|
||||
// the caller learns WHY a call failed (and therefore whether to retry)
|
||||
// without any change to the exported signatures. Thread-local because a
|
||||
// single ANSAWSS3 handle is routinely shared by many worker threads — a
|
||||
// per-instance field would report another worker's outcome.
|
||||
static thread_local int t_callStatus = ANSAWSS3::kCallPermanentError;
|
||||
|
||||
void ANSAWSS3::SetCallStatus(int status) { t_callStatus = status; }
|
||||
int ANSAWSS3::LastCallStatus() { return t_callStatus; }
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
// SummarizeChilkatRequestError: one line out of a request-level Chilkat log.
|
||||
//
|
||||
// The raw log is ~2 KB of call-stack scaffolding per failure. Written once
|
||||
// per retry, per worker, it buries the one thing an operator needs: what S3
|
||||
// actually said. S3 returns its reason as XML in the response body, which
|
||||
// Chilkat echoes into the log:
|
||||
// <Error><Code>NoSuchBucket</Code><Message>The specified bucket does
|
||||
// not exist</Message>...
|
||||
// Pull that out, prefix the status code, and drop the rest.
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
static std::string SummarizeChilkatRequestError(const char* raw, int statusCode) {
|
||||
std::ostringstream out;
|
||||
if (statusCode > 0) out << "HTTP " << statusCode;
|
||||
|
||||
auto tagValue = [](const std::string& s, const char* tag) -> std::string {
|
||||
const std::string open = std::string("<") + tag + ">";
|
||||
const std::string close = std::string("</") + tag + ">";
|
||||
const size_t a = s.find(open);
|
||||
if (a == std::string::npos) return {};
|
||||
const size_t b = s.find(close, a + open.size());
|
||||
if (b == std::string::npos) return {};
|
||||
return s.substr(a + open.size(), b - a - open.size());
|
||||
};
|
||||
|
||||
if (raw && *raw) {
|
||||
const std::string s(raw);
|
||||
const std::string code = tagValue(s, "Code");
|
||||
const std::string msg = tagValue(s, "Message");
|
||||
if (!code.empty()) {
|
||||
if (statusCode > 0) out << " ";
|
||||
out << code;
|
||||
if (!msg.empty()) out << ": " << msg;
|
||||
}
|
||||
else {
|
||||
// No S3 error document — fall back to the deepest concrete line
|
||||
// (same idea as SummarizeChilkatError, without the connect
|
||||
// specific fields).
|
||||
std::istringstream iss(s);
|
||||
std::string ln, leaf;
|
||||
while (std::getline(iss, ln)) {
|
||||
const size_t a = ln.find_first_not_of(" \t\r\n");
|
||||
if (a == std::string::npos) continue;
|
||||
const size_t b = ln.find_last_not_of(" \t\r\n");
|
||||
ln = ln.substr(a, b - a + 1);
|
||||
if (ln.rfind("--", 0) == 0) continue; // close marker
|
||||
if (!ln.empty() && ln.back() == ':') continue; // stack label
|
||||
if (ln == "Failed.") continue;
|
||||
leaf = ln;
|
||||
}
|
||||
if (!leaf.empty()) {
|
||||
if (statusCode > 0) out << " — ";
|
||||
out << leaf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string result = out.str();
|
||||
return result.empty() ? "(no detail in Chilkat log)" : result;
|
||||
}
|
||||
|
||||
// Private helper function to extract file name from a path
|
||||
// Helper function to extract filename from path
|
||||
std::string ANSAWSS3::ExtractFileName(const std::string& filePath) {
|
||||
@@ -302,12 +374,23 @@ namespace ANSCENTER
|
||||
return true;
|
||||
}
|
||||
|
||||
// Background connect loop, started by Connect() when the endpoint could not
|
||||
// be reached at all (return code 2).
|
||||
//
|
||||
// This loop NEVER gives up on its own. The caller — a LabVIEW VI, an
|
||||
// unattended AIBOX — calls Connect() exactly once at startup, so if this
|
||||
// thread returned while still unconnected the handle would stay dead for
|
||||
// the life of the process and every upload would fail instantly. Backoff
|
||||
// grows 3 s -> 30 s so a long outage costs little, and the loop only exits
|
||||
// once connected or when StopRetry() is called.
|
||||
void ANSAWSS3::RetryLoop() {
|
||||
int attempt = 0;
|
||||
int backoffSec = 3;
|
||||
constexpr int kMaxBackoffSec = 30;
|
||||
|
||||
while (!_stopRetry) {
|
||||
// Wait 3 seconds (in 1-second increments so we can respond to stop quickly)
|
||||
for (int i = 0; i < 3 && !_stopRetry; ++i) {
|
||||
// Sleep in 1-second increments so we can respond to stop quickly.
|
||||
for (int i = 0; i < backoffSec && !_stopRetry; ++i) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
if (_stopRetry) break;
|
||||
@@ -327,8 +410,12 @@ namespace ANSCENTER
|
||||
}
|
||||
if (!resolved) {
|
||||
_logger.LogDebug("ANSAWSS3::RetryLoop",
|
||||
"Retry #" + std::to_string(attempt) + " - no internet, retrying in 3s",
|
||||
"Retry #" + std::to_string(attempt) + " - no internet, retrying in " +
|
||||
std::to_string(backoffSec) + "s",
|
||||
__FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "RetryLoop #%d: DNS still failing, next try in %ds",
|
||||
attempt, backoffSec);
|
||||
backoffSec = (std::min)(kMaxBackoffSec, backoffSec * 2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -341,19 +428,24 @@ namespace ANSCENTER
|
||||
_logger.LogDebug("ANSAWSS3::RetryLoop",
|
||||
"Connected successfully after " + std::to_string(attempt) + " retries",
|
||||
__FILE__, __LINE__);
|
||||
_retryInProgress = false;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Internet is available but connection failed (bad auth/URL)
|
||||
// Stop retrying — no point, the parameters are wrong
|
||||
_logger.LogError("ANSAWSS3::RetryLoop",
|
||||
"Internet available but connection failed (check authentication or URL). Stopping retry.",
|
||||
__FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "RetryLoop: connected after %d attempt(s)", attempt);
|
||||
_retryInProgress = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// DNS resolves but the connection failed — bad credentials, wrong
|
||||
// URL, or the endpoint is refusing us. Keep trying anyway: the
|
||||
// caller has no other way back, and this state is often temporary
|
||||
// (endpoint rebooting, TLS interception clearing, clock skew being
|
||||
// corrected). Backoff keeps the cost negligible.
|
||||
_logger.LogError("ANSAWSS3::RetryLoop",
|
||||
"Retry #" + std::to_string(attempt) +
|
||||
" - endpoint resolves but connection failed (check authentication or URL). "
|
||||
"Retrying in " + std::to_string(backoffSec) + "s",
|
||||
__FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "RetryLoop #%d: connect failed, next try in %ds", attempt, backoffSec);
|
||||
backoffSec = (std::min)(kMaxBackoffSec, backoffSec * 2);
|
||||
}
|
||||
_retryInProgress = false;
|
||||
}
|
||||
@@ -366,9 +458,16 @@ namespace ANSCENTER
|
||||
std::unique_ptr<S3Connection> ANSAWSS3::CreateConnection(bool logOnFailure) {
|
||||
auto conn = std::make_unique<S3Connection>();
|
||||
|
||||
// Stamp the config generation this connection is built against so a
|
||||
// later Connect / SetAuthentication / SetServerProxy can invalidate it
|
||||
// even if it lands in the pool after that call cleared it.
|
||||
conn->configGen = _configGen.load();
|
||||
|
||||
// Apply request timeouts BEFORE Connect() so ConnectTimeoutMs takes
|
||||
// effect on this very handshake. IdleTimeoutMs is sticky and applies
|
||||
// to every subsequent request on this CkRest.
|
||||
// to every subsequent request on this CkRest. A brand-new connection
|
||||
// gets the FULL idle timeout — it is known-good, so it should be given
|
||||
// every chance to complete; only reuse gets the short leash.
|
||||
conn->rest.put_ConnectTimeoutMs(_connectTimeoutMs.load());
|
||||
conn->rest.put_IdleTimeoutMs(_idleTimeoutMs.load());
|
||||
|
||||
@@ -423,26 +522,82 @@ namespace ANSCENTER
|
||||
return conn;
|
||||
}
|
||||
|
||||
// Take a connection from the pool, skipping any that are stale (idle too
|
||||
// long) or built against superseded config. Falls through to a fresh
|
||||
// connection when nothing reusable is left.
|
||||
std::unique_ptr<S3Connection> ANSAWSS3::AcquireConnection() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
if (!_pool.empty()) {
|
||||
auto conn = std::move(_pool.back());
|
||||
const uint64_t gen = _configGen.load();
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
|
||||
for (;;) {
|
||||
std::unique_ptr<S3Connection> conn;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
if (_pool.empty()) break;
|
||||
conn = std::move(_pool.back());
|
||||
_pool.pop_back();
|
||||
return conn;
|
||||
}
|
||||
|
||||
if (conn->configGen != gen) {
|
||||
ANS_DBG("AWSS3", "Acquire: dropping pooled conn from older config gen %llu (now %llu)",
|
||||
(unsigned long long)conn->configGen, (unsigned long long)gen);
|
||||
DiscardConnection(std::move(conn)); // pool lock released first
|
||||
continue;
|
||||
}
|
||||
|
||||
const long long idleMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now - conn->lastUsed).count();
|
||||
if (idleMs > kMaxPooledIdleMs) {
|
||||
ANS_DBG("AWSS3", "Acquire: dropping pooled conn idle for %lldms (> %dms)",
|
||||
idleMs, kMaxPooledIdleMs);
|
||||
DiscardConnection(std::move(conn));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Clear per-request state left behind by whoever used this
|
||||
// connection last. Multipart uploads set uploadId / partNumber
|
||||
// query params; a plain PUT that inherited them would target the
|
||||
// wrong resource. Content-Encoding is set by UploadTextData only,
|
||||
// and a JPEG that inherited "gzip" would be stored with metadata
|
||||
// saying it is compressed — browsers would then fail to display it.
|
||||
// NOTE: do NOT call ClearAllHeaders here — it wipes Chilkat's SigV4
|
||||
// state (see commit fcc985e). Headers that every upload sets
|
||||
// explicitly (Content-Type, Expect) are overwritten by AddHeader
|
||||
// and need no clearing.
|
||||
conn->rest.ClearAllQueryParams();
|
||||
conn->rest.RemoveHeader("Content-Encoding");
|
||||
|
||||
// Short leash on reuse: if this socket died while idle, fail fast
|
||||
// and let the retry run on a fresh connection.
|
||||
conn->rest.put_IdleTimeoutMs(_reusedIdleTimeoutMs.load());
|
||||
return conn;
|
||||
}
|
||||
// Pool empty — create a new connection (no lock held during network I/O)
|
||||
|
||||
// Pool empty (or everything in it was stale) — create a new connection.
|
||||
std::lock_guard<std::mutex> cfgLk(_configMutex);
|
||||
return CreateConnection();
|
||||
}
|
||||
|
||||
void ANSAWSS3::ReleaseConnection(std::unique_ptr<S3Connection> conn) {
|
||||
if (!conn) return;
|
||||
// Mark as fresh and restore the full idle timeout; AcquireConnection
|
||||
// re-applies the short one when it hands the connection out again.
|
||||
conn->lastUsed = std::chrono::steady_clock::now();
|
||||
conn->rest.put_IdleTimeoutMs(_idleTimeoutMs.load());
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
_pool.push_back(std::move(conn));
|
||||
}
|
||||
|
||||
// Close a suspect connection instead of pooling it. Disconnect is given a
|
||||
// small budget only — the point is to release the socket, not to wait on a
|
||||
// peer that has already stopped answering.
|
||||
void ANSAWSS3::DiscardConnection(std::unique_ptr<S3Connection> conn) {
|
||||
if (!conn) return;
|
||||
conn->rest.Disconnect(100);
|
||||
ANS_DBG("AWSS3", "Discarded connection (not returned to pool)");
|
||||
// unique_ptr destructor tears the CkRest down here.
|
||||
}
|
||||
|
||||
// Pre-populate the pool with `count` ready-to-use connections. Each
|
||||
// connection performs a TLS handshake; doing `count` of them in parallel
|
||||
// (rather than serially as AcquireConnection would on a cold pool) cuts
|
||||
@@ -509,6 +664,16 @@ namespace ANSCENTER
|
||||
_connectTimeoutMs.store(connectMs);
|
||||
_idleTimeoutMs.store(idleMs);
|
||||
|
||||
// Reuse timeout scales with the configured idle timeout (a quarter of
|
||||
// it, clamped to a sane floor) so a deployment on a slow link that
|
||||
// raises idleMs does not end up with an over-aggressive leash on
|
||||
// pooled sockets.
|
||||
// Never longer than the configured idle timeout itself (idleMs can be
|
||||
// as low as 1000), and never so short that a healthy but busy server
|
||||
// gets cut off.
|
||||
const int reusedMs = (std::min)(idleMs, (std::max)(2000, idleMs / 4));
|
||||
_reusedIdleTimeoutMs.store(reusedMs);
|
||||
|
||||
// Propagate to existing pooled connections so already-warm workers
|
||||
// start using the new values on their next request.
|
||||
{
|
||||
@@ -522,16 +687,68 @@ namespace ANSCENTER
|
||||
}
|
||||
|
||||
_logger.LogDebug("ANSAWSS3::SetTimeouts",
|
||||
"connect=" + std::to_string(connectMs) + "ms, idle=" + std::to_string(idleMs) + "ms",
|
||||
"connect=" + std::to_string(connectMs) + "ms, idle=" + std::to_string(idleMs) +
|
||||
"ms, idle-on-reuse=" + std::to_string(reusedMs) + "ms",
|
||||
__FILE__, __LINE__);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shared precondition check for every upload entry point. The distinction
|
||||
// matters to the caller: a licence problem needs an operator, whereas "not
|
||||
// connected" clears itself once the background RetryLoop gets through — so
|
||||
// the two report different status codes.
|
||||
bool ANSAWSS3::CheckUploadPreconditions(const std::string& opName) {
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid) {
|
||||
_logger.LogError(opName,
|
||||
!_isLicenseValid ? "Invalid license" : "Invalid unlock code",
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError);
|
||||
return false;
|
||||
}
|
||||
if (!_bConnected) {
|
||||
const bool retrying = _retryInProgress.load();
|
||||
_logger.LogError(opName,
|
||||
retrying ? "Not connected (waiting for internet, retrying in background)"
|
||||
: "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "%s: not connected (background retry %s) — caller should retry later",
|
||||
opName.c_str(), retrying ? "active" : "inactive");
|
||||
SetCallStatus(kCallNotConnected);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// See the declaration comment in ANSUtilities.h for why a failed Chilkat
|
||||
// request is not automatically a network problem.
|
||||
ANSAWSS3::AttemptResult ANSAWSS3::ClassifyFailedRequest(
|
||||
std::unique_ptr<S3Connection> conn, std::string& lastError) {
|
||||
const int statusCode = conn ? conn->rest.get_ResponseStatusCode() : 0;
|
||||
lastError = SummarizeChilkatRequestError(
|
||||
conn ? conn->rest.lastErrorText() : nullptr, statusCode);
|
||||
|
||||
// The server answered, and its answer will not change on a retry:
|
||||
// wrong bucket, no permission, bad key. 408 and 429 are the exceptions
|
||||
// — those explicitly ask the client to try again.
|
||||
if (statusCode >= 400 && statusCode <= 499 &&
|
||||
statusCode != 408 && statusCode != 429) {
|
||||
ANS_DBG("AWSS3", "Request failed permanently: %s", lastError.c_str());
|
||||
ReleaseConnection(std::move(conn)); // the socket itself is fine
|
||||
return AttemptResult::Permanent;
|
||||
}
|
||||
|
||||
ANS_DBG("AWSS3", "Request failed transiently: %s", lastError.c_str());
|
||||
DiscardConnection(std::move(conn)); // suspect socket — do not pool
|
||||
return AttemptResult::Transient;
|
||||
}
|
||||
|
||||
// Drives a retry loop for a single upload operation. See the declaration
|
||||
// comment in ANSUtilities.h for the AttemptResult contract.
|
||||
//
|
||||
// Retry policy (shared across all upload entry points):
|
||||
// - kUploadMaxAttempts attempts total
|
||||
// - kUploadMaxAttempts attempts total, AND kUploadDeadlineMs wall-clock
|
||||
// (whichever comes first — the attempt count alone does not bound how
|
||||
// long the caller blocks, since one attempt can sit on a timeout)
|
||||
// - kUploadRetryDelayMs between attempts (no delay after the last one)
|
||||
// - std::exception thrown inside attemptFn is treated as Transient
|
||||
// - Any other exception is treated as Permanent (bail immediately)
|
||||
@@ -540,6 +757,11 @@ namespace ANSCENTER
|
||||
const std::function<AttemptResult(std::string& lastError)>& attemptFn) {
|
||||
|
||||
std::string lastError;
|
||||
const auto started = std::chrono::steady_clock::now();
|
||||
auto elapsedMs = [&started]() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - started).count();
|
||||
};
|
||||
|
||||
for (int attempt = 1; attempt <= kUploadMaxAttempts; ++attempt) {
|
||||
AttemptResult result = AttemptResult::Transient;
|
||||
@@ -556,6 +778,7 @@ namespace ANSCENTER
|
||||
}
|
||||
|
||||
if (result == AttemptResult::Success) {
|
||||
SetCallStatus(kCallSuccess);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -563,14 +786,29 @@ namespace ANSCENTER
|
||||
_logger.LogError(opName,
|
||||
"Permanent failure (no retry): " + lastError,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transient — retry if both budgets allow it.
|
||||
if (elapsedMs() >= kUploadDeadlineMs) {
|
||||
_logger.LogError(opName,
|
||||
"Upload gave up after " + std::to_string(attempt) + " attempt(s) / " +
|
||||
std::to_string(elapsedMs()) + "ms (deadline " +
|
||||
std::to_string(kUploadDeadlineMs) + "ms). Last error: " + lastError,
|
||||
__FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "%s: deadline exceeded after %d attempt(s), %lldms",
|
||||
opName.c_str(), attempt, elapsedMs());
|
||||
// Ran out of time on transient errors — the caller should retry.
|
||||
SetCallStatus(kCallTransientError);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transient — retry if attempts remain.
|
||||
if (attempt < kUploadMaxAttempts) {
|
||||
_logger.LogDebug(opName,
|
||||
"Attempt " + std::to_string(attempt) + "/" +
|
||||
std::to_string(kUploadMaxAttempts) + " failed: " + lastError +
|
||||
std::to_string(kUploadMaxAttempts) + " failed after " +
|
||||
std::to_string(elapsedMs()) + "ms: " + lastError +
|
||||
" — retrying in " + std::to_string(kUploadRetryDelayMs) + "ms",
|
||||
__FILE__, __LINE__);
|
||||
std::this_thread::sleep_for(
|
||||
@@ -580,8 +818,10 @@ namespace ANSCENTER
|
||||
|
||||
_logger.LogError(opName,
|
||||
"Upload failed after " + std::to_string(kUploadMaxAttempts) +
|
||||
" attempts. Last error: " + lastError,
|
||||
" attempts / " + std::to_string(elapsedMs()) + "ms. Last error: " + lastError,
|
||||
__FILE__, __LINE__);
|
||||
// Every attempt hit a transient error — worth retrying from the caller.
|
||||
SetCallStatus(kCallTransientError);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -652,7 +892,10 @@ namespace ANSCENTER
|
||||
// Simplified proxy validation logic
|
||||
_bProxy = !proxyHost.empty() && proxyPort > 0;
|
||||
|
||||
// Clear pool so new connections pick up proxy config
|
||||
// Clear pool so new connections pick up proxy config. Bumping the
|
||||
// generation also invalidates any connection still in flight
|
||||
// elsewhere, which would otherwise be pooled after this clear.
|
||||
_configGen.fetch_add(1);
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
_pool.clear();
|
||||
@@ -701,7 +944,9 @@ namespace ANSCENTER
|
||||
_bTls = bTls;
|
||||
_bAutoReconnect = autoReconnect;
|
||||
|
||||
// Clear pool so new connections use updated config
|
||||
// Clear pool so new connections use updated config (see the
|
||||
// generation note in SetServerProxy).
|
||||
_configGen.fetch_add(1);
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
_pool.clear();
|
||||
@@ -770,7 +1015,13 @@ namespace ANSCENTER
|
||||
_secretKey = secretKey;
|
||||
_authReady = true;
|
||||
|
||||
// Clear pool so new connections pick up new credentials.
|
||||
// Clear pool so new connections pick up new credentials. The
|
||||
// generation bump matters most here: the background RetryLoop
|
||||
// can complete a connect at any moment, and a connection it
|
||||
// built before _authReady was set carries no SigV4 state — if
|
||||
// it landed in the pool after this clear, every upload using it
|
||||
// would come back 403 (a permanent failure, so not retried).
|
||||
_configGen.fetch_add(1);
|
||||
std::lock_guard<std::mutex> lk(_poolMutex);
|
||||
_pool.clear();
|
||||
}
|
||||
@@ -809,7 +1060,7 @@ namespace ANSCENTER
|
||||
if (!conn->rest.FullRequestNoBodySb("GET", "/", sbResponse)) {
|
||||
_logger.LogError("ANSAWSS3::ListBuckets - Request failed",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -909,7 +1160,7 @@ namespace ANSCENTER
|
||||
if (!success) {
|
||||
_logger.LogError("ANSAWSS3::ListBucketObjects - Request failed on page " + std::to_string(pageCount),
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return objectList; // Return what we have so far
|
||||
}
|
||||
|
||||
@@ -1071,7 +1322,7 @@ namespace ANSCENTER
|
||||
if (!success) {
|
||||
_logger.LogError("ANSAWSS3::ListBucketObjectsWithPrefix - Request failed on page " + std::to_string(pageCount),
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return objectList; // Return what we have so far
|
||||
}
|
||||
|
||||
@@ -1227,7 +1478,7 @@ namespace ANSCENTER
|
||||
if (conn->rest.get_LastMethodSuccess() != true) {
|
||||
_logger.LogError("ANSAWSS3::CreateBucket - Request failed",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1314,7 +1565,7 @@ namespace ANSCENTER
|
||||
_logger.LogError("ANSAWSS3::DeleteBucket",
|
||||
"Failed to set AWS authentication: " + std::string(conn->rest.lastErrorText()),
|
||||
__FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1440,7 +1691,7 @@ namespace ANSCENTER
|
||||
if (conn->rest.get_LastMethodSuccess() != true) {
|
||||
_logger.LogError("ANSAWSS3::CreateFolder - Request failed",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1608,7 +1859,7 @@ namespace ANSCENTER
|
||||
if (conn->rest.get_LastMethodSuccess() != true) {
|
||||
_logger.LogError("ANSAWSS3::GetBucketRegion - Request failed",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1679,15 +1930,11 @@ namespace ANSCENTER
|
||||
// _logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || textFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1697,6 +1944,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Failed to extract filename from path: " + textFilePath,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
const std::string contentType = GetContentType(textFilePath);
|
||||
@@ -1740,9 +1988,7 @@ namespace ANSCENTER
|
||||
conn->rest.fullRequestString("PUT", objectPath.c_str(), fileContents);
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -1772,15 +2018,11 @@ namespace ANSCENTER
|
||||
// _logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || dataFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1789,6 +2031,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Failed to extract filename from path: " + dataFilePath,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
const std::string contentType = GetContentType(dataFilePath);
|
||||
@@ -1821,9 +2064,7 @@ namespace ANSCENTER
|
||||
|
||||
CkStringBuilder sbResponse;
|
||||
if (!conn->rest.FullRequestBd("PUT", objectPath.c_str(), binData, sbResponse)) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -1852,15 +2093,11 @@ namespace ANSCENTER
|
||||
//_logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || dataFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1872,6 +2109,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Failed to extract filename from path: " + dataFilePath,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1923,9 +2161,7 @@ namespace ANSCENTER
|
||||
|
||||
CkStringBuilder sbResponse;
|
||||
if (!conn->rest.FullRequestBd("PUT", objectPath.c_str(), binData, sbResponse)) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -1956,15 +2192,11 @@ namespace ANSCENTER
|
||||
//_logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || dataFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1994,9 +2226,7 @@ namespace ANSCENTER
|
||||
conn->rest.fullRequestStream("PUT", objectPath.c_str(), fileStream);
|
||||
|
||||
if (conn->rest.get_LastMethodSuccess() != true) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -2026,15 +2256,11 @@ namespace ANSCENTER
|
||||
//_logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || dataFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2042,6 +2268,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Part size must be at least 5MB (5242880 bytes)",
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2049,6 +2276,7 @@ namespace ANSCENTER
|
||||
CkFileAccess fac;
|
||||
if (!fac.FileExists(dataFilePath.c_str())) {
|
||||
_logger.LogError(kOp, "File not found: " + dataFilePath, __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2058,6 +2286,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Failed to extract filename from path: " + dataFilePath,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2106,9 +2335,8 @@ namespace ANSCENTER
|
||||
const char* responseXml = conn->rest.fullRequestNoBody("POST", objectPath.c_str());
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = std::string("Initiate failed: ") + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Initiate: " + lastError; return r; }
|
||||
}
|
||||
int initStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (initStatus != 200) {
|
||||
@@ -2160,9 +2388,8 @@ namespace ANSCENTER
|
||||
const char* responseStr = conn->rest.fullRequestStream("PUT", objectPath.c_str(), fileStream);
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = "Part " + std::to_string(partNumber) + " failed: " + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Part " + std::to_string(partNumber) + ": " + lastError; return r; }
|
||||
}
|
||||
int partStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (partStatus != 200) {
|
||||
@@ -2175,7 +2402,7 @@ namespace ANSCENTER
|
||||
const char* etag = conn->rest.responseHdrByName("ETag");
|
||||
if (!conn->rest.get_LastMethodSuccess() || etag == nullptr || etag[0] == '\0') {
|
||||
lastError = "Part " + std::to_string(partNumber) + ": ETag missing from response";
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return AttemptResult::Transient;
|
||||
}
|
||||
|
||||
@@ -2194,9 +2421,8 @@ namespace ANSCENTER
|
||||
responseXml = conn->rest.fullRequestString("POST", objectPath.c_str(), partsListXml.getXml());
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = std::string("Complete failed: ") + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Complete: " + lastError; return r; }
|
||||
}
|
||||
int completeStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (completeStatus != 200) {
|
||||
@@ -2227,15 +2453,11 @@ namespace ANSCENTER
|
||||
//_logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
|
||||
// Early validation (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || dataFilePath.empty()) {
|
||||
_logger.LogError(kOp, "Bucket name or file path is empty", __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2243,6 +2465,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Part size must be at least 5MB (5242880 bytes)",
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2250,6 +2473,7 @@ namespace ANSCENTER
|
||||
CkFileAccess fac;
|
||||
if (!fac.FileExists(dataFilePath.c_str())) {
|
||||
_logger.LogError(kOp, "File not found: " + dataFilePath, __FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2261,6 +2485,7 @@ namespace ANSCENTER
|
||||
_logger.LogError(kOp,
|
||||
"Failed to extract filename from path: " + dataFilePath,
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // bad input path — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2323,9 +2548,8 @@ namespace ANSCENTER
|
||||
const char* responseXml = conn->rest.fullRequestNoBody("POST", objectPath.c_str());
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = std::string("Initiate failed: ") + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Initiate: " + lastError; return r; }
|
||||
}
|
||||
int initStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (initStatus != 200) {
|
||||
@@ -2377,9 +2601,8 @@ namespace ANSCENTER
|
||||
const char* responseStr = conn->rest.fullRequestStream("PUT", objectPath.c_str(), fileStream);
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = "Part " + std::to_string(partNumber) + " failed: " + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Part " + std::to_string(partNumber) + ": " + lastError; return r; }
|
||||
}
|
||||
int partStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (partStatus != 200) {
|
||||
@@ -2392,7 +2615,7 @@ namespace ANSCENTER
|
||||
const char* etag = conn->rest.responseHdrByName("ETag");
|
||||
if (!conn->rest.get_LastMethodSuccess() || etag == nullptr || etag[0] == '\0') {
|
||||
lastError = "Part " + std::to_string(partNumber) + ": ETag missing from response";
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return AttemptResult::Transient;
|
||||
}
|
||||
|
||||
@@ -2410,9 +2633,8 @@ namespace ANSCENTER
|
||||
responseXml = conn->rest.fullRequestString("POST", objectPath.c_str(), partsListXml.getXml());
|
||||
|
||||
if (!conn->rest.get_LastMethodSuccess()) {
|
||||
lastError = std::string("Complete failed: ") + conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
{ AttemptResult r = ClassifyFailedRequest(std::move(conn), lastError);
|
||||
lastError = "Complete: " + lastError; return r; }
|
||||
}
|
||||
int completeStatus = conn->rest.get_ResponseStatusCode();
|
||||
if (completeStatus != 200) {
|
||||
@@ -2444,17 +2666,13 @@ namespace ANSCENTER
|
||||
const std::string kOp = "ANSAWSS3::UploadJpegImage";
|
||||
// _logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
// Early validation checks (permanent — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || bufferLength <= 0) {
|
||||
_logger.LogError(kOp,
|
||||
"Bucket name or buffer length is invalid",
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2486,9 +2704,7 @@ namespace ANSCENTER
|
||||
|
||||
CkStringBuilder sbResponse;
|
||||
if (!conn->rest.FullRequestBd("PUT", objectPath.c_str(), binData, sbResponse)) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -2516,17 +2732,13 @@ namespace ANSCENTER
|
||||
const std::string kOp = "ANSAWSS3::UploadPrefixJpegImage";
|
||||
//_logger.LogError(kOp,"Start Uploading...",__FILE__, __LINE__);
|
||||
// Early validation checks (permanent failures — do NOT retry)
|
||||
if (!_isLicenseValid || !_isUnlockCodeValid || !_bConnected) {
|
||||
_logger.LogError(kOp,
|
||||
!_isLicenseValid ? "Invalid license" : !_isUnlockCodeValid ? "Invalid unlock code" : _retryInProgress.load() ? "Not connected (waiting for internet, retrying in background)" : "Not connected (no internet or connection not established)",
|
||||
__FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
if (!CheckUploadPreconditions(kOp)) return false;
|
||||
|
||||
if (bucketName.empty() || bufferLength <= 0 || fileName.empty()) {
|
||||
_logger.LogError(kOp,
|
||||
"Bucket name, buffer length, or filename is invalid",
|
||||
__FILE__, __LINE__);
|
||||
SetCallStatus(kCallPermanentError); // caller bug — retrying cannot help
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2574,9 +2786,7 @@ namespace ANSCENTER
|
||||
|
||||
CkStringBuilder sbResponse;
|
||||
if (!conn->rest.FullRequestBd("PUT", objectPath.c_str(), binData, sbResponse)) {
|
||||
lastError = conn->rest.lastErrorText();
|
||||
ReleaseConnection(std::move(conn));
|
||||
return AttemptResult::Transient;
|
||||
return ClassifyFailedRequest(std::move(conn), lastError);
|
||||
}
|
||||
|
||||
int statusCode = conn->rest.get_ResponseStatusCode();
|
||||
@@ -2764,7 +2974,7 @@ namespace ANSCENTER
|
||||
if (!conn->rest.SendReqNoBody("GET", objectPath.c_str())) {
|
||||
_logger.LogError("ANSAWSS3::DownloadFile - Request failed",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2773,7 +2983,7 @@ namespace ANSCENTER
|
||||
if (responseStatusCode < 0) {
|
||||
_logger.LogError("ANSAWSS3::DownloadFile - Failed to read response header",
|
||||
conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
ReleaseConnection(std::move(conn));
|
||||
DiscardConnection(std::move(conn)); // transport failed — do not pool a suspect socket
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "ANSUtilities.h"
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <winevt.h> // EvtQuery / EvtRender for GetANSLoggerErrorEvents
|
||||
#pragma comment(lib, "wevtapi.lib")
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <CkFileAccess.h>
|
||||
@@ -1309,5 +1311,788 @@ namespace ANSCENTER
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// ====================================================================
|
||||
// GetANSLoggerErrorEvents / GetANSLoggerErrorEventsSinceLastCall
|
||||
//
|
||||
// Reads every Error-level event written by the "ANSLogger" source in
|
||||
// the Application channel using the modern winevt API. Events are
|
||||
// produced by WindowsEventSink in ANSLicensingSystem (see
|
||||
// ANSLicense.cpp::ReportEventW) — each carries a single inserted
|
||||
// string in <EventData><Data>...</Data></EventData>.
|
||||
//
|
||||
// DebugView: filter "[EVTLOG]".
|
||||
// ====================================================================
|
||||
|
||||
// ---- Watermark helpers (HKCU, no admin needed) ----------------------
|
||||
static constexpr const wchar_t* kWatermarkRegKey =
|
||||
L"Software\\ANSCENTER\\ANSUtilities\\EventLogWatermark";
|
||||
static constexpr const wchar_t* kWatermarkValueName = L"ANSLogger";
|
||||
|
||||
static uint64_t ReadAnsLoggerWatermark() {
|
||||
HKEY hKey = nullptr;
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER, kWatermarkRegKey, 0,
|
||||
KEY_READ, &hKey) != ERROR_SUCCESS) {
|
||||
return 0;
|
||||
}
|
||||
uint64_t value = 0;
|
||||
DWORD size = sizeof(value), type = 0;
|
||||
LONG rc = RegQueryValueExW(hKey, kWatermarkValueName, nullptr,
|
||||
&type, reinterpret_cast<LPBYTE>(&value),
|
||||
&size);
|
||||
RegCloseKey(hKey);
|
||||
return (rc == ERROR_SUCCESS && type == REG_QWORD) ? value : 0;
|
||||
}
|
||||
|
||||
static void WriteAnsLoggerWatermark(uint64_t value) {
|
||||
HKEY hKey = nullptr;
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER, kWatermarkRegKey, 0,
|
||||
nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE,
|
||||
nullptr, &hKey, nullptr) != ERROR_SUCCESS) {
|
||||
ANS_DBG("EVTLOG", "watermark RegCreateKey failed err=%lu",
|
||||
GetLastError());
|
||||
return;
|
||||
}
|
||||
LONG rc = RegSetValueExW(hKey, kWatermarkValueName, 0, REG_QWORD,
|
||||
reinterpret_cast<const BYTE*>(&value),
|
||||
sizeof(value));
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
ANS_DBG("EVTLOG", "watermark RegSetValue failed err=%ld", rc);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
// Extracts <EventRecordID>NNN</EventRecordID> from a rendered event XML.
|
||||
// Returns 0 if not present (shouldn't happen — every Windows event has one).
|
||||
static uint64_t ExtractRecordIdFromXml(const std::wstring& xml) {
|
||||
auto open = xml.find(L"<EventRecordID>");
|
||||
if (open == std::wstring::npos) return 0;
|
||||
open += 15; // length of "<EventRecordID>"
|
||||
auto close = xml.find(L"</EventRecordID>", open);
|
||||
if (close == std::wstring::npos) return 0;
|
||||
std::wstring numStr = xml.substr(open, close - open);
|
||||
return std::wcstoull(numStr.c_str(), nullptr, 10);
|
||||
}
|
||||
|
||||
// Returns the RecordID of the most recently written event in `channel`.
|
||||
// Used to detect channel clears: if our stored watermark > channelMax,
|
||||
// the channel was cleared and the new event counter restarted at 1, so
|
||||
// we must reset our watermark or risk skipping all new events.
|
||||
static uint64_t GetChannelMaxRecordId(const wchar_t* channel) {
|
||||
EVT_HANDLE hQuery = EvtQuery(nullptr, channel, nullptr,
|
||||
EvtQueryChannelPath | EvtQueryReverseDirection);
|
||||
if (!hQuery) return 0;
|
||||
|
||||
EVT_HANDLE hEvent = nullptr;
|
||||
DWORD returned = 0;
|
||||
uint64_t maxId = 0;
|
||||
if (EvtNext(hQuery, 1, &hEvent, 1000, 0, &returned) && returned > 0) {
|
||||
std::vector<wchar_t> buf(4096);
|
||||
DWORD used = 0, propCount = 0;
|
||||
BOOL ok = EvtRender(nullptr, hEvent, EvtRenderEventXml,
|
||||
static_cast<DWORD>(buf.size() * sizeof(wchar_t)),
|
||||
buf.data(), &used, &propCount);
|
||||
if (!ok && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
buf.resize(used / sizeof(wchar_t) + 1);
|
||||
ok = EvtRender(nullptr, hEvent, EvtRenderEventXml,
|
||||
static_cast<DWORD>(buf.size() * sizeof(wchar_t)),
|
||||
buf.data(), &used, &propCount);
|
||||
}
|
||||
if (ok) maxId = ExtractRecordIdFromXml(std::wstring(buf.data()));
|
||||
EvtClose(hEvent);
|
||||
}
|
||||
EvtClose(hQuery);
|
||||
return maxId;
|
||||
}
|
||||
|
||||
// ---- Shared implementation -----------------------------------------
|
||||
// Runs `query` against the Application channel, formats events as
|
||||
// "<DD/MM/YYYY h:mm:ss tt>: <event data>\n"
|
||||
// and optionally clears the channel afterwards. If trackWatermark is
|
||||
// true, also persists the highest EventRecordID seen to HKCU on return.
|
||||
static std::string ReadAnsLoggerEventsImpl(const wchar_t* query,
|
||||
bool clearAfterRead,
|
||||
bool trackWatermark)
|
||||
{
|
||||
EVT_HANDLE hResults = EvtQuery(nullptr, L"Application", query,
|
||||
EvtQueryChannelPath | EvtQueryForwardDirection);
|
||||
if (!hResults) {
|
||||
ANS_DBG("EVTLOG", "EvtQuery failed err=%lu", GetLastError());
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string out;
|
||||
uint64_t highestRecordId = 0;
|
||||
constexpr DWORD kBatch = 64;
|
||||
EVT_HANDLE events[kBatch];
|
||||
DWORD returned = 0;
|
||||
|
||||
// Render-buffer reused across events to avoid per-event allocation.
|
||||
std::vector<wchar_t> buf(8192);
|
||||
|
||||
while (EvtNext(hResults, kBatch, events, INFINITE, 0, &returned)) {
|
||||
for (DWORD i = 0; i < returned; ++i) {
|
||||
DWORD used = 0, propCount = 0;
|
||||
if (!EvtRender(nullptr, events[i], EvtRenderEventXml,
|
||||
static_cast<DWORD>(buf.size() * sizeof(wchar_t)),
|
||||
buf.data(), &used, &propCount)) {
|
||||
DWORD lastErr = GetLastError();
|
||||
if (lastErr == ERROR_INSUFFICIENT_BUFFER) {
|
||||
buf.resize(used / sizeof(wchar_t) + 1);
|
||||
if (!EvtRender(nullptr, events[i], EvtRenderEventXml,
|
||||
static_cast<DWORD>(buf.size() * sizeof(wchar_t)),
|
||||
buf.data(), &used, &propCount)) {
|
||||
EvtClose(events[i]);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
ANS_DBG("EVTLOG", "EvtRender failed err=%lu", lastErr);
|
||||
EvtClose(events[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
std::wstring xml(buf.data());
|
||||
|
||||
// Track the highest RecordID we've seen this call so we can
|
||||
// persist it as the new watermark on exit. Done before the
|
||||
// continue-on-malformed-XML paths below so an unrenderable
|
||||
// event still advances the watermark.
|
||||
if (trackWatermark) {
|
||||
uint64_t rid = ExtractRecordIdFromXml(xml);
|
||||
if (rid > highestRecordId) highestRecordId = rid;
|
||||
}
|
||||
|
||||
// ---- TimeCreated SystemTime='2026-05-18T11:52:07.123Z' ----
|
||||
// EvtRender produces either single- or double-quoted attrs
|
||||
// depending on Windows version, so handle both.
|
||||
std::string formattedTime;
|
||||
auto tcPos = xml.find(L"TimeCreated SystemTime=");
|
||||
if (tcPos != std::wstring::npos) {
|
||||
tcPos += 23; // length of "TimeCreated SystemTime="
|
||||
if (tcPos < xml.size() &&
|
||||
(xml[tcPos] == L'"' || xml[tcPos] == L'\'')) {
|
||||
wchar_t quote = xml[tcPos];
|
||||
++tcPos;
|
||||
auto endQuote = xml.find(quote, tcPos);
|
||||
if (endQuote != std::wstring::npos) {
|
||||
std::wstring iso = xml.substr(tcPos, endQuote - tcPos);
|
||||
int Y = 0, M = 0, D = 0, h = 0, m = 0, s = 0;
|
||||
if (swscanf_s(iso.c_str(), L"%d-%d-%dT%d:%d:%d",
|
||||
&Y, &M, &D, &h, &m, &s) == 6) {
|
||||
SYSTEMTIME utc{};
|
||||
utc.wYear = (WORD)Y; utc.wMonth = (WORD)M; utc.wDay = (WORD)D;
|
||||
utc.wHour = (WORD)h; utc.wMinute = (WORD)m; utc.wSecond = (WORD)s;
|
||||
SYSTEMTIME local{};
|
||||
if (!SystemTimeToTzSpecificLocalTime(nullptr, &utc, &local)) {
|
||||
local = utc; // fallback: show UTC
|
||||
}
|
||||
wchar_t dateBuf[64] = {}, timeBuf[64] = {};
|
||||
GetDateFormatW(LOCALE_USER_DEFAULT, 0, &local, nullptr,
|
||||
dateBuf, _countof(dateBuf));
|
||||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &local, nullptr,
|
||||
timeBuf, _countof(timeBuf));
|
||||
std::wstring combined = std::wstring(dateBuf) + L" " + timeBuf;
|
||||
int need = WideCharToMultiByte(CP_UTF8, 0,
|
||||
combined.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (need > 1) {
|
||||
formattedTime.resize(need - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, combined.c_str(), -1,
|
||||
formattedTime.data(), need, nullptr, nullptr);
|
||||
}
|
||||
} // close: if (swscanf_s ... == 6)
|
||||
} // close: if (endQuote != npos)
|
||||
} // close: if (xml[tcPos] is quote)
|
||||
} // close: if (tcPos != npos)
|
||||
|
||||
// ---- Concatenate every <Data>...</Data> inside <EventData> ----
|
||||
// ReportEventW with N strings produces N consecutive <Data>
|
||||
// elements. ANSLogger sends just one but we handle the general
|
||||
// case so the function works for other sources too.
|
||||
std::wstring wdata;
|
||||
auto edStart = xml.find(L"<EventData");
|
||||
auto edEnd = xml.find(L"</EventData>", edStart);
|
||||
if (edStart != std::wstring::npos && edEnd != std::wstring::npos) {
|
||||
auto bodyEnd = edEnd;
|
||||
auto cursor = edStart;
|
||||
while (cursor < bodyEnd) {
|
||||
auto dOpen = xml.find(L"<Data", cursor);
|
||||
if (dOpen == std::wstring::npos || dOpen >= bodyEnd) break;
|
||||
auto dGt = xml.find(L'>', dOpen);
|
||||
if (dGt == std::wstring::npos || dGt >= bodyEnd) break;
|
||||
auto dClose = xml.find(L"</Data>", dGt);
|
||||
if (dClose == std::wstring::npos || dClose > bodyEnd) break;
|
||||
if (!wdata.empty()) wdata += L' ';
|
||||
wdata.append(xml, dGt + 1, dClose - dGt - 1);
|
||||
cursor = dClose + sizeof("</Data>") - 1;
|
||||
}
|
||||
}
|
||||
std::string utf8Data;
|
||||
if (!wdata.empty()) {
|
||||
int need = WideCharToMultiByte(CP_UTF8, 0, wdata.c_str(), -1,
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
if (need > 1) {
|
||||
utf8Data.resize(need - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wdata.c_str(), -1,
|
||||
utf8Data.data(), need, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Flatten embedded CR/LF in the message body so the
|
||||
// "one line per event" contract holds. ChilkatLog and
|
||||
// similar multi-line payloads otherwise break callers
|
||||
// that split on '\n'.
|
||||
for (char& c : utf8Data) if (c == '\r' || c == '\n') c = ' ';
|
||||
|
||||
out += formattedTime;
|
||||
out += ": ";
|
||||
out += utf8Data;
|
||||
out += '\n';
|
||||
|
||||
EvtClose(events[i]);
|
||||
}
|
||||
}
|
||||
DWORD lastErr = GetLastError();
|
||||
if (lastErr != ERROR_NO_MORE_ITEMS) {
|
||||
ANS_DBG("EVTLOG", "EvtNext stopped err=%lu", lastErr);
|
||||
}
|
||||
EvtClose(hResults);
|
||||
|
||||
// Persist watermark BEFORE clearing — once EvtClearLog succeeds,
|
||||
// future events restart at RecordID 1, and we'd never see them
|
||||
// again if the watermark stayed at e.g. 547.
|
||||
// Special case: if clear is also going to succeed, the new
|
||||
// watermark is irrelevant (we'll reset on next call via the
|
||||
// GetChannelMaxRecordId check), so writing it here is harmless.
|
||||
if (trackWatermark && highestRecordId > 0) {
|
||||
WriteAnsLoggerWatermark(highestRecordId);
|
||||
ANS_DBG("EVTLOG", "watermark updated to %llu", highestRecordId);
|
||||
}
|
||||
|
||||
if (clearAfterRead) {
|
||||
// Clears the entire Application channel — see header warning.
|
||||
// DIAGNOSTIC: also print to stderr so callers without DebugView
|
||||
// can see what's going on. Common failure codes:
|
||||
// 5 ERROR_ACCESS_DENIED — process is not elevated
|
||||
// 1314 ERROR_PRIVILEGE_NOT_HELD — token missing SeSecurityPriv
|
||||
// 87 ERROR_INVALID_PARAMETER — channel name wrong
|
||||
if (!EvtClearLog(nullptr, L"Application", nullptr, 0)) {
|
||||
DWORD e = GetLastError();
|
||||
ANS_DBG("EVTLOG", "EvtClearLog failed err=%lu (need admin)", e);
|
||||
std::fprintf(stderr,
|
||||
"[ANSUtilities] EvtClearLog(Application) FAILED, "
|
||||
"GetLastError=%lu (5=AccessDenied, 1314=PrivNotHeld)\n", e);
|
||||
} else {
|
||||
ANS_DBG("EVTLOG", "EvtClearLog: Application channel cleared");
|
||||
std::fprintf(stderr,
|
||||
"[ANSUtilities] EvtClearLog(Application) OK\n");
|
||||
// Clear succeeded → counter resets to 1, so our watermark
|
||||
// is stale. Reset it now so the next call doesn't skip
|
||||
// legitimate new events whose RecordID < old watermark.
|
||||
if (trackWatermark) {
|
||||
WriteAnsLoggerWatermark(0);
|
||||
ANS_DBG("EVTLOG", "watermark reset to 0 after clear");
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---- Public: full read, no skip ------------------------------------
|
||||
std::string ANSUtilities::GetANSLoggerErrorEvents(bool clearAfterRead) {
|
||||
// XPath: Provider name "ANSLogger" AND Level 2 (EVENTLOG_ERROR_TYPE).
|
||||
// Forward direction keeps chronological insertion order so output
|
||||
// matches a fresh "oldest first" scroll through Event Viewer.
|
||||
return ReadAnsLoggerEventsImpl(
|
||||
L"*[System[Provider[@Name='ANSLogger'] and Level=2]]",
|
||||
clearAfterRead,
|
||||
/*trackWatermark=*/false);
|
||||
}
|
||||
|
||||
// ---- Public: incremental read using HKCU watermark -----------------
|
||||
std::string ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(bool clearAfterRead) {
|
||||
uint64_t watermark = ReadAnsLoggerWatermark();
|
||||
|
||||
// Channel-clear detection: if the channel's current max RecordID
|
||||
// is lower than our stored watermark, the log was cleared (by us
|
||||
// or by something else like Event Viewer's "Clear Log") and the
|
||||
// counter restarted at 1. Reset the watermark so we don't skip
|
||||
// events 1..watermark that are actually fresh.
|
||||
uint64_t channelMax = GetChannelMaxRecordId(L"Application");
|
||||
if (channelMax > 0 && watermark > channelMax) {
|
||||
ANS_DBG("EVTLOG", "watermark reset: stored=%llu channelMax=%llu "
|
||||
"(channel was cleared externally)",
|
||||
watermark, channelMax);
|
||||
watermark = 0;
|
||||
WriteAnsLoggerWatermark(0);
|
||||
}
|
||||
|
||||
// Embed the watermark in the XPath so Windows does the filtering;
|
||||
// we never see events <= watermark, which is more efficient than
|
||||
// post-filtering thousands of events on the client side.
|
||||
wchar_t queryBuf[256];
|
||||
swprintf_s(queryBuf, _countof(queryBuf),
|
||||
L"*[System[Provider[@Name='ANSLogger'] and Level=2 and "
|
||||
L"(EventRecordID>%llu)]]",
|
||||
watermark);
|
||||
ANS_DBG("EVTLOG", "GetANSLoggerErrorEventsSinceLastCall watermark=%llu",
|
||||
watermark);
|
||||
return ReadAnsLoggerEventsImpl(queryBuf, clearAfterRead,
|
||||
/*trackWatermark=*/true);
|
||||
}
|
||||
|
||||
} // namespace ANSCENTER
|
||||
|
||||
// ============================================================================
|
||||
// ScanDevices — AIBOX / ANSVIS discovery on the local LAN
|
||||
//
|
||||
// Port of the AIBOX Flutter app's MulticastService
|
||||
// (lib/src/core/network/multicast/multicast_service.dart). AIBOX boxes and
|
||||
// ANSVIS servers answer the same UDP probe and the same /ServerApi HTTP
|
||||
// endpoint, so one scan finds both. DebugView: filter "[ANSDISC]".
|
||||
//
|
||||
// Wire protocol:
|
||||
// UDP: probe text "Hello, Multicast" -> 230.50.200.150:58839 and subnet
|
||||
// broadcast :58839. Devices reply to UDP/58838 with
|
||||
// "<a>:<b>:<deviceName>:<firmware>".
|
||||
// HTTP: GET http://<ip>/ServerApi -> 200 + JSON with
|
||||
// {"OK": true, "Version": "<firmware>"}.
|
||||
//
|
||||
// Implementation: a UDP listener thread + a periodic UDP sender + a 64-way
|
||||
// HTTP sweep populate one mutex-guarded map. After `timeoutMs` the map is
|
||||
// converted to a deduplicated vector and returned.
|
||||
// ============================================================================
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <winhttp.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <queue>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
namespace {
|
||||
|
||||
// ---- Protocol constants (mirror AIBOX MulticastService) -----------------
|
||||
constexpr const char* kMulticastGroup = "230.50.200.150";
|
||||
constexpr unsigned short kProbePort = 58839; // device listens here
|
||||
constexpr unsigned short kListenPort = 58838; // we listen here
|
||||
constexpr const char* kProbeMessage = "Hello, Multicast";
|
||||
constexpr int kMulticastTtl = 225;
|
||||
constexpr int kHttpConcurrency = 64;
|
||||
constexpr int kHttpConnectTimeoutMs = 700;
|
||||
constexpr int kHttpProbeTimeoutMs = 2500;
|
||||
constexpr int kUdpProbeIntervalMs = 2000;
|
||||
constexpr const wchar_t* kHttpUserAgent = L"ANSUtilities-Scan/1.0";
|
||||
constexpr const wchar_t* kHttpPath = L"/ServerApi";
|
||||
|
||||
// HTTP ports answered by AIBOX boxes / ANSVIS servers. AIBOX listens on the
|
||||
// default HTTP port; the ANSVIS LabVIEW web server (App_serverConfig.httpPort
|
||||
// in ANSVIS.lvproj) listens on 22211. Each host gets probed on both ports.
|
||||
constexpr unsigned short kPortAibox = 80;
|
||||
constexpr unsigned short kPortAnsvis = 22211;
|
||||
constexpr unsigned short kSweepPorts[] = { kPortAibox, kPortAnsvis };
|
||||
|
||||
// ---- Winsock init (refcounted; safe to call repeatedly) -----------------
|
||||
struct WsaScope {
|
||||
bool ok{false};
|
||||
WsaScope() {
|
||||
WSADATA d{};
|
||||
ok = (WSAStartup(MAKEWORD(2, 2), &d) == 0);
|
||||
}
|
||||
~WsaScope() { if (ok) WSACleanup(); }
|
||||
WsaScope(const WsaScope&) = delete;
|
||||
WsaScope& operator=(const WsaScope&) = delete;
|
||||
};
|
||||
|
||||
// ---- Local IPv4 interfaces ----------------------------------------------
|
||||
struct LocalSubnet {
|
||||
std::string prefix; // "192.168.1." (final dot included)
|
||||
in_addr localAddr{};
|
||||
in_addr broadcast{};
|
||||
};
|
||||
|
||||
std::vector<LocalSubnet> EnumerateLocalSubnets() {
|
||||
std::vector<LocalSubnet> out;
|
||||
ULONG bufLen = 16 * 1024;
|
||||
std::vector<char> buf(bufLen);
|
||||
DWORD rc = GetAdaptersAddresses(AF_INET,
|
||||
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER,
|
||||
nullptr, reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buf.data()), &bufLen);
|
||||
if (rc == ERROR_BUFFER_OVERFLOW) {
|
||||
buf.resize(bufLen);
|
||||
rc = GetAdaptersAddresses(AF_INET,
|
||||
GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER,
|
||||
nullptr, reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buf.data()), &bufLen);
|
||||
}
|
||||
if (rc != NO_ERROR) {
|
||||
ANS_DBG("ANSDISC", "GetAdaptersAddresses failed rc=%lu", static_cast<unsigned long>(rc));
|
||||
return out;
|
||||
}
|
||||
auto* adapter = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buf.data());
|
||||
for (; adapter; adapter = adapter->Next) {
|
||||
if (adapter->OperStatus != IfOperStatusUp) continue;
|
||||
if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
|
||||
for (auto* ua = adapter->FirstUnicastAddress; ua; ua = ua->Next) {
|
||||
if (!ua->Address.lpSockaddr || ua->Address.lpSockaddr->sa_family != AF_INET) continue;
|
||||
auto* sin = reinterpret_cast<sockaddr_in*>(ua->Address.lpSockaddr);
|
||||
// Skip APIPA 169.254.x.x — multicast on link-local rarely useful.
|
||||
unsigned char b0 = reinterpret_cast<unsigned char*>(&sin->sin_addr)[0];
|
||||
unsigned char b1 = reinterpret_cast<unsigned char*>(&sin->sin_addr)[1];
|
||||
if (b0 == 169 && b1 == 254) continue;
|
||||
if (b0 == 127) continue;
|
||||
|
||||
char ipStr[INET_ADDRSTRLEN] = {};
|
||||
inet_ntop(AF_INET, &sin->sin_addr, ipStr, sizeof(ipStr));
|
||||
std::string s(ipStr);
|
||||
auto lastDot = s.find_last_of('.');
|
||||
if (lastDot == std::string::npos) continue;
|
||||
|
||||
LocalSubnet net;
|
||||
net.prefix = s.substr(0, lastDot + 1);
|
||||
net.localAddr = sin->sin_addr;
|
||||
inet_pton(AF_INET, (net.prefix + "255").c_str(), &net.broadcast);
|
||||
out.push_back(net);
|
||||
ANS_DBG("ANSDISC", "iface ip=%s subnet=%s/24", ipStr, net.prefix.c_str());
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---- Parse "<a>:<b>:<name>:<firmware>" reply ----------------------------
|
||||
// parts[0] and parts[1] are not used by the AIBOX Flutter app but the device
|
||||
// still sends them. Observed devices put their listen port in one of those
|
||||
// two fields, so we try both — first numeric wins. Unparseable -> port = 0.
|
||||
void ParseUdpReply(const std::string& body, std::string& name,
|
||||
std::string& firmware, int& port) {
|
||||
std::vector<std::string> parts;
|
||||
size_t start = 0;
|
||||
for (size_t i = 0; i <= body.size(); ++i) {
|
||||
if (i == body.size() || body[i] == ':') {
|
||||
parts.emplace_back(body.data() + start, i - start);
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
if (parts.size() > 3) { name = parts[2]; firmware = parts[3]; }
|
||||
else { name = "Unknown"; firmware = "-"; }
|
||||
|
||||
port = 0;
|
||||
auto tryPort = [&](const std::string& s) {
|
||||
if (port != 0 || s.empty() || s.size() > 5) return;
|
||||
for (char c : s) if (c < '0' || c > '9') return;
|
||||
int v = std::atoi(s.c_str());
|
||||
if (v > 0 && v < 65536) port = v;
|
||||
};
|
||||
if (parts.size() > 0) tryPort(parts[0]);
|
||||
if (parts.size() > 1) tryPort(parts[1]);
|
||||
}
|
||||
|
||||
// ---- Parse {"OK":true,"Version":"x"} ------------------------------------
|
||||
// Tiny scan rather than a JSON dependency. Looks for the two keys with any
|
||||
// amount of whitespace; rejects anything that doesn't say "OK":true.
|
||||
bool ParseServerApiJson(const std::string& body, std::string& version) {
|
||||
auto pos = body.find("\"OK\"");
|
||||
if (pos == std::string::npos) return false;
|
||||
pos = body.find(':', pos);
|
||||
if (pos == std::string::npos) return false;
|
||||
++pos;
|
||||
while (pos < body.size() && (body[pos] == ' ' || body[pos] == '\t')) ++pos;
|
||||
if (body.compare(pos, 4, "true") != 0) return false;
|
||||
|
||||
version.clear();
|
||||
pos = body.find("\"Version\"");
|
||||
if (pos == std::string::npos) { version = "-"; return true; }
|
||||
pos = body.find(':', pos);
|
||||
if (pos == std::string::npos) { version = "-"; return true; }
|
||||
pos = body.find('"', pos);
|
||||
if (pos == std::string::npos) { version = "-"; return true; }
|
||||
++pos;
|
||||
auto end = body.find('"', pos);
|
||||
if (end == std::string::npos) { version = "-"; return true; }
|
||||
version = body.substr(pos, end - pos);
|
||||
if (version.empty()) version = "-";
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- Shared scan state --------------------------------------------------
|
||||
enum SourceMask { kSrcMulticast = 1, kSrcSweep = 2 };
|
||||
|
||||
struct ScanState {
|
||||
std::mutex mu;
|
||||
std::unordered_map<std::string, ANSCENTER::ANSDeviceInfo> found;
|
||||
std::atomic<bool> stop{false};
|
||||
|
||||
void merge(const std::string& ip, const std::string& name,
|
||||
const std::string& firmware, int port, int srcBit) {
|
||||
std::lock_guard<std::mutex> lk(mu);
|
||||
auto& d = found[ip];
|
||||
if (d.ip.empty()) d.ip = ip;
|
||||
// Prefer non-empty / non-"-" values, regardless of which source ran first.
|
||||
if (!name.empty() && d.name.empty()) d.name = name;
|
||||
if (!firmware.empty() && firmware != "-" &&
|
||||
(d.firmware.empty() || d.firmware == "-")) d.firmware = firmware;
|
||||
else if (!firmware.empty() && d.firmware.empty()) d.firmware = firmware;
|
||||
// Port precedence: an HTTP probe proves the port actually responds,
|
||||
// so a sweep-supplied port overwrites whatever UDP parsing guessed.
|
||||
// A UDP-supplied port is only kept if HTTP hasn't filled it in.
|
||||
if (port > 0) {
|
||||
const bool fromHttp = (srcBit == kSrcSweep);
|
||||
const bool fromHttpAlready = (d.source & kSrcSweep) != 0;
|
||||
if (fromHttp || !fromHttpAlready) d.port = port;
|
||||
}
|
||||
d.source |= srcBit;
|
||||
}
|
||||
};
|
||||
|
||||
// ---- UDP listener thread -------------------------------------------------
|
||||
// Single socket bound to 0.0.0.0:58838, joined to 230.50.200.150 on every
|
||||
// local interface. Reads with a short timeout so it can poll `stop`.
|
||||
void RunUdpListener(ScanState& state, const std::vector<LocalSubnet>& subnets) {
|
||||
SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s == INVALID_SOCKET) {
|
||||
ANS_DBG("ANSDISC", "UDP socket() failed err=%d", WSAGetLastError());
|
||||
return;
|
||||
}
|
||||
BOOL on = TRUE;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&on), sizeof(on));
|
||||
setsockopt(s, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&on), sizeof(on));
|
||||
|
||||
sockaddr_in bindAddr{};
|
||||
bindAddr.sin_family = AF_INET;
|
||||
bindAddr.sin_port = htons(kListenPort);
|
||||
bindAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (bind(s, reinterpret_cast<sockaddr*>(&bindAddr), sizeof(bindAddr)) != 0) {
|
||||
ANS_DBG("ANSDISC", "UDP bind :%u failed err=%d", kListenPort, WSAGetLastError());
|
||||
closesocket(s);
|
||||
return;
|
||||
}
|
||||
|
||||
// Join multicast group on every interface so we receive replies on any path.
|
||||
for (const auto& net : subnets) {
|
||||
ip_mreq mreq{};
|
||||
inet_pton(AF_INET, kMulticastGroup, &mreq.imr_multiaddr);
|
||||
mreq.imr_interface = net.localAddr;
|
||||
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||
reinterpret_cast<char*>(&mreq), sizeof(mreq)) != 0) {
|
||||
ANS_DBG("ANSDISC", "IP_ADD_MEMBERSHIP on %.*s failed err=%d",
|
||||
static_cast<int>(net.prefix.size() - 1), net.prefix.c_str(),
|
||||
WSAGetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
char buf[2048];
|
||||
sockaddr_in from{};
|
||||
int fromLen = sizeof(from);
|
||||
while (!state.stop.load(std::memory_order_relaxed)) {
|
||||
fd_set rfds; FD_ZERO(&rfds); FD_SET(s, &rfds);
|
||||
timeval tv{ 0, 200 * 1000 }; // 200 ms
|
||||
int sel = select(0, &rfds, nullptr, nullptr, &tv);
|
||||
if (sel <= 0) continue;
|
||||
int n = recvfrom(s, buf, sizeof(buf), 0,
|
||||
reinterpret_cast<sockaddr*>(&from), &fromLen);
|
||||
if (n <= 0) continue;
|
||||
std::string body(buf, n);
|
||||
if (body == kProbeMessage) continue; // our own echo
|
||||
char ipStr[INET_ADDRSTRLEN] = {};
|
||||
inet_ntop(AF_INET, &from.sin_addr, ipStr, sizeof(ipStr));
|
||||
std::string name, fw;
|
||||
int port = 0;
|
||||
ParseUdpReply(body, name, fw, port);
|
||||
ANS_DBG("ANSDISC", "UDP reply from %s name=%s fw=%s port=%d raw=%s",
|
||||
ipStr, name.c_str(), fw.c_str(), port, body.c_str());
|
||||
state.merge(ipStr, name, fw, port, kSrcMulticast);
|
||||
}
|
||||
closesocket(s);
|
||||
}
|
||||
|
||||
// ---- UDP sender thread ---------------------------------------------------
|
||||
// Sends "Hello, Multicast" to the multicast group out each interface and
|
||||
// to each subnet broadcast. Repeats every kUdpProbeIntervalMs.
|
||||
void RunUdpSender(ScanState& state, const std::vector<LocalSubnet>& subnets) {
|
||||
SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s == INVALID_SOCKET) {
|
||||
ANS_DBG("ANSDISC", "sender socket() failed err=%d", WSAGetLastError());
|
||||
return;
|
||||
}
|
||||
BOOL on = TRUE;
|
||||
setsockopt(s, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char*>(&on), sizeof(on));
|
||||
int ttl = kMulticastTtl;
|
||||
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
|
||||
reinterpret_cast<char*>(&ttl), sizeof(ttl));
|
||||
|
||||
sockaddr_in mc{};
|
||||
mc.sin_family = AF_INET;
|
||||
mc.sin_port = htons(kProbePort);
|
||||
inet_pton(AF_INET, kMulticastGroup, &mc.sin_addr);
|
||||
|
||||
auto sendOnce = [&]() {
|
||||
for (const auto& net : subnets) {
|
||||
// Pin multicast egress to this interface so it leaves each NIC.
|
||||
setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
|
||||
reinterpret_cast<const char*>(&net.localAddr),
|
||||
sizeof(net.localAddr));
|
||||
sendto(s, kProbeMessage, static_cast<int>(strlen(kProbeMessage)), 0,
|
||||
reinterpret_cast<sockaddr*>(&mc), sizeof(mc));
|
||||
sockaddr_in bc{};
|
||||
bc.sin_family = AF_INET;
|
||||
bc.sin_port = htons(kProbePort);
|
||||
bc.sin_addr = net.broadcast;
|
||||
sendto(s, kProbeMessage, static_cast<int>(strlen(kProbeMessage)), 0,
|
||||
reinterpret_cast<sockaddr*>(&bc), sizeof(bc));
|
||||
}
|
||||
};
|
||||
|
||||
sendOnce();
|
||||
auto next = std::chrono::steady_clock::now() + std::chrono::milliseconds(kUdpProbeIntervalMs);
|
||||
while (!state.stop.load(std::memory_order_relaxed)) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (now >= next) {
|
||||
sendOnce();
|
||||
next = now + std::chrono::milliseconds(kUdpProbeIntervalMs);
|
||||
} else {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
closesocket(s);
|
||||
}
|
||||
|
||||
// ---- One synchronous HTTP probe via WinHTTP -----------------------------
|
||||
// On AIBOX/ANSVIS reply: out_version is set and returns true. Otherwise false.
|
||||
bool ProbeHttp(const std::string& ip, unsigned short port, std::string& out_version) {
|
||||
HINTERNET hSession = WinHttpOpen(kHttpUserAgent,
|
||||
WINHTTP_ACCESS_TYPE_NO_PROXY,
|
||||
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
|
||||
if (!hSession) return false;
|
||||
WinHttpSetTimeouts(hSession,
|
||||
kHttpConnectTimeoutMs, kHttpConnectTimeoutMs,
|
||||
kHttpProbeTimeoutMs, kHttpProbeTimeoutMs);
|
||||
|
||||
std::wstring host(ip.begin(), ip.end());
|
||||
HINTERNET hConn = WinHttpConnect(hSession, host.c_str(),
|
||||
static_cast<INTERNET_PORT>(port), 0);
|
||||
if (!hConn) { WinHttpCloseHandle(hSession); return false; }
|
||||
|
||||
HINTERNET hReq = WinHttpOpenRequest(hConn, L"GET", kHttpPath,
|
||||
nullptr, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
|
||||
if (!hReq) {
|
||||
WinHttpCloseHandle(hConn); WinHttpCloseHandle(hSession);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
if (WinHttpSendRequest(hReq, L"Accept: application/json\r\n", static_cast<DWORD>(-1L),
|
||||
WINHTTP_NO_REQUEST_DATA, 0, 0, 0) &&
|
||||
WinHttpReceiveResponse(hReq, nullptr))
|
||||
{
|
||||
DWORD status = 0, statusSize = sizeof(status);
|
||||
if (WinHttpQueryHeaders(hReq,
|
||||
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
|
||||
WINHTTP_HEADER_NAME_BY_INDEX, &status, &statusSize,
|
||||
WINHTTP_NO_HEADER_INDEX) && status == 200)
|
||||
{
|
||||
std::string body;
|
||||
DWORD avail = 0;
|
||||
// Cap body at 64 KB — /ServerApi is a few hundred bytes.
|
||||
while (body.size() < 65536 && WinHttpQueryDataAvailable(hReq, &avail) && avail) {
|
||||
std::vector<char> buf(avail);
|
||||
DWORD read = 0;
|
||||
if (!WinHttpReadData(hReq, buf.data(), avail, &read)) break;
|
||||
body.append(buf.data(), read);
|
||||
}
|
||||
ok = ParseServerApiJson(body, out_version);
|
||||
}
|
||||
}
|
||||
WinHttpCloseHandle(hReq);
|
||||
WinHttpCloseHandle(hConn);
|
||||
WinHttpCloseHandle(hSession);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// ---- HTTP sweep: 64-way worker pool consuming a queue of (ip, port) -----
|
||||
// Each host is probed on every port in kSweepPorts (80 + 22211) so one
|
||||
// sweep covers both AIBOX and ANSVIS.
|
||||
void RunHttpSweep(ScanState& state, const std::vector<LocalSubnet>& subnets) {
|
||||
struct Target { std::string ip; unsigned short port; };
|
||||
std::queue<Target> q;
|
||||
for (const auto& net : subnets) {
|
||||
for (int h = 1; h <= 254; ++h) {
|
||||
std::string ip = net.prefix + std::to_string(h);
|
||||
for (unsigned short p : kSweepPorts) q.push({ ip, p });
|
||||
}
|
||||
}
|
||||
ANS_DBG("ANSDISC", "HTTP sweep targets=%zu workers=%d", q.size(), kHttpConcurrency);
|
||||
|
||||
std::mutex qmu;
|
||||
auto worker = [&]() {
|
||||
for (;;) {
|
||||
if (state.stop.load(std::memory_order_relaxed)) return;
|
||||
Target t;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(qmu);
|
||||
if (q.empty()) return;
|
||||
t = std::move(q.front());
|
||||
q.pop();
|
||||
}
|
||||
std::string ver;
|
||||
if (ProbeHttp(t.ip, t.port, ver)) {
|
||||
ANS_DBG("ANSDISC", "HTTP hit %s:%u version=%s",
|
||||
t.ip.c_str(), static_cast<unsigned>(t.port), ver.c_str());
|
||||
state.merge(t.ip, std::string(), ver, static_cast<int>(t.port), kSrcSweep);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::thread> pool;
|
||||
pool.reserve(kHttpConcurrency);
|
||||
for (int i = 0; i < kHttpConcurrency; ++i) pool.emplace_back(worker);
|
||||
for (auto& t : pool) t.join();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace ANSCENTER {
|
||||
|
||||
std::vector<ANSDeviceInfo> ANSUtilities::ScanDevices(int timeoutMs) {
|
||||
if (timeoutMs < 500) timeoutMs = 500; // floor: enough for one UDP burst
|
||||
|
||||
ANS_DBG("ANSDISC", "ScanDevices: enter timeoutMs=%d", timeoutMs);
|
||||
WsaScope wsa;
|
||||
if (!wsa.ok) {
|
||||
ANS_DBG("ANSDISC", "WSAStartup failed");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto subnets = EnumerateLocalSubnets();
|
||||
if (subnets.empty()) {
|
||||
ANS_DBG("ANSDISC", "no usable IPv4 interfaces; aborting scan");
|
||||
return {};
|
||||
}
|
||||
|
||||
ScanState state;
|
||||
|
||||
std::thread tListen([&]{ RunUdpListener(state, subnets); });
|
||||
std::thread tSend ([&]{ RunUdpSender (state, subnets); });
|
||||
std::thread tSweep ([&]{ RunHttpSweep (state, subnets); });
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(timeoutMs));
|
||||
state.stop.store(true, std::memory_order_relaxed);
|
||||
|
||||
tListen.join();
|
||||
tSend.join();
|
||||
tSweep.join();
|
||||
|
||||
std::vector<ANSDeviceInfo> result;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(state.mu);
|
||||
result.reserve(state.found.size());
|
||||
for (auto& kv : state.found) result.push_back(std::move(kv.second));
|
||||
}
|
||||
ANS_DBG("ANSDISC", "ScanDevices: exit found=%zu", result.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace ANSCENTER
|
||||
|
||||
|
||||
@@ -17,9 +17,20 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
namespace ANSCENTER {
|
||||
// Discovered AIBOX / ANSVIS server on the local network.
|
||||
struct ANSDeviceInfo {
|
||||
std::string ip; // IPv4 address (dotted-decimal)
|
||||
std::string name; // Device name from UDP probe, empty if HTTP-only
|
||||
std::string firmware; // Version string ("-" if device did not report one)
|
||||
int port{ 0 }; // TCP port the device's HTTP API answers on
|
||||
// (AIBOX = 80, ANSVIS = 22211). 0 = unknown.
|
||||
int source{ 0 }; // 1 = multicast, 2 = HTTP sweep, 3 = both
|
||||
};
|
||||
|
||||
class ANSULT_API ANSUtilities {
|
||||
private:
|
||||
// Protects all shared mutable data
|
||||
@@ -144,12 +155,79 @@ namespace ANSCENTER {
|
||||
// Unescape double-escaped Unicode: "Th\\u1ee7y" becomes "Th\u1ee7y".
|
||||
// Reverses DoubleEscapeUnicode so other languages can parse \uXXXX correctly.
|
||||
static std::string UnescapeDoubleEscapedUnicode(const std::string& str);
|
||||
|
||||
// Read every Error-level event from "ANSLogger" in the Windows
|
||||
// Application event log. Output: one line per event in the form
|
||||
// "<DD/MM/YYYY h:mm:ss tt>: <event data string>\n"
|
||||
// Time is converted to the user's local timezone and formatted
|
||||
// using LOCALE_USER_DEFAULT (matches Event Viewer's display).
|
||||
//
|
||||
// clearAfterRead=true behaviour:
|
||||
// * Calls EvtClearLog on the entire Application channel after
|
||||
// reading. WARNING: this wipes every event from every source
|
||||
// in the Application log, not just ANSLogger entries — there
|
||||
// is no per-event delete API in Windows.
|
||||
// * REQUIRES THE CALLING PROCESS TO BE ELEVATED (run as
|
||||
// Administrator). Without elevation, EvtClearLog returns
|
||||
// ERROR_ACCESS_DENIED (Win32 error 5) and the events remain
|
||||
// in the log. The read still succeeds either way.
|
||||
// * Failures are reported on stderr in the form
|
||||
// "[ANSUtilities] EvtClearLog(Application) FAILED, GetLastError=N"
|
||||
// and via DebugView under the "EVTLOG" tag. The C++ return
|
||||
// value does NOT signal clear success — capture stderr or
|
||||
// check Event Viewer afterwards to confirm.
|
||||
[[nodiscard]] static std::string GetANSLoggerErrorEvents(bool clearAfterRead = false);
|
||||
|
||||
// Same as GetANSLoggerErrorEvents but only returns events that
|
||||
// have NOT been returned by a previous call from this user
|
||||
// account. The highest EventRecordID seen is persisted to
|
||||
// HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger
|
||||
// (REG_QWORD) and used as a Windows XPath filter
|
||||
// (EventRecordID > N) on the next call. No admin needed for the
|
||||
// skip mechanism — only for the optional clearAfterRead.
|
||||
//
|
||||
// Channel-clear handling: if Windows resets the Application
|
||||
// channel's RecordID counter (typical after EvtClearLog), this
|
||||
// function detects that the channel's current max RecordID is
|
||||
// less than the stored watermark and resets the watermark to 0
|
||||
// so no newly-written events are accidentally skipped.
|
||||
//
|
||||
// To force a re-read of all events, delete the registry value
|
||||
// above and call again.
|
||||
[[nodiscard]] static std::string GetANSLoggerErrorEventsSinceLastCall(bool clearAfterRead = false);
|
||||
|
||||
// Scan the local network for AIBOX / ANSVIS servers.
|
||||
// Runs two strategies in parallel and merges results by IP:
|
||||
// 1) UDP multicast probe to 230.50.200.150:58839 (with subnet
|
||||
// broadcast fallback). App listens on UDP/58838 for replies
|
||||
// in the form "<a>:<b>:<deviceName>:<firmware>".
|
||||
// 2) HTTP /24 subnet sweep on every local IPv4 interface, GETing
|
||||
// http://<host>/ServerApi with up to 64 concurrent connections.
|
||||
// A device is recognized when the JSON body contains
|
||||
// {"OK": true, "Version": "<firmware>"}.
|
||||
// `timeoutMs` is the maximum scan window (default 5000 ms). Shorter
|
||||
// values return faster but may miss slow devices. The call blocks
|
||||
// until the window elapses, then returns the deduplicated list.
|
||||
[[nodiscard]] static std::vector<ANSDeviceInfo> ScanDevices(int timeoutMs = 5000);
|
||||
};
|
||||
// Connection bundle for pool
|
||||
struct S3Connection {
|
||||
CkRest rest;
|
||||
CkSocket socket;
|
||||
CkAuthAws authAws;
|
||||
|
||||
// When this connection last completed a request successfully. A socket
|
||||
// that a NAT/firewall silently killed while idle costs a full
|
||||
// IdleTimeoutMs to discover, so anything idle longer than
|
||||
// kMaxPooledIdleMs is dropped rather than handed out again.
|
||||
std::chrono::steady_clock::time_point lastUsed{ std::chrono::steady_clock::now() };
|
||||
|
||||
// Value of ANSAWSS3::_configGen when this connection was built.
|
||||
// A mismatch means it predates a Connect / SetAuthentication /
|
||||
// SetServerProxy call — e.g. the background RetryLoop finished a
|
||||
// connect just after SetAuthentication cleared the pool — so its
|
||||
// endpoint, proxy or SigV4 state is stale and it must not be reused.
|
||||
uint64_t configGen{ 0 };
|
||||
};
|
||||
|
||||
class ANSULT_API ANSAWSS3 {
|
||||
@@ -188,6 +266,24 @@ namespace ANSCENTER {
|
||||
std::atomic<int> _connectTimeoutMs{ 10000 }; // 10 s
|
||||
std::atomic<int> _idleTimeoutMs { 20000 }; // 20 s
|
||||
|
||||
// Shorter idle timeout used for the FIRST request on a connection
|
||||
// taken from the pool. A pooled socket may have been silently
|
||||
// dropped by a middlebox since it was last used; without this the
|
||||
// caller pays the full _idleTimeoutMs (20 s by default) just to
|
||||
// discover that. A fresh connection still gets the full
|
||||
// _idleTimeoutMs, so the retry after a stale-socket failure is not
|
||||
// penalised. Derived from _idleTimeoutMs by SetTimeouts().
|
||||
std::atomic<int> _reusedIdleTimeoutMs{ 5000 }; // 5 s
|
||||
|
||||
// Bumped by Connect / SetAuthentication / SetServerProxy. Stamped
|
||||
// into every S3Connection at creation; see S3Connection::configGen.
|
||||
std::atomic<uint64_t> _configGen{ 1 };
|
||||
|
||||
// A pooled connection idle longer than this is closed instead of
|
||||
// reused. Kept below the ~20 s after which S3 (and most NAT
|
||||
// devices) stop caring about an idle keep-alive flow.
|
||||
static constexpr int kMaxPooledIdleMs = 15000;
|
||||
|
||||
// Proxy settings
|
||||
std::string _proxyHost;
|
||||
int _proxyPort{ 0 };
|
||||
@@ -201,7 +297,14 @@ namespace ANSCENTER {
|
||||
// Used by TryConnect's first attempt, which is allowed to fail for path-style/MinIO servers.
|
||||
std::unique_ptr<S3Connection> CreateConnection(bool logOnFailure = true);
|
||||
std::unique_ptr<S3Connection> AcquireConnection();
|
||||
// Return a healthy connection to the pool for reuse.
|
||||
void ReleaseConnection(std::unique_ptr<S3Connection> conn);
|
||||
// Close and destroy a connection instead of pooling it. Use on any
|
||||
// TRANSPORT failure (send/recv failed, timeout): that socket is
|
||||
// suspect, and putting it back means the next worker inherits the
|
||||
// same stall. An HTTP error status is NOT a transport failure — the
|
||||
// server answered — so those still go through ReleaseConnection.
|
||||
void DiscardConnection(std::unique_ptr<S3Connection> conn);
|
||||
|
||||
std::string ExtractFileName(const std::string& filePath);
|
||||
std::string GetContentType(const std::string& filePath);
|
||||
@@ -215,8 +318,34 @@ namespace ANSCENTER {
|
||||
// The lambda should write a short human-readable reason into
|
||||
// `lastError` on any non-Success outcome so it can be logged.
|
||||
enum class AttemptResult { Success, Transient, Permanent };
|
||||
// Record the outcome of the current call for the calling thread.
|
||||
static void SetCallStatus(int status);
|
||||
// Shared licence / unlock / connected check for the upload entry
|
||||
// points. Logs the reason and sets the per-thread call status
|
||||
// (permanent for a licence problem, not-connected for a link that
|
||||
// has not come up yet). Returns false if the call must not proceed.
|
||||
bool CheckUploadPreconditions(const std::string& opName);
|
||||
|
||||
// Decide what a failed Chilkat request means, and dispose of the
|
||||
// connection accordingly. Chilkat reports failure for an HTTP 4xx
|
||||
// delivered during an Expect: 100-continue exchange, so "the call
|
||||
// returned false" does NOT imply the network failed — a 404
|
||||
// NoSuchBucket arrives this way. Retrying those wastes the whole
|
||||
// retry budget and reports the wrong class to the caller.
|
||||
// 4xx (except 408/429) -> Permanent, socket healthy -> pooled
|
||||
// anything else -> Transient, socket suspect -> discarded
|
||||
// Takes ownership of `conn`, and rewrites `lastError` into one
|
||||
// readable line.
|
||||
AttemptResult ClassifyFailedRequest(std::unique_ptr<S3Connection> conn,
|
||||
std::string& lastError);
|
||||
static constexpr int kUploadMaxAttempts = 20;
|
||||
static constexpr int kUploadRetryDelayMs = 100;
|
||||
// Wall-clock budget for one upload call, across all attempts. The
|
||||
// attempt cap alone is not a bound on time: 20 attempts that each
|
||||
// hit a 20 s idle timeout would block the caller for ~400 s. A new
|
||||
// attempt is only started while inside this budget, so the worst
|
||||
// case is the budget plus one in-flight attempt.
|
||||
static constexpr int kUploadDeadlineMs = 30000;
|
||||
bool UploadWithRetry(
|
||||
const std::string& opName,
|
||||
const std::function<AttemptResult(std::string& lastError)>& attemptFn);
|
||||
@@ -230,6 +359,37 @@ namespace ANSCENTER {
|
||||
bool TryConnect(bool& awsPath);
|
||||
|
||||
public:
|
||||
// ---- Call status codes -------------------------------------------
|
||||
// Every upload entry point records one of these for the CALLING
|
||||
// THREAD, so the C exports can tell the caller whether a retry is
|
||||
// worth attempting without changing any function signature.
|
||||
//
|
||||
// These EXTEND the codes the C wrappers already return; they do not
|
||||
// redefine any of them. Full set seen by a LabVIEW caller:
|
||||
// 1 success
|
||||
// 0 null / invalid argument passed to the export
|
||||
// -1 handle not in the registry
|
||||
// -2 upload failed, reason not classified (fallback)
|
||||
// -3 std::exception escaped
|
||||
// -4 unknown exception escaped
|
||||
// -20 permanent: bad argument, licence, bucket, or HTTP 4xx
|
||||
// -21 not connected yet / reconnect in progress
|
||||
// -22 transient: network, timeout or 5xx after internal retries
|
||||
//
|
||||
// Retry rule for the caller: retry on -21 and -22 (and -2/-3/-4 if
|
||||
// it wants to be generous); do NOT retry on -20 or 0 — those need a
|
||||
// configuration or code fix. Success stays the only positive value,
|
||||
// so both `rc == 1` and `rc != 1` remain correct tests.
|
||||
static constexpr int kCallSuccess = 1;
|
||||
static constexpr int kCallPermanentError = -20;
|
||||
static constexpr int kCallNotConnected = -21;
|
||||
static constexpr int kCallTransientError = -22;
|
||||
|
||||
// Status of the most recent upload call made ON THIS THREAD.
|
||||
// Thread-local, so concurrent workers sharing one handle never see
|
||||
// each other's result. Read it immediately after the call.
|
||||
static int LastCallStatus();
|
||||
|
||||
ANSAWSS3();
|
||||
~ANSAWSS3();
|
||||
[[nodiscard]] bool Initialize(const std::string& licenseKey);
|
||||
@@ -345,6 +505,27 @@ extern "C" ANSULT_API int SendEmail(const char* smtpServer, int port,
|
||||
|
||||
extern "C" ANSULT_API int RebootSystem();
|
||||
|
||||
// Discover AIBOX / ANSVIS servers on the local network.
|
||||
// Returns a JSON array of objects: [{"ip":"...","name":"...","firmware":"...","source":3}, ...]
|
||||
// `source` is 1 = multicast, 2 = HTTP sweep, 3 = both.
|
||||
// `timeoutMs` caps the scan duration (typical: 3000-10000 ms).
|
||||
extern "C" ANSULT_API int ScanANSDevices(int timeoutMs, LStrHandle resultJson);
|
||||
extern "C" ANSULT_API int ScanANSDevicesCpp(int timeoutMs, std::string& resultJson);
|
||||
|
||||
// Read all Error-level events from "ANSLogger" in the Windows Application
|
||||
// event log. Returns a UTF-8 string with one event per line:
|
||||
// "<DD/MM/YYYY h:mm:ss tt>: <event data>\n"
|
||||
// `clearAfterRead` != 0 clears the entire Application channel afterwards
|
||||
// (requires Administrator; see header comment on the C++ method).
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEvents(int clearAfterRead, LStrHandle result);
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsCpp(int clearAfterRead, std::string& result);
|
||||
|
||||
// Watermarked variant: only returns events not seen by previous calls.
|
||||
// Watermark is stored in HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger
|
||||
// (REG_QWORD). No admin needed for the skip; only for clearAfterRead.
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCall(int clearAfterRead, LStrHandle result);
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCallCpp(int clearAfterRead, std::string& result);
|
||||
|
||||
// Unicode conversion utilities for LabVIEW
|
||||
extern "C" ANSULT_API int ANSConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM = 1);
|
||||
extern "C" ANSULT_API int ANSDecodeJsonUnicodeToUTF16LE(const char* escapedStr, LStrHandle result);
|
||||
|
||||
@@ -21,7 +21,10 @@ target_link_libraries(ANSUtilities
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(ANSUtilities PRIVATE ${WIN_COMMON_LIBS} crypt32)
|
||||
# WIN_COMMON_LIBS covers ws2_32, iphlpapi, etc. winhttp is needed for the
|
||||
# ScanDevices HTTP /ServerApi sweep. wevtapi is needed for
|
||||
# GetANSLoggerErrorEvents (EvtQuery / EvtRender / EvtClearLog).
|
||||
target_link_libraries(ANSUtilities PRIVATE ${WIN_COMMON_LIBS} crypt32 winhttp wevtapi)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(ANSUtilities PRIVATE UNICODE _UNICODE ANSUTILITIES_EXPORTS)
|
||||
|
||||
@@ -209,6 +209,20 @@ public:
|
||||
AWSHandleGuard& operator=(const AWSHandleGuard&) = delete;
|
||||
};
|
||||
|
||||
// Failure code for an upload whose C++ call returned false. ANSAWSS3 records
|
||||
// WHY on the calling thread, which is what lets the caller decide whether a
|
||||
// retry is worthwhile:
|
||||
// -20 permanent — bad argument / licence / bucket / HTTP 4xx: do not retry
|
||||
// -21 not connected — link not up yet, background retry running: retry later
|
||||
// -22 transient — network/timeout/5xx after internal retries: retry
|
||||
// Falls back to the historical -2 if no status was recorded. Never returns a
|
||||
// success code, so `rc == 1` remains an exact success test.
|
||||
static int AwsUploadFailureCode() {
|
||||
const int status = ANSCENTER::ANSAWSS3::LastCallStatus();
|
||||
if (status == ANSCENTER::ANSAWSS3::kCallSuccess) return -2;
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
@@ -1910,7 +1924,7 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle(ANSCENTER::ANSAWSS3** Hand
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadTextData(bucketName, textDataPath, outPath)) {
|
||||
@@ -1922,13 +1936,13 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle(ANSCENTER::ANSAWSS3** Hand
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* binaryDataPath, LStrHandle uploadedFilePath) {
|
||||
@@ -1936,7 +1950,7 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Ha
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadBinaryData(bucketName, binaryDataPath, outPath)) {
|
||||
@@ -1948,13 +1962,13 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Ha
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, LStrHandle uploadedFilePath) {
|
||||
@@ -1962,7 +1976,7 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3*
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadFileStream(bucketName, fileDataPath, outPath)) {
|
||||
@@ -1974,13 +1988,13 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3*
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, int fileSize, LStrHandle uploadedFilePath) {
|
||||
@@ -1988,7 +2002,7 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3**
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadMultipartData(bucketName, fileDataPath, outPath, fileSize)) {
|
||||
@@ -2000,13 +2014,13 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3**
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int DownloadFileStreamANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* objectName, const char* savedFilePath) {
|
||||
@@ -2043,7 +2057,7 @@ extern "C" ANSULT_API int UploadJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3** Han
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return -2;// failed upload
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return -3;//excception
|
||||
@@ -2088,9 +2102,10 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
ANS_DBG("ANSAWS", "Upload FAILED (-2): file=%s, UploadPrefixJpegImage returned false",
|
||||
fileName ? fileName : "(null)");
|
||||
return -2;
|
||||
const int rc = AwsUploadFailureCode();
|
||||
ANS_DBG("ANSAWS", "Upload FAILED (%d): file=%s, UploadPrefixJpegImage returned false",
|
||||
rc, fileName ? fileName : "(null)");
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
@@ -2159,7 +2174,7 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle(ANSCENTER::ANSA
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, outPath, fileSize)) {
|
||||
@@ -2171,13 +2186,13 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle(ANSCENTER::ANSA
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, LStrHandle uploadedFilePath) {
|
||||
@@ -2185,7 +2200,7 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS
|
||||
return 0;
|
||||
}
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, outPath)) {
|
||||
@@ -2197,79 +2212,79 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
return 0;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
// ── C++ test APIs (std::string& instead of LStrHandle) ──
|
||||
extern "C" ANSULT_API int UploadTextDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* textDataPath, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || textDataPath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadTextData(bucketName, textDataPath, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadTextData(bucketName, textDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* binaryDataPath, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || binaryDataPath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadBinaryData(bucketName, binaryDataPath, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadBinaryData(bucketName, binaryDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || fileDataPath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadFileStream(bucketName, fileDataPath, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadFileStream(bucketName, fileDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, int fileSize, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || fileDataPath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadMultipartData(bucketName, fileDataPath, uploadedFilePath, fileSize) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadMultipartData(bucketName, fileDataPath, uploadedFilePath, fileSize) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || binaryDataPath == nullptr || objectName == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* fileDataPath, const char* objectName, int fileSize, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, uploadedFilePath, fileSize) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, uploadedFilePath, fileSize) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, std::string& uploadedFilePath) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
return guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : 0;
|
||||
} catch (...) { return 0; }
|
||||
return guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
|
||||
} catch (...) { return -4; }
|
||||
}
|
||||
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* objectName, int validDays, std::string& presignedURL) {
|
||||
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || objectName == nullptr) return 0;
|
||||
@@ -2767,7 +2782,7 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle_V2(uint64_t handleVal, cons
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || textDataPath == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadTextData(bucketName, textDataPath, outPath)) {
|
||||
@@ -2779,17 +2794,17 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle_V2(uint64_t handleVal, cons
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* binaryDataPath, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || binaryDataPath == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadBinaryData(bucketName, binaryDataPath, outPath)) {
|
||||
@@ -2801,17 +2816,17 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_V2(uint64_t handleVal, co
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* fileDataPath, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || fileDataPath == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadFileStream(bucketName, fileDataPath, outPath)) {
|
||||
@@ -2823,17 +2838,17 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_V2(uint64_t handleVal
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* fileDataPath, int fileSize, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || fileDataPath == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadMultipartData(bucketName, fileDataPath, outPath, fileSize)) {
|
||||
@@ -2845,17 +2860,17 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_V2(uint64_t handleVal,
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, outPath)) {
|
||||
@@ -2867,17 +2882,17 @@ extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_V2(uint64_t handleVal, con
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || prefix == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, outPath)) {
|
||||
@@ -2889,10 +2904,10 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_V2(uint64_t handleVa
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* objectName, int validDays, LStrHandle presignedURL) {
|
||||
@@ -2921,7 +2936,7 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_V2(uint64_t hand
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0 || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, outPath, fileSize)) {
|
||||
@@ -2933,17 +2948,17 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_V2(uint64_t hand
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, LStrHandle uploadedFilePath) {
|
||||
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
|
||||
if (bucketName == nullptr || prefix == nullptr || binaryDataPath == nullptr || objectName == nullptr || uploadedFilePath == nullptr) return 0;
|
||||
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
|
||||
if (!guard) return 0;
|
||||
if (!guard) return -1; // handle not in registry
|
||||
try {
|
||||
std::string outPath;
|
||||
if (guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, outPath)) {
|
||||
@@ -2955,10 +2970,10 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_V2(uint64_t handleV
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
else return AwsUploadFailureCode();
|
||||
}
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
catch (std::exception& e) { return -3; }
|
||||
catch (...) { return -4; }
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int DownloadFileStreamANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* objectName, const char* savedFilePath) {
|
||||
@@ -2973,3 +2988,162 @@ extern "C" ANSULT_API int DownloadFileStreamANSAWSHandle_V2(uint64_t handleVal,
|
||||
catch (std::exception& e) { return 0; }
|
||||
catch (...) { return 0; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ScanANSDevices — discover AIBOX / ANSVIS servers on the local network.
|
||||
// Returns 1 on success (resultJson populated, possibly with empty "[]"), 0
|
||||
// on internal failure. The static C++ method does its own license/error
|
||||
// handling; this wrapper just serializes the device list to JSON.
|
||||
// ---------------------------------------------------------------------------
|
||||
static std::string JsonEscape(const std::string& s) {
|
||||
std::string out;
|
||||
out.reserve(s.size() + 2);
|
||||
for (char c : s) {
|
||||
switch (c) {
|
||||
case '"': out += "\\\""; break;
|
||||
case '\\': out += "\\\\"; break;
|
||||
case '\n': out += "\\n"; break;
|
||||
case '\r': out += "\\r"; break;
|
||||
case '\t': out += "\\t"; break;
|
||||
default:
|
||||
if (static_cast<unsigned char>(c) < 0x20) {
|
||||
char buf[8];
|
||||
snprintf(buf, sizeof(buf), "\\u%04x", static_cast<unsigned char>(c));
|
||||
out += buf;
|
||||
} else {
|
||||
out += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::string DevicesToJson(const std::vector<ANSCENTER::ANSDeviceInfo>& devs) {
|
||||
std::string j = "[";
|
||||
for (size_t i = 0; i < devs.size(); ++i) {
|
||||
if (i) j += ',';
|
||||
j += "{\"ip\":\""; j += JsonEscape(devs[i].ip); j += "\",";
|
||||
j += "\"name\":\""; j += JsonEscape(devs[i].name); j += "\",";
|
||||
j += "\"firmware\":\""; j += JsonEscape(devs[i].firmware); j += "\",";
|
||||
j += "\"port\":"; j += std::to_string(devs[i].port); j += ',';
|
||||
j += "\"source\":"; j += std::to_string(devs[i].source);
|
||||
j += '}';
|
||||
}
|
||||
j += ']';
|
||||
return j;
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int ScanANSDevicesCpp(int timeoutMs, std::string& resultJson) {
|
||||
ANS_DBG("ANSUTIL", "ScanANSDevicesCpp: timeoutMs=%d", timeoutMs);
|
||||
try {
|
||||
auto devs = ANSCENTER::ANSUtilities::ScanDevices(timeoutMs);
|
||||
resultJson = DevicesToJson(devs);
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSUTIL", "ScanANSDevicesCpp threw: %s", e.what());
|
||||
resultJson = "[]";
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSUTIL", "ScanANSDevicesCpp threw unknown");
|
||||
resultJson = "[]";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int ScanANSDevices(int timeoutMs, LStrHandle resultJson) {
|
||||
ANS_DBG("ANSUTIL", "ScanANSDevices: timeoutMs=%d", timeoutMs);
|
||||
if (!resultJson) return -1;
|
||||
try {
|
||||
std::string j;
|
||||
ScanANSDevicesCpp(timeoutMs, j);
|
||||
int size = static_cast<int>(j.size());
|
||||
MgErr error = DSSetHandleSize(resultJson, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error != noErr) return -2;
|
||||
(*resultJson)->cnt = size;
|
||||
if (size > 0) memcpy((*resultJson)->str, j.data(), size);
|
||||
return 1;
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GetANSLoggerErrorEvents — read Error-level events from the ANSLogger source
|
||||
// in the Windows Application event log. Returns 1 on success (string may be
|
||||
// empty if no events match), 0 on internal failure.
|
||||
// `clearAfterRead != 0` triggers EvtClearLog on the entire Application
|
||||
// channel — see ANSUtilities.h header comment for caveats.
|
||||
// ---------------------------------------------------------------------------
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsCpp(int clearAfterRead, std::string& result) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsCpp: clearAfterRead=%d", clearAfterRead);
|
||||
try {
|
||||
result = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(clearAfterRead != 0);
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsCpp threw: %s", e.what());
|
||||
result.clear();
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsCpp threw unknown");
|
||||
result.clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEvents(int clearAfterRead, LStrHandle result) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEvents: clearAfterRead=%d", clearAfterRead);
|
||||
if (!result) return -1;
|
||||
try {
|
||||
std::string s;
|
||||
GetANSLoggerErrorEventsCpp(clearAfterRead, s);
|
||||
int size = static_cast<int>(s.size());
|
||||
MgErr error = DSSetHandleSize(result, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error != noErr) return -2;
|
||||
(*result)->cnt = size;
|
||||
if (size > 0) memcpy((*result)->str, s.data(), size);
|
||||
return 1;
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// GetANSLoggerErrorEventsSinceLastCall — watermark-based incremental read.
|
||||
// Stores highest EventRecordID seen in HKCU; subsequent calls return only
|
||||
// newer events. No admin needed for the skip (only for clearAfterRead).
|
||||
// ---------------------------------------------------------------------------
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCallCpp(int clearAfterRead, std::string& result) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp: clearAfterRead=%d", clearAfterRead);
|
||||
try {
|
||||
result = ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(clearAfterRead != 0);
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp threw: %s", e.what());
|
||||
result.clear();
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp threw unknown");
|
||||
result.clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCall(int clearAfterRead, LStrHandle result) {
|
||||
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCall: clearAfterRead=%d", clearAfterRead);
|
||||
if (!result) return -1;
|
||||
try {
|
||||
std::string s;
|
||||
GetANSLoggerErrorEventsSinceLastCallCpp(clearAfterRead, s);
|
||||
int size = static_cast<int>(s.size());
|
||||
MgErr error = DSSetHandleSize(result, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error != noErr) return -2;
|
||||
(*result)->cnt = size;
|
||||
if (size > 0) memcpy((*result)->str, s.data(), size);
|
||||
return 1;
|
||||
}
|
||||
catch (...) { return -1; }
|
||||
}
|
||||
|
||||
@@ -833,7 +833,7 @@ int RSTPTestCVClient() {
|
||||
// std::string rtspUrl = "rtsp://admin:admin123@192.168.1.23:554";//"rtsp://alex:admin123@192.168.1.11:554";//
|
||||
//std::string rtspUrl = "rtsp://anscamuser:SonTay2020@anssontay.tplinkdns.com:554/Streaming/Channels/401";// "rtsp://admin:JA!uV_mx@42.1.117.99:8093/1/1";
|
||||
|
||||
std::string rtspUrl = "rtsp://admin:Grb%401212@14.224.237.228:15541/Streaming/channels/101";//"rtsp://admin:AnsHome16%&@192.168.1.104:554";//"rtsp://alex:admin123@192.168.1.11:554";//112
|
||||
std::string rtspUrl ="rtsp://admin:AnsHome16%&@192.168.1.103:554";//"rtsp://alex:admin123@192.168.1.11:554";//112
|
||||
|
||||
CreateANSRTSPHandle(&rtspClient, "", "", "", rtspUrl.c_str());
|
||||
//void SetRTSPImageQuality(ANSCENTER::ANSRTSPClient** Handle, int mode)
|
||||
@@ -877,7 +877,32 @@ int RSTPTestCVClient() {
|
||||
//if ((index == 2000) || (index == 2300) || (index == 2700)) { StartRTSP(&rtspClient); }
|
||||
//if (index > 20000) break;
|
||||
auto loopStart = std::chrono::steady_clock::now();
|
||||
auto getStart = loopStart;
|
||||
|
||||
// ── Camera-dead watchdog (mirrors ANSVIS production behaviour) ──────
|
||||
// ANSRTSPClient does NOT auto-reconnect by design: the application
|
||||
// layer polls frame age and calls ReconnectRTSP. Without this, a dead
|
||||
// session (camera reboot, network drop, laptop standby killing the TCP
|
||||
// connection) leaves the client returning the cached last frame
|
||||
// forever. Threshold is 20 s: the decoder's corruption keyframe gate
|
||||
// can legitimately hold delivery for up to ~12 s (300-frame safety
|
||||
// valve) during heavy packet loss, and a reconnect mid-gate would
|
||||
// throw away a recovery that was about to complete. Retry at most
|
||||
// every 15 s so a camera that is genuinely off doesn't get hammered.
|
||||
{
|
||||
static auto lastReconnectAttempt = std::chrono::steady_clock::now();
|
||||
const double frameAgeMs = GetRTSPLastFrameAgeMs(&rtspClient);
|
||||
if (frameAgeMs >= 20000.0 &&
|
||||
loopStart - lastReconnectAttempt > std::chrono::seconds(15)) {
|
||||
lastReconnectAttempt = loopStart;
|
||||
const std::time_t t = std::time(nullptr);
|
||||
char ts[32]; std::strftime(ts, sizeof ts, "%Y-%m-%d %H:%M:%S", std::localtime(&t));
|
||||
printf("[%s] [WATCHDOG] no decoded frame for %.0f s -- calling ReconnectRTSP\n",
|
||||
ts, frameAgeMs / 1000.0);
|
||||
ReconnectRTSP(&rtspClient);
|
||||
}
|
||||
}
|
||||
|
||||
auto getStart = std::chrono::steady_clock::now();
|
||||
cv::Mat* image = nullptr; // ✅ Use a pointer to hold the allocated image
|
||||
GetRTSPCVImage(&rtspClient, width, height, pts,&image);
|
||||
auto getEnd = std::chrono::steady_clock::now();
|
||||
@@ -887,7 +912,10 @@ int RSTPTestCVClient() {
|
||||
// ✅ Check if the image is valid BEFORE accessing it
|
||||
if (!image || image->empty()) {
|
||||
ANSCV_ReleaseImage_S(&image);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
// Wait via waitKey (not sleep) so the HighGUI window keeps pumping
|
||||
// Windows messages — a raw sleep here makes the "Image" window go
|
||||
// "Not Responding" whenever the stream stalls for a few seconds.
|
||||
if (cv::waitKey(1000) == 27) break;
|
||||
continue; // Skip processing if the image is empty
|
||||
}
|
||||
|
||||
@@ -1060,7 +1088,10 @@ int FPTestCVClient() {
|
||||
// ✅ Check if the image is valid BEFORE accessing it
|
||||
if (!image || image->empty()) {
|
||||
ANSCV_ReleaseImage_S(&image);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
// Wait via waitKey (not sleep) so the HighGUI window keeps pumping
|
||||
// Windows messages — a raw sleep here makes the "Image" window go
|
||||
// "Not Responding" whenever the stream stalls for a few seconds.
|
||||
if (cv::waitKey(1000) == 27) break;
|
||||
continue; // Skip processing if the image is empty
|
||||
}
|
||||
|
||||
@@ -1549,7 +1580,10 @@ int VideoPlayerClientTest() {
|
||||
// ✅ Check if the image is valid BEFORE accessing it
|
||||
if (!image || image->empty()) {
|
||||
ANSCV_ReleaseImage_S(&image);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
// Wait via waitKey (not sleep) so the HighGUI window keeps pumping
|
||||
// Windows messages — a raw sleep here makes the "Image" window go
|
||||
// "Not Responding" whenever the stream stalls for a few seconds.
|
||||
if (cv::waitKey(1000) == 27) break;
|
||||
continue; // Skip processing if the image is empty
|
||||
}
|
||||
|
||||
|
||||
@@ -4,40 +4,63 @@ add_executable(ANSCV-UnitTest
|
||||
OpenCVTest.cpp
|
||||
)
|
||||
|
||||
target_include_directories(ANSCV-UnitTest PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/modules/ANSCV
|
||||
${CMAKE_SOURCE_DIR}/MediaClient
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/media
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtsp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/bm
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/http
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/directx
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtmp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/librtmp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/srt
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/ffmpeg/include
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/openssl/include
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/libsrt/include
|
||||
${SHARED_INCLUDE_DIR}
|
||||
${ANSLIBS_DIR}/TurboJpeg
|
||||
${ANSLIBS_DIR}/QRCode
|
||||
# ANSCV Console Test — headless smoke test (no GUI/camera/disk), prints
|
||||
# PASS/FAIL per check and exits with the failure count. Built as its own
|
||||
# executable so it does not collide with ANSCV-UnitTest's GUI main().
|
||||
add_executable(ANSCV-ConsoleTest
|
||||
ConsoleTest.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ANSCV-UnitTest
|
||||
PRIVATE ANSCV
|
||||
PRIVATE ANSLicensingSystem
|
||||
PRIVATE anslicensing
|
||||
PRIVATE labview
|
||||
PRIVATE opencv
|
||||
PRIVATE turbojpeg
|
||||
PRIVATE zxing
|
||||
PRIVATE CUDA::cudart
|
||||
PRIVATE CUDA::nvjpeg
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(ANSCV-UnitTest PRIVATE ${WIN_COMMON_LIBS})
|
||||
# ans_imshow.hpp lives outside the repo (shipped with ANSMIND). Default to the
|
||||
# standard install location but allow overriding on other machines/CI via
|
||||
# -DANSMIND_INCLUDE_DIR=<path>. Warn (don't fail configure) if it's missing, so
|
||||
# unrelated targets still build; ConsoleTest will then fail to compile clearly.
|
||||
set(ANSMIND_INCLUDE_DIR "C:/ProgramData/ANSCENTER/ANSMIND"
|
||||
CACHE PATH "Directory containing ans_imshow.hpp (shipped with ANSMIND)")
|
||||
if(NOT EXISTS "${ANSMIND_INCLUDE_DIR}/ans_imshow.hpp")
|
||||
message(WARNING
|
||||
"ans_imshow.hpp not found in ANSMIND_INCLUDE_DIR='${ANSMIND_INCLUDE_DIR}'. "
|
||||
"ANSCV-ConsoleTest will fail to compile. "
|
||||
"Set -DANSMIND_INCLUDE_DIR=<path> to the directory containing ans_imshow.hpp.")
|
||||
endif()
|
||||
|
||||
target_compile_definitions(ANSCV-UnitTest PRIVATE UNICODE _UNICODE)
|
||||
foreach(_anscv_test ANSCV-UnitTest ANSCV-ConsoleTest)
|
||||
target_include_directories(${_anscv_test} PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/modules/ANSCV
|
||||
${CMAKE_SOURCE_DIR}/MediaClient
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/media
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtsp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/bm
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/http
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/directx
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/rtmp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/librtmp
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/srt
|
||||
${FFMPEG_INCLUDE_DIR} # FFmpeg 8.1 (n8.1); was vendored MediaClient/ffmpeg/include 4.0.2
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/openssl/include
|
||||
${CMAKE_SOURCE_DIR}/MediaClient/libsrt/include
|
||||
${SHARED_INCLUDE_DIR}
|
||||
${ANSLIBS_DIR}/TurboJpeg
|
||||
${ANSLIBS_DIR}/QRCode
|
||||
${ANSMIND_INCLUDE_DIR} # ans_imshow.hpp (ConsoleTest.cpp)
|
||||
)
|
||||
|
||||
target_link_libraries(${_anscv_test}
|
||||
PRIVATE ANSCV
|
||||
PRIVATE ANSLicensingSystem
|
||||
PRIVATE anslicensing
|
||||
PRIVATE labview
|
||||
PRIVATE opencv
|
||||
PRIVATE turbojpeg
|
||||
PRIVATE zxing
|
||||
PRIVATE CUDA::cudart
|
||||
PRIVATE CUDA::nvjpeg
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${_anscv_test} PRIVATE ${WIN_COMMON_LIBS})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${_anscv_test} PRIVATE UNICODE _UNICODE)
|
||||
endforeach()
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
// ANSCV Console Test
|
||||
// ------------------------------------------------------------------
|
||||
// A headless (no GUI) smoke test for ANSCENTER::ANSOPENCV image ops plus an
|
||||
// optional RTSP capture test (ANSCENTER::ANSRTSPClient). It prints a PASS/FAIL
|
||||
// line per check so results are visible in a plain console (and in CI).
|
||||
// Exit code == number of failed checks (0 == all OK).
|
||||
//
|
||||
// Usage:
|
||||
// ANSCV-ConsoleTest.exe # image ops only (no camera needed)
|
||||
// ANSCV-ConsoleTest.exe <rtsp-url> # image ops + headless RTSP capture
|
||||
// ANSCV-ConsoleTest.exe <rtsp-url> <maxFrames>
|
||||
// ANSCV-ConsoleTest.exe <rtsp-url> <maxFrames> <saveDir>
|
||||
// When <saveDir> is given:
|
||||
// <saveDir>/frames/NNNN.jpg full-res captured frames (MP4 input)
|
||||
// <saveDir>/preview_NNNN.jpg downscaled previews for quick viewing
|
||||
// <saveDir>/rtsp_clip.mp4 short clip (NVENC, via ANSCV ImagesToMP4HW)
|
||||
//
|
||||
// This is intentionally separate from ANSCV-UnitTest.cpp, whose main()
|
||||
// opens OpenCV windows (cv::imshow) for the same RTSP stream.
|
||||
#include "ANSOpenCV.h"
|
||||
#include "ANSRTSP.h"
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
#ifdef _WIN32
|
||||
# define NOMINMAX
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
using ANSCENTER::ANSOPENCV;
|
||||
using ANSCENTER::ANSRTSPClient;
|
||||
using ANSCENTER::DetectionObject;
|
||||
|
||||
namespace {
|
||||
|
||||
int g_pass = 0;
|
||||
int g_fail = 0;
|
||||
|
||||
// Report a single check. `detail` is appended for context (sizes, counts, ...).
|
||||
void check(const std::string& name, bool ok, const std::string& detail = "") {
|
||||
if (ok) {
|
||||
++g_pass;
|
||||
std::cout << " [PASS] " << name;
|
||||
} else {
|
||||
++g_fail;
|
||||
std::cout << " [FAIL] " << name;
|
||||
}
|
||||
if (!detail.empty()) std::cout << " (" << detail << ")";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::string dims(const cv::Mat& m) {
|
||||
return std::to_string(m.cols) + "x" + std::to_string(m.rows) +
|
||||
" ch=" + std::to_string(m.channels());
|
||||
}
|
||||
|
||||
// A 640x480 BGR test image: smooth gradient plus a few filled shapes so the
|
||||
// transforms operate on something with real structure (not a flat color).
|
||||
cv::Mat MakeTestImage(int w = 640, int h = 480) {
|
||||
cv::Mat img(h, w, CV_8UC3);
|
||||
for (int y = 0; y < h; ++y) {
|
||||
for (int x = 0; x < w; ++x) {
|
||||
img.at<cv::Vec3b>(y, x) = cv::Vec3b(
|
||||
static_cast<uchar>(x * 255 / w),
|
||||
static_cast<uchar>(y * 255 / h),
|
||||
static_cast<uchar>((x + y) * 255 / (w + h)));
|
||||
}
|
||||
}
|
||||
cv::rectangle(img, cv::Rect(50, 50, 200, 150), cv::Scalar(0, 0, 255), -1);
|
||||
cv::circle(img, cv::Point(450, 300), 80, cv::Scalar(0, 255, 0), -1);
|
||||
return img;
|
||||
}
|
||||
|
||||
// Headless RTSP capture test. Connects to `url`, pulls up to `maxFrames`
|
||||
// frames (or until `timeoutMs` elapses), and reports resolution, frame count,
|
||||
// JPEG sizes, per-grab latency and approximate FPS. No GUI — every frame is
|
||||
// reported as text. Bounded so it always terminates even if the camera is
|
||||
// unreachable. Adds PASS/FAIL checks to the global tally.
|
||||
void RtspConsoleTest(const std::string& url, int maxFrames,
|
||||
const std::string& saveDir = "", int timeoutMs = 15000) {
|
||||
std::cout << "-- RTSP capture --" << std::endl;
|
||||
std::cout << "URL: " << url << std::endl;
|
||||
// Give slow/high-res streams enough wall-clock to reach maxFrames.
|
||||
timeoutMs = (std::max)(timeoutMs, maxFrames * 1000);
|
||||
std::cout << "Grabbing up to " << maxFrames << " frames (timeout "
|
||||
<< timeoutMs << " ms)..." << std::endl;
|
||||
|
||||
// When saving, full-res frames go into <saveDir>/frames (clean, zero-padded
|
||||
// names) so the MP4 encoder globs only those; previews go into <saveDir>.
|
||||
std::string framesDir;
|
||||
if (!saveDir.empty()) {
|
||||
framesDir = saveDir + "/frames";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(framesDir, ec);
|
||||
std::cout << "Saving frames to: " << saveDir << std::endl;
|
||||
}
|
||||
|
||||
ANSOPENCV::InitCameraNetwork();
|
||||
|
||||
ANSRTSPClient* client = nullptr;
|
||||
// CreateANSRTSPHandle(handle, licenseKey, username, password, url).
|
||||
// Credentials embedded in the URL → pass empty user/pass, matching the
|
||||
// existing RSTPTestClient() usage.
|
||||
int created = CreateANSRTSPHandle(&client, "", "", "", url.c_str());
|
||||
check("CreateANSRTSPHandle", client != nullptr,
|
||||
"rc=" + std::to_string(created));
|
||||
if (client == nullptr) {
|
||||
ANSOPENCV::DeinitCameraNetwork();
|
||||
return;
|
||||
}
|
||||
|
||||
StartRTSP(&client);
|
||||
|
||||
int width = 0, height = 0;
|
||||
int64_t pts = 0;
|
||||
int frames = 0;
|
||||
long long totalJpegBytes = 0;
|
||||
long long totalGrabMs = 0;
|
||||
int firstW = 0, firstH = 0;
|
||||
int64_t firstPts = 0, lastPts = 0;
|
||||
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
auto elapsedMs = [&] {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - t0).count();
|
||||
};
|
||||
|
||||
int polls = 0;
|
||||
while (frames < maxFrames && elapsedMs() < timeoutMs) {
|
||||
++polls;
|
||||
std::string jpeg;
|
||||
const auto g0 = std::chrono::steady_clock::now();
|
||||
GetRTSPStrImage(&client, width, height, pts, jpeg);
|
||||
const auto grabMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - g0).count();
|
||||
|
||||
if (jpeg.empty()) {
|
||||
// No frame ready yet (connecting / between frames). Back off briefly.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frames == 0) { firstW = width; firstH = height; firstPts = pts; }
|
||||
lastPts = pts;
|
||||
++frames;
|
||||
totalJpegBytes += static_cast<long long>(jpeg.size());
|
||||
totalGrabMs += grabMs;
|
||||
|
||||
// Optionally persist the frame so it can be viewed outside the console.
|
||||
// The grabbed bytes are already a JPEG, so the full-res file is a direct
|
||||
// dump (no re-encode). The preview is decoded + downscaled for quick view.
|
||||
if (!saveDir.empty()) {
|
||||
// Zero-pad to 4 digits (lexicographic sort == capture order) without
|
||||
// snprintf: some included headers #define snprintf -> _snprintf.
|
||||
std::string idx = std::to_string(frames);
|
||||
if (idx.size() < 4) idx.insert(0, 4 - idx.size(), '0');
|
||||
// Full-res frame -> frames/ (MP4 input). Already JPEG: direct dump.
|
||||
std::ofstream f(framesDir + "/" + idx + ".jpg", std::ios::binary);
|
||||
f.write(jpeg.data(), static_cast<std::streamsize>(jpeg.size()));
|
||||
f.close();
|
||||
// Downscaled preview -> saveDir (chat-friendly viewing).
|
||||
std::vector<uchar> buf(jpeg.begin(), jpeg.end());
|
||||
cv::Mat full = cv::imdecode(buf, cv::IMREAD_COLOR);
|
||||
if (!full.empty()) {
|
||||
const int previewW = 960;
|
||||
cv::Mat preview;
|
||||
cv::resize(full, preview,
|
||||
cv::Size(previewW, full.rows * previewW / full.cols));
|
||||
cv::imwrite(saveDir + "/preview_" + idx + ".jpg", preview);
|
||||
}
|
||||
}
|
||||
|
||||
// Report every frame for the first few, then every 10th to stay readable.
|
||||
if (frames <= 5 || frames % 10 == 0) {
|
||||
std::cout << " frame " << frames << ": " << width << "x" << height
|
||||
<< " pts=" << pts << " jpeg=" << jpeg.size() << "B"
|
||||
<< " grab=" << grabMs << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const long long elapsed = elapsedMs();
|
||||
StopRTSP(&client);
|
||||
ReleaseANSRTSPHandle(&client);
|
||||
ANSOPENCV::DeinitCameraNetwork();
|
||||
|
||||
std::cout << " polls=" << polls << " frames=" << frames
|
||||
<< " elapsed=" << elapsed << "ms" << std::endl;
|
||||
if (frames > 0) {
|
||||
const double fps = elapsed > 0 ? frames * 1000.0 / elapsed : 0.0;
|
||||
std::cout << " resolution=" << firstW << "x" << firstH
|
||||
<< " avgJpeg=" << (totalJpegBytes / frames) << "B"
|
||||
<< " avgGrab=" << (totalGrabMs / frames) << "ms"
|
||||
<< " ~fps=" << fps
|
||||
<< " ptsDelta=" << (lastPts - firstPts) << std::endl;
|
||||
}
|
||||
|
||||
check("RTSP received >=1 frame", frames > 0,
|
||||
std::to_string(frames) + " frames in " + std::to_string(elapsed) + "ms");
|
||||
if (frames > 0) {
|
||||
check("RTSP frame has valid resolution", firstW > 0 && firstH > 0,
|
||||
std::to_string(firstW) + "x" + std::to_string(firstH));
|
||||
}
|
||||
|
||||
// Encode the captured frames into a short MP4 clip using ANSCV's own
|
||||
// hardware (NVENC) encoder, so the stream can actually be watched as video.
|
||||
// maxWidth=1280 downscales the 4K stills to a manageable file; playback fps
|
||||
// is fixed at 5 so a small burst yields a watchable clip.
|
||||
if (!saveDir.empty() && frames >= 2) {
|
||||
const std::string mp4Path = saveDir + "/rtsp_clip.mp4";
|
||||
const int playbackFps = 5;
|
||||
std::cout << " encoding MP4 (" << frames << " frames -> " << mp4Path
|
||||
<< ", maxW=1280, " << playbackFps << " fps)..." << std::endl;
|
||||
const int rc = ANSCV_ImagesToMP4HW_S(framesDir.c_str(), mp4Path.c_str(),
|
||||
1280, playbackFps);
|
||||
bool ok = rc != 0 && std::filesystem::exists(mp4Path);
|
||||
std::string detail = "rc=" + std::to_string(rc);
|
||||
if (ok) {
|
||||
const auto sz = std::filesystem::file_size(mp4Path);
|
||||
detail += ", " + std::to_string(sz) + " bytes";
|
||||
}
|
||||
check("RTSP frames encoded to MP4", ok, detail);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "==== ANSCV Console Test ====" << std::endl;
|
||||
|
||||
// Optional RTSP target. argv[1] = URL, argv[2] = max frames (default 60),
|
||||
// argv[3] = directory to save captured frames into (optional).
|
||||
const std::string rtspUrl = (argc > 1) ? argv[1] : "";
|
||||
const int rtspMaxFrames = (argc > 2) ? std::atoi(argv[2]) : 60;
|
||||
const std::string rtspSaveDir = (argc > 3) ? argv[3] : "";
|
||||
|
||||
ANSOPENCV cv_;
|
||||
const bool licensed = cv_.Init(""); // empty license key, matching existing tests
|
||||
std::cout << "Init(\"\") license valid: " << (licensed ? "yes" : "no") << std::endl;
|
||||
|
||||
const cv::Mat src = MakeTestImage();
|
||||
std::cout << "Source image: " << dims(src) << std::endl;
|
||||
std::cout << "-- Geometry / resize --" << std::endl;
|
||||
|
||||
{
|
||||
cv::Mat out;
|
||||
cv_.ImageResize(src, 320, 240, out);
|
||||
check("ImageResize 320x240", out.cols == 320 && out.rows == 240, dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out;
|
||||
cv_.ImageResizeWithRatio(src, 320, out);
|
||||
check("ImageResizeWithRatio width=320", out.cols == 320 && !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.ImageResizeV2(src, 200);
|
||||
check("ImageResizeV2 width=200", !out.empty() && out.cols == 200, dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.ImageCrop(src, cv::Rect(10, 20, 100, 80));
|
||||
check("ImageCrop 100x80", out.cols == 100 && out.rows == 80, dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.RotateImage(src, 90.0);
|
||||
check("RotateImage 90deg", !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.FlipImage(src, 1); // horizontal
|
||||
check("FlipImage horizontal", out.size() == src.size() && !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
// ShiftImage expands the canvas by |shiftX| x |shiftY| to keep all
|
||||
// pixels after the translation (640+30, 480+40).
|
||||
cv::Mat out = cv_.ShiftImage(src, 30, 40);
|
||||
check("ShiftImage (30,40) expands canvas",
|
||||
out.cols == src.cols + 30 && out.rows == src.rows + 40, dims(out));
|
||||
}
|
||||
|
||||
std::cout << "-- Color / enhancement --" << std::endl;
|
||||
{
|
||||
cv::Mat out = cv_.ToGray(src);
|
||||
check("ToGray -> 1 channel", out.channels() == 1 && !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.ImageContrastEnhancement(src);
|
||||
check("ImageContrastEnhancement", !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.ImageWhiteBalance(src);
|
||||
check("ImageWhiteBalance", !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.ImageDarkEnhancement(src, 1.5);
|
||||
check("ImageDarkEnhancement x1.5", !out.empty(), dims(out));
|
||||
}
|
||||
|
||||
std::cout << "-- Noise augmentation --" << std::endl;
|
||||
{
|
||||
cv::Mat out = cv_.AddGaussianNoise(src, 0.0, 20.0);
|
||||
check("AddGaussianNoise", out.size() == src.size() && !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.AddSaltAndPepperNoise(src, 0.02);
|
||||
check("AddSaltAndPepperNoise", out.size() == src.size() && !out.empty(), dims(out));
|
||||
}
|
||||
{
|
||||
cv::Mat out = cv_.AddSpeckleNoise(src, 0.1);
|
||||
check("AddSpeckleNoise", out.size() == src.size() && !out.empty(), dims(out));
|
||||
}
|
||||
|
||||
std::cout << "-- Encode --" << std::endl;
|
||||
{
|
||||
std::string bin = cv_.MatToBinaryData(src);
|
||||
check("MatToBinaryData non-empty", !bin.empty(),
|
||||
std::to_string(bin.size()) + " bytes");
|
||||
}
|
||||
{
|
||||
std::string b64 = cv_.MatToBase64(src);
|
||||
check("MatToBase64 non-empty", !b64.empty(),
|
||||
std::to_string(b64.size()) + " chars");
|
||||
}
|
||||
|
||||
std::cout << "-- Parse / serialize --" << std::endl;
|
||||
{
|
||||
// GetBoundingBoxes parses a JSON object with a "results" array, each
|
||||
// entry carrying x/y/width/height.
|
||||
const std::string boxesJson =
|
||||
R"({"results":[)"
|
||||
R"({"x":10,"y":20,"width":30,"height":40},)"
|
||||
R"({"x":100,"y":110,"width":50,"height":60}]})";
|
||||
std::vector<cv::Rect> boxes = cv_.GetBoundingBoxes(boxesJson);
|
||||
bool ok = boxes.size() == 2 &&
|
||||
boxes[0] == cv::Rect(10, 20, 30, 40) &&
|
||||
boxes[1] == cv::Rect(100, 110, 50, 60);
|
||||
check("GetBoundingBoxes parses 2 boxes", ok,
|
||||
std::to_string(boxes.size()) + " boxes");
|
||||
}
|
||||
{
|
||||
std::vector<DetectionObject> dets(2);
|
||||
dets[0].classId = 1; dets[0].className = "person";
|
||||
dets[0].confidence = 0.9f; dets[0].box = cv::Rect(10, 10, 40, 80);
|
||||
dets[1].classId = 2; dets[1].className = "car";
|
||||
dets[1].confidence = 0.8f; dets[1].box = cv::Rect(60, 60, 100, 50);
|
||||
std::string json = cv_.VectorDetectionToJsonString(dets);
|
||||
check("VectorDetectionToJsonString non-empty", !json.empty(),
|
||||
std::to_string(json.size()) + " chars");
|
||||
}
|
||||
|
||||
if (!rtspUrl.empty()) {
|
||||
RtspConsoleTest(rtspUrl, rtspMaxFrames, rtspSaveDir);
|
||||
} else {
|
||||
std::cout << "-- RTSP capture --" << std::endl;
|
||||
std::cout << " (skipped: no RTSP URL given; pass one as the first "
|
||||
"argument to run it)" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "============================" << std::endl;
|
||||
std::cout << "Result: " << g_pass << " passed, " << g_fail << " failed."
|
||||
<< std::endl;
|
||||
|
||||
// NOTE: at process exit one of the loaded DLLs throws a C++ exception
|
||||
// during DllMain(PROCESS_DETACH) (observed exit code 0xE06D7363),
|
||||
// regardless of test outcome. All test work is complete by this point, so
|
||||
// force a deterministic exit code for CI. TerminateProcess is used because
|
||||
// both return and quick_exit go through ExitProcess, which still triggers
|
||||
// the faulty DLL-detach path; TerminateProcess skips it.
|
||||
std::cout.flush();
|
||||
std::cerr.flush();
|
||||
#ifdef _WIN32
|
||||
::TerminateProcess(::GetCurrentProcess(), static_cast<UINT>(g_fail));
|
||||
#endif
|
||||
return g_fail;
|
||||
}
|
||||
@@ -731,7 +731,7 @@ int ANSVISTest() {
|
||||
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\ANSVIS_Issues\\face.mp4";
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\TestFR\\Face31.mp4";
|
||||
std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||
std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\TestFR\\school1.mp4";// "C:\\ProgramData\\ANSCENTER\\Shared\\classroom.mp4";
|
||||
|
||||
const char* configFilePath = "";
|
||||
@@ -1631,15 +1631,113 @@ int TestCompleteFR1() {
|
||||
std::cout << "End of program.\n";
|
||||
return 1;
|
||||
}
|
||||
int main()
|
||||
// ---- SCRFD-TRT face-detection reproduction on a video (headless) ----------
|
||||
int SCRFDVideoRepro()
|
||||
{
|
||||
std::string licenseKey = "";
|
||||
const char* configFilePath = "";
|
||||
std::string databaseFilePath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ANSFR.db";
|
||||
std::string recognizerFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ServerOptimised\\ANS_FaceRecognizer_v1.1_NVIDIAGeForceRTX3070LaptopGPU.zip";
|
||||
std::string detectorFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFDET\\ServerOptimised\\ANS_GenericFD(GPU)_v1.0_NVIDIAGeForceRTX3070LaptopGPU.zip";
|
||||
std::string videoPath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||
|
||||
std::cout << "[REPRO] detector = " << detectorFile << std::endl;
|
||||
std::cout << "[REPRO] recognizer = " << recognizerFile << std::endl;
|
||||
|
||||
ANSCENTER::ANSFacialRecognition* h = nullptr;
|
||||
int cr = CreateANSRFHandle(&h, licenseKey.c_str(), configFilePath,
|
||||
databaseFilePath.c_str(), recognizerFile.c_str(),
|
||||
detectorFile.c_str(), 0.3, 1, 1, 1);
|
||||
std::cout << "[REPRO] CreateANSRFHandle = " << cr << std::endl;
|
||||
|
||||
int le = LoadANSRFEngine(&h);
|
||||
std::cout << "[REPRO] LoadANSRFEngine = " << le << std::endl;
|
||||
|
||||
cv::VideoCapture cap(videoPath);
|
||||
if (!cap.isOpened()) { std::cout << "[REPRO] ERROR: cannot open video " << videoPath << std::endl; return 1; }
|
||||
|
||||
const std::string win = "ANSFR - SCRFD/TensorRT Face Detection (ESC to quit)";
|
||||
cv::namedWindow(win, cv::WINDOW_NORMAL);
|
||||
cv::resizeWindow(win, 1280, 720);
|
||||
|
||||
int frameIdx = 0, totalDet = 0, saved = 0;
|
||||
cv::Mat frame;
|
||||
while (cap.read(frame)) {
|
||||
if (frame.empty()) break;
|
||||
++frameIdx;
|
||||
if (frameIdx > 300) break; // proof run: first 300 frames
|
||||
unsigned int bufLen = 0;
|
||||
unsigned char* jpg = ANSCENTER::ANSFRHelper::CVMatToBytes(frame, bufLen);
|
||||
std::string res = RunANSRFInferenceBinary(&h, jpg, frame.cols, frame.rows);
|
||||
delete jpg;
|
||||
|
||||
int n = 0;
|
||||
try {
|
||||
boost::property_tree::ptree pt; std::stringstream ss; ss << res;
|
||||
boost::property_tree::read_json(ss, pt);
|
||||
if (pt.count("results")) {
|
||||
BOOST_FOREACH(const boost::property_tree::ptree::value_type& child, pt.get_child("results")) {
|
||||
const boost::property_tree::ptree& r = child.second;
|
||||
const int uid = GetData<int>(r, "user_id");
|
||||
const std::string uname = GetData<std::string>(r, "user_name");
|
||||
const float x = GetData<float>(r, "x");
|
||||
const float y = GetData<float>(r, "y");
|
||||
const float w = GetData<float>(r, "width");
|
||||
const float ht = GetData<float>(r, "height");
|
||||
cv::rectangle(frame, cv::Rect((int)x, (int)y, (int)w, (int)ht), cv::Scalar(0, 255, 0), 2);
|
||||
cv::putText(frame, cv::format("%s:%d", uname.c_str(), uid), cv::Point((int)x, (int)y - 8),
|
||||
cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
totalDet += n;
|
||||
|
||||
cv::putText(frame, cv::format("Frame %d faces detected = %d", frameIdx, n),
|
||||
cv::Point(25, 45), cv::FONT_HERSHEY_SIMPLEX, 1.1, cv::Scalar(0, 255, 255), 2, cv::LINE_AA);
|
||||
if (frameIdx % 30 == 0) {
|
||||
std::string fp = cv::format("C:\\Programs\\DemoAssets\\ANSFR_proof_frame_%04d_faces%d.jpg", frameIdx, n);
|
||||
cv::imwrite(fp, frame);
|
||||
++saved;
|
||||
std::cout << "[REPRO] saved annotated frame: " << fp << std::endl;
|
||||
}
|
||||
cv::imshow(win, frame);
|
||||
if (cv::waitKey(1) == 27) break; // ESC to quit
|
||||
}
|
||||
std::cout << "[REPRO] played " << frameIdx << " frames, total faces drawn = " << totalDet
|
||||
<< ", saved " << saved << " annotated images to C:\\Programs\\DemoAssets\\" << std::endl;
|
||||
cap.release();
|
||||
cv::destroyAllWindows();
|
||||
// NOTE: intentionally skipping ReleaseANSRFHandle/cudaDeviceReset here — there is
|
||||
// a known C++ exception at teardown (0xE06D7363); process exit reclaims everything.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// ── GPU visibility bisect (Blackwell Myelin l2cm debugging) ─────────────
|
||||
// Usage: ANSFR-UnitTest.exe --gpu 0 → only GPU0 visible (Test A, display GPU)
|
||||
// ANSFR-UnitTest.exe --gpu 1 → only GPU1 visible (Test B, headless GPU)
|
||||
// ANSFR-UnitTest.exe → all GPUs (default behaviour)
|
||||
// Sets CUDA_VISIBLE_DEVICES before the first CUDA call in this process, so
|
||||
// the CUDA runtime only enumerates the chosen physical GPU (it becomes
|
||||
// device 0 inside the process).
|
||||
for (int i = 1; i + 1 < argc; ++i) {
|
||||
if (std::string(argv[i]) == "--gpu") {
|
||||
_putenv_s("CUDA_VISIBLE_DEVICES", argv[i + 1]);
|
||||
std::cout << "==============================================\n"
|
||||
<< " GPU BISECT: CUDA_VISIBLE_DEVICES=" << argv[i + 1] << "\n"
|
||||
<< " (only this physical GPU is visible to CUDA)\n"
|
||||
<< "==============================================" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//FaceDetectorTest();
|
||||
//TestFaceRecognition();
|
||||
//TestCompleteFR1();
|
||||
|
||||
//ANSVISImageTest();
|
||||
//ANSVISTest();
|
||||
ANSVISTest();
|
||||
//ANSVISTestFilePlayer();
|
||||
// ANSVISRecordingTest();
|
||||
//FRStressTest();
|
||||
@@ -1653,8 +1751,7 @@ int main()
|
||||
// TestCompleteFR();
|
||||
//TestFaceRecognition();
|
||||
//FaceRecognitionBenchmark();
|
||||
ANSVISTestCPU_Lightweight();
|
||||
//ANSVISTestCPU();
|
||||
std::cin.get();
|
||||
//SCRFDVideoRepro();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1647,6 +1647,9 @@ int HelmetDetectionTest() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// ElasticGPUTest — Verify elastic pool, round-robin dispatch, multi-GPU,
|
||||
// concurrent inference, and idle-slot cleanup.
|
||||
@@ -2222,14 +2225,24 @@ int RTMPOSETest() {
|
||||
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FireNSmokeTest() {
|
||||
int modelType = 16; // Custom model type for helmet detection, adjust as needed based on how the model is set up in the engine
|
||||
std::string onnxclmodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke_v2.0\\ANS_FireSmoke_v2.0.zip";
|
||||
std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\BCA1.mp4";
|
||||
|
||||
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
//FallDetectorTest();
|
||||
//ALPROD_Test();
|
||||
//FireNSmokeTest();
|
||||
FireNSmokeTest();
|
||||
//ElasticGPUTest();
|
||||
RTMPOSETest_CPP();
|
||||
//RTMPOSETest_CPP();
|
||||
//RTMPOSETest();
|
||||
//YOLO26SEGYolo11Test();
|
||||
//YOLO26POSEYolo11Test();
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// windows.h must be included before any header that pulls in wincrypt.h
|
||||
// (Chilkat, OpenCV transitively). HKEY/RegOpenKeyExW are used by the
|
||||
// watermark readout in GetEventLogErrorsWatermarkTest.
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include "ANSUtilities.h"
|
||||
#include "ANSLLM.h"
|
||||
@@ -386,6 +390,226 @@ int ANSLLMOllamaTest() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Exercise ANSCENTER::ANSUtilities::ScanDevices — discovers AIBOX boxes and
|
||||
// ANSVIS servers on the local LAN via UDP multicast + HTTP /ServerApi sweep.
|
||||
// Run on a machine connected to the same subnet as at least one device.
|
||||
// DebugView (filter "[ANSDISC]") shows per-device hits and per-interface joins.
|
||||
int ScanDevicesTest()
|
||||
{
|
||||
std::cout << "\n===== ScanDevices (AIBOX / ANSVIS discovery) =====" << std::endl;
|
||||
|
||||
// 1) Direct static C++ call.
|
||||
const int timeoutMs = 5000;
|
||||
std::cout << "Scanning for " << timeoutMs << " ms ..." << std::endl;
|
||||
auto devices = ANSCENTER::ANSUtilities::ScanDevices(timeoutMs);
|
||||
|
||||
std::cout << "Found " << devices.size() << " device(s):" << std::endl;
|
||||
for (const auto& d : devices) {
|
||||
const char* src = (d.source == 3) ? "both"
|
||||
: (d.source == 2) ? "sweep"
|
||||
: (d.source == 1) ? "multicast"
|
||||
: "unknown";
|
||||
std::cout << " " << d.ip << ":" << d.port
|
||||
<< " name=\"" << d.name << "\""
|
||||
<< " firmware=\"" << d.firmware << "\""
|
||||
<< " source=" << src << std::endl;
|
||||
}
|
||||
|
||||
// 2) Exercise the C extern entrypoint that LabVIEW uses.
|
||||
std::string json;
|
||||
int rc = ScanANSDevicesCpp(timeoutMs, json);
|
||||
std::cout << "\nScanANSDevicesCpp rc=" << rc << " json=" << json << std::endl;
|
||||
|
||||
return static_cast<int>(devices.size());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Example: ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents
|
||||
//
|
||||
// Reads every Error-level event written by the "ANSLogger" source in the
|
||||
// Windows Application event log. Output is a UTF-8 string with one event
|
||||
// per line in the form:
|
||||
// "<DD/MM/YYYY h:mm:ss tt>: <event data>\n"
|
||||
//
|
||||
// Three usage patterns are demonstrated below:
|
||||
// 1. Read everything as one blob — simplest, what LabVIEW will do.
|
||||
// 2. Iterate line-by-line and split out timestamp + message — useful for
|
||||
// programmatic filtering, alerting, or writing to your own sink.
|
||||
// 3. Destructive clear (commented out) — wipes the entire Application
|
||||
// channel; only use if you genuinely want every event from every
|
||||
// source removed. Requires Administrator privileges.
|
||||
//
|
||||
// To verify against Event Viewer:
|
||||
// eventvwr.msc → Windows Logs → Application → Filter Current Log:
|
||||
// Event sources = ANSLogger, Event level = Error
|
||||
// The number this function returns must match Event Viewer's "Number of
|
||||
// events" line shown above the list.
|
||||
// ============================================================================
|
||||
int GetEventLogErrorsTest()
|
||||
{
|
||||
std::cout << "\n===== GetANSLoggerErrorEvents (Windows Event Log) =====" << std::endl;
|
||||
|
||||
// ── 1. Read every Error event from ANSLogger ────────────────────────────
|
||||
const bool kClearAfterRead = false; // NEVER true unless you really mean it
|
||||
std::string events = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(kClearAfterRead);
|
||||
|
||||
// Count events (one per newline).
|
||||
int lineCount = 0;
|
||||
for (char c : events) if (c == '\n') ++lineCount;
|
||||
std::cout << "Read " << lineCount << " ANSLogger error event(s), "
|
||||
<< events.size() << " bytes total" << std::endl;
|
||||
|
||||
// ── 2. Iterate line-by-line: extract timestamp + message ────────────────
|
||||
// Format is "<timestamp>: <message>" — split on the first ": ".
|
||||
// Prints the most recent 5 events so output isn't overwhelming.
|
||||
std::cout << "\n--- last 5 events (timestamp / message) ---" << std::endl;
|
||||
std::vector<std::pair<std::string, std::string>> parsed;
|
||||
parsed.reserve(static_cast<size_t>(lineCount));
|
||||
size_t lineStart = 0;
|
||||
for (size_t i = 0; i < events.size(); ++i) {
|
||||
if (events[i] != '\n') continue;
|
||||
std::string line = events.substr(lineStart, i - lineStart);
|
||||
lineStart = i + 1;
|
||||
auto sep = line.find(": ");
|
||||
if (sep == std::string::npos) {
|
||||
parsed.emplace_back(std::string(), std::move(line));
|
||||
} else {
|
||||
parsed.emplace_back(line.substr(0, sep), line.substr(sep + 2));
|
||||
}
|
||||
}
|
||||
const size_t showFrom = parsed.size() > 5 ? parsed.size() - 5 : 0;
|
||||
for (size_t i = showFrom; i < parsed.size(); ++i) {
|
||||
// Truncate noisy messages so the console stays readable.
|
||||
std::string msg = parsed[i].second;
|
||||
if (msg.size() > 120) msg = msg.substr(0, 117) + "...";
|
||||
std::cout << " [" << parsed[i].first << "] " << msg << std::endl;
|
||||
}
|
||||
|
||||
// ── 3. C extern entry point (this is what LabVIEW calls) ────────────────
|
||||
// Signature: int GetANSLoggerErrorEventsCpp(int clearAfterRead, std::string& out)
|
||||
// Passing 0 for clearAfterRead = read only.
|
||||
std::string fromExtern;
|
||||
int rc = GetANSLoggerErrorEventsCpp(0, fromExtern);
|
||||
std::cout << "\nGetANSLoggerErrorEventsCpp rc=" << rc
|
||||
<< " bytes=" << fromExtern.size() << std::endl;
|
||||
|
||||
// ── 4. DIAGNOSTIC: read → read+clear → read, prove whether the clear
|
||||
// flag actually does anything (and if not, capture the OS error).
|
||||
{
|
||||
std::cout << "\n--- clear-flag diagnostic ---" << std::endl;
|
||||
auto countLines = [](const std::string& s) {
|
||||
int n = 0;
|
||||
for (char c : s) if (c == '\n') ++n;
|
||||
return n;
|
||||
};
|
||||
|
||||
std::string before = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(false);
|
||||
std::cout << " before clear : " << countLines(before) << " events" << std::endl;
|
||||
|
||||
std::string cleared = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(true);
|
||||
std::cout << " with clear=true call returned: "
|
||||
<< countLines(cleared) << " events" << std::endl;
|
||||
|
||||
std::string after = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(false);
|
||||
std::cout << " after clear : " << countLines(after)
|
||||
<< " events (should be 0 if clear worked)" << std::endl;
|
||||
|
||||
const int beforeN = countLines(before);
|
||||
const int afterN = countLines(after);
|
||||
if (beforeN == 0) {
|
||||
std::cout << " RESULT: inconclusive (no events to clear). "
|
||||
"Check stderr above for the actual EvtClearLog status."
|
||||
<< std::endl;
|
||||
} else if (afterN == 0) {
|
||||
std::cout << " RESULT: clear SUCCEEDED — process was elevated."
|
||||
<< std::endl;
|
||||
} else if (afterN >= beforeN) {
|
||||
std::cout << " RESULT: clear FAILED. "
|
||||
"Check stderr above for the GetLastError code "
|
||||
"(5 = ACCESS_DENIED — re-run as Administrator)."
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << " RESULT: partial clear (" << beforeN << " -> "
|
||||
<< afterN << "). Likely a concurrent writer."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Example: ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall
|
||||
//
|
||||
// Watermark-based variant. Two consecutive calls demonstrate the skip:
|
||||
// 1st call: returns every Error event from ANSLogger (same as the full read)
|
||||
// 2nd call: returns 0 (or only events written between the two calls)
|
||||
// The watermark is stored at
|
||||
// HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger (REG_QWORD)
|
||||
// To force a re-read of everything, delete that registry value.
|
||||
// ============================================================================
|
||||
int GetEventLogErrorsWatermarkTest()
|
||||
{
|
||||
std::cout << "\n===== GetANSLoggerErrorEventsSinceLastCall (watermark) ====="
|
||||
<< std::endl;
|
||||
auto countLines = [](const std::string& s) {
|
||||
int n = 0;
|
||||
for (char c : s) if (c == '\n') ++n;
|
||||
return n;
|
||||
};
|
||||
|
||||
// Read the current watermark so we can show it before and after.
|
||||
auto readWatermark = []() -> unsigned long long {
|
||||
HKEY hKey = nullptr;
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
L"Software\\ANSCENTER\\ANSUtilities\\EventLogWatermark",
|
||||
0, KEY_READ, &hKey) != ERROR_SUCCESS) return 0ULL;
|
||||
unsigned long long v = 0;
|
||||
DWORD sz = sizeof(v), tp = 0;
|
||||
LONG rc = RegQueryValueExW(hKey, L"ANSLogger", nullptr, &tp,
|
||||
reinterpret_cast<LPBYTE>(&v), &sz);
|
||||
RegCloseKey(hKey);
|
||||
return (rc == ERROR_SUCCESS && tp == REG_QWORD) ? v : 0ULL;
|
||||
};
|
||||
|
||||
std::cout << " watermark before: " << readWatermark() << std::endl;
|
||||
|
||||
std::string first =
|
||||
ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(false);
|
||||
std::cout << " 1st call returned: " << countLines(first) << " event(s)"
|
||||
<< std::endl;
|
||||
std::cout << " watermark after 1st call: " << readWatermark() << std::endl;
|
||||
|
||||
std::string second =
|
||||
ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(false);
|
||||
std::cout << " 2nd call returned: " << countLines(second)
|
||||
<< " event(s) (should be 0 if no new errors were logged "
|
||||
"between the two calls)" << std::endl;
|
||||
|
||||
if (countLines(second) == 0 && countLines(first) > 0) {
|
||||
std::cout << " RESULT: watermark works — duplicates suppressed."
|
||||
<< std::endl;
|
||||
} else if (countLines(first) == 0) {
|
||||
std::cout << " RESULT: nothing to test (no ANSLogger errors in log)."
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << " RESULT: 2nd call returned " << countLines(second)
|
||||
<< " event(s) — either new errors arrived between calls, "
|
||||
"or the watermark didn't persist." << std::endl;
|
||||
}
|
||||
|
||||
// Note: passing the LabVIEW extern below as well so its parameter wiring
|
||||
// is exercised. Pass 0 = no clear; clear path is identical to the
|
||||
// already-tested admin-required version in GetEventLogErrorsTest.
|
||||
std::string fromExtern;
|
||||
int rc = GetANSLoggerErrorEventsSinceLastCallCpp(0, fromExtern);
|
||||
std::cout << " GetANSLoggerErrorEventsSinceLastCallCpp rc=" << rc
|
||||
<< " bytes=" << fromExtern.size()
|
||||
<< " (should be 0 — already watermarked above)" << std::endl;
|
||||
|
||||
return countLines(first);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//ANSLLMOllamaTest();
|
||||
@@ -393,11 +617,15 @@ int main()
|
||||
//std::cout << "===== MinIO (path-style) =====" << std::endl;
|
||||
//ANSFTechMinIOTest();
|
||||
|
||||
std::cout << "\n===== AWS S3 (virtual-host) =====" << std::endl;
|
||||
ANSAWSTest();
|
||||
//std::cout << "\n===== AWS S3 (virtual-host) =====" << std::endl;
|
||||
//ANSAWSTest();
|
||||
//ANSLLMTest();
|
||||
//SendEmailExample();
|
||||
//uploadFileToGoogleStorage();
|
||||
// EncrypyionExample();
|
||||
// EncrypyionExample();
|
||||
|
||||
ScanDevicesTest();
|
||||
GetEventLogErrorsTest();
|
||||
GetEventLogErrorsWatermarkTest();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Reports versions and ABI compatibility of the inference runtime stack
|
||||
(CUDA, cuDNN, TensorRT, OpenVINO, DirectML, ONNX Runtime per-EP) inside an
|
||||
ANSCENTER "Shared" folder, and optionally diffs two such folders.
|
||||
|
||||
.DESCRIPTION
|
||||
Rerun this after upgrading any DLL in SharedCore to confirm the pieces still
|
||||
line up. It does three things:
|
||||
1. Reads the version of every key library.
|
||||
- ORT: FileVersion of ep\<x>\onnxruntime.dll
|
||||
- OpenVINO / DirectML / cuDNN: FileVersion resource
|
||||
- CUDA components: inferred from the versioned file name (cudart64_13 => CUDA 13)
|
||||
- TensorRT: nvinfer_*.dll has NO version resource, so we p/invoke its
|
||||
exported getInferLibVersion() (packed int, e.g. 101501 => 10.15.1).
|
||||
2. Uses dumpbin /DEPENDENTS (if Visual Studio is installed) to list which
|
||||
CUDA / cuDNN / TensorRT / OpenVINO / DirectML DLLs each EP actually
|
||||
imports, and verifies every one exists in the root.
|
||||
3. Flags gaps: empty ep\cpu with no flat fallback, missing dependencies,
|
||||
ORT-version split across EP folders.
|
||||
|
||||
NOTE: the TensorRT probe uses a plain [DllImport] to nvinfer's exported
|
||||
getInferLibVersion(). It deliberately avoids LoadLibrary+GetProcAddress+
|
||||
GetDelegateForFunctionPointer, because that dynamic-resolution pattern trips
|
||||
Windows Defender AMSI ("malicious content") and blocks the whole script.
|
||||
|
||||
.PARAMETER Root
|
||||
The Shared folder to inspect. Default: C:\Projects\SharedCore
|
||||
|
||||
.PARAMETER CompareWith
|
||||
Optional second Shared folder to diff against Root (e.g. the deployed
|
||||
C:\ProgramData\ANSCENTER\Shared). Reports any version mismatches.
|
||||
|
||||
.PARAMETER SkipTensorRT
|
||||
Skip the TensorRT p/invoke probe (useful if your AV still objects, or to run
|
||||
purely on file-version metadata).
|
||||
|
||||
.EXAMPLE
|
||||
.\Check-SharedCoreVersions.ps1
|
||||
|
||||
.EXAMPLE
|
||||
.\Check-SharedCoreVersions.ps1 -Root C:\Projects\SharedCore `
|
||||
-CompareWith C:\ProgramData\ANSCENTER\Shared
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $Root = "C:\Projects\SharedCore",
|
||||
[string] $CompareWith,
|
||||
[switch] $SkipTensorRT
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ----------------------------------------------------------------------------
|
||||
function Get-FileVer([string]$path) {
|
||||
if (Test-Path -LiteralPath $path) { (Get-Item -LiteralPath $path).VersionInfo.FileVersion }
|
||||
else { $null }
|
||||
}
|
||||
|
||||
# Windows PowerShell 5.1 has no ?? operator - use this instead.
|
||||
function Coalesce($value, $fallback) {
|
||||
if ($value) { $value } else { $fallback }
|
||||
}
|
||||
|
||||
function Find-Dumpbin {
|
||||
$candidates = Get-ChildItem `
|
||||
"C:\Program Files\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe", `
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe" `
|
||||
-ErrorAction SilentlyContinue | Sort-Object FullName -Descending
|
||||
if ($candidates) { return $candidates[0].FullName }
|
||||
return $null
|
||||
}
|
||||
|
||||
# Declares plain DllImports to nvinfer's getInferLibVersion. Compiled once per
|
||||
# session. The DLLs are resolved via PATH, so callers must put the root dir on
|
||||
# PATH before invoking (Get-TensorRTVersion does this).
|
||||
function Initialize-TrtProbe {
|
||||
if ('AnsTrtProbe.Lib' -as [type]) { return }
|
||||
Add-Type -Namespace AnsTrtProbe -Name Lib -MemberDefinition @'
|
||||
[System.Runtime.InteropServices.DllImport("nvinfer_dispatch_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
||||
public static extern int Dispatch10();
|
||||
[System.Runtime.InteropServices.DllImport("nvinfer_lean_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
||||
public static extern int Lean10();
|
||||
[System.Runtime.InteropServices.DllImport("nvinfer_10.dll", EntryPoint = "getInferLibVersion", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
|
||||
public static extern int Full10();
|
||||
'@
|
||||
}
|
||||
|
||||
# Returns the packed TensorRT version int (e.g. 101501) or $null.
|
||||
function Get-TensorRTVersion([string]$dir) {
|
||||
if ($SkipTensorRT) { return $null }
|
||||
if (-not (Get-ChildItem -LiteralPath $dir -Filter 'nvinfer*_10.dll' -ErrorAction SilentlyContinue)) {
|
||||
return $null
|
||||
}
|
||||
$origPath = $env:Path
|
||||
$env:Path = "$dir;$env:Path" # so the stub and its deps resolve
|
||||
try {
|
||||
Initialize-TrtProbe
|
||||
foreach ($m in 'Dispatch10','Lean10','Full10') {
|
||||
try {
|
||||
$v = [AnsTrtProbe.Lib]::$m()
|
||||
if ($v -gt 0) { return $v }
|
||||
} catch { }
|
||||
}
|
||||
return $null
|
||||
} finally {
|
||||
$env:Path = $origPath
|
||||
}
|
||||
}
|
||||
|
||||
function Format-TensorRT($raw) {
|
||||
if (-not $raw) { return "UNKNOWN (probe skipped or failed)" }
|
||||
$maj = [math]::Floor($raw / 10000)
|
||||
$min = [math]::Floor(($raw % 10000) / 100)
|
||||
$pat = $raw % 100
|
||||
return "$maj.$min.$pat (raw $raw)"
|
||||
}
|
||||
|
||||
# Returns the lower-cased set of dependency DLLs (CUDA/TRT/OV/DML family) that
|
||||
# $path imports, via dumpbin /DEPENDENTS. Empty array if dumpbin unavailable.
|
||||
function Get-Deps([string]$dumpbin, [string]$path) {
|
||||
if (-not $dumpbin -or -not (Test-Path -LiteralPath $path)) { return @() }
|
||||
$rx = '(?i)cudart|cublas|cudnn|cufft|cusparse|cusolver|nvinfer|nvonnx|nvrtc|directml|openvino'
|
||||
& $dumpbin /DEPENDENTS $path 2>$null |
|
||||
Select-String -Pattern '^\s+\S+\.dll\s*$' |
|
||||
ForEach-Object { $_.Line.Trim().ToLower() } |
|
||||
Where-Object { $_ -match $rx } |
|
||||
Sort-Object -Unique
|
||||
}
|
||||
|
||||
$epMap = [ordered]@{
|
||||
"cpu" = "CPU"
|
||||
"cuda" = "NVIDIA_GPU (CUDA + TensorRT)"
|
||||
"directml" = "AMD_GPU (DirectML)"
|
||||
"openvino" = "OPENVINO_GPU (Intel)"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Inspect one root
|
||||
# ----------------------------------------------------------------------------
|
||||
function Inspect-Root([string]$root) {
|
||||
if (-not (Test-Path -LiteralPath $root)) {
|
||||
Write-Host "ERROR: root not found: $root" -ForegroundColor Red
|
||||
return $null
|
||||
}
|
||||
$dumpbin = Find-Dumpbin
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=================================================================="
|
||||
Write-Host " Shared root : $root"
|
||||
Write-Host " dumpbin : $(if($dumpbin){$dumpbin}else{'NOT FOUND - dependency checks skipped'})"
|
||||
Write-Host "=================================================================="
|
||||
|
||||
$result = [ordered]@{ Root = $root; Ort = [ordered]@{} }
|
||||
|
||||
# ---- Core libraries -----------------------------------------------------
|
||||
$trtRaw = Get-TensorRTVersion $root
|
||||
$result.TensorRT = $trtRaw
|
||||
Write-Host ""
|
||||
Write-Host "-- Core runtime libraries -----------------------------------------"
|
||||
Write-Host ("{0,-14} {1}" -f "TensorRT:", (Format-TensorRT $trtRaw))
|
||||
Write-Host ("{0,-14} {1}" -f "OpenVINO:", (Coalesce (Get-FileVer (Join-Path $root 'openvino.dll')) 'MISSING'))
|
||||
Write-Host ("{0,-14} {1}" -f "DirectML:", (Coalesce (Get-FileVer (Join-Path $root 'DirectML.dll')) 'MISSING'))
|
||||
Write-Host ("{0,-14} {1}" -f "cuDNN:", (Coalesce (Get-FileVer (Join-Path $root 'cudnn64_9.dll')) 'MISSING'))
|
||||
# CUDA toolkit generation is encoded in the file name suffix.
|
||||
$cudaFiles = Get-ChildItem -LiteralPath $root -Filter "cudart64_*.dll" -ErrorAction SilentlyContinue
|
||||
if ($cudaFiles) {
|
||||
$gen = ($cudaFiles[0].BaseName -replace 'cudart64_','')
|
||||
Write-Host ("{0,-14} {1}" -f "CUDA:", "toolkit $gen.x (cudart64_$gen.dll present)")
|
||||
} else {
|
||||
Write-Host ("{0,-14} {1}" -f "CUDA:", "MISSING (no cudart64_*.dll)")
|
||||
}
|
||||
|
||||
# ---- ORT per EP ---------------------------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "-- ONNX Runtime per EP --------------------------------------------"
|
||||
foreach ($ep in $epMap.Keys) {
|
||||
$epDir = Join-Path $root "ep\$ep"
|
||||
$ortDll = Join-Path $epDir "onnxruntime.dll"
|
||||
$ver = Get-FileVer $ortDll
|
||||
$result.Ort[$ep] = $ver
|
||||
if ($ver) {
|
||||
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, $ver, $epMap[$ep])
|
||||
} elseif (Test-Path -LiteralPath $epDir) {
|
||||
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, "EMPTY / no onnxruntime.dll", $epMap[$ep])
|
||||
} else {
|
||||
Write-Host ("{0,-10} {1,-26} [{2}]" -f $ep, "FOLDER MISSING", $epMap[$ep])
|
||||
}
|
||||
}
|
||||
|
||||
# ---- Dependency / presence check ---------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "-- EP dependency resolution (imports must exist in root) ----------"
|
||||
$missingDeps = @()
|
||||
$epProviders = @{
|
||||
"cuda" = @("onnxruntime_providers_cuda.dll","onnxruntime_providers_tensorrt.dll")
|
||||
"directml" = @() # DML is built into onnxruntime.dll; needs DirectML.dll from root
|
||||
"openvino" = @("onnxruntime_providers_openvino.dll")
|
||||
"cpu" = @()
|
||||
}
|
||||
foreach ($ep in $epProviders.Keys) {
|
||||
$epDir = Join-Path $root "ep\$ep"
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $epDir 'onnxruntime.dll'))) { continue }
|
||||
$checkFiles = @("onnxruntime.dll") + $epProviders[$ep]
|
||||
$deps = @()
|
||||
foreach ($cf in $checkFiles) { $deps += Get-Deps $dumpbin (Join-Path $epDir $cf) }
|
||||
$deps = $deps | Sort-Object -Unique
|
||||
if (-not $deps) { continue }
|
||||
Write-Host (" [{0}] imports: {1}" -f $ep, ($deps -join ', '))
|
||||
foreach ($d in $deps) {
|
||||
# provider DLLs live in the ep folder; everything else in root
|
||||
$inEp = Test-Path -LiteralPath (Join-Path $epDir $d)
|
||||
$inRoot = Test-Path -LiteralPath (Join-Path $root $d)
|
||||
if (-not $inEp -and -not $inRoot) {
|
||||
Write-Host (" MISSING: $d") -ForegroundColor Red
|
||||
$missingDeps += "$ep -> $d"
|
||||
}
|
||||
}
|
||||
}
|
||||
if (-not $missingDeps) { Write-Host " All imported CUDA/TRT/OV/DML DLLs are present." -ForegroundColor Green }
|
||||
$result.MissingDeps = $missingDeps
|
||||
|
||||
# ---- Gap checks ---------------------------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "-- Findings -------------------------------------------------------"
|
||||
$findings = @()
|
||||
|
||||
# CPU reachability: EngineType::CPU needs ep\cpu\onnxruntime.dll OR a flat root onnxruntime.dll
|
||||
$cpuDll = Test-Path -LiteralPath (Join-Path $root 'ep\cpu\onnxruntime.dll')
|
||||
$flatDll = Test-Path -LiteralPath (Join-Path $root 'onnxruntime.dll')
|
||||
if (-not $cpuDll -and -not $flatDll) {
|
||||
$findings += "CPU branch UNREACHABLE: ep\cpu is empty and no flat onnxruntime.dll fallback. A CPU-only machine will fail to load ORT."
|
||||
}
|
||||
|
||||
# ORT version split across EP folders
|
||||
$distinct = $result.Ort.Values | Where-Object { $_ } | Sort-Object -Unique
|
||||
if ($distinct.Count -gt 1) {
|
||||
$findings += "ORT versions differ across EP folders ($($distinct -join ' / ')). Fine ONLY because EPLoader loads one EP per process - never mix DLLs across folders."
|
||||
}
|
||||
|
||||
if ($missingDeps) { $findings += "Unresolved dependencies: $($missingDeps -join '; ')" }
|
||||
|
||||
if (-not $findings) {
|
||||
Write-Host " No issues detected." -ForegroundColor Green
|
||||
} else {
|
||||
foreach ($f in $findings) { Write-Host " ! $f" -ForegroundColor Yellow }
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Main
|
||||
# ----------------------------------------------------------------------------
|
||||
$primary = Inspect-Root $Root
|
||||
|
||||
if ($CompareWith) {
|
||||
$secondary = Inspect-Root $CompareWith
|
||||
if ($primary -and $secondary) {
|
||||
Write-Host ""
|
||||
Write-Host "=================================================================="
|
||||
Write-Host " DIFF: $Root vs $CompareWith"
|
||||
Write-Host "=================================================================="
|
||||
$mismatch = $false
|
||||
|
||||
if ($primary.TensorRT -ne $secondary.TensorRT) {
|
||||
Write-Host (" TensorRT: {0} vs {1}" -f (Format-TensorRT $primary.TensorRT), (Format-TensorRT $secondary.TensorRT)) -ForegroundColor Yellow
|
||||
$mismatch = $true
|
||||
}
|
||||
foreach ($ep in $epMap.Keys) {
|
||||
$a = $primary.Ort[$ep]; $b = $secondary.Ort[$ep]
|
||||
if ($a -ne $b) {
|
||||
Write-Host (" ORT ep\{0}: {1} vs {2}" -f $ep, (Coalesce $a 'MISSING'), (Coalesce $b 'MISSING')) -ForegroundColor Yellow
|
||||
$mismatch = $true
|
||||
}
|
||||
}
|
||||
foreach ($lib in @('openvino.dll','DirectML.dll','cudnn64_9.dll')) {
|
||||
$a = Get-FileVer (Join-Path $Root $lib); $b = Get-FileVer (Join-Path $CompareWith $lib)
|
||||
if ($a -ne $b) {
|
||||
Write-Host (" {0}: {1} vs {2}" -f $lib, (Coalesce $a 'MISSING'), (Coalesce $b 'MISSING')) -ForegroundColor Yellow
|
||||
$mismatch = $true
|
||||
}
|
||||
}
|
||||
if (-not $mismatch) { Write-Host " Identical across both roots." -ForegroundColor Green }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" >nul 2>nul
|
||||
cd /d "C:\Projects\CLionProjects\ANSCORE"
|
||||
"C:\Program Files\CMake\bin\cmake.exe" --build cmake-build-release --target ANSFR-UnitTest
|
||||
exit /b %errorlevel%
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
set "PATH=C:\Projects\CLionProjects\ANSCORE\cmake-build-release\bin;C:\Projects\SharedCore;%PATH%"
|
||||
cd /d "C:\Projects\CLionProjects\ANSCORE\cmake-build-release\bin"
|
||||
ANSFR-UnitTest.exe
|
||||
echo [REPRO] exitcode=%errorlevel%
|
||||
@@ -0,0 +1,77 @@
|
||||
@echo off
|
||||
REM ============================================================================
|
||||
REM build_openvino_ep.bat
|
||||
REM Build the ONNX Runtime OpenVINO Execution Provider (ORT 1.24 / API 24) and
|
||||
REM stage the 3 resulting DLLs into SharedCore\ep\openvino so verify_ep.ps1
|
||||
REM -RequiredApi 24 goes green.
|
||||
REM
|
||||
REM Self-contained: sets up MSVC + an isolated Python venv + OpenVINO env, then
|
||||
REM builds and stages. Run from a PLAIN cmd.exe (NOT PowerShell - OpenVINO's
|
||||
REM setupvars.bat env vars only persist in cmd).
|
||||
REM
|
||||
REM Usage: tools\build_openvino_ep.bat
|
||||
REM ============================================================================
|
||||
setlocal enableextensions
|
||||
|
||||
REM ---- Paths (edit here if your layout differs) ------------------------------
|
||||
set "ORT_SRC=C:\Projects\onnxruntime-ov"
|
||||
set "PYDIR=C:\ANSLibs\Python311"
|
||||
set "OV_SETUP=C:\ANSLibs\OpenVINO\setupvars.bat"
|
||||
set "EP_DST=C:\Projects\SharedCore\ep\openvino"
|
||||
set "OV_DEVICE=GPU"
|
||||
|
||||
echo === [1/6] Locate MSVC (vcvars64) ===
|
||||
set "VCVARS="
|
||||
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath 2^>nul`) do set "VSPATH=%%i"
|
||||
if defined VSPATH if exist "%VSPATH%\VC\Auxiliary\Build\vcvars64.bat" set "VCVARS=%VSPATH%\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if not defined VCVARS set "VCVARS=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if not exist "%VCVARS%" ( echo ERROR: vcvars64.bat not found. Install VS 2022 C++ workload. & exit /b 1 )
|
||||
call "%VCVARS%" || ( echo ERROR: vcvars64 failed & exit /b 1 )
|
||||
|
||||
echo === [2/6] OpenVINO environment ===
|
||||
if not exist "%OV_SETUP%" ( echo ERROR: OpenVINO setupvars not found at %OV_SETUP% & exit /b 1 )
|
||||
call "%OV_SETUP%"
|
||||
REM Release-only OpenVINO archives still ship a Debug cmake config whose DLLs are
|
||||
REM absent, which breaks find_package(OpenVINO). Neutralize it (safe: ANSCORE links
|
||||
REM OpenVINO via explicit paths, not find_package, and this build is Release-only).
|
||||
set "OV_DBG=C:\ANSLibs\OpenVINO\runtime\cmake\OpenVINOTargets-debug.cmake"
|
||||
if exist "%OV_DBG%" ( ren "%OV_DBG%" "OpenVINOTargets-debug.cmake.disabled" && echo neutralized OpenVINO Debug cmake config )
|
||||
REM This ANSLibs OpenVINO is stripped of its runtime DLLs (deployed to SharedCore),
|
||||
REM but find_package(OpenVINO) validates DLL presence. Restore Release DLLs from SharedCore.
|
||||
set "OV_REL=C:\ANSLibs\OpenVINO\runtime\bin\intel64\Release"
|
||||
if not exist "%OV_REL%\openvino_onnx_frontend.dll" (
|
||||
echo restoring OpenVINO Release DLLs from SharedCore...
|
||||
if not exist "%OV_REL%" mkdir "%OV_REL%"
|
||||
copy /Y "C:\Projects\SharedCore\openvino*.dll" "%OV_REL%\" >nul
|
||||
copy /Y "C:\Projects\SharedCore\tbb*.dll" "%OV_REL%\" >nul
|
||||
)
|
||||
|
||||
echo === [3/6] Isolated Python venv (keeps build deps out of %PYDIR%) ===
|
||||
if not exist "%PYDIR%\python.exe" ( echo ERROR: python not at %PYDIR% & exit /b 1 )
|
||||
if not exist "%ORT_SRC%\.buildvenv\Scripts\python.exe" (
|
||||
"%PYDIR%\python.exe" -m venv "%ORT_SRC%\.buildvenv" || ( echo ERROR: venv create failed & exit /b 1 )
|
||||
)
|
||||
call "%ORT_SRC%\.buildvenv\Scripts\activate.bat"
|
||||
python --version || ( echo ERROR: venv python not usable & exit /b 1 )
|
||||
python -m pip install --upgrade pip setuptools wheel packaging numpy >nul
|
||||
|
||||
echo === [4/6] Build (Release, shared lib, OpenVINO %OV_DEVICE%) ===
|
||||
cd /d "%ORT_SRC%" || ( echo ERROR: ORT source not found at %ORT_SRC% & exit /b 1 )
|
||||
REM NOTE: full path, not bare 'build.bat' - VS dev env sets
|
||||
REM NoDefaultCurrentDirectoryInExePath, so cmd won't resolve build.bat from CWD.
|
||||
call "%ORT_SRC%\build.bat" --config Release --use_openvino %OV_DEVICE% --build_shared_lib --parallel --skip_tests --cmake_generator "Visual Studio 17 2022"
|
||||
if errorlevel 1 ( echo ERROR: build failed - see log above & exit /b 1 )
|
||||
|
||||
echo === [5/6] Stage DLLs into %EP_DST% (with one-time backup) ===
|
||||
set "OUT=%ORT_SRC%\build\Windows\Release\Release"
|
||||
if not exist "%OUT%\onnxruntime_providers_openvino.dll" ( echo ERROR: build output missing in %OUT% & exit /b 1 )
|
||||
if not exist "%EP_DST%._bak_123" ( xcopy /E /I /Y "%EP_DST%" "%EP_DST%._bak_123" >nul )
|
||||
copy /Y "%OUT%\onnxruntime.dll" "%EP_DST%\" >nul
|
||||
copy /Y "%OUT%\onnxruntime_providers_openvino.dll" "%EP_DST%\" >nul
|
||||
copy /Y "%OUT%\onnxruntime_providers_shared.dll" "%EP_DST%\" >nul
|
||||
|
||||
echo === [6/6] Done ===
|
||||
echo Staged into %EP_DST% (1.23 backup at %EP_DST%._bak_123)
|
||||
echo Validate:
|
||||
echo powershell -ExecutionPolicy Bypass -File C:\Projects\CLionProjects\ANSCORE\tools\verify_ep.ps1 -RequiredApi 24
|
||||
endlocal
|
||||
@@ -0,0 +1,131 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Bump the link-time ONNX Runtime SDK in C:\ANSLibs\onnxruntime to a new version
|
||||
(e.g. 1.23 -> 1.24), safely and reversibly. ANSCORE compiles against this folder.
|
||||
|
||||
.DESCRIPTION
|
||||
Replaces C:\ANSLibs\onnxruntime\{include,lib} + the runtime<ver>_openvino<ver>.txt
|
||||
marker with a new ORT SDK, after validating the new SDK and backing up the old one.
|
||||
|
||||
It does NOT touch the runtime DLLs in SharedCore\ep - those are a separate step.
|
||||
ANSCORE only #includes onnxruntime_cxx_api.h (the EP-agnostic C++ API), so any
|
||||
matching ORT build's include\ works (GPU build's headers are fine).
|
||||
|
||||
SEQUENCING NOTE: bumping the link header to API N makes any runtime EP folder
|
||||
whose core is < N a latent risk. Unify the runtime (incl. the OpenVINO EP) to the
|
||||
target version FIRST, then run this. After running, rebuild ANSCORE and validate
|
||||
the runtime with: tools\verify_ep.ps1 -RequiredApi <N>
|
||||
|
||||
.PARAMETER SdkPath
|
||||
Folder of the NEW ORT SDK. Must contain:
|
||||
include\onnxruntime_c_api.h (with the new ORT_API_VERSION)
|
||||
lib\onnxruntime.lib
|
||||
Typically the unzipped onnxruntime-win-x64-gpu-<ver> release, or an Intel
|
||||
OpenVINO ORT build of the same version.
|
||||
|
||||
.PARAMETER AnsLibs
|
||||
ANSLibs root. Default: C:\ANSLibs
|
||||
|
||||
.PARAMETER Marker
|
||||
New marker filename to drop in (documents the version, mirrors the existing
|
||||
'runtime1.23.0_openvino2025.3.0.txt'). Optional - if omitted, no marker change.
|
||||
|
||||
.PARAMETER WhatIf
|
||||
Show what would happen without changing anything.
|
||||
|
||||
.EXAMPLE
|
||||
# Dry run first
|
||||
.\bump_ort_sdk.ps1 -SdkPath D:\dl\onnxruntime-win-x64-gpu-1.24.0 `
|
||||
-Marker runtime1.24.0_openvino2025.3.0.txt -WhatIf
|
||||
# Then for real
|
||||
.\bump_ort_sdk.ps1 -SdkPath D:\dl\onnxruntime-win-x64-gpu-1.24.0 `
|
||||
-Marker runtime1.24.0_openvino2025.3.0.txt
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string] $SdkPath,
|
||||
[string] $AnsLibs = "C:\ANSLibs",
|
||||
[string] $Marker
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Get-OrtApiFromHeader([string]$header) {
|
||||
if (-not (Test-Path -LiteralPath $header)) { return $null }
|
||||
$line = Select-String -LiteralPath $header -Pattern 'define\s+ORT_API_VERSION\s+(\d+)' | Select-Object -First 1
|
||||
if ($line) { return [int]$line.Matches[0].Groups[1].Value }
|
||||
return $null
|
||||
}
|
||||
|
||||
if (-not (Test-Path -LiteralPath $SdkPath)) {
|
||||
Write-Host "FAIL - SdkPath not found: $SdkPath" -ForegroundColor Red
|
||||
Write-Host "Point -SdkPath at an unzipped ORT release folder (with include\ and lib\)." -ForegroundColor Yellow
|
||||
exit 2
|
||||
}
|
||||
|
||||
$ortDir = Join-Path $AnsLibs 'onnxruntime'
|
||||
$newInc = Join-Path $SdkPath 'include'
|
||||
$newLib = Join-Path $SdkPath 'lib'
|
||||
$newHdr = Join-Path $newInc 'onnxruntime_c_api.h'
|
||||
|
||||
# ---- Validate NEW sdk -------------------------------------------------------
|
||||
Write-Host "== Validating new SDK at: $SdkPath =="
|
||||
$problems = @()
|
||||
if (-not (Test-Path -LiteralPath $newHdr)) { $problems += "missing include\onnxruntime_c_api.h" }
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $newInc 'onnxruntime_cxx_api.h'))) { $problems += "missing include\onnxruntime_cxx_api.h" }
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $newLib 'onnxruntime.lib'))) { $problems += "missing lib\onnxruntime.lib" }
|
||||
if ($problems) {
|
||||
Write-Host "FAIL - new SDK is incomplete:" -ForegroundColor Red
|
||||
$problems | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
|
||||
Write-Host "Point -SdkPath at an unzipped ORT release that has include\ and lib\." -ForegroundColor Yellow
|
||||
exit 2
|
||||
}
|
||||
|
||||
$newApi = Get-OrtApiFromHeader $newHdr
|
||||
$oldApi = Get-OrtApiFromHeader (Join-Path $ortDir 'include\onnxruntime_c_api.h')
|
||||
$newApiDisp = if ($newApi) { $newApi } else { '??' }
|
||||
$oldApiDisp = if ($oldApi) { $oldApi } else { 'none' }
|
||||
Write-Host (" new ORT_API_VERSION : {0}" -f $newApiDisp)
|
||||
Write-Host (" current (ANSLibs) : {0}" -f $oldApiDisp)
|
||||
if ($newApi -and $oldApi -and $newApi -le $oldApi) {
|
||||
Write-Host ("WARNING: new API ({0}) is not greater than current ({1}). Continue only if intentional." -f $newApi,$oldApi) -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ---- Back up CURRENT onnxruntime SDK ---------------------------------------
|
||||
$stamp = (Get-Date -Format 'yyyyMMdd_HHmmss')
|
||||
$backup = Join-Path $AnsLibs ("onnxruntime.bak_$stamp")
|
||||
Write-Host ""
|
||||
Write-Host "== Backing up current SDK -> $backup =="
|
||||
if ($PSCmdlet.ShouldProcess($ortDir, "copy to $backup")) {
|
||||
Copy-Item -LiteralPath $ortDir -Destination $backup -Recurse -Force
|
||||
}
|
||||
|
||||
# ---- Swap include\ and lib\ -------------------------------------------------
|
||||
Write-Host "== Installing new include\ and lib\ =="
|
||||
foreach ($sub in @('include','lib')) {
|
||||
$dst = Join-Path $ortDir $sub
|
||||
$src = Join-Path $SdkPath $sub
|
||||
if ($PSCmdlet.ShouldProcess($dst, "replace from $src")) {
|
||||
if (Test-Path -LiteralPath $dst) { Remove-Item -LiteralPath $dst -Recurse -Force }
|
||||
Copy-Item -LiteralPath $src -Destination $dst -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
# ---- Marker file ------------------------------------------------------------
|
||||
if ($Marker) {
|
||||
Write-Host "== Updating version marker -> $Marker =="
|
||||
if ($PSCmdlet.ShouldProcess($ortDir, "swap marker to $Marker")) {
|
||||
Get-ChildItem -LiteralPath $ortDir -Filter 'runtime*.txt' -File -ErrorAction SilentlyContinue |
|
||||
ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force }
|
||||
New-Item -ItemType File -Path (Join-Path $ortDir $Marker) -Force | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "== DONE ==" -ForegroundColor Green
|
||||
Write-Host "Next steps:" -ForegroundColor Cyan
|
||||
$apiForSteps = if ($newApi) { $newApi } else { 'N' }
|
||||
Write-Host (" 1. Clean-rebuild ANSCORE (it now compiles against ORT_API_VERSION {0})." -f $apiForSteps)
|
||||
Write-Host (" 2. Validate the runtime: tools\verify_ep.ps1 -RequiredApi {0}" -f $apiForSteps)
|
||||
Write-Host " (the openvino EP folder must also be at the new version or it will FAIL.)"
|
||||
Write-Host (" 3. If anything breaks, revert: Remove-Item '$ortDir' -Recurse -Force; Rename-Item '$backup' 'onnxruntime'")
|
||||
@@ -0,0 +1,115 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Assemble a complete link-time ONNX Runtime C/C++ SDK (include\ + lib\) by
|
||||
downloading the public headers at a given source commit and pairing them with
|
||||
an existing import lib. Output feeds straight into tools\bump_ort_sdk.ps1.
|
||||
|
||||
.DESCRIPTION
|
||||
ORT nightly builds (e.g. 1.24.YYYYMMDD.N.<hash>) ship DLLs + import libs but
|
||||
the matching C/C++ headers are only the public source files in the GitHub repo
|
||||
at the build's commit. ANSCORE compiles against ORT_API_VERSION via these
|
||||
headers, so this script pulls the exact header set for -Commit and copies in a
|
||||
matching onnxruntime.lib, producing a ready-to-install SDK folder.
|
||||
|
||||
Default -Commit 058787c matches SharedCore\ep\cuda (1.24.20260218) AND the
|
||||
onnxruntime.lib already on disk under LabellingTool\vendor (same build).
|
||||
|
||||
.PARAMETER Commit
|
||||
ORT source commit/branch/tag to fetch headers from. Default: 058787c (API 24).
|
||||
|
||||
.PARAMETER OutDir
|
||||
Where to assemble the SDK. Default: %TEMP%\ort_sdk_<commit>.
|
||||
|
||||
.PARAMETER LibSource
|
||||
Folder containing onnxruntime.lib (+ onnxruntime_providers_shared.lib) of the
|
||||
SAME build. Default: the LabellingTool vendor folder found on this machine.
|
||||
|
||||
.EXAMPLE
|
||||
.\fetch_ort_headers.ps1
|
||||
.\bump_ort_sdk.ps1 -SdkPath $env:TEMP\ort_sdk_058787c -Marker runtime1.24.0_openvino2025.3.0.txt -WhatIf
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $Commit = "058787c",
|
||||
[string] $OutDir,
|
||||
[string] $LibSource = "C:\Projects\CLionProjects\LabellingTool\vendor\onnxruntime-win\lib"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
if (-not $OutDir) { $OutDir = Join-Path $env:TEMP "ort_sdk_$Commit" }
|
||||
$incDir = Join-Path $OutDir 'include'
|
||||
$libDir = Join-Path $OutDir 'lib'
|
||||
New-Item -ItemType Directory -Force -Path $incDir, $libDir | Out-Null
|
||||
|
||||
$base = "https://raw.githubusercontent.com/microsoft/onnxruntime/$Commit/include/onnxruntime/core"
|
||||
|
||||
# Header set ANSCORE links against (mirrors ANSLibs, minus unused training headers).
|
||||
# Each entry: subpath under .../core/ -> flattened into include\
|
||||
$headers = @(
|
||||
"session/onnxruntime_c_api.h",
|
||||
"session/onnxruntime_cxx_api.h",
|
||||
"session/onnxruntime_cxx_inline.h",
|
||||
"session/onnxruntime_float16.h",
|
||||
"session/onnxruntime_lite_custom_op.h",
|
||||
"session/onnxruntime_run_options_config_keys.h",
|
||||
"session/onnxruntime_session_options_config_keys.h",
|
||||
"session/onnxruntime_ep_c_api.h",
|
||||
"session/onnxruntime_ep_device_ep_metadata_keys.h",
|
||||
"providers/cpu/cpu_provider_factory.h",
|
||||
"framework/provider_options.h"
|
||||
)
|
||||
|
||||
Write-Host "== Fetching ORT headers @ $Commit -> $incDir =="
|
||||
$ok = 0; $fail = @()
|
||||
foreach ($h in $headers) {
|
||||
$name = Split-Path $h -Leaf
|
||||
$url = "$base/$h"
|
||||
try {
|
||||
Invoke-WebRequest -Uri $url -OutFile (Join-Path $incDir $name) -UseBasicParsing
|
||||
# Guard against a 200-with-HTML (GitHub 404 page) sneaking through
|
||||
$first = Get-Content -LiteralPath (Join-Path $incDir $name) -TotalCount 1 -ErrorAction SilentlyContinue
|
||||
if ($first -match '^\s*<!DOCTYPE|^\s*<html') { throw "got HTML, not a header" }
|
||||
Write-Host (" OK {0}" -f $name) -ForegroundColor Green
|
||||
$ok++
|
||||
} catch {
|
||||
Write-Host (" FAIL {0} ({1})" -f $name, $_.Exception.Message) -ForegroundColor Red
|
||||
$fail += $name
|
||||
}
|
||||
}
|
||||
|
||||
# Verify the new API version actually parsed
|
||||
$apiLine = Select-String -LiteralPath (Join-Path $incDir 'onnxruntime_c_api.h') `
|
||||
-Pattern 'define\s+ORT_API_VERSION\s+(\d+)' -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
$api = if ($apiLine) { $apiLine.Matches[0].Groups[1].Value } else { '??' }
|
||||
Write-Host (" ORT_API_VERSION in fetched headers: {0}" -f $api)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "== Copying import libs from: $LibSource =="
|
||||
$libsOk = $true
|
||||
foreach ($l in @('onnxruntime.lib','onnxruntime_providers_shared.lib')) {
|
||||
$src = Join-Path $LibSource $l
|
||||
if (Test-Path -LiteralPath $src) {
|
||||
Copy-Item -LiteralPath $src -Destination (Join-Path $libDir $l) -Force
|
||||
Write-Host (" OK {0}" -f $l) -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host (" MISSING {0} in {1}" -f $l, $LibSource) -ForegroundColor Yellow
|
||||
if ($l -eq 'onnxruntime.lib') { $libsOk = $false }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
if ($fail.Count -eq 0 -and $libsOk) {
|
||||
Write-Host "== SDK assembled OK ==" -ForegroundColor Green
|
||||
Write-Host (" $OutDir (include\ = {0} headers @ API {1}, lib\ = import libs)" -f $ok, $api)
|
||||
Write-Host " Next:" -ForegroundColor Cyan
|
||||
Write-Host (" .\bump_ort_sdk.ps1 -SdkPath `"$OutDir`" -Marker runtime1.24.0_openvino2025.3.0.txt -WhatIf")
|
||||
exit 0
|
||||
} else {
|
||||
Write-Host "== INCOMPLETE ==" -ForegroundColor Red
|
||||
if ($fail.Count) { Write-Host (" headers failed: {0}" -f ($fail -join ', ')) -ForegroundColor Red }
|
||||
if (-not $libsOk) { Write-Host " onnxruntime.lib not found - set -LibSource to a folder that has it." -ForegroundColor Red }
|
||||
exit 1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
REM Rebuild ANSCORE (Release/Ninja) with the MSVC+CUDA env set up.
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" >nul 2>nul
|
||||
cd /d "C:\Projects\CLionProjects\ANSCORE"
|
||||
"C:\Program Files\CMake\bin\cmake.exe" --build cmake-build-release --parallel
|
||||
exit /b %errorlevel%
|
||||
@@ -0,0 +1,243 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Acceptance gate for an ANSCENTER ep\ ONNX Runtime tree. Returns exit code 0
|
||||
(all PASS) or 1 (any FAIL) so it can be wired into CI / a release checklist.
|
||||
|
||||
.DESCRIPTION
|
||||
Run this after swapping any onnxruntime*.dll in SharedCore\ep (e.g. when
|
||||
unifying all EP folders onto a single ORT version). It enforces the three
|
||||
rules that make an ep\ tree correct for ANSCORE:
|
||||
|
||||
CHECK 1 - API floor. Each EP folder's core onnxruntime.dll must expose an
|
||||
ORT C-API version >= the version ANSCORE links against
|
||||
(-RequiredApi, default 23 for ORT 1.23). ORT is backward
|
||||
compatible, so a NEWER core (1.24 => API 24) is fine; an OLDER
|
||||
one is not. API is derived from the file version (1.<minor> =>
|
||||
API <minor>).
|
||||
|
||||
CHECK 2 - Provider/core lock. Every onnxruntime_providers_*.dll in a
|
||||
folder must have the EXACT same file version as that folder's
|
||||
onnxruntime.dll. ORT provider DLLs are version-locked to the core;
|
||||
a mismatch is a silent crash waiting to happen.
|
||||
|
||||
CHECK 3 - Backend resolution. Every CUDA / cuDNN / TensorRT / OpenVINO /
|
||||
DirectML DLL imported by the core or its providers must exist in
|
||||
the ep folder, the Shared root, or System32.
|
||||
|
||||
It also prints a UNIFICATION summary (how many distinct core versions exist
|
||||
across the folders) so you can see when you've reached one-version-everywhere.
|
||||
|
||||
.PARAMETER EpRoot
|
||||
The ep\ folder to verify. Default: C:\Projects\SharedCore\ep
|
||||
(You may also pass the Shared root itself; the script appends \ep if needed.)
|
||||
|
||||
.PARAMETER SharedRoot
|
||||
The Shared folder that holds the backend DLLs (nvinfer_10.dll, openvino.dll,
|
||||
cudart64_13.dll, DirectML.dll, ...). Default: parent of EpRoot.
|
||||
|
||||
.PARAMETER RequiredApi
|
||||
Minimum acceptable ORT C-API version. Default: 23 (ANSCORE links ORT 1.23).
|
||||
|
||||
.EXAMPLE
|
||||
.\verify_ep.ps1
|
||||
.\verify_ep.ps1 -EpRoot C:\ProgramData\ANSCENTER\Shared\ep
|
||||
.\verify_ep.ps1 -RequiredApi 24 # after bumping ANSCORE's link SDK to 1.24
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $EpRoot = "C:\Projects\SharedCore\ep",
|
||||
[string] $SharedRoot,
|
||||
[int] $RequiredApi = 23
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers (kept consistent with Check-SharedCoreVersions.ps1)
|
||||
# ---------------------------------------------------------------------------
|
||||
function Coalesce($value, $fallback) { if ($value) { $value } else { $fallback } }
|
||||
|
||||
function Get-FileVer([string]$path) {
|
||||
if (Test-Path -LiteralPath $path) { (Get-Item -LiteralPath $path).VersionInfo.FileVersion }
|
||||
else { $null }
|
||||
}
|
||||
|
||||
function Find-Dumpbin {
|
||||
$c = Get-ChildItem `
|
||||
"C:\Program Files\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe", `
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe" `
|
||||
-ErrorAction SilentlyContinue | Sort-Object FullName -Descending
|
||||
if ($c) { return $c[0].FullName }
|
||||
return $null
|
||||
}
|
||||
|
||||
# Derive the ORT C-API version from a file version string. ORT 1.<minor> exposes
|
||||
# C-API version <minor> (1.23.* => 23, 1.24.* => 24). Returns $null if unparsable.
|
||||
function Get-OrtApi([string]$fileVer) {
|
||||
if (-not $fileVer) { return $null }
|
||||
$parts = $fileVer.Split('.')
|
||||
if ($parts.Count -lt 2) { return $null }
|
||||
$minor = 0
|
||||
if ([int]::TryParse($parts[1], [ref]$minor)) { return $minor }
|
||||
return $null
|
||||
}
|
||||
|
||||
# Lower-cased CUDA/TRT/OV/DML deps imported by $path (via dumpbin /DEPENDENTS).
|
||||
function Get-BackendDeps([string]$dumpbin, [string]$path) {
|
||||
if (-not $dumpbin -or -not (Test-Path -LiteralPath $path)) { return @() }
|
||||
$rx = '(?i)cudart|cublas|cudnn|cufft|cusparse|cusolver|nvinfer|nvonnx|nvrtc|directml|openvino'
|
||||
& $dumpbin /DEPENDENTS $path 2>$null |
|
||||
Select-String -Pattern '^\s+\S+\.dll\s*$' |
|
||||
ForEach-Object { $_.Line.Trim().ToLower() } |
|
||||
Where-Object { $_ -match $rx } |
|
||||
Sort-Object -Unique
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resolve paths
|
||||
# ---------------------------------------------------------------------------
|
||||
if (-not (Test-Path -LiteralPath $EpRoot)) {
|
||||
Write-Host "ERROR: EpRoot not found: $EpRoot" -ForegroundColor Red; exit 2
|
||||
}
|
||||
# Allow passing the Shared root instead of the ep folder.
|
||||
if ((Split-Path $EpRoot -Leaf) -ine 'ep' -and (Test-Path -LiteralPath (Join-Path $EpRoot 'ep'))) {
|
||||
$EpRoot = Join-Path $EpRoot 'ep'
|
||||
}
|
||||
if (-not $SharedRoot) { $SharedRoot = Split-Path $EpRoot -Parent }
|
||||
$sys32 = Join-Path $env:WINDIR 'System32'
|
||||
$dumpbin = Find-Dumpbin
|
||||
|
||||
# Providers expected per EP (DML is baked into the core; CPU has none).
|
||||
$epProviders = [ordered]@{
|
||||
"cpu" = @()
|
||||
"cuda" = @("onnxruntime_providers_cuda.dll","onnxruntime_providers_tensorrt.dll")
|
||||
"directml" = @()
|
||||
"openvino" = @("onnxruntime_providers_openvino.dll")
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=================================================================="
|
||||
Write-Host " verify_ep - ANSCORE ONNX Runtime acceptance gate"
|
||||
Write-Host " ep root : $EpRoot"
|
||||
Write-Host " shared root : $SharedRoot"
|
||||
Write-Host " required API : >= $RequiredApi (ANSCORE link version)"
|
||||
Write-Host " dumpbin : $(Coalesce $dumpbin 'NOT FOUND - CHECK 3 will be skipped')"
|
||||
Write-Host "=================================================================="
|
||||
|
||||
$overallFail = $false
|
||||
$coreVersions = @{} # ep -> core file version (for unification summary)
|
||||
|
||||
foreach ($ep in $epProviders.Keys) {
|
||||
$epDir = Join-Path $EpRoot $ep
|
||||
$core = Join-Path $epDir 'onnxruntime.dll'
|
||||
Write-Host ""
|
||||
Write-Host ("-- ep\{0} ------------------------------------------------------" -f $ep)
|
||||
|
||||
if (-not (Test-Path -LiteralPath $core)) {
|
||||
if (Test-Path -LiteralPath $epDir) {
|
||||
Write-Host " SKIP: folder present but no onnxruntime.dll" -ForegroundColor DarkYellow
|
||||
} else {
|
||||
Write-Host " SKIP: folder absent" -ForegroundColor DarkGray
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
$coreVer = Get-FileVer $core
|
||||
$coreVersions[$ep] = $coreVer
|
||||
$epFail = $false
|
||||
|
||||
# ----- CHECK 1: API floor ------------------------------------------------
|
||||
$api = Get-OrtApi $coreVer
|
||||
if ($null -eq $api) {
|
||||
Write-Host (" CHECK 1 API : FAIL - cannot parse version '{0}'" -f $coreVer) -ForegroundColor Red
|
||||
$epFail = $true
|
||||
} elseif ($api -lt $RequiredApi) {
|
||||
Write-Host (" CHECK 1 API : FAIL - core {0} => API {1} < required {2}" -f $coreVer,$api,$RequiredApi) -ForegroundColor Red
|
||||
$epFail = $true
|
||||
} else {
|
||||
Write-Host (" CHECK 1 API : PASS - core {0} => API {1} (>= {2})" -f $coreVer,$api,$RequiredApi) -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ----- CHECK 2: provider/core version lock -------------------------------
|
||||
$providers = Get-ChildItem -LiteralPath $epDir -Filter 'onnxruntime_providers_*.dll' -ErrorAction SilentlyContinue
|
||||
if (-not $providers) {
|
||||
Write-Host " CHECK 2 LOCK : PASS - no provider DLLs in folder (core-only EP)" -ForegroundColor Green
|
||||
} else {
|
||||
$bad = @()
|
||||
foreach ($p in $providers) {
|
||||
$pv = $p.VersionInfo.FileVersion
|
||||
if ($pv -ne $coreVer) { $bad += ("{0} ({1})" -f $p.Name, (Coalesce $pv 'no-version')) }
|
||||
}
|
||||
if ($bad) {
|
||||
Write-Host (" CHECK 2 LOCK : FAIL - version != core {0}: {1}" -f $coreVer, ($bad -join ', ')) -ForegroundColor Red
|
||||
$epFail = $true
|
||||
} else {
|
||||
Write-Host (" CHECK 2 LOCK : PASS - {0} provider DLL(s) all == {1}" -f $providers.Count, $coreVer) -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
# ----- CHECK 3: backend resolution ---------------------------------------
|
||||
if (-not $dumpbin) {
|
||||
Write-Host " CHECK 3 DEPS : SKIP - dumpbin not available" -ForegroundColor DarkYellow
|
||||
} else {
|
||||
$checkFiles = @('onnxruntime.dll') + $epProviders[$ep]
|
||||
$deps = @()
|
||||
foreach ($cf in $checkFiles) { $deps += Get-BackendDeps $dumpbin (Join-Path $epDir $cf) }
|
||||
$deps = $deps | Sort-Object -Unique
|
||||
if (-not $deps) {
|
||||
Write-Host " CHECK 3 DEPS : PASS - no CUDA/TRT/OV/DML imports" -ForegroundColor Green
|
||||
} else {
|
||||
$missing = @()
|
||||
foreach ($d in $deps) {
|
||||
$found = (Test-Path -LiteralPath (Join-Path $epDir $d)) -or `
|
||||
(Test-Path -LiteralPath (Join-Path $SharedRoot $d)) -or `
|
||||
(Test-Path -LiteralPath (Join-Path $sys32 $d))
|
||||
if (-not $found) { $missing += $d }
|
||||
}
|
||||
if ($missing) {
|
||||
Write-Host (" CHECK 3 DEPS : FAIL - missing: {0}" -f ($missing -join ', ')) -ForegroundColor Red
|
||||
Write-Host (" (imports: {0})" -f ($deps -join ', ')) -ForegroundColor DarkGray
|
||||
$epFail = $true
|
||||
} else {
|
||||
Write-Host (" CHECK 3 DEPS : PASS - all {0} backend import(s) resolved" -f $deps.Count) -ForegroundColor Green
|
||||
Write-Host (" {0}" -f ($deps -join ', ')) -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($epFail) { $overallFail = $true }
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Unification summary
|
||||
# ---------------------------------------------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "-- Unification summary --------------------------------------------"
|
||||
$distinct = $coreVersions.Values | Where-Object { $_ } | Sort-Object -Unique
|
||||
if ($distinct.Count -eq 0) {
|
||||
Write-Host " No ORT cores found." -ForegroundColor Red
|
||||
$overallFail = $true
|
||||
} elseif ($distinct.Count -eq 1) {
|
||||
Write-Host (" UNIFIED: all EP folders on a single ORT version ({0})." -f $distinct[0]) -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host (" {0} distinct ORT versions across folders:" -f $distinct.Count) -ForegroundColor Yellow
|
||||
foreach ($ep in $coreVersions.Keys) {
|
||||
Write-Host (" ep\{0,-9} {1}" -f $ep, $coreVersions[$ep])
|
||||
}
|
||||
Write-Host " Safe at runtime (one EP per process) but not yet unified - see tools recommendation." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Verdict
|
||||
# ---------------------------------------------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "=================================================================="
|
||||
if ($overallFail) {
|
||||
Write-Host " RESULT: FAIL - one or more EP folders did not pass." -ForegroundColor Red
|
||||
Write-Host "=================================================================="
|
||||
exit 1
|
||||
} else {
|
||||
Write-Host " RESULT: PASS - ep\ tree is correct for ANSCORE." -ForegroundColor Green
|
||||
Write-Host "=================================================================="
|
||||
exit 0
|
||||
}
|
||||