- Remove ALPR_OD Tracker and voting system.

- Disable debugview
This commit is contained in:
2026-04-19 23:15:50 +10:00
parent 51fe507dfd
commit 3418090042
13 changed files with 1266 additions and 129 deletions

View File

@@ -172,7 +172,23 @@
"Bash(grep -l \"AVFrame\\\\|AVCodecContext\\\\|AVFormatContext\\\\|AVPacket\\\\|AVStream\" \"C:/Projects/CLionProjects/ANSCORE/MediaClient/media/\"*.h)",
"Bash(\"C:/ANSLibs/ffmpeg-n8.1/bin/ffmpeg.exe\" -hide_banner -decoders)",
"Bash(\"C:/ANSLibs/ffmpeg-n8.1/bin/ffmpeg.exe\" -hide_banner -protocols)",
"Bash(\"C:/ANSLibs/ffmpeg-n8.1/bin/ffmpeg.exe\" -hide_banner -formats)"
"Bash(\"C:/ANSLibs/ffmpeg-n8.1/bin/ffmpeg.exe\" -hide_banner -formats)",
"Bash(grep -c '\\\\\\\\n\",$' modules/ANSUtilities/dllmain.cpp)",
"Bash(grep -c '\\\\\\\\n\", ' modules/ANSUtilities/dllmain.cpp)",
"Bash(grep -nP '\\\\\\\\n\",' dllmain.cpp)",
"Bash(awk '/\\\\[ANSTRE\\\\]/{tre++} /\\\\[ANSMOT\\\\]/{mot++} /\\\\[ANSOD\\\\]/{od++} /\\\\[ANSLPR\\\\]/{lpr++} /\\\\[ANSFR\\\\]/{fr++} /\\\\[ANSLLM\\\\]/{llm++} /\\\\[ANSOCR\\\\]/{ocr++} /\\\\[ANSUTIL\\\\]/{util++} /\\\\[ANSAWS\\\\]/{aws++} END{print \"TRE=\"tre, \"MOT=\"mot, \"OD=\"od, \"LPR=\"lpr, \"FR=\"fr, \"LLM=\"llm, \"OCR=\"ocr, \"UTIL=\"util, \"AWS=\"aws}' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -v target=5122 'NR>=target-30 && NR<=target+5 && /42332/' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -v target=5156 'NR>=target-30 && NR<=target+5 && /42332/' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk '/\\\\[ANSOD\\\\]/{ split\\($0, a, \"\\\\t\"\\); pid=a[3]; counts[pid]++ } END { for \\(p in counts\\) print p, counts[p] }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -F'\\\\t' '/UnregisterODHandle/ || /\\\\[ANSOD\\\\] Unregister/ || /\\\\[ANSOD\\\\] Acquire/ { print NR, $0 }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -F'\\\\t' '/\\\\[ANSMOT\\\\]/ { sub\\(/^[ \\\\t]+|[ \\\\t]+$/, \"\", $4\\); print $4 }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -F'\\\\t' '/\\\\[ANSUTIL\\\\]/ { msg=$4; sub\\(/[ ]*HandlePtr=.*$/, \"\", msg\\); sub\\(/[ ]*handle=.*$/, \"\", msg\\); sub\\(/[ ]*\\\\\\([0-9]+ entries.*\\\\\\)/, \"\", msg\\); print msg }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk -F'\\\\t' '/\\\\[ANSAWS\\\\]/ { msg=$4; sub\\(/HandlePtr=.*$/, \"\", msg\\); sub\\(/handle=.*$/, \"\", msg\\); sub\\(/file=.*$/, \"\", msg\\); sub\\(/[ ]+/, \" \", msg\\); print msg }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION.log\")",
"Bash(awk '/\\\\[ANSTRE\\\\]/{tre++} /\\\\[ANSMOT\\\\]/{mot++} /\\\\[ANSOD\\\\]/{od++} /\\\\[ANSLPR\\\\]/{lpr++} /\\\\[ANSFR\\\\]/{fr++} /\\\\[ANSLLM\\\\]/{llm++} /\\\\[ANSOCR\\\\]/{ocr++} /\\\\[ANSUTIL\\\\]/{util++} /\\\\[ANSAWS\\\\]/{aws++} END{print \"TRE=\"tre, \"MOT=\"mot, \"OD=\"od, \"LPR=\"lpr, \"FR=\"fr, \"LLM=\"llm, \"OCR=\"ocr, \"UTIL=\"util, \"AWS=\"aws}' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION1.log\")",
"Bash(awk '/\\\\[ANSOD\\\\]/{ split\\($0, a, \"\\\\t\"\\); pid=a[3]; counts[pid]++ } END { for \\(p in counts\\) print \"OD PID \"p\": \"counts[p] }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION1.log\")",
"Bash(awk '/\\\\[ANSAWS\\\\]/{ split\\($0, a, \"\\\\t\"\\); pid=a[3]; counts[pid]++ } END { for \\(p in counts\\) print \"AWS PID \"p\": \"counts[p] }' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION1.log\")",
"Bash(awk -F'\\\\t' '{print NR, $4}')",
"Bash(awk 'NR>=26275 && NR<=26285' \"C:\\\\Users\\\\nghia\\\\Downloads\\\\ANSLEGION1.log\")"
]
}
}

View File

