Thread: [Compbench-devel] CompBenchmarks++/libcompbenchmarks/System System.cpp, 1.1, 1.2 System-Cygwin.cpp,
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-25 15:38:59
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv7814 Modified Files: System.cpp System-Cygwin.cpp System-Cygwin.h System-FreeBSD.cpp System-FreeBSD.h System.h System-Linux.cpp System-Linux.h System-Unix.cpp System-Unix.h Log Message: CBM::Config used to handle package related data. Index: System-Cygwin.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Cygwin.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Cygwin.cpp 22 Jan 2007 17:50:39 -0000 1.1 --- System-Cygwin.cpp 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 12,17 **** #include <config.h> /* !!! */ ! SystemCygwin::SystemCygwin() ! : SystemUnix() { std::string cmd = "cscript.exe /nologo systemInfo.wmi"; --- 12,17 ---- #include <config.h> /* !!! */ ! SystemCygwin::SystemCygwin(std::string _filename) ! : SystemUnix(_filename) { std::string cmd = "cscript.exe /nologo systemInfo.wmi"; Index: System-Cygwin.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Cygwin.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Cygwin.h 22 Jan 2007 17:50:40 -0000 1.1 --- System-Cygwin.h 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 25,29 **** public: /** Constructor */ ! SystemCygwin(); /** Returns processor name --- 25,29 ---- public: /** Constructor */ ! SystemCygwin(std::string _filename = ""); /** Returns processor name Index: System-Linux.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Linux.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Linux.cpp 22 Jan 2007 17:50:41 -0000 1.1 --- System-Linux.cpp 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 14,19 **** using namespace CBM; ! SystemLinux::SystemLinux() ! : SystemUnix() { } --- 14,19 ---- using namespace CBM; ! SystemLinux::SystemLinux(std::string _filename) ! : SystemUnix(_filename) { } Index: System.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System.h 22 Jan 2007 17:50:40 -0000 1.1 --- System.h 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 27,54 **** class System { public: /** Temporary directory. * Defines typedef used to query temporary directories used by CompBenchmarks. */ ! typedef enum Temp { Root, /*!< Root directory */ ! HostDep, /*!< Prefix for host-dependend directory */ ! Extract, /*!< Archive extraction temporary directory */ ! Patches, /*!< Directory holding patches */ ! OS, /*!< System specific material */ ! Download, /*!< Downloads temporary directory */ ! Status, /*!< Directory holding status of packages and ! * benchmarks */ ! Configuration /*!< Directory for configuration related ! * informations */ }; private: - /** Check if the given directory holds patches. - * Check if given arguments holds patches needed by libcompbenchmarks. - * \param dir directory to check - * \return non-null if ok. - */ - virtual int verifyPatchDirectory(std::string dir); - protected: /** \sa Packages() */ --- 27,47 ---- class System { + protected: + class Config *configuration; + std::string configurationFile; + public: /** Temporary directory. * Defines typedef used to query temporary directories used by CompBenchmarks. */ ! typedef enum Dir { Root, /*!< Root directory */ ! HostDep, /*!< Prefix for host-dependend directory */ ! Extract, /*!< Archive extraction temporary directory */ ! Patches, /*!< Directory holding patches */ ! OS, /*!< System specific material */ ! Download /*!< Downloads temporary directory */ }; private: protected: /** \sa Packages() */ *************** *** 61,66 **** std::string lastCommandOutput; ! /** Constructor. */ ! System(); /** Virtual destructor */ virtual ~System(); --- 54,61 ---- std::string lastCommandOutput; ! /** Constructor. ! * \param _filename XML configuration file. ~/.compbenchmarks/compbenchmarks.xml is used by default. ! */ ! System(std::string _filename = ""); /** Virtual destructor */ virtual ~System(); *************** *** 81,85 **** \return 1 if ok. */ ! virtual int CheckDirectory(Temp where); public: --- 76,80 ---- \return 1 if ok. */ ! virtual int CheckDirectory(Dir where); public: *************** *** 91,94 **** --- 86,98 ---- virtual int init(void); + /** Get used configuration. + \return A configuration instance (CBM::Config) + */ + class Config *Config(void); + + virtual int storeConfiguration(void); + + virtual std::string env(std::string _var); + /** Get host ID * As hostid command does on UNIX. *************** *** 248,252 **** * \return an absolute directory name */ ! virtual std::string temporaryDirectory(Temp where); /** Removes (unlink) a file --- 252,256 ---- * \return an absolute directory name */ ! virtual std::string Directory(Dir where); /** Removes (unlink) a file *************** *** 256,274 **** virtual int unlink(std::string localfile) = 0; - /** Stores an couple key/value - Each key must be unique. Value can be text, or number. - \param key Key name - \param value Value for the key. - \return 1 if ok. - */ - virtual int store(char *key, - std::string value); - - /** Retrieves the value of a key - * \param key key name - * \return key's value - */ - virtual std::string read(char *key); - /** Tests if a file exists * \param fn (absolute) filename to test for --- 260,263 ---- *************** *** 277,280 **** --- 266,272 ---- virtual int fileExists(std::string fn); + virtual int fileWrite(std::string fn, + std::string data); + /** Returns current time in seconds, since EPOC. * \return Current time. Index: System-FreeBSD.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-FreeBSD.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-FreeBSD.cpp 22 Jan 2007 17:50:40 -0000 1.1 --- System-FreeBSD.cpp 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 14,19 **** using namespace CBM; ! SystemFreeBSD::SystemFreeBSD() ! : SystemUnix() { } --- 14,19 ---- using namespace CBM; ! SystemFreeBSD::SystemFreeBSD(std::string _filename) ! : SystemUnix(_filename) { } Index: System.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System.cpp 22 Jan 2007 17:50:39 -0000 1.1 --- System.cpp 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- #include <System/System.h> + #include <Base/Config.h> #include <Base/md5.h> #include <Benchmark/Benchmark-DLLoader.h> *************** *** 23,30 **** System *CBM::cbmSystem =0; ! System::System() { std::string tmp; cbmSystem=this; --- 24,33 ---- System *CBM::cbmSystem =0; ! System::System(std::string _filename) { std::string tmp; + configurationFile=_filename; + cbmSystem=this; *************** *** 40,64 **** } ! int System::verifyPatchDirectory(std::string dir) { ! std::string fn; if (!checkDirectory(dir)) { - return(0); - } - fn+="/scimark2.patch.gz"; - - return(fileExists(fn)); - } ! int System::CheckDirectory(Temp where) ! { ! std::string dir = temporaryDirectory(where); ! int r; - cbmUI->Information(CBM::UI::DirectoryCheck, - dir); - - if (!checkDirectory(dir)) { r=mkdir(dir); --- 43,56 ---- } ! int System::CheckDirectory(Dir where) { ! std::string dir = Directory(where); ! int r = 1; if (!checkDirectory(dir)) { ! cbmUI->Information(CBM::UI::DirectoryCreate, ! dir); r=mkdir(dir); *************** *** 70,74 **** } ! return(1); } --- 62,66 ---- } ! return(r); } *************** *** 103,131 **** { std::string pid; ! pid=read("lockfile.pid"); ! if (pid!="") { ! cbmUI->Fatal("According to lockfile.pid, process " \ ! " already uses Compbenchmarks' administrative files."); ! } else { ! CheckDirectory(Root); ! CheckDirectory(HostDep); ! CheckDirectory(Extract); ! CheckDirectory(Download); ! CheckDirectory(Status); ! CheckDirectory(Configuration); ! char c[16] = { 0 }; ! std::string tmp; ! sprintf(c, "%d", (int) getpid()); ! tmp=c; ! packageList(); ! return(store("lockfile.pid", ! tmp)); ! ! } ! return(0); } --- 95,146 ---- { std::string pid; + std::string rootDir; + + rootDir=env("HOME"); + rootDir+="/.compbenchmarks"; ! if (configurationFile == "") { ! configurationFile=rootDir; ! configurationFile+="/compbenchmarks.xml"; ! } ! checkDirectory(rootDir); ! configuration=new CBM::Config(configurationFile); ! CheckDirectory(HostDep); ! CheckDirectory(Extract); ! CheckDirectory(Download); ! // CheckDirectory(Status); ! // CheckDirectory(Configuration); ! ! char c[16] = { 0 }; ! std::string tmp; ! ! sprintf(c, "%d", (int) getpid()); ! tmp=c; ! packageList(); ! ! return(1); ! } ! ! CBM::Config *System::Config(void) ! { ! return(configuration); ! } ! ! ! std::string System::env(std::string _var) ! { ! std::string result = getenv(_var.c_str()); ! ! return(result); ! } ! ! int System::storeConfiguration(void) ! { ! std::string data = Config()->str(); ! ! return(fileWrite(configurationFile, data)); } *************** *** 452,593 **** } ! std::string System::temporaryDirectory(Temp where) ! { ! std::string result; ! std::string host; ! ! result=getenv("HOME"); ! result+="/.compbenchmarks"; ! ! host=hostname(); ! ! switch(where) { ! case Root: ! break; ! case HostDep: ! result+="/"; ! result+=host; ! break; ! case Extract: ! result+="/"; ! result+=host; ! result+="/Extracts"; ! break; ! case Download: ! result+="/Downloads"; ! break; ! case Status: ! result+="/"; ! result+=host; ! result+="/Status"; ! break; ! case Configuration: ! result+="/"; ! result+=host; ! result+="/Configuration"; ! break; ! case Patches: ! result=DATAROOTDIR; ! result+="/"; ! result+=PACKAGE; ! result+="/"; ! result+=VERSION; ! result+="/"; ! result+="patches"; ! if (!verifyPatchDirectory(result)) { ! result=getenv("PWD"); ! result+="/share/patches"; ! if (!verifyPatchDirectory(result)) { ! result=getenv("PWD"); ! result+="/../share/patches"; ! } ! } ! break; ! case OS: ! result=DATAROOTDIR; ! result+="/"; ! result+=PACKAGE; ! result+="/"; ! result+=VERSION; ! result+="/"; ! result+="system"; ! if (!checkDirectory(result)) { ! result=getenv("PWD"); ! result+="/share/system/"; ! #ifdef CBM_SYSTEM_CYGWIN ! result+="cygwin"; ! #else ! result=""; ! #endif ! } ! break; ! default: ! cbmUI->Fatal("Internal : Bad 'where' parameters in System::temporaryDirectory();"); ! return(""); ! } ! ! return(result); ! } ! ! int System::store(char *key, ! std::string value) { ! std::string fn; ! std::ofstream OUT; ! ! fn=temporaryDirectory(System::Status); ! fn+="/"; ! fn+=key; ! OUT.open(fn.c_str(),std::ios::out); ! OUT << value; ! OUT.close(); ! /* !!! */ ! ! return(1); } ! std::string System::read(char *key) { - std::string fn; std::ifstream IN; - std::ifstream::pos_type size; - char *buf; - std::string result; - - fn=temporaryDirectory(System::Status); - fn+="/"; - fn+=key; - IN.open(fn.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - if (IN.is_open()) { - size=IN.tellg(); - buf=new char[size]; - IN.seekg(0, std::ios::beg); - IN.read(buf, size); IN.close(); ! ! result.append(buf, size); ! ! delete[](buf); } else { ! /* !!! */ } - - return(result); } ! int System::fileExists(std::string fn) { ! std::ifstream IN; ! IN.open(fn.c_str(), ! std::ios::in | ! std::ios::binary | ! std::ios::ate); ! if (IN.is_open()) { ! IN.close(); return(1); } else { --- 467,501 ---- } ! std::string System::Directory(Dir where) { ! return(configuration->Path(where)); } ! int System::fileExists(std::string fn) { std::ifstream IN; IN.open(fn.c_str(), std::ios::in | std::ios::binary | std::ios::ate); if (IN.is_open()) { IN.close(); ! return(1); } else { ! return(0); } } ! int System::fileWrite(std::string fn, ! std::string data) { ! std::ofstream OUT; ! OUT.open(fn.c_str(), ! std::ios::out | ! std::ios::binary | ! std::ios::ate); ! if (OUT.is_open()) { ! OUT << data; ! OUT.close(); return(1); } else { *************** *** 606,613 **** CBM::cbmlib_done(); ! fn=temporaryDirectory(System::Status); ! fn+="/"; ! fn+="lockfile.pid"; ! return(unlink(fn)); } --- 514,522 ---- CBM::cbmlib_done(); ! if (configuration->Changes()) { ! storeConfiguration(); ! } ! ! return(1); } *************** *** 624,626 **** --- 533,536 ---- System::~System() { + delete(configuration); } Index: System-Linux.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Linux.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Linux.h 22 Jan 2007 17:50:41 -0000 1.1 --- System-Linux.h 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 23,27 **** public: /** Constructor */ ! SystemLinux(); /** Returns processor name --- 23,27 ---- public: /** Constructor */ ! SystemLinux(std::string _filename = ""); /** Returns processor name Index: System-FreeBSD.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-FreeBSD.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-FreeBSD.h 22 Jan 2007 17:50:40 -0000 1.1 --- System-FreeBSD.h 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 23,27 **** public: /** Constructor */ ! SystemFreeBSD(); /** Returns processor name --- 23,27 ---- public: /** Constructor */ ! SystemFreeBSD(std::string _filename = ""); /** Returns processor name Index: System-Unix.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Unix.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Unix.cpp 22 Jan 2007 17:50:41 -0000 1.1 --- System-Unix.cpp 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 22,27 **** } ! SystemUnix::SystemUnix() ! : System() { signal(SIGINT, sysunix_sighandler); --- 22,27 ---- } ! SystemUnix::SystemUnix(std::string _filename) ! : System(_filename) { signal(SIGINT, sysunix_sighandler); Index: System-Unix.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/System/System-Unix.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** System-Unix.h 22 Jan 2007 17:50:41 -0000 1.1 --- System-Unix.h 25 Jan 2007 15:38:49 -0000 1.2 *************** *** 31,35 **** public: /** Constructor. */ ! SystemUnix(); virtual int copy(std::string from, std::string to); --- 31,35 ---- public: /** Constructor. */ ! SystemUnix(std::string _filename = ""); virtual int copy(std::string from, std::string to); |