00001 // BESResponseHandlerList.cc 00002 00003 // This file is part of bes, A C++ back-end server implementation framework 00004 // for the OPeNDAP Data Access Protocol. 00005 00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research 00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu> 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 // You can contact University Corporation for Atmospheric Research at 00024 // 3080 Center Green Drive, Boulder, CO 80301 00025 00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005 00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR. 00028 // 00029 // Authors: 00030 // pwest Patrick West <pwest@ucar.edu> 00031 // jgarcia Jose Garcia <jgarcia@ucar.edu> 00032 00033 #include "BESResponseHandlerList.h" 00034 00035 BESResponseHandlerList *BESResponseHandlerList::_instance = 0 ; 00036 00051 bool 00052 BESResponseHandlerList::add_handler( const string &handler_name, 00053 p_response_handler handler_method ) 00054 { 00055 BESResponseHandlerList::Handler_citer i ; 00056 i = _handler_list.find( handler_name ) ; 00057 if( i == _handler_list.end() ) 00058 { 00059 _handler_list[handler_name] = handler_method ; 00060 return true ; 00061 } 00062 return false ; 00063 } 00064 00074 bool 00075 BESResponseHandlerList::remove_handler( const string &handler_name ) 00076 { 00077 BESResponseHandlerList::Handler_iter i ; 00078 i = _handler_list.find( handler_name ) ; 00079 if( i != _handler_list.end() ) 00080 { 00081 _handler_list.erase( i ) ; 00082 return true ; 00083 } 00084 return false ; 00085 } 00086 00099 BESResponseHandler * 00100 BESResponseHandlerList::find_handler( const string &handler_name ) 00101 { 00102 BESResponseHandlerList::Handler_citer i ; 00103 i = _handler_list.find( handler_name ) ; 00104 if( i != _handler_list.end() ) 00105 { 00106 p_response_handler p = (*i).second ; 00107 if( p ) 00108 { 00109 return p( handler_name ) ; 00110 } 00111 } 00112 return 0 ; 00113 } 00114 00122 string 00123 BESResponseHandlerList::get_handler_names() 00124 { 00125 string ret ; 00126 bool first_name = true ; 00127 BESResponseHandlerList::Handler_citer i = _handler_list.begin() ; 00128 for( ; i != _handler_list.end(); i++ ) 00129 { 00130 if( !first_name ) 00131 ret += ", " ; 00132 ret += (*i).first ; 00133 first_name = false ; 00134 } 00135 return ret ; 00136 } 00137 00145 void 00146 BESResponseHandlerList::dump( ostream &strm ) const 00147 { 00148 strm << BESIndent::LMarg << "BESResponseHandlerList::dump - (" 00149 << (void *)this << ")" << endl ; 00150 BESIndent::Indent() ; 00151 if( _handler_list.size() ) 00152 { 00153 strm << BESIndent::LMarg << "registered response handlers:" << endl ; 00154 BESIndent::Indent() ; 00155 BESResponseHandlerList::Handler_citer i = _handler_list.begin() ; 00156 BESResponseHandlerList::Handler_citer ie = _handler_list.end() ; 00157 for( ; i != ie; i++ ) 00158 { 00159 strm << BESIndent::LMarg << (*i).first << endl ; 00160 } 00161 BESIndent::UnIndent() ; 00162 } 00163 else 00164 { 00165 strm << BESIndent::LMarg << "registered response handlers: none" << endl ; 00166 } 00167 BESIndent::UnIndent() ; 00168 } 00169 00170 BESResponseHandlerList * 00171 BESResponseHandlerList::TheList() 00172 { 00173 if( _instance == 0 ) 00174 { 00175 _instance = new BESResponseHandlerList ; 00176 } 00177 return _instance ; 00178 } 00179