TriloBot Simulator (C++, Qt4, Flex, Readline, Boost)
File detail
Source code
/*
* Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
*
* This file is part of rob08
*
* rob08 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* rob08 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rob08. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "arena.h"
#include "core.h"
#include "coresync.h"
#include "viswnd.h"
#include "vscan.h"
#include "robIO.h"
#ifndef BUILDING_DOX
# include <QApplication>
# include <QObject>
# include <signal.h>
# include <sstream>
# include <string>
#endif
using namespace StreamDecorator;
using std::string;
int main(int argc, char *argv[]) {
#if CONSOLE_COLOR_OUTPUT
Color::enable(true);
#endif
QApplication app(argc, argv);
// set signal handler
struct sigaction sa;
bzero(&sa, sizeof(sa));
sa.sa_handler = SIG_IGN;
if (0!= sigaction(SIGUSR1, &sa, NULL))
std::cerr << Error(E_WARNING, argv[0], "can't set SIGUSR1 signal handler to SIG_IGN") << std::endl;
// create core
ICore *core = CoreFactory::createCore(0);
if (!core) {
return -1;
}
// create core synchronization wrapper
CoreSync *cs = new CoreSync(core);
// create SyncReader thread
SyncReader *reader = new SyncReader(std::cin, cs);
// create visualizer window and connect to SyncReader::finished slot
VisWnd *wnd = VisWnd::showMainWindow(cs);
QObject::connect(reader, SIGNAL(finished()), wnd, SLOT(syncThreadFinished()));
wnd->show();
// run SyncReader thread
#if DEBUG_THREAD
std::cerr << "vis: " << Color(C_LIGHT_GREEN) << "starting SyncReader thread..." << Color(C_NO_COLOR) << std::endl;
#endif
reader->start();
// run application instance
int ec = app.exec();
// wait for thread
reader->syncExit();
#if DEBUG_THREAD
std::cerr << "vis: " << Color(C_YELLOW) << "waiting for SyncReader thread to be finished..." << Color(C_NO_COLOR) << std::endl;
#endif
reader->wait();
#if DEBUG_THREAD
std::cerr << "vis: " << Color(C_LIGHT_BLUE) << "SyncReader finished..." << Color(C_NO_COLOR) << std::endl;
#endif
if (0==ec && reader->hasError()) {
std::cerr << Error(E_NOTE, "vis", "lexical error(s) detected") << std::endl;
ec = -1;
}
// destroy objects in reverse order
//delete arena;
delete reader;
delete cs;
delete core;
#if DEBUG_THREAD
if (ec)
std::cerr << "vis: " << Color(C_LIGHT_RED) << "exit failure" << Color(C_NO_COLOR) << ", EC = " << ec << std::endl;
else
std::cerr << "vis: " << Color(C_LIGHT_GREEN) << "exit successful" << Color(C_NO_COLOR) << ", EC = " << ec << std::endl;
#endif
return ec;
}