bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
38SayReporter::SayReporter() :
39 BESReporter(), _file_buffer(0)
40{
41 bool found = false;
42 TheBESKeys::TheKeys()->get_value("Say.LogName", _log_name, found);
43 if (_log_name == "") {
44 throw BESInternalError("cannot determine Say log name", __FILE__, __LINE__);
45 }
46 else {
47 _file_buffer = new ofstream(_log_name.c_str(), ios::out | ios::app);
48 if (!(*_file_buffer)) {
49 string s = "cannot open Say log file " + _log_name;
50 ;
51 throw BESInternalError(s, __FILE__, __LINE__);
52 }
53 }
54}
55
56SayReporter::~SayReporter()
57{
58 if (_file_buffer) {
59 delete _file_buffer;
60 _file_buffer = 0;
61 }
62}
63
64void SayReporter::report(BESDataHandlerInterface &dhi)
65{
66 const time_t sctime = time( NULL);
67 const struct tm *sttime = localtime(&sctime);
68 char zone_name[10];
69 strftime(zone_name, sizeof(zone_name), "%Z", sttime);
70 char *b = asctime(sttime);
71 *(_file_buffer) << "[" << zone_name << " ";
72 for (register int j = 0; b[j] != '\n'; j++)
73 *(_file_buffer) << b[j];
74 *(_file_buffer) << "] ";
75
76 string say_what;
77 string say_to;
78 BESDataHandlerInterface::data_citer i = dhi.data_c().find( SAY_WHAT);
79 if (i != dhi.data_c().end()) {
80 say_what = (*i).second;
81 }
82 i = dhi.data_c().find( SAY_TO);
83 if (i != dhi.data_c().end()) {
84 say_to = (*i).second;
85 *(_file_buffer) << "\"" << say_what << "\" said to \"" << say_to << "\"" << endl;
86 }
87}
88
96void SayReporter::dump(ostream &strm) const
97{
98 strm << BESIndent::LMarg << "SayReporter::dump - (" << (void *) this << ")" << endl;
99 BESIndent::Indent();
100 strm << BESIndent::LMarg << "Say log name: " << _log_name << endl;
101 BESIndent::UnIndent();
102}
103
Structure storing information used by the BES to handle the request.
exception thrown if internal error encountered
virtual void dump(std::ostream &strm) const
dumps information about this object
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
Definition TheBESKeys.cc:85
STL class.
STL class.