SayReporter.cc

Go to the documentation of this file.
00001 // SayReporter.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
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 

Generated on Sat Aug 22 06:06:22 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.0