Prevent OOM

This commit is contained in:
2026-06-18 05:55:31 +10:00
parent ebba70b9d9
commit b3436a61ee
44 changed files with 1797 additions and 66 deletions
+38 -6
View File
@@ -161,14 +161,40 @@ namespace ANSCENTER {
// Time is converted to the user's local timezone and formatted
// using LOCALE_USER_DEFAULT (matches Event Viewer's display).
//
// If `clearAfterRead` is true, calls EvtClearLog on the entire
// Application channel after reading. WARNING: this wipes every
// event from every source in the Application log, not just
// ANSLogger entries — there is no per-event delete API in
// Windows. Requires Administrator privileges; without elevation
// the clear silently fails (events are still returned).
// clearAfterRead=true behaviour:
// * Calls EvtClearLog on the entire Application channel after
// reading. WARNING: this wipes every event from every source
// in the Application log, not just ANSLogger entries — there
// is no per-event delete API in Windows.
// * REQUIRES THE CALLING PROCESS TO BE ELEVATED (run as
// Administrator). Without elevation, EvtClearLog returns
// ERROR_ACCESS_DENIED (Win32 error 5) and the events remain
// in the log. The read still succeeds either way.
// * Failures are reported on stderr in the form
// "[ANSUtilities] EvtClearLog(Application) FAILED, GetLastError=N"
// and via DebugView under the "EVTLOG" tag. The C++ return
// value does NOT signal clear success — capture stderr or
// check Event Viewer afterwards to confirm.
[[nodiscard]] static std::string GetANSLoggerErrorEvents(bool clearAfterRead = false);
// Same as GetANSLoggerErrorEvents but only returns events that
// have NOT been returned by a previous call from this user
// account. The highest EventRecordID seen is persisted to
// HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger
// (REG_QWORD) and used as a Windows XPath filter
// (EventRecordID > N) on the next call. No admin needed for the
// skip mechanism — only for the optional clearAfterRead.
//
// Channel-clear handling: if Windows resets the Application
// channel's RecordID counter (typical after EvtClearLog), this
// function detects that the channel's current max RecordID is
// less than the stored watermark and resets the watermark to 0
// so no newly-written events are accidentally skipped.
//
// To force a re-read of all events, delete the registry value
// above and call again.
[[nodiscard]] static std::string GetANSLoggerErrorEventsSinceLastCall(bool clearAfterRead = false);
// Scan the local network for AIBOX / ANSVIS servers.
// Runs two strategies in parallel and merges results by IP:
// 1) UDP multicast probe to 230.50.200.150:58839 (with subnet
@@ -398,6 +424,12 @@ extern "C" ANSULT_API int ScanANSDevicesCpp(int timeoutMs, std::string& resultJ
extern "C" ANSULT_API int GetANSLoggerErrorEvents(int clearAfterRead, LStrHandle result);
extern "C" ANSULT_API int GetANSLoggerErrorEventsCpp(int clearAfterRead, std::string& result);
// Watermarked variant: only returns events not seen by previous calls.
// Watermark is stored in HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger
// (REG_QWORD). No admin needed for the skip; only for clearAfterRead.
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCall(int clearAfterRead, LStrHandle result);
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCallCpp(int clearAfterRead, std::string& result);
// Unicode conversion utilities for LabVIEW
extern "C" ANSULT_API int ANSConvertUTF8ToUTF16LE(const char* utf8Str, LStrHandle result, int includeBOM = 1);
extern "C" ANSULT_API int ANSDecodeJsonUnicodeToUTF16LE(const char* escapedStr, LStrHandle result);