cleaned up pointers from the platform. Relized that having to manage them outisde of the platform will cause other issues.

This commit is contained in:
amerhifi 2019-05-13 06:50:08 -07:00
parent d019dc7d54
commit 13c9bb078c
7 changed files with 69 additions and 76 deletions

View file

@ -2495,9 +2495,9 @@ void Application::initPlatform() {
platform::enumeratePlatform(); platform::enumeratePlatform();
const nlohmann::json* test = platform::getGraphics(0); const nlohmann::json test = platform::getGraphics(0);
const nlohmann::json* test1 = platform::getProcessor(0); const nlohmann::json test1 = platform::getProcessor(0);
const nlohmann::json* test2 = platform::getMemory(0); const nlohmann::json test2 = platform::getMemory(0);
//const nlohmann::json* test3 = platform::getDisplay(0); //const nlohmann::json* test3 = platform::getDisplay(0);
} }

View file

@ -11,8 +11,11 @@
#include <thread> #include <thread>
#include <GPUIdent.h> #include <GPUIdent.h>
#include <string> #include <string>
#ifdef Q_MAC_OS
#include <unistd.h> #include <unistd.h>
#include <cpuid.h> #include <cpuid.h>
#endif
using namespace platform; using namespace platform;
@ -25,18 +28,20 @@ bool MACOSInstance::enumeratePlatform() {
static void getCpuId( uint32_t* p, uint32_t ax ) static void getCpuId( uint32_t* p, uint32_t ax )
{ {
#ifdef Q_OS_MAC
__asm __volatile __asm __volatile
( "movl %%ebx, %%esi\n\t" ( "movl %%ebx, %%esi\n\t"
"cpuid\n\t" "cpuid\n\t"
"xchgl %%ebx, %%esi" "xchgl %%ebx, %%esi"
: "=a" (p[0]), "=S" (p[1]), : "=a" (p[0]), "=S" (p[1]),
"=c" (p[2]), "=d" (p[3]) "=c" (p[2]), "=d" (p[3])
: "0" (ax) : "0" (ax)
); );
#endif
} }
void MACOSInstance::enumerateCpu() { void MACOSInstance::enumerateCpu() {
json *cpu= new json(); json cpu = {};
uint32_t cpuInfo[4]={0,0,0,0}; uint32_t cpuInfo[4]={0,0,0,0};
char CPUBrandString[16]; char CPUBrandString[16];
char CPUModelString[16]; char CPUModelString[16];
@ -57,10 +62,10 @@ void MACOSInstance::enumerateCpu() {
} }
} }
(*cpu)["brand"] = CPUBrandString; cpu["brand"] = CPUBrandString;
(*cpu)["model"] = CPUModelString; cpu["model"] = CPUModelString;
(*cpu)["clockSpeed"] = CPUClockString; cpu["clockSpeed"] = CPUClockString;
(*cpu)["numCores"] = getNumLogicalCores(); cpu["numCores"] = getNumLogicalCores();
_cpu.push_back(cpu); _cpu.push_back(cpu);
} }
@ -73,21 +78,22 @@ void MACOSInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance(); GPUIdent* ident = GPUIdent::getInstance();
json *gpu = new json(); json gpu = {};
(*gpu)["name"] = ident->getName().toUtf8().constData(); gpu["name"] = ident->getName().toUtf8().constData();
(*gpu)["memory"] = ident->getMemory(); gpu["memory"] = ident->getMemory();
(*gpu)["driver"] = ident->getDriver().toUtf8().constData(); gpu["driver"] = ident->getDriver().toUtf8().constData();
_gpu.push_back(gpu); _gpu.push_back(gpu);
_display = ident->getOutput(); _display = ident->getOutput();
} }
void MACOSInstance::enumerateRam() { void MACOSInstance::enumerateRam() {
json* ram = new json(); json ram = {};
long pages = sysconf(_SC_PHYS_PAGES); #ifdef Q_OS_MAC
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE); long page_size = sysconf(_SC_PAGE_SIZE);
(*ram)["totalMem"] = pages * page_size;; ram["totalMem"] = pages * page_size;;
#endif
_memory.push_back(ram); _memory.push_back(ram);
} }

View file

