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.

84 lines
1.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectCURSESLoggingService.h"
  2. objectCURSESLoggingService::objectCURSESLoggingService() :
  3. WindowCLI(NULL)
  4. {
  5. m_bLogging = true;
  6. #ifndef NEWT_CLI
  7. create(0, 49, 121, 20);
  8. #endif
  9. m_iLinesCount = 20;
  10. m_ppLines = (char **) malloc(m_iLinesCount * sizeof(char *));
  11. }
  12. objectCURSESLoggingService::objectCURSESLoggingService(int x, int y, int w, int h) :
  13. WindowCLI(NULL)
  14. {
  15. m_bLogging = true;
  16. #ifndef NEWT_CLI
  17. create(x, y, w, h);
  18. #endif
  19. m_iLinesCount = h;
  20. m_ppLines = (char **) malloc(m_iLinesCount * sizeof(char *));
  21. for (int index = 0; index < m_iLinesCount; index++)
  22. {
  23. m_ppLines[index] = NULL;
  24. };
  25. }
  26. objectCURSESLoggingService::~objectCURSESLoggingService()
  27. {
  28. for (int index = 0; index < m_iLinesCount; index++)
  29. {
  30. if (m_ppLines[index] != NULL)
  31. {
  32. free(m_ppLines[index]);
  33. }
  34. };
  35. free(m_ppLines);
  36. }
  37. void objectCURSESLoggingService::paint(void)
  38. {
  39. #ifndef NEWT_CLI
  40. createBox(true);
  41. for (int index = 0; index < (m_iLinesCount - 1); index++)
  42. {
  43. if (m_ppLines[index] != NULL)
  44. {
  45. mvwprintw(m_pWND, index + 1, 1, m_ppLines[index]);
  46. }
  47. };
  48. wrefresh(m_pWND);
  49. #endif
  50. }
  51. void objectCURSESLoggingService::logMessage(CSTR Msg)
  52. {
  53. logMessage((const char *) Msg);
  54. }
  55. void objectCURSESLoggingService::logMessage(const char * Msg)
  56. {
  57. if (m_bLogging)
  58. {
  59. if (m_ppLines[m_iLinesCount - 1] != NULL)
  60. {
  61. free(m_ppLines[m_iLinesCount - 1]);
  62. }
  63. for (int index = m_iLinesCount - 1; index > 0; index--)
  64. {
  65. m_ppLines[index] = m_ppLines[index - 1];
  66. };
  67. m_ppLines[0] = (char *) malloc(512);
  68. if (m_ppLines[0] != NULL)
  69. {
  70. time_t LocalTime;
  71. tm * gmt_time;
  72. time(&LocalTime);
  73. gmt_time = gmtime(&LocalTime);
  74. sprintf(m_ppLines[0], "%04d-%02d-%02d %02d:%02d:%02d %s\n", 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Msg);
  75. };
  76. paint();
  77. };
  78. }