00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <FFThread.hpp>
00021
00022 #include <StreamCenter.hpp>
00023 #include <Timer.hpp>
00024
00025 #include <ReferenceCounting.hpp>
00026
00027 #include <FFLexer.hpp>
00028 #include <ParametersInitialization.hpp>
00029
00030 #include <RealExpression.hpp>
00031
00032 #include <Expression.hpp>
00033 #include <Instruction.hpp>
00034
00035 #include <ErrorHandler.hpp>
00036
00037 #include <RunningOptions.hpp>
00038
00039 #include <vector>
00040 #include <fstream>
00041
00042
00043 #ifdef HAVE_GUI_LIBS
00044
00045 #include <QtGui/QTextEdit>
00046
00047 void FFThread::
00048 setConsole(QTextEdit* console)
00049 {
00050 __console = console;
00051 }
00052
00053 #endif // HAVE_GUI_LIBS
00054
00055
00056
00057
00058 Lexer* fflexer;
00059
00060
00061 int ffparse();
00062
00063 std::vector<ReferenceCounting<Instruction> > iSet;
00064
00065 void FFThread::run()
00066 {
00067 ThreadStaticCenter threadStaticCenter;
00068
00069 #ifdef HAVE_GUI_LIBS
00070 if (__console != 0) {
00071 StreamCenter::instance().setConsole(__console);
00072 }
00073 #endif // HAVE_GUI_LIBS
00074
00075 StreamCenter::instance().setDebugLevel(RunningOptions::instance().getVerbosity());
00076
00077 #ifdef HAVE_GUI_LIBS
00078 if (not(RunningOptions::instance().haveDisplay())) {
00079 fferr(0) << "Warning: Cannot open DISPLAY, falling back to text mode\n";
00080 }
00081 #endif // HAVE_GUI_LIBS
00082
00083 #ifdef HAVE_GUI_LIBS
00084 if (__console == 0) {
00085 #endif // HAVE_GUI_LIBS
00086 ffout(3) << "=========================\n";
00087 ffout(3) << "== Text mode execution ==\n";
00088 ffout(3) << "=========================\n";
00089 #ifdef HAVE_GUI_LIBS
00090 }
00091 #endif // HAVE_GUI_LIBS
00092
00093 try {
00094 Timer totalTime;
00095 totalTime.start();
00096 ffout(1) << "FreeFEM3D computing thread: started\n";
00097
00098 iSet.clear();
00099
00100 ffout(2) << "Parsing data\n";
00101 ParametersInitialization();
00102 {
00103 fflexer = new FFLexer(*__in);
00104 ffparse();
00105 delete fflexer;
00106 }
00107 ffout(2) << "Parsing data: done\n";
00108
00109 for (std::vector<ReferenceCounting<Instruction> >::iterator i = iSet.begin();
00110 i != iSet.end(); ++i) {
00111 (*(*i)).execute();
00112 }
00113 totalTime.stop();
00114 ffout(1) << "FreeFEM3D computing thread: done [costs: " << totalTime << "]\n";
00115 }
00116 catch(ErrorHandler e) {
00117 e.writeErrorMessage();
00118 }
00119 catch (std::exception e) {
00120 fferr(0) << "error: " << e.what() << "!\n";
00121
00122 fferr(0) << "\nSTDC++ ERROR: this should not occure, please report it\n";
00123 fferr(0) << "\nBUG REPORT: Please send bug reports to:\n"
00124 << " ff3d-dev@nongnu.org or freefem@ann.jussieu.fr\n"
00125 << "or better, use the Bug Tracking System:\n"
00126 << " http://savannah.nongnu.org/bugs/?group=ff3d\n";
00127 }
00128 catch(...) {
00129 fferr(0) << "error: Unknown exception caught!\n";
00130 fferr(0) << "\nUNEXPECTED ERROR: this should not occure, please report it\n";
00131 fferr(0) << "\nBUG REPORT: Please send bug reports to:\n"
00132 << " ff3d-dev@nongnu.org or freefem@ann.jussieu.fr\n"
00133 << "or better, use the Bug Tracking System:\n"
00134 << " http://savannah.nongnu.org/bugs/?group=ff3d\n";
00135 }
00136
00137 iSet.clear();
00138 }
00139
00140 void FFThread::setInput(std::istream& fin)
00141 {
00142 __in = &fin;
00143 }
00144
00145 FFThread::FFThread()
00146 :
00147 #ifdef HAVE_GUI_LIBS
00148 __console(0),
00149 #endif
00150 __in(0)
00151 {
00152 ;
00153 }
00154
00155 FFThread::~FFThread()
00156 {
00157 #ifdef HAVE_GUI_LIBS
00158 this->wait();
00159 #else // HAVE_GUI_LIBS
00160 this->join();
00161 #endif // HAVE_GUI_LIBS
00162 }