# RTIA/main.cc

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // CERTI - HLA RunTime Infrastructure
    00003 // Copyright (C) 2002-2005  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 // $Id: main.cc,v 3.25 2008/12/07 20:16:10 gotthardp Exp $
    00022 // ----------------------------------------------------------------------------
    00023
    00024 #include <config.h>
    00025
    00026 #include "RTIA.hh"
    00027 #include "RTIA_cmdline.h"
    00028
    00029 #include <sys/types.h>
    00030 #include <signal.h>
    00031
    00032 using namespace certi;
    00033 using namespace rtia;
    00034 using namespace std;
    00035
    00036 extern "C"void SignalHandler(int Signal);
    00037 void NewHandler();
    00038 int normal_end;
    00039
    00056 int
    00057 main(int argc, char **argv) {
    00058     signal(SIGINT, SignalHandler);
    00059 #ifndef _WIN32
    00060     signal(SIGPIPE, SignalHandler);
    00061 #endif
    00062
    00063     set_new_handler(NewHandler);
    00064     normal_end = 0;
    00065
    00066     if (NULL!=getenv("RTIA_DEBUG")) {
    00067         cerr << "RTIA:: RTIA_DEBUG is set: Waiting <"<< getenv("RTIA_DEBUG")
    00068                 << " seconds> before starting RTIA"<<endl;
    00069         sleep(atoi(getenv("RTIA_DEBUG")));
    00070     }
    00071
    00072     // Command line
    00073     gengetopt_args_info args ;
    00074     if (cmdline_parser(argc, argv, &args))
    00075         exit(EXIT_FAILURE);
    00076
    00077     try {
    00078         int rtia_port = 0;
    00079         if (args.port_given) {
    00080             rtia_port = args.port_arg;
    00081         }
    00082
    00083         RTIA rtia(rtia_port);
    00084
    00085         try {
    00086             rtia.execute();
    00087         }
    00088         catch (Exception &e) {
    00089                         if (! normal_end) {
    00090                     cerr << "RTIA:: RTIA has thrown " << e._name << " exception." << endl;
    00091                     cerr.flush();
    00092                         }
    00093             if (!e._reason.empty()) {
    00094                                 if (! normal_end) {
    00095                       cerr << "RTIA:: Reason: " << e._reason << endl;
    00096                       cerr.flush();
    00097                                 }
    00098                 rtia.displayStatistics();
    00099             }
    00100
    00101             return (EXIT_FAILURE);
    00102         }
    00103
    00104         rtia.displayStatistics();
    00105     } catch (Exception &e) {
    00106                 if (! normal_end) {
    00107               cerr << "RTIA:: RTIA has thrown " << e._name << " exception." << endl;
    00108               if (!e._reason.empty()) {
    00109               cerr << "RTIA:: Reason: " << e._reason << endl;
    00110               }
    00111                 }
    00112     }
    00113     cout << "RTIA:: End execution."<< endl ;
    00114
    00115     return (EXIT_SUCCESS);
    00116 }
    00117
    00118 // ----------------------------------------------------------------------------
    00119 void SignalHandler(int Signal) {
    00120
    00121     printf("\nRTIA: Received signal %d. Exiting peacefully.\n", Signal);
    00122         normal_end = 1;
    00123         //exit(0);
    00124 }
    00125
    00126 // ----------------------------------------------------------------------------
    00127 void NewHandler() {
    00128     throw MemoryExhausted("RTIA has exhausted memory error");
    00129 }
    00130
    00131 // EOF $Id: main.cc,v 3.25 2008/12/07 20:16:10 gotthardp Exp $