bes  Updated for version 3.20.6
DapFunctionsRequestHandler.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 //
3 // DapFunctionsRequestHandler.cc
4 //
5 // This file is part of BES DAP Functions module
6 //
7 // Copyright (c) 2016 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #include "config.h"
27 
28 #include "BESResponseHandler.h" // Used to access the DataHandlerInterface
29 #include "BESResponseNames.h" // for {HELP,VER}_RESPONSE constants
30 #include "BESDataHandlerInterface.h" // Used to get the Info object
31 #include "BESVersionInfo.h" // Includes BESInfo too
32 
33 #include "TheBESKeys.h" // A BES Key can be used to supply help info
34 
35 #include "DapFunctionsRequestHandler.h"
36 
37 using std::endl;
38 using std::ostream;
39 using std::string;
40 using std::map;
41 
51  BESRequestHandler(name)
52 {
55 }
56 
65 {
66  BESResponseObject *response = dhi.response_handler->get_response_object();
67  BESInfo *info = dynamic_cast<BESInfo *>(response);
68  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
69 
70  bool found = false;
71  string key = "BES.functions.Reference";
72  string ref;
73  TheBESKeys::TheKeys()->get_value(key, ref, found);
74  if (ref.empty()) ref = "http://docs.opendap.org/index.php/Server_Side_Processing_Functions";
75 
76  map<string, string> attrs;
77  attrs["name"] = MODULE_NAME;
78  attrs["version"] = MODULE_VERSION;
79  attrs["reference"] = ref;
80 
81  info->begin_tag("module", &attrs);
82  info->end_tag("module");
83 
84  return true;
85 }
86 
95 {
96  BESResponseObject *response = dhi.response_handler->get_response_object();
97  BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(response);
98  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
99 
100  info->add_module(MODULE_NAME, MODULE_VERSION);
101 
102  return true;
103 }
104 
111 void DapFunctionsRequestHandler::dump(ostream &strm) const
112 {
113  strm << BESIndent::LMarg << "DapFunctionsRequestHandler::dump - (" << (void *) this << ")" << endl;
114  BESIndent::Indent();
116  BESIndent::UnIndent();
117 }
118 
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
DapFunctionsRequestHandler::DapFunctionsRequestHandler
DapFunctionsRequestHandler(const std::string &name)
Constructor for FileOut NetCDF module.
Definition: DapFunctionsRequestHandler.cc:50
DapFunctionsRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: DapFunctionsRequestHandler.cc:111
BESInfo
informational response object
Definition: BESInfo.h:63
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
TheBESKeys::TheKeys
static TheBESKeys * TheKeys()
Definition: TheBESKeys.cc:62
BESResponseHandler::get_response_object
virtual BESResponseObject * get_response_object()
return the current response object
Definition: BESResponseHandler.cc:82
BESVersionInfo
Definition: BESVersionInfo.h:47
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
TheBESKeys::get_value
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: TheBESKeys.cc:272
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
DapFunctionsRequestHandler::build_version
static bool build_version(BESDataHandlerInterface &dhi)
add version information to a version response
Definition: DapFunctionsRequestHandler.cc:94
BESResponseObject
Abstract base class representing a specific set of information in response to a request to the BES.
Definition: BESResponseObject.h:45
DapFunctionsRequestHandler::build_help
static bool build_help(BESDataHandlerInterface &dhi)
Provides information for the DAP functions help request.
Definition: DapFunctionsRequestHandler.cc:64