00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #include "arena.h"
00023 #include "core.h"
00024 #include "coresync.h"
00025 #include "viswnd.h"
00026 #include "vscan.h"
00027 #include "robIO.h"
00028
00029 #ifndef BUILDING_DOX
00030 # include <QApplication>
00031 # include <QObject>
00032 # include <signal.h>
00033 # include <sstream>
00034 # include <string>
00035 #endif
00036
00037 using namespace StreamDecorator;
00038 using std::string;
00039
00040 int main(int argc, char *argv[]) {
00041 #if CONSOLE_COLOR_OUTPUT
00042 Color::enable(true);
00043 #endif
00044 QApplication app(argc, argv);
00045
00046
00047 struct sigaction sa;
00048 bzero(&sa, sizeof(sa));
00049 sa.sa_handler = SIG_IGN;
00050 if (0!= sigaction(SIGUSR1, &sa, NULL))
00051 std::cerr << Error(E_WARNING, argv[0], "can't set SIGUSR1 signal handler to SIG_IGN") << std::endl;
00052
00053
00054 ICore *core = CoreFactory::createCore(0);
00055 if (!core) {
00056 return -1;
00057 }
00058
00059
00060 CoreSync *cs = new CoreSync(core);
00061
00062
00063 SyncReader *reader = new SyncReader(std::cin, cs);
00064
00065
00066 VisWnd *wnd = VisWnd::showMainWindow(cs);
00067 QObject::connect(reader, SIGNAL(finished()), wnd, SLOT(syncThreadFinished()));
00068 wnd->show();
00069
00070
00071 #if DEBUG_THREAD
00072 std::cerr << "vis: " << Color(C_LIGHT_GREEN) << "starting SyncReader thread..." << Color(C_NO_COLOR) << std::endl;
00073 #endif
00074 reader->start();
00075
00076
00077 int ec = app.exec();
00078
00079
00080 reader->syncExit();
00081 #if DEBUG_THREAD
00082 std::cerr << "vis: " << Color(C_YELLOW) << "waiting for SyncReader thread to be finished..." << Color(C_NO_COLOR) << std::endl;
00083 #endif
00084 reader->wait();
00085 #if DEBUG_THREAD
00086 std::cerr << "vis: " << Color(C_LIGHT_BLUE) << "SyncReader finished..." << Color(C_NO_COLOR) << std::endl;
00087 #endif
00088 if (0==ec && reader->hasError()) {
00089 std::cerr << Error(E_NOTE, "vis", "lexical error(s) detected") << std::endl;
00090 ec = -1;
00091 }
00092
00093
00094
00095 delete reader;
00096 delete cs;
00097 delete core;
00098
00099 #if DEBUG_THREAD
00100 if (ec)
00101 std::cerr << "vis: " << Color(C_LIGHT_RED) << "exit failure" << Color(C_NO_COLOR) << ", EC = " << ec << std::endl;
00102 else
00103 std::cerr << "vis: " << Color(C_LIGHT_GREEN) << "exit successful" << Color(C_NO_COLOR) << ", EC = " << ec << std::endl;
00104 #endif
00105 return ec;
00106 }
00107