bes  Updated for version 3.17.4
BESResponseHandlerList.cc
1 // BESResponseHandlerList.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 "BESResponseHandlerList.h"
34 
35 BESResponseHandlerList *BESResponseHandlerList::_instance = 0 ;
36 
51 bool
52 BESResponseHandlerList::add_handler( const string &handler_name,
53  p_response_handler handler_method )
54 {
55  BESResponseHandlerList::Handler_citer i ;
56  i = _handler_list.find( handler_name ) ;
57  if( i == _handler_list.end() )
58  {
59  _handler_list[handler_name] = handler_method ;
60  return true ;
61  }
62  return false ;
63 }
64 
74 bool
75 BESResponseHandlerList::remove_handler( const string &handler_name )
76 {
77  BESResponseHandlerList::Handler_iter i ;
78  i = _handler_list.find( handler_name ) ;
79  if( i != _handler_list.end() )
80  {
81  _handler_list.erase( i ) ;
82  return true ;
83  }
84  return false ;
85 }
86 
100 BESResponseHandlerList::find_handler( const string &handler_name )
101 {
102  BESResponseHandlerList::Handler_citer i ;
103  i = _handler_list.find( handler_name ) ;
104  if( i != _handler_list.end() )
105  {
106  p_response_handler p = (*i).second ;
107  if( p )
108  {
109  return p( handler_name ) ;
110  }
111  }
112  return 0 ;
113 }
114 
122 string
124 {
125  string ret = "";
126  bool first_name = true ;
127  BESResponseHandlerList::Handler_citer i = _handler_list.begin() ;
128  for( ; i != _handler_list.end(); i++ )
129  {
130  if( !first_name )
131  ret += ", " ;
132  ret += (*i).first ;
133  first_name = false ;
134  }
135  return ret ;
136 }
137 
145 void
146 BESResponseHandlerList::dump( ostream &strm ) const
147 {
148  strm << BESIndent::LMarg << "BESResponseHandlerList::dump - ("
149  << (void *)this << ")" << endl ;
150  BESIndent::Indent() ;
151  if( _handler_list.size() )
152  {
153  strm << BESIndent::LMarg << "registered response handlers:" << endl ;
154  BESIndent::Indent() ;
155  BESResponseHandlerList::Handler_citer i = _handler_list.begin() ;
156  BESResponseHandlerList::Handler_citer ie = _handler_list.end() ;
157  for( ; i != ie; i++ )
158  {
159  strm << BESIndent::LMarg << (*i).first << endl ;
160  }
161  BESIndent::UnIndent() ;
162  }
163  else
164  {
165  strm << BESIndent::LMarg << "registered response handlers: none" << endl ;
166  }
167  BESIndent::UnIndent() ;
168 }
169 
171 BESResponseHandlerList::TheList()
172 {
173  if( _instance == 0 )
174  {
175  _instance = new BESResponseHandlerList ;
176  }
177  return _instance ;
178 }
179 
virtual BESResponseHandler * find_handler(const string &handler)
returns the response handler with the given name from the list
virtual string get_handler_names()
returns the comma separated list of all response handlers currently registered with this server...
List of all registered response handlers for this server.
handler object that knows how to create a specific response object
virtual bool add_handler(const string &handler, p_response_handler handler_method)
add a response handler to the list
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool remove_handler(const string &handler)
removes a response handler from the list