Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_MessageBinaryBodyNotInterpreted.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_MessageBinaryBodyNotInterpreted.hpp"
00021 
00022 #include "GeneratorTrace.hpp"
00023 #include "GeneratorError.h"
00024 
00025 #include "ProtocolData.hpp"
00026 
00027 C_MessageBinaryBodyNotInterpreted::C_MessageBinaryBodyNotInterpreted(C_ProtocolBinaryBodyNotInterpreted *P_protocol): C_MessageBinary(P_protocol) {
00028 
00029   int L_i ;
00030   // body non interpreted
00031   for(L_i = 0; L_i < MAX_BODY_VALUES; L_i++) {
00032     m_body_val[L_i].m_id = L_i ;
00033     m_body_val[L_i].m_value.m_val_binary.m_size = 0 ;
00034     m_body_val[L_i].m_value.m_val_binary.m_value = NULL ;
00035   }
00036 
00037   m_local_protocol = P_protocol ;
00038 
00039 }
00040 
00041 C_MessageBinaryBodyNotInterpreted::~C_MessageBinaryBodyNotInterpreted() {
00042 
00043   unsigned long L_i ;
00044   GEN_DEBUG(2, "m_nb_body_values = " << m_nb_body_values);
00045   
00046   for(L_i = 0; L_i < (unsigned long)m_nb_body_values; L_i++) {
00047     m_protocol->delete_body_value(&m_body_val[L_i]);
00048     GEN_DEBUG(2, "delete body value [" << L_i << "] OK");
00049   }
00050   FREE_TABLE(m_body_val);
00051   GEN_DEBUG(2, "FREE_TABLE(m_body_val) OK");
00052 
00053   m_nb_body_values = 0 ;
00054   
00055   m_protocol->reset_value_data (&m_id);
00056   
00057   m_local_protocol = NULL ;
00058   
00059 }
00060 
00061 
00062 T_pValueData C_MessageBinaryBodyNotInterpreted::get_session_id (C_ContextFrame *P_ctxt) {
00063 
00064   T_pValueData             L_id_value = NULL  ;
00065   int                      L_i           ;
00066   C_ProtocolBinary::T_pManagementSessionId   L_session_elt      ;
00067   int                      L_nb_manag_session ;
00068   T_ValueData              L_tmp_id_value     ;
00069 
00070   GEN_DEBUG(1, "C_MessageBinaryBodyNotInterpreted::get_session_id() start");
00071 
00072   // retrieve the number of managment session
00073   L_nb_manag_session = m_protocol->get_nb_management_session () ;
00074 
00075 
00076   for (L_i = 0 ; L_i < L_nb_manag_session ; L_i++) {
00077     L_session_elt = m_protocol->get_manage_session_elt(L_i);
00078 
00079     GEN_DEBUG(1, " L_session_elt->m_msg_id_id = " 
00080               << L_session_elt->m_msg_id_id 
00081               << " type is " 
00082               << L_session_elt->m_msg_id_type 
00083               << " (0: header, 1:body)");
00084 
00085     switch (L_session_elt->m_msg_id_type) {
00086     case C_ProtocolBinary::E_MSG_ID_HEADER:
00087       GEN_DEBUG(1, "Header Id :");
00088       L_id_value = &m_header_values[L_session_elt->m_msg_id_id];
00089       
00090       GEN_DEBUG(1, "value :\n  m_id :" << L_id_value->m_id << 
00091                 "\n  m_type: " << L_id_value->m_type << " ");
00092       
00093       if (L_session_elt->m_msg_id_value_type == E_TYPE_STRING) {
00094         memcpy(&L_tmp_id_value,L_id_value,sizeof(L_tmp_id_value)) ;
00095         m_protocol->reset_value_data(&m_id);
00096         m_protocol->convert_to_string(&m_id, &L_tmp_id_value);
00097         L_id_value = &m_id ;
00098       }
00099       break ;
00100 
00101     case C_ProtocolBinary::E_MSG_ID_BODY:
00102       GEN_DEBUG(1, "Body Id : nb value is " << m_nb_body_values << " ");
00103       
00104       if(m_protocol->check_present_session (m_header_id, L_session_elt->m_msg_id_id)) {
00105         m_protocol->reset_value_data(&m_id);
00106         
00107         //get_body_value(m_body_val[L_session_elt->m_msg_id_id], L_session_elt->m_msg_id_id);
00108         //      m_protocol->get_body_value(&m_id, &m_body_val[L_session_elt->m_msg_id_id]) ;
00109         get_body_value(&m_id,L_session_elt->m_msg_id_id);
00110         L_id_value = &m_id ;
00111       }
00112       break ;
00113     }
00114 
00115     if (L_id_value != NULL) {
00116       break;
00117     }
00118   } // for (L_i...)
00119 
00120   GEN_DEBUG(1, "C_MessageBinaryBodyNotInterpreted::get_session_id() end");
00121 
00122   return (L_id_value) ;
00123 
00124 }
00125 
00126 void C_MessageBinaryBodyNotInterpreted::get_body_value (T_pValueData P_res, 
00127                                                         int P_id) {
00128 
00129   C_ProtocolBinaryBodyNotInterpreted::T_HeaderBodyPositionSize L_pos ;
00130   // ctrl a ajouter
00131   if (P_id != 0) {
00132     // find position of field
00133     m_local_protocol->get_field_position(&L_pos, P_id);
00134     
00135     // copy value to m_body_val[P_id]
00136     if (L_pos.m_size != 0) {
00137       // init the m_body_val[P_id] to string with size 0
00138       if (m_body_val[P_id].m_value.m_val_binary.m_size != L_pos.m_size) {
00139         FREE_TABLE(m_body_val[P_id].m_value.m_val_binary.m_value);
00140         ALLOC_TABLE(m_body_val[P_id].m_value.m_val_binary.m_value,
00141                     unsigned char*,
00142                     sizeof(unsigned char),
00143                     L_pos.m_size);
00144         m_body_val[P_id].m_value.m_val_binary.m_size = L_pos.m_size;
00145       }
00146       extractBinaryVal(m_body_val[P_id].m_value, 
00147                        L_pos.m_position, 
00148                        L_pos.m_size, 
00149                        m_body_val[0].m_value);
00150     }
00151     m_protocol->get_body_value(P_res, &m_body_val[P_id]);
00152     resetValue(m_body_val[P_id].m_value);
00153 
00154   } else {
00155     m_protocol->get_body_value(P_res, &m_body_val[P_id]);
00156   }
00157 }
00158 
00159 
00160 bool C_MessageBinaryBodyNotInterpreted::set_body_value (int P_id, T_pValueData P_val) {
00161   C_ProtocolBinaryBodyNotInterpreted::T_HeaderBodyPositionSize L_pos ;
00162   // ctrl a ajouter
00163   if (P_id != 0) {
00164     // find position of field
00165     m_local_protocol->get_field_position(&L_pos, P_id);
00166 
00167     // copy value to m_body_val[P_id]
00168     if ((L_pos.m_size != 0) && (P_val->m_value.m_val_binary.m_size != 0)) {
00169       // init the m_body_val[P_id] to string with size 0
00170       copyBinaryVal(m_body_val[0].m_value, 
00171                     L_pos.m_position, 
00172                     L_pos.m_size, 
00173                     P_val->m_value);
00174     }
00175   } else {
00176     m_protocol->set_body_value(&m_body_val[0], P_val) ;
00177   }
00178   
00179   return (true) ;
00180 
00181 }
00182 
00183 
00184 
00185 
00186 

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