BsUnixPlatformUtility.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Utility/BsPlatformUtility.h"
  4. #include <stdlib.h>
  5. #include <uuid/uuid.h>
  6. #include <sys/utsname.h>
  7. namespace bs
  8. {
  9. void PlatformUtility::terminate(bool force)
  10. {
  11. // TODOPORT - Support clean exit by sending the main window a quit message
  12. exit(0);
  13. }
  14. SystemInfo PlatformUtility::getSystemInfo()
  15. {
  16. SystemInfo output;
  17. // Get CPU vendor, model and number of cores
  18. {
  19. std::ifstream file("/proc/meminfo");
  20. std::string token;
  21. while(file >> token)
  22. {
  23. if(token == "vendor_id")
  24. {
  25. if(file >> token && token == ":")
  26. {
  27. std::string vendorId;
  28. if(file >> vendorId)
  29. output.cpuManufacturer = vendorId.c_str();
  30. }
  31. }
  32. else if(token == "model")
  33. {
  34. if(file >> token && token == "name")
  35. {
  36. if (file >> token && token == ":")
  37. {
  38. std::stringstream modelName;
  39. if (file >> token)
  40. {
  41. modelName << token;
  42. while (file >> token)
  43. modelName << " " << token;
  44. }
  45. output.cpuManufacturer = modelName.str().c_str();
  46. }
  47. }
  48. }
  49. else if(token == "cpu")
  50. {
  51. if(file >> token)
  52. {
  53. if (token == "cores")
  54. {
  55. if (file >> token && token == ":")
  56. {
  57. UINT32 numCores;
  58. if (file >> numCores)
  59. output.cpuNumCores = numCores;
  60. }
  61. }
  62. }
  63. }
  64. // Ignore the rest of the line
  65. file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  66. }
  67. }
  68. // Get CPU frequency
  69. {
  70. std::ifstream file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
  71. UINT32 frequency;
  72. if(file >> frequency)
  73. output.cpuClockSpeedMhz = frequency / (1000 * 1000);
  74. }
  75. // Get amount of system memory
  76. {
  77. std::ifstream file("/proc/meminfo");
  78. std::string token;
  79. while(file >> token)
  80. {
  81. if(token == "MemTotal:")
  82. {
  83. UINT32 memTotal;
  84. if(file >> memTotal)
  85. output.memoryAmountMb = memTotal / (1024 * 1024);
  86. else
  87. output.memoryAmountMb = 0;
  88. break;
  89. }
  90. // Ignore the rest of the line
  91. file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  92. }
  93. }
  94. // Get OS version
  95. utsname osInfo;
  96. uname(&osInfo);
  97. // Note: This won't report the exact distro
  98. output.osName = String(osInfo.sysname) + String(osInfo.version);
  99. if (BS_ARCH_TYPE == BS_ARCHITECTURE_x86_64)
  100. output.osIs64Bit = true;
  101. else
  102. output.osIs64Bit = strstr(osInfo.machine, "64") != nullptr;
  103. // Get GPU info
  104. output.gpuInfo = sGPUInfo;
  105. return output;
  106. }
  107. String PlatformUtility::generateUUID()
  108. {
  109. uuid_t nativeUUID;
  110. uuid_generate(nativeUUID);
  111. char uuidChars[37];
  112. uuid_unparse(nativeUUID, uuidChars);
  113. return String(uuidChars);
  114. }
  115. void PlatformUtility::open(const Path& path)
  116. {
  117. // TODOPORT - This call will likely need to be renamed to openURL, and additionals calls
  118. // added depending on exact usage, since there is no direct equivalent to ShellExecute on
  119. // Linux.
  120. }
  121. }