ClockMeter.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. htop - ClockMeter.c
  3. (C) 2004-2011 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "ClockMeter.h"
  9. #include <time.h>
  10. #include <sys/time.h>
  11. #include "CRT.h"
  12. #include "Machine.h"
  13. #include "Object.h"
  14. static const int ClockMeter_attributes[] = {
  15. CLOCK
  16. };
  17. static void ClockMeter_updateValues(Meter* this) {
  18. const Machine* host = this->host;
  19. struct tm result;
  20. const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
  21. strftime(this->txtBuffer, sizeof(this->txtBuffer), "%H:%M:%S", lt);
  22. }
  23. const MeterClass ClockMeter_class = {
  24. .super = {
  25. .extends = Class(Meter),
  26. .delete = Meter_delete
  27. },
  28. .updateValues = ClockMeter_updateValues,
  29. .defaultMode = TEXT_METERMODE,
  30. .supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
  31. .maxItems = 0,
  32. .total = 0.0,
  33. .attributes = ClockMeter_attributes,
  34. .name = "Clock",
  35. .uiName = "Clock",
  36. .caption = "Time: ",
  37. };