Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Location:
code/branches/chat/src/orxonox
Files:
2 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
  • code/branches/chat/src/orxonox/ChatHistory.h

    r6652 r6688  
    2727 */
    2828
    29 #include <list>
     29#include <deque>
     30#include <string>
     31#include <fstream>
     32#include <iostream>
     33
     34#define TEST 0
     35
     36#ifndef TEST
    3037#include <core/BaseObject.h>
     38#endif
    3139
    3240#ifndef _ChatHistory_H__
    3341#define _ChatHistory_H__
    3442
     43
    3544/* Class to implement chat history */
     45#ifndef TEST
    3646namespace orxonox
    3747{
     48#endif
     49
     50  /* constructor */
     51  #ifndef TEST
    3852  class _OrxonoxExport ChatHistory : public BaseObject, public ChatListener
     53  #else
     54  class ChatHistory
     55  #endif
    3956  {
    4057    public:
    4158      /* constructors, destructors */
     59      #ifndef TEST
    4260      ChatHistory(BaseObject* creator);
     61      #else
     62      ChatHistory();
     63      #endif
    4364      virtual ~ChatHistory();
    4465
    4566 
    46     protected:
     67    //protected:
    4768      /** what to do with incoming chat
    4869       *
     
    5879       */
    5980      int syncLog();
     81
     82      /** debug-print */
     83      void debug_printhist();
    6084     
    6185    private:
    6286      /* FIELDS */
    6387      /** Vector to store the history in */
    64       list<std::string> hist_buffer;
     88      std::deque<std::string> hist_buffer;
    6589
    6690      /** Maximum number of lines stored in this history */
     
    7498
    7599      /** Output file stream for logfile */
    76       ofstream hist_logfile;
     100      std::ofstream hist_logfile;
    77101
    78102
     
    99123       */
    100124      int chat_hist_openlog();
    101   }
     125
     126
     127      /** close logfile */
     128      void chat_hist_closelog();
     129  };
     130
     131#ifndef TEST
    102132}
     133#endif
    103134
    104135
Note: See TracChangeset for help on using the changeset viewer.