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.

264 lines
6.3KB

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