Adding product name to DMI data class

This commit is contained in:
Chris M 2024-10-18 07:00:43 +11:00
parent 8565a3ddee
commit 2e199593e9
2 changed files with 43 additions and 22 deletions

View file

@ -26,27 +26,32 @@
\******************************************************************************************/
DMIInfo::DMIInfo()
{
mainboard = "";
manufacturer = "";
mainboard = readWMIQuery("SELECT * FROM Win32_BaseBoard", "Product");
manufacturer = readWMIQuery("SELECT * FROM Win32_BaseBoard", "Manufacturer");
product_name = readWMIQuery("SELECT * FROM Win32_ComputerSystem", "Model");
}
std::string DMIInfo::readWMIQuery(std::string query, std::string key)
{
HRESULT hres;
Wmi wmi;
// Query WMI for Win32_PnPSignedDriver entries with names matching "SMBUS" or "SM BUS"
// These devices may be browsed under Device Manager -> System Devices
std::vector<QueryObj> q_res_BaseBoard;
hres = wmi.query("SELECT * FROM Win32_BaseBoard", q_res_BaseBoard);
std::vector<QueryObj> q_result;
hres = wmi.query(query, q_result);
if (hres)
if(hres)
{
LOG_DEBUG("[DMI Info] Unable to read from %s", WMI);
return;
return "";
}
for (QueryObj &i : q_res_BaseBoard)
for(QueryObj &obj : q_result)
{
manufacturer = i["Manufacturer"].c_str();
mainboard = i["Product"].c_str();
return obj[key];
}
return "";
}
#else /* WIN32 */
@ -62,22 +67,24 @@ DMIInfo::DMIInfo()
\******************************************************************************************/
DMIInfo::DMIInfo()
{
mainboard = "";
manufacturer = "";
mainboard = readFilePath(SYSFS_MB_DMI "/board_vendor");
manufacturer = readFilePath(SYSFS_MB_DMI "/board_name");
product_name = readFilePath(SYSFS_PC_DMI "/product_name");
}
if ((access(SYSFSDMI "/board_vendor", R_OK)!=0) && (access(SYSFSDMI "/board_name", R_OK)!=0))
std::string DMIInfo::readFilePath(std::string path)
{
if(access(path.c_str(), R_OK)!=0)
{
LOG_DEBUG("[DMI Info] Unable to read from %s", SYSFSDMI);
return;
LOG_DEBUG("[DMI Info] Unable to read from %s", path);
return "";
}
std::string read_path;
std::ifstream mftr(SYSFSDMI "/board_vendor", std::ifstream::in);
getline(mftr, manufacturer);
mftr.close();
std::ifstream prdt(SYSFSDMI "/board_name", std::ifstream::in);
getline(prdt, mainboard);
prdt.close();
std::ifstream path_stream(path, std::ifstream::in);
getline(path_stream, read_path);
path_stream.close();
return read_path;
}
#endif /* WIN32 */
@ -95,3 +102,8 @@ std::string DMIInfo::getManufacturer()
{
return manufacturer;
}
std::string DMIInfo::getProductName()
{
return product_name;
}

View file

@ -21,7 +21,8 @@
#include <unistd.h> //Linux specific filesystem operation
#include <fstream>
#define SYSFSDMI "/sys/devices/virtual/dmi/id/" //Linux specific file path
#define SYSFS_MB_DMI "/sys/devices/virtual/dmi/id/" //Linux file path for Motherboard
#define SYSFS_PC_DMI "/sys/class/dmi/id/" //Linux file path for Product info
#endif
class DMIInfo
@ -30,9 +31,17 @@ public:
DMIInfo();
~DMIInfo();
#ifdef WIN32
std::string readWMIQuery(std::string query, std::string key);
#else
std::string readFilePath(std::string path);
#endif
std::string getMainboard();
std::string getManufacturer();
std::string getProductName();
private:
std::string mainboard;
std::string manufacturer;
std::string product_name;
};