bes  Updated for version 3.17.0
SayReporter.cc
1 // SayReporter.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "SayReporter.h"
34 #include "TheBESKeys.h"
35 #include "BESInternalError.h"
36 #include "SampleResponseNames.h"
37 
38 SayReporter::SayReporter()
39  : BESReporter(),
40  _file_buffer( 0 )
41 {
42  bool found = false ;
43  TheBESKeys::TheKeys()->get_value( "Say.LogName", _log_name, found );
44  if( _log_name == "" )
45  {
46  throw BESInternalError( "cannot determine Say log name", __FILE__, __LINE__ ) ;
47  }
48  else
49  {
50  _file_buffer = new ofstream( _log_name.c_str(), ios::out | ios::app ) ;
51  if( !(*_file_buffer) )
52  {
53  string s = "cannot open Say log file " + _log_name ;;
54  throw BESInternalError( s, __FILE__, __LINE__ ) ;
55  }
56  }
57 }
58 
59 SayReporter::~SayReporter()
60 {
61  if( _file_buffer )
62  {
63  delete _file_buffer ;
64  _file_buffer = 0 ;
65  }
66 }
67 
68 void
69 SayReporter::report( BESDataHandlerInterface &dhi )
70 {
71  const time_t sctime = time( NULL ) ;
72  const struct tm *sttime = localtime( &sctime ) ;
73  char zone_name[10] ;
74  strftime( zone_name, sizeof( zone_name ), "%Z", sttime ) ;
75  char *b = asctime( sttime ) ;
76  *(_file_buffer) << "[" << zone_name << " " ;
77  for(register int j = 0; b[j] != '\n'; j++ )
78  *(_file_buffer) << b[j] ;
79  *(_file_buffer) << "] " ;
80 
81  string say_what ;
82  string say_to ;
83  BESDataHandlerInterface::data_citer i = dhi.data_c().find( SAY_WHAT ) ;
84  if( i != dhi.data_c().end() )
85  {
86  say_what = (*i).second ;
87  }
88  i = dhi.data_c().find( SAY_TO ) ;
89  if( i != dhi.data_c().end() )
90  {
91  say_to = (*i).second ;
92  *(_file_buffer) << "\"" << say_what << "\" said to \"" << say_to << "\""
93  << endl ;
94  }
95 }
96 
104 void
105 SayReporter::dump( ostream &strm ) const
106 {
107  strm << BESIndent::LMarg << "SayReporter::dump - ("
108  << (void *)this << ")" << endl ;
109  BESIndent::Indent() ;
110  strm << BESIndent::LMarg << "Say log name: " << _log_name << endl ;
111  BESIndent::UnIndent() ;
112 }
113 
exception thrown if inernal error encountered
virtual void dump(ostream &strm) const
dumps information about this object
Definition: SayReporter.cc:105
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: BESKeys.cc:481
Structure storing information used by the BES to handle the request.
static BESKeys * TheKeys()
Definition: TheBESKeys.cc:43