main.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
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 // #include <sys/resource.h>
00123 // #include <unistd.h>
00124 
00125 #include <csignal> // sigaction definition
00126 #include <cstring>  // for memset
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 //   struct rlimit    L_rlimit     ;
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 //   if (getrlimit (RLIMIT_NOFILE, &L_rlimit) < 0) {
00174 //     GEN_FATAL(1, "getrlimit failed");
00175 //   }
00176 //   L_rlimit.rlim_max = 10000 ;
00177 //   L_rlimit.rlim_cur = L_rlimit.rlim_max ;
00178 //   if (setrlimit (RLIMIT_NOFILE, &L_rlimit) < 0) {
00179 //     GEN_FATAL(1, "RLIMIT_NOFILE modification failed");
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   //   NEW_VAR(L_Generator, C_Generator(P_argc, P_argv));
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   // Clean Generator main object
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   // Close trace
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 

Generated on Wed Mar 7 14:57:54 2007 for Seagull by  doxygen 1.4.6