00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_SetValueAction.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 #include "C_ScenarioControl.hpp"
00024
00025
00026 C_SetValueAction::C_SetValueAction(T_CmdAction P_cmdAction,
00027 T_pControllers P_controllers)
00028 : C_CommandAction (P_cmdAction, P_controllers) {
00029 }
00030
00031
00032 C_SetValueAction::~C_SetValueAction() {
00033
00034 int L_k ;
00035
00036 for(L_k = 0;
00037 L_k < m_string_expr->m_nb_portion; L_k++) {
00038 if (m_string_expr->m_portions[L_k].m_type
00039 == E_STR_STATIC) {
00040 FREE_TABLE(m_string_expr->m_portions[L_k].m_data.m_value);
00041 }
00042 }
00043 FREE_TABLE(m_string_expr->m_portions);
00044 FREE_VAR(m_string_expr);
00045 }
00046
00047 T_ValueData C_SetValueAction::search_memory(T_pCallContext P_callCtxt,
00048 C_MessageFrame *P_msg,
00049 bool &P_reset_value) {
00050
00051 T_ValueData L_mem ;
00052 char *L_values, *L_chr, *L_end_ptr ;
00053 unsigned long L_value ;
00054 int L_j ;
00055 char *L_ptr ;
00056 size_t L_size, L_current_size ;
00057
00058 static char L_tmp_string [250] ;
00059 static char L_tmp_string_filled [250] ;
00060
00061
00062 L_mem.m_type = E_TYPE_NUMBER ;
00063
00064 L_mem.m_type = P_msg->get_field_type(m_id,0);
00065
00066 switch (L_mem.m_type) {
00067
00068 case E_TYPE_NUMBER:
00069 L_mem.m_value.m_val_number = m_controllers.m_scenario_control->get_counter_value
00070 (m_string_expr->m_portions[0].m_data.m_id) ;
00071 break ;
00072
00073 case E_TYPE_SIGNED:
00074 L_mem.m_value.m_val_signed = (T_Integer32) m_controllers.m_scenario_control->get_counter_value
00075 (m_string_expr->m_portions[0].m_data.m_id) ;
00076 break ;
00077
00078 case E_TYPE_STRING:
00079 L_tmp_string[0] = '\0' ;
00080 L_ptr = L_tmp_string ;
00081 L_size = 0 ;
00082 for (L_j = 0 ;
00083 L_j < m_string_expr->m_nb_portion;
00084 L_j ++) {
00085 switch (m_string_expr->m_portions[L_j].m_type) {
00086 case E_STR_STATIC:
00087 strcpy(L_ptr,
00088 m_string_expr->m_portions[L_j].m_data.m_value);
00089 L_current_size = strlen(L_ptr) ;
00090 L_size += L_current_size ;
00091 L_ptr += L_current_size ;
00092 break ;
00093 case E_STR_COUNTER:
00094 sprintf(L_ptr, "%ld",
00095 m_controllers.m_scenario_control->get_counter_value
00096 (m_string_expr
00097 ->m_portions[L_j].m_data.m_id)) ;
00098 L_current_size = strlen(L_ptr);
00099 L_size += L_current_size;
00100 L_ptr += L_current_size;
00101 break ;
00102
00103 case E_STR_MEMORY: {
00104 T_pValueData L_memory ;
00105 L_memory = P_callCtxt->get_memory(m_string_expr
00106 ->m_portions[L_j].m_data.m_id);
00107 L_current_size = 250 - L_size ;
00108 valueToString(*L_memory, L_ptr, L_current_size);
00109 L_size += L_current_size ;
00110 L_ptr += L_current_size ;
00111 }
00112 break ;
00113 }
00114 }
00115 L_mem.m_value.m_val_binary.m_size = L_size ;
00116 L_mem.m_value.m_val_binary.m_value
00117 = (unsigned char *) L_tmp_string;
00118
00119 if (m_size != -1) {
00120 if (m_size > (int)L_size) {
00121 int L_filled_size = m_size - L_size ;
00122 int L_fill_idx = 0 ;
00123 memcpy(L_tmp_string_filled+L_filled_size,
00124 L_tmp_string,
00125 L_size);
00126
00127 while ((L_fill_idx+(m_pattern_size)) > L_filled_size) {
00128 memcpy(L_tmp_string_filled+L_fill_idx,
00129 m_pattern,
00130 m_pattern_size);
00131 L_fill_idx += m_pattern_size ;
00132 }
00133 L_mem.m_value.m_val_binary.m_size = m_size ;
00134 L_mem.m_value.m_val_binary.m_value
00135 = (unsigned char *) L_tmp_string_filled;
00136
00137 }
00138 }
00139
00140 P_reset_value = true ;
00141
00142 break;
00143
00144 case E_TYPE_STRUCT:{
00145
00146 P_msg -> get_field_value(m_id,
00147 0,0,
00148 &L_mem);
00149 switch (m_string_expr->m_nb_portion) {
00150 case 1:
00151 L_values = m_string_expr->m_portions[0].m_data.m_value ;
00152 L_chr = strrchr(L_values, ';');
00153 if (L_values == L_chr) {
00154
00155 if (*(L_chr+1) != '\0') {
00156 L_value = strtoul_f (L_chr+1, &L_end_ptr, 10);
00157 if (L_end_ptr[0] == '\0') {
00158 L_mem.m_value.m_val_struct.m_id_2
00159 = L_value ;
00160 }
00161 }
00162
00163 } else {
00164 *L_chr = '\0';
00165 L_value = strtoul_f (L_values, &L_end_ptr, 10);
00166 if (L_end_ptr[0] == '\0') {
00167 L_mem.m_value.m_val_struct.m_id_1
00168 = L_value ;
00169 }
00170 if (*(L_chr+1) != '\0') {
00171 L_value = strtoul_f (L_chr+1, &L_end_ptr, 10);
00172 if (L_end_ptr[0] == '\0') {
00173 L_mem.m_value.m_val_struct.m_id_2
00174 = L_value ;
00175 }
00176 }
00177 *L_chr = ';' ;
00178 }
00179 break ;
00180
00181 case 2:
00182 if (m_string_expr->m_portions[0].m_type == E_STR_COUNTER){
00183 L_mem.m_value.m_val_struct.m_id_1 = m_controllers.m_scenario_control->get_counter_value
00184 (m_string_expr->m_portions[0].m_data.m_id) ;
00185 L_values = m_string_expr->m_portions[1].m_data.m_value ;
00186 L_chr = strrchr(L_values, ';');
00187 if (*(L_chr+1) != '\0') {
00188 L_value = strtoul_f (L_chr+1, &L_end_ptr, 10);
00189 if (L_end_ptr[0] == '\0') {
00190 L_mem.m_value.m_val_struct.m_id_2
00191 = L_value ;
00192 }
00193 }
00194
00195 } else {
00196
00197 L_values = m_string_expr->m_portions[0].m_data.m_value ;
00198 L_chr = strrchr(L_values, ';');
00199 if (L_values != L_chr) {
00200 *L_chr = '\0' ;
00201 L_value = strtoul_f (L_values, &L_end_ptr, 10);
00202 if (L_end_ptr[0] == '\0') {
00203 L_mem.m_value.m_val_struct.m_id_1
00204 = L_value ;
00205 }
00206 *L_chr = ';' ;
00207 }
00208 L_mem.m_value.m_val_struct.m_id_2 = m_controllers.m_scenario_control->get_counter_value
00209 (m_string_expr->m_portions[1].m_data.m_id) ;
00210
00211 }
00212
00213 break ;
00214 case 3:
00215 L_mem.m_value.m_val_struct.m_id_1 = m_controllers.m_scenario_control->get_counter_value
00216 (m_string_expr->m_portions[0].m_data.m_id) ;
00217 L_mem.m_value.m_val_struct.m_id_2 = m_controllers.m_scenario_control->get_counter_value
00218 (m_string_expr->m_portions[2].m_data.m_id) ;
00219 break ;
00220 default:
00221 break ;
00222 }
00223 }
00224 break ;
00225
00226 case E_TYPE_NUMBER_64:
00227 L_mem.m_value.m_val_number_64 = (T_UnsignedInteger64) m_controllers.m_scenario_control->get_counter_value
00228 (m_string_expr->m_portions[0].m_data.m_id) ;
00229 break ;
00230
00231 case E_TYPE_SIGNED_64:
00232 L_mem.m_value.m_val_signed_64 = (T_Integer64) m_controllers.m_scenario_control->get_counter_value
00233 (m_string_expr->m_portions[0].m_data.m_id) ;
00234 break ;
00235
00236 default:
00237 GEN_FATAL(E_GEN_FATAL_ERROR, "Unsupported type for action execution");
00238 break ;
00239 }
00240
00241 return (L_mem);
00242 }
00243
00244 T_exeCode C_SetValueAction::execute(T_pCmd_scenario P_pCmd,
00245 T_pCallContext P_callCtxt,
00246 C_MessageFrame *P_msg,
00247 C_MessageFrame *P_ref) {
00248
00249
00250
00251
00252
00253 T_exeCode L_exeCode = E_EXE_NOERROR ;
00254 T_ValueData L_mem ;
00255 bool L_reset_value = false ;
00256
00257 L_mem = search_memory(P_callCtxt, P_msg, L_reset_value) ;
00258
00259
00260 if (P_msg->set_field_value(&L_mem,
00261 m_id,
00262 m_instance_id,
00263 m_sub_id) == false ) {
00264
00265 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00266 action_name_table[m_type]
00267 << ": problem when set field value");
00268
00269 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00270 "error on call with session-id ["
00271 << P_callCtxt->m_id_table[P_pCmd->m_channel_id] << "]");
00272
00273 L_exeCode = E_EXE_ERROR;
00274
00275 }
00276
00277 if (L_reset_value == true) {
00278 L_mem.m_type = E_TYPE_NUMBER ;
00279 }
00280
00281 return (L_exeCode);
00282 }
00283
00284
00285
00286
00287