bes  Updated for version 3.20.6
BESRequestHandler.cc
1 // BESRequestHandler.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 <sys/stat.h>
34 #include <string.h>
35 
36 #include "BESRequestHandler.h"
37 #include "BESNotFoundError.h"
38 
39 using std::endl;
40 using std::ostream;
41 using std::string;
42 
58 bool BESRequestHandler::add_method(const string &handler_name, p_request_handler_method handler_method)
59 {
60  if (find_method(handler_name) == 0) {
61  _handler_list[handler_name] = handler_method;
62  return true;
63  }
64  return false;
65 }
66 
74 bool BESRequestHandler::remove_method(const string &handler_name)
75 {
76  BESRequestHandler::Handler_iter i;
77  i = _handler_list.find(handler_name);
78  if (i != _handler_list.end()) {
79  _handler_list.erase(i);
80  return true;
81  }
82  return false;
83 }
84 
95 p_request_handler_method BESRequestHandler::find_method(const string &handler_name)
96 {
97  BESRequestHandler::Handler_citer i;
98  i = _handler_list.find(handler_name);
99  if (i != _handler_list.end()) {
100  return (*i).second;
101  }
102  return 0;
103 }
104 
113 {
114  string ret = "";
115  bool first_name = true;
116  BESRequestHandler::Handler_citer i = _handler_list.begin();
117  for (; i != _handler_list.end(); i++) {
118  if (!first_name) ret += ", ";
119  ret += (*i).first;
120  first_name = false;
121  }
122  return ret;
123 }
124 
133 time_t BESRequestHandler::get_lmt(const string &name){
134 // 5/31/19 - SBL - Initial code
135 // 6/03/19 - SBL - using BESUtil::pathConcat and throws BESNotFoundError
136  // Get the bes catalog root path from the conf info
137  //string root_dir = TheBESKeys::TheKeys()->read_string_key("BES.Catalog.catalog.RootDirectory", "");
138  // Get the name's LMT from the file system
139  //string filepath = BESUtil::pathConcat(root_dir, name, '/');
140  struct stat statbuf;
141  if (stat(name.c_str(), &statbuf) == -1){
142  //perror(filepath);
143  throw BESNotFoundError(strerror(errno), __FILE__, __LINE__);
144  }//end if
145 
146  return statbuf.st_mtime;
147 }//end get_lmt()
148 
149 void BESRequestHandler::add_attributes(BESDataHandlerInterface &dhi){
150 
151  // The current implementation ensures the execution of this function in the derived class.
152  // So will throw an error if code comes here. KY 10/30/19
153  throw BESNotFoundError("Cannot find the add_attributes() in the specific handler.", __FILE__, __LINE__);
154 }
155 
163 void BESRequestHandler::dump(ostream &strm) const
164 {
165  strm << BESIndent::LMarg << "BESRequestHandler::dump - (" << (void *) this << ")" << endl;
166  BESIndent::Indent();
167  strm << BESIndent::LMarg << "name: " << _name << endl;
168  if (_handler_list.size()) {
169  strm << BESIndent::LMarg << "registered handler functions:" << endl;
170  BESIndent::Indent();
171  BESRequestHandler::Handler_citer i = _handler_list.begin();
172  BESRequestHandler::Handler_citer ie = _handler_list.end();
173  for (; i != ie; i++) {
174  strm << BESIndent::LMarg << (*i).first << endl;
175  }
176  BESIndent::UnIndent();
177  }
178  else {
179  strm << BESIndent::LMarg << "registered handler functions: none" << endl;
180  }
181  BESIndent::UnIndent();
182 }
183 
BESRequestHandler::find_method
virtual p_request_handler_method find_method(const std::string &name)
find the method that can handle the specified response object type
Definition: BESRequestHandler.cc:95
BESNotFoundError
error thrown if the resource requested cannot be found
Definition: BESNotFoundError.h:40
BESRequestHandler::get_method_names
virtual std::string get_method_names()
return a comma separated list of response object types handled by this request handler
Definition: BESRequestHandler.cc:112
BESRequestHandler::remove_method
virtual bool remove_method(const std::string &name)
remove the specified handler method from this request handler
Definition: BESRequestHandler.cc:74
BESRequestHandler::add_method
virtual bool add_method(const std::string &name, p_request_handler_method method)
add a handler method to the request handler that knows how to fill in a specific response object
Definition: BESRequestHandler.cc:58
BESRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESRequestHandler.cc:163
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESRequestHandler::get_lmt
virtual time_t get_lmt(const std::string &name)
Get the Last modified time for.
Definition: BESRequestHandler.cc:133