bes  Updated for version 3.19.1
BESRequestHandler.cc
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., 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 "BESRequestHandler.h"
34 
50 bool BESRequestHandler::add_handler(const string &handler_name, p_request_handler handler_method)
51 {
52  if (find_handler(handler_name) == 0) {
53  _handler_list[handler_name] = handler_method;
54  return true;
55  }
56  return false;
57 }
58 
66 bool BESRequestHandler::remove_handler(const string &handler_name)
67 {
68  BESRequestHandler::Handler_iter i;
69  i = _handler_list.find(handler_name);
70  if (i != _handler_list.end()) {
71  _handler_list.erase(i);
72  return true;
73  }
74  return false;
75 }
76 
87 p_request_handler BESRequestHandler::find_handler(const string &handler_name)
88 {
89  BESRequestHandler::Handler_citer i;
90  i = _handler_list.find(handler_name);
91  if (i != _handler_list.end()) {
92  return (*i).second;
93  }
94  return 0;
95 }
96 
105 {
106  string ret = "";
107  bool first_name = true;
108  BESRequestHandler::Handler_citer i = _handler_list.begin();
109  for (; i != _handler_list.end(); i++) {
110  if (!first_name) ret += ", ";
111  ret += (*i).first;
112  first_name = false;
113  }
114  return ret;
115 }
116 
124 void BESRequestHandler::dump(ostream &strm) const
125 {
126  strm << BESIndent::LMarg << "BESRequestHandler::dump - (" << (void *) this << ")" << endl;
127  BESIndent::Indent();
128  strm << BESIndent::LMarg << "name: " << _name << endl;
129  if (_handler_list.size()) {
130  strm << BESIndent::LMarg << "registered handler functions:" << endl;
131  BESIndent::Indent();
132  BESRequestHandler::Handler_citer i = _handler_list.begin();
133  BESRequestHandler::Handler_citer ie = _handler_list.end();
134  for (; i != ie; i++) {
135  strm << BESIndent::LMarg << (*i).first << endl;
136  }
137  BESIndent::UnIndent();
138  }
139  else {
140  strm << BESIndent::LMarg << "registered handler functions: none" << endl;
141  }
142  BESIndent::UnIndent();
143 }
144 
virtual string get_handler_names()
return a comma separated list of response object types handled by this request handler
virtual void dump(ostream &strm) const
dumps information about this object
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
virtual bool remove_handler(const string &handler_name)
remove the specified handler method from this request handler
virtual p_request_handler find_handler(const string &handler_name)
find the method that can handle the specified response object type