The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
6.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  19. // compiled on its own).
  20. #ifdef JUCE_INCLUDED_FILE
  21. //==============================================================================
  22. /*static juce_noinline unsigned int getCPUIDWord (int* familyModel, int* extFeatures) throw()
  23. {
  24. unsigned int cpu = 0;
  25. unsigned int ext = 0;
  26. unsigned int family = 0;
  27. unsigned int dummy = 0;
  28. #if JUCE_64BIT
  29. __asm__ ("cpuid"
  30. : "=a" (family), "=b" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  31. #else
  32. __asm__ ("push %%ebx; cpuid; mov %%ebx, %%edi; pop %%ebx"
  33. : "=a" (family), "=D" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  34. #endif
  35. if (familyModel != 0)
  36. *familyModel = family;
  37. if (extFeatures != 0)
  38. *extFeatures = ext;
  39. return cpu;
  40. }*/
  41. //==============================================================================
  42. void Logger::outputDebugString (const String& text) throw()
  43. {
  44. fputs (text.toUTF8(), stdout);
  45. fputs ("\n", stdout);
  46. }
  47. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  48. {
  49. String text;
  50. va_list args;
  51. va_start (args, format);
  52. text.vprintf(format, args);
  53. outputDebugString(text);
  54. }
  55. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  56. {
  57. return Linux;
  58. }
  59. const String SystemStats::getOperatingSystemName() throw()
  60. {
  61. return T("Linux");
  62. }
  63. bool SystemStats::isOperatingSystem64Bit() throw()
  64. {
  65. #if JUCE_64BIT
  66. return true;
  67. #else
  68. //xxx not sure how to find this out?..
  69. return false;
  70. #endif
  71. }
  72. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  73. {
  74. String info;
  75. char buf [256];
  76. FILE* f = fopen ("/proc/cpuinfo", "r");
  77. while (f != 0 && fgets (buf, sizeof(buf), f))
  78. {
  79. if (strncmp (buf, key, strlen (key)) == 0)
  80. {
  81. char* p = buf;
  82. while (*p && *p != '\n')
  83. ++p;
  84. if (*p != 0)
  85. *p = 0;
  86. p = buf;
  87. while (*p != 0 && *p != ':')
  88. ++p;
  89. if (*p != 0 && *(p + 1) != 0)
  90. info = p + 2;
  91. if (! lastOne)
  92. break;
  93. }
  94. }
  95. fclose (f);
  96. return info;
  97. }
  98. bool SystemStats::hasMMX() throw()
  99. {
  100. return getCpuInfo ("flags").contains (T("mmx"));
  101. }
  102. bool SystemStats::hasSSE() throw()
  103. {
  104. return getCpuInfo ("flags").contains (T("sse"));
  105. }
  106. bool SystemStats::hasSSE2() throw()
  107. {
  108. return getCpuInfo ("flags").contains (T("sse2"));
  109. }
  110. bool SystemStats::has3DNow() throw()
  111. {
  112. return getCpuInfo ("flags").contains (T("3dnow"));
  113. }
  114. const String SystemStats::getCpuVendor() throw()
  115. {
  116. return getCpuInfo ("vendor_id");
  117. }
  118. int SystemStats::getCpuSpeedInMegaherz() throw()
  119. {
  120. const String speed (getCpuInfo ("cpu MHz"));
  121. return (int) (speed.getFloatValue() + 0.5f);
  122. }
  123. int SystemStats::getMemorySizeInMegabytes() throw()
  124. {
  125. struct sysinfo sysi;
  126. if (sysinfo (&sysi) == 0)
  127. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  128. return 0;
  129. }
  130. uint32 juce_millisecondsSinceStartup() throw()
  131. {
  132. static unsigned int calibrate = 0;
  133. static bool calibrated = false;
  134. timeval t;
  135. unsigned int ret = 0;
  136. if (! gettimeofday (&t, 0))
  137. {
  138. if (! calibrated)
  139. {
  140. struct sysinfo sysi;
  141. if (sysinfo (&sysi) == 0)
  142. // Safe to assume system was not brought up earlier than 1970!
  143. calibrate = t.tv_sec - sysi.uptime;
  144. calibrated = true;
  145. }
  146. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  147. }
  148. return ret;
  149. }
  150. double Time::getMillisecondCounterHiRes() throw()
  151. {
  152. return getHighResolutionTicks() * 0.001;
  153. }
  154. int64 Time::getHighResolutionTicks() throw()
  155. {
  156. timeval t;
  157. if (gettimeofday (&t, 0))
  158. return 0;
  159. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  160. }
  161. int64 Time::getHighResolutionTicksPerSecond() throw()
  162. {
  163. // Microseconds
  164. return 1000000;
  165. }
  166. bool Time::setSystemTimeToThisTime() const throw()
  167. {
  168. timeval t;
  169. t.tv_sec = millisSinceEpoch % 1000000;
  170. t.tv_usec = millisSinceEpoch - t.tv_sec;
  171. return settimeofday (&t, NULL) ? false : true;
  172. }
  173. int SystemStats::getPageSize() throw()
  174. {
  175. static int systemPageSize = 0;
  176. if (systemPageSize == 0)
  177. systemPageSize = sysconf (_SC_PAGESIZE);
  178. return systemPageSize;
  179. }
  180. int SystemStats::getNumCpus() throw()
  181. {
  182. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  183. return lastCpu + 1;
  184. }
  185. //==============================================================================
  186. void SystemStats::initialiseStats() throw()
  187. {
  188. // Process starts off as root when running suid
  189. Process::lowerPrivilege();
  190. String s (SystemStats::getJUCEVersion());
  191. }
  192. void PlatformUtilities::fpuReset()
  193. {
  194. }
  195. #endif