OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESRequestHandler.cc
Go to the documentation of this file.
1 // BESRequestHandler.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "BESRequestHandler.h"
34 
50 bool
51 BESRequestHandler::add_handler( const string &handler_name,
52  p_request_handler handler_method )
53 {
54  if( find_handler( handler_name ) == 0 )
55  {
56  _handler_list[handler_name] = handler_method ;
57  return true ;
58  }
59  return false ;
60 }
61 
69 bool
70 BESRequestHandler::remove_handler( const string &handler_name )
71 {
73  i = _handler_list.find( handler_name ) ;
74  if( i != _handler_list.end() )
75  {
76  _handler_list.erase( i ) ;
77  return true ;
78  }
79  return false ;
80 }
81 
93 BESRequestHandler::find_handler( const string &handler_name )
94 {
96  i = _handler_list.find( handler_name ) ;
97  if( i != _handler_list.end() )
98  {
99  return (*i).second;
100  }
101  return 0 ;
102 }
103 
111 string
113 {
114  string ret ;
115  bool first_name = true ;
116  BESRequestHandler::Handler_citer i = _handler_list.begin() ;
117  for( ; i != _handler_list.end(); i++ )
118  {
119  if( !first_name )
120  ret += ", " ;
121  ret += (*i).first ;
122  first_name = false ;
123  }
124  return ret ;
125 }
126 
134 void
135 BESRequestHandler::dump( ostream &strm ) const
136 {
137  strm << BESIndent::LMarg << "BESRequestHandler::dump - ("
138  << (void *)this << ")" << endl ;
140  strm << BESIndent::LMarg << "name: " << _name << endl ;
141  if( _handler_list.size() )
142  {
143  strm << BESIndent::LMarg << "registered handler functions:" << endl ;
145  BESRequestHandler::Handler_citer i = _handler_list.begin() ;
146  BESRequestHandler::Handler_citer ie = _handler_list.end() ;
147  for( ; i != ie; i++ )
148  {
149  strm << BESIndent::LMarg << (*i).first << endl ;
150  }
152  }
153  else
154  {
155  strm << BESIndent::LMarg << "registered handler functions: none" << endl ;
156  }
158 }
159 
virtual string get_handler_names()
return a comma separated list of response object types handled by this request handler ...
map< string, p_request_handler >::const_iterator Handler_citer
bool(* p_request_handler)(BESDataHandlerInterface &)
static void Indent()
Definition: BESIndent.cc:38
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual bool add_handler(const string &handler_name, p_request_handler handler_method)
add a handler method to the request handler that knows how to fill in a specific response object ...
map< string, p_request_handler >::iterator Handler_iter
static void UnIndent()
Definition: BESIndent.cc:44
virtual bool remove_handler(const string &handler_name)
remove the specified handler method from this request handler
virtual void dump(ostream &strm) const
dumps information about this object
virtual p_request_handler find_handler(const string &handler_name)
find the method that can handle the specified response object type