OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
00001 // BESContainerStorageList.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 <iostream> 00034 00035 using std::endl ; 00036 00037 #include "BESContainerStorageList.h" 00038 #include "BESContainerStorage.h" 00039 #include "BESSyntaxUserError.h" 00040 #include "BESContainer.h" 00041 #include "TheBESKeys.h" 00042 #include "BESLog.h" 00043 #include "BESInfo.h" 00044 00045 BESContainerStorageList *BESContainerStorageList::_instance = 0 ; 00046 00047 BESContainerStorageList::BESContainerStorageList() 00048 : _first( 0 ) 00049 { 00050 } 00051 00052 BESContainerStorageList::~BESContainerStorageList() 00053 { 00054 BESContainerStorageList::persistence_list *pl = _first ; 00055 while( pl ) 00056 { 00057 if( pl->_persistence_obj ) 00058 { 00059 delete pl->_persistence_obj ; 00060 } 00061 BESContainerStorageList::persistence_list *next = pl->_next ; 00062 delete pl ; 00063 pl = next ; 00064 } 00065 } 00066 00079 bool 00080 BESContainerStorageList::add_persistence( BESContainerStorage *cp ) 00081 { 00082 bool ret = false ; 00083 if( !_first ) 00084 { 00085 _first = new BESContainerStorageList::persistence_list ; 00086 _first->_persistence_obj = cp ; 00087 _first->_reference = 1 ; 00088 _first->_next = 0 ; 00089 ret = true ; 00090 } 00091 else 00092 { 00093 BESContainerStorageList::persistence_list *pl = _first ; 00094 bool done = false ; 00095 while( done == false ) 00096 { 00097 if( pl->_persistence_obj->get_name() != cp->get_name() ) 00098 { 00099 if( pl->_next ) 00100 { 00101 pl = pl->_next ; 00102 } 00103 else 00104 { 00105 pl->_next = new BESContainerStorageList::persistence_list ; 00106 pl->_next->_reference = 1 ; 00107 pl->_next->_persistence_obj = cp ; 00108 pl->_next->_next = 0 ; 00109 done = true ; 00110 ret = true ; 00111 } 00112 } 00113 else 00114 { 00115 done = true ; 00116 ret = false ; 00117 } 00118 } 00119 } 00120 return ret ; 00121 } 00122 00133 bool 00134 BESContainerStorageList::ref_persistence( const string &persist_name ) 00135 { 00136 bool ret = false ; 00137 BESContainerStorageList::persistence_list *pl = _first ; 00138 00139 bool done = false ; 00140 while( done == false ) 00141 { 00142 if( pl ) 00143 { 00144 if( pl->_persistence_obj && 00145 pl->_persistence_obj->get_name() == persist_name ) 00146 { 00147 done = true ; 00148 ret = true ; 00149 pl->_reference++ ; 00150 } 00151 else 00152 { 00153 pl = pl->_next ; 00154 } 00155 } 00156 else 00157 { 00158 done = true ; 00159 } 00160 } 00161 return ret ; 00162 } 00163 00176 bool 00177 BESContainerStorageList::deref_persistence( const string &persist_name ) 00178 { 00179 bool ret = false ; 00180 BESContainerStorageList::persistence_list *pl = _first ; 00181 BESContainerStorageList::persistence_list *last = 0 ; 00182 00183 bool done = false ; 00184 while( done == false ) 00185 { 00186 if( pl ) 00187 { 00188 if( pl->_persistence_obj && 00189 pl->_persistence_obj->get_name() == persist_name ) 00190 { 00191 ret = true ; 00192 done = true ; 00193 pl->_reference-- ; 00194 if( !pl->_reference ) 00195 { 00196 if( pl == _first ) 00197 { 00198 _first = _first->_next ; 00199 } 00200 else 00201 { 00202 if (!last) 00203 throw BESInternalError("ContainerStorageList last is null", __FILE__, __LINE__); 00204 last->_next = pl->_next ; 00205 } 00206 delete pl->_persistence_obj ; 00207 delete pl ; 00208 pl = 0 ; 00209 } 00210 } 00211 else 00212 { 00213 last = pl ; 00214 pl = pl->_next ; 00215 } 00216 } 00217 else 00218 { 00219 done = true ; 00220 } 00221 } 00222 00223 return ret ; 00224 } 00225 00234 BESContainerStorage * 00235 BESContainerStorageList::find_persistence( const string &persist_name ) 00236 { 00237 BESContainerStorage *ret = NULL ; 00238 BESContainerStorageList::persistence_list *pl = _first ; 00239 bool done = false ; 00240 while( done == false ) 00241 { 00242 if( pl ) 00243 { 00244 if( persist_name == pl->_persistence_obj->get_name() ) 00245 { 00246 ret = pl->_persistence_obj ; 00247 done = true ; 00248 } 00249 else 00250 { 00251 pl = pl->_next ; 00252 } 00253 } 00254 else 00255 { 00256 done = true ; 00257 } 00258 } 00259 return ret ; 00260 } 00261 00262 bool 00263 BESContainerStorageList::isnice() 00264 { 00265 bool ret = false ; 00266 string key = "BES.Container.Persistence" ; 00267 bool found = false ; 00268 string isnice ; 00269 TheBESKeys::TheKeys()->get_value( key, isnice, found ) ; 00270 if( isnice == "Nice" || isnice == "nice" || isnice == "NICE" ) 00271 ret = true ; 00272 else 00273 ret = false ; 00274 return ret ; 00275 } 00276 00300 BESContainer * 00301 BESContainerStorageList::look_for( const string &sym_name ) 00302 { 00303 BESContainer *ret_container = 0 ; 00304 BESContainerStorageList::persistence_list *pl = _first ; 00305 bool done = false ; 00306 while( done == false ) 00307 { 00308 if( pl ) 00309 { 00310 ret_container = pl->_persistence_obj->look_for( sym_name ) ; 00311 if( ret_container ) 00312 { 00313 done = true ; 00314 } 00315 else 00316 { 00317 pl = pl->_next ; 00318 } 00319 } 00320 else 00321 { 00322 done = true ; 00323 } 00324 } 00325 if( !ret_container ) 00326 { 00327 if( isnice() ) 00328 { 00329 (*BESLog::TheLog()) << "Could not find the symbolic name " 00330 << sym_name << endl ; 00331 } 00332 else 00333 { 00334 string s = (string)"Could not find the symbolic name " 00335 + sym_name ; 00336 throw BESSyntaxUserError( s, __FILE__, __LINE__ ) ; 00337 } 00338 } 00339 00340 return ret_container ; 00341 } 00342 00355 void 00356 BESContainerStorageList::show_containers( BESInfo &info ) 00357 { 00358 BESContainerStorageList::persistence_list *pl = _first ; 00359 while( pl ) 00360 { 00361 map<string,string> props ; 00362 props["name"] = pl->_persistence_obj->get_name() ; 00363 info.begin_tag( "store", &props ) ; 00364 pl->_persistence_obj->show_containers( info ) ; 00365 info.end_tag( "store" ) ; 00366 pl = pl->_next ; 00367 } 00368 } 00369 00377 void 00378 BESContainerStorageList::dump( ostream &strm ) const 00379 { 00380 strm << BESIndent::LMarg << "BESContainerStorageList::dump - (" 00381 << (void *)this << ")" << endl ; 00382 BESIndent::Indent() ; 00383 BESContainerStorageList::persistence_list *pl = _first ; 00384 if( pl ) 00385 { 00386 strm << BESIndent::LMarg << "container storage:" << endl ; 00387 BESIndent::Indent() ; 00388 while( pl ) 00389 { 00390 pl->_persistence_obj->dump( strm ) ; 00391 pl = pl->_next ; 00392 } 00393 BESIndent::UnIndent() ; 00394 } 00395 else 00396 { 00397 strm << BESIndent::LMarg << "container storage: empty" << endl ; 00398 } 00399 BESIndent::UnIndent() ; 00400 } 00401 00402 BESContainerStorageList * 00403 BESContainerStorageList::TheList() 00404 { 00405 if( _instance == 0 ) 00406 { 00407 _instance = new BESContainerStorageList ; 00408 } 00409 return _instance ; 00410 } 00411