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.

70 lines
2.4 KiB

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