mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 15:34:05 +02:00
add network card info to platform data
This commit is contained in:
parent
b95586239a
commit
0db69ecc20
7 changed files with 68 additions and 1 deletions
|
@ -12,4 +12,7 @@ if (APPLE)
|
|||
find_library(AppKit AppKit)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} ${OpenGL} ${AppKit})
|
||||
endif ()
|
||||
|
||||
elseif(WIN32)
|
||||
target_link_libraries(${TARGET_NAME} Iphlpapi.lib)
|
||||
endif ()
|
|
@ -31,6 +31,10 @@ namespace platform { namespace keys{
|
|||
extern const char* videoMemory;
|
||||
extern const char* driver;
|
||||
}
|
||||
namespace nic {
|
||||
extern const char* mac;
|
||||
extern const char* name;
|
||||
}
|
||||
namespace display {
|
||||
extern const char* description;
|
||||
extern const char* name;
|
||||
|
@ -63,6 +67,7 @@ namespace platform { namespace keys{
|
|||
extern const char* CPUS;
|
||||
extern const char* GPUS;
|
||||
extern const char* DISPLAYS;
|
||||
extern const char* NICS;
|
||||
extern const char* MEMORY;
|
||||
extern const char* COMPUTER;
|
||||
|
||||
|
|
|
@ -32,6 +32,10 @@ namespace platform { namespace keys {
|
|||
const char* videoMemory = "videoMemory";
|
||||
const char* driver = "driver";
|
||||
}
|
||||
namespace nic {
|
||||
const char* mac = "mac";
|
||||
const char* name = "name";
|
||||
}
|
||||
namespace display {
|
||||
const char* description = "description";
|
||||
const char* name = "deviceName";
|
||||
|
@ -63,6 +67,7 @@ namespace platform { namespace keys {
|
|||
const char* CPUS = "cpus";
|
||||
const char* GPUS = "gpus";
|
||||
const char* DISPLAYS = "displays";
|
||||
const char* NICS = "nics";
|
||||
const char* MEMORY = "memory";
|
||||
const char* COMPUTER = "computer";
|
||||
}}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
|
||||
#include "PlatformInstance.h"
|
||||
#include <QNetworkInterface>
|
||||
|
||||
#include "../PlatformKeys.h"
|
||||
#include "../Profiler.h"
|
||||
|
@ -20,12 +21,24 @@ bool Instance::enumeratePlatform() {
|
|||
enumerateCpus();
|
||||
enumerateGpus();
|
||||
enumerateDisplays();
|
||||
enumerateNics();
|
||||
|
||||
// And profile the platform and put the tier in "computer"
|
||||
_computer[keys::computer::profileTier] = Profiler::TierNames[Profiler::profilePlatform()];
|
||||
|
||||
return true;
|
||||
}
|
||||
void Instance::enumerateNics() {
|
||||
QNetworkInterface interface;
|
||||
foreach(interface, interface.allInterfaces()) {
|
||||
if (interface.flags().testFlag(QNetworkInterface::IsRunning) && !interface.hardwareAddress().isEmpty()) {
|
||||
json nic = {};
|
||||
nic[keys::nic::mac] = interface.hardwareAddress().toUtf8().constData();
|
||||
nic[keys::nic::name] = interface.humanReadableName().toUtf8().constData();
|
||||
_nics.push_back(nic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json Instance::getCPU(int index) {
|
||||
assert(index <(int) _cpus.size());
|
||||
|
@ -140,6 +153,7 @@ json Instance::getAll() {
|
|||
all[keys::CPUS] = _cpus;
|
||||
all[keys::GPUS] = _gpus;
|
||||
all[keys::DISPLAYS] = _displays;
|
||||
all[keys::NICS] = _nics;
|
||||
|
||||
return all;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
void virtual enumerateCpus()=0;
|
||||
void virtual enumerateGpus()=0;
|
||||
void virtual enumerateDisplays() {}
|
||||
void virtual enumerateNics();
|
||||
void virtual enumerateMemory() = 0;
|
||||
void virtual enumerateComputer()=0;
|
||||
|
||||
|
@ -51,6 +52,7 @@ protected:
|
|||
std::vector<json> _cpus;
|
||||
std::vector<json> _gpus;
|
||||
std::vector<json> _displays;
|
||||
std::vector<json> _nics;
|
||||
json _memory;
|
||||
json _computer;
|
||||
};
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <Windows.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <stdio.h>
|
||||
#include <QSysInfo>
|
||||
#endif
|
||||
|
||||
|
@ -68,3 +70,38 @@ void WINInstance::enumerateComputer(){
|
|||
_computer[keys::computer::OSVersion] = sysInfo.kernelVersion().toStdString();
|
||||
}
|
||||
|
||||
void WINInstance::enumerateNics() {
|
||||
// Start with the default from QT, getting the result into _nics:
|
||||
Instance::enumerateNics();
|
||||
|
||||
// We can usually do better than the QNetworkInterface::humanReadableName() by
|
||||
// matching up Iphlpapi.lib IP_ADAPTER_INFO by mac id.
|
||||
ULONG buflen = sizeof(IP_ADAPTER_INFO);
|
||||
IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(buflen);
|
||||
|
||||
// Size the buffer:
|
||||
if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) {
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(buflen);
|
||||
}
|
||||
|
||||
// Now get the data...
|
||||
if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) {
|
||||
for (json& nic : _nics) { // ... loop through the nics from above...
|
||||
// ...convert the json to a string without the colons...
|
||||
QString qtmac = nic[keys::nic::mac].get<std::string>().c_str();
|
||||
QString qtraw = qtmac.remove(QChar(':'), Qt::CaseInsensitive).toLower();
|
||||
// ... and find the matching on in pAdapter:
|
||||
for (IP_ADAPTER_INFO *pAdapter = pAdapterInfo; pAdapter; pAdapter = pAdapter->Next) {
|
||||
QByteArray wmac = QByteArray((const char *)(pAdapter->Address), pAdapter->AddressLength);
|
||||
QString wraw = wmac.toHex();
|
||||
if (qtraw == wraw) {
|
||||
nic[keys::nic::name] = pAdapter->Description;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pAdapterInfo) free(pAdapterInfo);
|
||||
}
|
|
@ -19,6 +19,7 @@ namespace platform {
|
|||
void enumerateGpus() override;
|
||||
void enumerateMemory() override;
|
||||
void enumerateComputer () override;
|
||||
void enumerateNics();
|
||||
};
|
||||
} // namespace platform
|
||||
|
||||
|
|
Loading…
Reference in a new issue