Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2010, 3:15:44 PM (14 years ago)
Author:
smerkli
Message:

Completed and tested the code as far as I could, now preparing questions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/chat/src/orxonox/ChatHistory.cc

    r6652 r6688  
    2727 */
    2828
    29 #include <ChatHistory.h>
     29#include "ChatHistory.h"
    3030
     31#ifndef TEST
    3132namespace orxonox
    3233{
     34#endif
    3335  /* is this necessary? if yes uncomment please :P */
    3436  //CreateFactory(ChatHistory);
    3537
    3638  /* constructor */
     39  #ifndef TEST
    3740  ChatHistory(BaseObject* creator) : BaseObject(creator)
     41  #else
     42  ChatHistory::ChatHistory()
     43  #endif
    3844  {
    3945    /* register the object */
     46    #ifndef TEST
    4047    RegisterObject(ChatHistory);
     48    #endif
     49
     50    this->hist_log_enabled = true;
    4151
    4252    /* Read setting for logfiles */
    43     if( true ) /* NOTE Make this a check for the logfile setting */
    44       this->chat_hist_openlog();
     53    if( hist_log_enabled ) /* NOTE Make this a check for the logfile setting */
     54    { this->chat_hist_openlog();
     55
     56      /* push starting line */
     57      this->chat_hist_logline( "--- Logfile opened ---" );
     58    }
    4559
    4660    /* Read setting for maximum number of lines and set limit */
    4761    this->hist_maxlines = 200; /* NOTE to be changed, 200 is just for testing */
    48 
    49     /* push starting line */
    50     this->hist_buffer.push_front( "--- Logfile opened ---" )
    5162  }
    5263
    5364  /* destructor */
    54   virtual ChatHistory::~ChatHistory()
     65  ChatHistory::~ChatHistory()
    5566  {
    56     /* check if loggin is enabled */
    57       /* y -> synchronize the logfile */
     67    chat_hist_closelog();
     68   
     69    /* TODO clear list */
    5870  }
    5971
    6072  /* react to incoming chat */
    61   virtual void ChatHistory::incomingChat(const std::string& message,
     73  void ChatHistory::incomingChat(const std::string& message,
    6274    unsigned int senderID)
    6375  {
     
    6678
    6779    /* format the message and senderID into a line */
    68     std::string buf = "empty"; /* NOTE to be changed */
     80    std::string buf = "" + senderID; /* NOTE to be changed */
    6981
     82    /* TODO */
    7083    /* --> a) look up the actual name of the sender */
    7184    /* --> b) add sender name and string up with a separator
     
    7487
    7588    /* add the line to the history */
    76     this->chat_hist_addline( buf );
     89    this->chat_hist_addline( buf + ": " + message );
    7790
    7891    /* add the line to the log */
    79     this->chat_hist_logline( buf );
     92    this->chat_hist_logline( buf + ": " + message );
    8093  }
    8194
    8295  /* Synchronize logfile onto the hard drive */ /* MARK MARK */
    83   int ChatHistory::syncLog();
     96  int ChatHistory::syncLog()
     97  {
     98    //if( this->hist_logfile )
     99      //this->hist_logfile.sync();
     100  }
    84101
    85102  /* add a line to this history */
    86   int ChatHistory::chat_hist_addline( const std::string& toadd );
     103  int ChatHistory::chat_hist_addline( const std::string& toadd )
    87104  {
     105    /* crop history at the end if it's too large */
     106    while( this->hist_buffer.size() > this->hist_maxlines+1 )
     107      this->hist_buffer.pop_front();
     108
    88109    /* push to the front of the history */
    89     this->hist_buffer.push_front( toadd );
     110    this->hist_buffer.push_back( toadd );
    90111
    91     /* crop history at the end if it's too large */
    92     this->hist_buffer.resize( this->hist_maxlines );
    93112  }
    94113
     
    101120    /* output the line to the file if logging is enabled */
    102121    if( this->hist_log_enabled )
    103       this->hist_logfile << buf << std::endl;
     122      this->hist_logfile << toadd << std::endl;
    104123  }
    105124
     
    111130     */
    112131    this->hist_logfile.open( "/tmp/setsomepath.txt",
    113       fstream::out | fstream::app );
     132      std::fstream::out | std::fstream::app );
    114133
    115134    /* TODO check whether this works (not sure how you'd like it?) */
     
    119138  }
    120139
     140  /* close logfile */
     141  void ChatHistory::chat_hist_closelog()
     142  {
     143    if( this->hist_logfile )
     144    { this->chat_hist_logline( "--- Logfile closed ---" );
     145      this->hist_logfile.close();
     146    }
     147  }
     148
     149  /* output history for debugging */
     150  void ChatHistory::debug_printhist()
     151  {
     152    std::deque<std::string>::iterator it;
     153
     154    for( it = this->hist_buffer.begin(); it != this->hist_buffer.end();
     155      ++it )
     156      std::cout << *it << std::endl;
     157
     158    std::cout << "Size: " << hist_buffer.size() << std::endl;
     159
     160   
     161  }
     162
     163#ifndef TEST
    121164}
     165#endif
Note: See TracChangeset for help on using the changeset viewer.