![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbAccess/BdbFileConfig.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: BdbFileConfig.cc,v 1.28 2002/06/21 18:30:19 ryd Exp $ 00004 // 00005 // Description: 00006 // Class BdbFileConfig implementation file. This class represents a 00007 // configuration of disk file systems. 00008 // 00009 // Environment: 00010 // Software developed for the BaBar Detector at the SLAC B-Factory. 00011 // 00012 // Author List: 00013 // David R. Quarrie Original Author 00014 // 00015 // History: 00016 // Jean-Noel Albert Locate a FS by the name of the path 00017 // 00018 //------------------------------------------------------------------------ 00019 //----------------------- 00020 // This Class's Header -- 00021 //----------------------- 00022 #include "BdbAccess/BdbFileConfig.hh" 00023 00024 //------------------------------- 00025 // Collaborating Class Headers -- 00026 //------------------------------- 00027 #ifndef BDBFSGROUP_HH 00028 #include "BdbAccess/BdbFSGroup.hh" 00029 #endif 00030 #ifndef BDBACCESSERRORS_HH 00031 #include "BdbAccess/BdbAccessErrors.hh" 00032 #endif 00033 #ifndef BDBDOMAINSPEC_HH 00034 #include "BdbAccess/BdbDomainSpec.hh" 00035 #endif 00036 #include "BdbAccess/BdbTFileSystem.hh" 00037 #include "BdbAccess/BdbFileSystem.hh" 00038 #include "BdbAccess/BdbTFSGroup.hh" 00039 00040 //------------- 00041 // C Headers -- 00042 //------------- 00043 extern "C" { 00044 #include <assert.h> 00045 #include <stddef.h> 00046 #include <stdio.h> 00047 #include <stdlib.h> 00048 #include <string.h> 00049 #include <unistd.h> 00050 #include <sys/param.h> 00051 } 00052 00053 //--------------- 00054 // C++ Headers -- 00055 //--------------- 00056 #include <fstream.h> 00057 #include <iostream.h> 00058 00059 #include <map> 00060 using std::map; 00061 #include <string> 00062 using std::string; 00063 00064 //----------------------------------------------------------------------- 00065 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00066 //----------------------------------------------------------------------- 00067 00068 static const char rcsid[] = "$Id: BdbFileConfig.cc,v 1.28 2002/06/21 18:30:19 ryd Exp $"; 00069 00070 // ----------------------------------------------- 00071 // -- Static Data & Function Member Definitions -- 00072 // ----------------------------------------------- 00073 00074 BdbHintInit(BdbFileConfig); 00075 00076 const char* BdbFileConfig::_mapName = "fsGroupMap" ; 00077 00078 // ---------------------------------------- 00079 // -- Public Function Member Definitions -- 00080 // ---------------------------------------- 00081 00082 00083 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00084 // 00085 // C O N S T R U C T O R / D E S T R U C T O R 00086 // 00087 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00088 00089 BdbFileConfig::BdbFileConfig() 00090 { 00091 initializeMap() ; 00092 } 00093 00094 00095 BdbFileConfig::BdbFileConfig(BdbFileConfig& obj) 00096 { 00097 _theMap = obj._theMap ; 00098 } 00099 00100 00101 BdbFileConfig::~BdbFileConfig() 00102 {} 00103 00104 00105 BdbStatus BdbFileConfig::initializeMap() 00106 { 00107 BdbHandle(BdbContObj) theHint = ooThis().containedIn() ; 00108 00109 if ( _theMap.lookupObj(theHint, _mapName, oocUpdate) != BdbcSuccess ) 00110 { _theMap = new(theHint) ooMap ; 00111 if ( _theMap == 0 ) 00112 return BdbSignal(BdbcUserError, BdbAccessErrNewFailed, 0, "BdbFileConfig::initializeMap", "ooMap") ; 00113 00114 _theMap.nameObj(theHint, _mapName) ; 00115 } 00116 00117 return BdbcSuccess ; 00118 } 00119 00120 00121 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00122 // 00123 // GETTING SIZE, GROUP NAME, FSGROUP 00124 // 00125 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00126 00127 d_ULong 00128 BdbFileConfig::size(const char* groupName) const 00129 { 00130 BdbHandle(BdbFSGroup) group ; 00131 if ( fsGroup(group, groupName) == 0 ) 00132 { BdbSignal(BdbcUserError, BdbAccessErrRetHNotValid, 0, "BdbFileConfig::size", "fsGroup") ; 00133 return 0 ; 00134 } 00135 00136 return group->size() ; 00137 } 00138 00139 00140 BdbStatus 00141 BdbFileConfig::fsGroup(BdbHandle(BdbFSGroup)& group, const char* fsGroupName) const 00142 { 00143 const char* fn = "BdbFileConfig::fsGroup"; 00144 00145 if ( _theMap == 0 ) { 00146 return BdbSignal(BdbcUserError, BdbAccessErrHandleNotValid, 0, fn); 00147 } 00148 00149 if ( fsGroupName == 0 ) { 00150 return BdbSignal(BdbcUserError, BdbAccessErrNullParameter, 0, fn); 00151 } 00152 00153 _theMap->lookup(fsGroupName, group); 00154 if ( group == 0 ) { 00155 return BdbSignal(BdbcUserError, BdbAccessErrIllegalGroup, 0, fn, fsGroupName); 00156 } 00157 00158 return BdbcSuccess; 00159 } 00160 00161 00162 d_Boolean 00163 BdbFileConfig::isValidGroupName(const char* name) const 00164 { 00165 if ( name == 0 || _theMap == 0 ) 00166 { BdbSignal(BdbcUserError, BdbAccessErrNullParameter, 0, "BdbFileConfig::isValidGroupName") ; 00167 return false ; 00168 } 00169 00170 if ( ! _theMap->isMember(name) ) 00171 { BdbSignal(BdbcUserError, BdbAccessErrGrNameNotValid, 0, "BdbFileConfig::isValidGroupName", name) ; 00172 return false ; 00173 } 00174 00175 return true ; 00176 } 00177 00178 00179 00180 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00181 // 00182 // A D D 00183 // 00184 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00185 00186 BdbStatus 00187 BdbFileConfig::addFS(BdbHandle(BdbFileSystem)& theFileSys, const char* groupName) 00188 { 00189 BdbHandle(BdbFSGroup) group ; 00190 if ( fsGroup(group, groupName) == 0 ) 00191 return BdbSignal(BdbcUserError, BdbAccessErrRetHNotValid, 0, "BdbFileConfig::addFS", "fsGroup") ; 00192 00193 if ( group->add(theFileSys) != BdbcSuccess ) 00194 return BdbSignal(BdbcUserError, BdbAccessErrFunctionFailed, 0, "BdbFileConfig::addFS", "while adding FS") ; 00195 00196 return BdbcSuccess ; 00197 } 00198 00199 00200 BdbStatus BdbFileConfig::addGroup(const char* newGroupName) 00201 { 00202 if ( _theMap == 0 ) 00203 return BdbSignal(BdbcUserError, BdbAccessErrHandleNotValid, 0, "BdbFileConfig::addGroup") ; 00204 00205 if ( newGroupName == 0 ) 00206 return BdbSignal(BdbcUserError, BdbAccessErrNullParameter, 0, "BdbFileConfig::addGroup") ; 00207 00208 if ( _theMap->isMember(newGroupName) ) 00209 return BdbcSuccess ; 00210 00211 BdbRef(BdbFSGroup) groupRef; 00212 BdbHandle(BdbFSGroup) groupH; 00213 groupH = new (BdbFileConfig::clustering()) BdbFSGroup; 00214 groupRef = groupH; 00215 00216 if ( _theMap->add(newGroupName, groupRef) != BdbcSuccess ) 00217 return BdbSignal(BdbcUserError, BdbAccessErrFunctionFailed, 0, "BdbFileConfig::addGroup", "_theMap->add") ; 00218 00219 return BdbcSuccess ; 00220 } 00221 00222 00223 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00224 // 00225 // G E T F S 00226 // 00227 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00228 00229 00230 BdbStatus BdbFileConfig::item(BdbHandle(BdbFileSystem)& theFileSys, d_ULong index, const char* groupName) 00231 { 00232 BdbHandle(BdbFSGroup) group ; 00233 if ( fsGroup(group, groupName) == 0 ) 00234 return BdbSignal(BdbcUserError, BdbAccessErrRetHNotValid, 0, "BdbFileConfig::item", "fsGroup") ; 00235 00236 if ( group->item(theFileSys, index) != BdbcSuccess ) 00237 return BdbSignal(BdbcUserError, BdbAccessErrFunctionFailed, 0, "BdbFileConfig::item", "in fsGroup->item") ; 00238 00239 return BdbcSuccess ; 00240 } 00241 00242 00243 BdbStatus BdbFileConfig::catalogFS(BdbHandle(BdbFileSystem)& theFileSys) 00244 { 00245 if ( item(theFileSys, 0, BdbDomainSpec::_catalogGroupName) != BdbcSuccess ) 00246 return BdbSignal(BdbcUserError, BdbAccessErrFunctionFailed, 0, "BdbFileConfig::catalogFS", "in item") ; 00247 00248 return BdbcSuccess ; 00249 } 00250 00251 00252 BdbStatus BdbFileConfig::lookupFS(BdbTFileSystem& fileSystem, const char* filepath, 00253 const char* host, int port) 00254 { 00255 _theMap.lookupObj(ooThis().containedIn(), _mapName) ; 00256 00257 if ( BdbIsNull(_theMap) ) 00258 return BdbcError; // ASCII file not loaded ? 00259 00260 ooMapItr mapI(_theMap); 00261 BdbHandle(BdbFSGroup) group; 00262 BdbHandle(BdbFileSystem) fs; 00263 00264 while ( mapI.next()) { 00265 group = (const BdbRef(BdbFSGroup)&) mapI->oid(); 00266 00267 d_ULong size = group->size(); 00268 for (d_ULong idx = 0; idx < size; idx++) { 00269 if (BdbcSuccess != group->item(fs, idx)) 00270 break; // Something wrong ?! 00271 00272 // Check if the file matches the file system attributes 00273 if (strncmp(filepath, fs->dirName(), strlen(fs->dirName())) == 0 && 00274 (host == 0 || *host == '\0' || fs->hostEqual(host)) && 00275 (port == 0 || port == fs->portNr())) 00276 { 00277 fileSystem.setDirName(fs->dirName()); 00278 fileSystem.setHostName(fs->hostName()); 00279 fileSystem.setPortNr(fs->portNr()); 00280 fileSystem.setMinDiskSpace(fs->minDiskSpace()); 00281 return BdbcSuccess; 00282 } 00283 } 00284 } 00285 00286 return BdbcError; // No match 00287 } 00288 00289 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00290 // 00291 // D I S P L A Y I N G D A T A 00292 // 00293 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00294 00295 BdbStatus BdbFileConfig::displayData() 00296 { 00297 cout << "\n\nF I L E C O N F I G\n" ; 00298 00299 _theMap.lookupObj(ooThis().containedIn(), _mapName) ; 00300 00301 if ( BdbIsNull(_theMap) ) 00302 return BdbSignal(BdbcUserError, BdbAccessErrMapNotFound, 0, "BdbFileConfig::displayData") ; 00303 00304 ooMapItr mapI(_theMap) ; 00305 00306 BdbRef(BdbFSGroup) group ; 00307 00308 while ( mapI.next()) 00309 { cout << "Group: " << mapI->name() << endl ; // display data 00310 00311 // Fixed by gg 15/10/98 for HP/aCC 00312 BdbRef(ooObj) groupGG = mapI->oid() ; 00313 group = (BdbRef(BdbFSGroup)&) groupGG ; 00314 00315 group->displayData() ; 00316 } 00317 00318 cout << endl ; 00319 00320 return BdbcSuccess ; 00321 } 00322 00323 00324 00325 BdbStatus 00326 BdbFileConfig::initTransient(BdbAuthMap* tDict) 00327 { 00328 ooMapItr mapItr(_theMap); 00329 00330 while ( mapItr.next() ) { 00331 const char* n = mapItr->name(); 00332 BdbRef(ooObj) obj = mapItr->oid() ; 00333 BdbRef(BdbFSGroup) pGroup = (BdbRef(BdbFSGroup)&) obj; 00334 (*tDict)[new string(n)]=new BdbTFSGroup(pGroup); 00335 } 00336 return BdbcSuccess; 00337 } 00338 00339 00340 00341 00342 00343 00344 00345
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002