p26001-store-acs-soc-fw-app/util/SystemInfo.h
2026-09-28 21:33:04 +08:00

140 lines
4.7 KiB
C++

#ifndef C42159C1_B275_444E_86D0_9A26B781F354
#define C42159C1_B275_444E_86D0_9A26B781F354
/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include <Poco/Net/IPAddress.h>
#include <Poco/Net/NetworkInterface.h>
#include <stdint.h>
#include <ctime>
#include "util/xpack/json.h"
namespace Util
{
/*
*******************************************************************************
* CLASS DECLARE
*******************************************************************************
*/
class SystemInfo
{
public:
struct MemoryInfo
{
uint32_t total;
uint32_t free;
uint32_t usage;
uint32_t available;
};
struct StorageInfo
{
std::string type = "";
int status = 0;
std::string device = "";
std::string path = "";
unsigned long long total = 0;
unsigned long long used = 0;
unsigned long long available = 0;
unsigned long long free = 0;
StorageInfo() = default;
XPACK(O(type, status, device, path, total, used, available, free));
};
struct FileInfo
{
std::string name;
std::string parentPath = "";
int type;
off_t size;
time_t lastModifyTime;
XPACK(O(name, parentPath, type, size, lastModifyTime));
};
struct NetworkInterfaceInfo
{
std::string name;
std::string displayName;
std::string ipAddress = "0.0.0.0";
std::string subnetMask = "0.0.0.0";
std::string broadcastAddress;
std::string gateway = "0.0.0.0";
std::string macAddress;
bool isUp;
bool isInitialized;
NetworkInterfaceInfo() = default;
XPACK(O(name, displayName, ipAddress, subnetMask, broadcastAddress, gateway, macAddress, isUp));
};
public:
static unsigned cpuUsage();
static MemoryInfo readMemoryInfo();
static std::map<std::string, Util::SystemInfo::StorageInfo> getStorageInfo(bool returnSpace = true);
static std::vector<std::string> getBlockDevices();
static std::vector<Util::SystemInfo::FileInfo> getFileInfoList(std::string parentPath);
static unsigned long long getPathFreeSpace(const std::string& path);
static unsigned long long checkSizeAndDelEarliestFile(const std::string& basePath, const unsigned int limitMB,
const std::string deletePath,
const std::string& deleteExtName,
const std::set<std::string> exculdePathOrFiles);
static bool mountPointEnable(const std::string& localPath);
static bool mountCifs(std::string ip, std::string remotePath, std::string localPath, std::string username,
std::string password, std::string vers = "2.0", std::string charset = "");
static bool mountNfs(std::string ip, std::string remotePath, std::string localPath, std::string vers = "4");
static bool umount(std::string localPath);
static int getProcessPID(const std::string& processName);
static std::vector<std::string> getNetworkInterfaceNames();
static NetworkInterfaceInfo getNetWorkInterfaceInfo(const std::string& interfaceName, bool returnGateway = false);
static bool netInterfaceIsExist(const std::string& interfaceName);
static bool netInterfaceIsAvailable(const std::string& interfaceName);
static Poco::Net::IPAddress localAddress(const std::string& interfaceName);
static std::map<std::string, Poco::Net::IPAddress> localAddresses();
static std::vector<std::string> localAddressesList();
static std::string localAddressOfAvailable();
static std::string getFirstWirelessInterfaceName();
static Poco::Net::IPAddress subnetMask(const std::string& interfaceName);
static Poco::Net::NetworkInterface::MACAddress macAddress(const std::string& interfaceName);
static Poco::Net::NetworkInterface::MACAddress getFirstMacAddress();
static Poco::Net::IPAddress gatewayAddress(const std::string& interfaceName);
static bool executeCommand(const std::string& command)
{
return executeCommand(command, 0);
}
static bool executeCommand(const std::string& command, int timeout_sec)
{
std::string output;
return executeCommand(command, timeout_sec, output);
}
static bool executeCommand(const std::string& command, int timeout_sec, std::string& output);
};
}
#endif