bes Updated for version 3.20.13
NgapRequestHandler.cc
1// NgapContainer.cc
2
3// -*- mode: c++; c-basic-offset:4 -*-
4
5// This file is part of ngap_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) 2020 OPeNDAP, Inc.
9// Author: Nathan Potter <ndp@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
29#include "config.h"
30
31#include <libdap/InternalErr.h>
32
33#include <BESResponseHandler.h>
34#include <BESResponseNames.h>
35#include <BESVersionInfo.h>
36#include <BESTextInfo.h>
37#include "BESDapNames.h"
38#include "BESDataDDSResponse.h"
39#include "BESDDSResponse.h"
40#include "BESDASResponse.h"
41#include <BESConstraintFuncs.h>
42#include <BESServiceRegistry.h>
43#include <BESUtil.h>
44
45#include "NgapRequestHandler.h"
46#include "NgapNames.h"
47
48using std::endl;
49using std::map;
50using std::list;
51using namespace libdap;
52using namespace ngap;
53
54NgapRequestHandler::NgapRequestHandler(const string &name) :
56{
57 add_method(VERS_RESPONSE, NgapRequestHandler::ngap_build_vers);
58 add_method(HELP_RESPONSE, NgapRequestHandler::ngap_build_help);
59}
60
61NgapRequestHandler::~NgapRequestHandler()
62{
63}
64
65bool NgapRequestHandler::ngap_build_vers(BESDataHandlerInterface &dhi)
66{
67 bool ret = true;
68 BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(dhi.response_handler->get_response_object());
69 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESVersionInfo instance");
70#if 0
71 info->add_module(PACKAGE_NAME, PACKAGE_VERSION);
72#endif
73 info->add_module(MODULE_NAME, MODULE_VERSION);
74 return ret;
75}
76
77bool NgapRequestHandler::ngap_build_help(BESDataHandlerInterface &dhi)
78{
79 bool ret = true;
80 BESInfo *info = dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
81 if (!info) throw InternalErr(__FILE__, __LINE__, "Expected a BESInfo instance");
82
83 // This is an example. If you had a help file you could load it like
84 // this and if your handler handled the following responses.
85 map<string, string> attrs;
86 attrs["name"] = MODULE_NAME;
87 attrs["version"] = MODULE_VERSION;
88#if 0
89 attrs["name"] = PACKAGE_NAME;
90 attrs["version"] = PACKAGE_VERSION;
91#endif
92 list<string> services;
93 BESServiceRegistry::TheRegistry()->services_handled(NGAP_NAME, services);
94 if (services.size() > 0) {
95 string handles = BESUtil::implode(services, ',');
96 attrs["handles"] = handles;
97 }
98 info->begin_tag("module", &attrs);
99 //info->add_data_from_file( "Ngap.Help", "Ngap Help" ) ;
100 info->end_tag("module");
101
102 return ret;
103}
104
105void NgapRequestHandler::dump(ostream &strm) const
106{
107 strm << BESIndent::LMarg << "NgapRequestHandler::dump - (" << (void *) this << ")" << endl;
108 BESIndent::Indent();
110 BESIndent::UnIndent();
111}
Structure storing information used by the BES to handle the request.
informational response object
Definition: BESInfo.h:63
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:617
virtual void dump(std::ostream &strm) const
dumps information about this object