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 "BESContainerStorageVolatile.h"
00034 #include "BESFileContainer.h"
00035 #include "BESContainerStorageException.h"
00036 #include "BESInfo.h"
00037 #include "TheBESKeys.h"
00038
00046 BESContainerStorageVolatile::BESContainerStorageVolatile( const string &n )
00047 : BESContainerStorage( n )
00048 {
00049 string base_key = "BES.Data.RootDirectory" ;
00050 bool found = false ;
00051 _root_dir = TheBESKeys::TheKeys()->get_key( base_key, found ) ;
00052 if( _root_dir == "" )
00053 {
00054 string s = base_key + " not defined in bes configuration file" ;
00055 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00056 }
00057 }
00058
00059 BESContainerStorageVolatile::~BESContainerStorageVolatile()
00060 {
00061 del_containers() ;
00062 }
00063
00073 BESContainer *
00074 BESContainerStorageVolatile::look_for( const string &sym_name )
00075 {
00076 BESContainer *ret_container = 0 ;
00077
00078 BESContainerStorageVolatile::Container_citer i ;
00079 i = _container_list.find( sym_name ) ;
00080 if( i != _container_list.end() )
00081 {
00082 BESContainer *c = (*i).second ;
00083 ret_container = c->ptr_duplicate() ;
00084 }
00085
00086 return ret_container ;
00087 }
00088
00104 void
00105 BESContainerStorageVolatile::add_container( const string &sym_name,
00106 const string &real_name,
00107 const string &type )
00108 {
00109 if( type == "" )
00110 {
00111 string s = "Unable to add container, type of data must be specified" ;
00112 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00113 }
00114
00115 BESContainerStorageVolatile::Container_citer i ;
00116 i = _container_list.find( sym_name ) ;
00117 if( i != _container_list.end() )
00118 {
00119 string s = (string)"A container with the name "
00120 + sym_name
00121 + " already exists" ;
00122 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00123 }
00124 string new_r_name = _root_dir + "/" + real_name ;
00125 BESContainer *c = new BESFileContainer( sym_name, new_r_name, type ) ;
00126 _container_list[sym_name] = c ;
00127 }
00128
00146 void
00147 BESContainerStorageVolatile::add_container( BESContainer *c )
00148 {
00149 if( !c )
00150 {
00151 string s = "Unable to add container, container passed is null" ;
00152 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00153 }
00154 if( c->get_container_type() == "" )
00155 {
00156 string s = "Unable to add container, type of data must be specified" ;
00157 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00158 }
00159 string sym_name = c->get_symbolic_name() ;
00160 BESContainerStorageVolatile::Container_citer i ;
00161 i = _container_list.find( sym_name ) ;
00162 if( i != _container_list.end() )
00163 {
00164 string s = (string)"A container with the name "
00165 + sym_name
00166 + " already exists" ;
00167 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00168 }
00169 _container_list[sym_name] = c ;
00170 }
00171
00178 bool
00179 BESContainerStorageVolatile::del_container( const string &s_name )
00180 {
00181 bool ret = false ;
00182 BESContainerStorageVolatile::Container_iter i ;
00183 i = _container_list.find( s_name ) ;
00184 if( i != _container_list.end() )
00185 {
00186 BESContainer *c = (*i).second;
00187 _container_list.erase( i ) ;
00188 delete c ;
00189 ret = true ;
00190 }
00191 return ret ;
00192 }
00193
00201 bool
00202 BESContainerStorageVolatile::del_containers( )
00203 {
00204 while( _container_list.size() != 0 )
00205 {
00206 Container_iter ci = _container_list.begin() ;
00207 BESContainer *c = (*ci).second ;
00208 _container_list.erase( ci ) ;
00209 if( c )
00210 {
00211 delete c ;
00212 }
00213 }
00214 return true ;
00215 }
00216
00231 void
00232 BESContainerStorageVolatile::show_containers( BESInfo &info )
00233 {
00234 info.add_tag( "name", get_name() ) ;
00235 BESContainerStorageVolatile::Container_iter i = _container_list.begin() ;
00236 for( ; i != _container_list.end(); i++ )
00237 {
00238 info.begin_tag( "container" ) ;
00239 BESContainer *c = (*i).second;
00240 string sym = c->get_symbolic_name() ;
00241 info.add_tag( "symbolicName", sym ) ;
00242 string real = c->get_real_name() ;
00243 info.add_tag( "realName", real ) ;
00244 string type = c->get_container_type() ;
00245 info.add_tag( "dataType", type ) ;
00246 info.end_tag( "container" ) ;
00247 }
00248 }
00249
00257 void
00258 BESContainerStorageVolatile::dump( ostream &strm ) const
00259 {
00260 strm << BESIndent::LMarg << "BESContainerStorageVolatile::dump - ("
00261 << (void *)this << ")" << endl ;
00262 BESIndent::Indent() ;
00263 strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00264 if( _container_list.size() )
00265 {
00266 strm << BESIndent::LMarg << "containers:" << endl ;
00267 BESIndent::Indent() ;
00268 BESContainerStorageVolatile::Container_citer i
00269 = _container_list.begin() ;
00270 BESContainerStorageVolatile::Container_citer ie
00271 = _container_list.end() ;
00272 for( ; i != ie; i++ )
00273 {
00274 BESContainer *c = (*i).second;
00275 c->dump( strm ) ;
00276 }
00277 BESIndent::UnIndent() ;
00278 }
00279 else
00280 {
00281 strm << BESIndent::LMarg << "containers: none" << endl ;
00282 }
00283 BESIndent::UnIndent() ;
00284 }
00285