bes  Updated for version 3.17.4
SampleRequestHandler.cc
1 // SampleRequestHandler.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-2009 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 #include "config.h"
34 
35 #include "SampleRequestHandler.h"
36 #include "BESResponseHandler.h"
37 #include "BESResponseNames.h"
38 #include "SampleResponseNames.h"
39 #include "BESVersionInfo.h"
40 #include "BESTextInfo.h"
41 #include "BESConstraintFuncs.h"
42 #include "BESInternalError.h"
43 
44 SampleRequestHandler::SampleRequestHandler( const string &name )
45  : BESRequestHandler( name )
46 {
47  add_handler( VERS_RESPONSE, SampleRequestHandler::sample_build_vers ) ;
48  add_handler( HELP_RESPONSE, SampleRequestHandler::sample_build_help ) ;
49 }
50 
51 SampleRequestHandler::~SampleRequestHandler()
52 {
53 }
54 
55 bool
56 SampleRequestHandler::sample_build_vers( BESDataHandlerInterface &dhi )
57 {
58  bool ret = true ;
59 
60  BESResponseObject *response =
61  dhi.response_handler->get_response_object();
62  BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response);
63  if( !info )
64  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
65  info->add_module( PACKAGE_NAME, PACKAGE_VERSION ) ;
66 
67  return ret ;
68 }
69 
70 bool
71 SampleRequestHandler::sample_build_help( BESDataHandlerInterface &dhi )
72 {
73  bool ret = true ;
74 
75  BESResponseObject *response =
76  dhi.response_handler->get_response_object() ;
77  BESInfo *info = dynamic_cast< BESInfo * >( response ) ;
78  if( !info )
79  throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
80 
81  map<string,string> attrs ;
82  attrs["name"] = PACKAGE_NAME ;
83  attrs["version"] = PACKAGE_VERSION ;
84  info->begin_tag( "module", &attrs ) ;
85  info->add_data_from_file( "Sample.Help", "Sample Help" ) ;
86  info->end_tag( "module" ) ;
87 
88  return ret ;
89 }
90 
91 void
92 SampleRequestHandler::dump( ostream &strm ) const
93 {
94  strm << BESIndent::LMarg << "SampleRequestHandler::dump - ("
95  << (void *)this << ")" << endl ;
96  BESIndent::Indent() ;
97  BESRequestHandler::dump( strm ) ;
98  BESIndent::UnIndent() ;
99 }
100 
exception thrown if inernal error encountered
virtual void add_data_from_file(const string &key, const string &name)
add data from a file to the informational object.
Definition: BESInfo.cc:170
informational response object
Definition: BESInfo.h:68
virtual BESResponseObject * get_response_object()
return the current response object
Represents a specific data type request handler.
virtual void dump(ostream &strm) const
dumps information about this object
Structure storing information used by the BES to handle the request.
virtual void dump(ostream &strm) const
dumps information about this object
Abstract base class representing a specific set of information in response to a request to the BES...