[Compbench-devel] CompBenchmarks++/libcompbenchmarks/UI UI.cpp, 1.7, 1.8 UI.h, 1.6, 1.7
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-06-06 15:55:11
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/UI In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9115 Modified Files: UI.cpp UI.h Log Message: XML based message reporting. Index: UI.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/UI/UI.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** UI.h 23 May 2007 18:25:00 -0000 1.6 --- UI.h 6 Jun 2007 15:55:07 -0000 1.7 *************** *** 10,14 **** #define H_CBMUI ! #include <string> namespace CBM { --- 10,14 ---- #define H_CBMUI ! #include <UI/UI-Msg.h> namespace CBM { *************** *** 21,90 **** { private: ! std::string msg; ! float progressLast; ! protected: ! public: ! UI(); ! ! /** Typedef for message sent to UI object. */ ! typedef enum Info { FileCreate, /*!< File creation */ ! FileRead, /*!< File is being read */ ! FileWrite, /*!< File has been written */ ! FileRemove, /*!< File has been removed */ ! Checksum, /*!< Checksum related messages */ ! DirectoryCreate, /*!< Directory has been created */ ! PackageDownload, /*!< Package download */ ! PackageExtract, /*!< Package extract */ ! PackagePatch, /*!< Package patching */ ! PackagePreconfigure, /*!< Package pre-configuration */ ! PackageConfigure, /*!< Package configuration */ ! PackageMake, /*!< Package building */ ! PackageTest, /*!< Package testing */ ! BenchBench, /*!< Benchmark ran */ ! BenchResult, /*!< Benchmark result is being ! * displayed */ ! PackageClean, /*!< Package cleaning */ ! PackageUninstall, /*!< Package uninstallation */ ! CompilerAutodetect /*!< Autodetect compilers */ ! }; ! typedef enum State { ! Start, Running, OK, Failed ! }; ! /** Throws a fatal error. ! Display a message and exits properly. ! \sa CBMSystem::done() ! \return 1 if ok. ! */ ! virtual int Fatal(std::string msg); ! /** Display information. ! Prints an header corresponding to the type, then shows msg. ! \param type Type of information ! \param msg Message (clear text) to display ! */ ! virtual std::string LastMessage(void); ! virtual float LastProgress(void); ! virtual int Information(Info type, ! std::string _msg, ! State state = Start, ! float _progress = 0); ! virtual int Information(Info type, ! State state = Start, ! float _progress = 0); - virtual void InformationBenchmarkResult(std::string _bid, - std::string _xtime, - std::string _r); ! /* ! virtual void ProgressInit(std::string msg); ! virtual void Progress(float _p); ! virtual void ProgressDone(void); ! */ /** Virtual destructor */ --- 21,66 ---- { private: ! UIMsg *root; ! UIMsg *current; ! virtual UIMsg *currentMsg(void); ! protected: ! /** Checks if in main thread ! */ ! virtual void postMsg(UIMsg *_msg); ! virtual void childDone(void); ! public: ! UI(); ! virtual UIMsg *msgFatal(std::string _text); ! virtual UIMsg *msgShell(std::string _shellCommand); ! virtual UIMsg *msgCreate(UIMsg::ObjectType _type, ! std::string _name); ! virtual UIMsg *msgDownload(std::string _url); ! virtual UIMsg *msgChecksum(std::string _file); ! virtual UIMsg *msgExtract(std::string _name); ! virtual UIMsg *msgPatch(std::string _name); ! virtual UIMsg *msgPreconfigure(std::string _name); ! virtual UIMsg *msgConfigure(std::string _info); ! virtual UIMsg *msgMake(std::string _name); ! virtual UIMsg *msgTest(std::string _name); ! virtual UIMsg *msgRelease(std::string _name); ! virtual UIMsg *msgInstall(std::string _name); ! virtual UIMsg *msgFetch(std::string _name); ! virtual UIMsg *msgUninstall(std::string _name); ! virtual UIMsg *msgBench(std::string _name); ! virtual UIMsg *outputInfo(std::string _text); ! virtual UIMsg *Progress(float _pc); ! /** Call childDone() */ ! virtual UIMsg *outputOK(std::string _test = ""); ! virtual UIMsg *outputKO(std::string _test = ""); ! virtual void Display(UIMsg *_msg) = 0; ! virtual void DisplayProgressUpdate(UIMsg *_msg) = 0; ! virtual void DisplayDone(UIMsg *_msg) = 0; /** Virtual destructor */ Index: UI.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/UI/UI.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** UI.cpp 23 May 2007 18:25:00 -0000 1.7 --- UI.cpp 6 Jun 2007 15:55:07 -0000 1.8 *************** *** 9,12 **** --- 9,13 ---- #include <UI/UI.h> #include <System/System.h> + #include <Base/Thread.h> #include <libcompbenchmarks.h> *************** *** 16,21 **** using namespace CBM; ! CBM::UI *CBM::cbmUI = 0; ! CBM::UI *CBM::cbmUI_old = 0; UI::UI() --- 17,23 ---- using namespace CBM; ! CBM::UI *CBM::cbmUI = 0; ! CBM::UI *CBM::cbmUI_old = 0; ! pthread_t ui_main_thread = currentThread(); UI::UI() *************** *** 26,203 **** cbmUI=this; ! msg=""; ! progressLast=0; } ! int UI::Fatal(std::string msg) { ! std::cerr << "FATAL ERROR: " << msg << std::endl; ! if (UO_fatal) { ! CBM::cbmSystem->done(); ! exit(1); } ! return(1); } ! std::string UI::LastMessage(void) { return(msg); } ! float UI::LastProgress(void) { ! return(progressLast); } ! int UI::Information(CBM::UI::Info type, ! std::string _msg, ! State state, ! float _progress) { ! std::string what; ! if (!UO_verbose) ! return(1); ! switch(type) { ! case FileCreate: ! what="Creating file"; ! break; ! case FileRead: ! what="Reading"; ! break; ! case FileWrite: ! what="Writing"; ! break; ! case FileRemove: ! what="Removing"; ! break; ! case Checksum: ! what="MD5 Checksum verification"; ! break; ! case DirectoryCreate: ! what="Creating directory"; ! break; ! case PackageDownload: ! what="Downloading"; ! break; ! case PackageExtract: ! what="Extracting"; ! break; ! case PackagePatch: ! what="Patching"; ! break; ! case PackagePreconfigure: ! what="Preconfiguring"; ! break; ! case PackageConfigure: ! what="Configuring"; ! break; ! case PackageTest: ! what="Testing"; ! break; ! case PackageMake: ! what="Making"; ! break; ! case BenchBench: ! what="Running benchmark"; ! break; ! case BenchResult: ! what="Benchmark result :"; ! break; ! case PackageClean: ! what="Cleaning"; ! break; ! case PackageUninstall: ! what="Uninstalling"; ! break; ! case CompilerAutodetect: ! what="Compiler autodetection"; ! default: ! what="(?)"; ! } ! msg=_msg; ! if (state==Running) { ! float n = _progress-progressLast; ! float np = progressLast; ! float i; ! n/=5.0; ! for(i=0; i<n; i+=1.0) { ! printf("="); ! np+=1.0; ! } ! progressLast=np; ! fflush(stdout); ! } else { ! std::string dum; ! switch(state) { ! case Start: ! dum="Starting"; ! break; ! case Running: ! dum="Running"; ! break; ! case OK: ! dum="OK"; ! break; ! case Failed: ! dum="Failed"; ! break; ! default: ! dum="??? <internal error>"; ! break; ! } ! if (progressLast!=0) { ! std::cout << std::endl; ! progressLast=0; ! } ! std::cout << msg << " " << what << " " << dum << std::endl; ! } ! return(1); } ! int UI::Information(CBM::UI::Info type, ! State state, ! float _progress) { ! return(Information(type, msg, state, _progress)); } ! void UI::InformationBenchmarkResult(std::string _bid, ! std::string _xtime, ! std::string _r) { ! std::cout << _bid << " Execution time (s) : " << _xtime << std::endl; ! std::cout << _bid << " Measured (higher is better) : " << _r << std::endl; } ! /* ! void UI::ProgressInit(std::string msg) { ! progressMsg=msg; ! printf("%s : ", progressMsg.c_str()); } ! void UI::Progress(float _p) { } ! void UI::ProgressDone(void) { ! Progress(100.0); ! printf(" - done.\n"); } - */ UI::~UI() { if (cbmUI_old) cbmUI=cbmUI_old; --- 28,263 ---- cbmUI=this; ! root=new UIMsg(); ! current=0; } ! UIMsg *UI::currentMsg(void) { ! return(current); ! } ! ! void UI::postMsg(UIMsg *_msg) ! { ! if (ui_main_thread!=currentThread()) { ! std::cerr << "BUG : UI::postMsg() used in another thread.\n" << std::endl; ! std::cerr << "BUG : here's message : " << std::endl; ! std::cerr << _msg->str() << std::endl; ! return; } ! ! if (!current) ! current=root; ! else ! current->addChild(_msg); ! ! current=_msg; ! Display(current); } ! void UI::childDone(void) ! { ! if (current) { ! DisplayDone(current); ! if (current->getParent()) ! current=(UIMsg*)current->getParent()->getParent(); ! else ! current=0; ! } ! } ! ! UIMsg *UI::msgFatal(std::string _text) { + UIMsg *msg = new UIMsgFatal(_text); + postMsg(msg); + msg->outputKO(); + + childDone(); + return(msg); } ! UIMsg *UI::msgShell(std::string _shellCommand) { ! UIMsg *msg = new UIMsgShell(_shellCommand); ! postMsg(msg); ! ! return(msg); } + UIMsg *UI::msgCreate(UIMsg::ObjectType _type, + std::string _name) + { + UIMsg *msg = new UIMsgCreate(_type, _name); + postMsg(msg); + + return(msg); + } ! UIMsg *UI::msgDownload(std::string _url) { ! UIMsg *msg = new UIMsgDownload(_url); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgChecksum(std::string _file) ! { ! UIMsg *msg = new UIMsgChecksum(_file); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgExtract(std::string _name) ! { ! UIMsg *msg = new UIMsgExtract(_name); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgPatch(std::string _name) ! { ! UIMsg *msg = new UIMsgPatch(_name); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgPreconfigure(std::string _name) ! { ! UIMsg *msg = new UIMsgPreconfigure(_name); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgConfigure(std::string _name) ! { ! UIMsg *msg = new UIMsgConfigure(_name); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgMake(std::string _name) ! { ! UIMsg *msg = new UIMsgMake(_name); ! postMsg(msg); ! ! return(msg); ! } ! UIMsg *UI::msgTest(std::string _name) ! { ! UIMsg *msg = new UIMsgTest(_name); ! postMsg(msg); ! ! return(msg); } ! UIMsg *UI::msgRelease(std::string _name) { ! UIMsg *msg = new UIMsgRelease(_name); ! postMsg(msg); ! ! return(msg); } ! UIMsg *UI::msgInstall(std::string _name) { ! UIMsg *msg = new UIMsgInstall(_name); ! postMsg(msg); ! ! return(msg); } ! UIMsg *UI::msgFetch(std::string _name) { ! UIMsg *msg = new UIMsgFetch(_name); ! postMsg(msg); ! ! return(msg); } ! UIMsg *UI::msgUninstall(std::string _name) { + UIMsg *msg = new UIMsgUninstall(_name); + postMsg(msg); + + return(msg); + } + UIMsg *UI::msgBench(std::string _name) + { + UIMsg *msg = new UIMsgBench(_name); + postMsg(msg); + + return(msg); } ! UIMsg *UI::outputInfo(std::string _test) { ! UIMsg *msg = currentMsg(); ! ! msg->outputInfo(_test); ! ! return(msg); } + UIMsg *UI::Progress(float _pc) + { + UIMsg *msg = currentMsg(); + + msg->setProgress(_pc); + DisplayProgressUpdate(msg); + + return(msg); + } + + UIMsg *UI::outputOK(std::string _test) + { + UIMsg *msg = currentMsg(); + + msg->outputOK(_test); + + childDone(); + + return(msg); + } + + UIMsg *UI::outputKO(std::string _test) + { + UIMsg *msg = currentMsg(); + + msg->outputKO(_test); + + childDone(); + + return(msg); + } + + /* + void UI::display(UIMsg *_msg) + { + std::cout << _msg->str(); + } + + void UI::displayProgressUpdate(UIMsg *_msg) + { + } + + void UI::displayDone(UIMsg *_msg) + { + std::cout << std::endl; + } + */ UI::~UI() { + if (root) + delete(root); + if (cbmUI_old) cbmUI=cbmUI_old; |