# RTIG/main.cc

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2002-2006  ONERA
    00004 //
    00005 // This file is part of CERTI
    00006 //
    00007 // CERTI is free software ; you can redistribute it and/or modify
    00008 // it under the terms of the GNU General Public License as published by
    00009 // the Free Software Foundation ; either version 2 of the License, or
    00010 // (at your option) any later version.
    00011 //
    00012 // CERTI is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY ; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00015 // GNU General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU General Public License
    00018 // along with this program ; if not, write to the Free Software
    00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    00020 // ----------------------------------------------------------------------------
    00021
    00022 #include "config.h"
    00023 #include "RTIG.hh"
    00024 #include "RTIG_cmdline.h"
    00025 #include "certi.hh"
    00026
    00027 #ifdef _WIN32
    00028 #include <signal.h>
    00029 #endif
    00030
    00031 #include <new>
    00032 #include <csignal>
    00033
    00034 using namespace certi ;
    00035 using namespace certi::rtig ;
    00036 using std::cerr ;
    00037 using std::cout ;
    00038 using std::endl ;
    00039 using std::string ;
    00040
    00041 // ----------------------------------------------------------------------------
    00043 extern "C" void SignalHandler(int sig)
    00044 {
    00045     RTIG::signalHandler(sig);
    00046     // Catch signal again.
    00047     std::signal(sig, SignalHandler);
    00048 }
    00049
    00050 // ----------------------------------------------------------------------------
    00052 void
    00053 NewHandler()
    00054 throw (MemoryExhausted)
    00055 {
    00056     throw MemoryExhausted("main RTIG");
    00057 }
    00058
    00059 // ----------------------------------------------------------------------------
    00094 int main(int argc, char *argv[])
    00095 {
    00096     RTIG myRTIG;
    00097     gengetopt_args_info args ;
    00098     if (cmdline_parser(argc, argv, &args)) exit(EXIT_FAILURE);
    00099     /* The default verbose level is 2 */
    00100     int verboseLevel = 2;
    00101     if (args.verbose_given)
    00102         verboseLevel = args.verbose_arg;
    00103
    00104 #if _WIN32
    00105     string dn = string(argv[0]);
    00106     dn = dn.substr(0,dn.find_last_of("\\"));
    00107     dn = dn.substr(0,dn.find_last_of("\\"));
    00108     if (NULL==getenv("CERTI_HOME")) {
    00109         dn = "CERTI_HOME="+dn+"\\";
    00110         cout << "Updating : " << dn << endl;
    00111         putenv(dn.c_str());
    00112     }
    00113 #endif
    00114
    00115     if (verboseLevel>0) {
    00116         cout << "CERTI RTIG " VERSION " - Copyright 2002-2008  ONERA" << endl ;
    00117         cout << "This is free software ; see the source for copying "
    00118              << "conditions. There is NO\nwarranty ; not even for "
    00119              << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
    00120              << endl << endl ;
    00121     }
    00122
    00123     std::signal(SIGINT, SignalHandler);
    00124 #ifndef _WIN32
    00125     std::signal(SIGPIPE, SignalHandler);
    00126 #endif
    00127
    00128     std::set_new_handler(NewHandler);
    00129
    00130     myRTIG.setVerboseLevel(verboseLevel);
    00131     myRTIG.execute();
    00132
    00133     if (verboseLevel>0) {
    00134         cout << "CERTI RTIG exiting." << endl ;
    00135     }
    00136     exit(EXIT_SUCCESS);
    00137 } /* end of main */