bes  Updated for version 3.20.5
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 namespace libdap;
47 using namespace gateway;
48 
49 GatewayRequestHandler::GatewayRequestHandler(const string &name) :
50  BESRequestHandler(name)
51 {
52  add_method(VERS_RESPONSE, GatewayRequestHandler::gateway_build_vers);
53  add_method(HELP_RESPONSE, GatewayRequestHandler::gateway_build_help);
54 }
55 
56 GatewayRequestHandler::~GatewayRequestHandler()
57 {
58 }
59 
60 bool GatewayRequestHandler::gateway_build_vers(BESDataHandlerInterface &dhi)
61 {
62  bool ret = true;
63  BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
64  if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
65 #if 0
66  info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
67 #endif
68  info->add_module(MODULE_NAME, MODULE_VERSION);
69  return ret;
70 }
71 
72 bool GatewayRequestHandler::gateway_build_help(BESDataHandlerInterface &dhi)
73 {
74  bool ret = true;
75  BESInfo *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
76  if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
77 
78  // This is an example. If you had a help file you could load it like
79  // this and if your handler handled the following responses.
80  map<string, string> attrs;
81  attrs["name"] = MODULE_NAME;
82  attrs["version"] = MODULE_VERSION;
83 #if 0
84  attrs["name"] = PACKAGE_NAME;
85  attrs["version"] = PACKAGE_VERSION;
86 #endif
87  list<string> services;
88  BESServiceRegistry::TheRegistry()->services_handled(Gateway_NAME, services);
89  if (services.size() > 0) {
90  string handles = BESUtil::implode(services, ',');
91  attrs["handles"] = handles;
92  }
93  info->begin_tag("module", &attrs);
94  //info->add_data_from_file( "Gateway.Help", "Gateway Help" ) ;
95  info->end_tag("module");
96 
97  return ret;
98 }
99 
100 void GatewayRequestHandler::dump(ostream &strm) const
101 {
102  strm << BESIndent::LMarg << "GatewayRequestHandler::dump - (" << (void *) this << ")" << endl;
103  BESIndent::Indent();
105  BESIndent::UnIndent();
106 }
informational response object
Definition: BESInfo.h:68
static string implode(const list< string > &values, char delim)
Definition: BESUtil.cc:635
virtual BESResponseObject * get_response_object()
return the current response object
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question