bes  Updated for version 3.20.6
GatewayRequestHandler.cc
1 // GatewayRequestHandler.cc
2 
3 // -*- mode: c++; c-basic-offset:4 -*-
4 
5 // This file is part of gateway_module, A C++ module that can be loaded in to
6 // the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
7 
8 // Copyright (c) 2002,2003 OPeNDAP, Inc.
9 // Author: Patrick West <pwest@ucar.edu>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 #include "config.h"
28 
29 #include <InternalErr.h>
30 
31 #include <BESResponseHandler.h>
32 #include <BESResponseNames.h>
33 #include <BESVersionInfo.h>
34 #include <BESTextInfo.h>
35 #include "BESDapNames.h"
36 #include "BESDataDDSResponse.h"
37 #include "BESDDSResponse.h"
38 #include "BESDASResponse.h"
39 #include <BESConstraintFuncs.h>
40 #include <BESServiceRegistry.h>
41 #include <BESUtil.h>
42 
43 #include "GatewayRequestHandler.h"
44 #include "GatewayResponseNames.h"
45 
46 using std::endl;
47 using std::map;
48 using std::list;
49 using namespace libdap;
50 using namespace gateway;
51 
52 GatewayRequestHandler::GatewayRequestHandler(const string &name) :
53  BESRequestHandler(name)
54 {
55  add_method(VERS_RESPONSE, GatewayRequestHandler::gateway_build_vers);
56  add_method(HELP_RESPONSE, GatewayRequestHandler::gateway_build_help);
57 }
58 
59 GatewayRequestHandler::~GatewayRequestHandler()
60 {
61 }
62 
63 bool GatewayRequestHandler::gateway_build_vers(BESDataHandlerInterface &dhi)
64 {
65  bool ret = true;
66  BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
67  if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
68 #if 0
69  info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
70 #endif
71  info->add_module(MODULE_NAME, MODULE_VERSION);
72  return ret;
73 }
74 
75 bool GatewayRequestHandler::gateway_build_help(BESDataHandlerInterface &dhi)
76 {
77  bool ret = true;
78  BESInfo *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
79  if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
80 
81  // This is an example. If you had a help file you could load it like
82  // this and if your handler handled the following responses.
83  map<string, string> attrs;
84  attrs["name"] = MODULE_NAME;
85  attrs["version"] = MODULE_VERSION;
86 #if 0
87  attrs["name"] = PACKAGE_NAME;
88  attrs["version"] = PACKAGE_VERSION;
89 #endif
90  list<string> services;
91  BESServiceRegistry::TheRegistry()->services_handled(Gateway_NAME, services);
92  if (services.size() > 0) {
93  string handles = BESUtil::implode(services, ',');
94  attrs["handles"] = handles;
95  }
96  info->begin_tag("module", &attrs);
97  //info->add_data_from_file( "Gateway.Help", "Gateway Help" ) ;
98  info->end_tag("module");
99 
100  return ret;
101 }
102 
103 void GatewayRequestHandler::dump(ostream &strm) const
104 {
105  strm << BESIndent::LMarg << "GatewayRequestHandler::dump - (" << (void *) this << ")" << endl;
106  BESIndent::Indent();
108  BESIndent::UnIndent();
109 }
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
BESServiceRegistry::services_handled
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
Definition: BESServiceRegistry.cc:334
BESInfo
informational response object
Definition: BESInfo.h:63
libdap
Definition: BESDapFunctionResponseCache.h:35
BESResponseHandler::get_response_object
virtual BESResponseObject * get_response_object()
return the current response object
Definition: BESResponseHandler.cc:82
BESVersionInfo
Definition: BESVersionInfo.h:47
BESRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESRequestHandler.cc:163
BESUtil::implode
static std::string implode(const std::list< std::string > &values, char delim)
Definition: BESUtil.cc:638
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
gateway::GatewayRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: GatewayRequestHandler.cc:103