00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Utils.hpp"
00021 #include "C_Generator.hpp"
00022 #include "GeneratorTrace.hpp"
00023 #include "TimeUtils.hpp"
00024
00025
00026 #include "cmd_line_t.hpp"
00027
00028 #include <sys/time.h>
00029
00030
00031
00032
00033 #include <csignal>
00034 #include <cstring>
00035
00036 static T_pC_Generator L_main ;
00037 static struct timeval L_stop_pressed, L_previous ;
00038
00039 static void sig_usr1_actions (int P_notused) {
00040 if (L_main != NULL) {
00041 L_main -> stop () ;
00042 }
00043 }
00044
00045 static void sig_int_actions (int P_notused) {
00046 gettimeofday(&L_stop_pressed, NULL);
00047 if (L_main != NULL) {
00048 if (ms_difftime (&L_stop_pressed, &L_previous) > 1000) {
00049 L_previous = L_stop_pressed ;
00050 L_main -> stop () ;
00051 }
00052 }
00053 }
00054
00055 int main_tool(int P_argc, char**P_argv) {
00056
00057 struct sigaction L_sig_stop ;
00058 struct sigaction L_sig_usr1 ;
00059 T_pC_Generator L_Generator ;
00060 T_GeneratorError L_error_code ;
00061
00062 cmd_line_pt L_cmd_line ;
00063
00064
00065
00066 gettimeofday(&L_previous, NULL);
00067
00068 memset(&L_sig_stop, 0, sizeof(struct sigaction));
00069 L_sig_stop.sa_handler = sig_int_actions ;
00070 if (sigaction(SIGINT, &L_sig_stop, NULL)) {
00071 GEN_FATAL(1,"SIGINT handler error");
00072 }
00073
00074 memset(&L_sig_usr1, 0, sizeof(struct sigaction));
00075 L_sig_usr1.sa_handler = sig_usr1_actions ;
00076 if (sigaction(SIGUSR1, &L_sig_usr1, NULL)) {
00077 GEN_FATAL(1,"SIGINT handler error");
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 L_cmd_line = create_cmd_line((P_argc+2)) ;
00092 copy_cmd_line(L_cmd_line, P_argc, P_argv);
00093
00094
00095
00096 NEW_VAR(L_Generator, C_Generator(L_cmd_line));
00097
00098 L_main = L_Generator ;
00099
00100 L_error_code = L_Generator -> init () ;
00101 if (L_error_code == E_GEN_NO_ERROR) {
00102 L_error_code = L_Generator -> run_all_once () ;
00103 }
00104
00105
00106 DELETE_VAR(L_Generator);
00107
00108
00109 destroy_cmd(L_cmd_line);
00110 L_cmd_line->m_nb_args += 2 ;
00111 DELETE_VAR(L_cmd_line);
00112
00113
00114 close_trace () ;
00115
00116 return (L_error_code) ;
00117 }
00118
00119 int main(int P_argc, char**P_argv) {
00120 int L_nRet;
00121
00122 L_nRet = main_tool(P_argc, P_argv);
00123
00124 return L_nRet;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133