hostinfo.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2018 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_HOSTINFO_H
  18. #define BOINC_HOSTINFO_H
  19. // Description of a host's hardware and software.
  20. // This is used a few places:
  21. // - it's part of the client's state file, client_state.xml
  22. // - it's passed in the reply to the get_host_info GUI RPC
  23. // - it's included in scheduler RPC requests
  24. //
  25. // Other host-specific info is kept in
  26. // TIME_STATS (on/connected/active fractions)
  27. // NET_STATS (average network bandwidths)
  28. #include "miofile.h"
  29. #include "coproc.h"
  30. #include "common_defs.h"
  31. #ifdef _WIN64
  32. #include "wslinfo.h"
  33. #endif
  34. #define USER_IDLE_TIME_INF 86400
  35. enum LINUX_OS_INFO_PARSER {
  36. lsbrelease,
  37. osrelease,
  38. redhatrelease
  39. };
  40. const char command_lsbrelease[] = "/usr/bin/lsb_release -a 2>&1";
  41. const char file_osrelease[] = "/etc/os-release";
  42. const char file_redhatrelease[] = "/etc/redhat-release";
  43. // if you add fields, update clear_host_info()
  44. #define P_FEATURES_SIZE 1024
  45. class HOST_INFO {
  46. public:
  47. int timezone; // local STANDARD time - UTC time (in seconds)
  48. char domain_name[256];
  49. char serialnum[256];
  50. char ip_addr[256];
  51. char host_cpid[64];
  52. int p_ncpus;
  53. char p_vendor[256];
  54. char p_model[256];
  55. char p_features[P_FEATURES_SIZE];
  56. double p_fpops;
  57. double p_iops;
  58. double p_membw;
  59. double p_calculated; // when benchmarks were last run, or zero
  60. bool p_vm_extensions_disabled;
  61. double m_nbytes; // Total amount of memory in bytes
  62. double m_cache;
  63. double m_swap; // Total amount of swap space in bytes
  64. double d_total; // Total amount of disk in bytes
  65. double d_free; // Total amount of free disk in bytes
  66. char os_name[256];
  67. char os_version[256];
  68. // WSL information for Win10 only
  69. bool wsl_available;
  70. #ifdef _WIN64
  71. WSLS wsls;
  72. #endif
  73. char product_name[256]; // manufacturer and/or model of system
  74. char mac_address[256]; // MAC addr e.g. 00:00:00:00:00:00
  75. // currently populated for Android
  76. // the following is non-empty if VBox is installed
  77. //
  78. char virtualbox_version[256];
  79. COPROCS coprocs;
  80. int num_opencl_cpu_platforms;
  81. OPENCL_CPU_PROP opencl_cpu_prop[MAX_OPENCL_CPU_PLATFORMS];
  82. #ifdef _WIN32
  83. int n_processor_groups;
  84. #endif
  85. void clear_host_info();
  86. HOST_INFO();
  87. int parse(XML_PARSER&, bool static_items_only = false);
  88. int write(MIOFILE&, bool include_net_info, bool include_coprocs);
  89. int parse_cpu_benchmarks(FILE*);
  90. int write_cpu_benchmarks(FILE*);
  91. void print();
  92. bool host_is_running_on_batteries();
  93. long user_idle_time(bool check_all_logins);
  94. // seconds since last user interaction
  95. int get_host_info(bool init);
  96. int get_cpu_info();
  97. int get_cpu_count();
  98. int get_memory_info();
  99. int get_os_info();
  100. int get_host_battery_charge();
  101. int get_host_battery_state();
  102. int get_local_network_info();
  103. int get_virtualbox_version();
  104. void make_random_string(const char* salt, char* out);
  105. void generate_host_cpid();
  106. static bool parse_linux_os_info(
  107. FILE* file, const LINUX_OS_INFO_PARSER parser,
  108. char* os_name, const int os_name_size, char* os_version,
  109. const int os_version_size
  110. );
  111. static bool parse_linux_os_info(
  112. const std::string& line, const LINUX_OS_INFO_PARSER parser,
  113. char* os_name, const int os_name_size, char* os_version,
  114. const int os_version_size
  115. );
  116. static bool parse_linux_os_info(
  117. const std::vector<std::string>& lines,
  118. const LINUX_OS_INFO_PARSER parser,
  119. char* os_name, const int os_name_size, char* os_version,
  120. const int os_version_size
  121. );
  122. #ifdef _WIN32
  123. void win_get_processor_info();
  124. #endif
  125. };
  126. extern void make_secure_random_string(char*);
  127. #ifdef _WIN64
  128. int get_wsl_information(bool& wsl_available, WSLS& wsls);
  129. int get_processor_group(HANDLE);
  130. #endif
  131. #ifdef __APPLE__
  132. int get_system_uptime();
  133. #ifdef __cplusplus
  134. extern "C" {
  135. #endif
  136. #include <IOKit/hidsystem/IOHIDLib.h>
  137. #include <IOKit/hidsystem/IOHIDParameter.h>
  138. #include <IOKit/hidsystem/event_status_driver.h>
  139. bool isDualGPUMacBook();
  140. // Apple has removed NxIdleTime() beginning with OS 10.6, so we must try
  141. // loading it at run time to avoid a link error. For details, please see
  142. // the comments in the __APPLE__ version of HOST_INFO::users_idle() in
  143. // client/hostinfo_unix.cpp.
  144. typedef double (*nxIdleTimeProc)(NXEventHandle handle);
  145. #ifdef __cplusplus
  146. } // extern "C"
  147. #endif
  148. extern NXEventHandle gEventHandle;
  149. #endif
  150. #endif