bes  Updated for version 3.20.6
BESUsageRequestHandler.cc
1 // BESUsageRequestHandler.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 
34 #include "../usage/BESUsageRequestHandler.h"
35 
36 #include "BESResponseHandler.h"
37 #include "BESResponseNames.h"
38 #include "BESVersionInfo.h"
39 #include "BESDataNames.h"
40 #include "config.h"
41 
42 using std::endl;
43 using std::ostream;
44 using std::string;
45 using std::map;
46 
47 BESUsageRequestHandler::BESUsageRequestHandler( const string &name )
48  : BESRequestHandler( name )
49 {
50  add_method( HELP_RESPONSE, BESUsageRequestHandler::dap_build_help ) ;
51  add_method( VERS_RESPONSE, BESUsageRequestHandler::dap_build_version ) ;
52 }
53 
54 BESUsageRequestHandler::~BESUsageRequestHandler()
55 {
56 }
57 
58 bool
59 BESUsageRequestHandler::dap_build_help( BESDataHandlerInterface &dhi )
60 {
61  BESResponseObject *response = dhi.response_handler->get_response_object() ;
62  BESInfo *info = dynamic_cast < BESInfo * >(response) ;
63  if( !info )
64  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
65 
66  map<string,string> attrs ;
67  attrs["name"] = PACKAGE_NAME ;
68  attrs["version"] = PACKAGE_VERSION ;
69  info->begin_tag( "module", &attrs ) ;
70  info->add_data_from_file( "DAP-SERVER.Help", "Dap server Help" ) ;
71  info->end_tag( "module" ) ;
72 
73  return true ;
74 }
75 
76 bool
77 BESUsageRequestHandler::dap_build_version( BESDataHandlerInterface &dhi )
78 {
79  BESResponseObject *response = dhi.response_handler->get_response_object() ;
80  BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response) ;
81  if( !info )
82  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
83 
84  info->add_module( MODULE_NAME, MODULE_VERSION ) ;
85 
86  return true ;
87 }
88 
95 void
96 BESUsageRequestHandler::dump( ostream &strm ) const
97 {
98  strm << BESIndent::LMarg << "BESUsageRequestHandler::dump - ("
99  << (void *)this << ")" << endl ;
100  BESIndent::Indent() ;
101  BESRequestHandler::dump( strm ) ;
102  BESIndent::UnIndent() ;
103 }
104 
BESRequestHandler
Represents a specific data type request handler.
Definition: BESRequestHandler.h:74
BESInfo
informational response object
Definition: BESInfo.h:63
BESInfo::add_data_from_file
virtual void add_data_from_file(const std::string &key, const std::string &name)
add data from a file to the informational object.
Definition: BESInfo.cc:182
BESResponseHandler::get_response_object
virtual BESResponseObject * get_response_object()
return the current response object
Definition: BESResponseHandler.cc:82
BESVersionInfo
Definition: BESVersionInfo.h:47
BESInternalError
exception thrown if internal error encountered
Definition: BESInternalError.h:43
BESUsageRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESUsageRequestHandler.cc:96
BESRequestHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESRequestHandler.cc:163
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESResponseObject
Abstract base class representing a specific set of information in response to a request to the BES.
Definition: BESResponseObject.h:45