@ -28,7 +28,7 @@ bool WINInstance::enumeratePlatform() {
} }
void WINInstance::enumerateCpu() { void WINInstance::enumerateCpu() {
json *cpu= new json(); json cpu = {};
int CPUInfo[4] = { -1 }; int CPUInfo[4] = { -1 };
unsigned nExIds; unsigned nExIds;
unsigned int i = 0; unsigned int i = 0;
@ -53,10 +53,10 @@ void WINInstance::enumerateCpu() {
} }
} }
(*cpu)["brand"] = CPUBrandString; cpu["brand"] = CPUBrandString;
(*cpu)["model"] = CPUModelString; cpu["model"] = CPUModelString;
(*cpu)["clockSpeed"] = CPUClockString; cpu["clockSpeed"] = CPUClockString;
(*cpu)["numCores"] = getNumLogicalCores(); cpu["numCores"] = getNumLogicalCores();
#endif #endif
_cpu.push_back(cpu); _cpu.push_back(cpu);
} }
@ -69,23 +69,23 @@ void WINInstance::enumerateGpu() {
GPUIdent* ident = GPUIdent::getInstance(); GPUIdent* ident = GPUIdent::getInstance();
json *gpu = new json(); json gpu = {};
(*gpu)["name"] = ident->getName().toUtf8().constData(); gpu["name"] = ident->getName().toUtf8().constData();
(*gpu)["memory"] = ident->getMemory(); gpu["memory"] = ident->getMemory();
(*gpu)["driver"] = ident->getDriver().toUtf8().constData(); gpu["driver"] = ident->getDriver().toUtf8().constData();
_gpu.push_back(gpu); _gpu.push_back(gpu);
_display = ident->getOutput(); _display = ident->getOutput();
} }
void WINInstance::enumerateRam() { void WINInstance::enumerateRam() {
json* ram = new json(); json ram = {};
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
MEMORYSTATUSEX statex; MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex); statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex); GlobalMemoryStatusEx(&statex);
int totalRam = statex.ullTotalPhys / 1024 / 1024; int totalRam = statex.ullTotalPhys / 1024 / 1024;
(*ram)["totalMem"] = totalRam; ram["totalMem"] = totalRam;
#endif #endif
_memory.push_back(ram); _memory.push_back(ram);
} }

View file

@ -24,7 +24,7 @@
using namespace platform; using namespace platform;
Instance* _instance; Instance *_instance;
void platform::create() { void platform::create() {
@ -42,37 +42,37 @@ void platform::destroy() {
delete _instance; delete _instance;
} }
json* Instance::getCPU(int index) { json Instance::getCPU(int index) {
assert(index <(int) _cpu.size()); assert(index <(int) _cpu.size());
if (index >= (int)_cpu.size()) if (index >= (int)_cpu.size())
return nullptr; return NULL;
return _cpu.at(index); return _cpu.at(index);
} }
//These are ripe for template.. will work on that next //These are ripe for template.. will work on that next
json* Instance::getMemory(int index) { json Instance::getMemory(int index) {
assert(index <(int) _memory.size()); assert(index <(int) _memory.size());
if(index >= (int)_memory.size()) if(index >= (int)_memory.size())
return nullptr; return NULL;
return _memory.at(index); return _memory.at(index);
} }
json* Instance::getGPU(int index) { json Instance::getGPU(int index) {
assert(index <(int) _gpu.size()); assert(index <(int) _gpu.size());
if (index >=(int) _gpu.size()) if (index >=(int) _gpu.size())
return nullptr; return NULL;
return _gpu.at(index); return _gpu.at(index);
} }
json* Instance::getDisplay(int index) { json Instance::getDisplay(int index) {
assert(index <(int) _display.size()); assert(index <(int) _display.size());
if (index >=(int) _display.size()) if (index >=(int) _display.size())
return nullptr; return NULL;
return _display.at(index); return _display.at(index);
} }
@ -80,31 +80,19 @@ json* Instance::getDisplay(int index) {
Instance::~Instance() { Instance::~Instance() {
if (_cpu.size() > 0) { if (_cpu.size() > 0) {
for (std::vector<json*>::iterator it = _cpu.begin(); it != _cpu.end(); ++it) {
delete (*it);
}
_cpu.clear(); _cpu.clear();
} }
if (_memory.size() > 0) { if (_memory.size() > 0) {
for (std::vector<json*>::iterator it = _memory.begin(); it != _memory.end(); ++it) {
delete (*it);
}
_memory.clear(); _memory.clear();
} }
if (_gpu.size() > 0) { if (_gpu.size() > 0) {
for (std::vector<json*>::iterator it = _gpu.begin(); it != _gpu.end(); ++it) {
delete (*it);
}
_gpu.clear(); _gpu.clear();
} }
if (_display.size() > 0) { if (_display.size() > 0) {
for (std::vector<json*>::iterator it = _display.begin(); it != _display.end(); ++it) {
delete (*it);
}
_display.clear(); _display.clear();
} }
} }
@ -117,7 +105,7 @@ int platform::getNumProcessor() {
return _instance->getNumCPU(); return _instance->getNumCPU();
} }
const json* platform::getProcessor(int index) { json platform::getProcessor(int index) {
return _instance->getCPU(index); return _instance->getCPU(index);
} }
@ -125,7 +113,7 @@ int platform::getNumGraphics() {
return _instance->getNumGPU(); return _instance->getNumGPU();
} }
const json* platform::getGraphics(int index) { json platform::getGraphics(int index) {
return _instance->getGPU(index); return _instance->getGPU(index);
} }
@ -133,7 +121,7 @@ int platform::getNumDisplay() {
return _instance->getNumDisplay(); return _instance->getNumDisplay();
} }
const json* platform::getDisplay(int index) { json platform::getDisplay(int index) {
return _instance->getDisplay(index); return _instance->getDisplay(index);
} }
@ -141,7 +129,7 @@ int platform::getNumMemory() {
return _instance->getNumMemory(); return _instance->getNumMemory();
} }
const json* platform::getMemory(int index) { json platform::getMemory(int index) {
return _instance->getMemory(index); return _instance->getMemory(index);
} }

