![]() |
|
|
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/BdbTFileSystem.cc
Go to the documentation of this file.00001 //------------------------------------------------------------------------ 00002 // 00003 // Description: 00004 // Class BdbTFileSystem implementation file. This transient class 00005 // represents a disk file system. 00006 // 00007 // Environment: 00008 // Software developed for the BaBar Detector at the SLAC B-Factory. 00009 // 00010 // Author List: 00011 // David R. Quarrie Original Author 00012 // Jacek Becla 00013 // 00014 // History: 00015 // 00016 //------------------------------------------------------------------------ 00017 //----------------------- 00018 // This Class's Header -- 00019 //----------------------- 00020 #ifndef BDBTFILESYSTEM_HH 00021 #include "BdbAccess/BdbTFileSystem.hh" 00022 #endif 00023 00024 //------------------------------- 00025 // Collaborating Class Headers -- 00026 //------------------------------- 00027 #ifndef BDBACCESSERRORS_HH 00028 #include "BdbAccess/BdbAccessErrors.hh" 00029 #endif 00030 00031 //------------- 00032 // C Headers -- 00033 //------------- 00034 extern "C" { 00035 #include <assert.h> 00036 #include <stddef.h> 00037 #include <stdio.h> 00038 #include <stdlib.h> 00039 #include <string.h> 00040 #include <strings.h> 00041 #include <unistd.h> 00042 #include <sys/param.h> 00043 } 00044 00045 // Network data structure & host query 00046 extern "C" { 00047 #include <arpa/inet.h> 00048 #include <netdb.h> 00049 #include <sys/utsname.h> 00050 } 00051 00052 //--------------- 00053 // C++ Headers -- 00054 //--------------- 00055 #include <fstream.h> 00056 #include <iostream.h> 00057 00058 //---------------------------------------- 00059 //-- Public Function Member Definitions -- 00060 //---------------------------------------- 00061 00062 //--------------- 00063 // Constructor -- 00064 //--------------- 00065 00066 BdbTFileSystem::BdbTFileSystem( const char* const theDirName, 00067 const char* const theHostName, 00068 d_ULong theMinDiskSpace, 00069 d_Short thePortNr ) 00070 { 00071 if ( 0 != theDirName ) { 00072 _dirName.resize(strlen(theDirName)+1); 00073 _dirName = theDirName; 00074 } 00075 00076 00077 if ( 0 != theHostName ) { 00078 _hostName.resize(strlen(theHostName)+1); 00079 _hostName = theHostName; 00080 } 00081 00082 _minDiskSpace = theMinDiskSpace ; // Set to 0 if not specified (default parameter) 00083 // It happens if fs configuration is unavailable. 00084 // In this case space availability is not checked at all. 00085 _portNr = thePortNr ; // Set to 0 if not specified (default parameter) 00086 } 00087 00088 00089 BdbTFileSystem::BdbTFileSystem(const BdbTFileSystem& obj) 00090 { 00091 const char* n = obj._dirName.head(); 00092 if ( 0 != n ) { 00093 _dirName.resize(strlen(n)+1); 00094 _dirName = n; 00095 } 00096 00097 n = obj._hostName.head(); 00098 if ( 0 != n ) { 00099 _hostName.resize(strlen(n)+1); 00100 _hostName = n; 00101 } 00102 00103 _minDiskSpace = obj._minDiskSpace; 00104 _portNr = obj._portNr; 00105 } 00106 00107 00108 //-------------- 00109 // Destructor -- 00110 //-------------- 00111 00112 BdbTFileSystem::~BdbTFileSystem( ) 00113 {} 00114 00115 //------------- 00116 // Selectors -- 00117 //------------- 00118 00119 const char* 00120 BdbTFileSystem::dirName( ) const 00121 { 00122 return _dirName.head() ; 00123 } 00124 00125 const char* 00126 BdbTFileSystem::hostName( ) const 00127 { 00128 return _hostName.head() ; 00129 } 00130 00131 d_Short 00132 BdbTFileSystem::portNr( ) const 00133 { 00134 return _portNr; 00135 } 00136 00137 d_ULong 00138 BdbTFileSystem::minDiskSpace( ) const 00139 { 00140 return _minDiskSpace ; 00141 } 00142 00143 //------------- 00144 // Modifiers -- 00145 //------------- 00146 00147 void 00148 BdbTFileSystem::setDirName( const char* const theDirName ) 00149 { 00150 _dirName = theDirName; 00151 } 00152 00153 void 00154 BdbTFileSystem::setHostName( const char* const theHostName ) 00155 { 00156 _hostName = theHostName; 00157 } 00158 00159 void 00160 BdbTFileSystem::setPortNr( d_Short thePortNr ) 00161 { 00162 _portNr = thePortNr; 00163 } 00164 00165 void 00166 BdbTFileSystem::setMinDiskSpace( d_ULong theMin ) 00167 { 00168 _minDiskSpace = theMin; 00169 } 00170 00171 // ---------- 00172 // Display -- 00173 // ---------- 00174 00175 BdbStatus 00176 BdbTFileSystem::displayData() 00177 { 00178 cout << " " << hostName() << "::" << dirName() << " portNr=" << portNr() << " minDiskSpace=" << minDiskSpace() << endl ; // display data 00179 00180 return BdbcSuccess ; 00181 } 00182 00183 void 00184 BdbTFileSystem::print(ostream& o, int noSpaces) const 00185 { 00186 char* theSpace = new char [noSpaces+1]; 00187 memset(theSpace, ' ', noSpaces); 00188 *(theSpace+noSpaces)='\0'; 00189 00190 o << theSpace << "hostName = " << hostName() << "\n" 00191 << theSpace << "dirName = " << dirName() << "\n" 00192 << theSpace << "port = " << portNr() << "\n" 00193 << theSpace << "minDiskSpace = " << minDiskSpace() << endl; 00194 00195 delete [] theSpace; 00196 } 00197 00198 00199 00200 00201 d_Boolean BdbTFileSystem::hostEqual(const char* host) const 00202 { 00203 return hostEqual(_hostName, host); 00204 } 00205 00206 d_Boolean BdbTFileSystem::hostEqual(const char* h1, const char* h2) 00207 { 00208 if ((h1 == 0 || *h1 == '\0') && (h2 == 0 || *h2 == '\0')) 00209 return d_True; // ? 00210 00211 else if (h1 == 0 || *h1 == '\0' || h2 == 0 || *h2 == '\0') 00212 return d_False; 00213 00214 char host1[128]; 00215 struct hostent* hent1 = gethostbyname(h1); 00216 if (0 != hent1) 00217 strcpy(host1, hent1->h_name); 00218 else 00219 host1[0] = 0; 00220 00221 char host2[128]; 00222 struct hostent* hent2 = gethostbyname(h2); 00223 if (0 != hent2) 00224 strcpy(host2, hent2->h_name); 00225 else 00226 host2[0] = 0; 00227 00228 if (0 == host1[0] && 0 == host2[0]) 00229 return (strcasecmp(h1, h2) == 0); 00230 00231 else if (0 != host1[0] && 0 != host2[0]) 00232 return (strcasecmp(host1, host2) == 0); 00233 00234 return d_False; 00235 } 00236 00237 const char* BdbTFileSystem::localHostName() 00238 { 00239 static char localhost[128]; 00240 if (0 == localhost[0]) { 00241 struct utsname ubuffer; 00242 if (uname(&ubuffer) >= 0) { 00243 struct hostent* hent = gethostbyname(ubuffer.nodename); 00244 if (hent == 0) 00245 strcpy(localhost, ubuffer.nodename); 00246 else 00247 strcpy(localhost, hent->h_name); 00248 } 00249 } 00250 00251 return localhost; 00252 }
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002