rob08vis.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
00003  *
00004  * This file is part of rob08
00005  *
00006  * rob08 is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * any later version.
00010  *
00011  * rob08 is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with rob08.  If not, see <http://www.gnu.org/licenses/>.
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     // set signal handler
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     // create core
00054     ICore *core = CoreFactory::createCore(0);
00055     if (!core) {
00056         return -1;
00057     }
00058 
00059     // create core synchronization wrapper
00060     CoreSync *cs = new CoreSync(core);
00061 
00062     // create SyncReader thread
00063     SyncReader *reader = new SyncReader(std::cin, cs);
00064 
00065     // create visualizer window and connect to SyncReader::finished slot
00066     VisWnd *wnd = VisWnd::showMainWindow(cs);
00067     QObject::connect(reader, SIGNAL(finished()), wnd, SLOT(syncThreadFinished()));
00068     wnd->show();
00069 
00070     // run SyncReader thread
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     // run application instance
00077     int ec = app.exec();
00078 
00079     // wait for thread
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     // destroy objects in reverse order
00094     //delete arena;
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 

Generated on Fri Jul 10 22:42:01 2009 for rob08 by  doxygen 1.5.4