00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <iostream>
00034
00035 using std::endl ;
00036
00037 #include "BESContainerStorageList.h"
00038 #include "BESContainerStorage.h"
00039 #include "BESContainerStorageException.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->_next = 0 ;
00088 ret = true ;
00089 }
00090 else
00091 {
00092 BESContainerStorageList::persistence_list *pl = _first ;
00093 bool done = false ;
00094 while( done == false )
00095 {
00096 if( pl->_persistence_obj->get_name() != cp->get_name() )
00097 {
00098 if( pl->_next )
00099 {
00100 pl = pl->_next ;
00101 }
00102 else
00103 {
00104 pl->_next = new BESContainerStorageList::persistence_list ;
00105 pl->_next->_persistence_obj = cp ;
00106 pl->_next->_next = 0 ;
00107 done = true ;
00108 ret = true ;
00109 }
00110 }
00111 else
00112 {
00113 done = true ;
00114 ret = false ;
00115 }
00116 }
00117 }
00118 return ret ;
00119 }
00120
00129 bool
00130 BESContainerStorageList::del_persistence( const string &persist_name )
00131 {
00132 bool ret = false ;
00133 BESContainerStorageList::persistence_list *pl = _first ;
00134 BESContainerStorageList::persistence_list *last = 0 ;
00135
00136 bool done = false ;
00137 while( done == false )
00138 {
00139 if( pl )
00140 {
00141 if( pl->_persistence_obj->get_name() == persist_name )
00142 {
00143 ret = true ;
00144 done = true ;
00145 if( pl == _first )
00146 {
00147 _first = _first->_next ;
00148 }
00149 else
00150 {
00151 last->_next = pl->_next ;
00152 }
00153 delete pl->_persistence_obj ;
00154 delete pl ;
00155 }
00156 else
00157 {
00158 last = pl ;
00159 pl = pl->_next ;
00160 }
00161 }
00162 else
00163 {
00164 done = true ;
00165 }
00166 }
00167
00168 return ret ;
00169 }
00170
00179 BESContainerStorage *
00180 BESContainerStorageList::find_persistence( const string &persist_name )
00181 {
00182 BESContainerStorage *ret = NULL ;
00183 BESContainerStorageList::persistence_list *pl = _first ;
00184 bool done = false ;
00185 while( done == false )
00186 {
00187 if( pl )
00188 {
00189 if( persist_name == pl->_persistence_obj->get_name() )
00190 {
00191 ret = pl->_persistence_obj ;
00192 done = true ;
00193 }
00194 else
00195 {
00196 pl = pl->_next ;
00197 }
00198 }
00199 else
00200 {
00201 done = true ;
00202 }
00203 }
00204 return ret ;
00205 }
00206
00207 bool
00208 BESContainerStorageList::isnice()
00209 {
00210 bool ret = false ;
00211 string key = "BES.Container.Persistence" ;
00212 bool found = false ;
00213 string isnice = TheBESKeys::TheKeys()->get_key( key, found ) ;
00214 if( isnice == "Nice" || isnice == "nice" || isnice == "NICE" )
00215 ret = true ;
00216 else
00217 ret = false ;
00218 return ret ;
00219 }
00220
00242 void
00243 BESContainerStorageList::look_for( BESContainer &d )
00244 {
00245 BESContainerStorageList::persistence_list *pl = _first ;
00246 bool done = false ;
00247 while( done == false )
00248 {
00249 if( pl )
00250 {
00251 pl->_persistence_obj->look_for( d ) ;
00252 if( d.is_valid() )
00253 {
00254 done = true ;
00255 }
00256 else
00257 {
00258 pl = pl->_next ;
00259 }
00260 }
00261 else
00262 {
00263 done = true ;
00264 }
00265 }
00266 if( d.is_valid() == false )
00267 {
00268 if( isnice() )
00269 {
00270 (*BESLog::TheLog()) << "Could not find the symbolic name "
00271 << d.get_symbolic_name().c_str() << endl ;
00272 }
00273 else
00274 {
00275 string s = (string)"Could not find the symbolic name "
00276 + d.get_symbolic_name() ;
00277 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00278 }
00279 }
00280 }
00281
00294 void
00295 BESContainerStorageList::show_containers( BESInfo &info )
00296 {
00297 BESContainerStorageList::persistence_list *pl = _first ;
00298 while( pl )
00299 {
00300 info.begin_tag( "store" ) ;
00301 pl->_persistence_obj->show_containers( info ) ;
00302 info.end_tag( "store" ) ;
00303 pl = pl->_next ;
00304 }
00305 }
00306
00314 void
00315 BESContainerStorageList::dump( ostream &strm ) const
00316 {
00317 strm << BESIndent::LMarg << "BESContainerStorageList::dump - ("
00318 << (void *)this << ")" << endl ;
00319 BESIndent::Indent() ;
00320 BESContainerStorageList::persistence_list *pl = _first ;
00321 if( pl )
00322 {
00323 strm << BESIndent::LMarg << "container storage:" << endl ;
00324 BESIndent::Indent() ;
00325 while( pl )
00326 {
00327 pl->_persistence_obj->dump( strm ) ;
00328 pl = pl->_next ;
00329 }
00330 BESIndent::UnIndent() ;
00331 }
00332 else
00333 {
00334 strm << BESIndent::LMarg << "container storage: empty" << endl ;
00335 }
00336 BESIndent::UnIndent() ;
00337 }
00338
00339 BESContainerStorageList *
00340 BESContainerStorageList::TheList()
00341 {
00342 if( _instance == 0 )
00343 {
00344 _instance = new BESContainerStorageList ;
00345 }
00346 return _instance ;
00347 }
00348