View file

@ -20,24 +20,24 @@ public:
bool virtual enumeratePlatform() = 0; bool virtual enumeratePlatform() = 0;
int getNumCPU() { return _cpu.size(); } int getNumCPU() { return _cpu.size(); }
json* getCPU(int index); json getCPU(int index);
int getNumGPU() { return _gpu.size(); } int getNumGPU() { return _gpu.size(); }
json* getGPU(int index); json getGPU(int index);
int getNumMemory() { return _memory.size(); } int getNumMemory() { return _memory.size(); }
json* getMemory(int index); json getMemory(int index);
int getNumDisplay() { return _display.size(); } int getNumDisplay() { return _display.size(); }
json* getDisplay(int index); json getDisplay(int index);
virtual ~Instance(); virtual ~Instance();
protected: protected:
std::vector<json*> _cpu; std::vector<json> _cpu;
std::vector<json*> _memory; std::vector<json> _memory;
std::vector<json*> _gpu; std::vector<json> _gpu;
std::vector<json*> _display; std::vector<json> _display;
}; };
//Platform level functions //Platform level functions
@ -47,17 +47,17 @@ void destroy();
bool enumeratePlatform(); bool enumeratePlatform();
int getNumProcessor(); int getNumProcessor();
const json* getProcessor(int index); json getProcessor(int index);
int getNumGraphics(); int getNumGraphics();
const json* getGraphics(int index); json getGraphics(int index);
int getNumDisplay(); int getNumDisplay();
const json* getDisplay(int index); json getDisplay(int index);
int getNumMemory(); int getNumMemory();
const json* getMemory(int index); json getMemory(int index);
} // namespace platform } // namespace platform

View file

@ -258,17 +258,16 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer)
entry.first.first.Description; entry.first.first.Description;
for (auto test = entry.second.begin(); test != entry.second.end(); test++) { for (auto test = entry.second.begin(); test != entry.second.end(); test++) {
nlohmann::json* output = new nlohmann::json(); nlohmann::json output = {};
(*output)["description"] = entry.first.first.Description;
(*output)["deviceName"]= test->DeviceName; output["description"] = entry.first.first.Description;
(*output)["coordinatesleft"] = test->DesktopCoordinates.left; output["deviceName"]= test->DeviceName;
(*output)["coordinatesright"] = test->DesktopCoordinates.right; output["coordinatesleft"] = test->DesktopCoordinates.left;
(*output)["coordinatestop"] = test->DesktopCoordinates.top; output["coordinatesright"] = test->DesktopCoordinates.right;
(*output)["coordinatesbottom"] = test->DesktopCoordinates.bottom; output["coordinatestop"] = test->DesktopCoordinates.top;
output["coordinatesbottom"] = test->DesktopCoordinates.bottom;
_output.push_back(output); _output.push_back(output);
} }
} }
auto& adapterEntry = adapterToOutputs[validAdapterList.front()]; auto& adapterEntry = adapterToOutputs[validAdapterList.front()];

View file

@ -28,12 +28,12 @@ public:
QString getName() { return _name; } QString getName() { return _name; }
QString getDriver() { return _driver; } QString getDriver() { return _driver; }
bool isValid() { return _isValid; } bool isValid() { return _isValid; }
std::vector<nlohmann::json*> getOutput() { return _output; } std::vector<nlohmann::json> getOutput() { return _output; }
// E.g., GPUIdent::getInstance()->getMemory(); // E.g., GPUIdent::getInstance()->getMemory();
static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); } static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); }
private: private:
std::vector<nlohmann::json*> _output; std::vector<nlohmann::json> _output;
uint64_t _dedicatedMemoryMB { 0 }; uint64_t _dedicatedMemoryMB { 0 };
QString _name { "" }; QString _name { "" };
QString _driver { "" }; QString _driver { "" };