mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 02:23:38 +02:00
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:
parent
d019dc7d54
commit
13c9bb078c
7 changed files with 69 additions and 76 deletions
|
@ -2495,9 +2495,9 @@ void Application::initPlatform() {
|
|||
|
||||
platform::enumeratePlatform();
|
||||
|
||||
const nlohmann::json* test = platform::getGraphics(0);
|
||||
const nlohmann::json* test1 = platform::getProcessor(0);
|
||||
const nlohmann::json* test2 = platform::getMemory(0);
|
||||
const nlohmann::json test = platform::getGraphics(0);
|
||||
const nlohmann::json test1 = platform::getProcessor(0);
|
||||
const nlohmann::json test2 = platform::getMemory(0);
|
||||
//const nlohmann::json* test3 = platform::getDisplay(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,11 @@
|
|||
#include <thread>
|
||||
#include <GPUIdent.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef Q_MAC_OS
|
||||
#include <unistd.h>
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
|
||||
using namespace platform;
|
||||
|
||||
|
@ -25,18 +28,20 @@ bool MACOSInstance::enumeratePlatform() {
|
|||
|
||||
static void getCpuId( uint32_t* p, uint32_t ax )
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
__asm __volatile
|
||||
( "movl %%ebx, %%esi\n\t"
|
||||
( "movl %%ebx, %%esi\n\t"
|
||||
"cpuid\n\t"
|
||||
"xchgl %%ebx, %%esi"
|
||||
: "=a" (p[0]), "=S" (p[1]),
|
||||
"=c" (p[2]), "=d" (p[3])
|
||||
: "0" (ax)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MACOSInstance::enumerateCpu() {
|
||||
json *cpu= new json();
|
||||
json cpu = {};
|
||||
uint32_t cpuInfo[4]={0,0,0,0};
|
||||
char CPUBrandString[16];
|
||||
char CPUModelString[16];
|
||||
|
@ -57,10 +62,10 @@ void MACOSInstance::enumerateCpu() {
|
|||
}
|
||||
}
|
||||
|
||||
(*cpu)["brand"] = CPUBrandString;
|
||||
(*cpu)["model"] = CPUModelString;
|
||||
(*cpu)["clockSpeed"] = CPUClockString;
|
||||
(*cpu)["numCores"] = getNumLogicalCores();
|
||||
cpu["brand"] = CPUBrandString;
|
||||
cpu["model"] = CPUModelString;
|
||||
cpu["clockSpeed"] = CPUClockString;
|
||||
cpu["numCores"] = getNumLogicalCores();
|
||||
|
||||
_cpu.push_back(cpu);
|
||||
}
|
||||
|
@ -73,21 +78,22 @@ void MACOSInstance::enumerateGpu() {
|
|||
|
||||
GPUIdent* ident = GPUIdent::getInstance();
|
||||
|
||||
json *gpu = new json();
|
||||
(*gpu)["name"] = ident->getName().toUtf8().constData();
|
||||
(*gpu)["memory"] = ident->getMemory();
|
||||
(*gpu)["driver"] = ident->getDriver().toUtf8().constData();
|
||||
json gpu = {};
|
||||
gpu["name"] = ident->getName().toUtf8().constData();
|
||||
gpu["memory"] = ident->getMemory();
|
||||
gpu["driver"] = ident->getDriver().toUtf8().constData();
|
||||
|
||||
_gpu.push_back(gpu);
|
||||
_display = ident->getOutput();
|
||||
}
|
||||
|
||||
void MACOSInstance::enumerateRam() {
|
||||
json* ram = new json();
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
json ram = {};
|
||||
#ifdef Q_OS_MAC
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
long page_size = sysconf(_SC_PAGE_SIZE);
|
||||
|
||||
(*ram)["totalMem"] = pages * page_size;;
|
||||
|
||||
ram["totalMem"] = pages * page_size;;
|
||||
#endif
|
||||
_memory.push_back(ram);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ bool WINInstance::enumeratePlatform() {
|
|||
}
|
||||
|
||||
void WINInstance::enumerateCpu() {
|
||||
json *cpu= new json();
|
||||
json cpu = {};
|
||||
int CPUInfo[4] = { -1 };
|
||||
unsigned nExIds;
|
||||
unsigned int i = 0;
|
||||
|
@ -53,10 +53,10 @@ void WINInstance::enumerateCpu() {
|
|||
}
|
||||
}
|
||||
|
||||
(*cpu)["brand"] = CPUBrandString;
|
||||
(*cpu)["model"] = CPUModelString;
|
||||
(*cpu)["clockSpeed"] = CPUClockString;
|
||||
(*cpu)["numCores"] = getNumLogicalCores();
|
||||
cpu["brand"] = CPUBrandString;
|
||||
cpu["model"] = CPUModelString;
|
||||
cpu["clockSpeed"] = CPUClockString;
|
||||
cpu["numCores"] = getNumLogicalCores();
|
||||
#endif
|
||||
_cpu.push_back(cpu);
|
||||
}
|
||||
|
@ -69,23 +69,23 @@ void WINInstance::enumerateGpu() {
|
|||
|
||||
GPUIdent* ident = GPUIdent::getInstance();
|
||||
|
||||
json *gpu = new json();
|
||||
(*gpu)["name"] = ident->getName().toUtf8().constData();
|
||||
(*gpu)["memory"] = ident->getMemory();
|
||||
(*gpu)["driver"] = ident->getDriver().toUtf8().constData();
|
||||
json gpu = {};
|
||||
gpu["name"] = ident->getName().toUtf8().constData();
|
||||
gpu["memory"] = ident->getMemory();
|
||||
gpu["driver"] = ident->getDriver().toUtf8().constData();
|
||||
|
||||
_gpu.push_back(gpu);
|
||||
_display = ident->getOutput();
|
||||
}
|
||||
|
||||
void WINInstance::enumerateRam() {
|
||||
json* ram = new json();
|
||||
json ram = {};
|
||||
#ifdef Q_OS_WINDOWS
|
||||
MEMORYSTATUSEX statex;
|
||||
statex.dwLength = sizeof(statex);
|
||||
GlobalMemoryStatusEx(&statex);
|
||||
int totalRam = statex.ullTotalPhys / 1024 / 1024;
|
||||
(*ram)["totalMem"] = totalRam;
|
||||
ram["totalMem"] = totalRam;
|
||||
#endif
|
||||
_memory.push_back(ram);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using namespace platform;
|
||||
|
||||
Instance* _instance;
|
||||
Instance *_instance;
|
||||
|
||||
void platform::create() {
|
||||
|
||||
|
@ -42,37 +42,37 @@ void platform::destroy() {
|
|||
delete _instance;
|
||||
}
|
||||
|
||||
json* Instance::getCPU(int index) {
|
||||
json Instance::getCPU(int index) {
|
||||
assert(index <(int) _cpu.size());
|
||||
if (index >= (int)_cpu.size())
|
||||
return nullptr;
|
||||
return NULL;
|
||||
|
||||
return _cpu.at(index);
|
||||
}
|
||||
|
||||
|
||||
//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());
|
||||
if(index >= (int)_memory.size())
|
||||
return nullptr;
|
||||
return NULL;
|
||||
|
||||
return _memory.at(index);
|
||||
}
|
||||
|
||||
json* Instance::getGPU(int index) {
|
||||
json Instance::getGPU(int index) {
|
||||
assert(index <(int) _gpu.size());
|
||||
if (index >=(int) _gpu.size())
|
||||
return nullptr;
|
||||
return NULL;
|
||||
|
||||
return _gpu.at(index);
|
||||
}
|
||||
|
||||
json* Instance::getDisplay(int index) {
|
||||
json Instance::getDisplay(int index) {
|
||||
assert(index <(int) _display.size());
|
||||
|
||||
if (index >=(int) _display.size())
|
||||
return nullptr;
|
||||
return NULL;
|
||||
|
||||
return _display.at(index);
|
||||
}
|
||||
|
@ -80,31 +80,19 @@ json* Instance::getDisplay(int index) {
|
|||
Instance::~Instance() {
|
||||
if (_cpu.size() > 0) {
|
||||
|
||||
for (std::vector<json*>::iterator it = _cpu.begin(); it != _cpu.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
_cpu.clear();
|
||||
}
|
||||
|
||||
if (_memory.size() > 0) {
|
||||
for (std::vector<json*>::iterator it = _memory.begin(); it != _memory.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
_memory.clear();
|
||||
}
|
||||
|
||||
|
||||
if (_gpu.size() > 0) {
|
||||
for (std::vector<json*>::iterator it = _gpu.begin(); it != _gpu.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
_gpu.clear();
|
||||
}
|
||||
|
||||
if (_display.size() > 0) {
|
||||
for (std::vector<json*>::iterator it = _display.begin(); it != _display.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
_display.clear();
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +105,7 @@ int platform::getNumProcessor() {
|
|||
return _instance->getNumCPU();
|
||||
}
|
||||
|
||||
const json* platform::getProcessor(int index) {
|
||||
json platform::getProcessor(int index) {
|
||||
return _instance->getCPU(index);
|
||||
}
|
||||
|
||||
|
@ -125,7 +113,7 @@ int platform::getNumGraphics() {
|
|||
return _instance->getNumGPU();
|
||||
}
|
||||
|
||||
const json* platform::getGraphics(int index) {
|
||||
json platform::getGraphics(int index) {
|
||||
return _instance->getGPU(index);
|
||||
}
|
||||
|
||||
|
@ -133,7 +121,7 @@ int platform::getNumDisplay() {
|
|||
return _instance->getNumDisplay();
|
||||
}
|
||||
|
||||
const json* platform::getDisplay(int index) {
|
||||
json platform::getDisplay(int index) {
|
||||
return _instance->getDisplay(index);
|
||||
}
|
||||
|
||||
|
@ -141,7 +129,7 @@ int platform::getNumMemory() {
|
|||
return _instance->getNumMemory();
|
||||
}
|
||||
|
||||
const json* platform::getMemory(int index) {
|
||||
json platform::getMemory(int index) {
|
||||
return _instance->getMemory(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,24 +20,24 @@ public:
|
|||
bool virtual enumeratePlatform() = 0;
|
||||
|
||||
int getNumCPU() { return _cpu.size(); }
|
||||
json* getCPU(int index);
|
||||
json getCPU(int index);
|
||||
|
||||
int getNumGPU() { return _gpu.size(); }
|
||||
json* getGPU(int index);
|
||||
json getGPU(int index);
|
||||
|
||||
int getNumMemory() { return _memory.size(); }
|
||||
json* getMemory(int index);
|
||||
json getMemory(int index);
|
||||
|
||||
int getNumDisplay() { return _display.size(); }
|
||||
json* getDisplay(int index);
|
||||
json getDisplay(int index);
|
||||
|
||||
virtual ~Instance();
|
||||
|
||||
protected:
|
||||
std::vector<json*> _cpu;
|
||||
std::vector<json*> _memory;
|
||||
std::vector<json*> _gpu;
|
||||
std::vector<json*> _display;
|
||||
std::vector<json> _cpu;
|
||||
std::vector<json> _memory;
|
||||
std::vector<json> _gpu;
|
||||
std::vector<json> _display;
|
||||
};
|
||||
|
||||
//Platform level functions
|
||||
|
@ -47,17 +47,17 @@ void destroy();
|
|||
bool enumeratePlatform();
|
||||
|
||||
int getNumProcessor();
|
||||
const json* getProcessor(int index);
|
||||
json getProcessor(int index);
|
||||
|
||||
int getNumGraphics();
|
||||
const json* getGraphics(int index);
|
||||
json getGraphics(int index);
|
||||
|
||||
int getNumDisplay();
|
||||
const json* getDisplay(int index);
|
||||
json getDisplay(int index);
|
||||
|
||||
|
||||
int getNumMemory();
|
||||
const json* getMemory(int index);
|
||||
json getMemory(int index);
|
||||
|
||||
} // namespace platform
|
||||
|
||||
|
|
|
@ -258,17 +258,16 @@ GPUIdent* GPUIdent::ensureQuery(const QString& vendor, const QString& renderer)
|
|||
|
||||
entry.first.first.Description;
|
||||
for (auto test = entry.second.begin(); test != entry.second.end(); test++) {
|
||||
nlohmann::json* output = new nlohmann::json();
|
||||
(*output)["description"] = entry.first.first.Description;
|
||||
(*output)["deviceName"]= test->DeviceName;
|
||||
(*output)["coordinatesleft"] = test->DesktopCoordinates.left;
|
||||
(*output)["coordinatesright"] = test->DesktopCoordinates.right;
|
||||
(*output)["coordinatestop"] = test->DesktopCoordinates.top;
|
||||
(*output)["coordinatesbottom"] = test->DesktopCoordinates.bottom;
|
||||
nlohmann::json output = {};
|
||||
|
||||
output["description"] = entry.first.first.Description;
|
||||
output["deviceName"]= test->DeviceName;
|
||||
output["coordinatesleft"] = test->DesktopCoordinates.left;
|
||||
output["coordinatesright"] = test->DesktopCoordinates.right;
|
||||
output["coordinatestop"] = test->DesktopCoordinates.top;
|
||||
output["coordinatesbottom"] = test->DesktopCoordinates.bottom;
|
||||
_output.push_back(output);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto& adapterEntry = adapterToOutputs[validAdapterList.front()];
|
||||
|
|
|
@ -28,12 +28,12 @@ public:
|
|||
QString getName() { return _name; }
|
||||
QString getDriver() { return _driver; }
|
||||
bool isValid() { return _isValid; }
|
||||
std::vector<nlohmann::json*> getOutput() { return _output; }
|
||||
std::vector<nlohmann::json> getOutput() { return _output; }
|
||||
|
||||
// E.g., GPUIdent::getInstance()->getMemory();
|
||||
static GPUIdent* getInstance(const QString& vendor = "", const QString& renderer = "") { return _instance.ensureQuery(vendor, renderer); }
|
||||
private:
|
||||
std::vector<nlohmann::json*> _output;
|
||||
std::vector<nlohmann::json> _output;
|
||||
uint64_t _dedicatedMemoryMB { 0 };
|
||||
QString _name { "" };
|
||||
QString _driver { "" };
|
||||
|
|
Loading…
Reference in a new issue