| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Utility/BsPlatformUtility.h"
- #include <stdlib.h>
- #include <uuid/uuid.h>
- #include <sys/utsname.h>
- namespace bs
- {
- void PlatformUtility::terminate(bool force)
- {
- // TODOPORT - Support clean exit by sending the main window a quit message
- exit(0);
- }
- SystemInfo PlatformUtility::getSystemInfo()
- {
- SystemInfo output;
- // Get CPU vendor, model and number of cores
- {
- std::ifstream file("/proc/meminfo");
- std::string token;
- while(file >> token)
- {
- if(token == "vendor_id")
- {
- if(file >> token && token == ":")
- {
- std::string vendorId;
- if(file >> vendorId)
- output.cpuManufacturer = vendorId.c_str();
- }
- }
- else if(token == "model")
- {
- if(file >> token && token == "name")
- {
- if (file >> token && token == ":")
- {
- std::stringstream modelName;
- if (file >> token)
- {
- modelName << token;
- while (file >> token)
- modelName << " " << token;
- }
- output.cpuManufacturer = modelName.str().c_str();
- }
- }
- }
- else if(token == "cpu")
- {
- if(file >> token)
- {
- if (token == "cores")
- {
- if (file >> token && token == ":")
- {
- UINT32 numCores;
- if (file >> numCores)
- output.cpuNumCores = numCores;
- }
- }
- }
- }
- // Ignore the rest of the line
- file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- }
- }
- // Get CPU frequency
- {
- std::ifstream file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
- UINT32 frequency;
- if(file >> frequency)
- output.cpuClockSpeedMhz = frequency / (1000 * 1000);
- }
- // Get amount of system memory
- {
- std::ifstream file("/proc/meminfo");
- std::string token;
- while(file >> token)
- {
- if(token == "MemTotal:")
- {
- UINT32 memTotal;
- if(file >> memTotal)
- output.memoryAmountMb = memTotal / (1024 * 1024);
- else
- output.memoryAmountMb = 0;
- break;
- }
- // Ignore the rest of the line
- file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- }
- }
- // Get OS version
- utsname osInfo;
- uname(&osInfo);
- // Note: This won't report the exact distro
- output.osName = String(osInfo.sysname) + String(osInfo.version);
- if (BS_ARCH_TYPE == BS_ARCHITECTURE_x86_64)
- output.osIs64Bit = true;
- else
- output.osIs64Bit = strstr(osInfo.machine, "64") != nullptr;
- // Get GPU info
- output.gpuInfo = sGPUInfo;
- return output;
- }
- String PlatformUtility::generateUUID()
- {
- uuid_t nativeUUID;
- uuid_generate(nativeUUID);
- char uuidChars[37];
- uuid_unparse(nativeUUID, uuidChars);
- return String(uuidChars);
- }
- void PlatformUtility::open(const Path& path)
- {
- // TODOPORT - This call will likely need to be renamed to openURL, and additionals calls
- // added depending on exact usage, since there is no direct equivalent to ShellExecute on
- // Linux.
- }
- }
|