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.

95 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectCliLoggingServices.h"
  2. objectCliLoggingService::objectCliLoggingService() :
  3. WindowCLI(NULL)
  4. {
  5. m_bLogging = true;
  6. m_iLinesCount = 22;
  7. m_ppLines = (char **) malloc(m_iLinesCount * sizeof(char *));
  8. m_x = 3;
  9. m_y = 30;
  10. m_w = 121;
  11. m_h = 22;
  12. #ifdef NEWT_CLI
  13. for (int index = 0; index < m_iLinesCount; index++)
  14. {
  15. m_ppLines[index] = NULL;
  16. m_t[index] = newtTextbox(1, index, 118, 1, 0);
  17. newtFormAddComponents(m_oForm, m_t[index], NULL);
  18. };
  19. m_b1 = newtCompactButton(3, 21, "Refresh");
  20. m_b2 = newtCompactButton(23, 21, "Close");
  21. newtFormAddComponents(m_oForm, m_b1, m_b2, NULL);
  22. // paint();
  23. #else
  24. create(0, 49, 121, 20);
  25. #endif
  26. }
  27. objectCliLoggingService::~objectCliLoggingService()
  28. {
  29. for (int index = 0; index < m_iLinesCount; index++)
  30. {
  31. if (m_ppLines[index] != NULL)
  32. {
  33. free(m_ppLines[index]);
  34. }
  35. };
  36. free(m_ppLines);
  37. }
  38. void objectCliLoggingService::paint(void)
  39. {
  40. #ifdef NEWT_CLI
  41. // newtOpenWindow( m_x, m_y, m_w, m_h, "Log Messages" );
  42. newtCenteredWindow(m_w, m_h, "Log Messages");
  43. for (int index = 0; index < (m_iLinesCount - 1); index++)
  44. {
  45. if (m_ppLines[index] != NULL)
  46. {
  47. newtTextboxSetText(m_t[index], m_ppLines[index]);
  48. }
  49. };
  50. newtDrawForm(m_oForm);
  51. #else
  52. createBox(true);
  53. for (int index = 0; index < (m_iLinesCount - 1); index++)
  54. {
  55. if (m_ppLines[index] != NULL)
  56. {
  57. mvwprintw(m_pWND, index + 1, 1, m_ppLines[index]);
  58. }
  59. };
  60. wrefresh(m_pWND);
  61. #endif
  62. }
  63. void objectCliLoggingService::logMessage(CSTR Msg)
  64. {
  65. logMessage((const char *) Msg);
  66. }
  67. void objectCliLoggingService::logMessage(const char * Msg)
  68. {
  69. if (m_bLogging)
  70. {
  71. if (m_ppLines[m_iLinesCount - 1] != NULL)
  72. {
  73. free(m_ppLines[m_iLinesCount - 1]);
  74. }
  75. for (int index = m_iLinesCount - 1; index > 0; index--)
  76. {
  77. m_ppLines[index] = m_ppLines[index - 1];
  78. };
  79. m_ppLines[0] = (char *) malloc(512);
  80. if (m_ppLines[0] != NULL)
  81. {
  82. time_t LocalTime;
  83. tm * gmt_time;
  84. time(&LocalTime);
  85. gmt_time = gmtime(&LocalTime);
  86. 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);
  87. };
  88. // paint();
  89. };
  90. }