Fix other ANSCV classes
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
#include "pch.h"
|
||||
#include "ANSLicense.h"
|
||||
#include "Utility.h"
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
@@ -369,6 +373,137 @@ extern "C" __declspec(dllexport) int GetSystemHardwareInformation(LStrHandle sys
|
||||
}
|
||||
}
|
||||
|
||||
// SystemHealthParameters cluster, decomposed into individual scalar outputs so
|
||||
// LabVIEW can wire each indicator straight to a Call Library Function Node.
|
||||
// Any pointer may be nullptr (LabVIEW will pass nullptr for cluster fields the
|
||||
// caller hasn't bound). cpuModel is optional but recommended; pass an LStrHandle
|
||||
// or nullptr to skip. Returns 1 on success, 0 on hard failure.
|
||||
extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
||||
double* cpuLoadPercent,
|
||||
double* cpuTempDegC,
|
||||
double* cpuFreqGHz,
|
||||
LStrHandle cpuModel,
|
||||
double* memTotalGB,
|
||||
double* rssPercent,
|
||||
double* swapPercent,
|
||||
double* gpuLoadPercent,
|
||||
int64_t* valIRSS_MB,
|
||||
int64_t* valSwap_MB,
|
||||
int64_t* valIGPU_MB,
|
||||
double* memoryUsedGB,
|
||||
double* memoryFreeGB,
|
||||
double* diskLoadPercent,
|
||||
double* diskReadSpeedMBs,
|
||||
double* diskWriteSpeedMBs,
|
||||
double* diskUsedGB,
|
||||
double* diskTotalGB,
|
||||
double* netLoadPercent,
|
||||
double* netReceiveSpeedMBs,
|
||||
double* netSendSpeedMBs,
|
||||
LStrHandle gpuName,
|
||||
LStrHandle gpuAdaptersDetail)
|
||||
{
|
||||
try {
|
||||
const ANSCENTER::SystemHealthInfo info =
|
||||
ANSCENTER::ANSLicenseHelper::GetSystemHealthInformation();
|
||||
|
||||
auto writeLStr = [](LStrHandle handle, const std::string& s) {
|
||||
if (!handle) return;
|
||||
const int size = static_cast<int>(s.length());
|
||||
const MgErr err = DSSetHandleSize(handle, sizeof(int32) + size * sizeof(uChar));
|
||||
if (err == noErr) {
|
||||
(*handle)->cnt = size;
|
||||
if (size > 0) memcpy((*handle)->str, s.c_str(), size);
|
||||
}
|
||||
};
|
||||
|
||||
if (cpuLoadPercent) *cpuLoadPercent = info.cpuLoadPercent;
|
||||
if (cpuTempDegC) *cpuTempDegC = info.cpuTempDegC;
|
||||
if (cpuFreqGHz) *cpuFreqGHz = info.cpuFreqGHz;
|
||||
if (memTotalGB) *memTotalGB = info.memTotalGB;
|
||||
if (rssPercent) *rssPercent = info.rssPercent;
|
||||
if (swapPercent) *swapPercent = info.swapPercent;
|
||||
if (gpuLoadPercent) *gpuLoadPercent = info.gpuLoadPercent;
|
||||
if (valIRSS_MB) *valIRSS_MB = info.valIRSS_MB;
|
||||
if (valSwap_MB) *valSwap_MB = info.valSwap_MB;
|
||||
if (valIGPU_MB) *valIGPU_MB = info.valIGPU_MB;
|
||||
if (memoryUsedGB) *memoryUsedGB = info.memoryUsedGB;
|
||||
if (memoryFreeGB) *memoryFreeGB = info.memoryFreeGB;
|
||||
if (diskLoadPercent) *diskLoadPercent = info.diskLoadPercent;
|
||||
if (diskReadSpeedMBs) *diskReadSpeedMBs = info.diskReadSpeedMBs;
|
||||
if (diskWriteSpeedMBs) *diskWriteSpeedMBs = info.diskWriteSpeedMBs;
|
||||
if (diskUsedGB) *diskUsedGB = info.diskUsedGB;
|
||||
if (diskTotalGB) *diskTotalGB = info.diskTotalGB;
|
||||
if (netLoadPercent) *netLoadPercent = info.netLoadPercent;
|
||||
if (netReceiveSpeedMBs) *netReceiveSpeedMBs = info.netReceiveSpeedMBs;
|
||||
if (netSendSpeedMBs) *netSendSpeedMBs = info.netSendSpeedMBs;
|
||||
|
||||
writeLStr(cpuModel, info.cpuModel);
|
||||
writeLStr(gpuName, info.gpuName);
|
||||
writeLStr(gpuAdaptersDetail, info.gpuAdaptersDetail);
|
||||
return 1;
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int GetSystemHealthParametersString(LStrHandle outString) {
|
||||
try {
|
||||
if (!outString) return 0;
|
||||
|
||||
const ANSCENTER::SystemHealthInfo info =
|
||||
ANSCENTER::ANSLicenseHelper::GetSystemHealthInformation();
|
||||
|
||||
// Keep ';' as a clean separator: rewrite any literal ';' inside any
|
||||
// free-form string field (rare, but vendor strings aren't safe by
|
||||
// contract).
|
||||
auto sanitize = [](std::string s) {
|
||||
std::replace(s.begin(), s.end(), ';', ',');
|
||||
return s;
|
||||
};
|
||||
const std::string model = sanitize(info.cpuModel);
|
||||
const std::string gpuName_ = sanitize(info.gpuName);
|
||||
const std::string gpuDetail = sanitize(info.gpuAdaptersDetail);
|
||||
|
||||
std::ostringstream os;
|
||||
os.imbue(std::locale::classic()); // force '.' decimal regardless of system locale
|
||||
os << std::fixed << std::setprecision(2);
|
||||
os << info.cpuLoadPercent << ';'
|
||||
<< info.cpuTempDegC << ';'
|
||||
<< info.cpuFreqGHz << ';'
|
||||
<< model << ';'
|
||||
<< info.memTotalGB << ';'
|
||||
<< info.rssPercent << ';'
|
||||
<< info.swapPercent << ';'
|
||||
<< info.gpuLoadPercent << ';'
|
||||
<< info.valIRSS_MB << ';'
|
||||
<< info.valSwap_MB << ';'
|
||||
<< info.valIGPU_MB << ';'
|
||||
<< info.memoryUsedGB << ';'
|
||||
<< info.memoryFreeGB << ';'
|
||||
<< info.diskLoadPercent << ';'
|
||||
<< info.diskReadSpeedMBs << ';'
|
||||
<< info.diskWriteSpeedMBs << ';'
|
||||
<< info.diskUsedGB << ';'
|
||||
<< info.diskTotalGB << ';'
|
||||
<< info.netLoadPercent << ';'
|
||||
<< info.netReceiveSpeedMBs << ';'
|
||||
<< info.netSendSpeedMBs << ';'
|
||||
<< gpuName_ << ';'
|
||||
<< gpuDetail;
|
||||
|
||||
const std::string s = os.str();
|
||||
const int size = static_cast<int>(s.length());
|
||||
const MgErr err = DSSetHandleSize(outString, sizeof(int32) + size * sizeof(uChar));
|
||||
if (err != noErr) return 0;
|
||||
(*outString)->cnt = size;
|
||||
if (size > 0) memcpy((*outString)->str, s.c_str(), size);
|
||||
return 1;
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ReleaseLoggers() {
|
||||
try {
|
||||
bool result = ANSCENTER::ANSLSHelper::ReleaseLogger();
|
||||
|
||||
Reference in New Issue
Block a user