00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00112 #include "Utils.hpp"
00113 #include "C_Generator.hpp"
00114 #include "GeneratorTrace.hpp"
00115 #include "TimeUtils.hpp"
00116 
00117 
00118 #include "cmd_line_t.hpp"
00119 
00120 #include <sys/time.h>
00121 
00122 
00123 
00124 
00125 #include <csignal> 
00126 #include <cstring>  
00127 
00128 static T_pC_Generator L_main ;
00129 static struct timeval L_stop_pressed, L_previous ;
00130 
00131 static void sig_usr1_actions (int P_notused) {
00132   if (L_main != NULL) {
00133       L_main -> stop () ;
00134   }
00135 }
00136 
00137 static void sig_int_actions (int P_notused) {
00138   gettimeofday(&L_stop_pressed, NULL);
00139   if (L_main != NULL) {
00140     if (ms_difftime (&L_stop_pressed, &L_previous) > 1000) {
00141       L_previous = L_stop_pressed ;
00142       L_main -> stop () ;
00143     }
00144   }
00145 }
00146 
00147 int main_tool(int P_argc, char**P_argv) {
00148 
00149   struct sigaction L_sig_stop   ;
00150   struct sigaction L_sig_usr1   ;
00151   T_pC_Generator   L_Generator  ;
00152   T_GeneratorError L_error_code ;
00153   
00154   cmd_line_pt      L_cmd_line   ;
00155 
00156 
00157 
00158   gettimeofday(&L_previous, NULL);
00159 
00160   memset(&L_sig_stop, 0, sizeof(struct sigaction));
00161   L_sig_stop.sa_handler = sig_int_actions ;
00162   if (sigaction(SIGINT, &L_sig_stop, NULL)) {
00163     GEN_FATAL(1,"SIGINT handler error");
00164   }
00165 
00166   memset(&L_sig_usr1, 0, sizeof(struct sigaction));
00167   L_sig_usr1.sa_handler = sig_usr1_actions ;
00168   if (sigaction(SIGUSR1, &L_sig_usr1, NULL)) {
00169     GEN_FATAL(1,"SIGINT handler error");
00170   }
00171   
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183   L_cmd_line = create_cmd_line((P_argc+2)) ;
00184   copy_cmd_line(L_cmd_line, P_argc, P_argv);
00185 
00186 
00187   
00188   NEW_VAR(L_Generator, C_Generator(L_cmd_line));
00189 
00190   L_main = L_Generator ;
00191  
00192   L_error_code = L_Generator -> init () ;
00193   if (L_error_code == E_GEN_NO_ERROR) {
00194     L_error_code = L_Generator -> run_all_once () ; 
00195   }
00196   
00197   
00198   DELETE_VAR(L_Generator);
00199 
00200 
00201   destroy_cmd(L_cmd_line);
00202   L_cmd_line->m_nb_args += 2 ;
00203   DELETE_VAR(L_cmd_line);
00204 
00205   
00206   close_trace () ;
00207 
00208   return (L_error_code) ;
00209 }
00210 
00211 int main(int P_argc, char**P_argv) {
00212   int L_nRet;
00213   
00214   L_nRet = main_tool(P_argc, P_argv);
00215 
00216   return L_nRet;
00217 }
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225