@@ -26,6 +26,8 @@ std::atomic<bool> g_forceNoPool{false};
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
// DebugView: filter on "[ANSFR]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSRFHandle is called while inference is still running.
// destructionStarted: set by the first Unregister caller; blocks new Acquires
@@ -48,14 +50,30 @@ static std::condition_variable& FRHandleRegistryCV() {
static void RegisterFRHandle(ANSCENTER::ANSFacialRecognition* h) {
std::lock_guard<std::mutex> lk(FRHandleRegistryMutex());
FRHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSFR","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, FRHandleRegistry().size());
}
static ANSCENTER::ANSFacialRecognition* AcquireFRHandle(ANSCENTER::ANSFacialRecognition* h) {
std::lock_guard<std::mutex> lk(FRHandleRegistryMutex());
auto it = FRHandleRegistry().find(h);
if (it == FRHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == FRHandleRegistry().end()) {
ANS_DBG("ANSFR","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, FRHandleRegistry().size());
size_t i = 0;
for (auto& kv : FRHandleRegistry()) {
ANS_DBG("ANSFR"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSFR","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSFR","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -73,10 +91,15 @@ static bool ReleaseFRHandleRef(ANSCENTER::ANSFacialRecognition* h) {
static bool UnregisterFRHandle(ANSCENTER::ANSFacialRecognition* h) {
std::unique_lock<std::mutex> lk(FRHandleRegistryMutex());
auto it = FRHandleRegistry().find(h);
if (it == FRHandleRegistry().end()) return false;
if (it == FRHandleRegistry().end()) {
ANS_DBG("ANSFR","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSFR","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSFR","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = FRHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -84,6 +107,7 @@ static bool UnregisterFRHandle(ANSCENTER::ANSFacialRecognition* h) {
return it2 == FRHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSFR","WARNING: Unregister timed out waiting for in-flight inference on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterFRHandle timed out waiting for in-flight inference\n");
}
FRHandleRegistry().erase(h);
@@ -228,14 +252,22 @@ extern "C" ANSFR_API int CreateANSRFHandle(ANSCENTER::ANSFacialRecognition**
int enableHeadPose,
int minFaceSize,
float faceDetectorThreshold,
int enableFaceLiveness,
int enableFaceLiveness,
int enableAntiSpoofing)
{
ANS_DBG("ANSFR","CreateANSRFHandle called: HandlePtr=%p, *Handle(in)=%p, precision=%d, knownThr=%f, ageGender=%d, emotions=%d, headPose=%d, minFace=%d, faceThr=%f, liveness=%d, antiSpoof=%d, configFile=%s, dbFile=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), precisionType, knownPersonThreshold,
enableAgeGender, enableFaceEmotions, enableHeadPose, minFaceSize, faceDetectorThreshold,
enableFaceLiveness, enableAntiSpoofing,
configFilePath ? configFilePath : "(null)", databaseFilePath ? databaseFilePath : "(null)");
try {
// Ensure all shared DLLs (OpenCV, OpenVINO, TRT, ORT) are pre-loaded
ANSCENTER::ANSLibsLoader::Initialize();
if (!Handle || !licenseKey || !configFilePath || !databaseFilePath || !recogniserFilePath) return -1;
if (!Handle || !licenseKey || !configFilePath || !databaseFilePath || !recogniserFilePath) {
ANS_DBG("ANSFR","CreateANSRFHandle FAIL: required pointer is null");
return -1;
}
// Log the detected vendor path so field triage between NVIDIA / AMD /
// Intel / CPU machines is trivial from the debug log. Mirrors the
@@ -269,6 +301,8 @@ extern "C" ANSFR_API int CreateANSRFHandle(ANSCENTER::ANSFacialRecognition**
// std::unique_ptr ensures automatic cleanup if Initialize() throws
auto ptr = std::make_unique<ANSCENTER::ANSFacialRecognition>();
ANS_DBG("ANSFR","CreateANSRFHandle: allocated handle=%p (uint=%llu), calling Initialize...",
(void*)ptr.get(), (unsigned long long)(uintptr_t)ptr.get());
const bool _enableFaceLiveness = (enableFaceLiveness == 1);
const bool _enableAntiSpoofing = (enableAntiSpoofing == 1);
@@ -291,6 +325,7 @@ extern "C" ANSFR_API int CreateANSRFHandle(ANSCENTER::ANSFacialRecognition**
_enableAntiSpoofing);
if (result < 0) {
ANS_DBG("ANSFR","CreateANSRFHandle FAIL: Initialize returned %d, handle being freed", result);
*Handle = nullptr;
return result;
}
@@ -298,14 +333,18 @@ extern "C" ANSFR_API int CreateANSRFHandle(ANSCENTER::ANSFacialRecognition**
// Transfer ownership to caller on success
*Handle = ptr.release();
RegisterFRHandle(*Handle);
ANS_DBG("ANSFR","CreateANSRFHandle OK: handle=%p (uint=%llu) result=%d",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, result);
return result;
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","CreateANSRFHandle EXCEPTION (std::exception): %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int LoadANSRFEngine(ANSCENTER::ANSFacialRecognition** Handle) {
ANS_DBG("ANSFR","LoadANSRFEngine: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle) return -1;
bool result = (*Handle)->LoadEngine();
@@ -313,23 +352,33 @@ extern "C" ANSFR_API int LoadANSRFEngine(ANSCENTER::ANSFacialRecognition** Ha
else return 0;
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","LoadANSRFEngine EXCEPTION: %s", e.what());
return -1;
}
}
static int ReleaseANSRFHandle_Impl(ANSCENTER::ANSFacialRecognition** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterFRHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSFR","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSFacialRecognition* h = *Handle;
ANS_DBG("ANSFR","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterFRHandle(h)) {
ANS_DBG("ANSFR","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1; // Not in registry — already freed
}
(*Handle)->Destroy();
delete *Handle;
h->Destroy();
delete h;
*Handle = nullptr;
ANS_DBG("ANSFR","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, FRHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSFR","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
@@ -340,10 +389,13 @@ extern "C" ANSFR_API int ReleaseANSRFHandle(ANSCENTER::ANSFacialRecogni
return ReleaseANSRFHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSFR","ReleaseANSRFHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSFR_API std::string RunANSRFInference(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","RunANSRFInference: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -362,6 +414,7 @@ extern "C" ANSFR_API std::string RunANSRFInference(ANSCENTER::ANSFacialRecognit
extern "C" ANSFR_API std::string RunANSRFInferenceBinary(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSFR","RunANSRFInferenceBinary: HandlePtr=%p, *Handle=%p, %ux%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -377,6 +430,7 @@ extern "C" ANSFR_API std::string RunANSRFInferenceBinary(ANSCENTER::ANSFacialRe
catch (...) { return ""; }
}
extern "C" ANSFR_API std::string RunANSRFRecognition(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","RunANSRFRecognition: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -392,6 +446,7 @@ extern "C" ANSFR_API std::string RunANSRFRecognition(ANSCENTER::ANSFacialRecogn
catch (...) { return ""; }
}
extern "C" ANSFR_API std::string RunANSRFRecognitionBinary(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSFR","RunANSRFRecognitionBinary: HandlePtr=%p, *Handle=%p, %ux%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -407,6 +462,7 @@ extern "C" ANSFR_API std::string RunANSRFRecognitionBinary(ANSCENTER::ANSFacial
catch (...) { return ""; }
}
extern "C" ANSFR_API std::string RunANSRFDetectorBinary(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSFR","RunANSRFDetectorBinary: HandlePtr=%p, *Handle=%p, %ux%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -422,6 +478,7 @@ extern "C" ANSFR_API std::string RunANSRFDetectorBinary(ANSCENTER::ANSFacialRec
catch (...) { return ""; }
}
extern "C" ANSFR_API std::string RunANSRFDetector(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","RunANSRFDetector: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -439,16 +496,20 @@ extern "C" ANSFR_API std::string RunANSRFDetector(ANSCENTER::ANSFacialRecogniti
//// For LabVIEW API
extern "C" ANSFR_API int RunInference_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunInference_LV: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !detectionResult) return -1;
std::string st = RunANSRFInference(Handle, jpeg_string, bufferLength);
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunInference_LV EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunInferenceWithCamId_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunInferenceWithCamId_LV: HandlePtr=%p, *Handle=%p, bufLen=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return -3;
@@ -467,17 +528,21 @@ extern "C" ANSFR_API int RunInferenceWithCamId_LV(ANSCENTER::ANSFacialR
extern "C" ANSFR_API int RunDetector_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult)
{
ANS_DBG("ANSFR","RunDetector_LV: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !detectionResult) return -1;
std::string st = RunANSRFDetector(Handle, jpeg_string, bufferLength);
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunDetector_LV EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunDetectorWithCamId_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunDetectorWithCamId_LV: HandlePtr=%p, *Handle=%p, bufLen=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return -3;
@@ -494,16 +559,20 @@ extern "C" ANSFR_API int RunDetectorWithCamId_LV(ANSCENTER::ANSFacialRe
}
extern "C" ANSFR_API int RunRecognition_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunRecognition_LV: HandlePtr=%p, *Handle=%p, bufLen=%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !detectionResult) return -1;
std::string st = RunANSRFRecognition(Handle, jpeg_string, bufferLength);
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunRecognition_LV EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunRecognitionWithCamId_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunRecognitionWithCamId_LV: HandlePtr=%p, *Handle=%p, bufLen=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return -3;
@@ -519,6 +588,8 @@ extern "C" ANSFR_API int RunRecognitionWithCamId_LV(ANSCENTER::ANSFacia
catch (...) { return -1; }
}
extern "C" ANSFR_API int RunFaceDetection_LV(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunFaceDetection_LV: HandlePtr=%p, *Handle=%p, bufLen=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return -3;
@@ -535,6 +606,7 @@ extern "C" ANSFR_API int RunFaceDetection_LV(ANSCENTER::ANSFacialRecogn
}
extern "C" ANSFR_API std::string RunANSRFFaceDetector(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height)
{
ANS_DBG("ANSFR","RunANSRFFaceDetector: HandlePtr=%p, *Handle=%p, %ux%u", (void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
FRHandleGuard guard(AcquireFRHandle(*Handle));
if (!guard) return "";
@@ -552,6 +624,8 @@ extern "C" ANSFR_API std::string RunANSRFFaceDetector(ANSCENTER::ANSFacialRecog
// User management
extern "C" ANSFR_API int InsertUser(ANSCENTER::ANSFacialRecognition** Handle, const char* userCode, const char* userName) {
ANS_DBG("ANSFR","InsertUser: HandlePtr=%p, *Handle=%p, userCode=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userCode ? userCode : "(null)");
try {
if (!Handle || !*Handle || !userCode || !userName) return -1;
int result = (*Handle)->InsertUser(userCode, userName);
@@ -713,6 +787,8 @@ static std::string LStrHandleToUTF8(LStrHandle handle) {
}
extern "C" ANSFR_API int InsertUser_LV(ANSCENTER::ANSFacialRecognition** Handle, const char* userCode, LStrHandle userName) {
ANS_DBG("ANSFR","InsertUser_LV: HandlePtr=%p, *Handle=%p, userCode=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userCode ? userCode : "(null)");
try {
if (!Handle || !*Handle || !userCode || !userName) return -1;
std::string utf8Name = LStrHandleToUTF8(userName);
@@ -723,6 +799,8 @@ extern "C" ANSFR_API int InsertUser_LV(ANSCENTER::ANSFacialRecognition** Handle,
}
extern "C" ANSFR_API int UpdateUser_LV(ANSCENTER::ANSFacialRecognition** Handle, int userId, const char* userCode, LStrHandle userName) {
ANS_DBG("ANSFR","UpdateUser_LV: HandlePtr=%p, *Handle=%p, userId=%d, userCode=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId, userCode ? userCode : "(null)");
try {
if (!Handle || !*Handle || !userCode || !userName) return -1;
std::string utf8Name = LStrHandleToUTF8(userName);
@@ -733,6 +811,8 @@ extern "C" ANSFR_API int UpdateUser_LV(ANSCENTER::ANSFacialRecognition** Handle,
}
extern "C" ANSFR_API int UpdateUser(ANSCENTER::ANSFacialRecognition** Handle, int userId, const char* userCode, const char* userName) {
ANS_DBG("ANSFR","UpdateUser: HandlePtr=%p, *Handle=%p, userId=%d, userCode=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId, userCode ? userCode : "(null)");
try {
if (!Handle || !*Handle || !userCode || !userName) return -1;
int result = (*Handle)->UpdateUser(userId, userCode, userName);
@@ -743,6 +823,8 @@ extern "C" ANSFR_API int UpdateUser(ANSCENTER::ANSFacialRecognition** H
}
}
extern "C" ANSFR_API int DeleteUser(ANSCENTER::ANSFacialRecognition** Handle, int userId) {
ANS_DBG("ANSFR","DeleteUser: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle) return -1;
int result = (*Handle)->DeleteUser(userId);
@@ -753,6 +835,8 @@ extern "C" ANSFR_API int DeleteUser(ANSCENTER::ANSFacialRecognition** H
}
}
extern "C" ANSFR_API int DeleteUsers(ANSCENTER::ANSFacialRecognition** Handle, int* userIds, int count) {
ANS_DBG("ANSFR","DeleteUsers: HandlePtr=%p, *Handle=%p, count=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), count);
try {
if (!Handle || !*Handle || !userIds || count <= 0) return -1;
std::vector<int> ids(userIds, userIds + count);
@@ -763,6 +847,8 @@ extern "C" ANSFR_API int DeleteUsers(ANSCENTER::ANSFacialRecognition**
}
}
extern "C" ANSFR_API int InsertFace(ANSCENTER::ANSFacialRecognition** Handle, int userId, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","InsertFace: HandlePtr=%p, *Handle=%p, userId=%d, bufLen=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId, bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0) return -1;
cv::Mat frame = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
@@ -778,6 +864,8 @@ extern "C" ANSFR_API int InsertFace(ANSCENTER::ANSFacialRecognition** H
}
extern "C" ANSFR_API int InsertFaces(ANSCENTER::ANSFacialRecognition** Handle, int userId, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle faceIdsStr) {
ANS_DBG("ANSFR","InsertFaces: HandlePtr=%p, *Handle=%p, userId=%d, bufLen=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId, bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0 || !faceIdsStr) return -1;
cv::Mat frame = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
@@ -797,6 +885,8 @@ extern "C" ANSFR_API int InsertFaces(ANSCENTER::ANSFacialRecognition**
extern "C" ANSFR_API int CheckFaceEmbedding(ANSCENTER::ANSFacialRecognition** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","CheckFaceEmbedding: HandlePtr=%p, *Handle=%p, bufLen=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
if (!Handle || !*Handle || !jpeg_string || bufferLength == 0) return -1;
cv::Mat frame = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
@@ -812,6 +902,8 @@ extern "C" ANSFR_API int CheckFaceEmbedding(ANSCENTER::ANSFacialRecogni
}
extern "C" ANSFR_API int InsertFaceBinary(ANSCENTER::ANSFacialRecognition** Handle, int userId, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSFR","InsertFaceBinary: HandlePtr=%p, *Handle=%p, userId=%d, %ux%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId, width, height);
try {
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return -1;
cv::Mat frame = cv::Mat(height, width, CV_8UC3, jpeg_bytes).clone(); // make a copy
@@ -826,6 +918,8 @@ extern "C" ANSFR_API int InsertFaceBinary(ANSCENTER::ANSFacialRecogniti
}
}
extern "C" ANSFR_API int DeleteFace(ANSCENTER::ANSFacialRecognition** Handle, int faceId) {
ANS_DBG("ANSFR","DeleteFace: HandlePtr=%p, *Handle=%p, faceId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), faceId);
try {
if (!Handle || !*Handle) return -1;
int result = (*Handle)->DeleteFace(faceId);
@@ -836,6 +930,7 @@ extern "C" ANSFR_API int DeleteFace(ANSCENTER::ANSFacialRecognition** H
}
}
extern "C" ANSFR_API int Reload(ANSCENTER::ANSFacialRecognition** Handle) {
ANS_DBG("ANSFR","Reload: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle) return -1;
bool result = (*Handle)->Reload();
@@ -849,6 +944,8 @@ extern "C" ANSFR_API int Reload(ANSCENTER::ANSFacialRecognition** Handl
// New management API
extern "C" ANSFR_API int GetUser(ANSCENTER::ANSFacialRecognition** Handle, int userId, LStrHandle userRecord) {
ANS_DBG("ANSFR","GetUser: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle || !userRecord) return -1;
std::string st;
@@ -860,6 +957,7 @@ extern "C" ANSFR_API int GetUser(ANSCENTER::ANSFacialRecognition** Handle, in
}
}
extern "C" ANSFR_API int GetUsers(ANSCENTER::ANSFacialRecognition** Handle, LStrHandle userRecords) {
ANS_DBG("ANSFR","GetUsers: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle || !userRecords) return -1;
std::string st;
@@ -872,6 +970,8 @@ extern "C" ANSFR_API int GetUsers(ANSCENTER::ANSFacialRecognition** Handle, L
}
}
extern "C" ANSFR_API int GetFace(ANSCENTER::ANSFacialRecognition** Handle, int faceId, LStrHandle faceRecord) {
ANS_DBG("ANSFR","GetFace: HandlePtr=%p, *Handle=%p, faceId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), faceId);
try {
if (!Handle || !*Handle || !faceRecord) return -1;
std::string st;
@@ -883,6 +983,8 @@ extern "C" ANSFR_API int GetFace(ANSCENTER::ANSFacialRecognition** Handle, in
}
}
extern "C" ANSFR_API int GetFaces(ANSCENTER::ANSFacialRecognition** Handle, int userId, LStrHandle faceRecords) {
ANS_DBG("ANSFR","GetFaces: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle || !faceRecords) return -1;
std::string st;
@@ -894,6 +996,8 @@ extern "C" ANSFR_API int GetFaces(ANSCENTER::ANSFacialRecognition** Handle, i
}
}
extern "C" ANSFR_API int DeleteFacesByUser(ANSCENTER::ANSFacialRecognition** Handle, int userId) {
ANS_DBG("ANSFR","DeleteFacesByUser: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle) return -1;
int ret = (*Handle)->DeleteFacesByUser(userId);
@@ -907,6 +1011,8 @@ extern "C" ANSFR_API int DeleteFacesByUser(ANSCENTER::ANSFacialRecognition**
// For testing only
extern "C" ANSFR_API int GetUserString(ANSCENTER::ANSFacialRecognition** Handle, int userId, std::string& userRecord) {
ANS_DBG("ANSFR","GetUserString: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle) return -1;
(*Handle)->GetUser(userId, userRecord);
@@ -917,6 +1023,7 @@ extern "C" ANSFR_API int GetUserString(ANSCENTER::ANSFacialRecognition** Hand
}
}
extern "C" ANSFR_API int GetUsersString(ANSCENTER::ANSFacialRecognition** Handle, std::string& userRecords, std::vector<int>& userIds) {
ANS_DBG("ANSFR","GetUsersString: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle) return -1;
(*Handle)->GetUsers(userRecords, userIds);
@@ -927,6 +1034,8 @@ extern "C" ANSFR_API int GetUsersString(ANSCENTER::ANSFacialRecognition** Han
}
}
extern "C" ANSFR_API int GetFaceString(ANSCENTER::ANSFacialRecognition** Handle, int faceId, std::string& faceRecord) {
ANS_DBG("ANSFR","GetFaceString: HandlePtr=%p, *Handle=%p, faceId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), faceId);
try {
if (!Handle || !*Handle) return -1;
(*Handle)->GetFace(faceId, faceRecord);
@@ -937,6 +1046,8 @@ extern "C" ANSFR_API int GetFaceString(ANSCENTER::ANSFacialRecognition** Hand
}
}
extern "C" ANSFR_API int GetFacesString(ANSCENTER::ANSFacialRecognition** Handle, int userId, std::string& faceRecords) {
ANS_DBG("ANSFR","GetFacesString: HandlePtr=%p, *Handle=%p, userId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), userId);
try {
if (!Handle || !*Handle) return -1;
(*Handle)->GetFaces(userId, faceRecords);
@@ -949,6 +1060,7 @@ extern "C" ANSFR_API int GetFacesString(ANSCENTER::ANSFacialRecognition** Han
extern "C" ANSFR_API double BlurCalculation(unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSFR","BlurCalculation: bufLen=%u", bufferLength);
try {
if (!jpeg_string || bufferLength == 0) return -1;
cv::Mat image = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
@@ -970,6 +1082,8 @@ extern "C" ANSFR_API double BlurCalculation(unsigned char* jpeg_string, un
// Unicode conversion utilities for LabVIEW wrapper classes
extern "C" ANSFR_API int ANSFR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM) {
ANS_DBG("ANSFR","ANSFR_ConvertUTF8ToUTF16LE: includeBOM=%d, len=%d",
includeBOM, utf8Str ? (int)strlen(utf8Str) : -1);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -1025,6 +1139,7 @@ extern "C" ANSFR_API int ANSFR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHan
}
extern "C" ANSFR_API int ANSFR_ConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSFR","ANSFR_ConvertUTF16LEToUTF8: byteLen=%d", byteLen);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
bool isUtf16le = (byteLen >= 2 && byteLen % 2 == 0);
@@ -1062,6 +1177,10 @@ extern "C" ANSFR_API int ANSFR_ConvertUTF16LEToUTF8(const unsigned char* utf16le
}
extern "C" ANSFR_API int UpdateParameters(ANSCENTER::ANSFacialRecognition** Handle, float knownPersonThreshold, int enableAgeGender, int enableFaceEmotions, int enableHeadPose, int minFaceSize, float faceDetectorThreshold, int enableFaceliveness, int antiSpoof, int removeFakeFaces) {
ANS_DBG("ANSFR","UpdateParameters: HandlePtr=%p, *Handle=%p, knownThr=%f, ageGender=%d, emotions=%d, headPose=%d, minFace=%d, faceThr=%f, liveness=%d, antiSpoof=%d, removeFake=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), knownPersonThreshold,
enableAgeGender, enableFaceEmotions, enableHeadPose, minFaceSize,
faceDetectorThreshold, enableFaceliveness, antiSpoof, removeFakeFaces);
try {
if (!Handle || !*Handle) return -1;
bool _enableAgeGender = false;
@@ -1088,6 +1207,7 @@ extern "C" ANSFR_API int UpdateParameters(ANSCENTER::ANSFacialRecogniti
extern "C" ANSFR_API int GetParamters(ANSCENTER::ANSFacialRecognition** Handle, LStrHandle faceParams) {
ANS_DBG("ANSFR","GetParamters: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle || !faceParams) return -1;
std::string st;
@@ -1134,6 +1254,8 @@ extern "C" ANSFR_API int GetParamters(ANSCENTER::ANSFacialRecognition** Handl
}
}
extern "C" ANSFR_API int UpdateFaceQueue(ANSCENTER::ANSFacialRecognition** Handle, int queueSize, int numKnownFaceInQueue, int enableFaceQueue) {
ANS_DBG("ANSFR","UpdateFaceQueue: HandlePtr=%p, *Handle=%p, queueSize=%d, numKnown=%d, enable=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), queueSize, numKnownFaceInQueue, enableFaceQueue);
try {
if (!Handle || !*Handle) return -1;
bool _enableFaceQueue = false;
@@ -1147,6 +1269,7 @@ extern "C" ANSFR_API int UpdateFaceQueue(ANSCENTER::ANSFacialRecognitio
}
}
extern "C" ANSFR_API int GetFaceQueue(ANSCENTER::ANSFacialRecognition** Handle, LStrHandle faceQueue) {
ANS_DBG("ANSFR","GetFaceQueue: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (!Handle || !*Handle || !faceQueue) return -1;
std::string st;
@@ -1178,6 +1301,9 @@ extern "C" ANSFR_API int RunInferenceComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunInferenceComplete_LV: HandlePtr=%p, *Handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
// Validate inputs
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
if (!Handle || !(*Handle)) return -2;
@@ -1273,6 +1399,9 @@ extern "C" ANSFR_API int RunFaceDetectionComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunFaceDetectionComplete_LV: HandlePtr=%p, *Handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
// Validate inputs
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
if (!Handle || !(*Handle)) return -2;
@@ -1368,6 +1497,9 @@ extern "C" ANSFR_API int RunFaceRecogniserComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunFaceRecogniserComplete_LV: HandlePtr=%p, *Handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
// Validate inputs
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
if (!Handle || !(*Handle)) return -2;
@@ -1465,6 +1597,8 @@ extern "C" ANSFR_API int RunFaceRecogniserComplete_LV(
ANSCENTER::ANSFacialRecognition** Handle = &_v2Arr[0];
extern "C" ANSFR_API int RunInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunInference_LV_V2: handleVal=%llu handle=%p, bufLen=%u",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal), bufferLength);
FR_V2_HANDLE_SETUP(handleVal);
try {
if (!jpeg_string || bufferLength == 0 || !detectionResult) return -1;
@@ -1472,11 +1606,15 @@ extern "C" ANSFR_API int RunInference_LV_V2(uint64_t handleVal, unsigned char* j
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunInference_LV_V2 EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunInferenceWithCamId_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunInferenceWithCamId_LV_V2: handleVal=%llu handle=%p, bufLen=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
@@ -1496,6 +1634,8 @@ extern "C" ANSFR_API int RunInferenceWithCamId_LV_V2(uint64_t handleVal, unsigne
}
extern "C" ANSFR_API int RunDetector_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunDetector_LV_V2: handleVal=%llu handle=%p, bufLen=%u",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal), bufferLength);
FR_V2_HANDLE_SETUP(handleVal);
try {
if (!jpeg_string || bufferLength == 0 || !detectionResult) return -1;
@@ -1503,11 +1643,15 @@ extern "C" ANSFR_API int RunDetector_LV_V2(uint64_t handleVal, unsigned char* jp
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunDetector_LV_V2 EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunDetectorWithCamId_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunDetectorWithCamId_LV_V2: handleVal=%llu handle=%p, bufLen=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
@@ -1527,6 +1671,8 @@ extern "C" ANSFR_API int RunDetectorWithCamId_LV_V2(uint64_t handleVal, unsigned
}
extern "C" ANSFR_API int RunRecognition_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunRecognition_LV_V2: handleVal=%llu handle=%p, bufLen=%u",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal), bufferLength);
FR_V2_HANDLE_SETUP(handleVal);
try {
if (!jpeg_string || bufferLength == 0 || !detectionResult) return -1;
@@ -1534,11 +1680,15 @@ extern "C" ANSFR_API int RunRecognition_LV_V2(uint64_t handleVal, unsigned char*
return CopyToLStrHandle(detectionResult, st);
}
catch (const std::exception& e) {
ANS_DBG("ANSFR","RunRecognition_LV_V2 EXCEPTION: %s", e.what());
return -1;
}
}
extern "C" ANSFR_API int RunRecognitionWithCamId_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunRecognitionWithCamId_LV_V2: handleVal=%llu handle=%p, bufLen=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
@@ -1558,6 +1708,9 @@ extern "C" ANSFR_API int RunRecognitionWithCamId_LV_V2(uint64_t handleVal, unsig
}
extern "C" ANSFR_API int RunFaceDetection_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSFR","RunFaceDetection_LV_V2: handleVal=%llu handle=%p, bufLen=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!jpeg_string || bufferLength == 0 || !cameraId || !detectionResult) return -1;
@@ -1585,6 +1738,9 @@ extern "C" ANSFR_API int RunInferenceComplete_LV_V2(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunInferenceComplete_LV_V2: handleVal=%llu handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1674,6 +1830,9 @@ extern "C" ANSFR_API int RunFaceDetectionComplete_LV_V2(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunFaceDetectionComplete_LV_V2: handleVal=%llu handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1763,6 +1922,9 @@ extern "C" ANSFR_API int RunFaceRecogniserComplete_LV_V2(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSFR","RunFaceRecogniserComplete_LV_V2: handleVal=%llu handle=%p, cam=%s, getJpeg=%d, jpegSize=%d",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
ANSCENTER::ANSFacialRecognition* _v2Direct = reinterpret_cast<ANSCENTER::ANSFacialRecognition*>(handleVal);
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;

View File

@@ -7,6 +7,8 @@
#include <mutex>
#include <cstdint>
// DebugView: filter on "[ANSLLM]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSLLMHandle is called while an operation is still running.
// destructionStarted: set by the first Unregister caller; blocks new Acquires
@@ -29,14 +31,30 @@ static std::condition_variable& LLMHandleRegistryCV() {
static void RegisterLLMHandle(ANSCENTER::ANSLLM* h) {
std::lock_guard<std::mutex> lk(LLMHandleRegistryMutex());
LLMHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSLLM","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, LLMHandleRegistry().size());
}
static ANSCENTER::ANSLLM* AcquireLLMHandle(ANSCENTER::ANSLLM* h) {
std::lock_guard<std::mutex> lk(LLMHandleRegistryMutex());
auto it = LLMHandleRegistry().find(h);
if (it == LLMHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == LLMHandleRegistry().end()) {
ANS_DBG("ANSLLM","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, LLMHandleRegistry().size());
size_t i = 0;
for (auto& kv : LLMHandleRegistry()) {
ANS_DBG("ANSLLM"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSLLM","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSLLM","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -54,10 +72,15 @@ static bool ReleaseLLMHandleRef(ANSCENTER::ANSLLM* h) {
static bool UnregisterLLMHandle(ANSCENTER::ANSLLM* h) {
std::unique_lock<std::mutex> lk(LLMHandleRegistryMutex());
auto it = LLMHandleRegistry().find(h);
if (it == LLMHandleRegistry().end()) return false;
if (it == LLMHandleRegistry().end()) {
ANS_DBG("ANSLLM","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSLLM","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSLLM","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = LLMHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -65,6 +88,7 @@ static bool UnregisterLLMHandle(ANSCENTER::ANSLLM* h) {
return it2 == LLMHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSLLM","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterLLMHandle timed out waiting for in-flight operations\n");
}
LLMHandleRegistry().erase(h);
@@ -112,7 +136,10 @@ static int CopyToLStrHandle(LStrHandle handle, const std::string& str) noexcept
}
extern "C" ANSLLM_API int CreateANSLLMHandle(ANSCENTER::ANSLLM** Handle, const char* licenseKey, int localLLM) {
if (Handle == nullptr || licenseKey == nullptr) return 0;
ANS_DBG("ANSLLM","Create called: HandlePtr=%p, *Handle(in)=%p, localLLM=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), localLLM);
if (Handle == nullptr) { ANS_DBG("ANSLLM","Create FAIL: Handle is null"); return 0; }
if (licenseKey == nullptr) { ANS_DBG("ANSLLM","Create FAIL: licenseKey is null"); return 0; }
try {
// Pure constructor: ignore *Handle(in). LabVIEW's CLF Node marshalling
// reuses the same temp buffer per call site, so *Handle(in) often holds
@@ -126,37 +153,52 @@ extern "C" ANSLLM_API int CreateANSLLMHandle(ANSCENTER::ANSLLM** Handle, const
// std::unique_ptr ensures automatic cleanup on any failure path
auto ptr = std::make_unique<ANSCENTER::ANSLLM>();
ANS_DBG("ANSLLM","Create: allocated handle=%p (uint=%llu), calling Initialize...",
(void*)ptr.get(), (unsigned long long)(uintptr_t)ptr.get());
if (!ptr->Initialize(licenseKey, localLLM != 0)) {
// unique_ptr automatically deletes — no leak
ANS_DBG("ANSLLM","Create FAIL: Initialize returned false, handle=%p auto-deleted", (void*)ptr.get());
*Handle = nullptr;
return 0;
}
// Transfer ownership to caller on success
*Handle = ptr.release();
RegisterLLMHandle(*Handle);
ANS_DBG("ANSLLM","Create OK: handle=%p (uint=%llu)", (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return 1;
}
catch (const std::exception&) {
catch (const std::exception& e) {
ANS_DBG("ANSLLM","Create EXCEPTION (std::exception): %s", e.what());
*Handle = nullptr;
return 0;
}
catch (...) {
ANS_DBG("ANSLLM","Create EXCEPTION (unknown)");
*Handle = nullptr;
return 0;
}
}
static int ReleaseANSLLMHandle_Impl(ANSCENTER::ANSLLM** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterLLMHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSLLM","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSLLM* h = *Handle;
ANS_DBG("ANSLLM","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterLLMHandle(h)) {
ANS_DBG("ANSLLM","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1;
}
delete *Handle;
delete h;
*Handle = nullptr;
ANS_DBG("ANSLLM","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, LLMHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSLLM","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
@@ -167,12 +209,15 @@ extern "C" ANSLLM_API int ReleaseANSLLMHandle(ANSCENTER::ANSLLM** Handle) {
return ReleaseANSLLMHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSLLM","ReleaseANSLLMHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSLLM_API int SetANSLLMProvider(ANSCENTER::ANSLLM** Handle, const char* provider) {
ANS_DBG("ANSLLM","SetANSLLMProvider: HandlePtr=%p, *Handle=%p, provider=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), provider ? provider : "(null)");
if (Handle == nullptr || *Handle == nullptr || provider == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -187,6 +232,7 @@ extern "C" ANSLLM_API int SetANSLLMProvider(ANSCENTER::ANSLLM** Handle, const c
}
}
extern "C" ANSLLM_API int GetANSLLMProvider(ANSCENTER::ANSLLM** Handle, LStrHandle provider) {
ANS_DBG("ANSLLM","GetANSLLMProvider: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -202,6 +248,7 @@ extern "C" ANSLLM_API int GetANSLLMProvider(ANSCENTER::ANSLLM** Handle, LStrHan
}
extern "C" ANSLLM_API int SetApiKey(ANSCENTER::ANSLLM** Handle, const char* apiKey) {
ANS_DBG("ANSLLM","SetApiKey: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || apiKey == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -218,6 +265,7 @@ extern "C" ANSLLM_API int SetApiKey(ANSCENTER::ANSLLM** Handle, const char* api
extern "C" ANSLLM_API int ANSLLMGetModelList(ANSCENTER::ANSLLM** Handle, LStrHandle modelList) {
ANS_DBG("ANSLLM","ANSLLMGetModelList: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -238,6 +286,8 @@ extern "C" ANSLLM_API int ANSLLMGetModelList(ANSCENTER::ANSLLM** Handle, LStrHa
}
}
extern "C" ANSLLM_API int ANSLLMSetTranscriptMode(ANSCENTER::ANSLLM** Handle, int transcriptMode) {
ANS_DBG("ANSLLM","ANSLLMSetTranscriptMode: HandlePtr=%p, *Handle=%p, transcriptMode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), transcriptMode);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -252,6 +302,8 @@ extern "C" ANSLLM_API int ANSLLMSetTranscriptMode(ANSCENTER::ANSLLM** Handle, i
}
}
extern "C" ANSLLM_API int ANSLLMSetModel(ANSCENTER::ANSLLM** Handle, const char* modelName) {
ANS_DBG("ANSLLM","ANSLLMSetModel: HandlePtr=%p, *Handle=%p, modelName=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), modelName ? modelName : "(null)");
if (Handle == nullptr || *Handle == nullptr || modelName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -267,6 +319,7 @@ extern "C" ANSLLM_API int ANSLLMSetModel(ANSCENTER::ANSLLM** Handle, const char
}
extern "C" ANSLLM_API int ANSLLMInputAddText(ANSCENTER::ANSLLM** Handle, const char* inputText) {
ANS_DBG("ANSLLM","ANSLLMInputAddText: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || inputText == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -281,6 +334,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddText(ANSCENTER::ANSLLM** Handle, const
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageUrl(ANSCENTER::ANSLLM** Handle, const char* imageURL, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageUrl: HandlePtr=%p, *Handle=%p, imageURL=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageURL ? imageURL : "(null)");
if (Handle == nullptr || *Handle == nullptr || imageURL == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -296,6 +351,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageUrl(ANSCENTER::ANSLLM** Handle, co
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageFromPath(ANSCENTER::ANSLLM** Handle, const char* filePath, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageFromPath: HandlePtr=%p, *Handle=%p, filePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), filePath ? filePath : "(null)");
if (Handle == nullptr || *Handle == nullptr || filePath == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -311,6 +368,7 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageFromPath(ANSCENTER::ANSLLM** Handl
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageFromBase64(ANSCENTER::ANSLLM** Handle, const char* base64Image, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageFromBase64: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || base64Image == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -326,6 +384,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageFromBase64(ANSCENTER::ANSLLM** Han
}
}
extern "C" ANSLLM_API int ANSLLMInputAddFileURL(ANSCENTER::ANSLLM** Handle, const char* fileURL, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddFileURL: HandlePtr=%p, *Handle=%p, fileURL=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), fileURL ? fileURL : "(null)");
if (Handle == nullptr || *Handle == nullptr || fileURL == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -341,6 +401,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddFileURL(ANSCENTER::ANSLLM** Handle, con
}
}
extern "C" ANSLLM_API int ANSLLMInputAddFileData(ANSCENTER::ANSLLM** Handle, const char* filePath, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddFileData: HandlePtr=%p, *Handle=%p, filePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), filePath ? filePath : "(null)");
if (Handle == nullptr || *Handle == nullptr || filePath == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -356,6 +418,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddFileData(ANSCENTER::ANSLLM** Handle, co
}
}
extern "C" ANSLLM_API int ANSLLMCreateConversation(ANSCENTER::ANSLLM** Handle, const char* systemMessage, const char* developerMessage, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMCreateConversation: HandlePtr=%p, *Handle=%p, conversationName=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), conversationName ? conversationName : "(null)");
if (Handle == nullptr || *Handle == nullptr) return 0;
if (systemMessage == nullptr || developerMessage == nullptr || conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
@@ -371,6 +435,8 @@ extern "C" ANSLLM_API int ANSLLMCreateConversation(ANSCENTER::ANSLLM** Handle,
}
}
extern "C" ANSLLM_API int ANSLLMSetConversation(ANSCENTER::ANSLLM** Handle, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMSetConversation: HandlePtr=%p, *Handle=%p, conversationName=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), conversationName ? conversationName : "(null)");
if (Handle == nullptr || *Handle == nullptr || conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -385,6 +451,7 @@ extern "C" ANSLLM_API int ANSLLMSetConversation(ANSCENTER::ANSLLM** Handle, con
}
}
extern "C" ANSLLM_API int ANSLLMAsk(ANSCENTER::ANSLLM** Handle, const char* prompt, LStrHandle response) {
ANS_DBG("ANSLLM","ANSLLMAsk: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || prompt == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -400,6 +467,7 @@ extern "C" ANSLLM_API int ANSLLMAsk(ANSCENTER::ANSLLM** Handle, const char* pro
}
extern "C" ANSLLM_API int ANSLLMClearInput(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMClearInput: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -414,6 +482,7 @@ extern "C" ANSLLM_API int ANSLLMClearInput(ANSCENTER::ANSLLM** Handle) {
}
}
extern "C" ANSLLM_API int ANSLLMGetConversationList(ANSCENTER::ANSLLM** Handle, LStrHandle conversationList) {
ANS_DBG("ANSLLM","ANSLLMGetConversationList: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -434,6 +503,8 @@ extern "C" ANSLLM_API int ANSLLMGetConversationList(ANSCENTER::ANSLLM** Handle,
}
}
extern "C" ANSLLM_API int ANSLLMDeleteConversation(ANSCENTER::ANSLLM** Handle, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMDeleteConversation: HandlePtr=%p, *Handle=%p, conversationName=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), conversationName ? conversationName : "(null)");
if (Handle == nullptr || *Handle == nullptr || conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -448,6 +519,8 @@ extern "C" ANSLLM_API int ANSLLMDeleteConversation(ANSCENTER::ANSLLM** Handle,
}
}
extern "C" ANSLLM_API int ANSLLMSetUTF8(ANSCENTER::ANSLLM** Handle, int utf8Mode) {
ANS_DBG("ANSLLM","ANSLLMSetUTF8: HandlePtr=%p, *Handle=%p, utf8Mode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), utf8Mode);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -462,6 +535,7 @@ extern "C" ANSLLM_API int ANSLLMSetUTF8(ANSCENTER::ANSLLM** Handle, int utf8Mod
}
}
extern "C" ANSLLM_API int ANSLLMGetUTF8(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMGetUTF8: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -476,6 +550,8 @@ extern "C" ANSLLM_API int ANSLLMGetUTF8(ANSCENTER::ANSLLM** Handle) {
}
}
extern "C" ANSLLM_API int ANSLLMPollAi(ANSCENTER::ANSLLM** Handle, int abort) {
ANS_DBG("ANSLLM","ANSLLMPollAi: HandlePtr=%p, *Handle=%p, abort=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), abort);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -491,6 +567,8 @@ extern "C" ANSLLM_API int ANSLLMPollAi(ANSCENTER::ANSLLM** Handle, int abort) {
}
extern "C" ANSLLM_API int ANSLLMSetLocalLLM(ANSCENTER::ANSLLM** Handle, int localLLM) {
ANS_DBG("ANSLLM","ANSLLMSetLocalLLM: HandlePtr=%p, *Handle=%p, localLLM=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), localLLM);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -505,6 +583,8 @@ extern "C" ANSLLM_API int ANSLLMSetLocalLLM(ANSCENTER::ANSLLM** Handle, int loc
}
}
extern "C" ANSLLM_API int ANSLLMSetOllamaBaseUrl(ANSCENTER::ANSLLM** Handle, const char* baseUrl) {
ANS_DBG("ANSLLM","ANSLLMSetOllamaBaseUrl: HandlePtr=%p, *Handle=%p, baseUrl=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), baseUrl ? baseUrl : "(null)");
if (Handle == nullptr || *Handle == nullptr || baseUrl == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -519,6 +599,8 @@ extern "C" ANSLLM_API int ANSLLMSetOllamaBaseUrl(ANSCENTER::ANSLLM** Handle, co
}
}
extern "C" ANSLLM_API int ANSLLMSetBaseURL(ANSCENTER::ANSLLM** Handle, const char* baseURL) {
ANS_DBG("ANSLLM","ANSLLMSetBaseURL: HandlePtr=%p, *Handle=%p, baseURL=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), baseURL ? baseURL : "(null)");
if (Handle == nullptr || *Handle == nullptr || baseURL == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -533,6 +615,8 @@ extern "C" ANSLLM_API int ANSLLMSetBaseURL(ANSCENTER::ANSLLM** Handle, const ch
}
}
extern "C" ANSLLM_API int ANSLLMSetHeartbeatMs(ANSCENTER::ANSLLM** Handle, int heartbeatMs) {
ANS_DBG("ANSLLM","ANSLLMSetHeartbeatMs: HandlePtr=%p, *Handle=%p, heartbeatMs=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), heartbeatMs);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -547,6 +631,7 @@ extern "C" ANSLLM_API int ANSLLMSetHeartbeatMs(ANSCENTER::ANSLLM** Handle, int
}
}
extern "C" ANSLLM_API int ANSLLMGetHeartbeatMs(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMGetHeartbeatMs: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return -1;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return -1;
@@ -561,6 +646,8 @@ extern "C" ANSLLM_API int ANSLLMGetHeartbeatMs(ANSCENTER::ANSLLM** Handle) {
}
}
extern "C" ANSLLM_API int ANSLLMSetHostedConversation(ANSCENTER::ANSLLM** Handle, int hostedConversationMode) {
ANS_DBG("ANSLLM","ANSLLMSetHostedConversation: HandlePtr=%p, *Handle=%p, hostedConversationMode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), hostedConversationMode);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -575,6 +662,7 @@ extern "C" ANSLLM_API int ANSLLMSetHostedConversation(ANSCENTER::ANSLLM** Handl
}
}
extern "C" ANSLLM_API int ANSLLMGetHostedConversation(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMGetHostedConversation: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -589,6 +677,7 @@ extern "C" ANSLLM_API int ANSLLMGetHostedConversation(ANSCENTER::ANSLLM** Handl
}
}
extern "C" ANSLLM_API int ANSLLMGetStreamingMode(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMGetStreamingMode: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -603,6 +692,8 @@ extern "C" ANSLLM_API int ANSLLMGetStreamingMode(ANSCENTER::ANSLLM** Handle) {
}
}
extern "C" ANSLLM_API int ANSLLMSetStreamingMode(ANSCENTER::ANSLLM** Handle, int streamingMode) {
ANS_DBG("ANSLLM","ANSLLMSetStreamingMode: HandlePtr=%p, *Handle=%p, streamingMode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), streamingMode);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -617,6 +708,7 @@ extern "C" ANSLLM_API int ANSLLMSetStreamingMode(ANSCENTER::ANSLLM** Handle, in
}
}
extern "C" ANSLLM_API int ANSLLMGetIdleTimeoutMs(ANSCENTER::ANSLLM** Handle) {
ANS_DBG("ANSLLM","ANSLLMGetIdleTimeoutMs: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return -1;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return -1;
@@ -631,6 +723,8 @@ extern "C" ANSLLM_API int ANSLLMGetIdleTimeoutMs(ANSCENTER::ANSLLM** Handle) {
}
}
extern "C" ANSLLM_API int ANSLLMSetIdleTimeoutMs(ANSCENTER::ANSLLM** Handle, int idleTimeoutMs) {
ANS_DBG("ANSLLM","ANSLLMSetIdleTimeoutMs: HandlePtr=%p, *Handle=%p, idleTimeoutMs=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), idleTimeoutMs);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -646,6 +740,8 @@ extern "C" ANSLLM_API int ANSLLMSetIdleTimeoutMs(ANSCENTER::ANSLLM** Handle, in
}
extern "C" ANSLLM_API int ANSLLMSetSleepMs(ANSCENTER::ANSLLM** Handle, int sleepMs) {
ANS_DBG("ANSLLM","ANSLLMSetSleepMs: HandlePtr=%p, *Handle=%p, sleepMs=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), sleepMs);
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -660,6 +756,7 @@ extern "C" ANSLLM_API int ANSLLMSetSleepMs(ANSCENTER::ANSLLM** Handle, int slee
}
}
extern "C" ANSLLM_API int ANSLLMGetLastErrorMessage(ANSCENTER::ANSLLM** Handle, LStrHandle LastErrorMessage) {
ANS_DBG("ANSLLM","ANSLLMGetLastErrorMessage: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -674,6 +771,7 @@ extern "C" ANSLLM_API int ANSLLMGetLastErrorMessage(ANSCENTER::ANSLLM** Handle,
}
}
extern "C" ANSLLM_API int ANSLLMGetOutputText(ANSCENTER::ANSLLM** Handle, LStrHandle outputText) {
ANS_DBG("ANSLLM","ANSLLMGetOutputText: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -688,6 +786,7 @@ extern "C" ANSLLM_API int ANSLLMGetOutputText(ANSCENTER::ANSLLM** Handle, LStrH
}
}
extern "C" ANSLLM_API int ANSLLMGetOutputTextSb(ANSCENTER::ANSLLM** Handle, LStrHandle outputTextSb) {
ANS_DBG("ANSLLM","ANSLLMGetOutputTextSb: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(*Handle));
if (!guard) return 0;
@@ -709,6 +808,8 @@ extern "C" ANSLLM_API int ANSLLMGetOutputTextSb(ANSCENTER::ANSLLM** Handle, LSt
// ============================================================================
extern "C" ANSLLM_API int SetANSLLMProvider_V2(uint64_t handleVal, const char* provider) {
ANS_DBG("ANSLLM","SetANSLLMProvider_V2: handleVal=%llu, provider=%s",
(unsigned long long)handleVal, provider ? provider : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -723,6 +824,7 @@ extern "C" ANSLLM_API int SetANSLLMProvider_V2(uint64_t handleVal, const char*
}
}
extern "C" ANSLLM_API int GetANSLLMProvider_V2(uint64_t handleVal, LStrHandle provider) {
ANS_DBG("ANSLLM","GetANSLLMProvider_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -737,6 +839,7 @@ extern "C" ANSLLM_API int GetANSLLMProvider_V2(uint64_t handleVal, LStrHandle p
}
}
extern "C" ANSLLM_API int SetApiKey_V2(uint64_t handleVal, const char* apiKey) {
ANS_DBG("ANSLLM","SetApiKey_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -751,6 +854,7 @@ extern "C" ANSLLM_API int SetApiKey_V2(uint64_t handleVal, const char* apiKey)
}
}
extern "C" ANSLLM_API int ANSLLMGetModelList_V2(uint64_t handleVal, LStrHandle modelList) {
ANS_DBG("ANSLLM","ANSLLMGetModelList_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -771,6 +875,8 @@ extern "C" ANSLLM_API int ANSLLMGetModelList_V2(uint64_t handleVal, LStrHandle
}
}
extern "C" ANSLLM_API int ANSLLMSetTranscriptMode_V2(uint64_t handleVal, int transcriptMode) {
ANS_DBG("ANSLLM","ANSLLMSetTranscriptMode_V2: handleVal=%llu, transcriptMode=%d",
(unsigned long long)handleVal, transcriptMode);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -785,6 +891,8 @@ extern "C" ANSLLM_API int ANSLLMSetTranscriptMode_V2(uint64_t handleVal, int tr
}
}
extern "C" ANSLLM_API int ANSLLMSetModel_V2(uint64_t handleVal, const char* modelName) {
ANS_DBG("ANSLLM","ANSLLMSetModel_V2: handleVal=%llu, modelName=%s",
(unsigned long long)handleVal, modelName ? modelName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -799,6 +907,7 @@ extern "C" ANSLLM_API int ANSLLMSetModel_V2(uint64_t handleVal, const char* mod
}
}
extern "C" ANSLLM_API int ANSLLMInputAddText_V2(uint64_t handleVal, const char* inputText) {
ANS_DBG("ANSLLM","ANSLLMInputAddText_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -813,6 +922,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddText_V2(uint64_t handleVal, const char*
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageUrl_V2(uint64_t handleVal, const char* imageURL, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageUrl_V2: handleVal=%llu, imageURL=%s",
(unsigned long long)handleVal, imageURL ? imageURL : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -828,6 +939,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageUrl_V2(uint64_t handleVal, const c
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageFromPath_V2(uint64_t handleVal, const char* filePath, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageFromPath_V2: handleVal=%llu, filePath=%s",
(unsigned long long)handleVal, filePath ? filePath : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -843,6 +956,7 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageFromPath_V2(uint64_t handleVal, co
}
}
extern "C" ANSLLM_API int ANSLLMInputAddImageFromBase64_V2(uint64_t handleVal, const char* base64Image, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddImageFromBase64_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -858,6 +972,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddImageFromBase64_V2(uint64_t handleVal,
}
}
extern "C" ANSLLM_API int ANSLLMInputAddFileURL_V2(uint64_t handleVal, const char* fileURL, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddFileURL_V2: handleVal=%llu, fileURL=%s",
(unsigned long long)handleVal, fileURL ? fileURL : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -873,6 +989,8 @@ extern "C" ANSLLM_API int ANSLLMInputAddFileURL_V2(uint64_t handleVal, const ch
}
}
extern "C" ANSLLM_API int ANSLLMInputAddFileData_V2(uint64_t handleVal, const char* filePath, const char* summary) {
ANS_DBG("ANSLLM","ANSLLMInputAddFileData_V2: handleVal=%llu, filePath=%s",
(unsigned long long)handleVal, filePath ? filePath : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -888,6 +1006,7 @@ extern "C" ANSLLM_API int ANSLLMInputAddFileData_V2(uint64_t handleVal, const c
}
}
extern "C" ANSLLM_API int ANSLLMClearInput_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMClearInput_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -902,6 +1021,8 @@ extern "C" ANSLLM_API int ANSLLMClearInput_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMCreateConversation_V2(uint64_t handleVal, const char* systemMessage, const char* developerMessage, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMCreateConversation_V2: handleVal=%llu, conversationName=%s",
(unsigned long long)handleVal, conversationName ? conversationName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (systemMessage == nullptr || developerMessage == nullptr || conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -917,6 +1038,8 @@ extern "C" ANSLLM_API int ANSLLMCreateConversation_V2(uint64_t handleVal, const
}
}
extern "C" ANSLLM_API int ANSLLMSetConversation_V2(uint64_t handleVal, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMSetConversation_V2: handleVal=%llu, conversationName=%s",
(unsigned long long)handleVal, conversationName ? conversationName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -932,6 +1055,8 @@ extern "C" ANSLLM_API int ANSLLMSetConversation_V2(uint64_t handleVal, const ch
}
}
extern "C" ANSLLM_API int ANSLLMDeleteConversation_V2(uint64_t handleVal, const char* conversationName) {
ANS_DBG("ANSLLM","ANSLLMDeleteConversation_V2: handleVal=%llu, conversationName=%s",
(unsigned long long)handleVal, conversationName ? conversationName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (conversationName == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -947,6 +1072,7 @@ extern "C" ANSLLM_API int ANSLLMDeleteConversation_V2(uint64_t handleVal, const
}
}
extern "C" ANSLLM_API int ANSLLMGetConversationList_V2(uint64_t handleVal, LStrHandle conversationList) {
ANS_DBG("ANSLLM","ANSLLMGetConversationList_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -967,6 +1093,7 @@ extern "C" ANSLLM_API int ANSLLMGetConversationList_V2(uint64_t handleVal, LStr
}
}
extern "C" ANSLLM_API int ANSLLMAsk_V2(uint64_t handleVal, const char* prompt, LStrHandle response) {
ANS_DBG("ANSLLM","ANSLLMAsk_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (prompt == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -982,6 +1109,8 @@ extern "C" ANSLLM_API int ANSLLMAsk_V2(uint64_t handleVal, const char* prompt,
}
}
extern "C" ANSLLM_API int ANSLLMPollAi_V2(uint64_t handleVal, int abort) {
ANS_DBG("ANSLLM","ANSLLMPollAi_V2: handleVal=%llu, abort=%d",
(unsigned long long)handleVal, abort);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -996,6 +1125,8 @@ extern "C" ANSLLM_API int ANSLLMPollAi_V2(uint64_t handleVal, int abort) {
}
}
extern "C" ANSLLM_API int ANSLLMSetUTF8_V2(uint64_t handleVal, int utf8Mode) {
ANS_DBG("ANSLLM","ANSLLMSetUTF8_V2: handleVal=%llu, utf8Mode=%d",
(unsigned long long)handleVal, utf8Mode);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1010,6 +1141,7 @@ extern "C" ANSLLM_API int ANSLLMSetUTF8_V2(uint64_t handleVal, int utf8Mode) {
}
}
extern "C" ANSLLM_API int ANSLLMGetUTF8_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMGetUTF8_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1024,6 +1156,8 @@ extern "C" ANSLLM_API int ANSLLMGetUTF8_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMSetLocalLLM_V2(uint64_t handleVal, int localLLM) {
ANS_DBG("ANSLLM","ANSLLMSetLocalLLM_V2: handleVal=%llu, localLLM=%d",
(unsigned long long)handleVal, localLLM);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1038,6 +1172,8 @@ extern "C" ANSLLM_API int ANSLLMSetLocalLLM_V2(uint64_t handleVal, int localLLM
}
}
extern "C" ANSLLM_API int ANSLLMSetOllamaBaseUrl_V2(uint64_t handleVal, const char* baseUrl) {
ANS_DBG("ANSLLM","ANSLLMSetOllamaBaseUrl_V2: handleVal=%llu, baseUrl=%s",
(unsigned long long)handleVal, baseUrl ? baseUrl : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (baseUrl == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -1053,6 +1189,8 @@ extern "C" ANSLLM_API int ANSLLMSetOllamaBaseUrl_V2(uint64_t handleVal, const c
}
}
extern "C" ANSLLM_API int ANSLLMSetBaseURL_V2(uint64_t handleVal, const char* baseURL) {
ANS_DBG("ANSLLM","ANSLLMSetBaseURL_V2: handleVal=%llu, baseURL=%s",
(unsigned long long)handleVal, baseURL ? baseURL : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
if (baseURL == nullptr) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
@@ -1068,6 +1206,8 @@ extern "C" ANSLLM_API int ANSLLMSetBaseURL_V2(uint64_t handleVal, const char* b
}
}
extern "C" ANSLLM_API int ANSLLMSetHeartbeatMs_V2(uint64_t handleVal, int heartbeatMs) {
ANS_DBG("ANSLLM","ANSLLMSetHeartbeatMs_V2: handleVal=%llu, heartbeatMs=%d",
(unsigned long long)handleVal, heartbeatMs);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1082,6 +1222,7 @@ extern "C" ANSLLM_API int ANSLLMSetHeartbeatMs_V2(uint64_t handleVal, int heart
}
}
extern "C" ANSLLM_API int ANSLLMGetHeartbeatMs_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMGetHeartbeatMs_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return -1;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return -1;
@@ -1096,6 +1237,8 @@ extern "C" ANSLLM_API int ANSLLMGetHeartbeatMs_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMSetHostedConversation_V2(uint64_t handleVal, int hostedConversationMode) {
ANS_DBG("ANSLLM","ANSLLMSetHostedConversation_V2: handleVal=%llu, hostedConversationMode=%d",
(unsigned long long)handleVal, hostedConversationMode);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1110,6 +1253,7 @@ extern "C" ANSLLM_API int ANSLLMSetHostedConversation_V2(uint64_t handleVal, in
}
}
extern "C" ANSLLM_API int ANSLLMGetHostedConversation_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMGetHostedConversation_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1124,6 +1268,7 @@ extern "C" ANSLLM_API int ANSLLMGetHostedConversation_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMGetStreamingMode_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMGetStreamingMode_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1138,6 +1283,8 @@ extern "C" ANSLLM_API int ANSLLMGetStreamingMode_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMSetStreamingMode_V2(uint64_t handleVal, int streamingMode) {
ANS_DBG("ANSLLM","ANSLLMSetStreamingMode_V2: handleVal=%llu, streamingMode=%d",
(unsigned long long)handleVal, streamingMode);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1152,6 +1299,7 @@ extern "C" ANSLLM_API int ANSLLMSetStreamingMode_V2(uint64_t handleVal, int str
}
}
extern "C" ANSLLM_API int ANSLLMGetIdleTimeoutMs_V2(uint64_t handleVal) {
ANS_DBG("ANSLLM","ANSLLMGetIdleTimeoutMs_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return -1;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return -1;
@@ -1166,6 +1314,8 @@ extern "C" ANSLLM_API int ANSLLMGetIdleTimeoutMs_V2(uint64_t handleVal) {
}
}
extern "C" ANSLLM_API int ANSLLMSetIdleTimeoutMs_V2(uint64_t handleVal, int idleTimeoutMs) {
ANS_DBG("ANSLLM","ANSLLMSetIdleTimeoutMs_V2: handleVal=%llu, idleTimeoutMs=%d",
(unsigned long long)handleVal, idleTimeoutMs);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1180,6 +1330,8 @@ extern "C" ANSLLM_API int ANSLLMSetIdleTimeoutMs_V2(uint64_t handleVal, int idl
}
}
extern "C" ANSLLM_API int ANSLLMSetSleepMs_V2(uint64_t handleVal, int sleepMs) {
ANS_DBG("ANSLLM","ANSLLMSetSleepMs_V2: handleVal=%llu, sleepMs=%d",
(unsigned long long)handleVal, sleepMs);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1194,6 +1346,7 @@ extern "C" ANSLLM_API int ANSLLMSetSleepMs_V2(uint64_t handleVal, int sleepMs)
}
}
extern "C" ANSLLM_API int ANSLLMGetLastErrorMessage_V2(uint64_t handleVal, LStrHandle LastErrorMessage) {
ANS_DBG("ANSLLM","ANSLLMGetLastErrorMessage_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1208,6 +1361,7 @@ extern "C" ANSLLM_API int ANSLLMGetLastErrorMessage_V2(uint64_t handleVal, LStr
}
}
extern "C" ANSLLM_API int ANSLLMGetOutputText_V2(uint64_t handleVal, LStrHandle outputText) {
ANS_DBG("ANSLLM","ANSLLMGetOutputText_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;
@@ -1222,6 +1376,7 @@ extern "C" ANSLLM_API int ANSLLMGetOutputText_V2(uint64_t handleVal, LStrHandle
}
}
extern "C" ANSLLM_API int ANSLLMGetOutputTextSb_V2(uint64_t handleVal, LStrHandle outputTextSb) {
ANS_DBG("ANSLLM","ANSLLMGetOutputTextSb_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSLLM*>(handleVal); if (!_v2h) return 0;
LLMHandleGuard guard(AcquireLLMHandle(_v2h));
if (!guard) return 0;

View File

@@ -1032,6 +1032,11 @@ namespace ANSCENTER {
}
bool ANSALPR_OD::shouldUseALPRChecker(const cv::Size& imageSize, const std::string& cameraId) {
// Master switch for tracker + voting post-processing. Off by default;
// flip with SetTrackerVotingEnabled(true) to re-enable alprChecker
// voting and ensureUniquePlateText dedup in all Inference/RunInference paths.
if (!_enableTrackerVoting) return false;
// Force disabled → never use
if (!_enableALPRChecker) return false;

View File

@@ -164,6 +164,12 @@ namespace ANSCENTER
// Tri-state: -1 = auto-detect (default), 0 = explicitly disabled, 1 = explicitly enabled
// _enableALPRChecker is inherited from ANSALPR base class
// Master switch for tracker + voting post-processing inside
// RunInference / RunInferenceSingleFrame. When false, these methods
// return raw per-frame OCR output (no alprChecker.checkPlateByTrackId
// voting, no spatial ensureUniquePlateText dedup). Default: disabled.
bool _enableTrackerVoting{ false };
struct ImageSizeTracker {
cv::Size lastSize{0, 0};
int consistentCount = 0;
@@ -252,6 +258,9 @@ namespace ANSCENTER
}
// SetALPRCheckerEnabled() and IsALPRCheckerEnabled() inherited from ANSALPR base class
void SetTrackerVotingEnabled(bool enable) { _enableTrackerVoting = enable; }
[[nodiscard]] bool IsTrackerVotingEnabled() const { return _enableTrackerVoting; }
};
}
#endif

View File

@@ -12,6 +12,8 @@
#include <condition_variable>
#include <cstdint>
// DebugView: filter on "[ANSLPR]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Write a message to Windows Event Log (Application log, source "ANSLogger").
// Works even when spdlog is not initialized — useful for crash diagnostics.
static void WriteWindowsEventLog(const char* message, WORD eventType = EVENTLOG_ERROR_TYPE) {
@@ -48,6 +50,8 @@ static std::condition_variable& ALPRHandleRegistryCV() {
static void RegisterALPRHandle(ANSCENTER::ANSALPR* h) {
std::lock_guard<std::mutex> lk(ALPRHandleRegistryMutex());
ALPRHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSLPR","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ALPRHandleRegistry().size());
}
// Acquire a handle for use (increment refcount). Returns the handle
@@ -55,9 +59,23 @@ static void RegisterALPRHandle(ANSCENTER::ANSALPR* h) {
static ANSCENTER::ANSALPR* AcquireALPRHandle(ANSCENTER::ANSALPR* h) {
std::lock_guard<std::mutex> lk(ALPRHandleRegistryMutex());
auto it = ALPRHandleRegistry().find(h);
if (it == ALPRHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == ALPRHandleRegistry().end()) {
ANS_DBG("ANSLPR","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ALPRHandleRegistry().size());
size_t i = 0;
for (auto& kv : ALPRHandleRegistry()) {
ANS_DBG("ANSLPR"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSLPR","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSLPR","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -79,11 +97,16 @@ static bool ReleaseALPRHandleRef(ANSCENTER::ANSALPR* h) {
static bool UnregisterALPRHandle(ANSCENTER::ANSALPR* h) {
std::unique_lock<std::mutex> lk(ALPRHandleRegistryMutex());
auto it = ALPRHandleRegistry().find(h);
if (it == ALPRHandleRegistry().end()) return false;
if (it->second.destructionStarted) {
// Another thread already owns the delete — back off.
if (it == ALPRHandleRegistry().end()) {
ANS_DBG("ANSLPR","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
// Another thread already owns the delete — back off.
ANS_DBG("ANSLPR","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false;
}
ANS_DBG("ANSLPR","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--; // Remove creation ref
bool ok = ALPRHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -91,6 +114,7 @@ static bool UnregisterALPRHandle(ANSCENTER::ANSALPR* h) {
return it2 == ALPRHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSLPR","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterALPRHandle timed out waiting for in-flight inference\n");
}
ALPRHandleRegistry().erase(h);
@@ -142,6 +166,10 @@ BOOL APIENTRY DllMain( HMODULE hModule,
static int CreateANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle, const char* licenseKey, const char* modelZipFilePath, const char* modelZipPassword,
int engineType, double detectorThreshold, double ocrThreshold, double colourThreshold) {
ANS_DBG("ANSLPR","Create called: HandlePtr=%p, *Handle(in)=%p, engineType=%d, detTh=%.3f, ocrTh=%.3f, colTh=%.3f, modelZip=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), engineType, detectorThreshold, ocrThreshold, colourThreshold,
modelZipFilePath ? modelZipFilePath : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSLPR","Create FAIL: Handle is null"); return 0; }
try {
// Ensure all shared DLLs (OpenCV, OpenVINO, TRT, ORT) are pre-loaded
ANSCENTER::ANSLibsLoader::Initialize();
@@ -166,31 +194,41 @@ static int CreateANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle, const char* lic
(*Handle) = new ANSCENTER::ANSALPR_OCR();// ONNX OCR (PaddleOCR v5)
}
else {
ANS_DBG("ANSLPR","Create FAIL: unknown engineType=%d", engineType);
return 0;
}
if (*Handle == nullptr) return 0;
if (*Handle == nullptr) { ANS_DBG("ANSLPR","Create FAIL: new returned null for engineType=%d", engineType); return 0; }
else {
ANS_DBG("ANSLPR","Create: allocated handle=%p (uint=%llu) engineType=%d, calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, engineType);
RegisterALPRHandle(*Handle);
int result = (*Handle)->Initialize(licenseKey, modelZipFilePath, modelZipPassword, detectorThreshold, ocrThreshold,colourThreshold);
ANS_DBG("ANSLPR","Create: Initialize returned %d for handle=%p (uint=%llu)",
result, (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return result;
}
}
catch (std::exception& e) {
ANS_DBG("ANSLPR","Create EXCEPTION (std::exception): %s", e.what());
return 0;
}
catch (...) {
ANS_DBG("ANSLPR","Create EXCEPTION (unknown)");
return 0;
}
}
extern "C" ANSLPR_API int CreateANSALPRHandle(ANSCENTER::ANSALPR * *Handle, const char* licenseKey, const char* modelZipFilePath, const char* modelZipPassword,
int engineType, double detectorThreshold, double ocrThreshold, double colourThreshold) {
ANS_DBG("ANSLPR","CreateANSALPRHandle: HandlePtr=%p, *Handle=%p, engineType=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), engineType);
__try {
return CreateANSALPRHandle_Impl(Handle, licenseKey, modelZipFilePath, modelZipPassword, engineType, detectorThreshold, ocrThreshold, colourThreshold);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
char buf[256];
snprintf(buf, sizeof(buf), "ANSLPR CreateANSALPRHandle: SEH exception 0x%08X caught during initialization", GetExceptionCode());
ANS_DBG("ANSLPR","CreateANSALPRHandle: SEH exception caught");
WriteWindowsEventLog(buf);
if (Handle) *Handle = nullptr;
return 0;
@@ -213,17 +251,22 @@ static int LoadANSALPREngineHandle_Impl(ANSCENTER::ANSALPR** Handle) {
}
extern "C" ANSLPR_API int LoadANSALPREngineHandle(ANSCENTER::ANSALPR** Handle) {
ANS_DBG("ANSLPR","LoadANSALPREngineHandle: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return LoadANSALPREngineHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
char buf[256];
snprintf(buf, sizeof(buf), "ANSLPR LoadANSALPREngineHandle: SEH exception 0x%08X caught during engine load", GetExceptionCode());
ANS_DBG("ANSLPR","LoadANSALPREngineHandle: SEH exception caught");
WriteWindowsEventLog(buf);
return 0;
}
}
extern "C" ANSLPR_API std::string ANSALPR_RunInference(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSLPR","ANSALPR_RunInference: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -240,6 +283,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInference(ANSCENTER::ANSALPR * *Ha
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceWithCamID(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%u, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -256,6 +301,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceWithCamID(ANSCENTER::ANSA
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImages(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -274,6 +321,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImages(ANSCENTER
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImagesWithCamID(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -292,6 +341,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceInCroppedImagesWithCamID(
}
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinary(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -309,6 +360,8 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinary(ANSCENTER::ANSALPR
extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinaryInCroppedImages(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, const char* strBboxes) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinaryInCroppedImages: HandlePtr=%p, *Handle=%p, width=%u, height=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return "";
ALPRHandleGuard guard(AcquireALPRHandle(*Handle));
if (!guard) return "";
@@ -328,32 +381,47 @@ extern "C" ANSLPR_API std::string ANSALPR_RunInferenceBinaryInCroppedImages(ANS
static int ReleaseANSALPRHandle_Impl(ANSCENTER::ANSALPR** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterALPRHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSLPR","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSALPR* h = *Handle;
ANS_DBG("ANSLPR","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterALPRHandle(h)) {
ANS_DBG("ANSLPR","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1; // Not in registry — already freed
}
(*Handle)->Destroy();
delete *Handle;
*Handle = nullptr;
ANS_DBG("ANSLPR","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, ALPRHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSLPR","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSLPR_API int ReleaseANSALPRHandle(ANSCENTER::ANSALPR** Handle) {
ANS_DBG("ANSLPR","ReleaseANSALPRHandle: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return ReleaseANSALPRHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSLPR","ReleaseANSALPRHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
//// For LabVIEW API
extern "C" ANSLPR_API int ANSALPR_RunInference_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInference_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
std::string st = ANSALPR_RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -375,8 +443,10 @@ extern "C" ANSLPR_API int ANSALPR_RunInference_LV(ANSCENTER::ANSALPR * *Handl
return 0;
}
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult)
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
if (st.empty()) return 0;
@@ -399,6 +469,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV(ANSCENTER::ANSALPR
}
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary_LV: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
std::string st = ANSALPR_RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -423,6 +495,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV(ANSCENTER::ANSALPR * *H
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV(ANSCENTER::ANSALPR * *Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
if (st.empty()) return 0;
@@ -446,6 +520,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV(ANSCENTER::A
}
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImagesWithCamID_LV(ANSCENTER::ANSALPR** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
if (st.empty()) return 0;
@@ -476,6 +552,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -580,6 +659,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV(
extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_CPP(ANSCENTER::ANSALPR** Handle, cv::Mat** cvImage, const char* cameraId, int getJpegString, int jpegImageSize, std::string& detectionResult, std::string& imageStr) {
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_CPP: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -661,6 +743,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesComplete_LV(
const char* strBboxes,
LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferencesComplete_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -756,6 +841,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV(
const char* strBboxes,
LStrHandle detectionResult)
{
ANS_DBG("ANSLPR","ANSALPR_RunInferencesBatch_LV: HandlePtr=%p, *Handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -832,6 +920,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV(
extern "C" ANSLPR_API int ANSALPR_SetFormat(ANSCENTER::ANSALPR** Handle, const char* format) {
ANS_DBG("ANSLPR","ANSALPR_SetFormat: HandlePtr=%p, *Handle=%p, format=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), format ? format : "(null)");
if (!Handle || !*Handle) return -1;
if (!format) return -1;
try {
@@ -848,6 +938,8 @@ extern "C" ANSLPR_API int ANSALPR_SetFormat(ANSCENTER::ANSALPR** Handle, con
}
extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, const char* formats){// semi separated formats
ANS_DBG("ANSLPR","ANSALPR_SetFormats: HandlePtr=%p, *Handle=%p, formats=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), formats ? formats : "(null)");
if (!Handle || !*Handle) return -1;
if (!formats) return -1;
try {
@@ -871,6 +963,8 @@ extern "C" ANSLPR_API int ANSALPR_SetFormats(ANSCENTER::ANSALPR** Handle, co
// ALPRChecker: 1 = enabled (full-frame auto-detected), 0 = disabled (raw OCR)
extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR** Handle, int enable) {
ANS_DBG("ANSLPR","ANSALPR_SetALPRCheckerEnabled: HandlePtr=%p, *Handle=%p, enable=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), enable);
if (!Handle || !*Handle) return -1;
try {
(*Handle)->SetALPRCheckerEnabled(enable != 0);
@@ -884,6 +978,8 @@ extern "C" ANSLPR_API int ANSALPR_SetALPRCheckerEnabled(ANSCENTER::ANSALPR**
}
extern "C" ANSLPR_API int ANSALPR_SetCountry(ANSCENTER::ANSALPR** Handle, int country) {
ANS_DBG("ANSLPR","ANSALPR_SetCountry: HandlePtr=%p, *Handle=%p, country=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), country);
if (!Handle || !*Handle) return -1;
try {
(*Handle)->SetCountry(static_cast<ANSCENTER::Country>(country));
@@ -896,6 +992,8 @@ extern "C" ANSLPR_API int ANSALPR_SetCountry(ANSCENTER::ANSALPR** Handle, in
extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LStrHandle Lstrformats)// semi separated formats
{
ANS_DBG("ANSLPR","ANSALPR_GetFormats: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (!Handle || !*Handle) return -1;
if (!Lstrformats) return -1;
try {
@@ -925,6 +1023,8 @@ extern "C" ANSLPR_API int ANSALPR_GetFormats(ANSCENTER::ANSALPR** Handle, LS
// Unicode conversion utilities for LabVIEW wrapper classes
extern "C" ANSLPR_API int ANSLPR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM) {
ANS_DBG("ANSLPR","ANSLPR_ConvertUTF8ToUTF16LE: utf8Str=%p, result=%p, includeBOM=%d",
(void*)utf8Str, (void*)result, includeBOM);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -980,6 +1080,8 @@ extern "C" ANSLPR_API int ANSLPR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrH
}
extern "C" ANSLPR_API int ANSLPR_ConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSLPR","ANSLPR_ConvertUTF16LEToUTF8: utf16leBytes=%p, byteLen=%d, result=%p",
(void*)utf16leBytes, byteLen, (void*)result);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
bool isUtf16le = (byteLen >= 2 && byteLen % 2 == 0);
@@ -1027,6 +1129,8 @@ extern "C" ANSLPR_API int ANSLPR_ConvertUTF16LEToUTF8(const unsigned char* utf16
extern "C" ANSLPR_API int ANSALPR_RunInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInference_LV_V2: handleVal=%llu handle=%p, bufferLength=%u",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength);
try {
std::string st = ANSALPR_RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -1051,6 +1155,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInference_LV_V2(uint64_t handleVal, unsigne
extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceWithCamID_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, cameraId=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
if (st.empty()) return 0;
@@ -1075,6 +1181,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceWithCamID_LV_V2(uint64_t handleVal
extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV_V2(uint64_t handleVal, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceBinary_LV_V2: handleVal=%llu handle=%p, width=%u, height=%u",
(unsigned long long)handleVal, (void*)_v2Direct, width, height);
try {
std::string st = ANSALPR_RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -1099,6 +1207,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceBinary_LV_V2(uint64_t handleVal, u
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImages_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, strBboxes ? strBboxes : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
if (st.empty()) return 0;
@@ -1123,6 +1233,8 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImages_LV_V2(uint64_t han
extern "C" ANSLPR_API int ANSALPR_RunInferenceInCroppedImagesWithCamID_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ALPR_V2_HANDLE_SETUP(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceInCroppedImagesWithCamID_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, strBboxes=%s, cameraId=%s",
(unsigned long long)handleVal, (void*)_v2Direct, bufferLength, strBboxes ? strBboxes : "(null)", cameraId ? cameraId : "(null)");
try {
std::string st = ANSALPR_RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
if (st.empty()) return 0;
@@ -1155,6 +1267,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferenceComplete_LV_V2(
LStrHandle imageStr)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferenceComplete_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, getJpeg=%d, jpegImageSize=%d",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1268,6 +1383,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesBatch_LV_V2(
LStrHandle detectionResult)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferencesBatch_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1343,6 +1461,9 @@ extern "C" ANSLPR_API int ANSALPR_RunInferencesComplete_LV_V2(
LStrHandle detectionResult)
{
ANSCENTER::ANSALPR* _v2Direct = reinterpret_cast<ANSCENTER::ANSALPR*>(handleVal);
ANS_DBG("ANSLPR","ANSALPR_RunInferencesComplete_LV_V2: handleVal=%llu handle=%p, cvImage=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)_v2Direct, (void*)(cvImage ? *cvImage : nullptr),
cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? strBboxes : "(null)");
if (_v2Direct == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;

View File

@@ -11,6 +11,8 @@
#include <mutex>
#include <cstdint>
// DebugView: filter on "[ANSMOT]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSMOTHandle is called while an operation is still running.
// destructionStarted: set by the first Unregister caller; blocks new Acquires
@@ -33,14 +35,30 @@ static std::condition_variable& MOTHandleRegistryCV() {
static void RegisterMOTHandle(ANSCENTER::ANSMOT* h) {
std::lock_guard<std::mutex> lk(MOTHandleRegistryMutex());
MOTHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSMOT","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, MOTHandleRegistry().size());
}
static ANSCENTER::ANSMOT* AcquireMOTHandle(ANSCENTER::ANSMOT* h) {
std::lock_guard<std::mutex> lk(MOTHandleRegistryMutex());
auto it = MOTHandleRegistry().find(h);
if (it == MOTHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == MOTHandleRegistry().end()) {
ANS_DBG("ANSMOT","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, MOTHandleRegistry().size());
size_t i = 0;
for (auto& kv : MOTHandleRegistry()) {
ANS_DBG("ANSMOT"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSMOT","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSMOT","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -58,10 +76,15 @@ static bool ReleaseMOTHandleRef(ANSCENTER::ANSMOT* h) {
static bool UnregisterMOTHandle(ANSCENTER::ANSMOT* h) {
std::unique_lock<std::mutex> lk(MOTHandleRegistryMutex());
auto it = MOTHandleRegistry().find(h);
if (it == MOTHandleRegistry().end()) return false;
if (it == MOTHandleRegistry().end()) {
ANS_DBG("ANSMOT","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSMOT","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSMOT","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = MOTHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -69,6 +92,7 @@ static bool UnregisterMOTHandle(ANSCENTER::ANSMOT* h) {
return it2 == MOTHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSMOT","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterMOTHandle timed out waiting for in-flight operations\n");
}
MOTHandleRegistry().erase(h);
@@ -111,7 +135,9 @@ BOOL APIENTRY DllMain( HMODULE hModule,
};
*/
extern "C" __declspec(dllexport) int __cdecl CreateANSMOTHandle(ANSCENTER::ANSMOT **Handle, int motType) {
if (Handle == nullptr) return 0;
ANS_DBG("ANSMOT","CreateANSMOTHandle: HandlePtr=%p, *Handle(in)=%p, motType=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), motType);
if (Handle == nullptr) { ANS_DBG("ANSMOT","Create FAIL: Handle is null"); return 0; }
try {
// Pure constructor: ignore *Handle(in). LabVIEW's CLF Node marshalling
// reuses the same temp buffer per call site, so *Handle(in) often holds
@@ -144,49 +170,70 @@ extern "C" __declspec(dllexport) int __cdecl CreateANSMOTHandle(ANSCENTER::
break;
}
if (*Handle == nullptr) {
ANS_DBG("ANSMOT","Create FAIL: new returned null");
return 0;
}
else {
ANS_DBG("ANSMOT","Create: allocated handle=%p (uint=%llu), calling Register...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
RegisterMOTHandle(*Handle);
ANS_DBG("ANSMOT","Create OK: handle=%p (uint=%llu)", (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return 1;
}
}
catch (std::exception& e) {
ANS_DBG("ANSMOT","Create EXCEPTION (std::exception): %s", e.what());
return 0;
}
catch (...) {
ANS_DBG("ANSMOT","Create EXCEPTION (unknown)");
return 0;
}
}
static int ReleaseANSMOTHandle_Impl(ANSCENTER::ANSMOT** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterMOTHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSMOT","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSMOT* h = *Handle;
ANS_DBG("ANSMOT","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterMOTHandle(h)) {
ANS_DBG("ANSMOT","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1;
}
(*Handle)->Destroy();
delete *Handle;
h->Destroy();
delete h;
*Handle = nullptr;
ANS_DBG("ANSMOT","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, MOTHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSMOT","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" __declspec(dllexport) int __cdecl ReleaseANSMOTHandle(ANSCENTER::ANSMOT **Handle) {
ANS_DBG("ANSMOT","ReleaseANSMOTHandle: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return ReleaseANSMOTHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSMOT","ReleaseANSMOTHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" __declspec(dllexport) int __cdecl UpdateANSMOTParameters(ANSCENTER::ANSMOT * *Handle, const char* trackerParameter) {
ANS_DBG("ANSMOT","UpdateANSMOTParameters: HandlePtr=%p, *Handle=%p, trackerParameter=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
trackerParameter ? trackerParameter : "(null)");
if (Handle == nullptr || *Handle == nullptr) return -1;
MOTHandleGuard guard(AcquireMOTHandle(*Handle));
if (!guard) return -1;
@@ -204,6 +251,8 @@ extern "C" __declspec(dllexport) int __cdecl UpdateANSMOTParameters(ANSCENTE
}
extern "C" __declspec(dllexport) int __cdecl UpdateANSMOT(ANSCENTER::ANSMOT * *Handle, int modelId, const char* detectionData, std::string & result) {
ANS_DBG("ANSMOT","UpdateANSMOT: HandlePtr=%p, *Handle=%p, modelId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), modelId);
if (Handle == nullptr || *Handle == nullptr) return -1;
MOTHandleGuard guard(AcquireMOTHandle(*Handle));
if (!guard) return -1;
@@ -220,6 +269,8 @@ extern "C" __declspec(dllexport) int __cdecl UpdateANSMOT(ANSCENTER::ANSMOT * *H
}
}
extern "C" __declspec(dllexport) int __cdecl UpdateANSMOT_LV(ANSCENTER::ANSMOT * *Handle, int modelId, const char* detectionData, LStrHandle trackerResult) {
ANS_DBG("ANSMOT","UpdateANSMOT_LV: HandlePtr=%p, *Handle=%p, modelId=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), modelId);
if (Handle == nullptr || *Handle == nullptr) return -1;
MOTHandleGuard guard(AcquireMOTHandle(*Handle));
if (!guard) return -1;
@@ -246,6 +297,8 @@ extern "C" __declspec(dllexport) int __cdecl UpdateANSMOT_LV(ANSCENTE
extern "C" __declspec(dllexport) int __cdecl UpdateANSMOTTracker(ANSCENTER::ANSMOT** Handle, int modelId, const std::vector<ANSCENTER::TrackerObject>& detectionObjects, std::vector<ANSCENTER::TrackerObject>& trackedObjects)
{
ANS_DBG("ANSMOT","UpdateANSMOTTracker: HandlePtr=%p, *Handle=%p, modelId=%d, detectionObjects.size=%zu",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), modelId, detectionObjects.size());
if (Handle == nullptr || *Handle == nullptr) return -1;
MOTHandleGuard guard(AcquireMOTHandle(*Handle));
if (!guard) return -1;
@@ -271,6 +324,8 @@ extern "C" __declspec(dllexport) int __cdecl UpdateANSMOTTracker(ANSC
extern "C" __declspec(dllexport) int __cdecl UpdateANSMOT_LV_V2(uint64_t handleVal, int modelId, const char* detectionData, LStrHandle trackerResult) {
ANSCENTER::ANSMOT* directHandle = reinterpret_cast<ANSCENTER::ANSMOT*>(handleVal);
ANS_DBG("ANSMOT","UpdateANSMOT_LV_V2: handleVal=%llu handle=%p, modelId=%d",
(unsigned long long)handleVal, (void*)directHandle, modelId);
if (directHandle == nullptr) return -1;
MOTHandleGuard guard(AcquireMOTHandle(directHandle));
if (!guard) return -1;

View File

@@ -14,6 +14,7 @@
#include <condition_variable>
#include <cstdint>
// DebugView: filter on "[ANSOCR]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSOCRHandle is called while inference is still running.
@@ -37,14 +38,30 @@ static std::condition_variable& OCRHandleRegistryCV() {
static void RegisterOCRHandle(ANSCENTER::ANSOCRBase* h) {
std::lock_guard<std::mutex> lk(OCRHandleRegistryMutex());
OCRHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSOCR","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, OCRHandleRegistry().size());
}
static ANSCENTER::ANSOCRBase* AcquireOCRHandle(ANSCENTER::ANSOCRBase* h) {
std::lock_guard<std::mutex> lk(OCRHandleRegistryMutex());
auto it = OCRHandleRegistry().find(h);
if (it == OCRHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == OCRHandleRegistry().end()) {
ANS_DBG("ANSOCR","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, OCRHandleRegistry().size());
size_t i = 0;
for (auto& kv : OCRHandleRegistry()) {
ANS_DBG("ANSOCR"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSOCR","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSOCR","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -62,10 +79,15 @@ static bool ReleaseOCRHandleRef(ANSCENTER::ANSOCRBase* h) {
static bool UnregisterOCRHandle(ANSCENTER::ANSOCRBase* h) {
std::unique_lock<std::mutex> lk(OCRHandleRegistryMutex());
auto it = OCRHandleRegistry().find(h);
if (it == OCRHandleRegistry().end()) return false;
if (it == OCRHandleRegistry().end()) {
ANS_DBG("ANSOCR","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSOCR","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSOCR","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = OCRHandleRegistryCV().wait_for(lk, std::chrono::seconds(5), [&]() {
@@ -73,6 +95,7 @@ static bool UnregisterOCRHandle(ANSCENTER::ANSOCRBase* h) {
return it2 == OCRHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSOCR","WARNING: Unregister timed out waiting for in-flight inference on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterOCRHandle timed out waiting for in-flight inference\n");
}
OCRHandleRegistry().erase(h);
@@ -153,6 +176,10 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
int gpuId,
double detectorDBThreshold, double detectorDBBoxThreshold, double detectorDBUnclipRatio,
double classifierThreshold, int useDilation, int limitSideLen) {
ANS_DBG("ANSOCR","CreateEx called: HandlePtr=%p, *Handle(in)=%p, language=%d, engineMode=%d, gpuId=%d, limitSideLen=%d, modelPath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), language, engineMode, gpuId, limitSideLen,
modelFilePath ? modelFilePath : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSOCR","CreateEx FAIL: Handle is null"); return 0; }
try {
// Ensure all shared DLLs (OpenCV, OpenVINO, TRT, ORT) are pre-loaded
ANSCENTER::ANSLibsLoader::Initialize();
@@ -190,6 +217,7 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
if (isLegacyModel) {
(*Handle) = new ANSCENTER::ANSCPUOCR();
ANS_DBG("ANSOCR","CreateEx: legacy model detected, allocated ANSCPUOCR=%p", (void*)*Handle);
}
else {
// ANSRTOCR wraps PaddleOCRV5RTEngine which is strictly NVIDIA/CUDA:
@@ -224,8 +252,10 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
break;
}
}
if (*Handle == nullptr) return 0;
if (*Handle == nullptr) { ANS_DBG("ANSOCR","CreateEx FAIL: new returned null"); return 0; }
else {
ANS_DBG("ANSOCR","CreateEx: allocated handle=%p (uint=%llu), calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
RegisterOCRHandle(*Handle);
ANSCENTER::OCRModelConfig modelConfig;
switch (language) {
@@ -287,6 +317,7 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
modelConfig.limitSideLen = limitSideLen;
int result = (*Handle)->Initialize(licenseKey, modelConfig, modelFilePath, modelFileZipPassword, engineMode);
if (!result) {
ANS_DBG("ANSOCR","CreateEx FAIL: Initialize returned false, tearing down handle=%p", (void*)*Handle);
// Initialize failed — tear down the engine we just registered so
// the caller, who sees a 0 return and (typically) does not call
// ReleaseANSOCRHandle, does not leak the engine + registry entry.
@@ -297,10 +328,12 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
*Handle = nullptr;
return 0;
}
ANS_DBG("ANSOCR","CreateEx OK: handle=%p (uint=%llu)", (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return result;
}
}
catch (std::exception& e) {
ANS_DBG("ANSOCR","CreateEx EXCEPTION (std::exception): %s", e.what());
// Partially-constructed engine may already be registered — unwind it
// so the leak does not accumulate across repeated failed Create calls.
if (Handle && *Handle) {
@@ -313,6 +346,7 @@ extern "C" ANSOCR_API int CreateANSOCRHandleEx(ANSCENTER::ANSOCRBase** Handle,
return 0;
}
catch (...) {
ANS_DBG("ANSOCR","CreateEx EXCEPTION (unknown)");
if (Handle && *Handle) {
if (UnregisterOCRHandle(*Handle)) {
try { (*Handle)->Destroy(); } catch (...) {}
@@ -332,6 +366,8 @@ extern "C" ANSOCR_API int CreateANSOCRHandle(ANSCENTER::ANSOCRBase** Handle, co
int gpuId,
double detectorDBThreshold, double detectorDBBoxThreshold, double detectorDBUnclipRatio,
double classifierThreshold, int useDilation) {
ANS_DBG("ANSOCR","CreateANSOCRHandle: HandlePtr=%p, language=%d, engineMode=%d, gpuId=%d (delegating to CreateEx, limitSideLen=960)",
(void*)Handle, language, engineMode, gpuId);
return CreateANSOCRHandleEx(Handle, licenseKey, modelFilePath, modelFileZipPassword,
language, engineMode, gpuId,
detectorDBThreshold, detectorDBBoxThreshold, detectorDBUnclipRatio,
@@ -352,6 +388,8 @@ static std::string SerializeOCRResults(ANSCENTER::ANSOCRBase* engine,
}
extern "C" ANSOCR_API std::string RunInference(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength) {
ANS_DBG("ANSOCR","RunInference: HandlePtr=%p, *Handle=%p, bufferLength=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength);
if (!Handle || !*Handle) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -369,6 +407,8 @@ extern "C" ANSOCR_API std::string RunInference(ANSCENTER::ANSOCRBase** Handle,
}
extern "C" ANSOCR_API std::string RunInferenceWithCamID(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId) {
ANS_DBG("ANSOCR","RunInferenceWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%d, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -386,6 +426,8 @@ extern "C" ANSOCR_API std::string RunInferenceWithCamID(ANSCENTER::ANSOCRBase**
}
extern "C" ANSOCR_API int RunInferenceCV(ANSCENTER::ANSOCRBase** Handle, const cv::Mat& image, std::string& ocrResult) {
ANS_DBG("ANSOCR","RunInferenceCV: HandlePtr=%p, *Handle=%p, image=%dx%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), image.cols, image.rows);
if (!Handle || !*Handle) return -1;
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return -3;
@@ -400,6 +442,8 @@ extern "C" ANSOCR_API int RunInferenceCV(ANSCENTER::ANSOCRBase** Handle, const c
}
extern "C" ANSOCR_API std::string RunInferenceBinary(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSOCR","RunInferenceBinary: HandlePtr=%p, *Handle=%p, %ux%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
if (!Handle || !*Handle || !jpeg_bytes || width == 0 || height == 0) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -417,17 +461,26 @@ extern "C" ANSOCR_API std::string RunInferenceBinary(ANSCENTER::ANSOCRBase** Ha
}
static int ReleaseANSOCRHandle_Impl(ANSCENTER::ANSOCRBase** Handle) {
try {
if (!Handle || !*Handle) return 0;
if (!UnregisterOCRHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSOCR","Release: HandlePtr or *Handle is null, no-op");
return 0;
}
ANSCENTER::ANSOCRBase* h = *Handle;
ANS_DBG("ANSOCR","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterOCRHandle(h)) {
ANS_DBG("ANSOCR","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 0; // Not in registry — already freed
}
(*Handle)->Destroy();
delete *Handle;
*Handle = nullptr;
ANS_DBG("ANSOCR","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, OCRHandleRegistry().size());
return 0;
}
catch (...) {
ANS_DBG("ANSOCR","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 1;
}
@@ -438,6 +491,7 @@ extern "C" ANSOCR_API int ReleaseANSOCRHandle(ANSCENTER::ANSOCRBase** Handle) {
return ReleaseANSOCRHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSOCR","ReleaseANSOCRHandle: SEH exception caught");
return 1;
}
}
@@ -445,18 +499,24 @@ extern "C" ANSOCR_API int ReleaseANSOCRHandle(ANSCENTER::ANSOCRBase** Handle) {
// ── ALPR Configuration API ──────────────────────────────────────────
extern "C" ANSOCR_API int SetANSOCRMode(ANSCENTER::ANSOCRBase** Handle, int ocrMode) {
ANS_DBG("ANSOCR","SetANSOCRMode: HandlePtr=%p, *Handle=%p, ocrMode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), ocrMode);
if (!Handle || !*Handle) return -1;
(*Handle)->SetOCRMode(static_cast<ANSCENTER::OCRMode>(ocrMode));
return 0;
}
extern "C" ANSOCR_API int SetANSOCRCountry(ANSCENTER::ANSOCRBase** Handle, int country) {
ANS_DBG("ANSOCR","SetANSOCRCountry: HandlePtr=%p, *Handle=%p, country=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), country);
if (!Handle || !*Handle) return -1;
(*Handle)->SetCountry(static_cast<ANSCENTER::Country>(country));
return 0;
}
extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, const char* formatJson) {
ANS_DBG("ANSOCR","SetANSOCRALPRFormat: HandlePtr=%p, *Handle=%p, formatJson=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), formatJson ? "(set)" : "(null)");
if (!Handle || !*Handle || !formatJson) return -1;
try {
nlohmann::json j = nlohmann::json::parse(formatJson);
@@ -504,6 +564,8 @@ extern "C" ANSOCR_API int SetANSOCRALPRFormat(ANSCENTER::ANSOCRBase** Handle, co
// - Raw UTF-8 encoded strings
// Pure ASCII input is passed through directly (no conversion overhead).
extern "C" ANSOCR_API int ANSOCR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM) {
ANS_DBG("ANSOCR","ANSOCR_ConvertUTF8ToUTF16LE: utf8Str=%s, includeBOM=%d",
utf8Str ? "(set)" : "(null)", includeBOM);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -565,6 +627,8 @@ extern "C" ANSOCR_API int ANSOCR_ConvertUTF8ToUTF16LE(const char* utf8Str, LStrH
}
extern "C" ANSOCR_API int ANSOCR_ConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSOCR","ANSOCR_ConvertUTF16LEToUTF8: utf16leBytes=%s, byteLen=%d",
utf16leBytes ? "(set)" : "(null)", byteLen);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
// Check if input is already pure ASCII (no high bytes, or not valid UTF-16LE)
@@ -609,6 +673,8 @@ extern "C" ANSOCR_API int ANSOCR_ConvertUTF16LEToUTF8(const unsigned char* utf16
}
extern "C" ANSOCR_API std::string RunInferenceImagePath(ANSCENTER::ANSOCRBase** Handle, const char* imageFilePath) {
ANS_DBG("ANSOCR","RunInferenceImagePath: HandlePtr=%p, *Handle=%p, imageFilePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageFilePath ? imageFilePath : "(null)");
if (!Handle || !*Handle) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -628,6 +694,8 @@ extern "C" ANSOCR_API std::string RunInferenceImagePath(ANSCENTER::ANSOCRBase**
extern "C" ANSOCR_API std::string RunInferenceInCroppedImages(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImages: HandlePtr=%p, *Handle=%p, bufferLength=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, strBboxes ? "(set)" : "(null)");
if (!Handle || !*Handle) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -645,6 +713,9 @@ extern "C" ANSOCR_API std::string RunInferenceInCroppedImages(ANSCENTER::ANSOCR
catch (...) { return ""; }
}
extern "C" ANSOCR_API std::string RunInferenceInCroppedImagesWithCamID(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes, const char* cameraId) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImagesWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%d, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength,
strBboxes ? "(set)" : "(null)", cameraId ? cameraId : "(null)");
if (!Handle || !*Handle) return "";
OCRHandleGuard guard(AcquireOCRHandle(*Handle));
if (!guard) return "";
@@ -663,6 +734,8 @@ extern "C" ANSOCR_API std::string RunInferenceInCroppedImagesWithCamID(ANSCENTE
}
//// For LabVIEW API
extern "C" ANSOCR_API int RunInference_LV(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInference_LV: HandlePtr=%p, *Handle=%p, bufferLength=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength);
try {
std::string st = RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -686,6 +759,8 @@ extern "C" ANSOCR_API int RunInference_LV(ANSCENTER::ANSOCRBase** Handl
}
extern "C" ANSOCR_API int RunInference_LVWithCamID(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInference_LVWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%d, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
if (st.empty()) return 0;
@@ -708,6 +783,8 @@ extern "C" ANSOCR_API int RunInference_LVWithCamID(ANSCENTER::ANSOCRBas
}
}
extern "C" ANSOCR_API int RunInferenceBinary_LV(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceBinary_LV: HandlePtr=%p, *Handle=%p, %ux%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
std::string st = RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -730,6 +807,8 @@ extern "C" ANSOCR_API int RunInferenceBinary_LV(ANSCENTER::ANSOCRBase**
}
}
extern "C" ANSOCR_API int RunInferenceImagePath_LV(ANSCENTER::ANSOCRBase** Handle, const char* imageFilePath, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceImagePath_LV: HandlePtr=%p, *Handle=%p, imageFilePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageFilePath ? imageFilePath : "(null)");
try {
std::string st = RunInferenceImagePath(Handle, imageFilePath);
if (st.empty()) return 0;
@@ -753,6 +832,8 @@ extern "C" ANSOCR_API int RunInferenceImagePath_LV(ANSCENTER::ANSOCRBase** H
}
extern "C" ANSOCR_API int ANSOCRUnitTest(const char* modelFilePath, const char* imageFilePath, LStrHandle detectionResult)
{
ANS_DBG("ANSOCR","ANSOCRUnitTest: modelFilePath=%s, imageFilePath=%s",
modelFilePath ? modelFilePath : "(null)", imageFilePath ? imageFilePath : "(null)");
try {
ANSCENTER::ANSOCRBase* infHandle;
std::string licenseKey = "";
@@ -782,6 +863,8 @@ extern "C" ANSOCR_API int ANSOCRUnitTest(const char* modelFilePath, const ch
}
extern "C" ANSOCR_API int RunInferenceInCroppedImages_LV(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImages_LV: HandlePtr=%p, *Handle=%p, bufferLength=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, strBboxes ? "(set)" : "(null)");
try {
std::string st = RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
if (st.empty()) return 0;
@@ -804,6 +887,9 @@ extern "C" ANSOCR_API int RunInferenceInCroppedImages_LV(ANSCENTER::ANS
}
}
extern "C" ANSOCR_API int RunInferenceInCroppedImages_LVWithCamID(ANSCENTER::ANSOCRBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImages_LVWithCamID: HandlePtr=%p, *Handle=%p, bufferLength=%d, strBboxes=%s, cameraId=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength,
strBboxes ? "(set)" : "(null)", cameraId ? cameraId : "(null)");
try {
std::string st = RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
if (st.empty()) return 0;
@@ -835,6 +921,8 @@ extern "C" ANSOCR_API int RunInferenceComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSOCR","RunInferenceComplete_LV: HandlePtr=%p, *Handle=%p, cameraId=%s, getJpegString=%d, jpegImageSize=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -926,6 +1014,8 @@ extern "C" ANSOCR_API int RunInferenceComplete_LV(
catch (...) { return 0; }
}
extern "C" ANSOCR_API int RunInferencesComplete_LV(ANSCENTER::ANSOCRBase** Handle, cv::Mat** cvImage, const char* cameraId, int maxImageSize, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferencesComplete_LV: HandlePtr=%p, *Handle=%p, cameraId=%s, maxImageSize=%d, strBboxes=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? "(set)" : "(null)");
if (!Handle || !*Handle) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1009,6 +1099,8 @@ extern "C" ANSOCR_API int RunInferencesComplete_LV(ANSCENTER::ANSOCRBase** Handl
ANSCENTER::ANSOCRBase** Handle = &_v2Arr[0];
extern "C" ANSOCR_API int RunInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInference_LV_V2: handleVal=%llu (handle=%p), bufferLength=%d",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, (int)bufferLength);
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInference(Handle, jpeg_string, bufferLength);
@@ -1026,6 +1118,8 @@ extern "C" ANSOCR_API int RunInference_LV_V2(uint64_t handleVal, unsigned char*
}
extern "C" ANSOCR_API int RunInference_LVWithCamID_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInference_LVWithCamID_V2: handleVal=%llu (handle=%p), bufferLength=%d, cameraId=%s",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, (int)bufferLength, cameraId ? cameraId : "(null)");
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceWithCamID(Handle, jpeg_string, bufferLength, cameraId);
@@ -1043,6 +1137,8 @@ extern "C" ANSOCR_API int RunInference_LVWithCamID_V2(uint64_t handleVal, unsign
}
extern "C" ANSOCR_API int RunInferenceBinary_LV_V2(uint64_t handleVal, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceBinary_LV_V2: handleVal=%llu (handle=%p), %ux%u",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, width, height);
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceBinary(Handle, jpeg_bytes, width, height);
@@ -1060,6 +1156,8 @@ extern "C" ANSOCR_API int RunInferenceBinary_LV_V2(uint64_t handleVal, unsigned
}
extern "C" ANSOCR_API int RunInferenceImagePath_LV_V2(uint64_t handleVal, const char* imageFilePath, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceImagePath_LV_V2: handleVal=%llu (handle=%p), imageFilePath=%s",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, imageFilePath ? imageFilePath : "(null)");
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceImagePath(Handle, imageFilePath);
@@ -1077,6 +1175,8 @@ extern "C" ANSOCR_API int RunInferenceImagePath_LV_V2(uint64_t handleVal, const
}
extern "C" ANSOCR_API int RunInferenceInCroppedImages_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImages_LV_V2: handleVal=%llu (handle=%p), bufferLength=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, (int)bufferLength, strBboxes ? "(set)" : "(null)");
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceInCroppedImages(Handle, jpeg_string, bufferLength, strBboxes);
@@ -1094,6 +1194,9 @@ extern "C" ANSOCR_API int RunInferenceInCroppedImages_LV_V2(uint64_t handleVal,
}
extern "C" ANSOCR_API int RunInferenceInCroppedImages_LVWithCamID_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, const char* strBboxes, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferenceInCroppedImages_LVWithCamID_V2: handleVal=%llu (handle=%p), bufferLength=%d, strBboxes=%s, cameraId=%s",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, (int)bufferLength,
strBboxes ? "(set)" : "(null)", cameraId ? cameraId : "(null)");
try {
OCR_V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceInCroppedImagesWithCamID(Handle, jpeg_string, bufferLength, strBboxes, cameraId);
@@ -1119,6 +1222,8 @@ extern "C" ANSOCR_API int RunInferenceComplete_LV_V2(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSOCR","RunInferenceComplete_LV_V2: handleVal=%llu (handle=%p), cameraId=%s, getJpegString=%d, jpegImageSize=%d",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, cameraId ? cameraId : "(null)", getJpegString, jpegImageSize);
ANSCENTER::ANSOCRBase* directHandle = reinterpret_cast<ANSCENTER::ANSOCRBase*>(handleVal);
if (directHandle == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1212,6 +1317,8 @@ extern "C" ANSOCR_API int RunInferenceComplete_LV_V2(
}
extern "C" ANSOCR_API int RunInferencesComplete_LV_V2(uint64_t handleVal, cv::Mat** cvImage, const char* cameraId, int maxImageSize, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOCR","RunInferencesComplete_LV_V2: handleVal=%llu (handle=%p), cameraId=%s, maxImageSize=%d, strBboxes=%s",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal, cameraId ? cameraId : "(null)", maxImageSize, strBboxes ? "(set)" : "(null)");
ANSCENTER::ANSOCRBase* directHandle = reinterpret_cast<ANSCENTER::ANSOCRBase*>(handleVal);
if (directHandle == nullptr) return -1;
if (!cvImage || !(*cvImage) || (*cvImage)->empty()) return -2;
@@ -1290,6 +1397,8 @@ extern "C" ANSOCR_API uint64_t CreateANSOCRHandleEx_V2(const char* licenseKey,
int gpuId,
double detectorDBThreshold, double detectorDBBoxThreshold, double detectorDBUnclipRatio,
double classifierThreshold, int useDilation, int limitSideLen) {
ANS_DBG("ANSOCR","CreateANSOCRHandleEx_V2: language=%d, engineMode=%d, gpuId=%d, limitSideLen=%d, modelPath=%s",
language, engineMode, gpuId, limitSideLen, modelFilePath ? modelFilePath : "(null)");
try {
ANSCENTER::ANSOCRBase* handle = nullptr;
int result = CreateANSOCRHandleEx(&handle, licenseKey, modelFilePath, modelFileZipPassword,
@@ -1308,6 +1417,8 @@ extern "C" ANSOCR_API uint64_t CreateANSOCRHandle_V2(const char* licenseKey,
int gpuId,
double detectorDBThreshold, double detectorDBBoxThreshold, double detectorDBUnclipRatio,
double classifierThreshold, int useDilation) {
ANS_DBG("ANSOCR","CreateANSOCRHandle_V2: language=%d, engineMode=%d, gpuId=%d (delegating to CreateEx_V2, limitSideLen=960)",
language, engineMode, gpuId);
return CreateANSOCRHandleEx_V2(licenseKey, modelFilePath, modelFileZipPassword,
language, engineMode, gpuId,
detectorDBThreshold, detectorDBBoxThreshold, detectorDBUnclipRatio,
@@ -1315,17 +1426,26 @@ extern "C" ANSOCR_API uint64_t CreateANSOCRHandle_V2(const char* licenseKey,
}
extern "C" ANSOCR_API int ReleaseANSOCRHandle_V2(uint64_t handleVal) {
ANS_DBG("ANSOCR","ReleaseANSOCRHandle_V2: handleVal=%llu (handle=%p)",
(unsigned long long)handleVal, (void*)(uintptr_t)handleVal);
try {
ANSCENTER::ANSOCRBase* directHandle = reinterpret_cast<ANSCENTER::ANSOCRBase*>(handleVal);
if (directHandle == nullptr) return 0;
if (directHandle == nullptr) {
ANS_DBG("ANSOCR","Release_V2: handleVal is 0/null, no-op");
return 0;
}
if (!UnregisterOCRHandle(directHandle)) {
ANS_DBG("ANSOCR","Release_V2: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)directHandle);
return 0; // Not in registry — already freed
}
directHandle->Destroy();
delete directHandle;
ANS_DBG("ANSOCR","Release_V2 OK: handle=%p deleted, registry now has %zu entries",
(void*)directHandle, OCRHandleRegistry().size());
return 0;
}
catch (...) {
ANS_DBG("ANSOCR","Release_V2 EXCEPTION (unknown)");
return 1;
}
}

View File

@@ -62,6 +62,8 @@ extern "C" ANSODENGINE_API GpuFrameData** ANSODEngine_GetTlsGpuFrame() {
#include <unordered_set>
#include <mutex>
// DebugView: filter on "[ANSOD]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSODHandle is called while inference is still running.
// refcount: starts at 1 on Register. AcquireODHandle increments,
@@ -213,6 +215,8 @@ static std::condition_variable& ODHandleRegistryCV() {
static void RegisterODHandle(ANSCENTER::ANSODBase* h) {
std::lock_guard<std::mutex> lk(ODHandleRegistryMutex());
ODHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSOD","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ODHandleRegistry().size());
}
// Acquire a handle for use (increment refcount). Returns the handle
@@ -220,9 +224,23 @@ static void RegisterODHandle(ANSCENTER::ANSODBase* h) {
static ANSCENTER::ANSODBase* AcquireODHandle(ANSCENTER::ANSODBase* h) {
std::lock_guard<std::mutex> lk(ODHandleRegistryMutex());
auto it = ODHandleRegistry().find(h);
if (it == ODHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == ODHandleRegistry().end()) {
ANS_DBG("ANSOD","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, ODHandleRegistry().size());
size_t i = 0;
for (auto& kv : ODHandleRegistry()) {
ANS_DBG("ANSOD"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSOD","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSOD","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -244,10 +262,15 @@ static bool ReleaseODHandleRef(ANSCENTER::ANSODBase* h) {
static bool UnregisterODHandle(ANSCENTER::ANSODBase* h) {
std::unique_lock<std::mutex> lk(ODHandleRegistryMutex());
auto it = ODHandleRegistry().find(h);
if (it == ODHandleRegistry().end()) return false;
if (it == ODHandleRegistry().end()) {
ANS_DBG("ANSOD","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSOD","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSOD","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--; // Remove creation ref
// Wait for in-flight inferences to finish (30s timeout as safety net)
@@ -256,6 +279,7 @@ static bool UnregisterODHandle(ANSCENTER::ANSODBase* h) {
return it2 == ODHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSOD","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterODHandle timed out waiting for in-flight inference\n");
}
ODHandleRegistry().erase(h);
@@ -361,7 +385,11 @@ extern "C" ANSODENGINE_API std::string CreateANSODHandle(ANSCENTER::ANSODBase**
int detectionType,
int loadEngineOnCreation)
{
if (Handle == nullptr) return "";
ANS_DBG("ANSOD","CreateANSODHandle: HandlePtr=%p, *Handle(in)=%p, modelType=%d, detectionType=%d, autoDetectEngine=%d, loadOnCreate=%d, modelPath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
modelType, detectionType, autoDetectEngine, loadEngineOnCreation,
modelFilePath ? modelFilePath : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSOD","CreateANSODHandle FAIL: Handle is null"); return ""; }
// NOTE: We intentionally do NOT destroy any existing *Handle here.
// LabVIEW reuses DLL parameter buffer addresses, so *Handle may point
@@ -667,9 +695,12 @@ extern "C" ANSODENGINE_API std::string CreateANSODHandle(ANSCENTER::ANSODBase**
break;
}
if (*Handle == nullptr) {
ANS_DBG("ANSOD","CreateANSODHandle FAIL: allocation produced null handle (modelType=%d)", modelType);
return labelMap;
}
else {
ANS_DBG("ANSOD","CreateANSODHandle: allocated handle=%p (uint=%llu) modelType=%d, calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, (int)modelConfig.modelType);
// CUDA round-robin + VRAM check — only relevant for NVIDIA GPUs.
// On AMD/DirectML and OpenVINO these calls hit stub CUDA APIs that
// return bogus 0-byte VRAM and pollute the log with false warnings.
@@ -683,6 +714,8 @@ extern "C" ANSODENGINE_API std::string CreateANSODHandle(ANSCENTER::ANSODBase**
RegisterODHandle(*Handle);
(*Handle)->SetLoadEngineOnCreation(_loadEngineOnCreation); //Set force to load the engine immediately
bool loadResult = (*Handle)->Initialize(licenseKey, modelConfig, modelFilePath, modelFileZipPassword, labelMap);
ANS_DBG("ANSOD","CreateANSODHandle OK: handle=%p initResult=%d labelMapLen=%zu",
(void*)*Handle, loadResult ? 1 : 0, labelMap.size());
return labelMap;
}
}
@@ -699,7 +732,11 @@ extern "C" ANSODENGINE_API int CreateANSODHandleEx(ANSCENTER::ANSODBase** Handl
std::string& labelMap,
int loadEngineOnCreation)
{
if (Handle == nullptr) return -1; // invalid modelType return
ANS_DBG("ANSOD","CreateANSODHandleEx: HandlePtr=%p, *Handle(in)=%p, modelType=%d, detectionType=%d, autoDetectEngine=%d, loadOnCreate=%d, modelPath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
modelType, detectionType, autoDetectEngine, loadEngineOnCreation,
modelFilePath ? modelFilePath : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSOD","CreateANSODHandleEx FAIL: Handle is null"); return -1; } // invalid modelType return
bool _loadEngineOnCreation = false;
if (loadEngineOnCreation == 1) {
@@ -1003,10 +1040,13 @@ extern "C" ANSODENGINE_API int CreateANSODHandleEx(ANSCENTER::ANSODBase** Handl
returnModelType = static_cast<int>(modelConfig.modelType);
if (*Handle == nullptr) {
ANS_DBG("ANSOD","CreateANSODHandleEx FAIL: allocation produced null handle (modelType=%d)", modelType);
labelMap ="";
return returnModelType;
}
else {
ANS_DBG("ANSOD","CreateANSODHandleEx: allocated handle=%p (uint=%llu) modelType=%d, calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, (int)modelConfig.modelType);
// CUDA round-robin + VRAM check — only relevant for NVIDIA GPUs.
// On AMD/DirectML and OpenVINO these calls hit stub CUDA APIs that
// return bogus 0-byte VRAM and pollute the log with false warnings.
@@ -1020,12 +1060,18 @@ extern "C" ANSODENGINE_API int CreateANSODHandleEx(ANSCENTER::ANSODBase** Handl
RegisterODHandle(*Handle);
(*Handle)->SetLoadEngineOnCreation(_loadEngineOnCreation); //Set force to load the engine immediately
bool loadResult = (*Handle)->Initialize(licenseKey, modelConfig, modelFilePath, modelFileZipPassword, labelMap);
ANS_DBG("ANSOD","CreateANSODHandleEx OK: handle=%p initResult=%d returnModelType=%d labelMapLen=%zu",
(void*)*Handle, loadResult ? 1 : 0, returnModelType, labelMap.size());
return returnModelType;
}
}
//// For LabVIEW API
extern "C" ANSODENGINE_API int CreateANSODHandle_LV(ANSCENTER::ANSODBase** Handle, const char* licenseKey, const char* modelFilePath, const char* modelFileZipPassword, float modelThreshold, float modelConfThreshold, float modelNMSThreshold, int autoDetectEngine, int modelType, int detectorType, int loadEngineOnCreation, LStrHandle labelMap) {
ANS_DBG("ANSOD","CreateANSODHandle_LV: HandlePtr=%p, *Handle(in)=%p, modelType=%d, detectorType=%d, autoDetectEngine=%d, loadOnCreate=%d, modelPath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
modelType, detectorType, autoDetectEngine, loadEngineOnCreation,
modelFilePath ? modelFilePath : "(null)");
try {
std::string lbMap;
@@ -1071,9 +1117,13 @@ extern "C" __declspec(dllexport) int LoadModelFromFolder(ANSCENTER::ANSODBase**
const char* modelFolder,
std::string& labelMap)
{
ANS_DBG("ANSOD","LoadModelFromFolder: HandlePtr=%p, *Handle(in)=%p, modelType=%d, detectionType=%d, autoDetectEngine=%d, modelFolder=%s, modelName=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
modelType, detectionType, autoDetectEngine,
modelFolder ? modelFolder : "(null)", modelName ? modelName : "(null)");
try
{
if (Handle == nullptr) return 0;
if (Handle == nullptr) { ANS_DBG("ANSOD","LoadModelFromFolder FAIL: Handle is null"); return 0; }
labelMap.clear();
ANSCENTER::ModelConfig modelConfig;
bool _loadEngineOnCreation = false;
@@ -1366,9 +1416,12 @@ extern "C" __declspec(dllexport) int LoadModelFromFolder(ANSCENTER::ANSODBase**
break;
}
if (*Handle == nullptr) {
ANS_DBG("ANSOD","LoadModelFromFolder FAIL: allocation produced null handle (modelType=%d)", modelType);
return -1;
}
else {
ANS_DBG("ANSOD","LoadModelFromFolder: allocated handle=%p (uint=%llu) modelType=%d, calling LoadModelFromFolder...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle, (int)modelConfig.modelType);
// CUDA round-robin + VRAM check — NVIDIA only (see CreateANSODHandle).
if (engineType == ANSCENTER::EngineType::NVIDIA_GPU) {
const int assignedGPU = AssignNextGPU();
@@ -1380,16 +1433,25 @@ extern "C" __declspec(dllexport) int LoadModelFromFolder(ANSCENTER::ANSODBase**
RegisterODHandle(*Handle);
(*Handle)->SetLoadEngineOnCreation(_loadEngineOnCreation); //Set force to load the engine immediately
bool result = (*Handle)->LoadModelFromFolder(licenseKey, modelConfig, modelName, className, modelFolder, labelMap);
ANS_DBG("ANSOD","LoadModelFromFolder OK: handle=%p loadResult=%d labelMapLen=%zu",
(void*)*Handle, result ? 1 : 0, labelMap.size());
if (result) return 1;
else return 0;
}
}
catch (const std::exception& e) {
ANS_DBG("ANSOD","LoadModelFromFolder EXCEPTION (std::exception): %s", e.what());
return 0;
}
catch (...) {
ANS_DBG("ANSOD","LoadModelFromFolder EXCEPTION (unknown)");
return 0;
}
}
ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* modelFileZipPassword, int modelType, int modelDetectionType, int fp16, std::string& modelFolder) {
ANS_DBG("ANSOD","OptimizeModelStr: modelType=%d, modelDetectionType=%d, fp16=%d, modelPath=%s",
modelType, modelDetectionType, fp16, modelFilePath ? modelFilePath : "(null)");
try {
bool optimizedResult = false;
// NOTE: odMutex was removed here. OptimizeModelStr creates its own
@@ -1578,22 +1640,35 @@ ANSODENGINE_API int OptimizeModelStr(const char* modelFilePath, const char* mode
}
static int ReleaseANSODHandle_Impl(ANSCENTER::ANSODBase** Handle) {
try {
if (Handle == nullptr) return 0;
if (*Handle == nullptr) return 0;
if (Handle == nullptr) {
ANS_DBG("ANSOD","ReleaseANSODHandle: HandlePtr is null, no-op");
return 0;
}
if (*Handle == nullptr) {
ANS_DBG("ANSOD","ReleaseANSODHandle: *Handle is null, no-op");
return 0;
}
ANSCENTER::ANSODBase* h = *Handle;
ANS_DBG("ANSOD","ReleaseANSODHandle called: handle=%p (uint=%llu)",
(void*)h, (unsigned long long)(uintptr_t)h);
// Only release if this handle was registered by us
if (!UnregisterODHandle(*Handle)) {
if (!UnregisterODHandle(h)) {
// Not in registry — already freed or not ours
ANS_DBG("ANSOD","ReleaseANSODHandle: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 0;
}
(*Handle)->Destroy();
delete *Handle;
h->Destroy();
delete h;
*Handle = nullptr;
ANS_DBG("ANSOD","ReleaseANSODHandle OK: handle=%p deleted, registry now has %zu entries",
(void*)h, ODHandleRegistry().size());
return 0;
}
catch (...) {
*Handle = nullptr;
ANS_DBG("ANSOD","ReleaseANSODHandle EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 1;
}
}
@@ -1603,10 +1678,14 @@ extern "C" ANSODENGINE_API int ReleaseANSODHandle(ANSCENTER::ANSODBase** Handle)
return ReleaseANSODHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSOD","ReleaseANSODHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 1;
}
}
ANSODENGINE_API std::string RunInference(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSOD","RunInference: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
if (Handle == nullptr || *Handle == nullptr) return "";
if (jpeg_string == nullptr || bufferLength == 0) return "";
@@ -1629,6 +1708,9 @@ ANSODENGINE_API std::string RunInference(ANSCENTER::ANSODBase** Handle, unsigned
}
ANSODENGINE_API std::string RunTiledInference(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, int tiledWidth, int titledHeight, double overlap, const char* cameraId) {
ANS_DBG("ANSOD","RunTiledInference: HandlePtr=%p, *Handle=%p, bufferLength=%u, tile=%dx%d, overlap=%.3f, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, tiledWidth, titledHeight, overlap,
cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
if (jpeg_string == nullptr || bufferLength == 0) return "";
@@ -1650,6 +1732,8 @@ ANSODENGINE_API std::string RunTiledInference(ANSCENTER::ANSODBase** Handle, uns
}
ANSODENGINE_API std::string RunInferenceFromJpegString(ANSCENTER::ANSODBase** Handle, const char* jpeg_string, unsigned long jpeg_size, const char* cameraId) {
ANS_DBG("ANSOD","RunInferenceFromJpegString: HandlePtr=%p, *Handle=%p, jpeg_size=%lu, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), jpeg_size, cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
std::vector<ANSCENTER::Object> outputs = (*Handle)->RunInferenceFromJpegString(jpeg_string, jpeg_size, cameraId);
@@ -1663,6 +1747,9 @@ ANSODENGINE_API std::string RunInferenceFromJpegString(ANSCENTER::ANSODBase** Ha
}
}
ANSODENGINE_API std::string RunTiledInferenceFromJpegString(ANSCENTER::ANSODBase** Handle, const char* jpeg_string, unsigned long jpeg_size, int tiledWidth, int titledHeight, double overlap, const char* cameraId) {
ANS_DBG("ANSOD","RunTiledInferenceFromJpegString: HandlePtr=%p, *Handle=%p, jpeg_size=%lu, tile=%dx%d, overlap=%.3f, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), jpeg_size, tiledWidth, titledHeight, overlap,
cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
std::vector<ANSCENTER::Object> outputs = (*Handle)->RunTiledInferenceFromJpegString(jpeg_string, jpeg_size, tiledWidth, titledHeight, overlap, cameraId);
@@ -1678,6 +1765,8 @@ ANSODENGINE_API std::string RunTiledInferenceFromJpegString(ANSCENTER::ANSODBase
}
ANSODENGINE_API std::string RunInferenceFromCV(ANSCENTER::ANSODBase** Handle, cv::Mat image)
{
ANS_DBG("ANSOD","RunInferenceFromCV: HandlePtr=%p, *Handle=%p, image=%dx%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), image.cols, image.rows);
try {
if (Handle == nullptr || *Handle == nullptr) return "";
std::string detectionResult;
@@ -1691,6 +1780,9 @@ ANSODENGINE_API std::string RunInferenceFromCV(ANSCENTER::ANSODBase** Handle, cv
}
}
extern "C" ANSODENGINE_API void RunDetectMovement(ANSCENTER::ANSODBase** Handle, cv::Mat image, const char* cameraId, std::vector<ANSCENTER::Object>& results) {
ANS_DBG("ANSOD","RunDetectMovement: HandlePtr=%p, *Handle=%p, image=%dx%d, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), image.cols, image.rows,
cameraId ? cameraId : "(null)");
try{
if (Handle == nullptr || *Handle == nullptr) { results.clear(); return; }
results = (*Handle)->DetectMovement(image, cameraId);
@@ -1700,6 +1792,9 @@ extern "C" ANSODENGINE_API void RunDetectMovement(ANSCENTER::ANSODBase** Handl
}
}
extern "C" ANSODENGINE_API void RunTiledInferenceFromCV(ANSCENTER::ANSODBase** Handle, cv::Mat image, int tiledWidth, int titledHeight, double overlap, std::vector<ANSCENTER::Object>& results, const char* cameraId) {
ANS_DBG("ANSOD","RunTiledInferenceFromCV: HandlePtr=%p, *Handle=%p, image=%dx%d, tile=%dx%d, overlap=%.3f, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), image.cols, image.rows,
tiledWidth, titledHeight, overlap, cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) { results.clear(); return; }
results = (*Handle)->RunInferences(image, tiledWidth, titledHeight, overlap, cameraId);
@@ -1709,6 +1804,8 @@ extern "C" ANSODENGINE_API void RunTiledInferenceFromCV(ANSCENTER::ANSODBase** H
}
}
ANSODENGINE_API std::string RunInferenceInCroppedBBoxImages(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, const char* strBboxes) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxImages: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
if (jpeg_string == nullptr || bufferLength == 0) return "";
@@ -1731,6 +1828,8 @@ ANSODENGINE_API std::string RunInferenceInCroppedBBoxImages(ANSCENTER::ANSODBase
}
ANSODENGINE_API std::string RunInferenceInCroppedPolygonImages(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, const char* strPolygon) {
ANS_DBG("ANSOD","RunInferenceInCroppedPolygonImages: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
if (jpeg_string == nullptr || bufferLength == 0) return "";
@@ -1752,6 +1851,8 @@ ANSODENGINE_API std::string RunInferenceInCroppedPolygonImages(ANSCENTER::ANSODB
}
}
ANSODENGINE_API std::string RunInferenceBinary(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSOD","RunInferenceBinary: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
if (Handle == nullptr || *Handle == nullptr) return "";
if (jpeg_bytes == nullptr || width == 0 || height == 0) return "";
@@ -1774,6 +1875,8 @@ ANSODENGINE_API std::string RunInferenceBinary(ANSCENTER::ANSODBase** Handle, un
}
ANSODENGINE_API std::string RunInferenceImagePath(ANSCENTER::ANSODBase** Handle, const char* imageFilePath) {
ANS_DBG("ANSOD","RunInferenceImagePath: HandlePtr=%p, *Handle=%p, imageFilePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageFilePath ? imageFilePath : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) return "";
std::string stImageFileName(imageFilePath);
@@ -1797,6 +1900,8 @@ ANSODENGINE_API std::string RunInferenceImagePath(ANSCENTER::ANSODBase** Handle,
}
extern "C" ANSODENGINE_API int RunInference_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInference_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
std::string st = RunInference(Handle, jpeg_string, bufferLength);
if (st.empty()) return 0;
@@ -1816,6 +1921,9 @@ extern "C" ANSODENGINE_API int RunInference_LV(ANSCENTER::ANSODBase** Handle,
}
}
extern "C" ANSODENGINE_API int RunTiledInference_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, int tiledWidth, int titledHeight, double overlap, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunTiledInference_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, tile=%dx%d, overlap=%.3f, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, tiledWidth, titledHeight, overlap,
cameraId ? cameraId : "(null)");
try {
std::string st = RunTiledInference(Handle, jpeg_string, bufferLength, tiledWidth, titledHeight, overlap, cameraId);
if (st.empty()) return 0;
@@ -1835,6 +1943,8 @@ extern "C" ANSODENGINE_API int RunTiledInference_LV(ANSCENTER::ANSODBase** Han
}
}
extern "C" ANSODENGINE_API int RunInferenceFromJpegString_LV(ANSCENTER::ANSODBase** Handle, const char* jpeg_string, unsigned long jpeg_size, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceFromJpegString_LV: HandlePtr=%p, *Handle=%p, jpeg_size=%lu, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), jpeg_size, cameraId ? cameraId : "(null)");
try {
std::string st = RunInferenceFromJpegString(Handle, jpeg_string, jpeg_size, cameraId);
if (st.empty()) return 0;
@@ -1855,6 +1965,9 @@ extern "C" ANSODENGINE_API int RunInferenceFromJpegString_LV(ANSCENTER::ANSODB
}
extern "C" ANSODENGINE_API int RunTiledInferenceFromJpegString_LV(ANSCENTER::ANSODBase** Handle, const char* jpeg_string, unsigned long jpeg_size, int tiledWidth, int titledHeight, double overlap, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunTiledInferenceFromJpegString_LV: HandlePtr=%p, *Handle=%p, jpeg_size=%lu, tile=%dx%d, overlap=%.3f, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), jpeg_size, tiledWidth, titledHeight, overlap,
cameraId ? cameraId : "(null)");
try {
std::string st = RunTiledInferenceFromJpegString(Handle, jpeg_string, jpeg_size, tiledWidth, titledHeight, overlap, cameraId);
if (st.empty()) return 0;
@@ -1875,6 +1988,8 @@ extern "C" ANSODENGINE_API int RunTiledInferenceFromJpegString_LV(ANSCENTER::A
}
extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxImages_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxImages_LV: HandlePtr=%p, *Handle=%p, bufferLength=%d, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = RunInferenceInCroppedBBoxImages(Handle, jpeg_string, bufferLength, cameraId, strBboxes);
if (st.empty()) return 0;
@@ -1894,6 +2009,8 @@ extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxImages_LV(ANSCENTER
}
}
extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxPolygonImages_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, const char* strPolygon, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxPolygonImages_LV: HandlePtr=%p, *Handle=%p, bufferLength=%d, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), (int)bufferLength, cameraId ? cameraId : "(null)");
try {
std::string st = RunInferenceInCroppedPolygonImages(Handle, jpeg_string, bufferLength, cameraId, strPolygon);
if (st.empty()) return 0;
@@ -1913,6 +2030,8 @@ extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxPolygonImages_LV(AN
}
}
extern "C" ANSODENGINE_API int RunInferenceBinary_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceBinary_LV: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
std::string st = RunInferenceBinary(Handle, jpeg_bytes, width, height);
if (st.empty()) return 0;
@@ -1933,6 +2052,8 @@ extern "C" ANSODENGINE_API int RunInferenceBinary_LV(ANSCENTER::ANSODBase** Ha
}
extern "C" ANSODENGINE_API int RunInferenceImagePath_LV(ANSCENTER::ANSODBase** Handle, const char* imageFilePath, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceImagePath_LV: HandlePtr=%p, *Handle=%p, imageFilePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageFilePath ? imageFilePath : "(null)");
try {
std::string st = RunInferenceImagePath(Handle, imageFilePath);
if (st.empty()) return 0;
@@ -1954,6 +2075,8 @@ extern "C" ANSODENGINE_API int RunInferenceImagePath_LV(ANSCENTER::ANSODBase**
}
extern "C" ANSODENGINE_API int OptimizeModel(const char* modelFilePath, const char* modelFileZipPassword,int modelType, int modelDetectionType, int fp16, LStrHandle optimizedModelFolder) {
ANS_DBG("ANSOD","OptimizeModel: modelType=%d, modelDetectionType=%d, fp16=%d, modelPath=%s",
modelType, modelDetectionType, fp16, modelFilePath ? modelFilePath : "(null)");
try {
std::string st;
int ret = OptimizeModelStr(modelFilePath, modelFileZipPassword, modelType, modelDetectionType, fp16, st);
@@ -1979,6 +2102,10 @@ extern "C" ANSODENGINE_API int OptimizeModel(const char* modelFilePath, const ch
}
}
extern "C" __declspec(dllexport) const char* CreateANSODHandle_CS(ANSCENTER::ANSODBase** Handle, const char* licenseKey, const char* modelFilePath, const char* modelFileZipPassword, float modelThreshold, float modelConfThreshold, float modelNMSThreshold, int autoDetectEngine, int modelType, int detectionType, int loadEngineOnCreation) {
ANS_DBG("ANSOD","CreateANSODHandle_CS: HandlePtr=%p, *Handle(in)=%p, modelType=%d, detectionType=%d, autoDetectEngine=%d, loadOnCreate=%d, modelPath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
modelType, detectionType, autoDetectEngine, loadEngineOnCreation,
modelFilePath ? modelFilePath : "(null)");
try {
static std::string result;
result = CreateANSODHandle(Handle, licenseKey, modelFilePath, modelFileZipPassword, modelThreshold, modelConfThreshold, modelNMSThreshold, autoDetectEngine, modelType, detectionType, loadEngineOnCreation);
@@ -1990,6 +2117,8 @@ extern "C" __declspec(dllexport) const char* CreateANSODHandle_CS(ANSCENTER::ANS
}
extern "C" __declspec(dllexport) const char* RunInferenceImagePath_CS(ANSCENTER::ANSODBase** Handle, const char* imageFilePath) {
ANS_DBG("ANSOD","RunInferenceImagePath_CS: HandlePtr=%p, *Handle=%p, imageFilePath=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), imageFilePath ? imageFilePath : "(null)");
try {
static std::string result;
result = RunInferenceImagePath(Handle, imageFilePath);
@@ -2001,6 +2130,8 @@ extern "C" __declspec(dllexport) const char* RunInferenceImagePath_CS(ANSCENTER:
}
extern "C" __declspec(dllexport) const char* RunInference_CS(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength) {
ANS_DBG("ANSOD","RunInference_CS: HandlePtr=%p, *Handle=%p, bufferLength=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength);
try {
static std::string result;
result = RunInference(Handle, jpeg_string, bufferLength);
@@ -2012,6 +2143,8 @@ extern "C" __declspec(dllexport) const char* RunInference_CS(ANSCENTER::ANSODBas
}
extern "C" __declspec(dllexport) const char* RunInferenceInCroppedBBoxImages_CS(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, const char* strBboxes) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxImages_CS: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
static std::string result;
result = RunInferenceInCroppedBBoxImages(Handle, jpeg_string, bufferLength, cameraId, strBboxes);
@@ -2023,6 +2156,8 @@ extern "C" __declspec(dllexport) const char* RunInferenceInCroppedBBoxImages_CS(
}
extern "C" __declspec(dllexport) const char* RunInferenceInCroppedPolygonImages_CS(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, const char* strPolygon) {
ANS_DBG("ANSOD","RunInferenceInCroppedPolygonImages_CS: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
static std::string result;
result = RunInferenceInCroppedPolygonImages(Handle, jpeg_string, bufferLength, cameraId, strPolygon);
@@ -2033,6 +2168,8 @@ extern "C" __declspec(dllexport) const char* RunInferenceInCroppedPolygonImages_
}
}
extern "C" __declspec(dllexport) const char* RunInferenceBinary_CS(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_bytes, unsigned int width, unsigned int height) {
ANS_DBG("ANSOD","RunInferenceBinary_CS: HandlePtr=%p, *Handle=%p, width=%u, height=%u",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), width, height);
try {
static std::string result;
result = RunInferenceBinary(Handle, jpeg_bytes, width, height);
@@ -2045,6 +2182,8 @@ extern "C" __declspec(dllexport) const char* RunInferenceBinary_CS(ANSCENTER::AN
}
extern "C" __declspec(dllexport) const char* OptimizeModelStr_CS(const char* modelFilePath, const char* modelFileZipPassword, int modelType, int modelDetectionType, int fp16)
{
ANS_DBG("ANSOD","OptimizeModelStr_CS: modelType=%d, modelDetectionType=%d, fp16=%d, modelPath=%s",
modelType, modelDetectionType, fp16, modelFilePath ? modelFilePath : "(null)");
try {
static std::string result;
result.clear();
@@ -2059,6 +2198,8 @@ extern "C" __declspec(dllexport) const char* OptimizeModelStr_CS(const char* mod
// with camera id
extern "C" ANSODENGINE_API int RunDetectMovement_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunDetectMovement_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
cv::Mat frame = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
if (frame.empty()) {
@@ -2085,6 +2226,8 @@ extern "C" ANSODENGINE_API int RunDetectMovement_LV(ANSCENTER::ANSODBase** Han
}
extern "C" ANSODENGINE_API int RunInferenceFromJpegStringWithCameraId_LV(ANSCENTER::ANSODBase** Handle, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceFromJpegStringWithCameraId_LV: HandlePtr=%p, *Handle=%p, bufferLength=%u, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), bufferLength, cameraId ? cameraId : "(null)");
try {
cv::Mat frame = cv::imdecode(cv::Mat(1, bufferLength, CV_8UC1, jpeg_string), cv::IMREAD_COLOR);
if (frame.empty()) {
@@ -2293,6 +2436,10 @@ extern "C" ANSODENGINE_API int RunInferenceComplete_LV(
LStrHandle detectionResult,
LStrHandle imageStr)
{
ANS_DBG("ANSOD","RunInferenceComplete_LV: HandlePtr=%p, *Handle=%p, cam=%s, getJpeg=%d, jpegImageSize=%d, roi=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize,
activeROIMode ? activeROIMode : "(null)");
return RunInferenceComplete_LV_SEH(Handle, cvImage, cameraId, getJpegString, jpegImageSize, activeROIMode, detectionResult, imageStr);
}
@@ -2311,6 +2458,10 @@ extern "C" ANSODENGINE_API int RunInferenceComplete_LV_V2(
{
// Cast the by-value integer back to the engine pointer — no double dereference
ANSCENTER::ANSODBase* directHandle = reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal);
ANS_DBG("ANSOD","RunInferenceComplete_LV_V2: handleVal=%llu handle=%p, cam=%s, getJpeg=%d, jpegImageSize=%d, roi=%s",
(unsigned long long)handleVal, (void*)directHandle,
cameraId ? cameraId : "(null)", getJpegString, jpegImageSize,
activeROIMode ? activeROIMode : "(null)");
if (directHandle == nullptr) {
return -1;
}
@@ -2341,6 +2492,8 @@ extern "C" ANSODENGINE_API int RunInferenceComplete_LV_V2(
ANSCENTER::ANSODBase** Handle = &_v2Arr[0];
extern "C" ANSODENGINE_API int RunInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInference_LV_V2: handleVal=%llu handle=%p, bufferLength=%u",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal), bufferLength);
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInference(Handle, jpeg_string, bufferLength);
@@ -2358,6 +2511,9 @@ extern "C" ANSODENGINE_API int RunInference_LV_V2(uint64_t handleVal, unsigned c
}
extern "C" ANSODENGINE_API int RunTiledInference_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, int tiledWidth, int titledHeight, double overlap, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunTiledInference_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, tile=%dx%d, overlap=%.3f, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
bufferLength, tiledWidth, titledHeight, overlap, cameraId ? cameraId : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunTiledInference(Handle, jpeg_string, bufferLength, tiledWidth, titledHeight, overlap, cameraId);
@@ -2375,6 +2531,9 @@ extern "C" ANSODENGINE_API int RunTiledInference_LV_V2(uint64_t handleVal, unsig
}
extern "C" ANSODENGINE_API int RunTiledInferenceFromJpegString_LV_V2(uint64_t handleVal, const char* jpeg_string, unsigned long jpeg_size, int tiledWidth, int titledHeight, double overlap, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunTiledInferenceFromJpegString_LV_V2: handleVal=%llu handle=%p, jpeg_size=%lu, tile=%dx%d, overlap=%.3f, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
jpeg_size, tiledWidth, titledHeight, overlap, cameraId ? cameraId : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunTiledInferenceFromJpegString(Handle, jpeg_string, jpeg_size, tiledWidth, titledHeight, overlap, cameraId);
@@ -2392,6 +2551,9 @@ extern "C" ANSODENGINE_API int RunTiledInferenceFromJpegString_LV_V2(uint64_t ha
}
extern "C" ANSODENGINE_API int RunInferenceFromJpegString_LV_V2(uint64_t handleVal, const char* jpeg_string, unsigned long jpeg_size, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceFromJpegString_LV_V2: handleVal=%llu handle=%p, jpeg_size=%lu, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
jpeg_size, cameraId ? cameraId : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceFromJpegString(Handle, jpeg_string, jpeg_size, cameraId);
@@ -2409,6 +2571,8 @@ extern "C" ANSODENGINE_API int RunInferenceFromJpegString_LV_V2(uint64_t handleV
}
extern "C" ANSODENGINE_API int RunInferenceBinary_LV_V2(uint64_t handleVal, unsigned char* jpeg_bytes, unsigned int width, unsigned int height, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceBinary_LV_V2: handleVal=%llu handle=%p, width=%u, height=%u",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal), width, height);
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceBinary(Handle, jpeg_bytes, width, height);
@@ -2426,6 +2590,9 @@ extern "C" ANSODENGINE_API int RunInferenceBinary_LV_V2(uint64_t handleVal, unsi
}
extern "C" ANSODENGINE_API int RunInferenceImagePath_LV_V2(uint64_t handleVal, const char* imageFilePath, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceImagePath_LV_V2: handleVal=%llu handle=%p, imageFilePath=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
imageFilePath ? imageFilePath : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceImagePath(Handle, imageFilePath);
@@ -2443,6 +2610,9 @@ extern "C" ANSODENGINE_API int RunInferenceImagePath_LV_V2(uint64_t handleVal, c
}
extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxImages_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, const char* strBboxes, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxImages_LV_V2: handleVal=%llu handle=%p, bufferLength=%d, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
(int)bufferLength, cameraId ? cameraId : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceInCroppedBBoxImages(Handle, jpeg_string, bufferLength, cameraId, strBboxes);
@@ -2460,6 +2630,9 @@ extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxImages_LV_V2(uint64_t ha
}
extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxPolygonImages_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, int32 bufferLength, const char* cameraId, const char* strPolygon, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceInCroppedBBoxPolygonImages_LV_V2: handleVal=%llu handle=%p, bufferLength=%d, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
(int)bufferLength, cameraId ? cameraId : "(null)");
try {
V2_HANDLE_SETUP(handleVal);
std::string st = RunInferenceInCroppedPolygonImages(Handle, jpeg_string, bufferLength, cameraId, strPolygon);
@@ -2477,6 +2650,9 @@ extern "C" ANSODENGINE_API int RunInferenceInCroppedBBoxPolygonImages_LV_V2(uint
}
extern "C" ANSODENGINE_API int RunDetectMovement_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunDetectMovement_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
try {
ANSCENTER::ANSODBase* directHandle = reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal);
if (directHandle == nullptr) return 0;
@@ -2499,6 +2675,9 @@ extern "C" ANSODENGINE_API int RunDetectMovement_LV_V2(uint64_t handleVal, unsig
}
extern "C" ANSODENGINE_API int RunInferenceFromJpegStringWithCameraId_LV_V2(uint64_t handleVal, unsigned char* jpeg_string, unsigned int bufferLength, const char* cameraId, LStrHandle detectionResult) {
ANS_DBG("ANSOD","RunInferenceFromJpegStringWithCameraId_LV_V2: handleVal=%llu handle=%p, bufferLength=%u, cam=%s",
(unsigned long long)handleVal, (void*)reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal),
bufferLength, cameraId ? cameraId : "(null)");
try {
ANSCENTER::ANSODBase* directHandle = reinterpret_cast<ANSCENTER::ANSODBase*>(handleVal);
if (directHandle == nullptr) return 0;
@@ -2521,6 +2700,9 @@ extern "C" ANSODENGINE_API int RunInferenceFromJpegStringWithCameraId_LV_V2(uint
}
extern "C" ANSODENGINE_API int RunInferenceComplete_CPP(ANSCENTER::ANSODBase** Handle, cv::Mat** cvImage, const char* cameraId, const char* activeROIMode, std::vector<ANSCENTER::Object> &detectionResult) {
ANS_DBG("ANSOD","RunInferenceComplete_CPP: HandlePtr=%p, *Handle=%p, cam=%s, roi=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
cameraId ? cameraId : "(null)", activeROIMode ? activeROIMode : "(null)");
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null in RunInferenceComplete_CPP!" << std::endl;
return -1;
@@ -2575,6 +2757,8 @@ extern "C" ANSODENGINE_API int RunInferenceComplete_CPP(ANSCENTER::ANSODBase**
}
extern "C" ANSODENGINE_API int RunInference_CPP(ANSCENTER::ANSODBase** Handle, cv::Mat** cvImage, const char* cameraId, std::vector<ANSCENTER::Object>& detectionResult) {
ANS_DBG("ANSOD","RunInference_CPP: HandlePtr=%p, *Handle=%p, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), cameraId ? cameraId : "(null)");
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null in RunInference_CPP!" << std::endl;
return -1;
@@ -2624,6 +2808,7 @@ extern "C" ANSODENGINE_API int RunInference_CPP(ANSCENTER::ANSODBase** Handle,
// Utility function to convert a string to a vector of cv::Point
extern "C" __declspec(dllexport) int GetEngineType() {
ANS_DBG("ANSOD","GetEngineType: called");
ANSCENTER::EngineType engineType = ANSCENTER::ANSLicenseHelper::CheckHardwareInformation();
switch (engineType) {
case ANSCENTER::EngineType::CPU:
@@ -2641,6 +2826,8 @@ extern "C" __declspec(dllexport) int GetEngineType() {
extern "C" __declspec(dllexport) int GetActiveRect(ANSCENTER::ANSODBase** Handle, cv::Mat cvImage, cv::Rect& activeWindow) {
ANS_DBG("ANSOD","GetActiveRect: HandlePtr=%p, *Handle=%p, image=%dx%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), cvImage.cols, cvImage.rows);
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2667,6 +2854,9 @@ extern "C" __declspec(dllexport) int GetActiveRect(ANSCENTER::ANSODBase** Handle
}
extern "C" __declspec(dllexport) int DetectMovement(ANSCENTER::ANSODBase** Handle, cv::Mat image, const char* cameraId, std::vector<ANSCENTER::Object>& results) {
ANS_DBG("ANSOD","DetectMovement: HandlePtr=%p, *Handle=%p, image=%dx%d, cam=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), image.cols, image.rows,
cameraId ? cameraId : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2693,6 +2883,8 @@ extern "C" __declspec(dllexport) int DetectMovement(ANSCENTER::ANSODBase** Handl
}
extern "C" __declspec(dllexport) int Optimize(ANSCENTER::ANSODBase** Handle, bool fp16) {
ANS_DBG("ANSOD","Optimize: HandlePtr=%p, *Handle=%p, fp16=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), fp16 ? 1 : 0);
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2714,6 +2906,8 @@ extern "C" __declspec(dllexport) int Optimize(ANSCENTER::ANSODBase** Handle, boo
}
extern "C" __declspec(dllexport) int SetODParameters(ANSCENTER::ANSODBase** Handle, const char* parameters) {
ANS_DBG("ANSOD","SetODParameters: HandlePtr=%p, *Handle=%p, parameters=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), parameters ? parameters : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2741,6 +2935,8 @@ extern "C" __declspec(dllexport) int SetODParameters(ANSCENTER::ANSODBase** Hand
}
extern "C" __declspec(dllexport) int GetODParameters(ANSCENTER::ANSODBase** Handle, ANSCENTER::Params& param) {
ANS_DBG("ANSOD","GetODParameters: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2755,6 +2951,8 @@ extern "C" __declspec(dllexport) int GetODParameters(ANSCENTER::ANSODBase** Hand
}
}
extern "C" __declspec(dllexport) int GetConfiguredParameters(ANSCENTER::ANSODBase** Handle, LStrHandle stParam) {
ANS_DBG("ANSOD","GetConfiguredParameters: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
__try {
return [&]() -> int {
try {
@@ -2801,6 +2999,8 @@ extern "C" __declspec(dllexport) int GetConfiguredParameters(ANSCENTER::ANSODBas
}
}
extern "C" __declspec(dllexport) int GetConfiguredParameters_CPP(ANSCENTER::ANSODBase** Handle, std::string& stParam) {
ANS_DBG("ANSOD","GetConfiguredParameters_CPP: HandlePtr=%p, *Handle=%p",
(void*)Handle, (void*)(Handle ? *Handle : nullptr));
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2823,14 +3023,18 @@ extern "C" __declspec(dllexport) int GetConfiguredParameters_CPP(ANSCENTER::ANSO
}
extern "C" ANSODENGINE_API int ShutdownPythonEngine() {
ANS_DBG("ANSOD","ShutdownPythonEngine: called");
ANSCENTER::ANSCUSTOMPY::SafeShutdownAll(false);
return 1;
}
extern "C" ANSODENGINE_API int ShutdownPythonEngine_CPP() {
ANS_DBG("ANSOD","ShutdownPythonEngine_CPP: called");
ANSCENTER::ANSCUSTOMPY::SafeShutdownAll(true);
return 1;
}
extern "C" __declspec(dllexport) int UpdateDetectionMinScore(ANSCENTER::ANSODBase** Handle, float detectionScore) {
ANS_DBG("ANSOD","UpdateDetectionMinScore: HandlePtr=%p, *Handle=%p, detectionScore=%.4f",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), detectionScore);
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2851,6 +3055,8 @@ extern "C" __declspec(dllexport) int UpdateDetectionMinScore(ANSCENTER::ANSODBas
}
}
extern "C" __declspec(dllexport) int SetPrompt(ANSCENTER::ANSODBase** Handle, const char* textPrompt) {
ANS_DBG("ANSOD","SetPrompt: HandlePtr=%p, *Handle=%p, textPrompt=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), textPrompt ? textPrompt : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2875,6 +3081,8 @@ extern "C" __declspec(dllexport) int SetPrompt(ANSCENTER::ANSODBase** Handle, co
}
}
extern "C" __declspec(dllexport) int SetTracker(ANSCENTER::ANSODBase** Handle, int trackerType, int enableTracker) {
ANS_DBG("ANSOD","SetTracker: HandlePtr=%p, *Handle=%p, trackerType=%d, enableTracker=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), trackerType, enableTracker);
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2911,6 +3119,8 @@ extern "C" __declspec(dllexport) int SetTracker(ANSCENTER::ANSODBase** Handle, i
}
}
extern "C" __declspec(dllexport) int SetTrackerParameters(ANSCENTER::ANSODBase** Handle, const char* trackerParams) {
ANS_DBG("ANSOD","SetTrackerParameters: HandlePtr=%p, *Handle=%p, trackerParams=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), trackerParams ? trackerParams : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) {
std::cerr << "Error: Handle is null!" << std::endl;
@@ -2938,6 +3148,8 @@ extern "C" __declspec(dllexport) int SetTrackerParameters(ANSCENTER::ANSODBase**
// All keys are optional — omit to keep current defaults.
// Example: {"ema_alpha":0.4, "class_consistency_frames":8, "hysteresis_enter":0.5, "hysteresis_keep":0.3}
extern "C" __declspec(dllexport) int SetStabilizationParameters(ANSCENTER::ANSODBase** Handle, const char* stabParams) {
ANS_DBG("ANSOD","SetStabilizationParameters: HandlePtr=%p, *Handle=%p, stabParams=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), stabParams ? stabParams : "(null)");
try {
if (Handle == nullptr || *Handle == nullptr) {
return -1;

View File

@@ -18,6 +18,8 @@
#include <unordered_map>
#include <condition_variable>
// DebugView: filter on "[ANSTRE]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// Handle registry with refcount — prevents use-after-free when
// ReleaseANSTREHandle is called while an operation is still running.
// destructionStarted: set by the first Unregister caller; blocks new Acquires
@@ -40,14 +42,30 @@ static std::condition_variable& TREHandleRegistryCV() {
static void RegisterTREHandle(ANSCENTER::ANSTRE* h) {
std::lock_guard<std::mutex> lk(TREHandleRegistryMutex());
TREHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSTRE","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, TREHandleRegistry().size());
}
static ANSCENTER::ANSTRE* AcquireTREHandle(ANSCENTER::ANSTRE* h) {
std::lock_guard<std::mutex> lk(TREHandleRegistryMutex());
auto it = TREHandleRegistry().find(h);
if (it == TREHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == TREHandleRegistry().end()) {
ANS_DBG("ANSTRE","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, TREHandleRegistry().size());
size_t i = 0;
for (auto& kv : TREHandleRegistry()) {
ANS_DBG("ANSTRE"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSTRE","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSTRE","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -65,10 +83,15 @@ static bool ReleaseTREHandleRef(ANSCENTER::ANSTRE* h) {
static bool UnregisterTREHandle(ANSCENTER::ANSTRE* h) {
std::unique_lock<std::mutex> lk(TREHandleRegistryMutex());
auto it = TREHandleRegistry().find(h);
if (it == TREHandleRegistry().end()) return false;
if (it == TREHandleRegistry().end()) {
ANS_DBG("ANSTRE","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSTRE","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false; // Another thread already owns the delete.
}
ANS_DBG("ANSTRE","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = TREHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -76,6 +99,7 @@ static bool UnregisterTREHandle(ANSCENTER::ANSTRE* h) {
return it2 == TREHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSTRE","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterTREHandle timed out waiting for in-flight operations\n");
}
TREHandleRegistry().erase(h);
@@ -327,8 +351,14 @@ namespace ANSCENTER
}
extern "C" ANSTRE_API int CreateANSTREHandle(ANSCENTER::ANSTRE** Handle, const char* licenseKey, const char* projectDirectory, const char* engineDirectory, const char* modelTemplateDirectory, const char* modelZipPassword, int trainingEngineType, int latestEngine) {
if (Handle == nullptr) return 0;
if (licenseKey == nullptr || projectDirectory == nullptr || engineDirectory == nullptr || modelTemplateDirectory == nullptr || modelZipPassword == nullptr) return 0;
ANS_DBG("ANSTRE","Create called: HandlePtr=%p, *Handle(in)=%p, engineType=%d, latestEngine=%d, projectDir=%s, engineDir=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), trainingEngineType, latestEngine,
projectDirectory ? projectDirectory : "(null)", engineDirectory ? engineDirectory : "(null)");
if (Handle == nullptr) { ANS_DBG("ANSTRE","Create FAIL: Handle is null"); return 0; }
if (licenseKey == nullptr || projectDirectory == nullptr || engineDirectory == nullptr || modelTemplateDirectory == nullptr || modelZipPassword == nullptr) {
ANS_DBG("ANSTRE","Create FAIL: one of the string params is null");
return 0;
}
// Pure constructor: ignore *Handle(in). LabVIEW's CLF Node marshalling
// reuses the same temp buffer per call site, so *Handle(in) often holds
// leftover bytes from the previous Create's output even when the actual
@@ -360,36 +390,51 @@ extern "C" ANSTRE_API int CreateANSTREHandle(ANSCENTER::ANSTRE** Handle, const
(*Handle) = new ANSCENTER::ANSODTRE();
break;
}
if (*Handle == nullptr) return 0;
if (*Handle == nullptr) { ANS_DBG("ANSTRE","Create FAIL: new returned null"); return 0; }
ANS_DBG("ANSTRE","Create: allocated handle=%p (uint=%llu), calling Init...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
bool isLatestEngine = (latestEngine == 1) ? true : false;
if ((*Handle)->Init(licenseKey, projectDirectory, engineDirectory, modelTemplateDirectory, modelZipPassword, isLatestEngine)) {
RegisterTREHandle(*Handle);
ANS_DBG("ANSTRE","Create OK: handle=%p (uint=%llu)", (void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return 1;
}
ANS_DBG("ANSTRE","Create FAIL: Init returned false, deleting handle=%p", (void*)*Handle);
delete *Handle; *Handle = nullptr;
return 0;
}
catch (std::exception& e) {
ANS_DBG("ANSTRE","Create EXCEPTION (std::exception): %s", e.what());
if (*Handle != nullptr) { delete *Handle; *Handle = nullptr; }
return 0;
}
catch (...) {
ANS_DBG("ANSTRE","Create EXCEPTION (unknown)");
if (*Handle != nullptr) { delete *Handle; *Handle = nullptr; }
return 0;
}
}
static int ReleaseANSTREHandle_Impl(ANSCENTER::ANSTRE** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterTREHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSTRE","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSTRE* h = *Handle;
ANS_DBG("ANSTRE","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterTREHandle(h)) {
ANS_DBG("ANSTRE","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1;
}
delete *Handle;
delete h;
*Handle = nullptr;
ANS_DBG("ANSTRE","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, TREHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSTRE","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
@@ -400,11 +445,13 @@ extern "C" ANSTRE_API int ReleaseANSTREHandle(ANSCENTER::ANSTRE** Handle) {
return ReleaseANSTREHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSTRE","ReleaseANSTREHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjects(ANSCENTER::ANSTRE** Handle, LStrHandle strProjects) {
ANS_DBG("ANSTRE","ANSTRE_GetProjects: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || strProjects == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -427,6 +474,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjects(ANSCENTER::ANSTRE** Handle, LStrHa
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments(ANSCENTER::ANSTRE** Handle, const char* projectName, LStrHandle strProjectExperiments) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperiments: HandlePtr=%p, *Handle=%p, project=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)");
if (Handle == nullptr || projectName == nullptr || strProjectExperiments == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -449,6 +498,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments(ANSCENTER::ANSTRE** Hand
}
}
extern "C" ANSTRE_API int ANSTRE_CreateProject(ANSCENTER::ANSTRE** Handle, const char* projectName) {
ANS_DBG("ANSTRE","ANSTRE_CreateProject: HandlePtr=%p, *Handle=%p, project=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)");
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -462,6 +513,8 @@ extern "C" ANSTRE_API int ANSTRE_CreateProject(ANSCENTER::ANSTRE** Handle, cons
}
}
extern "C" ANSTRE_API int ANSTRE_DeleteProject(ANSCENTER::ANSTRE** Handle, const char* projectName) {
ANS_DBG("ANSTRE","ANSTRE_DeleteProject: HandlePtr=%p, *Handle=%p, project=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)");
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -475,6 +528,8 @@ extern "C" ANSTRE_API int ANSTRE_DeleteProject(ANSCENTER::ANSTRE** Handle, cons
}
}
extern "C" ANSTRE_API int ANSTRE_SetWorkingDirectory(ANSCENTER::ANSTRE** Handle, const char* workingDirectory) {
ANS_DBG("ANSTRE","ANSTRE_SetWorkingDirectory: HandlePtr=%p, *Handle=%p, dir=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), workingDirectory ? workingDirectory : "(null)");
if (Handle == nullptr || workingDirectory == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -488,6 +543,8 @@ extern "C" ANSTRE_API int ANSTRE_SetWorkingDirectory(ANSCENTER::ANSTRE** Handle
}
}
extern "C" ANSTRE_API int ANSTRE_UploadTrainingData(ANSCENTER::ANSTRE** Handle, const char* projectName) {
ANS_DBG("ANSTRE","ANSTRE_UploadTrainingData: HandlePtr=%p, *Handle=%p, project=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)");
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -501,6 +558,9 @@ extern "C" ANSTRE_API int ANSTRE_UploadTrainingData(ANSCENTER::ANSTRE** Handle,
}
}
extern "C" ANSTRE_API int ANSTRE_CreateTrainingEngine(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, int extractorType, long numberStep, int batchSize, double learningRate) {
ANS_DBG("ANSTRE","ANSTRE_CreateTrainingEngine: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, extractor=%d, steps=%ld, batch=%d, lr=%f",
(void*)Handle, (void*)(Handle ? *Handle : nullptr),
projectName ? projectName : "(null)", experimentNumber, extractorType, numberStep, batchSize, learningRate);
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -514,6 +574,8 @@ extern "C" ANSTRE_API int ANSTRE_CreateTrainingEngine(ANSCENTER::ANSTRE** Handl
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, LStrHandle projectStatus) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperimentStatus: HandlePtr=%p, *Handle=%p, project=%s, exp=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber);
if (Handle == nullptr || projectName == nullptr || projectStatus == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -536,6 +598,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus(ANSCENTER::ANSTRE**
}
}
extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, int extractorType, LStrHandle trainingCommand) {
ANS_DBG("ANSTRE","ANSTRE_GenerateTrainingCommand: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, extractor=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, extractorType);
if (Handle == nullptr || projectName == nullptr || trainingCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -558,6 +622,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand(ANSCENTER::ANSTRE** Ha
}
}
extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, int extractorType, const char* pretrainedModel, LStrHandle trainingCommand) {
ANS_DBG("ANSTRE","ANSTRE_GenerateCustomTrainingCommand: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, extractor=%d, pretrained=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, extractorType, pretrainedModel ? pretrainedModel : "(null)");
if (Handle == nullptr || projectName == nullptr || pretrainedModel == nullptr || trainingCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -580,6 +646,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand(ANSCENTER::ANSTR
}
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModel(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, LStrHandle mAPResult) {
ANS_DBG("ANSTRE","ANSTRE_EvaluateModel: HandlePtr=%p, *Handle=%p, project=%s, exp=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber);
if (Handle == nullptr || projectName == nullptr || mAPResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -603,6 +671,9 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModel(ANSCENTER::ANSTRE** Handle, cons
}
extern "C" ANSTRE_API int ANSTRE_DownloadModel(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, const char* downloadDirDestination, int modelMode)
{
ANS_DBG("ANSTRE","ANSTRE_DownloadModel: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, dest=%s, mode=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber,
downloadDirDestination ? downloadDirDestination : "(null)", modelMode);
if (Handle == nullptr || projectName == nullptr || downloadDirDestination == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -617,6 +688,7 @@ extern "C" ANSTRE_API int ANSTRE_DownloadModel(ANSCENTER::ANSTRE** Handle, cons
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory(ANSCENTER::ANSTRE** Handle, LStrHandle strProjectDir) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectDirectory: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || strProjectDir == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -638,6 +710,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory(ANSCENTER::ANSTRE** Handle
}
}
extern "C" ANSTRE_API int ANSTRE_ZipExperiment(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber) {
ANS_DBG("ANSTRE","ANSTRE_ZipExperiment: HandlePtr=%p, *Handle=%p, project=%s, exp=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber);
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -651,6 +725,7 @@ extern "C" ANSTRE_API int ANSTRE_ZipExperiment(ANSCENTER::ANSTRE** Handle, cons
}
}
extern "C" ANSTRE_API double ANSTRE_ParseMAP(ANSCENTER::ANSTRE** Handle, const char* evaluationResult) {
ANS_DBG("ANSTRE","ANSTRE_ParseMAP: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || evaluationResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -663,6 +738,7 @@ extern "C" ANSTRE_API double ANSTRE_ParseMAP(ANSCENTER::ANSTRE** Handle, const
}
}
extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults(ANSCENTER::ANSTRE** Handle, const char* trainingResult, LStrHandle strResult) {
ANS_DBG("ANSTRE","ANSTRE_ParseTrainingResults: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || trainingResult == nullptr || strResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -687,6 +763,7 @@ extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults(ANSCENTER::ANSTRE** Handl
//CPP interface
extern "C" ANSTRE_API int ANSTRE_GetProjects_CPP(ANSCENTER::ANSTRE** Handle, std::string& strProjects) {
ANS_DBG("ANSTRE","ANSTRE_GetProjects_CPP: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -700,6 +777,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjects_CPP(ANSCENTER::ANSTRE** Handle, st
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, std::string& strProjectExperiments) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperiments_CPP: HandlePtr=%p, *Handle=%p, project=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)");
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -713,6 +792,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments_CPP(ANSCENTER::ANSTRE**
}
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, std::string& projectStatus) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperimentStatus_CPP: HandlePtr=%p, *Handle=%p, project=%s, exp=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber);
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -726,6 +807,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus_CPP(ANSCENTER::ANST
}
}
extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, int extractorType, std::string& trainingCommand) {
ANS_DBG("ANSTRE","ANSTRE_GenerateTrainingCommand_CPP: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, extractor=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, extractorType);
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -739,6 +822,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand_CPP(ANSCENTER::ANSTRE*
}
}
extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, int extractorType, const char* pretrainedModel, std::string& trainingCommand) {
ANS_DBG("ANSTRE","ANSTRE_GenerateCustomTrainingCommand_CPP: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, extractor=%d, pretrained=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, extractorType, pretrainedModel ? pretrainedModel : "(null)");
if (Handle == nullptr || projectName == nullptr || pretrainedModel == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -752,6 +837,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand_CPP(ANSCENTER::A
}
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModel_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, std::string& mAPResult) {
ANS_DBG("ANSTRE","ANSTRE_EvaluateModel_CPP: HandlePtr=%p, *Handle=%p, project=%s, exp=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber);
if (Handle == nullptr || projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -765,6 +852,8 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModel_CPP(ANSCENTER::ANSTRE** Handle,
}
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData_CPP(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, const char* dataFolder,std::string& evaluationCommand) {
ANS_DBG("ANSTRE","ANSTRE_EvaluateModelOnTestData_CPP: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, dataFolder=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, dataFolder ? dataFolder : "(null)");
if (Handle == nullptr || projectName == nullptr || dataFolder == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -784,6 +873,8 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData_CPP(ANSCENTER::ANSTRE*
}
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData(ANSCENTER::ANSTRE** Handle, const char* projectName, int experimentNumber, const char* dataFolder, LStrHandle evaluationCommand) {
ANS_DBG("ANSTRE","ANSTRE_EvaluateModelOnTestData: HandlePtr=%p, *Handle=%p, project=%s, exp=%d, dataFolder=%s",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), projectName ? projectName : "(null)", experimentNumber, dataFolder ? dataFolder : "(null)");
if (Handle == nullptr || projectName == nullptr || dataFolder == nullptr || evaluationCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -809,6 +900,7 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData(ANSCENTER::ANSTRE** Ha
extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory_CPP(ANSCENTER::ANSTRE** Handle, std::string& strProjectDir) {
ANS_DBG("ANSTRE","ANSTRE_GetProjectDirectory_CPP: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -821,6 +913,7 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory_CPP(ANSCENTER::ANSTRE** Ha
}
}
extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults_CPP(ANSCENTER::ANSTRE** Handle, const char* trainingResult, std::string& strResult) {
ANS_DBG("ANSTRE","ANSTRE_ParseTrainingResults_CPP: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || trainingResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -834,6 +927,7 @@ extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults_CPP(ANSCENTER::ANSTRE** H
}
}
extern "C" ANSTRE_API int ANSTRE_CheckEngineStatus(ANSCENTER::ANSTRE** Handle) {
ANS_DBG("ANSTRE","ANSTRE_CheckEngineStatus: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -847,6 +941,7 @@ extern "C" ANSTRE_API int ANSTRE_CheckEngineStatus(ANSCENTER::ANSTRE** Handle)
}
}
extern "C" ANSTRE_API int ANSTRE_CheckEngine(ANSCENTER::ANSTRE** Handle) {
ANS_DBG("ANSTRE","ANSTRE_CheckEngine: HandlePtr=%p, *Handle=%p", (void*)Handle, (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(*Handle));
if (!guard) return 0;
@@ -868,6 +963,7 @@ extern "C" ANSTRE_API int ANSTRE_CheckEngine(ANSCENTER::ANSTRE** Handle) {
extern "C" ANSTRE_API int ANSTRE_GetProjects_V2(uint64_t handleVal, LStrHandle strProjects) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GetProjects_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0;
if (strProjects == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -892,6 +988,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjects_V2(uint64_t handleVal, LStrHandle
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments_V2(uint64_t handleVal, const char* projectName, LStrHandle strProjectExperiments) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperiments_V2: handleVal=%llu handle=%p, project=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr || strProjectExperiments == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -916,6 +1014,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperiments_V2(uint64_t handleVal, c
}
extern "C" ANSTRE_API int ANSTRE_CreateProject_V2(uint64_t handleVal, const char* projectName) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_CreateProject_V2: handleVal=%llu handle=%p, project=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -931,6 +1031,8 @@ extern "C" ANSTRE_API int ANSTRE_CreateProject_V2(uint64_t handleVal, const cha
}
extern "C" ANSTRE_API int ANSTRE_DeleteProject_V2(uint64_t handleVal, const char* projectName) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_DeleteProject_V2: handleVal=%llu handle=%p, project=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -946,6 +1048,8 @@ extern "C" ANSTRE_API int ANSTRE_DeleteProject_V2(uint64_t handleVal, const cha
}
extern "C" ANSTRE_API int ANSTRE_SetWorkingDirectory_V2(uint64_t handleVal, const char* workingDirectory) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_SetWorkingDirectory_V2: handleVal=%llu handle=%p, dir=%s",
(unsigned long long)handleVal, (void*)_v2h, workingDirectory ? workingDirectory : "(null)");
if (!_v2h) return 0;
if (workingDirectory == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -961,6 +1065,8 @@ extern "C" ANSTRE_API int ANSTRE_SetWorkingDirectory_V2(uint64_t handleVal, con
}
extern "C" ANSTRE_API int ANSTRE_UploadTrainingData_V2(uint64_t handleVal, const char* projectName) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_UploadTrainingData_V2: handleVal=%llu handle=%p, project=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -976,6 +1082,8 @@ extern "C" ANSTRE_API int ANSTRE_UploadTrainingData_V2(uint64_t handleVal, cons
}
extern "C" ANSTRE_API int ANSTRE_CreateTrainingEngine_V2(uint64_t handleVal, const char* projectName, int experimentNumber, int extractorType, long numberStep, int batchSize, double learningRate) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_CreateTrainingEngine_V2: handleVal=%llu handle=%p, project=%s, exp=%d, extractor=%d, steps=%ld, batch=%d, lr=%f",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber, extractorType, numberStep, batchSize, learningRate);
if (!_v2h) return 0;
if (projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -991,6 +1099,8 @@ extern "C" ANSTRE_API int ANSTRE_CreateTrainingEngine_V2(uint64_t handleVal, co
}
extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus_V2(uint64_t handleVal, const char* projectName, int experimentNumber, LStrHandle projectStatus) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GetProjectExperimentStatus_V2: handleVal=%llu handle=%p, project=%s, exp=%d",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber);
if (!_v2h) return 0;
if (projectName == nullptr || projectStatus == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1015,6 +1125,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectExperimentStatus_V2(uint64_t handleV
}
extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand_V2(uint64_t handleVal, const char* projectName, int experimentNumber, int extractorType, LStrHandle trainingCommand) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GenerateTrainingCommand_V2: handleVal=%llu handle=%p, project=%s, exp=%d, extractor=%d",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber, extractorType);
if (!_v2h) return 0;
if (projectName == nullptr || trainingCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1039,6 +1151,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateTrainingCommand_V2(uint64_t handleVal,
}
extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand_V2(uint64_t handleVal, const char* projectName, int experimentNumber, int extractorType, const char* pretrainedModel, LStrHandle trainingCommand) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GenerateCustomTrainingCommand_V2: handleVal=%llu handle=%p, project=%s, exp=%d, extractor=%d, pretrained=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber, extractorType, pretrainedModel ? pretrainedModel : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr || pretrainedModel == nullptr || trainingCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1063,6 +1177,8 @@ extern "C" ANSTRE_API int ANSTRE_GenerateCustomTrainingCommand_V2(uint64_t hand
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModel_V2(uint64_t handleVal, const char* projectName, int experimentNumber, LStrHandle mAPResult) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_EvaluateModel_V2: handleVal=%llu handle=%p, project=%s, exp=%d",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber);
if (!_v2h) return 0;
if (projectName == nullptr || mAPResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1087,6 +1203,8 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModel_V2(uint64_t handleVal, const cha
}
extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData_V2(uint64_t handleVal, const char* projectName, int experimentNumber, const char* dataFolder, LStrHandle evaluationCommand) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_EvaluateModelOnTestData_V2: handleVal=%llu handle=%p, project=%s, exp=%d, dataFolder=%s",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber, dataFolder ? dataFolder : "(null)");
if (!_v2h) return 0;
if (projectName == nullptr || dataFolder == nullptr || evaluationCommand == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1112,6 +1230,9 @@ extern "C" ANSTRE_API int ANSTRE_EvaluateModelOnTestData_V2(uint64_t handleVal,
}
extern "C" ANSTRE_API int ANSTRE_DownloadModel_V2(uint64_t handleVal, const char* projectName, int experimentNumber, const char* downloadDirDestination, int modelMode) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_DownloadModel_V2: handleVal=%llu handle=%p, project=%s, exp=%d, dest=%s, mode=%d",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber,
downloadDirDestination ? downloadDirDestination : "(null)", modelMode);
if (!_v2h) return 0;
if (projectName == nullptr || downloadDirDestination == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1128,6 +1249,7 @@ extern "C" ANSTRE_API int ANSTRE_DownloadModel_V2(uint64_t handleVal, const cha
}
extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory_V2(uint64_t handleVal, LStrHandle strProjectDir) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_GetProjectDirectory_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0;
if (strProjectDir == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1151,6 +1273,8 @@ extern "C" ANSTRE_API int ANSTRE_GetProjectDirectory_V2(uint64_t handleVal, LSt
}
extern "C" ANSTRE_API int ANSTRE_ZipExperiment_V2(uint64_t handleVal, const char* projectName, int experimentNumber) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_ZipExperiment_V2: handleVal=%llu handle=%p, project=%s, exp=%d",
(unsigned long long)handleVal, (void*)_v2h, projectName ? projectName : "(null)", experimentNumber);
if (!_v2h) return 0;
if (projectName == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1166,6 +1290,7 @@ extern "C" ANSTRE_API int ANSTRE_ZipExperiment_V2(uint64_t handleVal, const cha
}
extern "C" ANSTRE_API double ANSTRE_ParseMAP_V2(uint64_t handleVal, const char* evaluationResult) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_ParseMAP_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0.0;
if (evaluationResult == nullptr) return 0.0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1180,6 +1305,7 @@ extern "C" ANSTRE_API double ANSTRE_ParseMAP_V2(uint64_t handleVal, const char*
}
extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults_V2(uint64_t handleVal, const char* trainingResult, LStrHandle strResult) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_ParseTrainingResults_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0;
if (trainingResult == nullptr || strResult == nullptr) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
@@ -1204,6 +1330,7 @@ extern "C" ANSTRE_API int ANSTRE_ParseTrainingResults_V2(uint64_t handleVal, co
}
extern "C" ANSTRE_API int ANSTRE_CheckEngineStatus_V2(uint64_t handleVal) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_CheckEngineStatus_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
if (!guard) return 0;
@@ -1218,6 +1345,7 @@ extern "C" ANSTRE_API int ANSTRE_CheckEngineStatus_V2(uint64_t handleVal) {
}
extern "C" ANSTRE_API int ANSTRE_CheckEngine_V2(uint64_t handleVal) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSTRE*>(handleVal);
ANS_DBG("ANSTRE","ANSTRE_CheckEngine_V2: handleVal=%llu handle=%p", (unsigned long long)handleVal, (void*)_v2h);
if (!_v2h) return 0;
TREHandleGuard guard(AcquireTREHandle(_v2h));
if (!guard) return 0;

View File

@@ -2431,7 +2431,7 @@ namespace ANSCENTER
// addressing style) — always the canonical path-style URL.
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + objectKey;
_logger.LogError(kOp,
_logger.LogDebug(kOp,
"Successfully uploaded: " + objectKey + " (" + std::to_string(bufferLength) + " bytes) | URL: " + uploadedFilePath,
__FILE__, __LINE__);
ReleaseConnection(std::move(conn));

View File

@@ -3,21 +3,11 @@
#include "ANSUtilities.h"
#include <cstdint>
#include <cstdio>
#include <cstdarg>
#include <unordered_map>
#include <condition_variable>
#include <mutex>
// ── DebugView logger (filter on "[ANSAWS]") ──
static void AWSDbg(const char* fmt, ...) {
char buf[512];
va_list ap;
va_start(ap, fmt);
int n = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (n < 0) return;
OutputDebugStringA(buf);
}
// DebugView: filter on "[ANSAWS]" or "[ANSUTIL]" — gated by ANSCORE_DEBUGVIEW in ANSLicense.h.
// ── ANSUtilities handle registry ──
// destructionStarted: set by the first Unregister caller; blocks new Acquires
@@ -40,14 +30,30 @@ static std::condition_variable& UtilHandleRegistryCV() {
static void RegisterUtilHandle(ANSCENTER::ANSUtilities* h) {
std::lock_guard<std::mutex> lk(UtilHandleRegistryMutex());
UtilHandleRegistry()[h] = { 1, false };
ANS_DBG("ANSUTIL","Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, UtilHandleRegistry().size());
}
static ANSCENTER::ANSUtilities* AcquireUtilHandle(ANSCENTER::ANSUtilities* h) {
std::lock_guard<std::mutex> lk(UtilHandleRegistryMutex());
auto it = UtilHandleRegistry().find(h);
if (it == UtilHandleRegistry().end()) return nullptr;
if (it->second.destructionStarted) return nullptr;
if (it == UtilHandleRegistry().end()) {
ANS_DBG("ANSUTIL","Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, UtilHandleRegistry().size());
size_t i = 0;
for (auto& kv : UtilHandleRegistry()) {
ANS_DBG("ANSUTIL"," registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
ANS_DBG("ANSUTIL","Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
ANS_DBG("ANSUTIL","Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -65,11 +71,16 @@ static bool ReleaseUtilHandleRef(ANSCENTER::ANSUtilities* h) {
static bool UnregisterUtilHandle(ANSCENTER::ANSUtilities* h) {
std::unique_lock<std::mutex> lk(UtilHandleRegistryMutex());
auto it = UtilHandleRegistry().find(h);
if (it == UtilHandleRegistry().end()) return false;
if (it->second.destructionStarted) {
// Another thread is already tearing this handle down; let it own the delete.
if (it == UtilHandleRegistry().end()) {
ANS_DBG("ANSUTIL","Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
// Another thread is already tearing this handle down; let it own the delete.
ANS_DBG("ANSUTIL","Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false;
}
ANS_DBG("ANSUTIL","Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = UtilHandleRegistryCV().wait_for(lk, std::chrono::seconds(30), [&]() {
@@ -77,6 +88,7 @@ static bool UnregisterUtilHandle(ANSCENTER::ANSUtilities* h) {
return it2 == UtilHandleRegistry().end() || it2->second.refcount <= 0;
});
if (!ok) {
ANS_DBG("ANSUTIL","WARNING: Unregister timed out waiting for in-flight operations on handle=%p", (void*)h);
OutputDebugStringA("WARNING: UnregisterUtilHandle timed out waiting for in-flight operations\n");
}
UtilHandleRegistry().erase(h);
@@ -116,7 +128,7 @@ static std::condition_variable& AWSHandleRegistryCV() {
static void RegisterAWSHandle(ANSCENTER::ANSAWSS3* h) {
std::lock_guard<std::mutex> lk(AWSHandleRegistryMutex());
AWSHandleRegistry()[h] = { 1, false };
AWSDbg("[ANSAWS] Register: handle=%p (uint=%llu) registrySize=%zu\n",
ANS_DBG("ANSAWS", "Register: handle=%p (uint=%llu) registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, AWSHandleRegistry().size());
}
@@ -130,22 +142,22 @@ static ANSCENTER::ANSAWSS3* AcquireAWSHandle(ANSCENTER::ANSAWSS3* h) {
std::lock_guard<std::mutex> lk(AWSHandleRegistryMutex());
auto it = AWSHandleRegistry().find(h);
if (it == AWSHandleRegistry().end()) {
AWSDbg("[ANSAWS] Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu\n",
ANS_DBG("ANSAWS", "Acquire FAIL: handle=%p (uint=%llu) NOT in registry. registrySize=%zu",
(void*)h, (unsigned long long)(uintptr_t)h, AWSHandleRegistry().size());
size_t i = 0;
for (auto& kv : AWSHandleRegistry()) {
AWSDbg("[ANSAWS] registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d\n",
ANS_DBG("ANSAWS", " registry[%zu] = %p (uint=%llu) refcount=%d destructionStarted=%d",
i++, (void*)kv.first, (unsigned long long)(uintptr_t)kv.first,
kv.second.refcount, kv.second.destructionStarted ? 1 : 0);
}
return nullptr;
}
if (it->second.destructionStarted) {
AWSDbg("[ANSAWS] Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)\n", (void*)h);
ANS_DBG("ANSAWS", "Acquire FAIL: handle=%p is being destroyed (destructionStarted=true)", (void*)h);
return nullptr;
}
it->second.refcount++;
AWSDbg("[ANSAWS] Acquire OK: handle=%p refcount=%d\n", (void*)h, it->second.refcount);
ANS_DBG("ANSAWS", "Acquire OK: handle=%p refcount=%d", (void*)h, it->second.refcount);
return h;
}
@@ -164,14 +176,14 @@ static bool UnregisterAWSHandle(ANSCENTER::ANSAWSS3* h) {
std::unique_lock<std::mutex> lk(AWSHandleRegistryMutex());
auto it = AWSHandleRegistry().find(h);
if (it == AWSHandleRegistry().end()) {
AWSDbg("[ANSAWS] Unregister: handle=%p NOT in registry (already gone)\n", (void*)h);
ANS_DBG("ANSAWS", "Unregister: handle=%p NOT in registry (already gone)", (void*)h);
return false;
}
if (it->second.destructionStarted) {
AWSDbg("[ANSAWS] Unregister: handle=%p already being destroyed by another thread, returning false\n", (void*)h);
ANS_DBG("ANSAWS", "Unregister: handle=%p already being destroyed by another thread, returning false", (void*)h);
return false;
}
AWSDbg("[ANSAWS] Unregister: handle=%p starting (refcount before=%d)\n", (void*)h, it->second.refcount);
ANS_DBG("ANSAWS", "Unregister: handle=%p starting (refcount before=%d)", (void*)h, it->second.refcount);
it->second.destructionStarted = true;
it->second.refcount--;
bool ok = AWSHandleRegistryCV().wait_for(lk, std::chrono::seconds(120), [&]() {
@@ -225,22 +237,36 @@ BOOL APIENTRY DllMain( HMODULE hModule,
// (releasing live objects we "see" in the input) destroys legitimate parallel
// instances and is far worse. (Same reasoning as CreateANSAWSHandle.)
extern "C" ANSULT_API int CreateANSUtilityHandle(ANSCENTER::ANSUtilities** Handle, const char* licenseKey) {
if (Handle == nullptr || licenseKey == nullptr) return 0;
ANS_DBG("ANSUTIL","Create called: HandlePtr=%p, *Handle(in)=%p (input ignored, always allocates new)",
(void*)Handle, Handle ? (void*)*Handle : nullptr);
if (Handle == nullptr || licenseKey == nullptr) {
ANS_DBG("ANSUTIL","Create FAIL: Handle or licenseKey is null");
return 0;
}
*Handle = nullptr;
try {
*Handle = new ANSCENTER::ANSUtilities();
if (*Handle == nullptr) return 0;
if (*Handle == nullptr) {
ANS_DBG("ANSUTIL","Create FAIL: new returned null");
return 0;
}
ANS_DBG("ANSUTIL","Create: allocated handle=%p (uint=%llu), calling Initialize...",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
if ((*Handle)->Initialize(licenseKey)) {
RegisterUtilHandle(*Handle);
ANS_DBG("ANSUTIL","Create OK: handle=%p (uint=%llu)",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return 1;
}
// Initialize failed - clean up to prevent memory leak
ANS_DBG("ANSUTIL","Create FAIL: Initialize returned false, deleting handle=%p", (void*)*Handle);
delete *Handle;
*Handle = nullptr;
return 0;
}
catch (std::exception& e) {
// Clean up on exception to prevent memory leak
ANS_DBG("ANSUTIL","Create EXCEPTION (std::exception): %s", e.what());
if (*Handle != nullptr) {
delete *Handle;
*Handle = nullptr;
@@ -248,6 +274,7 @@ extern "C" ANSULT_API int CreateANSUtilityHandle(ANSCENTER::ANSUtilities** Hand
return 0;
}
catch (...) {
ANS_DBG("ANSUTIL","Create EXCEPTION (unknown)");
if (*Handle != nullptr) {
delete *Handle;
*Handle = nullptr;
@@ -258,16 +285,25 @@ extern "C" ANSULT_API int CreateANSUtilityHandle(ANSCENTER::ANSUtilities** Hand
}
static int ReleaseANSUtilityHandle_Impl(ANSCENTER::ANSUtilities** Handle) {
try {
if (!Handle || !*Handle) return 1;
if (!UnregisterUtilHandle(*Handle)) {
if (!Handle || !*Handle) {
ANS_DBG("ANSUTIL","Release: HandlePtr or *Handle is null, no-op");
return 1;
}
ANSCENTER::ANSUtilities* h = *Handle;
ANS_DBG("ANSUTIL","Release called: handle=%p (uint=%llu)", (void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterUtilHandle(h)) {
ANS_DBG("ANSUTIL","Release: Unregister returned false (already gone or being destroyed by another thread), handle=%p", (void*)h);
*Handle = nullptr;
return 1;
}
delete *Handle;
delete h;
*Handle = nullptr;
ANS_DBG("ANSUTIL","Release OK: handle=%p deleted, registry now has %zu entries",
(void*)h, UtilHandleRegistry().size());
return 1;
}
catch (...) {
ANS_DBG("ANSUTIL","Release EXCEPTION (unknown)");
if (Handle) *Handle = nullptr;
return 0;
}
@@ -278,11 +314,13 @@ extern "C" ANSULT_API int ReleaseANSUtilityHandle(ANSCENTER::ANSUtilities** Han
return ReleaseANSUtilityHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
ANS_DBG("ANSUTIL","ReleaseANSUtilityHandle: SEH exception caught");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSULT_API int GetFCMAccessToken(ANSCENTER::ANSUtilities** Handle,const char* privateKey, LStrHandle accessToken) {
ANS_DBG("ANSUTIL","GetFCMAccessToken: *Handle=%p", (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || privateKey == nullptr || accessToken == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -308,6 +346,8 @@ extern "C" ANSULT_API int GetFCMAccessToken(ANSCENTER::ANSUtilities** Handle,co
}
}
extern "C" ANSULT_API int CreateAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, LStrHandle arnTopic) {
ANS_DBG("ANSUTIL","CreateAWSSNSTopic: *Handle=%p, snsTopicName=%s",
(void*)(Handle ? *Handle : nullptr), snsTopicName ? snsTopicName : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || arnTopic == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -333,6 +373,7 @@ extern "C" ANSULT_API int CreateAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, c
}
}
extern "C" ANSULT_API int GetFCMAccessTokenCpp(ANSCENTER::ANSUtilities** Handle, const char* privateKey, std::string& accessToken) {
ANS_DBG("ANSUTIL","GetFCMAccessTokenCpp: *Handle=%p", (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || privateKey == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -354,6 +395,8 @@ extern "C" ANSULT_API int GetFCMAccessTokenCpp(ANSCENTER::ANSUtilities** Handle
}
}
extern "C" ANSULT_API int CreateAWSSNSTopicCpp(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, std::string& arnTopic) {
ANS_DBG("ANSUTIL","CreateAWSSNSTopicCpp: *Handle=%p, snsTopicName=%s",
(void*)(Handle ? *Handle : nullptr), snsTopicName ? snsTopicName : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -374,6 +417,8 @@ extern "C" ANSULT_API int CreateAWSSNSTopicCpp(ANSCENTER::ANSUtilities** Handle
}
}
extern "C" ANSULT_API int DeleteAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, const char* arnTopic) {
ANS_DBG("ANSUTIL","DeleteAWSSNSTopic: *Handle=%p, arnTopic=%s",
(void*)(Handle ? *Handle : nullptr), arnTopic ? arnTopic : "(null)");
if (Handle == nullptr || *Handle == nullptr || arnTopic == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -389,6 +434,10 @@ extern "C" ANSULT_API int DeleteAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, c
}
}
extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* phoneNumber, LStrHandle subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeSMSPhoneNumberAWSSNSTopic: *Handle=%p, snsTopicName=%s, phoneNumber=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
phoneNumber ? phoneNumber : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || phoneNumber == nullptr || subscribedARN == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -415,6 +464,10 @@ extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopic(ANSCENTER::ANSUtili
}
extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* emailAddress, LStrHandle subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeEmailAddressAWSSNSTopic: *Handle=%p, snsTopicName=%s, emailAddress=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
emailAddress ? emailAddress : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || emailAddress == nullptr || subscribedARN == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -440,6 +493,10 @@ extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopic(ANSCENTER::ANSUtiliti
}
}
extern "C" ANSULT_API int SendMessageToAWSSNSTopic(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* subjectContent, const char* messageContent, LStrHandle messageId) {
ANS_DBG("ANSUTIL","SendMessageToAWSSNSTopic: *Handle=%p, snsTopicName=%s, subject=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
subjectContent ? subjectContent : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || subjectContent == nullptr || messageContent == nullptr || messageId == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -465,6 +522,9 @@ extern "C" ANSULT_API int SendMessageToAWSSNSTopic(ANSCENTER::ANSUtilities** Ha
}
}
extern "C" ANSULT_API int SendMessageToPhoneNumber(ANSCENTER::ANSUtilities** Handle, const char* phoneNumber, const char* messageContent, LStrHandle messageId) {
ANS_DBG("ANSUTIL","SendMessageToPhoneNumber: *Handle=%p, phoneNumber=%s",
(void*)(Handle ? *Handle : nullptr),
phoneNumber ? phoneNumber : "(null)");
if (Handle == nullptr || *Handle == nullptr || phoneNumber == nullptr || messageContent == nullptr || messageId == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -490,6 +550,10 @@ extern "C" ANSULT_API int SendMessageToPhoneNumber(ANSCENTER::ANSUtilities** Ha
}
}
extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopicCpp(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* phoneNumber, std::string& subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeSMSPhoneNumberAWSSNSTopicCpp: *Handle=%p, snsTopicName=%s, phoneNumber=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
phoneNumber ? phoneNumber : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || phoneNumber == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -510,6 +574,10 @@ extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopicCpp(ANSCENTER::ANSUt
}
}
extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopicCpp(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* emailAddress, std::string& subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeEmailAddressAWSSNSTopicCpp: *Handle=%p, snsTopicName=%s, emailAddress=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
emailAddress ? emailAddress : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || emailAddress == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -530,6 +598,10 @@ extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopicCpp(ANSCENTER::ANSUtil
}
}
extern "C" ANSULT_API int SendMessageToAWSSNSTopicCpp(ANSCENTER::ANSUtilities** Handle, const char* snsTopicName, const char* subjectContent, const char* messageContent, std::string& messageId) {
ANS_DBG("ANSUTIL","SendMessageToAWSSNSTopicCpp: *Handle=%p, snsTopicName=%s, subject=%s",
(void*)(Handle ? *Handle : nullptr),
snsTopicName ? snsTopicName : "(null)",
subjectContent ? subjectContent : "(null)");
if (Handle == nullptr || *Handle == nullptr || snsTopicName == nullptr || subjectContent == nullptr || messageContent == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -550,6 +622,9 @@ extern "C" ANSULT_API int SendMessageToAWSSNSTopicCpp(ANSCENTER::ANSUtilities**
}
}
extern "C" ANSULT_API int SendMessageToPhoneNumberCpp(ANSCENTER::ANSUtilities** Handle, const char* phoneNumber, const char* messageContent, std::string& messageId) {
ANS_DBG("ANSUTIL","SendMessageToPhoneNumberCpp: *Handle=%p, phoneNumber=%s",
(void*)(Handle ? *Handle : nullptr),
phoneNumber ? phoneNumber : "(null)");
if (Handle == nullptr || *Handle == nullptr || phoneNumber == nullptr || messageContent == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -570,6 +645,7 @@ extern "C" ANSULT_API int SendMessageToPhoneNumberCpp(ANSCENTER::ANSUtilities**
}
}
extern "C" ANSULT_API int ListASWTopics(ANSCENTER::ANSUtilities** Handle, LStrHandle arnTopics) {
ANS_DBG("ANSUTIL","ListASWTopics: *Handle=%p", (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr || arnTopics == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -595,6 +671,7 @@ extern "C" ANSULT_API int ListASWTopics(ANSCENTER::ANSUtilities** Handle, LStrH
}
}
extern "C" ANSULT_API int AESEncryption(const char* inputString, const char* inputKey, LStrHandle encryptionMessage) {
ANS_DBG("ANSUTIL","AESEncryption: inputString len=%zu", inputString ? strlen(inputString) : 0);
if (inputString == nullptr || inputKey == nullptr || encryptionMessage == nullptr) return 0;
try {
std::string st = ANSCENTER::ANSUtilities::AESEncryption(inputString, inputKey);
@@ -620,6 +697,7 @@ extern "C" ANSULT_API int AESEncryption(const char* inputString, const char* in
}
extern "C" ANSULT_API int MD5HashFile(const char* filePath, LStrHandle decryptionMessage)
{
ANS_DBG("ANSUTIL","MD5HashFile: filePath=%s", filePath ? filePath : "(null)");
if (filePath == nullptr || decryptionMessage == nullptr) return 0;
try {
std::string st = ANSCENTER::ANSUtilities::MD5HashFile(filePath);
@@ -643,6 +721,7 @@ extern "C" ANSULT_API int MD5HashFile(const char* filePath, LStrHandle decrypti
}
}
extern "C" ANSULT_API int AESDecryption(const char* encryptedString, const char* inputKey, LStrHandle decryptionMessage) {
ANS_DBG("ANSUTIL","AESDecryption: encryptedString len=%zu", encryptedString ? strlen(encryptedString) : 0);
if (encryptedString == nullptr || inputKey == nullptr || decryptionMessage == nullptr) return 0;
try {
std::string st = ANSCENTER::ANSUtilities::AESDecryption(encryptedString, inputKey);
@@ -667,6 +746,7 @@ extern "C" ANSULT_API int AESDecryption(const char* encryptedString, const char
}
extern "C" ANSULT_API int ListASWTopicsCpp(ANSCENTER::ANSUtilities** Handle, std::string& arnTopics) {
ANS_DBG("ANSUTIL","ListASWTopicsCpp: *Handle=%p", (void*)(Handle ? *Handle : nullptr));
if (Handle == nullptr || *Handle == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -687,6 +767,7 @@ extern "C" ANSULT_API int ListASWTopicsCpp(ANSCENTER::ANSUtilities** Handle, st
}
}
extern "C" ANSULT_API int AESEncryptionCpp(const char* inputString, const char* inputKey, std::string& encryptedString) {
ANS_DBG("ANSUTIL","AESEncryptionCpp: inputString len=%zu", inputString ? strlen(inputString) : 0);
if (inputString == nullptr || inputKey == nullptr) return 0;
try {
encryptedString = ANSCENTER::ANSUtilities::AESEncryption(inputString, inputKey);
@@ -705,6 +786,7 @@ extern "C" ANSULT_API int AESEncryptionCpp(const char* inputString, const char*
}
}
extern "C" ANSULT_API int AESDecryptionCpp(const char* encryptedString, const char* inputKey, std::string& decryptionMessage) {
ANS_DBG("ANSUTIL","AESDecryptionCpp: encryptedString len=%zu", encryptedString ? strlen(encryptedString) : 0);
if (encryptedString == nullptr || inputKey == nullptr) return 0;
try {
decryptionMessage = ANSCENTER::ANSUtilities::AESDecryption(encryptedString, inputKey);
@@ -723,6 +805,8 @@ extern "C" ANSULT_API int AESDecryptionCpp(const char* encryptedString, const c
}
}
extern "C" ANSULT_API int AuthenticateGCS(ANSCENTER::ANSUtilities** Handle, const char* jsonKeyString) {
ANS_DBG("ANSUTIL","AuthenticateGCS: *Handle=%p, jsonKey len=%zu",
(void*)(Handle ? *Handle : nullptr), jsonKeyString ? strlen(jsonKeyString) : 0);
if (Handle == nullptr || *Handle == nullptr || jsonKeyString == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -738,6 +822,11 @@ extern "C" ANSULT_API int AuthenticateGCS(ANSCENTER::ANSUtilities** Handle, con
}
}
extern "C" ANSULT_API int UploadMatToGCS(ANSCENTER::ANSUtilities** Handle, const char* bucketName, const char* objectName, unsigned char* jpeg_string, int32 bufferLength) {
ANS_DBG("ANSUTIL","UploadMatToGCS: *Handle=%p, bucket=%s, object=%s, len=%d",
(void*)(Handle ? *Handle : nullptr),
bucketName ? bucketName : "(null)",
objectName ? objectName : "(null)",
bufferLength);
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || objectName == nullptr || jpeg_string == nullptr || bufferLength <= 0) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -757,6 +846,10 @@ extern "C" ANSULT_API int UploadMatToGCS(ANSCENTER::ANSUtilities** Handle, cons
}
}
extern "C" ANSULT_API int UploadImageToGCS(ANSCENTER::ANSUtilities** Handle, const char* bucketName, const char* objectName, cv::Mat image) {
ANS_DBG("ANSUTIL","UploadImageToGCS: *Handle=%p, bucket=%s, object=%s",
(void*)(Handle ? *Handle : nullptr),
bucketName ? bucketName : "(null)",
objectName ? objectName : "(null)");
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || objectName == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -773,6 +866,11 @@ extern "C" ANSULT_API int UploadImageToGCS(ANSCENTER::ANSUtilities** Handle, co
}
}
extern "C" ANSULT_API int SetupServerProxy(ANSCENTER::ANSUtilities** Handle, const char* hostName, int port, const char* userName, const char* passWord) {
ANS_DBG("ANSUTIL","SetupServerProxy: *Handle=%p, hostName=%s, port=%d, userName=%s",
(void*)(Handle ? *Handle : nullptr),
hostName ? hostName : "(null)",
port,
userName ? userName : "(null)");
if (Handle == nullptr || *Handle == nullptr || hostName == nullptr || userName == nullptr || passWord == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(*Handle));
if (!guard) return 0;
@@ -797,6 +895,11 @@ extern "C" ANSULT_API int SendEmail(const char* smtpServer, int port,
const char* ccEmails,
const char* bccEmails)
{
ANS_DBG("ANSUTIL","SendEmail: smtpServer=%s, port=%d, userName=%s, fromEmailSender=%s, toEmails=%s",
smtpServer ? smtpServer : "(null)", port,
userName ? userName : "(null)",
fromEmailSender ? fromEmailSender : "(null)",
toEmails ? toEmails : "(null)");
if (smtpServer == nullptr || userName == nullptr || password == nullptr ||
title == nullptr || fromEmailSender == nullptr) return 0;
try {
@@ -852,6 +955,7 @@ extern "C" ANSULT_API int SendEmail(const char* smtpServer, int port,
}
extern "C" ANSULT_API int RebootSystem() {
ANS_DBG("ANSUTIL","RebootSystem called");
try {
if (ANSCENTER::ANSUtilities::RestartPC()) return 1;
else return 0;
@@ -862,6 +966,8 @@ extern "C" ANSULT_API int RebootSystem() {
}
extern "C" ANSULT_API int ANSConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM) {
ANS_DBG("ANSUTIL","ANSConvertUTF8ToUTF16LE: utf8Str len=%zu, includeBOM=%d",
utf8Str ? strlen(utf8Str) : 0, includeBOM);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -931,6 +1037,7 @@ extern "C" ANSULT_API int ANSConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandl
}
extern "C" ANSULT_API int ANSConvertUTF16LEToUTF8(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF16LEToUTF8: byteLen=%d", byteLen);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
const unsigned char* data = utf16leBytes;
@@ -970,6 +1077,7 @@ extern "C" ANSULT_API int ANSConvertUTF16LEToUTF8(const unsigned char* utf16leBy
}
extern "C" ANSULT_API int ANSDecodeJsonUnicodeToUTF16LE(const char* escapedStr, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSDecodeJsonUnicodeToUTF16LE: escapedStr len=%zu", escapedStr ? strlen(escapedStr) : 0);
try {
if (!escapedStr || !result) return -1;
std::string decoded = ANSCENTER::ANSUtilities::DecodeJsonUnicodeToUTF16LE(escapedStr);
@@ -985,6 +1093,7 @@ extern "C" ANSULT_API int ANSDecodeJsonUnicodeToUTF16LE(const char* escapedStr,
}
extern "C" ANSULT_API int ANSConvertUTF16LEToUnicodeEscapes(const unsigned char* utf16leBytes, int byteLen, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF16LEToUnicodeEscapes: byteLen=%d", byteLen);
try {
if (!utf16leBytes || byteLen <= 0 || !result) return -1;
std::string escaped = ANSCENTER::ANSUtilities::ConvertUTF16LEToUnicodeEscapes(
@@ -1042,6 +1151,7 @@ static const unsigned char* StripBOM(const unsigned char* data, int& len) {
// 2. Contains UTF-16LE (BOM or 0x00 bytes) → RepairLabVIEWUTF16LE (normalizes
// mixed UTF-8/UTF-16LE + lone spaces to clean UTF-16LE) → convert to UTF-8
extern "C" ANSULT_API int ANSConvertUTF16LEToUTF8_LV(LStrHandle input, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF16LEToUTF8_LV: input=%p, result=%p", (void*)input, (void*)result);
try {
if (!input || !result) return -1;
int byteLen = (*input)->cnt;
@@ -1097,6 +1207,7 @@ extern "C" ANSULT_API int ANSConvertUTF16LEToUTF8_LV(LStrHandle input, LStrHandl
// 1. Pure UTF-8 → convert UTF-8 to Unicode escapes (\uXXXX)
// 2. Contains UTF-16LE → RepairLabVIEWUTF16LE → convert to Unicode escapes
extern "C" ANSULT_API int ANSConvertUTF16LEToUnicodeEscapes_LV(LStrHandle input, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF16LEToUnicodeEscapes_LV: input=%p, result=%p", (void*)input, (void*)result);
try {
if (!input || !result) return -1;
int byteLen = (*input)->cnt;
@@ -1163,6 +1274,7 @@ extern "C" ANSULT_API int ANSConvertUTF16LEToUnicodeEscapes_LV(LStrHandle input,
}
extern "C" ANSULT_API int ANSConvertUnicodeEscapesToUTF8(const char* escapedStr, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUnicodeEscapesToUTF8: escapedStr len=%zu", escapedStr ? strlen(escapedStr) : 0);
try {
if (!escapedStr || !result) return -1;
int len = (int)strlen(escapedStr);
@@ -1180,6 +1292,7 @@ extern "C" ANSULT_API int ANSConvertUnicodeEscapesToUTF8(const char* escapedStr,
}
extern "C" ANSULT_API int ANSConvertUTF8ToUnicodeEscapes(const char* utf8Str, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF8ToUnicodeEscapes: utf8Str len=%zu", utf8Str ? strlen(utf8Str) : 0);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -1197,6 +1310,7 @@ extern "C" ANSULT_API int ANSConvertUTF8ToUnicodeEscapes(const char* utf8Str, LS
}
extern "C" ANSULT_API int ANSDoubleEscapeUnicode(const char* str, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSDoubleEscapeUnicode: str len=%zu", str ? strlen(str) : 0);
try {
if (!str || !result) return -1;
int len = (int)strlen(str);
@@ -1214,6 +1328,7 @@ extern "C" ANSULT_API int ANSDoubleEscapeUnicode(const char* str, LStrHandle res
}
extern "C" ANSULT_API int ANSConvertUTF8ToDoubleEscapedUnicode(const char* utf8Str, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSConvertUTF8ToDoubleEscapedUnicode: utf8Str len=%zu", utf8Str ? strlen(utf8Str) : 0);
try {
if (!utf8Str || !result) return -1;
int len = (int)strlen(utf8Str);
@@ -1231,6 +1346,7 @@ extern "C" ANSULT_API int ANSConvertUTF8ToDoubleEscapedUnicode(const char* utf8S
}
extern "C" ANSULT_API int ANSUnescapeDoubleEscapedUnicode(const char* str, LStrHandle result) {
ANS_DBG("ANSUTIL","ANSUnescapeDoubleEscapedUnicode: str len=%zu", str ? strlen(str) : 0);
try {
if (!str || !result) return -1;
int len = (int)strlen(str);
@@ -1266,7 +1382,7 @@ extern "C" ANSULT_API int ANSUnescapeDoubleEscapedUnicode(const char* str, LStrH
// 1 : success, *Handle now points to a new registered instance
// 0 : invalid arg, alloc failure, or Initialize() failed
extern "C" ANSULT_API int CreateANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* licenseKey) {
AWSDbg("[ANSAWS] Create called: HandlePtr=%p, *Handle(in)=%p (input ignored, always allocates new)\n",
ANS_DBG("ANSAWS", "Create called: HandlePtr=%p, *Handle(in)=%p (input ignored, always allocates new)",
(void*)Handle, Handle ? (void*)*Handle : nullptr);
if (Handle == nullptr || licenseKey == nullptr) return 0;
*Handle = nullptr;
@@ -1276,7 +1392,7 @@ extern "C" ANSULT_API int CreateANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, cons
if (*Handle == nullptr) return 0;
if ((*Handle)->Initialize(licenseKey)) {
RegisterAWSHandle(*Handle);
AWSDbg("[ANSAWS] Create OK: *Handle(out)=%p (uint=%llu) -- LabVIEW will see this number\n",
ANS_DBG("ANSAWS", "Create OK: *Handle(out)=%p (uint=%llu) -- LabVIEW will see this number",
(void*)*Handle, (unsigned long long)(uintptr_t)*Handle);
return 1;
}
@@ -1304,25 +1420,25 @@ extern "C" ANSULT_API int CreateANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, cons
static int ReleaseANSAWSHandle_Impl(ANSCENTER::ANSAWSS3** Handle) {
try {
if (!Handle || !*Handle) {
AWSDbg("[ANSAWS] Release: noop (Handle or *Handle was null)\n");
ANS_DBG("ANSAWS", "Release: noop (Handle or *Handle was null)");
return 1;
}
ANSCENTER::ANSAWSS3* h = *Handle;
AWSDbg("[ANSAWS] Release called: handle=%p (uint=%llu)\n",
ANS_DBG("ANSAWS", "Release called: handle=%p (uint=%llu)",
(void*)h, (unsigned long long)(uintptr_t)h);
if (!UnregisterAWSHandle(h)) {
AWSDbg("[ANSAWS] Release: handle %p not in registry, clearing wire only\n", (void*)h);
ANS_DBG("ANSAWS", "Release: handle %p not in registry, clearing wire only", (void*)h);
*Handle = nullptr;
return 1;
}
delete h;
*Handle = nullptr;
AWSDbg("[ANSAWS] Release OK: handle %p deleted, registry now has %zu entries\n",
ANS_DBG("ANSAWS", "Release OK: handle %p deleted, registry now has %zu entries",
(void*)h, AWSHandleRegistry().size());
return 1;
}
catch (...) {
AWSDbg("[ANSAWS] Release EXCEPTION: clearing wire and returning 0\n");
ANS_DBG("ANSAWS", "Release EXCEPTION: clearing wire and returning 0");
if (Handle) *Handle = nullptr;
return 0;
}
@@ -1333,25 +1449,25 @@ extern "C" ANSULT_API int ReleaseANSAWSHandle(ANSCENTER::ANSAWSS3** Handle) {
return ReleaseANSAWSHandle_Impl(Handle);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
AWSDbg("[ANSAWS] Release SEH EXCEPTION: clearing wire and returning 0\n");
ANS_DBG("ANSAWS", "Release SEH EXCEPTION: clearing wire and returning 0");
if (Handle) *Handle = nullptr;
return 0;
}
}
extern "C" ANSULT_API int ConnectANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* baseDomain, const char* bucketRegion, const char* serviceName, int port, int bTls, int autoReconnect, int* awsPath) {
AWSDbg("[ANSAWS] Connect called: *Handle=%p, baseDomain=%s, region=%s, service=%s, port=%d, tls=%d, autoReconnect=%d\n",
ANS_DBG("ANSAWS", "Connect called: *Handle=%p, baseDomain=%s, region=%s, service=%s, port=%d, tls=%d, autoReconnect=%d",
Handle ? (void*)*Handle : nullptr,
baseDomain ? baseDomain : "(null)",
bucketRegion ? bucketRegion : "(null)",
serviceName ? serviceName : "(null)",
port, bTls, autoReconnect);
if (Handle == nullptr || *Handle == nullptr || awsPath == nullptr) {
AWSDbg("[ANSAWS] Connect: returning 0 (null arg)\n");
ANS_DBG("ANSAWS", "Connect: returning 0 (null arg)");
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) {
AWSDbg("[ANSAWS] Connect: returning 0 (handle %p not in registry)\n", (void*)*Handle);
ANS_DBG("ANSAWS", "Connect: returning 0 (handle %p not in registry)", (void*)*Handle);
return 0;
}
try {
@@ -1360,73 +1476,73 @@ extern "C" ANSULT_API int ConnectANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, con
bool awsPathBool = true;
int result = guard.get()->Connect(baseDomain, bucketRegion, serviceName, port, bTlsBool, autoReconnectBool, awsPathBool);
*awsPath = awsPathBool ? 1 : 0;
AWSDbg("[ANSAWS] Connect result: %d (1=connected, 0=failed, 2=no internet) awsPath=%d\n", result, *awsPath);
ANS_DBG("ANSAWS", "Connect result: %d (1=connected, 0=failed, 2=no internet) awsPath=%d", result, *awsPath);
return result; // 1 = connected, 0 = failed, 2 = no internet (retrying)
}
catch (std::exception& e) {
AWSDbg("[ANSAWS] Connect EXCEPTION: %s\n", e.what());
ANS_DBG("ANSAWS", "Connect EXCEPTION: %s", e.what());
return 0;
}
catch (...) {
AWSDbg("[ANSAWS] Connect EXCEPTION: unknown\n");
ANS_DBG("ANSAWS", "Connect EXCEPTION: unknown");
return 0;
}
}
extern "C" ANSULT_API int SetProxyANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* proxyHost, int proxyPort, const char* proxyUsername, const char* proxyPassword) {
AWSDbg("[ANSAWS] SetProxy called: *Handle=%p, host=%s, port=%d, user=%s\n",
ANS_DBG("ANSAWS", "SetProxy called: *Handle=%p, host=%s, port=%d, user=%s",
Handle ? (void*)*Handle : nullptr,
proxyHost ? proxyHost : "(null)",
proxyPort,
proxyUsername ? proxyUsername : "(null)");
if (Handle == nullptr || *Handle == nullptr) {
AWSDbg("[ANSAWS] SetProxy: returning 0 (null arg)\n");
ANS_DBG("ANSAWS", "SetProxy: returning 0 (null arg)");
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) {
AWSDbg("[ANSAWS] SetProxy: returning 0 (handle %p not in registry)\n", (void*)*Handle);
ANS_DBG("ANSAWS", "SetProxy: returning 0 (handle %p not in registry)", (void*)*Handle);
return 0;
}
try {
if (guard.get()->SetServerProxy(proxyHost, proxyPort, proxyUsername, proxyPassword)) {
AWSDbg("[ANSAWS] SetProxy OK\n");
ANS_DBG("ANSAWS", "SetProxy OK");
return 1;
}
else {
AWSDbg("[ANSAWS] SetProxy FAILED (SetServerProxy returned false)\n");
ANS_DBG("ANSAWS", "SetProxy FAILED (SetServerProxy returned false)");
return 0;
}
}
catch (std::exception& e) {
AWSDbg("[ANSAWS] SetProxy EXCEPTION: %s\n", e.what());
ANS_DBG("ANSAWS", "SetProxy EXCEPTION: %s", e.what());
return 0;
}
catch (...) {
AWSDbg("[ANSAWS] SetProxy EXCEPTION: unknown\n");
ANS_DBG("ANSAWS", "SetProxy EXCEPTION: unknown");
return 0;
}
}
extern "C" ANSULT_API int SetAuthenticationANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* accessKey, const char* secretKey) {
AWSDbg("[ANSAWS] SetAuth called: *Handle=%p, accessKey=%.6s... (length-only secretKey=%zu)\n",
ANS_DBG("ANSAWS", "SetAuth called: *Handle=%p, accessKey=%.6s... (length-only secretKey=%zu)",
Handle ? (void*)*Handle : nullptr,
accessKey ? accessKey : "(null)",
secretKey ? strlen(secretKey) : 0);
if (Handle == nullptr || *Handle == nullptr ) {
AWSDbg("[ANSAWS] SetAuth: returning 0 (null arg)\n");
ANS_DBG("ANSAWS", "SetAuth: returning 0 (null arg)");
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) {
AWSDbg("[ANSAWS] SetAuth: returning 0 (handle %p not in registry)\n", (void*)*Handle);
ANS_DBG("ANSAWS", "SetAuth: returning 0 (handle %p not in registry)", (void*)*Handle);
return 0;
}
try {
if (guard.get()->SetAuthentication(accessKey, secretKey)) {
AWSDbg("[ANSAWS] SetAuth OK\n");
ANS_DBG("ANSAWS", "SetAuth OK");
return 1;
}
else {
AWSDbg("[ANSAWS] SetAuth FAILED (SetAuthentication returned false)\n");
ANS_DBG("ANSAWS", "SetAuth FAILED (SetAuthentication returned false)");
return 0;
}
}
@@ -1936,7 +2052,7 @@ extern "C" ANSULT_API int UploadJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3** Han
}
}
extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, LStrHandle uploadedFilePath) {
AWSDbg("[ANSAWS] Upload called: HandlePtr=%p, *Handle=%p (uint=%llu), bucket=%s, prefix=%s, file=%s, len=%d\n",
ANS_DBG("ANSAWS", "Upload called: HandlePtr=%p, *Handle=%p (uint=%llu), bucket=%s, prefix=%s, file=%s, len=%d",
(void*)Handle,
Handle ? (void*)*Handle : nullptr,
Handle && *Handle ? (unsigned long long)(uintptr_t)*Handle : 0ULL,
@@ -1949,12 +2065,12 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3
jpeg_string == nullptr || bufferLength <= 0 ||
fileName == nullptr)
{
AWSDbg("[ANSAWS] Upload: returning 0 (null/invalid arg)\n");
ANS_DBG("ANSAWS", "Upload: returning 0 (null/invalid arg)");
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) {
AWSDbg("[ANSAWS] Upload: returning -1 (handle %p not in registry)\n", (void*)*Handle);
ANS_DBG("ANSAWS", "Upload: returning -1 (handle %p not in registry)", (void*)*Handle);
return -1;
}
try {
@@ -1966,23 +2082,23 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3
(*uploadedFilePath)->cnt = size;
memcpy((*uploadedFilePath)->str, outPath.c_str(), size);
}
AWSDbg("[ANSAWS] Upload OK (1): file=%s -> %s\n",
ANS_DBG("ANSAWS", "Upload OK (1): file=%s -> %s",
fileName ? fileName : "(null)", outPath.c_str());
return 1;
}
else {
AWSDbg("[ANSAWS] Upload FAILED (-2): file=%s, UploadPrefixJpegImage returned false\n",
ANS_DBG("ANSAWS", "Upload FAILED (-2): file=%s, UploadPrefixJpegImage returned false",
fileName ? fileName : "(null)");
return -2;
}
}
catch (std::exception& e) {
AWSDbg("[ANSAWS] Upload EXCEPTION (-3): file=%s, what=%s\n",
ANS_DBG("ANSAWS", "Upload EXCEPTION (-3): file=%s, what=%s",
fileName ? fileName : "(null)", e.what());
return -3;
}
catch (...) {
AWSDbg("[ANSAWS] Upload EXCEPTION (-4): file=%s, unknown exception\n",
ANS_DBG("ANSAWS", "Upload EXCEPTION (-4): file=%s, unknown exception",
fileName ? fileName : "(null)");
return -4;
}
@@ -2112,6 +2228,7 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAW
// ── ANSUtilities V2 ──
extern "C" ANSULT_API int GetFCMAccessToken_V2(uint64_t handleVal, const char* privateKey, LStrHandle accessToken) {
ANS_DBG("ANSUTIL","GetFCMAccessToken_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (privateKey == nullptr || accessToken == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2134,6 +2251,8 @@ extern "C" ANSULT_API int GetFCMAccessToken_V2(uint64_t handleVal, const char* p
}
extern "C" ANSULT_API int CreateAWSSNSTopic_V2(uint64_t handleVal, const char* snsTopicName, LStrHandle arnTopic) {
ANS_DBG("ANSUTIL","CreateAWSSNSTopic_V2: handleVal=%llu, snsTopicName=%s",
(unsigned long long)handleVal, snsTopicName ? snsTopicName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (snsTopicName == nullptr || arnTopic == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2156,6 +2275,8 @@ extern "C" ANSULT_API int CreateAWSSNSTopic_V2(uint64_t handleVal, const char* s
}
extern "C" ANSULT_API int DeleteAWSSNSTopic_V2(uint64_t handleVal, const char* arnTopic) {
ANS_DBG("ANSUTIL","DeleteAWSSNSTopic_V2: handleVal=%llu, arnTopic=%s",
(unsigned long long)handleVal, arnTopic ? arnTopic : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (arnTopic == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2169,6 +2290,7 @@ extern "C" ANSULT_API int DeleteAWSSNSTopic_V2(uint64_t handleVal, const char* a
}
extern "C" ANSULT_API int ListASWTopics_V2(uint64_t handleVal, LStrHandle arnTopics) {
ANS_DBG("ANSUTIL","ListASWTopics_V2: handleVal=%llu", (unsigned long long)handleVal);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (arnTopics == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2191,6 +2313,10 @@ extern "C" ANSULT_API int ListASWTopics_V2(uint64_t handleVal, LStrHandle arnTop
}
extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopic_V2(uint64_t handleVal, const char* snsTopicName, const char* phoneNumber, LStrHandle subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeSMSPhoneNumberAWSSNSTopic_V2: handleVal=%llu, snsTopicName=%s, phoneNumber=%s",
(unsigned long long)handleVal,
snsTopicName ? snsTopicName : "(null)",
phoneNumber ? phoneNumber : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (snsTopicName == nullptr || phoneNumber == nullptr || subscribedARN == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2213,6 +2339,10 @@ extern "C" ANSULT_API int SubcribeSMSPhoneNumberAWSSNSTopic_V2(uint64_t handleVa
}
extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopic_V2(uint64_t handleVal, const char* snsTopicName, const char* emailAddress, LStrHandle subscribedARN) {
ANS_DBG("ANSUTIL","SubcribeEmailAddressAWSSNSTopic_V2: handleVal=%llu, snsTopicName=%s, emailAddress=%s",
(unsigned long long)handleVal,
snsTopicName ? snsTopicName : "(null)",
emailAddress ? emailAddress : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (snsTopicName == nullptr || emailAddress == nullptr || subscribedARN == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2235,6 +2365,10 @@ extern "C" ANSULT_API int SubcribeEmailAddressAWSSNSTopic_V2(uint64_t handleVal,
}
extern "C" ANSULT_API int SendMessageToAWSSNSTopic_V2(uint64_t handleVal, const char* snsTopicName, const char* subjectContent, const char* messageContent, LStrHandle messageId) {
ANS_DBG("ANSUTIL","SendMessageToAWSSNSTopic_V2: handleVal=%llu, snsTopicName=%s, subject=%s",
(unsigned long long)handleVal,
snsTopicName ? snsTopicName : "(null)",
subjectContent ? subjectContent : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (snsTopicName == nullptr || subjectContent == nullptr || messageContent == nullptr || messageId == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2257,6 +2391,9 @@ extern "C" ANSULT_API int SendMessageToAWSSNSTopic_V2(uint64_t handleVal, const
}
extern "C" ANSULT_API int SendMessageToPhoneNumber_V2(uint64_t handleVal, const char* phoneNumber, const char* messageContent, LStrHandle messageId) {
ANS_DBG("ANSUTIL","SendMessageToPhoneNumber_V2: handleVal=%llu, phoneNumber=%s",
(unsigned long long)handleVal,
phoneNumber ? phoneNumber : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (phoneNumber == nullptr || messageContent == nullptr || messageId == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2279,6 +2416,11 @@ extern "C" ANSULT_API int SendMessageToPhoneNumber_V2(uint64_t handleVal, const
}
extern "C" ANSULT_API int SetupServerProxy_V2(uint64_t handleVal, const char* hostName, int port, const char* userName, const char* passWord) {
ANS_DBG("ANSUTIL","SetupServerProxy_V2: handleVal=%llu, hostName=%s, port=%d, userName=%s",
(unsigned long long)handleVal,
hostName ? hostName : "(null)",
port,
userName ? userName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (hostName == nullptr || userName == nullptr || passWord == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2292,6 +2434,9 @@ extern "C" ANSULT_API int SetupServerProxy_V2(uint64_t handleVal, const char* ho
}
extern "C" ANSULT_API int AuthenticateGCS_V2(uint64_t handleVal, const char* jsonKeyString) {
ANS_DBG("ANSUTIL","AuthenticateGCS_V2: handleVal=%llu, jsonKey len=%zu",
(unsigned long long)handleVal,
jsonKeyString ? strlen(jsonKeyString) : 0);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (jsonKeyString == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2305,6 +2450,11 @@ extern "C" ANSULT_API int AuthenticateGCS_V2(uint64_t handleVal, const char* jso
}
extern "C" ANSULT_API int UploadMatToGCS_V2(uint64_t handleVal, const char* bucketName, const char* objectName, unsigned char* jpeg_string, int32 bufferLength) {
ANS_DBG("ANSUTIL","UploadMatToGCS_V2: handleVal=%llu, bucket=%s, object=%s, len=%d",
(unsigned long long)handleVal,
bucketName ? bucketName : "(null)",
objectName ? objectName : "(null)",
bufferLength);
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || objectName == nullptr || jpeg_string == nullptr || bufferLength <= 0) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));
@@ -2318,6 +2468,10 @@ extern "C" ANSULT_API int UploadMatToGCS_V2(uint64_t handleVal, const char* buck
}
extern "C" ANSULT_API int UploadImageToGCS_V2(uint64_t handleVal, const char* bucketName, const char* objectName, cv::Mat image) {
ANS_DBG("ANSUTIL","UploadImageToGCS_V2: handleVal=%llu, bucket=%s, object=%s",
(unsigned long long)handleVal,
bucketName ? bucketName : "(null)",
objectName ? objectName : "(null)");
auto* _v2h = reinterpret_cast<ANSCENTER::ANSUtilities*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || objectName == nullptr) return 0;
UtilHandleGuard guard(AcquireUtilHandle(_v2h));

View File

@@ -497,7 +497,7 @@ int ANSLPR_OD_Inferences_FileTest() {
ANSCENTER::ANSALPR* infHandle;
std::string licenseKey = "";
std::string modelZipFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSALPR\\ServerOptimised\\ANS_ALPR_v1.2_NVIDIAGeForceRTX4070LaptopGPU.zip";
std::string imageFilePath = "E:\\Programs\\DemoAssets\\Images\\ALPRTest\\WrongOrder\\1109.jpg";//20250912_213850.717.jpg; 20250912_213850.511.jpg;//20250912_213850.411.jpg;//20250912_213850.261.jpg(65H115912:0.73) cororect (20250912_213850.071.jpg: 65H115833)
std::string imageFilePath = "E:\\Programs\\DemoAssets\\Images\\864.jpg";//;"E:\\Programs\\DemoAssets\\Images\\ALPRTest\\WrongOrder\\1109.jpg";//20250912_213850.717.jpg; 20250912_213850.511.jpg;//20250912_213850.411.jpg;//20250912_213850.261.jpg(65H115912:0.73) cororect (20250912_213850.071.jpg: 65H115833)
std::string lpnResult;
int engineType = 1;
double detectionThreshold = 0.3;
@@ -3955,7 +3955,7 @@ int main()
SetConsoleCP(CP_UTF8);
#endif
// ANSLPR_OD_INDOInferences_FileTest();
//ANSLPR_OD_Inferences_FileTest();
ANSLPR_OD_Inferences_FileTest();
//ANSLPR_OD_VideoTest();
//ANSLPR_BigSize_VideoTest();
//ANSLPR_CPU_VideoTest();
@@ -3969,7 +3969,7 @@ int main()
// ANSLPR_MultiGPU_StressTest_FilePlayer();
//ANSLPR_OD_CPU_VideoTest();
//ALPR_OCR_Test();
ALPR_OCR_VideoTest();
//ALPR_OCR_VideoTest();
return 0;
}