Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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 
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 // #include <sys/resource.h>
00031 // #include <unistd.h>
00032 
00033 #include <csignal> // sigaction definition
00034 #include <cstring>  // for memset
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 //   struct rlimit    L_rlimit     ;
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 //   if (getrlimit (RLIMIT_NOFILE, &L_rlimit) < 0) {
00082 //     GEN_FATAL(1, "getrlimit failed");
00083 //   }
00084 //   L_rlimit.rlim_max = 10000 ;
00085 //   L_rlimit.rlim_cur = L_rlimit.rlim_max ;
00086 //   if (setrlimit (RLIMIT_NOFILE, &L_rlimit) < 0) {
00087 //     GEN_FATAL(1, "RLIMIT_NOFILE modification failed");
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   //   NEW_VAR(L_Generator, C_Generator(P_argc, P_argv));
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   // Clean Generator main object
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   // Close trace
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 

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002