00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "C_SetValueBitAction.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 #include "BufferUtils.hpp"
00024
00025
00026 C_SetValueBitAction::C_SetValueBitAction(T_CmdAction P_cmdAction,
00027 T_pControllers P_controllers)
00028 : C_CommandAction (P_cmdAction, P_controllers) {
00029 }
00030
00031
00032 C_SetValueBitAction::~C_SetValueBitAction() {
00033 }
00034
00035
00036 T_exeCode C_SetValueBitAction::execute(T_pCmd_scenario P_pCmd,
00037 T_pCallContext P_callCtxt,
00038 C_MessageFrame *P_msg,
00039 C_MessageFrame *P_ref) {
00040
00041 T_exeCode L_exeCode = E_EXE_NOERROR ;
00042 T_ValueData L_val ;
00043
00044
00045 int L_position_octet ;
00046 int L_index_octet ;
00047 int L_index ;
00048 unsigned char L_car ;
00049 const size_t L_cNum = 8 ;
00050 L_val.m_type = E_TYPE_NUMBER ;
00051
00052
00053 if (P_msg -> get_field_value(m_id,
00054 m_instance_id,
00055 m_sub_id,
00056 &L_val) == false) {
00057
00058 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00059 action_name_table[m_type]
00060 << ": the value of the field asked is incorrect or not found");
00061
00062 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00063 "error on call with session-id ["
00064 << P_callCtxt->m_id_table[P_pCmd->m_channel_id] << "]");
00065
00066 L_exeCode = E_EXE_ERROR;
00067 return (L_exeCode);
00068 }
00069
00070 switch (L_val.m_type) {
00071
00072 case E_TYPE_NUMBER : {
00073
00074 unsigned long L_value = L_val.m_value.m_val_number ;
00075 size_t L_value_size = sizeof(L_value);
00076 unsigned char L_buf [50] ;
00077
00078 if (m_position > (int)(L_value_size*8)) {
00079 GEN_ERROR(E_GEN_FATAL_ERROR, "bad position value ["
00080 << m_position << "] Incoherent size with memory size ["
00081 << L_value_size
00082 << "] ");
00083 L_exeCode = E_EXE_ERROR ;
00084 break ;
00085 } else {
00086 convert_ul_to_bin_network(L_buf,
00087 L_value_size,
00088 L_value);
00089
00090 L_index_octet = (m_position / L_cNum) + 1 ;
00091 L_position_octet = m_position % L_cNum ;
00092
00093 L_index = L_value_size - L_index_octet ;
00094 L_car = L_buf[L_index] ;
00095
00096 if (m_field_data_num == 1) {
00097 L_buf[L_index] = (1<<L_position_octet) | L_car ;
00098 } else {
00099 L_buf[L_index] = ~(1<<L_position_octet) & L_car ;
00100 }
00101 L_val.m_value.m_val_number
00102 = convert_bin_network_to_ul (L_buf, L_value_size);
00103 }
00104 }
00105 break ;
00106
00107 case E_TYPE_STRING :
00108
00109 if (L_val.m_value.m_val_binary.m_size == 0) {
00110 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00111 action_name_table[m_type]
00112 << " memory zone that was not previously stored");
00113
00114 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00115 " or memory stored is not STRING type");
00116 return (L_exeCode);
00117 }
00118
00119
00120 if (m_position > (int)(L_val.m_value.m_val_binary.m_size * 8)) {
00121 GEN_ERROR(E_GEN_FATAL_ERROR, "bad position value ["
00122 << m_position << "] Incoherent size with memory size ["
00123 << L_val.m_value.m_val_binary.m_size
00124 << "] ");
00125
00126 resetMemory(L_val);
00127 L_exeCode = E_EXE_ERROR ;
00128 break ;
00129 } else {
00130 L_index_octet = (m_position / L_cNum) + 1 ;
00131 L_position_octet = m_position % L_cNum ;
00132
00133 L_index = L_val.m_value.m_val_binary.m_size - L_index_octet ;
00134 L_car = L_val.m_value.m_val_binary.m_value[L_index] ;
00135
00136 if (m_field_data_num == 1) {
00137 L_car = (1<<L_position_octet) | L_car ;
00138 } else {
00139 L_car = ~(1<<L_position_octet) & L_car ;
00140
00141 }
00142 L_val.m_value.m_val_binary.m_value[L_index] = L_car;
00143 }
00144 break ;
00145
00146 default:
00147 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00148 "unsupported type for set-value-bit action: action only supports type string or number");
00149 L_exeCode = E_EXE_ERROR ;
00150 break;
00151
00152 }
00153
00154 if (L_exeCode == E_EXE_NOERROR) {
00155 if (P_msg -> set_field_value(&L_val,
00156 m_id,
00157 m_instance_id,
00158 m_sub_id) == false ) {
00159
00160 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00161 action_name_table[m_type]
00162 << ": problem when set field value");
00163
00164 GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00165 "error on call with session-id ["
00166 << P_callCtxt->m_id_table[P_pCmd->m_channel_id] << "]");
00167
00168 L_exeCode = E_EXE_ERROR;
00169 }
00170 resetMemory(L_val);
00171 }
00172
00173
00174 return (L_exeCode);
00175 }
00176
00177
00178
00179
00180