Platform.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef HEADER_Platform
  2. #define HEADER_Platform
  3. /*
  4. htop - solaris/Platform.h
  5. (C) 2014 Hisham H. Muhammad
  6. (C) 2015 David C. Hunt
  7. (C) 2017,2018 Guy M. Broome
  8. Released under the GNU GPLv2+, see the COPYING file
  9. in the source distribution for its full text.
  10. */
  11. #include <kstat.h>
  12. /* On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key.
  13. * Since ncruses macros use the ERR macro, we can not use another name.
  14. */
  15. #undef ERR
  16. #include <libproc.h>
  17. #undef ERR
  18. #define ERR (-1)
  19. #include <signal.h>
  20. #include <stdbool.h>
  21. #include <sys/mkdev.h>
  22. #include <sys/proc.h>
  23. #include <sys/types.h>
  24. #include "Action.h"
  25. #include "BatteryMeter.h"
  26. #include "CommandLine.h"
  27. #include "DiskIOMeter.h"
  28. #include "Hashtable.h"
  29. #include "NetworkIOMeter.h"
  30. #include "ProcessLocksScreen.h"
  31. #include "SignalsPanel.h"
  32. #include "generic/gettime.h"
  33. #include "generic/hostname.h"
  34. #include "generic/uname.h"
  35. #define kill(pid, signal) kill(pid / 1024, signal)
  36. typedef struct var kvar_t;
  37. typedef struct envAccum_ {
  38. size_t capacity;
  39. size_t size;
  40. size_t bytes;
  41. char* env;
  42. } envAccum;
  43. extern const ScreenDefaults Platform_defaultScreens[];
  44. extern const unsigned int Platform_numberOfDefaultScreens;
  45. extern const SignalItem Platform_signals[];
  46. extern const unsigned int Platform_numberOfSignals;
  47. extern const MeterClass* const Platform_meterTypes[];
  48. bool Platform_init(void);
  49. void Platform_done(void);
  50. void Platform_setBindings(Htop_Action* keys);
  51. int Platform_getUptime(void);
  52. void Platform_getLoadAverage(double* one, double* five, double* fifteen);
  53. pid_t Platform_getMaxPid(void);
  54. double Platform_setCPUValues(Meter* this, unsigned int cpu);
  55. void Platform_setMemoryValues(Meter* this);
  56. void Platform_setSwapValues(Meter* this);
  57. void Platform_setZfsArcValues(Meter* this);
  58. void Platform_setZfsCompressedArcValues(Meter* this);
  59. char* Platform_getProcessEnv(pid_t pid);
  60. FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
  61. void Platform_getFileDescriptors(double* used, double* max);
  62. bool Platform_getDiskIO(DiskIOData* data);
  63. bool Platform_getNetworkIO(NetworkIOData* data);
  64. void Platform_getBattery(double* percent, ACPresence* isOnAC);
  65. static inline void Platform_getHostname(char* buffer, size_t size) {
  66. Generic_hostname(buffer, size);
  67. }
  68. static inline void Platform_getRelease(char** string) {
  69. *string = Generic_uname();
  70. }
  71. #define PLATFORM_LONG_OPTIONS
  72. static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { }
  73. static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) {
  74. return STATUS_ERROR_EXIT;
  75. }
  76. static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
  77. Generic_gettime_realtime(tv, msec);
  78. }
  79. static inline void Platform_gettime_monotonic(uint64_t* msec) {
  80. Generic_gettime_monotonic(msec);
  81. }
  82. static inline void* kstat_data_lookup_wrapper(kstat_t* ksp, const char* name) {
  83. IGNORE_WCASTQUAL_BEGIN
  84. return kstat_data_lookup(ksp, (char*)name);
  85. IGNORE_WCASTQUAL_END
  86. }
  87. static inline kstat_t* kstat_lookup_wrapper(kstat_ctl_t* kc, const char* ks_module, int ks_instance, const char* ks_name) {
  88. IGNORE_WCASTQUAL_BEGIN
  89. return kstat_lookup(kc, (char*)ks_module, ks_instance, (char*)ks_name);
  90. IGNORE_WCASTQUAL_END
  91. }
  92. static inline Hashtable* Platform_dynamicMeters(void) {
  93. return NULL;
  94. }
  95. static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { }
  96. static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { }
  97. static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { }
  98. static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { }
  99. static inline Hashtable* Platform_dynamicColumns(void) {
  100. return NULL;
  101. }
  102. static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
  103. static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
  104. return NULL;
  105. }
  106. static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) {
  107. return false;
  108. }
  109. static inline Hashtable* Platform_dynamicScreens(void) {
  110. return NULL;
  111. }
  112. static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
  113. static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
  114. static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
  115. static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
  116. #endif