Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_Scenario.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_Scenario.hpp"
00021 #include "Utils.hpp"
00022 #include "GeneratorTrace.hpp"
00023 #include "GeneratorError.h"
00024 #include "BufferUtils.hpp"
00025 #include "TimeUtils.hpp"
00026 #include "C_CommandAction.hpp"
00027 
00028 #include "C_ScenarioControl.hpp"
00029 
00030 #include "integer_t.hpp" // For strtoul_f
00031 
00032   
00033 
00034 const char* command_name_table [] = {
00035   "send",
00036   "receive",
00037   "wait-ms",
00038   "end"} ;
00039 
00040 const char* action_name_table [] = {
00041   "open",
00042   "close",
00043   "store",
00044   "restore",
00045   "start-timer",
00046   "stop-timer",
00047   "set-value",
00048   "inc-counter",
00049   "check-presence",
00050   "restore-from-external",
00051   "inc-var",
00052   "check-value",
00053   "check-order",
00054   "set-new-session-id",
00055   "transport-option",
00056   "set-bit",
00057   "set-value-bit",
00058   "E_NB_ACTION_SCEN",  // internal actions after this value
00059   "E_ACTION_SCEN_INTERNAL_INIT_DONE",
00060   "E_ACTION_SCEN_CHECK_ALL_MSG",
00061   "E_ACTION_SCEN_ADD_IN_CALL_MAP",
00062   "E_ACTION_SCEN_SELECT_EXTERNAL_DATA_LINE"
00063 } ;
00064 
00065 
00066 C_Scenario::C_Scenario (C_ScenarioControl     *P_scenario_control,
00067                         C_ChannelControl      *P_channel_control,
00068                         C_ExternalDataControl *P_external_data_control,
00069                         T_exeCode              P_exe_code,
00070                         char                  *P_behaviour,
00071                         bool                   P_retrans_enabled,
00072                         unsigned int           P_check_mask, 
00073                         T_CheckBehaviour       P_checkBehaviour
00074                         ) {
00075 
00076   GEN_DEBUG(1, "C_Scenario::C_Scenario() start");
00077   m_sequence_max = 0 ;
00078   m_sequence_size = 0 ;
00079   m_cmd_sequence = NULL ;
00080   m_stat = C_GeneratorStats::instance() ;
00081   m_check_mask = P_check_mask ;
00082   m_check_behaviour = P_checkBehaviour ;
00083   m_log = NULL ;
00084   m_channel_ctrl = P_channel_control ;
00085   m_controller = P_scenario_control ;
00086   m_external_data = P_external_data_control ;
00087   m_stats  = NULL ;
00088 
00089   m_exe_end_code = P_exe_code ;
00090   m_retrans_enabled        = P_retrans_enabled ;
00091   m_nb_retrans = 0 ;
00092 
00093   m_nb_send_per_scene = 0 ;
00094   m_nb_recv_per_scene = 0 ;
00095 
00096   if (P_behaviour == NULL) {
00097     m_behaviour = E_BEHAVIOUR_SCEN_SUCCESS ;
00098   } else {
00099     if (strcmp(P_behaviour,(char*)"failed") == 0) {
00100       m_behaviour = E_BEHAVIOUR_SCEN_FAILED ;
00101       m_exe_end_code = E_EXE_ERROR ;
00102     } else if (strcmp(P_behaviour,(char*)"ignore") == 0) { 
00103       m_behaviour = E_BEHAVIOUR_SCEN_IGNORE ;
00104       m_exe_end_code = E_EXE_IGNORE ;
00105     } else {
00106       m_behaviour = E_BEHAVIOUR_SCEN_SUCCESS ;
00107     }
00108   }
00109 
00110   GEN_DEBUG(1, "C_Scenario::C_Scenario() end");
00111 
00112 }
00113 
00114 C_Scenario::~C_Scenario () {
00115 
00116   int          L_i;
00117   int          L_j;
00118   GEN_DEBUG(1, "C_Scenario::~C_Scenario() start seq nb: " << m_sequence_max);
00119 
00120   if (m_sequence_max) {
00121 
00122     for (L_i = 0; L_i < m_sequence_max; L_i++) {
00123 
00124       // Do not delete sequence message here 
00125       // this is made during specific protocol clean
00126 
00127       if (m_cmd_sequence[L_i].m_pre_action != 0) {
00128         for (L_j = 0 ; L_j < m_cmd_sequence[L_i].m_pre_action; L_j ++) {
00129           DELETE_VAR(m_cmd_sequence[L_i].m_pre_action_table[L_j]);
00130         }
00131         FREE_TABLE(m_cmd_sequence[L_i].m_pre_action_table);
00132       }
00133 
00134       if (m_cmd_sequence[L_i].m_post_action != 0) {
00135         for (L_j = 0 ; L_j < m_cmd_sequence[L_i].m_post_action; L_j ++) {
00136           DELETE_VAR(m_cmd_sequence[L_i].m_post_action_table[L_j]);
00137         }
00138         FREE_TABLE(m_cmd_sequence[L_i].m_post_action_table);
00139       }
00140 
00141     }
00142   }
00143   FREE_TABLE(m_cmd_sequence);
00144   m_sequence_max = 0 ;
00145   m_sequence_size = 0 ;
00146   m_stat = NULL ;
00147   m_stats = NULL ;
00148 
00149   m_nb_retrans = 0 ;
00150 
00151   m_nb_send_per_scene = 0 ;
00152   m_nb_recv_per_scene = 0 ;
00153 
00154 
00155   GEN_DEBUG(1, "C_Scenario::~C_Scenario() end");
00156 }
00157 
00158 void C_Scenario::set_data_log_controller (C_DataLogControl *P_log) {
00159   int L_i, L_j ;
00160   GEN_DEBUG(1, "C_Scenario::set_data_log_controller start");
00161   m_log = P_log ;
00162 
00163   for(L_i=0; L_i < m_sequence_max; L_i++) {
00164     for (L_j = 0 ; L_j < m_cmd_sequence[L_i].m_pre_action; L_j ++) {
00165       m_cmd_sequence[L_i].m_pre_action_table[L_j]
00166         ->update_log_controller(P_log);
00167     }
00168     for (L_j = 0 ; L_j < m_cmd_sequence[L_i].m_post_action; L_j ++) {
00169       m_cmd_sequence[L_i].m_post_action_table[L_j]
00170         ->update_log_controller(P_log);
00171     }
00172   }
00173   GEN_DEBUG(1, "C_Scenario::set_data_log_controller m_log is" << m_log);
00174   GEN_DEBUG(1, "C_Scenario::set_data_log_controller end");
00175 }
00176 
00177 T_CallContextState C_Scenario::first_state () {
00178   T_CallContextState L_ret ;
00179 
00180   GEN_DEBUG(1, "C_Scenario::first_state() start");
00181 
00182   switch(m_cmd_sequence[0].m_type) {
00183   case E_CMD_SCEN_SEND:
00184     L_ret = E_CTXT_SEND ;
00185     break ;
00186   case E_CMD_SCEN_RECEIVE:
00187     L_ret = E_CTXT_RECEIVE ;
00188     break ;
00189   case E_CMD_SCEN_WAIT:
00190     L_ret = 
00191       E_CTXT_WAIT+m_cmd_sequence[0].m_duration_index ;
00192     break ; 
00193   default:
00194     L_ret = E_CTXT_NBSTATE ;
00195     break ;
00196   }
00197   GEN_DEBUG(1, "C_Scenario::first_state() end");
00198   return (L_ret);
00199 }
00200 
00201 T_exeCode C_Scenario::execute_cmd_retrans (int P_index, T_pCallContext P_callCtxt) {
00202   T_exeCode           L_exeCode    = E_EXE_NOERROR ;
00203   int                 L_cmdIdx                     ;
00204   T_pCmd_scenario     L_pCmd                       ;
00205   
00206   struct timezone     L_timeZone                   ;
00207   
00208   C_MessageFrame     *L_retransMsg = NULL          ;
00209   int                 L_channel_id = -1            ;
00210 
00211   GEN_DEBUG(1, "C_Scenario::execute_cmd_retrans() start");
00212 
00213   // retrieve command execution informations
00214   L_cmdIdx = P_callCtxt->m_retrans_cmd_idx[P_index];
00215   L_pCmd = &m_cmd_sequence[L_cmdIdx] ;
00216 
00217   switch (L_pCmd->m_type) {
00218 
00219   case E_CMD_SCEN_SEND: {
00220     
00221     L_channel_id = L_pCmd -> m_channel_id ;
00222     L_retransMsg = P_callCtxt->m_retrans_msg[P_index] ;
00223       
00224     if (m_channel_ctrl->
00225         send_to_channel(L_channel_id, P_callCtxt->m_channel_table, L_retransMsg)) {
00226       
00227       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR, 
00228                     "Send error on call with session-id ["
00229                     << P_callCtxt->m_id_table[L_channel_id] << "]");
00230       
00231       L_exeCode = E_EXE_ERROR_SEND ;
00232     } else {
00233       // to modify use a new counter 
00234       m_stat -> executeStatAction (C_GeneratorStats::E_SEND_MSG);
00235       gettimeofday(&(P_callCtxt->m_retrans_time[P_index]), &L_timeZone) ;
00236       (P_callCtxt->m_nb_retrans_done[P_index]) ++;
00237       if (m_stats) {
00238         m_stats->updateStats(L_cmdIdx,C_ScenarioStats::E_RETRANS,0);
00239         // m_stats->updateStats(L_cmdIdx,C_ScenarioStats::E_MESSAGE,0);
00240 
00241       }
00242     }
00243   }
00244   break ;
00245   default:
00246     GEN_DEBUG (1, "C_Scenario::execute_cmd() Incorrect type "
00247                << L_pCmd->m_type
00248                << " command execution");
00249     L_exeCode = E_EXE_ERROR;
00250     break ;
00251   }
00252   
00253   GEN_DEBUG(1, "C_Scenario::execute_cmd_retrans() end");
00254   return (L_exeCode);
00255 }
00256 
00257 
00258 T_exeCode C_Scenario::execute_cmd (T_pCallContext P_callCtxt,
00259                                    bool P_resume) {
00260 
00261   T_exeCode           L_exeCode = E_EXE_NOERROR ;
00262   int                 L_cmdIdx  ;
00263   T_pCmd_scenario     L_pCmd ;
00264 
00265   struct timezone     L_timeZone ;
00266 
00267   C_MessageFrame                  *L_sendMsg = NULL ;
00268   int                              L_channel_id = -1    ;
00269 
00270 
00271   GEN_DEBUG(1, "C_Scenario::execute_cmd() start");
00272 
00273   // retrieve command execution informations
00274   L_cmdIdx = P_callCtxt->get_current_cmd_idx();
00275   L_pCmd = &m_cmd_sequence[L_cmdIdx] ;
00276 
00277 
00278   switch (L_pCmd->m_type) {
00279 
00280   case E_CMD_SCEN_SEND: {
00281 
00282 
00283     GEN_DEBUG (1, "C_Scenario::execute_cmd() send command execution");
00284 
00285     if (P_resume == false) {
00286 
00287       L_channel_id = L_pCmd -> m_channel_id ;
00288 
00289       L_sendMsg = (m_channel_ctrl->get_channel_protocol(L_channel_id))
00290         ->create_new_message(L_pCmd->m_message);
00291 
00292       // now execution of the pre-actions
00293       if (L_pCmd->m_pre_action != 0) {
00294         L_exeCode = execute_action(L_pCmd, P_callCtxt, 
00295                                    L_sendMsg, 
00296                                    L_pCmd->m_pre_action,
00297                                    L_pCmd->m_pre_action_table,
00298                                    L_pCmd->m_message) ;
00299       }
00300     } else {
00301       L_channel_id = L_pCmd -> m_channel_id ;
00302       L_sendMsg = P_callCtxt->m_suspend_msg ;
00303     }
00304 
00305     if ((L_exeCode == E_EXE_NOERROR) && (L_exeCode != E_EXE_SUSPEND)) {  
00306 
00307       if (m_channel_ctrl->send_to_channel(L_channel_id, P_callCtxt->m_channel_table, L_sendMsg)) {
00308 
00309         GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR, 
00310                       "Send error on call with session-id ["
00311                       << P_callCtxt->m_id_table[L_channel_id] << "]");
00312 
00313         L_exeCode = E_EXE_ERROR_SEND ;
00314       } else {
00315         m_stat -> executeStatAction (C_GeneratorStats::E_SEND_MSG);
00316         gettimeofday(&P_callCtxt->m_current_time, &L_timeZone) ;
00317         
00318         if (m_stats) {
00319           m_stats->updateStats(L_cmdIdx,C_ScenarioStats::E_MESSAGE,0);
00320         }
00321 
00322 
00323         if (m_retrans_enabled) {
00324           if (L_pCmd->m_retrans_delay > 0) {
00325             P_callCtxt->m_retrans_context.m_retrans_index = L_pCmd->m_retrans_index ;
00326             P_callCtxt->m_retrans_context.m_retrans_delay_index = L_pCmd->m_retrans_delay_index ;
00327             P_callCtxt->m_retrans_context.m_context = P_callCtxt ;
00328             // std::cerr << "m_retrans_context.m_context =" << P_callCtxt << std::endl ;
00329             P_callCtxt->m_retrans_time[L_pCmd->m_retrans_index] = P_callCtxt->m_current_time ;
00330             P_callCtxt->m_retrans_cmd_idx[L_pCmd->m_retrans_index] = L_cmdIdx;
00331             P_callCtxt->m_retrans_msg[L_pCmd->m_retrans_index] = L_sendMsg ;
00332             P_callCtxt->m_retrans_to_do = true ;
00333           }
00334         }
00335       }
00336     }
00337 
00338     if ((L_exeCode == E_EXE_NOERROR) && (L_exeCode != E_EXE_SUSPEND)) {  
00339       // now execute post actions
00340       if (L_pCmd->m_post_action != 0) {
00341         L_exeCode = execute_action(L_pCmd, P_callCtxt, 
00342                                    L_sendMsg, 
00343                                    L_pCmd->m_post_action,
00344                                    L_pCmd->m_post_action_table,
00345                                    L_pCmd->m_message) ;
00346       }
00347     }
00348 
00349 
00350     if (L_exeCode != E_EXE_SUSPEND) {
00351       if ((m_retrans_enabled) && (L_pCmd->m_retrans_delay > 0)) {
00352         L_sendMsg = NULL ;
00353       } else {
00354         DELETE_VAR(L_sendMsg);
00355       }
00356     }
00357 
00358 
00359   }
00360     
00361     break ;
00362 
00363   case E_CMD_SCEN_RECEIVE: {
00364 
00365     C_MessageFrame *L_msgReceived  = NULL ;
00366 
00367     GEN_DEBUG (1, "C_Scenario::execute_cmd() receive command execution");
00368 
00369     // => check channel first
00370     L_channel_id = L_pCmd -> m_channel_id ;
00371     if (L_channel_id != P_callCtxt->m_channel_received) {
00372       GEN_ERROR(E_GEN_FATAL_ERROR, "Channel error: expected channel ["
00373                 << L_channel_id 
00374                 << "] received on [" 
00375                 << P_callCtxt->m_channel_received << "]");
00376       L_exeCode = E_EXE_ERROR_MSG ;
00377     } else {
00378     
00379       L_msgReceived = P_callCtxt->get_msg_received() ;
00380 
00381       if (L_msgReceived -> update_fields(L_pCmd->m_message)) {
00382         GEN_LOG_EVENT(LOG_LEVEL_MSG, 
00383                       "Received [" << *L_msgReceived << "]");
00384       } 
00385 
00386       if (L_msgReceived -> compare_types (L_pCmd->m_message)) {
00387         
00388         if (P_resume == false) {
00389           if (L_pCmd->m_pre_action != 0) {
00390             L_exeCode = execute_action(L_pCmd, P_callCtxt, 
00391                                        L_msgReceived,
00392                                        L_pCmd->m_pre_action,
00393                                        L_pCmd->m_pre_action_table,
00394                                        L_pCmd->m_message) ;
00395           }
00396         }
00397         
00398         if (L_exeCode == E_EXE_NOERROR) {
00399           
00400           if (L_pCmd->m_post_action != 0) {
00401             L_exeCode = execute_action(L_pCmd, P_callCtxt, 
00402                                        L_msgReceived, 
00403                                        L_pCmd->m_post_action,
00404                                        L_pCmd->m_post_action_table,
00405                                        L_pCmd->m_message) ;
00406           }
00407           
00408         }
00409         L_msgReceived -> update_message_stats();
00410         
00411         if (m_stats) {
00412           m_stats->updateStats(L_cmdIdx,C_ScenarioStats::E_MESSAGE,0);
00413         }
00414 
00415       } else {
00416         // unexpected message during call
00417         // TO-DO
00418         GEN_ERROR(1,"Unexpexted message that doesn't match the scenario.");
00419 
00420         if (!(genTraceLevel & gen_mask_table[LOG_LEVEL_TRAFFIC_ERR])) {
00421           GEN_ERROR(1,"Activate 'T' log level");
00422         }
00423 
00424         GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR, 
00425                       "Unexpected message on call with session-id ["
00426                       << P_callCtxt->m_id_table[L_channel_id] << "]");
00427 
00428         if ((L_msgReceived)->name() == NULL) {
00429           GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00430                         "Received [Unknown Message] when expecting ["
00431                         << (L_pCmd->m_message)->name()
00432                         << "]");
00433         } else {
00434           GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00435                         "Received ["
00436                         << (L_msgReceived)->name()
00437                         << "] when expecting ["
00438                         << (L_pCmd->m_message)->name()
00439                         << "]");
00440         }
00441         GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR, 
00442                       "Unexpected message received [ " << (*L_msgReceived) <<
00443                       GEN_HEADER_LOG << GEN_HEADER_NO_LEVEL << "]" );
00444         
00445         // TO-DO
00446         L_exeCode = E_EXE_ERROR_MSG ;
00447         
00448         if (m_stats) {
00449           m_stats->updateStats(L_cmdIdx,C_ScenarioStats::E_UNEXPECTED,0);
00450         }
00451       }
00452     }
00453 
00454   }
00455     break ;
00456 
00457  
00458   case E_CMD_SCEN_WAIT:
00459     GEN_DEBUG (1, "C_Scenario::execute_cmd() wait command execution");
00460     L_exeCode = E_EXE_NOERROR ;
00461     break ;
00462 
00463 
00464   case E_CMD_SCEN_END:
00465     GEN_DEBUG (1, "C_Scenario::execute_cmd() scenario end command execution");
00466     L_exeCode = m_exe_end_code;
00467     break ;
00468 
00469   default:
00470     GEN_DEBUG (1, "C_Scenario::execute_cmd() unknown "
00471                   << L_pCmd->m_type
00472                   << " command execution");
00473     break ;
00474   }
00475 
00476   switch (L_exeCode) {
00477   case E_EXE_NOERROR:
00478 
00479     // Get the next command
00480     P_callCtxt -> next_cmd();
00481     L_cmdIdx = P_callCtxt->get_current_cmd_idx();
00482 
00483     // Get new command description
00484     L_pCmd = &m_cmd_sequence[L_cmdIdx] ;
00485 
00486     // Change call context state dependinf on new command
00487     switch (L_pCmd->m_type) {
00488     case E_CMD_SCEN_RECEIVE:
00489       P_callCtxt->set_state(E_CTXT_RECEIVE);
00490       break ;
00491     case E_CMD_SCEN_SEND:
00492       P_callCtxt->set_state(E_CTXT_SEND);
00493       break ;
00494     case E_CMD_SCEN_WAIT:
00495       P_callCtxt->set_state(E_CTXT_WAIT+L_pCmd->m_duration_index);
00496       break ;
00497     case E_CMD_SCEN_END :
00498       L_exeCode = E_EXE_NOERROR;
00499       if (L_pCmd->m_pre_action != 0) {
00500         L_exeCode = execute_action(L_pCmd, P_callCtxt, 
00501                                    NULL,
00502                                    L_pCmd->m_pre_action,
00503                                    L_pCmd->m_pre_action_table,
00504                                    L_pCmd->m_message) ;
00505       }
00506       if (L_exeCode == E_EXE_NOERROR) {
00507         if (L_pCmd->m_post_action != 0) {
00508           L_exeCode = execute_action(L_pCmd,P_callCtxt, 
00509                                      NULL, 
00510                                      L_pCmd->m_post_action,
00511                                      L_pCmd->m_post_action_table,
00512                                      L_pCmd->m_message) ;
00513         }
00514       }
00515       if (L_exeCode == E_EXE_NOERROR) {
00516         L_exeCode = m_exe_end_code;
00517       }
00518       break ;
00519     default:
00520       break;
00521     }
00522     break ;
00523   case E_EXE_TRAFFIC_END:
00524   case E_EXE_DEFAULT_END:
00525   case E_EXE_ABORT_END:
00526   case E_EXE_INIT_END:
00527     break ;
00528   default:
00529     if (L_channel_id > 0) {
00530       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR, 
00531                     "Execution error on call with session-id ["
00532                     << P_callCtxt->m_id_table[L_channel_id] << "]");
00533     }
00534     break ;
00535   }
00536 
00537   GEN_DEBUG(1, "C_Scenario::execute_cmd() end");
00538   return (L_exeCode);
00539 }
00540 
00541 bool C_Scenario::check_msg_received (T_pReceiveMsgContext P_rcvMsg) {
00542 
00543   bool L_msgOk = false ;
00544   GEN_DEBUG(1, "C_Scenario::check_msg_received() start");
00545 
00546   // Don t forget to dump the message ?
00547   // GEN_DEBUG(1, "C_Scenario::check_msg_received the message is [" << (*P_msg) << "]");
00548   GEN_DEBUG(1, "C_Scenario::check_msg_received m_sequence_max [" << m_sequence_max << "]");
00549 
00550   if (m_sequence_max) {
00551     if (m_cmd_sequence[0].m_type == E_CMD_SCEN_RECEIVE) {
00552       L_msgOk = ((P_rcvMsg->m_msg) -> update_fields(m_cmd_sequence[0].m_message)) ;
00553        
00554       if (L_msgOk) {
00555         L_msgOk = (P_rcvMsg->m_msg) -> compare_types(m_cmd_sequence[0].m_message) &&
00556           (P_rcvMsg->m_channel == m_cmd_sequence[0].m_channel_id) ;
00557       }
00558     }
00559   }
00560 
00561   GEN_DEBUG(1, "C_Scenario::check_msg_received the result of compare type message is " << L_msgOk);
00562   GEN_DEBUG(1, "C_Scenario::check_msg_received() end");
00563   return (L_msgOk) ;
00564 }
00565 
00566 void C_Scenario::set_size (size_t P_size) {
00567   GEN_DEBUG(1, "C_Scenario::set_size() start");
00568   m_sequence_size = P_size ;
00569   ALLOC_TABLE(m_cmd_sequence, T_pCmd_scenario, 
00570               sizeof(T_cmd_scenario), m_sequence_size);
00571   GEN_DEBUG(1, "C_Scenario::set_size() end");
00572 }
00573 
00574 
00575 
00576 size_t C_Scenario::define_post_actions  
00577 (int          P_nb_post_action,
00578  C_CommandAction** P_post_act_table) {
00579 
00580   GEN_DEBUG(1, "C_Scenario::define_post_actions() start");
00581 
00582   if (m_sequence_max-1 >= 0) {
00583     T_pCmd_scenario L_cmd_sequence = &(m_cmd_sequence[m_sequence_max-1]) ;
00584     if ((P_nb_post_action != 0) && (P_post_act_table != NULL)) {
00585       delete_post_actions(m_sequence_max-1);
00586       L_cmd_sequence->m_post_action = P_nb_post_action ;
00587       L_cmd_sequence->m_post_action_table = P_post_act_table ;
00588     }
00589   }
00590 
00591   GEN_DEBUG(1, "C_Scenario::define_post_actions() end");
00592 
00593   return (m_sequence_max);
00594 }
00595 
00596 
00597 size_t C_Scenario::define_pre_actions  
00598 (int               P_nb_pre_action,
00599  C_CommandAction** P_pre_act_table) {
00600 
00601   GEN_DEBUG(1, "C_Scenario::define_post_actions() start");
00602 
00603   if (m_sequence_max-1 >= 0) {
00604     T_pCmd_scenario L_cmd_sequence = &(m_cmd_sequence[m_sequence_max-1]) ;
00605     if ((P_nb_pre_action != 0) && (P_pre_act_table != NULL)) {
00606       L_cmd_sequence->m_pre_action = P_nb_pre_action ;
00607       L_cmd_sequence->m_pre_action_table = P_pre_act_table ;
00608     }
00609   }
00610 
00611   GEN_DEBUG(1, "C_Scenario::define_post_actions() end");
00612 
00613   return (m_sequence_max);
00614 }
00615 
00616 
00617 
00618 
00619 size_t C_Scenario::add_cmd  (T_cmd_type          P_type,
00620                              int                 P_channel_id,
00621                              T_pC_MessageFrame   P_msg,
00622                              int                 P_nb_pre_action,
00623                              C_CommandAction**   P_pre_act_table,
00624                              unsigned long       P_retrans_delay) {
00625 
00626   GEN_DEBUG(1, "C_Scenario::add_cmd() start");
00627 
00628   if (m_sequence_max < m_sequence_size) {
00629 
00630     T_pCmd_scenario L_cmd_sequence = &(m_cmd_sequence[m_sequence_max]) ;
00631 
00632     L_cmd_sequence->m_type = P_type ;
00633     switch (P_type) {
00634 
00635     case E_CMD_SCEN_SEND: 
00636       m_nb_send_per_scene++;
00637       break ;
00638       
00639     case E_CMD_SCEN_RECEIVE:
00640       m_nb_recv_per_scene++;
00641       break ;
00642     default :
00643       break;
00644     }
00645 
00646     L_cmd_sequence->m_message = P_msg ;
00647     L_cmd_sequence->m_channel_id = P_channel_id ;
00648 
00649 
00650     if (m_retrans_enabled == false) {
00651       L_cmd_sequence->m_retrans_delay = 0 ;
00652       L_cmd_sequence->m_retrans_index = 0 ;
00653       L_cmd_sequence->m_retrans_delay_index = 0 ;
00654     } else {
00655       L_cmd_sequence->m_retrans_delay = P_retrans_delay ;
00656       if (P_retrans_delay > 0) {
00657         L_cmd_sequence->m_retrans_index = m_nb_retrans ;
00658         m_nb_retrans++;
00659       } else {
00660         L_cmd_sequence->m_retrans_index = 0 ;
00661       }
00662       L_cmd_sequence->m_retrans_delay_index = 0 ;
00663     }
00664 
00665     if ((P_nb_pre_action != 0) && (P_pre_act_table != NULL)) {
00666       L_cmd_sequence->m_pre_action = P_nb_pre_action ;
00667       L_cmd_sequence->m_pre_action_table = P_pre_act_table ;
00668     } else {
00669       L_cmd_sequence->m_pre_action = 0 ;
00670       L_cmd_sequence->m_pre_action_table = NULL ;
00671     }
00672     L_cmd_sequence->m_post_action = 0 ;
00673     L_cmd_sequence->m_post_action_table = NULL ;
00674 
00675     m_sequence_max++ ;
00676     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00677     return (m_sequence_max);
00678   } else {
00679     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00680     return (0) ;
00681   }
00682 }
00683 
00684 size_t C_Scenario::add_cmd  (T_cmd_type    P_type,
00685                              unsigned long P_duration) {
00686   GEN_DEBUG(1, "C_Scenario::add_cmd() start");
00687   if (m_sequence_max < m_sequence_size) {
00688     T_pCmd_scenario L_cmd_sequence = &(m_cmd_sequence[m_sequence_max]) ;
00689     L_cmd_sequence->m_type = P_type ;
00690     L_cmd_sequence->m_duration = P_duration ;
00691 
00692     L_cmd_sequence->m_pre_action = 0 ;
00693     L_cmd_sequence->m_pre_action_table = NULL ;
00694     L_cmd_sequence->m_post_action = 0 ;
00695     L_cmd_sequence->m_post_action_table = NULL ;
00696 
00697     L_cmd_sequence->m_retrans_delay = 0 ;
00698     L_cmd_sequence->m_retrans_index = 0 ;
00699     L_cmd_sequence->m_retrans_delay_index = 0 ;
00700 
00701     m_sequence_max++ ;
00702     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00703     return (m_sequence_max);
00704   } else {
00705     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00706     return (0) ;
00707   }
00708 }
00709 
00710 size_t C_Scenario::add_cmd  (T_cmd_type    P_type) {
00711   GEN_DEBUG(1, "C_Scenario::add_cmd() start");
00712   if (m_sequence_max < m_sequence_size) {
00713     T_pCmd_scenario L_cmd_sequence = &(m_cmd_sequence[m_sequence_max]) ;
00714     L_cmd_sequence->m_type = P_type ;
00715 
00716     L_cmd_sequence->m_pre_action = 0 ;
00717     L_cmd_sequence->m_pre_action_table = NULL ;
00718     L_cmd_sequence->m_post_action = 0 ;
00719     L_cmd_sequence->m_post_action_table = NULL ;
00720 
00721     L_cmd_sequence->m_retrans_delay = 0 ;
00722     L_cmd_sequence->m_retrans_index = 0 ;
00723     L_cmd_sequence->m_retrans_delay_index = 0 ;
00724 
00725     m_sequence_max++ ;
00726     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00727     return (m_sequence_max);
00728   } else {
00729     GEN_DEBUG(1, "C_Scenario::add_cmd() end");
00730     return (0) ;
00731   }
00732 }
00733 
00734 iostream_output& operator<<(iostream_output& P_ostream, C_Scenario& P_scen) {
00735   
00736   // to be updated
00737   int L_i ;
00738 
00739   for (L_i = 0 ;
00740        L_i < P_scen.m_sequence_max;
00741        L_i++) {
00742     switch (P_scen.m_cmd_sequence[L_i].m_type) {
00743     case E_CMD_SCEN_SEND:
00744       P_ostream << "send " ;
00745       break ;
00746     case E_CMD_SCEN_RECEIVE:
00747       P_ostream << "receive " ;
00748       break ;
00749     case E_CMD_SCEN_WAIT:
00750       P_ostream << "wait (" << P_scen.m_cmd_sequence[L_i].m_duration << ")" ;
00751       break ;
00752     case E_CMD_SCEN_END:
00753       P_ostream << "end" ;
00754       break ;
00755     case E_NB_CMD_SCEN:
00756       break ;
00757     }
00758     P_ostream << iostream_endl ;
00759   }
00760 
00761   return (P_ostream);
00762 }
00763 
00764 T_exeCode C_Scenario::execute_action(T_pCmd_scenario P_pCmd,
00765                                      T_pCallContext  P_callCtxt,
00766                                      C_MessageFrame *P_msg,
00767                                      int             P_nbActions,
00768                                      C_CommandAction** P_actions,
00769                                      C_MessageFrame *P_ref) {
00770 
00771   T_exeCode           L_exeCode = E_EXE_NOERROR ;
00772   int                 L_i ;
00773 
00774   C_CommandAction*    L_current_action;
00775 
00776   bool                L_suspend = false 
00777 
00778 
00779   GEN_DEBUG(1, "C_Scenario::execute_action() start");
00780   GEN_DEBUG(1, "C_Scenario::execute_action() P_nbActions is " << 
00781                   P_nbActions);
00782 
00783   for (L_i = 0; L_i < P_nbActions ; L_i++) {
00784 
00785     L_current_action = P_actions[L_i] ;
00786     L_exeCode = L_current_action->execute(P_pCmd,
00787                                           P_callCtxt,
00788                                           P_msg,
00789                                           P_ref);
00790     
00791     if (L_exeCode == E_EXE_SUSPEND ) {
00792       L_suspend = true;
00793     }
00794 
00795 
00796   } // for L_i
00797 
00798 
00799   if ((L_exeCode == E_EXE_NOERROR) && (L_suspend == true)) {
00800     L_exeCode = E_EXE_SUSPEND ;
00801   }
00802 
00803   
00804   GEN_DEBUG(1, "C_Scenario::execute_action() end");
00805   return (L_exeCode);
00806 }
00807 
00808 void C_Scenario::update_retrans_delay_cmd (size_t P_nb, unsigned long *P_table) {
00809   int      L_i ;
00810   size_t   L_j ;
00811   for(L_i=0; L_i < m_sequence_max; L_i++) {
00812     if (m_cmd_sequence[L_i].m_retrans_delay > 0 ) {
00813       for (L_j = 0; L_j < P_nb; L_j++) {
00814         if (m_cmd_sequence[L_i].m_retrans_delay == P_table[L_j]) {
00815           m_cmd_sequence[L_i].m_retrans_delay_index = L_j ;
00816           break ;
00817         }
00818       }
00819     }
00820   }
00821 }
00822 
00823 void C_Scenario::update_wait_cmd (size_t P_nb, unsigned long *P_table) {
00824   int      L_i ;
00825   size_t   L_j ;
00826   for(L_i=0; L_i < m_sequence_max; L_i++) {
00827     if (m_cmd_sequence[L_i].m_type == E_CMD_SCEN_WAIT) {
00828       for (L_j = 0; L_j < P_nb; L_j++) {
00829 
00830         if (m_cmd_sequence[L_i].m_duration == P_table[L_j]) {
00831           m_cmd_sequence[L_i].m_duration_index = L_j ;
00832           break ;
00833         }
00834       }
00835     }
00836   }
00837 }
00838 
00839 void C_Scenario::delete_post_actions (int P_cmd_index) {
00840 
00841   int L_j ;
00842 
00843   if (m_cmd_sequence[P_cmd_index].m_post_action != 0) {
00844     for (L_j = 0 ; L_j < m_cmd_sequence[P_cmd_index].m_post_action; L_j ++) {
00845       DELETE_VAR(m_cmd_sequence[P_cmd_index].m_post_action_table[L_j])
00846     }
00847     FREE_TABLE(m_cmd_sequence[P_cmd_index].m_post_action_table);
00848     m_cmd_sequence[P_cmd_index].m_post_action = 0 ;
00849   }
00850 }
00851 
00852 void C_Scenario::set_stats (C_ScenarioStats *P_scenStat) {
00853   m_stats = P_scenStat ;
00854 }
00855 
00856 C_ScenarioStats* C_Scenario::get_stats () {
00857   return (m_stats) ;
00858 }
00859 
00860 void C_Scenario::delete_stats () {
00861   DELETE_VAR(m_stats);
00862 }
00863 
00864 
00865 T_exeCode    C_Scenario::get_exe_end_code() {
00866   return (m_exe_end_code)  ;
00867 }
00868 
00869 int C_Scenario::get_nb_retrans ()
00870 {
00871   return (m_nb_retrans);
00872 }
00873 
00874 T_pCmd_scenario C_Scenario::get_commands() {
00875   return (m_cmd_sequence);
00876 }
00877 
00878 
00879 int C_Scenario::get_nb_send_per_scen ()
00880 {
00881   return (m_nb_send_per_scene);
00882 }
00883 
00884 
00885 int C_Scenario::get_nb_recv_per_scen ()
00886 {
00887   return (m_nb_recv_per_scene);
00888 }

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