From 8273e5b666def4389ce75a52a5de857ac693a988 Mon Sep 17 00:00:00 2001 From: amer cerkic Date: Mon, 6 May 2019 12:27:46 -0700 Subject: [PATCH] fixing stuff based on comments and feedback from Sam. willc reate template for some of the getters since its the same old --- interface/src/Application.cpp | 4 +- libraries/platform/src/WINPlatform.cpp | 42 +++++++------------- libraries/platform/src/WINPlatform.h | 6 +-- libraries/platform/src/platform.cpp | 55 +++++++++++++++++++++++--- libraries/platform/src/platform.h | 41 +++++++++---------- 5 files changed, 86 insertions(+), 62 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b5970fad49..6e3711d60a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -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); } } } diff --git a/libraries/platform/src/WINPlatform.cpp b/libraries/platform/src/WINPlatform.cpp index d1fa0c0d25..c335e3745e 100644 --- a/libraries/platform/src/WINPlatform.cpp +++ b/libraries/platform/src/WINPlatform.cpp @@ -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; -} + + diff --git a/libraries/platform/src/WINPlatform.h b/libraries/platform/src/WINPlatform.h index 9fbdcd6da4..f03fb2c95a 100644 --- a/libraries/platform/src/WINPlatform.h +++ b/libraries/platform/src/WINPlatform.h @@ -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 \ No newline at end of file diff --git a/libraries/platform/src/platform.cpp b/libraries/platform/src/platform.cpp index c581387909..5ab2e7fbc2 100644 --- a/libraries/platform/src/platform.cpp +++ b/libraries/platform/src/platform.cpp @@ -6,7 +6,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + #include "platform.h" + #include #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(); } \ No newline at end of file diff --git a/libraries/platform/src/platform.h b/libraries/platform/src/platform.h index 2d1c29a187..3dfb2f2b14 100644 --- a/libraries/platform/src/platform.h +++ b/libraries/platform/src/platform.h @@ -9,39 +9,36 @@ #pragma once #include #include - +#include 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 _processors; - struct memory _memory; + std::vector _processors; + std::vector _memory; + std::vector _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 \ No newline at end of file