bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
BuildDmrppRequestHandler.cc
1// BuildDmrppRequestHandler.cc
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of builddmrpp_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) 2023 OPeNDAP, Inc.
9// Author: Daniel Holloway <dholloway@opendap.org>
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// Authors:
27// ndp Nathan Potter <ndp@opendap.org>
28// dan Daniel Holloway <dholloway@opendap.org>
29
30#include "config.h"
31
32#include <string>
33#include <ostream>
34
35#include <libdap/InternalErr.h>
36
37#include <BESResponseHandler.h>
38#include <BESResponseNames.h>
39#include <BESVersionInfo.h>
40#include <BESServiceRegistry.h>
41#include <BESUtil.h>
42
43#include "BuildDmrppRequestHandler.h"
44#include "NgapNames.h"
45
46using std::endl;
47using std::map;
48using std::list;
49using namespace libdap;
50using namespace builddmrpp;
51
52BuildDmrppRequestHandler::BuildDmrppRequestHandler(const string &name) :
54{
55 add_method(VERS_RESPONSE, BuildDmrppRequestHandler::mkdmrpp_build_vers);
56 add_method(HELP_RESPONSE, BuildDmrppRequestHandler::mkdmrpp_build_help);
57}
58
59bool BuildDmrppRequestHandler::mkdmrpp_build_vers(BESDataHandlerInterface &dhi)
60{
61 bool ret = true;
62 auto *info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
63 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
64 info->add_module(MODULE_NAME, MODULE_VERSION);
65 return ret;
66}
67
68bool BuildDmrppRequestHandler::mkdmrpp_build_help(BESDataHandlerInterface &dhi)
69{
70 bool ret = true;
71 auto *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
72 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
73
74 // This is an example. If you had a help file you could load it like
75 // this and if your handler handled the following responses.
76 map<string, string, std::less<>> attrs;
77 attrs["name"] = MODULE_NAME;
78 attrs["version"] = MODULE_VERSION;
79 list<string> services;
80 BESServiceRegistry::TheRegistry()->services_handled(NGAP_NAME, services);
81 if (!services.empty()) {
82 string handles = BESUtil::implode(services, ',');
83 attrs["handles"] = handles;
84 }
85 info->begin_tag("module", &attrs);
86 info->end_tag("module");
87
88 return ret;
89}
90
92{
93 strm << BESIndent::LMarg << "BuildDmrppRequestHandler::dump - (" << (void *) this << ")" << endl;
94 BESIndent::Indent();
96 BESIndent::UnIndent();
97}
Structure storing information used by the BES to handle the request.
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
void dump(std::ostream &strm) const override
dumps information about this object
STL class.