Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_Generator.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 "C_Generator.hpp"
00021 #include "C_XmlParser.hpp"
00022 #include "Utils.hpp"
00023 #include "TimeUtils.hpp"
00024 #include "GeneratorTrace.hpp"
00025 #include "GeneratorError.h"
00026 #include "TrafficType.h"
00027 #include "C_GeneratorStats.hpp"
00028 
00029 #include "C_SequentialExtDataCtrl.hpp"
00030 #include "C_RandomExtDataCtrl.hpp"
00031 
00032 #include "C_ProtocolFrame.hpp"
00033 
00034 #include "C_ProtocolStatsFrame.hpp"
00035 
00036 #include "C_ScenarioStats.hpp"
00037 
00038 #include "string_t.hpp"
00039 #include "iostream_t.hpp"
00040 
00041 #include <cstdlib>
00042 
00043 
00044 typedef struct _end_trace_arg {
00045   C_TaskControl *m_instance ;
00046   pthread_t     *m_thread   ;
00047 } T_EndTraceArg, *T_pEndTraceArg ;
00048 
00049 void _gen_stop_controller (void* P_arg);
00050 
00051 void _gen_log_error(char *P_data) {
00052   GEN_ERROR(E_GEN_FATAL_ERROR, P_data);
00053 }
00054 
00055 void _gen_log_info(char *P_data) {
00056   GEN_LOG_EVENT_FORCE(P_data);
00057 }
00058 
00059 C_Generator::C_Generator(cmd_line_pt P_cmd_line) : C_TaskControl() {
00060   int L_i;  
00061 
00062   // generator model
00063   NEW_VAR(m_transport_ctrl, C_TransportControl(_gen_log_error, _gen_log_info));
00064   NEW_VAR(m_protocol_ctrl, C_ProtocolControl(m_transport_ctrl));
00065   NEW_VAR(m_channel_ctrl, C_ChannelControl());
00066 
00067   NEW_VAR(m_scen_control, 
00068           C_ScenarioControl(m_protocol_ctrl,m_transport_ctrl, m_channel_ctrl));
00069   NEW_VAR(m_read_control, C_ReadControl(m_channel_ctrl, m_transport_ctrl));
00070 
00071   NEW_VAR(m_keyboard_control, C_KeyboardControl());
00072   m_do_keyboard_control = false ;
00073 
00074 
00075   m_nb_forced = 0 ;
00076 
00077 
00078   for (L_i = 0 ; L_i < P_cmd_line->m_nb_args ; L_i ++) {
00079     if ((P_cmd_line->m_args[L_i]) && (strcmp(P_cmd_line->m_args[L_i],(char*)"-ctrl")== 0)) {
00080       P_cmd_line->m_nb_args += 2 ;
00081       
00082       ALLOC_TABLE(P_cmd_line->m_args[P_cmd_line->m_nb_args-2],
00083                   char*,
00084                   sizeof(char),
00085                   strlen((char*)"-dico")+1);
00086       strcpy(P_cmd_line->m_args[P_cmd_line->m_nb_args-2],(char*)"-dico");
00087 
00088       ALLOC_TABLE(P_cmd_line->m_args[P_cmd_line->m_nb_args-1],
00089                   char*,
00090                   sizeof(char),
00091                   strlen((char*)"remote-ctrl.xml")+1);
00092       strcpy(P_cmd_line->m_args[P_cmd_line->m_nb_args-1],
00093              (char*)"remote-ctrl.xml");
00094       break;
00095     }
00096   }
00097 
00098 //    for (L_i = 0 ; L_i < P_cmd_line->m_nb_args ; L_i ++) {
00099 //      std::cerr << "P_cmd_line->m_args[" << L_i << "] " << 
00100 //        P_cmd_line->m_args[L_i] << std::endl;
00101 //    }
00102 
00103   m_cmd_line_size =  P_cmd_line->m_nb_args ;
00104   m_cmd_line_values = P_cmd_line->m_args;
00105 
00106   m_xml_data = NULL ;
00107 
00108   m_do_display_control = false ;
00109   m_display_control = NULL ;
00110 
00111   m_do_log_stat_control = false ;
00112   m_log_stat_control = NULL ;
00113 
00114 
00115   m_nb_log_protocol_stat_control = 0 ;
00116   m_log_protocol_stat_control = NULL ;
00117 
00118 
00119   m_do_data_log_control = false ;
00120   m_data_log_control = NULL ;
00121 
00122   m_external_data_control = NULL ;
00123 
00124   m_display_traffic = NULL ;
00125   m_display_rtime = NULL ;
00126   m_display_help = NULL ;
00127 
00128   m_display_period = 0 ;
00129 
00130 }
00131 
00132 C_Generator::~C_Generator() {
00133 
00134   int  L_i ;
00135   GEN_DEBUG(1, "C_Generator::~C_Generator() start");
00136 
00137   DELETE_VAR(m_read_control);
00138   DELETE_VAR(m_scen_control);
00139 
00140   m_do_log_stat_control = false ;
00141   DELETE_VAR(m_log_stat_control);
00142 
00143   for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
00144     DELETE_VAR(m_log_protocol_stat_control[L_i]);
00145   }
00146 
00147   DELETE_TABLE(m_log_protocol_stat_control);
00148 
00149 
00150   DELETE_VAR(m_remote_control);
00151   m_do_remote_control = false ;
00152 
00153   DELETE_VAR(m_keyboard_control);
00154   m_do_keyboard_control = false ;
00155 
00156   DELETE_VAR(m_data_log_control);
00157   m_do_data_log_control = false ;
00158 
00159   m_do_display_control = false ;
00160   DELETE_VAR(m_display_control);
00161 
00162   DELETE_VAR(m_external_data_control);
00163 
00164   // generator model
00165   DELETE_VAR(m_channel_ctrl);
00166   DELETE_VAR(m_transport_ctrl);
00167 
00168   DELETE_VAR(m_protocol_ctrl);
00169   GEN_DEBUG(1, "C_Generator::~C_Generator() after protocol");
00170 
00171   // Close the Stat object
00172   C_GeneratorStats::instance() ->close();
00173 
00174   // DELETE_VAR (m_xml_data);
00175   m_xml_data = NULL ;
00176   m_cmd_line_size = 0 ;
00177   m_cmd_line_values = NULL ;
00178 
00179   DELETE_VAR(m_display_traffic);
00180   DELETE_VAR(m_display_rtime);
00181   DELETE_VAR(m_display_help);
00182 
00183   m_display_period = 0 ;
00184 
00185   GEN_DEBUG(1, "C_Generator::~C_Generator() end");
00186 }
00187 
00188 T_GeneratorError C_Generator::TaskProcedure() {
00189 
00190   T_GeneratorError        L_error_code = E_GEN_NO_ERROR ;
00191 
00192   pthread_t              *L_displayThread = NULL;
00193   pthread_t              *L_logStatThread = NULL;
00194   pthread_t              *L_logDataThread = NULL;
00195   pthread_t             **L_logProtocolStatThread = NULL ;
00196 
00197   pthread_t              *L_remoteThread = NULL;
00198   
00199   T_pEndTraceArg          L_arg           = NULL;
00200 
00201 
00202   int                     L_nb_protocol         ;
00203   int                     L_i                   ;
00204 
00205   char                    L_comment[80] ;
00206 
00207   GEN_DEBUG(1, "C_Generator::TaskProcedure() start");
00208 
00209   if (m_do_keyboard_control == true) {
00210     m_keyboard_control->init(this);
00211 
00212     m_keyboard_thread = start_thread_control(m_keyboard_control);
00213 
00214     // keyboard thread launched => modify end procedure for fatal errors
00215     ALLOC_VAR(L_arg, T_pEndTraceArg, sizeof(T_EndTraceArg));
00216     L_arg -> m_instance = m_keyboard_control ;
00217     L_arg -> m_thread = m_keyboard_thread ;
00218     
00219     use_trace_end(_gen_stop_controller, (void*)L_arg);
00220   }
00221 
00222   if (m_do_remote_control == true) {
00223     m_remote_control->init();
00224     L_remoteThread = start_thread_control(m_remote_control);
00225   }
00226 
00227   // start display control if needed
00228   if (m_do_display_control == true) {
00229 
00230     // retrieve nb protocol from protocol control
00231     C_ProtocolFrame      *L_ref            = NULL ;
00232     C_ProtocolStatsFrame *L_protocol_stats = NULL ;
00233     char                  L_char                  ;
00234 
00235     if (m_config->get_display_protocol_stat()) {
00236 
00237     L_nb_protocol = m_protocol_ctrl->get_nb_protocol();
00238     for (L_i = 0; L_i < L_nb_protocol ; L_i++) {
00239       L_ref = m_protocol_ctrl->get_protocol(L_i);
00240       snprintf(L_comment, 80, "Protocol %s screen(s)", 
00241               m_protocol_ctrl->get_protocol_name(L_i));
00242       L_protocol_stats = L_ref->get_stats() ;
00243       // retrieve m_protocol_stat for each protocol
00244       // add_display for each
00245       if (L_protocol_stats != NULL) {
00246         L_char = '3' + L_i ;
00247         m_display_control->add_screen(L_protocol_stats->get_display(),
00248                                       L_char,
00249                                       L_comment);
00250       }
00251     }
00252     }
00253 
00254     if (m_config->get_display_scenario_stat()) {
00255       // retrieve nb scenario from m_scen_control
00256       // int    L_nb_scen ;
00257       T_pC_Scenario L_init_scen     = NULL ;
00258       T_pC_Scenario L_traffic_scen  = NULL ;
00259       T_pC_Scenario L_abort_scen    = NULL ;
00260       C_ScenarioStats *L_scenario_stats = NULL ;
00261       
00262       L_char =   'A' ;
00263       
00264       // L_nb_scen = m_scen_control->get_nb_scenario();
00265       L_init_scen = m_scen_control->get_init_scenario() ;
00266       if (L_init_scen != NULL) {
00267         // there is a scenario init 
00268         L_scenario_stats = L_init_scen->get_stats();
00269         if (L_scenario_stats) {
00270           snprintf(L_comment, 80, "%s", "Scenario init stats");
00271           m_display_control->add_screen(L_scenario_stats,
00272                                         L_char,
00273                                         L_comment);
00274           L_char++;
00275         }
00276       }
00277       
00278       L_traffic_scen = m_scen_control->get_traffic_scenario() ;
00279       if (L_traffic_scen != NULL) {
00280         // there is a scenario traffic 
00281         L_scenario_stats = L_traffic_scen->get_stats();
00282         if (L_scenario_stats) {
00283           snprintf(L_comment, 80, "%s", "Scenario traffic stats");
00284           m_display_control->add_screen(L_scenario_stats,
00285                                         L_char,
00286                                         L_comment);
00287           L_char++;
00288         }
00289       }
00290       
00291       L_abort_scen = m_scen_control->get_abort_scenario() ;
00292       if (L_abort_scen != NULL) {
00293         // there is a scenario abort 
00294         L_scenario_stats = L_abort_scen->get_stats();
00295         if (L_scenario_stats) {
00296           snprintf(L_comment, 80, "%s", "Scenario abort stats");
00297           m_display_control->add_screen(L_scenario_stats,
00298                                         L_char,
00299                                         L_comment);
00300           L_char++;
00301         }
00302       }
00303       
00304       if (m_scen_control->get_nb_default_scenario() != 0) {
00305         // there is once or more scenario default 
00306         C_Scenario *L_default_scen ;
00307         int         L_default ;
00308         for (L_default = 0; L_default < m_scen_control->get_nb_default_scenario();
00309              L_default++) {
00310           L_default_scen = m_scen_control->get_default_scenario(L_default);
00311           L_scenario_stats = L_default_scen->get_stats();
00312           if (L_scenario_stats) {
00313             snprintf(L_comment, 80, "Scenario default %d stats", L_default);
00314             m_display_control->add_screen(L_scenario_stats,
00315                                           L_char,
00316                                           L_comment);
00317             L_char++;
00318           }
00319         }
00320       }
00321     }
00322     
00323     m_display_control->init_screens();
00324     L_displayThread = start_thread_control(m_display_control);
00325   }
00326   // start log stat control if needed
00327   if (m_do_log_stat_control == true) {
00328     L_logStatThread = start_thread_control(m_log_stat_control);
00329   }
00330 
00331   if (m_nb_log_protocol_stat_control) {
00332     ALLOC_TABLE(L_logProtocolStatThread,
00333                 pthread_t**,
00334                 sizeof(pthread_t*),
00335                 m_nb_log_protocol_stat_control);
00336     for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
00337       L_logProtocolStatThread[L_i] 
00338         = start_thread_control(m_log_protocol_stat_control[L_i]);
00339     }
00340   }
00341 
00342 
00343   // start log data control if needed
00344   if (m_do_data_log_control == true) {
00345     L_logDataThread = start_thread_control(m_data_log_control);
00346   }
00347 
00348   // start read controller
00349   if (L_error_code == E_GEN_NO_ERROR) {
00350     L_error_code = m_read_control -> run() ;
00351   }
00352 
00353   if (m_do_keyboard_control == true) {
00354     m_keyboard_control -> stop () ;
00355   }
00356 
00357   if (m_do_remote_control == true) {
00358     m_remote_control -> stop () ;
00359   }
00360 
00361   if (m_do_display_control == true) {
00362     m_display_control -> stop() ;
00363   }
00364   if (m_do_log_stat_control == true) {
00365     m_log_stat_control -> stop() ;
00366   }
00367   if (m_do_data_log_control == true) {
00368     m_data_log_control -> stop() ;
00369   }
00370   for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
00371     m_log_protocol_stat_control[L_i] -> stop() ;
00372   }
00373 
00374   GEN_DEBUG(1, "C_Generator::TaskProcedure() wait log data end");
00375   if (m_do_data_log_control == true) {
00376     wait_thread_control_end (L_logDataThread);
00377   }
00378 
00379   GEN_DEBUG(1, "C_Generator::TaskProcedure() wait log stat end");
00380   if (m_do_log_stat_control == true) {
00381     wait_thread_control_end (L_logStatThread);
00382   }
00383 
00384   if (m_do_remote_control == true) {
00385     wait_thread_control_end (L_remoteThread);
00386   }
00387 
00388 
00389   GEN_DEBUG(1, "C_Generator::TaskProcedure() wait display end");
00390   if (m_do_display_control == true) {
00391     wait_thread_control_end (L_displayThread);
00392   }
00393 
00394   GEN_DEBUG(1, "C_Generator::TaskProcedure() wait keyboard end");
00395   if (m_do_keyboard_control == true) {
00396     wait_thread_control_end (m_keyboard_thread);
00397     FREE_VAR(L_arg);
00398   }
00399 
00400   for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
00401     wait_thread_control_end(L_logProtocolStatThread[L_i]);
00402   }
00403   FREE_TABLE(L_logProtocolStatThread);
00404 
00405   // TO DO: delete thread_t struct
00406 
00407   GEN_DEBUG(1, "C_Generator::TaskProcedure() end");
00408   return (L_error_code);
00409 }
00410 
00411 T_GeneratorError C_Generator::InitProcedure() {
00412 
00413   T_GeneratorError                 L_genError = E_GEN_NO_ERROR ;
00414   C_XmlParser                      L_parser    ;
00415   int                              L_error     = 0 ;
00416   char                            *L_conf_file ;
00417   char                            *L_scen_file ;
00418   
00419   string_t                        *L_file_all        =NULL    ;
00420   T_pcharPlist                     L_dico_file_list           ;
00421   int                              L_i                        ;
00422   int                              L_number_file              ; 
00423   int                              L_size_dico_file_list      ;
00424   list_t<char*>::iterator          L_it                       ;
00425 
00426   char                            *L_remote_cmd               ;
00427   char                            *L_remote_dico_path         ;
00428 
00429 
00430   string_t                         L_log_file("") ;
00431 
00432   T_TrafficType                    L_trafficType ;
00433 
00434   bool                             L_action_check_abort = false ;
00435 
00436   long                             L_displayPeriod = 0 ;
00437   unsigned int                     L_logLevel ;
00438 
00439   long                             L_logStatPeriod = 0 ;
00440   string_t                         L_logStatFileName ;
00441 
00442   char*                            L_repart ;
00443 
00444   struct timeval                   L_time_file ;
00445   char                             L_time_char [TIME_STRING_LENGTH] ;
00446   size_t                           L_pos ;
00447 
00448   bool                             L_check_msg ;
00449 
00450   bool                             L_data_mesure = false ;
00451   char                            *L_external_data_file = NULL ;
00452 
00453   bool                             L_files_no_timestamp = false ;
00454 
00455   long                             L_logProtocolStatPeriod = 0    ;
00456   string_t                         L_logProtocolStatFileName      ;
00457   char                            *L_logProtocolStatName = NULL   ;
00458   list_t<char*>::iterator          L_it_elt                       ;
00459 
00460 
00461   GEN_DEBUG(1, "C_Generator::InitProcedure() start");
00462 
00463   GET_TIME(&L_time_file);
00464   time_tochar_minus(L_time_char, &L_time_file);
00465 
00466   // comand line analysis
00467   NEW_VAR(m_config, C_GeneratorConfig(m_cmd_line_size, m_cmd_line_values));
00468 
00469   // retrieve values from command line
00470   L_conf_file = m_config -> get_conf_file () ;
00471   L_logLevel  = m_config -> get_log_level () ;
00472   L_scen_file = m_config -> get_scen_file () ;
00473 
00474   L_dico_file_list = m_config -> get_dico_file_list () ;
00475   L_size_dico_file_list  = L_dico_file_list->size() ;
00476 
00477   L_check_msg = m_config -> get_check_msg () ;
00478 
00479   L_remote_cmd = m_config -> get_remote_cmd () ;
00480 
00481 
00482   L_remote_dico_path = m_config -> get_remote_dico_path () ;
00483 
00484   // configuration xml file analysis
00485   if (L_conf_file != NULL) {
00486 
00487     GEN_DEBUG(1," the conf file [" << L_conf_file << "]" );
00488     GEN_DEBUG(1," the number of dico [" << L_size_dico_file_list  << "]");
00489 
00490     L_number_file = L_size_dico_file_list + 2 ;
00491 
00492     NEW_TABLE(L_file_all, string_t, L_number_file); 
00493     L_file_all[0] = L_conf_file ;
00494 
00495     L_i=1;
00496     for (L_it = L_dico_file_list->begin();
00497          L_it != L_dico_file_list->end();
00498          L_it++) {
00499       
00500       if ((L_remote_cmd) && (strcmp(*L_it,(char*)"remote-ctrl.xml")== 0)) {
00501         char      L_name_dico[80];
00502         snprintf(L_name_dico, 80, 
00503                  "%s/%s",L_remote_dico_path,*L_it); 
00504         L_file_all[L_i] = L_name_dico ;
00505       } else {
00506         L_file_all[L_i] = *L_it;
00507       }
00508       L_i ++ ;
00509     }
00510     L_file_all[L_i] = L_scen_file;
00511 
00512     m_xml_data = L_parser.parse(L_number_file, L_file_all, &L_error);
00513     
00514     DELETE_TABLE(L_file_all);
00515 
00516     if (L_error != 0) {
00517       L_genError = E_GEN_FATAL_ERROR ;
00518     }
00519   }
00520 
00521   // config management
00522   if (L_genError == E_GEN_NO_ERROR) {
00523     GEN_DEBUG(1, "C_Generator::InitProcedure() m_config->fromXml called");
00524 
00525     L_genError = (m_config->fromXml(m_xml_data) == false) 
00526       ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00527   }
00528 
00529   if (L_genError == E_GEN_NO_ERROR) {
00530     L_files_no_timestamp = m_config -> get_files_no_timestamp () ;
00531     if (m_config->get_log_file() != NULL) {
00532       L_log_file.append(m_config->get_log_file()) ;
00533     }
00534 
00535     if (L_log_file != "") {
00536       
00537       bool L_found = false ;
00538       L_pos = L_log_file.find('.');
00539       
00540       while (L_pos < L_log_file.size()) {
00541         if (L_pos+1 < L_log_file.size()) {
00542           if (L_log_file[L_pos+1] != '.') {
00543             L_found = true ;
00544             if (L_files_no_timestamp == false) {
00545               L_log_file.insert(L_pos,L_time_char);
00546               L_log_file.insert(L_pos,".");
00547             }
00548           break ;
00549           } else {
00550           if (L_pos+2 < L_log_file.size()) {
00551             L_pos = L_log_file.find('.', L_pos+2);
00552           } else {
00553             break ;
00554           }
00555           }
00556         } else {
00557           break ;
00558         }
00559       }
00560       
00561       if (L_found == false) {
00562         if (L_files_no_timestamp == false) {
00563           L_log_file += "." ;
00564           L_log_file.append(L_time_char);
00565         }
00566       }
00567       
00568     }
00569     
00570   }
00571 
00572 
00573   // transport management
00574   if (L_genError == E_GEN_NO_ERROR) {
00575     GEN_DEBUG(1, "C_Generator::InitProcedure() m_transport_ctrl->fromXml called");
00576     L_genError = (m_transport_ctrl->fromXml(m_xml_data) == false) 
00577       ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00578   }
00579 
00580   // protocol management
00581   if (L_genError == E_GEN_NO_ERROR) {
00582     GEN_DEBUG(1, "C_Generator::InitProcedure() m_protocol_ctrl->fromXml called");
00583     L_genError = (m_protocol_ctrl->fromXml(m_xml_data, 
00584                                            m_config->get_config_param_list(),
00585                                            m_config->get_display_protocol_stat()) == false) 
00586       ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00587   }
00588 
00589   // display control update with protocol stats
00590   if (L_genError == E_GEN_NO_ERROR) {
00591     GEN_DEBUG(1, "C_Generator::InitProcedure() m_transport_ctrl->set_config_value called");
00592     L_genError = (m_transport_ctrl->set_config_value(m_config->get_config_param_list()) == false) 
00593    ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00594   }
00595 
00596   // channel management
00597   if (L_genError == E_GEN_NO_ERROR) {
00598     GEN_DEBUG(1, "C_Generator::InitProcedure() m_channel_ctrl->fromXml called");
00599     L_genError = (m_channel_ctrl->fromXml(m_xml_data, 
00600                                           m_protocol_ctrl, 
00601                                           m_transport_ctrl) == false) 
00602       ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00603   }
00604 
00605 
00606   GEN_DEBUG(1, "C_Generator::InitProcedure() fromXml called success");
00607   m_read_control -> set_config (m_config) ;
00608   m_scen_control -> set_config (m_config) ;
00609   
00610   if (m_config->get_value(E_CFG_OPT_RESP_TIME_REPART, &L_repart)) {
00611     C_GeneratorStats::instance() 
00612       ->setRepartitionResponseTime(L_repart);
00613   }
00614 
00615 
00616   if (L_genError == E_GEN_NO_ERROR) {
00617 
00618     unsigned int           L_external_select    ;
00619     bool                   L_result             ;
00620 
00621     if (m_config->get_value (E_CFG_OPT_EXTERNAL_DATA_FILE,
00622                              &L_external_data_file)) {
00623       if (L_external_data_file != NULL) {
00624         (void)m_config->get_value 
00625           (E_CFG_OPT_EXTERNAL_DATA_SELECT, &L_external_select);
00626 
00627         switch (L_external_select) {
00628         case 0:
00629           NEW_VAR(m_external_data_control, C_SequentialExtDataCtrl());
00630           break ;
00631         case 1:
00632           NEW_VAR(m_external_data_control, C_RandomExtDataCtrl());
00633           break ;
00634         default:
00635           GEN_FATAL(E_GEN_FATAL_ERROR, "Internal: Selection option not recognized for external data");
00636           break ;
00637         }
00638         
00639         L_result = m_external_data_control->init(L_external_data_file);
00640         if (L_result == false) {
00641           GEN_ERROR(E_GEN_FATAL_ERROR, "External data definition error");
00642           L_genError = E_GEN_FATAL_ERROR ;
00643         }
00644       }
00645     }
00646   }
00647 
00648   // scenario management 
00649   if (L_genError == E_GEN_NO_ERROR) {
00650     m_scen_control->set_external_data_controller(m_external_data_control);
00651     L_genError = (m_scen_control->fromXml(m_xml_data, 
00652                                           L_check_msg, 
00653                                           &L_data_mesure, 
00654                                           &L_trafficType,
00655                                           &L_action_check_abort) == false)
00656       ? E_GEN_FATAL_ERROR : E_GEN_NO_ERROR ;
00657   } 
00658 
00659 
00660   if (L_genError == E_GEN_NO_ERROR) {
00661     if (L_external_data_file == NULL) {
00662         if (m_scen_control->external_data_used() == true) {
00663           GEN_FATAL(E_GEN_FATAL_ERROR, "Using external data action with no external file definition");
00664           L_genError = E_GEN_FATAL_ERROR ;
00665         }
00666     }
00667   }
00668 
00669 
00670   if (L_genError == E_GEN_NO_ERROR) {
00671     m_read_control -> set_scenario_control (m_scen_control, L_trafficType) ;
00672   }
00673 
00674 
00675   if (L_genError == E_GEN_NO_ERROR) {
00676     init_trace (L_logLevel, 
00677                 L_log_file, 
00678                 m_config->get_timestamp_log()) ;
00679   }
00680 
00681 
00682   if (L_genError == E_GEN_NO_ERROR) {
00683 
00684 #if BYTE_ORDER == BIG_ENDIAN 
00685     GEN_LOG_EVENT_FORCE("Platform use BIG_ENDIAN coding");
00686 #else
00687     GEN_LOG_EVENT_FORCE("Platform use LITTLE_ENDIAN coding");
00688 #endif
00689 
00690     GEN_LOG_EVENT_FORCE("Integer32 Type size is: " << sizeof(T_Integer32));
00691 
00692     if (sizeof(T_Integer32) < 4) {
00693      GEN_FATAL(E_GEN_FATAL_ERROR, "Integer32 Type is not 4 bytes size minimum");
00694      L_genError = E_GEN_FATAL_ERROR ;
00695     }
00696   }
00697 
00698   if (L_genError == E_GEN_NO_ERROR) {
00699     GEN_LOG_EVENT_FORCE("Integer64 Type size is: " << sizeof(T_Integer64));
00700 
00701     if (sizeof(T_Integer64) < 8) {
00702      GEN_FATAL(E_GEN_FATAL_ERROR, "Integer64 Type is not 8 bytes size minimum");
00703      L_genError = E_GEN_FATAL_ERROR ;
00704     }
00705   }
00706 
00707   if (L_genError == E_GEN_NO_ERROR) {
00708     GEN_LOG_EVENT_FORCE(*m_config);
00709   }
00710 
00711   if (L_genError == E_GEN_NO_ERROR) {
00712 
00713     if ((m_config -> get_call_timeout_beh_abr () == true) &&
00714         (m_scen_control->get_abort_scenario() == NULL)) {
00715       // there isn't a scenario abort 
00716       GEN_LOG_EVENT_FORCE("Abort scenario not found and you use call-timeout-behaviour-abort traffic option ");
00717     }
00718 
00719     if (L_action_check_abort == true) {
00720       GEN_LOG_EVENT_FORCE("Abort scenario not found and you use an action check with behavior abort");
00721 
00722     }
00723     
00724   }
00725 
00726 
00727 
00728   if (L_genError == E_GEN_NO_ERROR) {
00729     L_genError = m_read_control -> init() ;
00730   }
00731 
00732   if (L_genError == E_GEN_NO_ERROR) {
00733 
00734     // display control init
00735     if (m_config->get_value (E_CFG_OPT_DISPLAY_PERIOD, 
00736                              (unsigned long *)&L_displayPeriod)) {
00737       if (L_displayPeriod != 0) {
00738         m_display_period = L_displayPeriod ;
00739         
00740 
00741         m_do_display_control = true ;
00742         NEW_VAR(m_display_control, C_DisplayControl());
00743         m_display_control->init(L_displayPeriod);
00744 
00745         // set generator screens
00746         NEW_VAR(m_display_traffic, C_DisplayTraffic());
00747         NEW_VAR(m_display_rtime, C_DisplayRTime());
00748         NEW_VAR(m_display_help, C_DisplayHelp());
00749 
00750         m_display_help->set_display_control(m_display_control);
00751 
00752 
00753         m_display_control
00754           ->add_help('+',
00755                      (char*)"Increase call rate by call-rate-scale (default 1)");
00756         m_display_control
00757           ->add_help('-',
00758                      (char*)"Decrease call rate by call-rate-scale (default 1)");
00759         
00760         m_display_control
00761           ->add_help('c',
00762                      (char*)"Command mode (format : set var value)");
00763 
00764         m_display_control
00765           ->add_help('q',
00766                      (char*)"Tool exit (forced when pressed two times)");
00767         m_display_control
00768           ->add_help('p',
00769                      (char*)"Pause traffic");
00770         m_display_control
00771           ->add_help('r',
00772                      (char*)"Resume traffic (after pause)");
00773         m_display_control
00774           ->add_help('f',
00775                      (char*)"Force init scenario (switch to traffic)");
00776 
00777 
00778         m_display_control
00779           ->add_help('d',
00780                      (char*)"Reset cumulative counters for each stat set in config file");
00781 
00782         m_display_control
00783           ->add_help('a',
00784                      (char*)"activate/deactivate: percentage in Response time screen");
00785         
00786 
00787         m_display_control->add_screen(m_display_traffic,
00788                                       '1',
00789                                       (char *)"Traffic screen");
00790         m_display_control->add_screen(m_display_rtime,
00791                                       '2',
00792                                       (char *)"Response time screen");
00793 
00794         m_display_control->add_screen(m_display_help,
00795                                       'h',
00796                                       (char *)"Help screen");
00797 
00798       }
00799     }
00800 
00801 
00802     // stat logging init
00803     if (m_config->get_value (E_CFG_OPT_LOG_STAT_PERIOD, 
00804                              (unsigned long *)&L_logStatPeriod)) {
00805       if (L_logStatPeriod != 0) {
00806         if (m_config->get_value (E_CFG_OPT_LOG_STAT_FILE,
00807                                  L_logStatFileName)) {
00808           if (L_logStatFileName != "") {
00809 
00810             bool L_found = false ;
00811             L_pos = L_logStatFileName.find('.');
00812             while (L_pos < L_logStatFileName.size()) {
00813               if (L_pos+1 < L_logStatFileName.size()) {
00814                 if (L_logStatFileName[L_pos+1] != '.') {
00815                   L_found = true ;
00816                   if (L_files_no_timestamp == false) {
00817                     L_logStatFileName.insert(L_pos,L_time_char);
00818                     L_logStatFileName.insert(L_pos,".");
00819                   }
00820                   break ;
00821                 } else {
00822                   if (L_pos+2 < L_logStatFileName.size()) {
00823                     L_pos = L_logStatFileName.find('.', L_pos+2);
00824                   } else {
00825                     break ;
00826                   }
00827                 }
00828               } else {
00829                 break ;
00830               }
00831             }
00832             
00833             if (L_found == false) {
00834               L_logStatFileName += "." ;
00835               L_logStatFileName.append(L_time_char);
00836             }
00837             m_do_log_stat_control = true ;
00838             NEW_VAR(m_log_stat_control, C_LogStatControl());
00839             m_log_stat_control->init(L_logStatPeriod, L_logStatFileName);
00840           } else {
00841             GEN_ERROR(E_GEN_FATAL_ERROR, "No file defined for statistic log");
00842           }
00843         }
00844       }
00845     }
00846 
00847     if (L_remote_cmd) {
00848       char                    L_remote_address[80] ;
00849 
00850       snprintf(L_remote_address, 80, 
00851                "mode=server;source=%s",L_remote_cmd); 
00852       NEW_VAR(m_remote_control, C_RemoteControl(this,m_protocol_ctrl,L_remote_address)); // add a port
00853       m_do_remote_control = true ; 
00854     }
00855 
00856     if (m_config->get_display_protocol_stat()) {
00857       if (m_config->get_value (E_CFG_OPT_LOG_PROTOCOL_STAT_PERIOD, 
00858                                (unsigned long *)&L_logProtocolStatPeriod)) {
00859         if (L_logProtocolStatPeriod != 0) {
00860           // retrieve the name of protocol stat
00861           if (m_config->get_value (E_CFG_OPT_LOG_PROTOCOL_STAT_FILE,
00862                                    L_logProtocolStatFileName)) {
00863             if (L_logProtocolStatFileName == "") {
00864               GEN_ERROR(E_GEN_FATAL_ERROR, "No file defined for statistic log");
00865             } else {
00866               // retrieve protocol 
00867               if (m_config->get_value (E_CFG_OPT_LOG_PROTOCOL_STAT_NAME,
00868                                        &L_logProtocolStatName)) {
00869                 if (L_logProtocolStatName == NULL) {
00870                   GEN_ERROR(E_GEN_FATAL_ERROR, "No name defined for protocol statistic log");
00871                 } else {
00872                   // Regular expression
00873                   T_charPlist                *L_protocol_list                ;
00874                   bool                        L_all_found      = false       ;
00875                   C_ProtocolFrame            *L_ref = NULL                   ;
00876                   // char                       *L_protocol_name  = NULL        ;
00877                   int                         L_nb_protocol    = 0           ;
00878                   C_ProtocolStatsFrame       *L_protocol_stats = NULL        ;
00879                   C_LogProtocolStatControl   *L_proto_stat_inter = NULL      ;
00880                   int                         L_id                           ;
00881                   
00882                   
00883                   NEW_VAR (L_protocol_list, T_charPlist);
00884                   
00885                   if (m_config->analyze_protocol_stat(L_logProtocolStatName,
00886                                                       L_protocol_list,
00887                                                       &L_all_found) == -1 ) {
00888                     GEN_ERROR(E_GEN_FATAL_ERROR, "Regular expression building is failed");
00889                     L_genError = E_GEN_FATAL_ERROR ;
00890                   } else {
00891                     // retrieve nb protocol from m_protocol_control
00892                     if (L_all_found == true) {
00893                       L_nb_protocol = m_protocol_ctrl->get_nb_protocol();
00894                       for (L_i = 0; L_i < L_nb_protocol ; L_i++) {
00895                         // retrieve the name of each protocol
00896                         // L_protocol_name = m_protocol_ctrl->get_protocol_name (L_i);
00897                         L_ref = m_protocol_ctrl->get_protocol(L_i);                   
00898                         L_protocol_stats = L_ref->get_stats() ;               
00899                         if (L_protocol_stats != NULL) {
00900                           L_protocol_stats->do_log();
00901                           m_nb_log_protocol_stat_control++ ;
00902                         }
00903                       }
00904                       
00905                       if ( m_nb_log_protocol_stat_control != 0 ) {
00906                         
00907                         NEW_TABLE(m_log_protocol_stat_control,
00908                                   C_LogProtocolStatControl*,
00909                                   m_nb_log_protocol_stat_control);
00910                         
00911                         L_id = 0;
00912                         for (L_i = 0; L_i < L_nb_protocol ; L_i++) {
00913                           
00914                           L_proto_stat_inter 
00915                             = create_log_protocol_stats(m_protocol_ctrl->get_protocol(L_i),
00916                                                         L_time_char,
00917                                                         L_logProtocolStatFileName,
00918                                                         L_logProtocolStatPeriod,
00919                                                         L_files_no_timestamp);
00920                           if (L_proto_stat_inter != NULL) {
00921                             m_log_protocol_stat_control[L_id] = L_proto_stat_inter ;
00922                             L_id++ ;
00923                           }
00924                           
00925                           
00926                         } //  for (L_i = 0; L_i < L_nb_protocol ; L_i++)
00927                     } // if ( m_nb_log_protocol_stat_control != 0 )
00928                       
00929                       
00930                     } else {
00931                       if (!L_protocol_list->empty()) {
00932                         for (L_it_elt  = L_protocol_list->begin() ;
00933                              L_it_elt != L_protocol_list->end()  ;
00934                              L_it_elt++) {
00935                           L_ref = m_protocol_ctrl->get_protocol (*L_it_elt);
00936                           if (L_ref == NULL) {
00937                             GEN_ERROR(E_GEN_FATAL_ERROR, "No protocol found for this name ["
00938                                       << *L_it_elt << "]");
00939                           } else {
00940                             
00941                             L_protocol_stats = L_ref->get_stats() ;                   
00942                             if (L_protocol_stats != NULL) {
00943                               L_protocol_stats->do_log();
00944                               m_nb_log_protocol_stat_control++ ; 
00945                             }
00946                           } 
00947                         } // for (L_it_elt...
00948                         
00949                         if ( m_nb_log_protocol_stat_control != 0 ) {
00950                           
00951                           NEW_TABLE(m_log_protocol_stat_control,
00952                                     C_LogProtocolStatControl*,
00953                                     m_nb_log_protocol_stat_control);
00954                           
00955                           L_id = 0;
00956                           
00957                           for (L_it_elt  = L_protocol_list->begin() ;
00958                                L_it_elt != L_protocol_list->end()  ;
00959                                L_it_elt++) {
00960                             L_ref = m_protocol_ctrl->get_protocol (*L_it_elt);
00961                             
00962                             if (L_ref != NULL) {
00963                               L_protocol_stats = L_ref->get_stats() ;      
00964                               if (L_protocol_stats != NULL) {
00965                                 L_proto_stat_inter 
00966                                   = create_log_protocol_stats(L_ref,
00967                                                               L_time_char,
00968                                                               L_logProtocolStatFileName,
00969                                                               L_logProtocolStatPeriod,
00970                                                               L_files_no_timestamp);
00971                                 if (L_proto_stat_inter != NULL) {
00972                                   m_log_protocol_stat_control[L_id] = L_proto_stat_inter ;
00973                                   L_id++ ;
00974                                 }
00975                               } // if (L_protocol_stats != NULL)
00976                             } // if (L_ref != NULL)
00977                           } // for (L_it_elt  = L_protocol_list->begin() ..
00978                         } // if ( m_nb_log_protocol_stat_control != 0 )
00979                       } // if (!L_protocol_list->empty())
00980                     } // if (L_all_found == true)
00981                     
00982                     
00983                     // remove list 
00984                     if (!L_protocol_list->empty()) {
00985                       // for each element free table
00986                       for (L_it_elt  = L_protocol_list->begin() ;
00987                            L_it_elt != L_protocol_list->end()  ;
00988                            L_it_elt++) {
00989                         FREE_TABLE(*L_it_elt);
00990                       }
00991                       L_protocol_list->erase(L_protocol_list->begin(),
00992                                              L_protocol_list->end());
00993                       
00994                     }
00995                     DELETE_VAR(L_protocol_list);
00996                     
00997                     
00998                   } // if (m_config->analyze_protocol_stat...
00999                   
01000                 } //  if (L_logProtocolStat != NULL)
01001               }
01002             } // if (L_logProtocolStatFileName == "")
01003           }
01004         } // if (L_logProtocolStatPeriod != 0)
01005       } // if (m_config->get_value (...
01006     }
01007 
01008 
01009     // data logging init
01010     if (L_data_mesure == true) {
01011 
01012       string_t              L_data_log_file ;
01013       size_t                L_data_nb = 0;
01014       unsigned long         L_data_val, L_data_period ;
01015 
01016       unsigned long         L_data_rtdistrib = 0 ;
01017 
01018       // take values from configuration
01019       if (m_config->get_value (E_CFG_OPT_DATA_LOG_FILE,
01020                                L_data_log_file)) {
01021 
01022         if (L_data_log_file != "") {
01023           bool L_found = false ;
01024           (void)m_config->get_value 
01025             (E_CFG_OPT_DATA_LOG_PERIOD, &L_data_period);
01026           (void)m_config->get_value
01027             (E_CFG_OPT_DATA_LOG_NUMBER, &L_data_val);
01028           L_data_nb = (size_t) L_data_val ;
01029 
01030           // add date
01031           L_pos = L_data_log_file.find('.');
01032           
01033           while (L_pos < L_data_log_file.size()) {
01034             if (L_pos+1 < L_data_log_file.size()) {
01035               if (L_data_log_file[L_pos+1] != '.') {
01036                 L_found = true ;
01037                 if (L_files_no_timestamp == false) {
01038                   L_data_log_file.insert(L_pos,L_time_char);
01039                   L_data_log_file.insert(L_pos,".");
01040                 }
01041                 break ;
01042               } else {
01043                 if (L_pos+2 < L_data_log_file.size()) {
01044                   L_pos = L_data_log_file.find('.', L_pos+2);
01045                 } else {
01046                   break ;
01047                 }
01048               }
01049             } else {
01050               break ;
01051             }
01052           }
01053           
01054           if (L_found == false) {
01055             L_data_log_file += "." ;
01056             L_data_log_file.append(L_time_char);
01057           }
01058           
01059           if (L_data_nb == 0) {
01060             m_do_data_log_control = false ;
01061           } else {
01062             if (L_data_period == 0) {
01063               m_do_data_log_control = false ;
01064             } else {
01065               m_do_data_log_control = true ;
01066             }
01067           }
01068 
01069         } else {
01070           m_do_data_log_control = false ;
01071         }
01072 
01073         if (m_do_data_log_control == true) {
01074           
01075           GEN_DEBUG(1, "C_Generator::InitProcedure() L_data_nb is " << L_data_nb);
01076           GEN_DEBUG(1, "C_Generator::InitProcedure() L_data_period is " << L_data_period);
01077 
01078           (void)m_config->get_value 
01079             (E_CFG_OPT_DATA_LOG_RTDISTRIB, &L_data_rtdistrib);
01080           
01081           if (L_data_rtdistrib == 0) {
01082             NEW_VAR(m_data_log_control, 
01083                     C_DataLogControl(2*L_data_nb,
01084                                      L_data_nb,
01085                                      (char*)L_data_log_file.c_str(),
01086                                      L_data_period));
01087           } else {
01088             NEW_VAR(m_data_log_control, 
01089                     C_DataLogRTDistrib(2*L_data_nb,
01090                                        L_data_nb,
01091                                        (char*)L_data_log_file.c_str(),
01092                                        L_data_period, L_data_rtdistrib));
01093             
01094           }
01095           
01096           m_scen_control->set_data_log_controller(m_data_log_control);
01097           m_data_log_control->init();
01098           if (L_data_rtdistrib == 0) {
01099             if (m_data_log_control->data((char*)"time-ms;response-time-ms;") == 0) {
01100               GEN_ERROR(E_GEN_FATAL_ERROR, "Internal error");
01101               L_genError = E_GEN_FATAL_ERROR ;
01102             }
01103           }
01104         }
01105         
01106       }
01107       
01108     }
01109     
01110   }
01111 
01112 
01113   if (L_genError == E_GEN_NO_ERROR) {
01114 
01115     // background mode
01116     if (m_config->get_bg_mode() == true) {
01117 
01118       pid_t L_pid;
01119 
01120       m_do_display_control = false ; // no display
01121       m_do_keyboard_control = false ; // no keyboard control
01122       switch(L_pid = fork())
01123         {
01124         case -1:
01125           // error when forking !
01126           GEN_FATAL(E_GEN_FATAL_ERROR, "Forking error");
01127           break ;
01128         case 0:
01129           // child process - poursuing the execution
01130           // background mode ok
01131           break;
01132         default:
01133           // parent process - killing the parent - the child get the parent pid
01134           iostream_error << "Background mode - PID [" 
01135                          << L_pid << "]" << iostream_endl ;
01136           exit(0);
01137         }
01138       
01139     } else {
01140       m_do_keyboard_control = true ;
01141     }
01142     GEN_LOG_EVENT_FORCE("PID [" << getpid() << "]");
01143   }
01144 
01145   GEN_DEBUG(1, "C_Generator::InitProcedure() end");
01146   return (L_genError);
01147 }
01148 
01149 T_GeneratorError C_Generator::EndProcedure() {
01150 
01151   GEN_DEBUG(1, "C_Generator::EndProcedure() start");
01152 
01153   DELETE_VAR(m_config);
01154 
01155   GEN_DEBUG(1, "C_Generator::EndProcedure() end");
01156   
01157   return (E_GEN_NO_ERROR);
01158 }
01159 
01160 T_GeneratorError C_Generator::ForcedStoppingProcedure() {
01161 
01162   // just other thread concerned
01163   m_read_control->stop();
01164 
01165   m_nb_forced++ ;
01166 
01167   if (m_nb_forced >= 2) {
01168     iostream_error << "Forced exit" << iostream_endl ;
01169     GEN_LOG_EVENT_FORCE("Forced exit");
01170     ExitProcedure() ;
01171   }
01172 
01173   return (E_GEN_NO_ERROR);
01174 }
01175 
01176 
01177 T_GeneratorError C_Generator::StoppingProcedure() {
01178 
01179   GEN_DEBUG(1, "C_Generator::StoppingProcedure () start");
01180   // just other thread concerned
01181   m_read_control -> stop() ;
01182 
01183   GEN_DEBUG(1, "C_Generator::StoppingProcedure () end");
01184   return (E_GEN_NO_ERROR);
01185 }
01186 
01187 void C_Generator::set_screen (char P_key) {
01188   GEN_DEBUG(1, "C_Generator::set_screen(" << P_key << ") start");
01189   if (m_display_control != NULL) {
01190     m_display_control->set_screen(P_key) ;
01191   }
01192   GEN_DEBUG(1, "C_Generator::set_screen() end");
01193 }
01194 
01195 void C_Generator::pause_traffic () {
01196   GEN_DEBUG(1, "C_Generator::pause_traffic()");
01197   if (m_read_control != NULL) {
01198     m_read_control -> pause_traffic () ;
01199   }
01200   GEN_DEBUG(2, "C_Generator::pause_traffic()");
01201 }
01202 
01203 void C_Generator::pause_display () {
01204   GEN_DEBUG(1, "C_Generator::pause_traffic()");
01205   if (m_display_control != NULL) {
01206     m_display_control -> pause () ;
01207   }
01208   GEN_DEBUG(2, "C_Generator::pause_traffic()");
01209 }
01210 
01211 void C_Generator::restart_traffic () {
01212   GEN_DEBUG(1, "C_Generator::restart_traffic()");
01213   if (m_read_control != NULL) {
01214     m_read_control -> restart_traffic () ;
01215   }
01216   GEN_DEBUG(2, "C_Generator::restart_traffic()");
01217 }
01218 
01219 void C_Generator::force_init() {
01220   if (m_read_control != NULL) {
01221     m_read_control -> force_init() ;
01222   }
01223 }
01224 
01225 unsigned long C_Generator::get_call_rate() {
01226   unsigned long L_ret = 0 ;
01227   if (m_read_control != NULL) {
01228     L_ret = m_read_control -> get_call_rate ();
01229   }
01230   return (L_ret);
01231 }
01232 
01233 
01234 void C_Generator::change_call_rate(T_GenChangeOperation P_op,
01235                                    unsigned long        P_rate) {
01236   if (m_read_control != NULL) {
01237     m_read_control -> change_call_rate (P_op, P_rate);
01238   }
01239 }
01240 
01241 void C_Generator::change_rate_scale(unsigned long P_scale) {
01242   if (m_read_control != NULL) {
01243     m_read_control -> change_rate_scale (P_scale);
01244   }
01245 }
01246 
01247 
01248 void C_Generator::change_burst (unsigned long P_burst) {
01249   if (m_read_control != NULL) {
01250     m_read_control -> change_burst (P_burst);
01251   }
01252 }
01253 
01254 
01255 void C_Generator::change_display_period(long P_period) {
01256   if ((m_display_period) && (P_period) && (m_display_control != NULL) ) {
01257     m_display_control -> change_display_period (P_period);
01258   }
01259 }
01260 
01261 void C_Generator::ExitProcedure () {
01262   int L_i = 0 ;
01263   if (m_do_keyboard_control == true) {
01264     m_keyboard_control -> stop () ;
01265   }
01266   if (m_do_display_control == true) {
01267     m_display_control -> stop() ;
01268   }
01269   if (m_do_log_stat_control == true) {
01270     m_log_stat_control -> stop() ;
01271   }
01272 
01273   if (m_do_remote_control == true) {
01274     m_remote_control -> stop () ;
01275   }
01276 
01277   if (m_do_keyboard_control == true) {
01278     m_keyboard_control->force_end_procedure();
01279   }
01280   for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
01281     m_log_protocol_stat_control[L_i] -> stop() ;
01282   }
01283   exit (-1) ;
01284 }
01285 
01286 void _gen_stop_controller (void* P_arg) {
01287 
01288   T_pEndTraceArg L_arg = (T_pEndTraceArg) P_arg ;
01289 
01290   if (L_arg != NULL) {
01291     if (L_arg->m_instance != NULL) {
01292       L_arg->m_instance->stop() ;
01293       if (L_arg->m_thread != NULL) {
01294         wait_thread_control_end(L_arg->m_thread);
01295       }
01296     }
01297   }
01298 
01299 }
01300 
01301 
01302 C_LogProtocolStatControl* C_Generator::create_log_protocol_stats (C_ProtocolFrame *P_protocol,
01303                                                                   char            *P_timechar,
01304                                                                   string_t&        P_logProtocolStatFileName,
01305                                                                   unsigned long    P_log_period_period,
01306                                                                   bool             P_files_no_timestamp) {
01307   
01308   C_ProtocolStatsFrame       *L_protocol_stats   = NULL  ;
01309   C_LogProtocolStatControl   *L_proto_stat_inter = NULL  ;
01310   bool                        L_found            = false ;
01311   size_t                      L_pos                      ;
01312   char                       *L_protocol_name            ;
01313   string_t                    L_file_name("")            ;
01314   
01315   L_protocol_stats = P_protocol->get_stats() ;  
01316   L_protocol_name = P_protocol->name();
01317 
01318   L_file_name += P_logProtocolStatFileName ;
01319 
01320   if (L_protocol_stats != NULL) {
01321     
01322     L_pos = L_file_name.find('.');
01323     
01324     while (L_pos < L_file_name.size()) {
01325       if (L_pos+1 < L_file_name.size()) {
01326         if (L_file_name[L_pos+1] != '.') {
01327           L_found = true ;
01328           if (P_files_no_timestamp == false) {
01329             L_file_name.insert(L_pos,P_timechar);
01330             L_file_name.insert(L_pos,".");
01331           }
01332 
01333           L_file_name.insert(L_pos,L_protocol_name);
01334           L_file_name.insert(L_pos,".");
01335           break ;
01336         } else {
01337           if (L_pos+2 < L_file_name.size()) {
01338             L_pos = L_file_name.find('.', L_pos+2);
01339           } else {
01340             break ;
01341           }
01342         }
01343       } else {
01344         break ;
01345       }
01346     }
01347     
01348     if (L_found == false) {
01349       L_file_name += "." ;
01350       L_file_name.insert(L_pos,L_protocol_name);
01351       if (P_files_no_timestamp == false) {
01352         L_file_name += "." ;
01353         L_file_name.append(P_timechar);
01354       }
01355     }
01356         
01357     NEW_VAR(L_proto_stat_inter, 
01358             C_LogProtocolStatControl(L_protocol_stats));
01359     
01360     L_proto_stat_inter->init(P_log_period_period, L_file_name);
01361   }
01362 
01363   return (L_proto_stat_inter);
01364                           
01365 }                 
01366 
01367 
01368 void C_Generator::reset_cumul_counters () {
01369   int  L_i ;
01370   GEN_DEBUG(1, "C_Generator::reset_cumul_counters() start");
01371 
01372   GEN_LOG_EVENT_FORCE("Reset cumulative counters for each stat set in config file");
01373 
01374   if (m_do_log_stat_control == true) {
01375     m_log_stat_control -> reset_cumul_counters() ;
01376   }
01377 
01378   for (L_i = 0 ; L_i < m_nb_log_protocol_stat_control ; L_i++ ) {
01379     m_log_protocol_stat_control[L_i] -> reset_cumul_counters() ;
01380   }
01381 
01382   if (m_config->get_display_scenario_stat()) {
01383     // retrieve nb scenario from m_scen_control
01384     T_pC_Scenario L_init_scen     = NULL ;
01385     T_pC_Scenario L_traffic_scen  = NULL ;
01386     T_pC_Scenario L_abort_scen    = NULL ;
01387     C_ScenarioStats *L_scenario_stats = NULL ;
01388     
01389     L_init_scen = m_scen_control->get_init_scenario() ;
01390     if (L_init_scen != NULL) {
01391       // there is a scenario init 
01392       L_scenario_stats = L_init_scen->get_stats();
01393       if (L_scenario_stats) {
01394         L_scenario_stats->reset_cumul_counters() ;
01395       }
01396     }
01397     
01398     L_traffic_scen = m_scen_control->get_traffic_scenario() ;
01399     if (L_traffic_scen != NULL) {
01400       // there is a scenario traffic 
01401       L_scenario_stats = L_traffic_scen->get_stats();
01402       if (L_scenario_stats) {
01403         L_scenario_stats->reset_cumul_counters() ;
01404       }
01405     }
01406       
01407     L_abort_scen = m_scen_control->get_abort_scenario() ;
01408     if (L_abort_scen != NULL) {
01409       // there is a scenario abort 
01410       L_scenario_stats = L_abort_scen->get_stats();
01411       if (L_scenario_stats) {
01412         L_scenario_stats->reset_cumul_counters() ;
01413       }
01414     }
01415       
01416     if (m_scen_control->get_nb_default_scenario() != 0) {
01417       // there is once or more scenario default 
01418       C_Scenario *L_default_scen ;
01419       int         L_default ;
01420       for (L_default = 0; L_default < m_scen_control->get_nb_default_scenario();
01421            L_default++) {
01422         L_default_scen = m_scen_control->get_default_scenario(L_default);
01423         L_scenario_stats = L_default_scen->get_stats();
01424         if (L_scenario_stats) {
01425           L_scenario_stats->reset_cumul_counters() ;
01426         }
01427       }
01428     }
01429   } //  if (m_config->get_display_scenario_stat())
01430 
01431 
01432   GEN_DEBUG(1, "C_Generator::reset_cumul_counters() end");
01433 }
01434 
01435 
01436 
01437 
01438 void C_Generator::activate_percent_traffic () {
01439   if (m_do_log_stat_control == true) {
01440     m_log_stat_control -> activate_percent_traffic() ;
01441   }
01442 }
01443 
01444 
01445 
01446 

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