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 "BESContainer.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 }
00062
00071 void
00072 BESContainerStorageVolatile::look_for( BESContainer &d )
00073 {
00074 d.set_valid_flag( false ) ;
00075
00076 string sym_name = d.get_symbolic_name() ;
00077
00078 BESContainerStorageVolatile::Container_citer i =
00079 _container_list.begin() ;
00080
00081 i = _container_list.find( sym_name ) ;
00082 if( i != _container_list.end() )
00083 {
00084 BESContainer *c = (*i).second ;
00085 d.set_real_name( c->get_real_name() ) ;
00086 d.set_container_type( c->get_container_type() ) ;
00087 d.set_valid_flag( true ) ;
00088 }
00089 }
00090
00091 void
00092 BESContainerStorageVolatile::add_container( const string &s_name,
00093 const string &r_name,
00094 const string &type )
00095 {
00096 if( type == "" )
00097 {
00098 string s = "Unable to add container, type of data must be specified" ;
00099 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00100 }
00101
00102 BESContainerStorageVolatile::Container_citer i =
00103 _container_list.begin() ;
00104
00105 i = _container_list.find( s_name ) ;
00106 if( i != _container_list.end() )
00107 {
00108 string s = (string)"A container with the name " + s_name
00109 + " already exists" ;
00110 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00111 }
00112 string::size_type dotdot = r_name.find( ".." ) ;
00113 if( dotdot != string::npos )
00114 {
00115 string s = (string)"'../' not allowed in container real name " + r_name;
00116 throw BESContainerStorageException( s, __FILE__, __LINE__ ) ;
00117 }
00118 BESContainer *c = new BESContainer( s_name ) ;
00119 string new_r_name = _root_dir + "/" + r_name ;
00120 c->set_real_name( new_r_name ) ;
00121 c->set_container_type( type ) ;
00122 _container_list[s_name] = c ;
00123 }
00124
00133 bool
00134 BESContainerStorageVolatile::del_container( const string &s_name )
00135 {
00136 bool ret = false ;
00137 BESContainerStorageVolatile::Container_iter i ;
00138 i = _container_list.find( s_name ) ;
00139 if( i != _container_list.end() )
00140 {
00141 BESContainer *c = (*i).second;
00142 _container_list.erase( i ) ;
00143 delete c ;
00144 ret = true ;
00145 }
00146 return ret ;
00147 }
00148
00156 bool
00157 BESContainerStorageVolatile::del_containers( )
00158 {
00159 while( _container_list.size() != 0 )
00160 {
00161 Container_iter ci = _container_list.begin() ;
00162 BESContainer *c = (*ci).second ;
00163 _container_list.erase( ci ) ;
00164 if( c )
00165 {
00166 delete c ;
00167 }
00168 }
00169 return true ;
00170 }
00171
00186 void
00187 BESContainerStorageVolatile::show_containers( BESInfo &info )
00188 {
00189 info.add_tag( "name", get_name() ) ;
00190 BESContainerStorageVolatile::Container_iter i = _container_list.begin() ;
00191 for( ; i != _container_list.end(); i++ )
00192 {
00193 info.begin_tag( "container" ) ;
00194 BESContainer *c = (*i).second;
00195 string sym = c->get_symbolic_name() ;
00196 info.add_tag( "symbolicName", sym ) ;
00197 string real = c->get_real_name() ;
00198 info.add_tag( "realName", real ) ;
00199 string type = c->get_container_type() ;
00200 info.add_tag( "dataType", type ) ;
00201 info.end_tag( "container" ) ;
00202 }
00203 }
00204
00212 void
00213 BESContainerStorageVolatile::dump( ostream &strm ) const
00214 {
00215 strm << BESIndent::LMarg << "BESContainerStorageVolatile::dump - ("
00216 << (void *)this << ")" << endl ;
00217 BESIndent::Indent() ;
00218 strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00219 if( _container_list.size() )
00220 {
00221 strm << BESIndent::LMarg << "containers:" << endl ;
00222 BESIndent::Indent() ;
00223 BESContainerStorageVolatile::Container_citer i
00224 = _container_list.begin() ;
00225 BESContainerStorageVolatile::Container_citer ie
00226 = _container_list.end() ;
00227 for( ; i != ie; i++ )
00228 {
00229 BESContainer *c = (*i).second;
00230 c->dump( strm ) ;
00231 }
00232 BESIndent::UnIndent() ;
00233 }
00234 else
00235 {
00236 strm << BESIndent::LMarg << "containers: none" << endl ;
00237 }
00238 BESIndent::UnIndent() ;
00239 }
00240