mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
fixing stuff based on comments and feedback from Sam. willc reate template for some of the getters since its the same old
This commit is contained in:
parent
cadcb8b7c3
commit
8273e5b666
5 changed files with 86 additions and 62 deletions
|
@ -2466,8 +2466,8 @@ void Application::initializePlatform() {
|
|||
|
||||
//run the enumeration
|
||||
if (platform::enumerateProcessors()) {
|
||||
for (int i = 0; i < platform::getProcessorCount(); i++) {
|
||||
std::string myPlat = platform::getProcessor(0);
|
||||
for (int i = 0; i < platform::getNumProcessor(); i++) {
|
||||
platform::getProcessor(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,20 +16,24 @@ using namespace nlohmann;
|
|||
|
||||
bool WINInstance::enumerateProcessors() {
|
||||
|
||||
cpu cpu;
|
||||
|
||||
json cpu;
|
||||
|
||||
getCpuDetails(cpu);
|
||||
|
||||
cpu.numberOfCores = getNumLogicalCores();
|
||||
cpu["numCores"] = getNumLogicalCores();
|
||||
|
||||
_processors.push_back(cpu);
|
||||
|
||||
_memory.totalMb = getTotalSystemRamMb();
|
||||
json mem;
|
||||
mem["totalRam"] = getTotalSystemRam();
|
||||
|
||||
_memory.push_back(mem);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WINInstance::getCpuDetails(cpu &cpu) {
|
||||
void WINInstance::getCpuDetails(json &cpu) {
|
||||
int CPUInfo[4] = { -1 };
|
||||
unsigned nExIds;
|
||||
unsigned int i = 0;
|
||||
|
@ -53,41 +57,23 @@ void WINInstance::getCpuDetails(cpu &cpu) {
|
|||
}
|
||||
}
|
||||
|
||||
cpu.brand = CPUBrandString;
|
||||
cpu.model = CPUModelString;
|
||||
cpu.clockSpeed = CPUClockString;
|
||||
cpu["brand"] = CPUBrandString;
|
||||
cpu["model"] = CPUModelString;
|
||||
cpu["clockSpeed"] = CPUClockString;
|
||||
}
|
||||
|
||||
unsigned int WINInstance::getNumLogicalCores() {
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
int WINInstance::getTotalSystemRamMb() {
|
||||
int WINInstance::getTotalSystemRam() {
|
||||
MEMORYSTATUSEX statex;
|
||||
statex.dwLength = sizeof(statex);
|
||||
GlobalMemoryStatusEx(&statex);
|
||||
return statex.ullTotalPhys / 1024 / 1024;
|
||||
}
|
||||
|
||||
std::string WINInstance::getProcessor(int index) {
|
||||
|
||||
std::string result;
|
||||
if (index >= _processors.size())
|
||||
return result;
|
||||
|
||||
json j;
|
||||
to_Json(j, _processors.at(index));
|
||||
|
||||
//serialize this
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
void WINInstance::to_Json(json& result, const cpu& cpu) {
|
||||
|
||||
result["cpuBrand"] = cpu.brand;
|
||||
result["cpuModel"] = cpu.model;
|
||||
result["cpuClockSpeed"] = cpu.clockSpeed;
|
||||
result["cpuNumberOfCores"] = cpu.numberOfCores;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,13 +18,11 @@ namespace platform {
|
|||
|
||||
public:
|
||||
bool enumerateProcessors();
|
||||
std::string getProcessor(int index);
|
||||
|
||||
private:
|
||||
unsigned int getNumLogicalCores();
|
||||
void getCpuDetails(cpu& cpu);
|
||||
int getTotalSystemRamMb();
|
||||
void to_Json(nlohmann::json& result, const cpu& cpu);
|
||||
void getCpuDetails(nlohmann::json& cpu);
|
||||
int getTotalSystemRam();
|
||||
};
|
||||
|
||||
} // namespace platform
|
|
@ -6,7 +6,9 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -21,6 +23,9 @@
|
|||
#endif
|
||||
|
||||
using namespace platform;
|
||||
using namespace nlohmann;
|
||||
|
||||
Instance* _instance;
|
||||
|
||||
void platform::create() {
|
||||
|
||||
|
@ -30,18 +35,56 @@ void platform::create() {
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string platform::getProcessor(int index) {
|
||||
return _instance->getProcessor(index);
|
||||
json Instance::getProcessor(int index) {
|
||||
assert(index < _processor.size());
|
||||
|
||||
json result;
|
||||
if (index >= _processors.size())
|
||||
return result;
|
||||
|
||||
return _processors.at(index);
|
||||
}
|
||||
|
||||
|
||||
//These are ripe for template.. will work on that next
|
||||
json Instance::getSystemRam(int index) {
|
||||
|
||||
assert(index < _memory.size());
|
||||
|
||||
json result;
|
||||
if(index>= _memory.size())
|
||||
return result;
|
||||
|
||||
return _memory.at(index);
|
||||
}
|
||||
|
||||
json Instance::getGPU(int index) {
|
||||
assert(index < _gpu.size());
|
||||
|
||||
json result;
|
||||
if (index >= _gpu.size())
|
||||
return result;
|
||||
|
||||
return _gpu.at(index);
|
||||
}
|
||||
|
||||
|
||||
bool platform::enumerateProcessors() {
|
||||
return _instance->enumerateProcessors();
|
||||
}
|
||||
|
||||
int platform::getTotalSystemRamMb() {
|
||||
return _instance->getTotalSystemRamMb();
|
||||
json platform::getProcessor(int index) {
|
||||
return _instance->getProcessor(index);
|
||||
}
|
||||
|
||||
int platform::getProcessorCount() {
|
||||
return _instance->getProcessorCount();
|
||||
json platform::getSystemRam(int index) {
|
||||
return _instance->getSystemRam(index);
|
||||
}
|
||||
|
||||
int platform::getNumMemory() {
|
||||
return _instance->getNumMemory();
|
||||
}
|
||||
|
||||
int platform::getNumProcessor() {
|
||||
return _instance->getNumProcessor();
|
||||
}
|
|
@ -9,39 +9,36 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
namespace platform {
|
||||
|
||||
struct cpu {
|
||||
std::string brand;
|
||||
std::string model;
|
||||
int numberOfCores;
|
||||
std::string clockSpeed;
|
||||
};
|
||||
|
||||
struct memory {
|
||||
int totalMb;
|
||||
};
|
||||
|
||||
class Instance {
|
||||
public:
|
||||
std::string virtual getProcessor(int index) = 0;
|
||||
bool virtual enumerateProcessors() = 0;
|
||||
int virtual getTotalSystemRamMb() = 0;
|
||||
int getProcessorCount() {return _processors.size(); }
|
||||
|
||||
int getNumProcessor() { return _processors.size(); }
|
||||
nlohmann::json getProcessor(int index);
|
||||
|
||||
int getNumMemory() { return _memory.size(); }
|
||||
nlohmann::json getSystemRam(int index);
|
||||
|
||||
int getNumGPU() { return _gpu.size(); }
|
||||
nlohmann::json getGPU(int index);
|
||||
|
||||
|
||||
protected:
|
||||
std::vector<cpu> _processors;
|
||||
struct memory _memory;
|
||||
std::vector<nlohmann::json> _processors;
|
||||
std::vector<nlohmann::json> _memory;
|
||||
std::vector<nlohmann::json> _gpu;
|
||||
};
|
||||
|
||||
static Instance* _instance;
|
||||
|
||||
//Platform level functions
|
||||
void create();
|
||||
std::string getProcessor(int index);
|
||||
int getProcessorCount();
|
||||
|
||||
bool enumerateProcessors();
|
||||
int getTotalSystemRamMb();
|
||||
int getNumProcessor();
|
||||
nlohmann::json getProcessor(int index);
|
||||
int getNumMemory();
|
||||
nlohmann::json getSystemRam(int index);
|
||||
|
||||
} // namespace platform
|
Loading…
Reference in a new issue