00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_CallContext.hpp"
00021 #include "C_Scenario.hpp"
00022 #include "GeneratorTrace.hpp"
00023 #include "C_CallControl.hpp"
00024
00025 #include "Utils.hpp"
00026
00027 int C_CallContext::m_nb_channel = 0 ;
00028
00029 T_pValueData
00030 C_CallContext::set_id(int P_channel_id, T_pValueData P_val) {
00031 m_id_table[P_channel_id] = *P_val ;
00032 if (P_val->m_type == E_TYPE_STRING) {
00033 ALLOC_TABLE(m_id_table[P_channel_id].m_value.m_val_binary.m_value,
00034 unsigned char*,
00035 sizeof(unsigned char),
00036 P_val->m_value.m_val_binary.m_size);
00037 memcpy (m_id_table[P_channel_id].m_value.m_val_binary.m_value,
00038 P_val->m_value.m_val_binary.m_value,
00039 P_val->m_value.m_val_binary.m_size);
00040 m_id_table[P_channel_id].m_value.m_val_binary.m_size
00041 = P_val->m_value.m_val_binary.m_size ;
00042 }
00043 return (&m_id_table[P_channel_id]);
00044 }
00045
00046
00047 void C_CallContext::next_cmd() {
00048 m_current_cmd_idx++;
00049 }
00050
00051
00052 void C_CallContext::reset_id(int P_channel_id) {
00053 if (m_id_table[P_channel_id].m_type == E_TYPE_STRING) {
00054 if (m_id_table[P_channel_id].m_value.m_val_binary.m_size) {
00055 FREE_TABLE(m_id_table[P_channel_id].m_value.m_val_binary.m_value);
00056 }
00057 }
00058 m_id_table[P_channel_id].m_type = E_TYPE_NUMBER ;
00059 m_id_table[P_channel_id].m_value.m_val_number = 0 ;
00060 }
00061
00062 void C_CallContext::reset_id () {
00063 int L_i ;
00064 for (L_i = 0 ; L_i < m_nb_channel; L_i++) {
00065 if (m_id_table[L_i].m_type == E_TYPE_STRING) {
00066 if (m_id_table[L_i].m_value.m_val_binary.m_size) {
00067 FREE_TABLE(m_id_table[L_i].m_value.m_val_binary.m_value);
00068 }
00069 }
00070 m_id_table[L_i].m_type = E_TYPE_NUMBER ;
00071 m_id_table[L_i].m_value.m_val_number = 0 ;
00072 }
00073 }
00074
00075
00076 void C_CallContext::reset_memory(int P_id) {
00077 GEN_DEBUG(2, "C_CallContext::reset_memory start P_id: " << P_id
00078 << " type: " << m_memory_table[P_id].m_type);
00079
00080 if (m_memory_table[P_id].m_type == E_TYPE_STRING) {
00081 if (m_memory_table[P_id].m_value.m_val_binary.m_size) {
00082 FREE_TABLE(m_memory_table[P_id].m_value.m_val_binary.m_value);
00083 }
00084 }
00085 m_memory_table[P_id].m_type = E_TYPE_NUMBER ;
00086 m_memory_table[P_id].m_value.m_val_number = 0 ;
00087
00088 GEN_DEBUG(2, "C_CallContext::reset_memory end");
00089 }
00090
00091
00092 C_CallContext::C_CallContext(C_CallControl *P_call_control,
00093 int P_id, int P_nbChannel,
00094 int P_mem, int P_nbRetrans) : C_ContextFrame() {
00095 int L_i ;
00096 m_call_control = P_call_control ;
00097 m_internal_call_id = P_id ;
00098 m_state = E_CTXT_ERROR ;
00099 m_scenario = NULL ;
00100 m_msg_received = NULL ;
00101 m_current_cmd_idx = -1 ;
00102 m_selected_line = -1 ;
00103
00104
00105 if (P_mem) {
00106 ALLOC_TABLE(m_memory_table,
00107 T_pValueData,
00108 sizeof(T_ValueData),
00109 P_mem);
00110 for (L_i = 0; L_i < P_mem; L_i++) {
00111 m_memory_table[L_i].m_type = E_TYPE_NUMBER ;
00112 m_memory_table[L_i].m_value.m_val_number = 0 ;
00113 }
00114 m_nb_mem = P_mem ;
00115 } else {
00116 m_memory_table = NULL ;
00117 m_nb_mem = 0 ;
00118 }
00119 m_created_call = false ;
00120
00121 if (P_nbChannel) {
00122 m_nb_channel = P_nbChannel ;
00123 ALLOC_TABLE(m_channel_table,
00124 int *,
00125 sizeof(int),
00126 P_nbChannel);
00127 ALLOC_TABLE(m_id_table,
00128 T_pValueData,
00129 sizeof(T_ValueData),
00130 P_nbChannel);
00131 for(L_i = 0 ; L_i < P_nbChannel; L_i++) {
00132 m_channel_table[L_i] = -1 ;
00133 m_id_table[L_i].m_type = E_TYPE_NUMBER ;
00134 m_id_table[L_i].m_value.m_val_number = 0 ;
00135 }
00136 }
00137
00138 m_nb_retrans = P_nbRetrans ;
00139 if (P_nbRetrans) {
00140 ALLOC_TABLE(m_retrans_msg, C_MessageFrame**, sizeof(C_MessageFrame*), P_nbRetrans);
00141 ALLOC_TABLE(m_retrans_time, struct timeval*, sizeof(struct timeval), P_nbRetrans);
00142 ALLOC_TABLE(m_nb_retrans_done, int*, sizeof(int), P_nbRetrans);
00143 ALLOC_TABLE(m_retrans_cmd_idx, int*, sizeof(int), P_nbRetrans);
00144
00145 ALLOC_TABLE(m_retrans_it, T_retransContextList::iterator*, sizeof(T_retransContextList::iterator), P_nbRetrans);
00146 ALLOC_TABLE(m_retrans_it_available, bool*, sizeof(bool), P_nbRetrans);
00147
00148
00149 for(L_i = 0 ; L_i < P_nbRetrans; L_i++) {
00150 m_nb_retrans_done[L_i] = 0 ;
00151 m_retrans_cmd_idx[L_i] = 0 ;
00152 m_retrans_msg[L_i] = NULL ;
00153 m_retrans_it_available[L_i] = false ;
00154 }
00155 } else {
00156 m_retrans_msg = NULL ;
00157 m_retrans_time = NULL ;
00158 m_nb_retrans_done = NULL ;
00159 m_retrans_cmd_idx = NULL ;
00160 m_retrans_it = NULL ;
00161 m_retrans_it_available = NULL ;
00162 }
00163
00164 m_retrans_to_do = false ;
00165
00166 }
00167
00168 C_CallContext::~C_CallContext() {
00169 int L_i ;
00170
00171 m_internal_call_id = -1 ;
00172 m_state = E_CTXT_ERROR ;
00173 m_scenario = NULL ;
00174 m_msg_received = NULL ;
00175 m_current_cmd_idx = -1 ;
00176 m_selected_line = -1 ;
00177 reset_id() ;
00178 m_created_call = false ;
00179
00180
00181 for (L_i = 0 ; L_i < m_nb_mem; L_i++) {
00182 reset_memory(L_i) ;
00183 }
00184 FREE_TABLE(m_memory_table);
00185 m_nb_mem = 0 ;
00186
00187 FREE_TABLE(m_channel_table);
00188
00189 FREE_TABLE(m_id_table);
00190
00191 clean_retrans();
00192
00193 FREE_TABLE(m_retrans_time);
00194 FREE_TABLE(m_nb_retrans_done);
00195 FREE_TABLE(m_retrans_cmd_idx);
00196
00197 FREE_TABLE(m_retrans_it);
00198 FREE_TABLE(m_retrans_it_available);
00199
00200 }
00201
00202 void C_CallContext::init() {
00203 int L_i ;
00204 m_state = E_CTXT_AVAILABLE ;
00205 m_current_cmd_idx = 0 ;
00206 m_created_call = false ;
00207 reset_id();
00208 for (L_i = 0 ; L_i < m_nb_mem; L_i++) {
00209 reset_memory(L_i) ;
00210 }
00211
00212 clean_retrans () ;
00213 }
00214
00215 void C_CallContext::reset() {
00216 m_state = E_CTXT_AVAILABLE ;
00217 m_current_cmd_idx = 0 ;
00218 m_created_call = false ;
00219 clean_retrans () ;
00220 }
00221
00222 T_CallContextState C_CallContext::get_state() {
00223 return (m_state);
00224 }
00225
00226 void C_CallContext::set_state(T_CallContextState P_state) {
00227 m_state = P_state ;
00228 }
00229
00230 T_pC_Scenario C_CallContext::get_scenario() {
00231 return (m_scenario);
00232 }
00233
00234 void C_CallContext::set_scenario(T_pC_Scenario P_scen) {
00235 m_scenario = P_scen ;
00236 }
00237
00238 C_MessageFrame* C_CallContext::get_msg_received() {
00239 return (m_msg_received);
00240 }
00241
00242 void C_CallContext::set_msg_received(C_MessageFrame *P_msg) {
00243 m_msg_received = P_msg ;
00244 }
00245
00246 int C_CallContext::get_current_cmd_idx() {
00247 return (m_current_cmd_idx);
00248 }
00249
00250 T_CallContextState C_CallContext::init_state (T_pC_Scenario P_scen,
00251 struct timeval *P_time) {
00252
00253 m_scenario = P_scen ;
00254 m_state = m_scenario->first_state();
00255 m_msg_received = NULL ;
00256 m_current_cmd_idx = 0 ;
00257 reset_id();
00258 m_created_call = false ;
00259 m_current_time = *P_time ;
00260 clean_retrans () ;
00261 return (m_state);
00262 }
00263
00264 T_CallContextState C_CallContext::init_state (T_pC_Scenario P_scen) {
00265
00266 m_scenario = P_scen ;
00267 m_state = m_scenario->first_state();
00268 m_msg_received = NULL ;
00269 m_current_cmd_idx = 0 ;
00270 reset_id();
00271 m_created_call = false ;
00272 clean_retrans () ;
00273 return (m_state);
00274 }
00275
00276 void C_CallContext::init_state(C_Scenario *P_scen, T_pReceiveMsgContext P_rcvCtxt) {
00277 m_state = E_CTXT_RECEIVE ;
00278 m_scenario = P_scen ;
00279 m_msg_received = P_rcvCtxt->m_msg ;
00280 m_channel_received = P_rcvCtxt->m_channel ;
00281 m_current_cmd_idx = 0 ;
00282
00283 clean_retrans () ;
00284 m_created_call = false ;
00285 m_current_time = P_rcvCtxt->m_time ;
00286
00287 m_channel_table[P_rcvCtxt->m_channel] = P_rcvCtxt->m_response ;
00288
00289 }
00290
00291 bool C_CallContext::msg_received(T_pReceiveMsgContext P_rcvCtxt) {
00292
00293 bool L_ret ;
00294
00295 if (m_state == E_CTXT_RECEIVE) {
00296 m_msg_received = P_rcvCtxt -> m_msg ;
00297 m_channel_received = P_rcvCtxt->m_channel ;
00298 m_current_time = P_rcvCtxt -> m_time ;
00299 m_channel_table[P_rcvCtxt->m_channel] = P_rcvCtxt->m_response ;
00300 L_ret = true ;
00301 } else {
00302 L_ret = false ;
00303 }
00304 return (L_ret);
00305
00306 }
00307
00308
00309 bool C_CallContext::state_receive() {
00310 return (m_state == E_CTXT_RECEIVE);
00311 }
00312
00313 int C_CallContext::get_internal_id() {
00314 return (m_internal_call_id);
00315 }
00316
00317 T_pValueData C_CallContext::get_memory (int P_id) {
00318 return (&(m_memory_table[P_id])) ;
00319 }
00320
00321 void C_CallContext::switch_to_scenario (C_Scenario *P_scen) {
00322 m_scenario = P_scen ;
00323 m_state = P_scen->first_state();
00324 m_current_cmd_idx = 0 ;
00325 m_retrans_to_do = false ;
00326 }
00327
00328 void C_CallContext::clean_suspended () {
00329 DELETE_VAR(m_suspend_msg) ;
00330 }
00331
00332 void C_CallContext::clean_retrans () {
00333 int L_i = 0 ;
00334 for (L_i = 0 ; L_i < m_nb_retrans; L_i++) {
00335 m_nb_retrans_done[L_i] = 0 ;
00336 m_retrans_cmd_idx[L_i] = 0 ;
00337 DELETE_VAR(m_retrans_msg[L_i]);
00338 m_retrans_it_available[L_i] = false ;
00339 }
00340 m_retrans_to_do = false ;
00341 }
00342
00343
00344
00345
00346