00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00124 }
00125
00126
00127 void NewHandler() {
00128 throw MemoryExhausted("RTIA has exhausted memory error");
00129 }
00130
00131