Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_SetBitAction.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_SetBitAction.hpp"
00021 #include "GeneratorTrace.hpp"
00022 #include "GeneratorError.h"
00023 #include "BufferUtils.hpp"
00024 
00025 
00026 C_SetBitAction::C_SetBitAction(T_CmdAction        P_cmdAction,
00027                                  T_pControllers P_controllers)
00028   : C_CommandAction (P_cmdAction, P_controllers) {
00029 }
00030 
00031 
00032 C_SetBitAction::~C_SetBitAction() {
00033 }
00034 
00035 
00036 T_exeCode    C_SetBitAction::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_pValueData        L_mem                        ;
00043   int                 L_position_octet             ;
00044   int                 L_index_octet                ;
00045   int                 L_index                      ;
00046   unsigned char       L_car                        ;
00047   const size_t        L_cNum = 8                   ;
00048 
00049 
00050   L_mem = P_callCtxt->get_memory(m_mem_id);
00051 
00052 
00053   switch (L_mem->m_type) {
00054 
00055   case E_TYPE_NUMBER : {
00056     
00057     unsigned long  L_value = L_mem->m_value.m_val_number ;
00058     size_t         L_value_size = sizeof(L_value);
00059     unsigned char  L_buf [50] ;
00060 
00061     if (m_position > (int)(L_value_size*8)) {
00062       GEN_ERROR(E_GEN_FATAL_ERROR, "bad position value ["
00063                 << m_position << "] Incoherent size with memory size ["
00064                 << L_value_size
00065                 << "] ");
00066       L_exeCode = E_EXE_ERROR ;
00067       break ;
00068     } else {
00069       convert_ul_to_bin_network(L_buf,
00070                                 L_value_size,
00071                                 L_value);
00072       
00073       L_index_octet    = (m_position / L_cNum) + 1 ; 
00074       L_position_octet = m_position % L_cNum ; 
00075       
00076       L_index = L_value_size - L_index_octet ;
00077       L_car = L_buf[L_index] ;
00078       
00079       if (m_field_data_num == 1) {
00080         L_buf[L_index] = (1<<L_position_octet) | L_car ;
00081       } else {
00082         L_buf[L_index] = ~(1<<L_position_octet) & L_car ;
00083       }
00084     
00085       L_mem->m_value.m_val_number
00086         = convert_bin_network_to_ul (L_buf, L_value_size);
00087     }
00088 
00089   }
00090   break ;
00091   
00092   case E_TYPE_STRING :
00093 
00094     if (L_mem->m_value.m_val_binary.m_size == 0) {
00095       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00096                     action_name_table[m_type] 
00097                     << " memory zone that was not previously stored");
00098       
00099       GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00100                     " or memory stored is not STRING type");
00101       return (L_exeCode);
00102     }
00103 
00104     // ctrl number field
00105     if (m_position > (int)(L_mem->m_value.m_val_binary.m_size * 8)) {
00106       GEN_ERROR(E_GEN_FATAL_ERROR, "bad position value ["
00107                 << m_position << "] Incoherent size with memory size ["
00108                 << L_mem->m_value.m_val_binary.m_size
00109                 << "] ");
00110       L_exeCode = E_EXE_ERROR ;
00111       break ;
00112     } else {
00113       L_index_octet    = (m_position / L_cNum) + 1 ; 
00114       L_position_octet = m_position % L_cNum ; 
00115       
00116       L_index = L_mem->m_value.m_val_binary.m_size - L_index_octet ;
00117       L_car = L_mem->m_value.m_val_binary.m_value[L_index] ;
00118       
00119       if (m_field_data_num == 1) {
00120         L_car = (1<<L_position_octet) | L_car ;
00121       } else {
00122         L_car = ~(1<<L_position_octet) & L_car ;
00123         
00124       }
00125       
00126       L_mem->m_value.m_val_binary.m_value[L_index] = L_car;
00127       
00128     }
00129     break ;
00130 
00131   default:
00132     GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
00133                   "unsupported type for set-bit action: action only supports type string or number");
00134     L_exeCode = E_EXE_ERROR ;
00135     break;
00136       
00137   }
00138     
00139 
00140 
00141   return (L_exeCode);
00142 }
00143 
00144 
00145 
00146 
00147 

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