SayReporter.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "SayReporter.h"
00034 #include "TheBESKeys.h"
00035 #include "BESInternalError.h"
00036 #include "SampleResponseNames.h"
00037
00038 SayReporter::SayReporter()
00039 : BESReporter(),
00040 _file_buffer( 0 )
00041 {
00042 bool found = false ;
00043 _log_name = TheBESKeys::TheKeys()->get_key( "Say.LogName", found );
00044 if( _log_name == "" )
00045 {
00046 throw BESInternalError( "cannot determine Say log name", __FILE__, __LINE__ ) ;
00047 }
00048 else
00049 {
00050 _file_buffer = new ofstream( _log_name.c_str(), ios::out | ios::app ) ;
00051 if( !(*_file_buffer) )
00052 {
00053 string s = "cannot open Say log file " + _log_name ;;
00054 throw BESInternalError( s, __FILE__, __LINE__ ) ;
00055 }
00056 }
00057 }
00058
00059 SayReporter::~SayReporter()
00060 {
00061 if( _file_buffer )
00062 {
00063 delete _file_buffer ;
00064 _file_buffer = 0 ;
00065 }
00066 }
00067
00068 void
00069 SayReporter::report( BESDataHandlerInterface &dhi )
00070 {
00071 const time_t sctime = time( NULL ) ;
00072 const struct tm *sttime = localtime( &sctime ) ;
00073 char zone_name[10] ;
00074 strftime( zone_name, sizeof( zone_name ), "%Z", sttime ) ;
00075 char *b = asctime( sttime ) ;
00076 *(_file_buffer) << "[" << zone_name << " " ;
00077 for(register int j = 0; b[j] != '\n'; j++ )
00078 *(_file_buffer) << b[j] ;
00079 *(_file_buffer) << "] " ;
00080
00081 string say_what ;
00082 string say_to ;
00083 BESDataHandlerInterface::data_citer i = dhi.data_c().find( SAY_WHAT ) ;
00084 if( i != dhi.data_c().end() )
00085 {
00086 say_what = (*i).second ;
00087 }
00088 i = dhi.data_c().find( SAY_TO ) ;
00089 if( i != dhi.data_c().end() )
00090 {
00091 say_to = (*i).second ;
00092 *(_file_buffer) << "\"" << say_what << "\" said to \"" << say_to << "\""
00093 << endl ;
00094 }
00095 }
00096
00104 void
00105 SayReporter::dump( ostream &strm ) const
00106 {
00107 strm << BESIndent::LMarg << "SayReporter::dump - ("
00108 << (void *)this << ")" << endl ;
00109 BESIndent::Indent() ;
00110 strm << BESIndent::LMarg << "Say log name: " << _log_name << endl ;
00111 BESIndent::UnIndent() ;
00112 }
00113