00001 // BESReporterList.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 "BESReporterList.h" 00034 #include "BESReporter.h" 00035 00036 BESReporterList *BESReporterList::_instance = 0 ; 00037 00038 BESReporterList::BESReporterList() 00039 { 00040 } 00041 00042 BESReporterList::~BESReporterList() 00043 { 00044 BESReporter *reporter = 0 ; 00045 BESReporterList::Reporter_iter i = _reporter_list.begin() ; 00046 for( ; i != _reporter_list.end(); i++ ) 00047 { 00048 reporter = (*i).second ; 00049 if( reporter ) delete reporter ; 00050 _reporter_list.erase( i ) ; 00051 } 00052 } 00053 00054 bool 00055 BESReporterList::add_reporter( string reporter_name, 00056 BESReporter *reporter_object ) 00057 { 00058 if( find_reporter( reporter_name ) == 0 ) 00059 { 00060 _reporter_list[reporter_name] = reporter_object ; 00061 return true ; 00062 } 00063 return false ; 00064 } 00065 00066 BESReporter * 00067 BESReporterList::remove_reporter( string reporter_name ) 00068 { 00069 BESReporter *ret = 0 ; 00070 BESReporterList::Reporter_iter i ; 00071 i = _reporter_list.find( reporter_name ) ; 00072 if( i != _reporter_list.end() ) 00073 { 00074 ret = (*i).second; 00075 _reporter_list.erase( i ) ; 00076 } 00077 return ret ; 00078 } 00079 00080 BESReporter * 00081 BESReporterList::find_reporter( string reporter_name ) 00082 { 00083 BESReporterList::Reporter_citer i ; 00084 i = _reporter_list.find( reporter_name ) ; 00085 if( i != _reporter_list.end() ) 00086 { 00087 return (*i).second; 00088 } 00089 return 0 ; 00090 } 00091 00092 void 00093 BESReporterList::report( BESDataHandlerInterface &dhi ) 00094 { 00095 BESReporter *reporter = 0 ; 00096 BESReporterList::Reporter_iter i = _reporter_list.begin() ; 00097 for( ; i != _reporter_list.end(); i++ ) 00098 { 00099 reporter = (*i).second ; 00100 if( reporter ) reporter->report( dhi ) ; 00101 } 00102 } 00103 00111 void 00112 BESReporterList::dump( ostream &strm ) const 00113 { 00114 strm << BESIndent::LMarg << "BESReporterList::dump - (" 00115 << (void *)this << ")" << endl ; 00116 BESIndent::Indent() ; 00117 if( _reporter_list.size() ) 00118 { 00119 strm << BESIndent::LMarg << "registered reporters:" << endl ; 00120 BESIndent::Indent() ; 00121 BESReporterList::Reporter_citer i = _reporter_list.begin() ; 00122 BESReporterList::Reporter_citer ie = _reporter_list.end() ; 00123 for( ; i != ie; i++ ) 00124 { 00125 strm << BESIndent::LMarg << "reporter: " << (*i).first << endl ; 00126 BESIndent::Indent() ; 00127 BESReporter *reporter = (*i).second ; 00128 reporter->dump( strm ) ; 00129 BESIndent::UnIndent() ; 00130 } 00131 BESIndent::UnIndent() ; 00132 } 00133 else 00134 { 00135 strm << BESIndent::LMarg << "registered reporters: none" << endl ; 00136 } 00137 BESIndent::UnIndent() ; 00138 } 00139 00140 BESReporterList * 00141 BESReporterList::TheList() 00142 { 00143 if( _instance == 0 ) 00144 { 00145 _instance = new BESReporterList ; 00146 } 00147 return _instance ; 00148 } 00149