bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 <libdap/InternalErr.h>
30
31#include <BESResponseHandler.h>
32#include <BESResponseNames.h>
33#include <BESVersionInfo.h>
34#include <BESConstraintFuncs.h>
35#include <BESServiceRegistry.h>
36#include <BESUtil.h>
37
38#include "GatewayRequestHandler.h"
39#include "GatewayNames.h"
40
41using std::endl;
42using std::map;
43using std::list;
44using namespace libdap;
45using namespace gateway;
46
47GatewayRequestHandler::GatewayRequestHandler(const string &name) :
49{
50 add_method(VERS_RESPONSE, GatewayRequestHandler::gateway_build_vers);
51 add_method(HELP_RESPONSE, GatewayRequestHandler::gateway_build_help);
52}
53
54GatewayRequestHandler::~GatewayRequestHandler()
55{
56}
57
58bool GatewayRequestHandler::gateway_build_vers(BESDataHandlerInterface &dhi)
59{
60 bool ret = true;
61 BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
62 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
63#if 0
64 info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
65#endif
66 info->add_module(GATEWAY_MODULE, GATEWAY_MODULE_VERSION);
67 return ret;
68}
69
70bool GatewayRequestHandler::gateway_build_help(BESDataHandlerInterface &dhi)
71{
72 bool ret = true;
73 BESInfo *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
74 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
75
76 // This is an example. If you had a help file you could load it like
77 // this and if your handler handled the following responses.
78 map<string, string, std::less<>> attrs;
79 attrs["name"] = GATEWAY_MODULE;
80 attrs["version"] = GATEWAY_MODULE_VERSION;
81#if 0
82 attrs["name"] = PACKAGE_NAME;
83 attrs["version"] = PACKAGE_VERSION;
84#endif
85 list<string> services;
86 BESServiceRegistry::TheRegistry()->services_handled(GATEWAY_MODULE, services);
87 if (services.size() > 0) {
88 string handles = BESUtil::implode(services, ',');
89 attrs["handles"] = handles;
90 }
91 info->begin_tag("module", &attrs);
92 //info->add_data_from_file( "Gateway.Help", "Gateway Help" ) ;
93 info->end_tag("module");
94
95 return ret;
96}
97
99{
100 strm << BESIndent::LMarg << "GatewayRequestHandler::dump - (" << (void *) this << ")" << endl;
101 BESIndent::Indent();
103 BESIndent::UnIndent();
104}
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
static std::string implode(const std::list< std::string > &values, char delim)
Definition BESUtil.cc:620
virtual void dump(std::ostream &strm) const
dumps information about this object
STL class.