Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_MessageBinary.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_MessageBinary.hpp"
00021 #include "BufferUtils.hpp"
00022 
00023 #include "GeneratorTrace.hpp"
00024 #include "GeneratorError.h"
00025 
00026 #include "ProtocolData.hpp"
00027 
00028 C_MessageBinary::C_MessageBinary(C_ProtocolBinary *P_protocol) {
00029 
00030   unsigned long L_nbFields, L_i ;
00031 
00032   GEN_DEBUG(1, "C_MessageBinary::C_MessageBinary() start");
00033 
00034    m_header_id = -1 ;
00035    m_nb_body_values = 0 ;
00036 
00037    
00038    ALLOC_TABLE(m_body_val, 
00039                C_ProtocolBinary::T_pBodyValue,
00040                sizeof(C_ProtocolBinary::T_BodyValue),
00041                MAX_BODY_VALUES);
00042 
00043    for(L_i = 0 ; L_i < MAX_BODY_VALUES ; L_i++) {
00044      m_body_val[L_i].m_id = -1 ;
00045    }
00046    
00047    m_protocol = P_protocol ;
00048    m_call_id = 0 ;
00049    L_nbFields = m_protocol->get_nb_field_header() ;
00050    ALLOC_TABLE(m_header_values, 
00051                T_pValueData, 
00052                sizeof(T_ValueData), 
00053                L_nbFields);
00054    
00055    for(L_i = 0 ; L_i < L_nbFields; L_i++) {
00056      // Reset Value Data ok because struct used
00057      memset(&m_header_values[L_i], 0, sizeof(T_ValueData));
00058      
00059      // Set the id in header value
00060      m_header_values[L_i].m_id = L_i ;
00061    }
00062 
00063    // Init m_id
00064    memset (&m_id, 0, sizeof(T_ValueData));
00065    m_id.m_type = E_TYPE_NUMBER ;
00066    
00067    m_header_body_field_separator = m_protocol->get_header_body_field_separator () ;
00068 
00069 
00070    GEN_DEBUG(1, "C_MessageBinary::C_MessageBinary() end");
00071 }
00072 
00073 void C_MessageBinary::set_header_value (int P_id, unsigned long P_val) {
00074 
00075   GEN_DEBUG(1, "C_MessageBinary::set_header_value() start: P_id:" << P_id << " value ul:" << P_val);
00076   m_header_values[P_id].m_type = E_TYPE_NUMBER ;
00077   m_header_values[P_id].m_value.m_val_number = P_val ;
00078   GEN_DEBUG(1, "C_MessageBinary::set_header_value() end");
00079 
00080 }
00081 
00082 void C_MessageBinary::set_header_value (char* P_name, unsigned long P_val) {
00083 
00084   C_ProtocolBinary::T_pHeaderField L_desc ;
00085   int                        L_id   ;
00086 
00087   GEN_DEBUG(1, "C_MessageBinary::set_header_value() start: name:" << P_name << " value ul:" << P_val);
00088   L_desc = m_protocol -> get_header_field_description(P_name) ;
00089   if (L_desc != NULL) {
00090     L_id = L_desc -> m_id ;
00091     m_header_values[L_id].m_type = E_TYPE_NUMBER ;
00092     m_header_values[L_id].m_value.m_val_number = P_val ;
00093   }
00094   GEN_DEBUG(1, "C_MessageBinary::set_header_value() end");
00095 
00096 }
00097 
00098 void C_MessageBinary::set_header_value (char* P_name, char *P_val) {
00099   C_ProtocolBinary::T_pHeaderField L_desc ;
00100   int                        L_id   ;
00101 
00102   GEN_DEBUG(1, "C_MessageBinary::set_header_value() start: name:" << P_name << " value char:" << *P_val);
00103   L_desc = m_protocol -> get_header_field_description(P_name) ;
00104   if (L_desc != NULL) {
00105     L_id = L_desc -> m_id ;
00106     m_header_values[L_id].m_type = E_TYPE_NUMBER ;
00107     m_header_values[L_id].m_value.m_val_number = convert_char_to_ul(P_val) ;
00108   }
00109   GEN_DEBUG(1, "C_MessageBinary::set_header_value() end");
00110 }
00111 
00112 void C_MessageBinary::set_header_value (int P_id, T_pValueData P_val) {
00113 
00114   GEN_DEBUG(1, "C_MessageBinary::set_header_value() start: P_id:" << P_id );
00115   m_protocol->set_header_value(P_id, &(m_header_values[P_id]), P_val);
00116   GEN_DEBUG(1, "C_MessageBinary::set_header_value() end");
00117 }
00118 
00119 
00120 C_MessageBinary::~C_MessageBinary() {
00121 
00122   unsigned long L_i ;
00123   unsigned long L_nbFields;
00124 
00125   GEN_DEBUG(1, "\nC_MessageBinary::~C_MessageBinary() start: name " << name());
00126   m_call_id = 0 ;
00127 
00128   if (m_protocol->get_complex_header_presence())
00129   {
00130     L_nbFields = m_protocol->get_nb_field_header();
00131     GEN_DEBUG(2, "nb header fields = " << L_nbFields);
00132 
00133     for(L_i = 0; L_i < L_nbFields; L_i++) {
00134       m_protocol->delete_header_value(&m_header_values[L_i]);
00135       GEN_DEBUG(2, "delete_header value [" << L_i << "] OK");
00136     }
00137   }
00138   FREE_TABLE(m_header_values) ;
00139   GEN_DEBUG(2, "FREE_TABLE(m_header_values) OK\n");
00140 
00141   m_header_id = -1 ;
00142   
00143   GEN_DEBUG(2, "m_nb_body_values = " << m_nb_body_values);
00144 
00145   for(L_i = 0; L_i < (unsigned long)m_nb_body_values; L_i++) {
00146     m_protocol->delete_body_value(&m_body_val[L_i]);
00147 
00148     GEN_DEBUG(2, "delete body value [" << L_i << "] OK");
00149   }
00150   FREE_TABLE(m_body_val);
00151   GEN_DEBUG(2, "FREE_TABLE(m_body_val) OK");
00152   m_nb_body_values = 0 ;
00153 
00154   m_protocol->reset_value_data (&m_id);
00155   m_header_body_field_separator = NULL ;
00156   m_protocol = NULL ;
00157 
00158   GEN_DEBUG(1, "C_MessageBinary::~C_MessageBinary() end");
00159 
00160 }
00161 
00162 bool C_MessageBinary::update_fields (C_MessageFrame* P_msg) {
00163   return (true);
00164 }
00165 
00166 bool C_MessageBinary::compare_types (C_MessageFrame* P_msg) {
00167 
00168   bool             L_result ;
00169   C_MessageBinary *L_msg ;
00170 
00171   L_msg = dynamic_cast<C_MessageBinary*>(P_msg) ;
00172 
00173   GEN_DEBUG(1, "C_MessageBinary::compare_types() start");
00174   if (L_msg == NULL) {
00175     L_result = false ;
00176   } else {
00177     GEN_DEBUG(1, "C_MessageBinary::compare_types() get_type() " << get_type());
00178     L_result = (L_msg -> get_type()  == get_type()) ? true : false ;
00179     GEN_DEBUG(1, "C_MessageBinary::compare_types()  L_result of compare the type of message" << L_result);
00180   }
00181   GEN_DEBUG(1, "C_MessageBinary::compare_types() end");
00182 
00183   return (L_result) ;
00184 }
00185 
00186 unsigned long  C_MessageBinary::get_type () {
00187 
00188   int           L_idx = m_protocol -> get_header_type_id() ;
00189   unsigned long L_type = 0;
00190   bool          L_found = false ;
00191   int           L_i ;
00192 
00193   GEN_DEBUG(1, "C_MessageBinary::get_type() start");
00194 
00195   if (L_idx != -1) {
00196       L_type = m_header_values[L_idx].m_value.m_val_number ;
00197       GEN_DEBUG(1, "C_MessageBinary::get_type() when L_idx != -1 the type is " 
00198                 << L_type );
00199   } else {
00200       L_idx = m_protocol -> get_header_type_id_body() ;
00201       GEN_DEBUG(1, "C_MessageBinary::get_type() the L_idx is " 
00202                 << L_idx);
00203       GEN_DEBUG(1, "C_MessageBinary::get_type() the m_nb_body_values is " 
00204                 << m_nb_body_values);
00205 
00206       for (L_i=0; L_i < m_nb_body_values ; L_i++) { // remenber: to be optimized
00207           if (m_body_val[L_i].m_id == L_idx) { 
00208             L_found=true; 
00209             break; 
00210           }
00211       }
00212       
00213       GEN_DEBUG(1, "C_MessageBinary::get_type() the L_i is " 
00214                 << L_i) ;
00215 
00216       if (L_found == true) {
00217         L_type = m_body_val[L_i].m_value.m_val_number ;
00218 
00219         GEN_DEBUG(1, "C_MessageBinary::get_type()  L_type " << L_type << 
00220                   " and m_body_val[L_i].m_value.m_val_signed " 
00221                   << m_body_val[L_i].m_value.m_val_signed);
00222         GEN_DEBUG(1, "C_MessageBinary::get_type()  L_type " << L_type << 
00223                   " and m_body_val[L_i].m_value.m_val_number " 
00224                   << m_body_val[L_i].m_value.m_val_number);
00225       }
00226   }
00227 
00228   GEN_DEBUG(1, "C_MessageBinary::get_type() returns " << L_type);
00229   return (L_type) ;
00230 }
00231 
00232 void  C_MessageBinary::set_type (unsigned long P_type) {
00233   int L_idx = m_protocol -> get_header_type_id() ;
00234   GEN_DEBUG(1, "C_MessageBinary::set_type() start");
00235   m_header_values[L_idx].m_type = E_TYPE_NUMBER ;
00236   m_header_values[L_idx].m_value.m_val_number = P_type ;
00237   GEN_DEBUG(1, "C_MessageBinary::set_type() end");
00238 }
00239 
00240 unsigned long  C_MessageBinary::get_call_id () {
00241   GEN_DEBUG(1, "C_MessageBinary::get_call_id() start");
00242   GEN_DEBUG(1, "C_MessageBinary::get_call_id() end");
00243   return (m_call_id);
00244 }
00245 
00246 
00247 void C_MessageBinary::set_call_id (unsigned long P_id) {
00248   GEN_DEBUG(1, "C_MessageBinary::set_call_id() start");
00249   m_call_id = P_id ;
00250   GEN_DEBUG(1, "C_MessageBinary::set_call_id() end");
00251 }
00252 
00253 unsigned long C_MessageBinary::decode (unsigned char *P_buffer, 
00254                                        size_t         P_size,
00255                                        C_ProtocolFrame::T_pMsgError P_error) {
00256   
00257   unsigned char *L_ptr = P_buffer ;
00258   unsigned long  L_ret = 0 ; 
00259   unsigned long  L_size_to_decode = 0 ;
00260   unsigned long  L_body_size = 0 ;
00261   int            L_ret_decode ;
00262 
00263   GEN_DEBUG(1, "C_MessageBinary::decode() start");
00264   L_size_to_decode = m_protocol->get_header_size() ;
00265 
00266   GEN_DEBUG(1, "C_MessageBinary::decode() header size [" << L_size_to_decode << "]");
00267   // first decode message size 
00268   
00269   if (P_size < L_size_to_decode) {
00270 
00271     // segmentation case
00272     *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00273     GEN_DEBUG(1, "C_MessageBinary::decode() size < header");
00274 
00275   } else {
00276     L_ptr += L_size_to_decode ;
00277 
00278     if (m_protocol->get_msg_length_start_detected()) {
00279       L_body_size 
00280         = m_protocol->decode_msg_size (P_buffer, P_size)
00281         - L_size_to_decode + m_protocol->get_msg_length_start() ;
00282     } else {
00283       if(m_protocol->get_header_length_excluded () ) {
00284         L_body_size 
00285           = m_protocol->decode_msg_size (P_buffer, P_size) ;
00286       } else {
00287         L_body_size 
00288           = m_protocol->decode_msg_size (P_buffer, P_size)
00289           - L_size_to_decode ;
00290       }
00291     }
00292 
00293     GEN_DEBUG(1, "C_MessageBinary::decode() body size [" << L_body_size << "]");
00294 
00295     L_size_to_decode += L_body_size ;
00296 
00297     if (P_size < L_size_to_decode) {
00298 
00299       // segmentation case
00300       // *P_error = C_ProtocolBinaryFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00301       *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING_SIZE_LESS ;
00302       
00303       GEN_DEBUG(1, "C_MessageBinary::decode() size < body");
00304       
00305     } else { // ok lets decode the buffer
00306 
00307       GEN_DEBUG(1, "C_MessageBinary::decode() message complete [buf size " 
00308                    << L_size_to_decode <<" | body size "<< L_body_size << "]");
00309       // first decode the header
00310 
00311       m_header_id = m_protocol -> decode_header (P_buffer, 
00312                                                  L_size_to_decode,
00313                                                  m_header_values) ;
00314 
00315       // now decode the body
00316       if ((m_header_id != -1) || (m_protocol->get_header_type_id() == -1)) {
00317 
00318         m_nb_body_values = MAX_BODY_VALUES ;
00319 
00320         L_ret_decode = m_protocol->decode_body(L_ptr,
00321                                                L_body_size,
00322                                                m_body_val,
00323                                                &m_nb_body_values,
00324                                                &m_header_id);
00325         if (L_ret_decode != -1) {
00326           GEN_DEBUG(1, "C_MessageBinary::decode() message decoded ");
00327           *P_error = C_ProtocolFrame::E_MSG_OK ;
00328           L_ret = P_size - L_size_to_decode ;
00329         } else {
00330           
00331           GEN_ERROR(E_GEN_FATAL_ERROR, "message error (body content)");
00332           //      *P_error = C_ProtocolBinaryFrame::E_MSG_ERROR_DECODING;
00333           *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING;
00334           L_ret = 0 ;
00335 
00336         }
00337           
00338 
00339       } else {
00340         GEN_ERROR(E_GEN_FATAL_ERROR, "Unrecognized buffer header");     
00341         *P_error = C_ProtocolFrame::E_MSG_ERROR_DECODING;
00342         L_ret = 0 ;
00343       }
00344 
00345       
00346     }
00347 
00348   }
00349 
00350   // TO BE IMPLEMENTED
00351   // check the size of buffer according to the
00352   // protocol definition
00353 
00354   GEN_DEBUG(1, "C_MessageBinary::decode() end");
00355   
00356   return (L_ret) ;
00357 }
00358 
00359 
00360 void C_MessageBinary::encode (unsigned char* P_buffer, 
00361                              size_t* P_size,
00362                              C_ProtocolFrame::T_pMsgError P_error) {
00363 
00364   unsigned char *L_ptr = P_buffer ;
00365   size_t         L_size_header, L_size_body, L_size_all ;
00366 
00367   size_t         L_size_buffer ;
00368   
00369   GEN_DEBUG(1, "C_MessageBinary::encode() start ");
00370 
00371   L_size_all = 0 ;
00372   L_size_header = *P_size ;
00373 
00374   C_ProtocolFrame::T_MsgError L_error = C_ProtocolFrame::E_MSG_OK ;
00375 
00376   L_size_buffer = *P_size ;
00377 
00378   // start with header
00379   m_protocol->encode_header
00380     (m_header_id, m_header_values, L_ptr, &L_size_header, &L_error);
00381 
00382   if (L_error == C_ProtocolFrame::E_MSG_OK) {
00383 
00384     L_size_buffer -= L_size_header ;
00385 
00386     L_size_body = L_size_buffer ;
00387   
00388     L_ptr += L_size_header ;
00389     L_size_all += L_size_header ;
00390 
00391     L_error = m_protocol->encode_body(m_nb_body_values,
00392                                       m_body_val,
00393                                       L_ptr,
00394                                       &L_size_body);
00395 
00396     if (L_error == C_ProtocolFrame::E_MSG_OK) {
00397       L_size_all += L_size_body ;
00398 
00399       if (m_protocol->get_msg_length_start_detected()) {
00400         m_protocol->update_length(P_buffer, 
00401                                   (L_size_all-(m_protocol->get_msg_length_start())));
00402       } else {
00403         if(m_protocol->get_header_length_excluded () ) { 
00404           m_protocol->update_length(P_buffer, L_size_body);
00405         } else {
00406           m_protocol->update_length(P_buffer, L_size_all);
00407         }
00408       }
00409 
00410       *P_size = L_size_all ;
00411     }
00412 
00413   }
00414 
00415   *P_error = L_error ;
00416   
00417   GEN_DEBUG(1, "C_MessageBinary::encode() end");
00418 }
00419 
00420 void C_MessageBinary::set_header_id_value (int P_id) {
00421   
00422   GEN_DEBUG(1, "C_MessageBinary::set_header_id_value(" << P_id << ") start");
00423   m_header_id = P_id ;
00424   m_protocol->get_header_values (P_id, m_header_values) ;
00425   m_protocol->get_body_values (P_id, m_body_val, &m_nb_body_values);
00426   
00427   GEN_DEBUG(1, "C_MessageBinary::set_header_id_value() end");
00428 }
00429 
00430 void C_MessageBinary::set_body_value (C_ProtocolBinary::T_pBodyValue P_val) {
00431   
00432   GEN_DEBUG(1, "C_MessageBinary::set_body_value() start current nb: " << m_nb_body_values );
00433 //  GEN_DEBUG(1, "C_MessageBinary::set_body_value() P_val: " << P_val);
00434 
00435   if (m_nb_body_values == MAX_BODY_VALUES) {
00436     GEN_FATAL(E_GEN_FATAL_ERROR, 
00437           "Maximum number of values ["
00438           << MAX_BODY_VALUES << "] reached" << iostream_endl) ;
00439   } else {
00440     m_protocol->set_body_value(&m_body_val[m_nb_body_values], P_val);
00441     m_nb_body_values++ ;
00442   }
00443 
00444   GEN_DEBUG(1, "C_MessageBinary::set_body_value() end - new nb: " << m_nb_body_values);
00445 }
00446 
00447 C_MessageBinary& C_MessageBinary::operator= (C_MessageBinary & P_val) {
00448 
00449   m_protocol  = P_val.m_protocol ;
00450   m_call_id   = P_val.m_call_id ;
00451   m_header_id = P_val.m_header_id ;
00452 
00453   if (m_protocol->get_complex_header_presence())
00454   {
00455     m_protocol -> reset_header_values(m_protocol->get_nb_field_header(), 
00456                                       m_header_values);
00457   }
00458   m_protocol -> reset_body_values(m_nb_body_values, m_body_val);
00459 
00460   m_nb_body_values = P_val.m_nb_body_values ;
00461   m_protocol -> set_header_values (m_header_values, P_val.m_header_values);
00462   m_protocol -> set_body_values (m_nb_body_values, m_body_val, P_val.m_body_val);
00463 
00464   return (*this) ;
00465 }
00466 
00467 void C_MessageBinary::get_header_value (T_pValueData P_res, 
00468                                       int P_id) {
00469   *P_res = m_header_values[P_id] ;
00470 }
00471 
00472 void C_MessageBinary::get_body_value (T_pValueData P_res, 
00473                                     int P_id) {
00474 
00475   int  L_i ;
00476   bool L_found = false ;
00477 
00478 
00479   // Search the body value in the array
00480   for (L_i=0 ; L_i < m_nb_body_values ; L_i++) {
00481     if (m_body_val[L_i].m_id == P_id) { 
00482       L_found=true; 
00483       break; 
00484     }
00485   }
00486   if (L_found == true) {
00487     m_protocol->get_body_value(P_res, &m_body_val[L_i]) ;
00488   } 
00489 }
00490 
00491 bool C_MessageBinary::set_body_value (int P_id, T_pValueData P_val) {
00492 
00493   int  L_i ;
00494   bool L_found = false ;
00495 
00496   for (L_i=0 ; L_i < m_nb_body_values ; L_i++) {
00497     if (m_body_val[L_i].m_id == P_id) { L_found=true; break; }
00498   }
00499   if (L_found == true) {
00500     m_protocol->set_body_value(&m_body_val[L_i], P_val) ;
00501   }
00502 
00503   return (L_found);
00504   
00505 }
00506 
00507 
00508 iostream_output& operator<< (iostream_output& P_stream, C_MessageBinary &P_msg) {
00509   P_stream << "[" ;
00510   P_msg.m_protocol->print_header(P_stream, 
00511                                  P_msg.m_header_id, 
00512                                  P_msg.m_header_values) ;
00513   P_msg.m_protocol->print_body(P_stream,
00514                                P_msg.m_nb_body_values,
00515                                P_msg.m_body_val);
00516   P_stream << GEN_HEADER_LOG << GEN_HEADER_LEVEL(LOG_LEVEL_MSG) << "]" ;
00517   return (P_stream) ;
00518 }
00519 
00520 C_ProtocolBinary* C_MessageBinary::get_protocol() {
00521   return (m_protocol);
00522 }
00523 
00524 T_pValueData C_MessageBinary::get_session_id (C_ContextFrame *P_ctxt) {
00525 
00526   T_pValueData L_id_value = NULL ;
00527   int                      L_i, L_id  ;
00528   bool                     L_found = false ;
00529 
00530   GEN_DEBUG(1, "C_MessageBinary::get_session_id() start");
00531 
00532   L_id = m_protocol->get_msg_id() ;
00533 
00534   GEN_DEBUG(1, "L_id = " << L_id << " type is " << 
00535                m_protocol->get_msg_id_type() << " (0: header, 1:body)");
00536 
00537   switch (m_protocol->get_msg_id_type()) {
00538   case C_ProtocolBinary::E_MSG_ID_HEADER:
00539     GEN_DEBUG(1, "Header Id :");
00540     L_id_value = &m_header_values[L_id];
00541 
00542     GEN_DEBUG(1, "value :\n\tm_id :" << L_id_value->m_id << 
00543                  "\tm_type: " << L_id_value->m_type << " ");
00544 
00545     break ;
00546   case C_ProtocolBinary::E_MSG_ID_BODY:
00547 
00548     GEN_DEBUG(1, "Body Id : nb value is " << m_nb_body_values << " ");
00549 
00550     for (L_i=0 ; L_i < m_nb_body_values ; L_i++) {
00551 
00552       GEN_DEBUG(1, "Body Id [" << L_i << "] = " << m_body_val[L_i].m_id << " ");
00553 
00554       if (m_body_val[L_i].m_id == L_id) { L_found=true; break; }
00555 
00556 
00557     }
00558     if (L_found == true) {
00559       m_protocol->reset_value_data(&m_id);
00560       m_protocol->get_body_value(&m_id, &m_body_val[L_i]) ;
00561       L_id_value = &m_id ;
00562 
00563       GEN_DEBUG(1, "value :\n\tm_id :" << L_id_value->m_id << 
00564                    "\tm_type: " << L_id_value->m_type << " ");
00565 
00566     }
00567     break ;
00568   }
00569   GEN_DEBUG(1, "C_MessageBinary::get_session_id() end");
00570 
00571   if (L_id_value == NULL) {
00572     L_id_value = get_out_of_session_id();
00573   }
00574 
00575   return (L_id_value) ;
00576 
00577 }
00578 
00579 T_pValueData C_MessageBinary::get_out_of_session_id () {
00580 
00581   T_pValueData L_id_value = NULL ;
00582 
00583   int                      L_i, L_id  ;
00584   bool                     L_found = false ;
00585 
00586   // Gilles PB
00587   T_ValueData L_tmp_id_value ;
00588   
00589 
00590   GEN_DEBUG(1, "C_MessageBinary::get_out_of_session_id() start");
00591 
00592   L_id = m_protocol->get_out_of_session_id() ;
00593 
00594   GEN_DEBUG(1, "L_id = " << L_id << " with type: " 
00595                << m_protocol->get_out_of_session_id_type() 
00596                << " (0: header, 1:body)");
00597 
00598   switch (m_protocol->get_out_of_session_id_type ()) {
00599   case C_ProtocolBinary::E_MSG_ID_HEADER:
00600     GEN_DEBUG(1, "Header Id :");
00601 
00602     L_id_value = &m_header_values[L_id];
00603 
00604     GEN_DEBUG(1, "value :\n  m_id :" << L_id_value->m_id << 
00605                  "\n  m_type: " << L_id_value->m_type << " ");
00606 
00607     if (m_protocol->get_msg_id_value_type() 
00608         == E_TYPE_STRING) {
00609       GEN_DEBUG(1, "C_MessageBinary::get_out_of_session_id() reset PB");
00610       memcpy(&L_tmp_id_value,L_id_value,sizeof(L_tmp_id_value)) ;
00611 
00612       m_protocol->reset_value_data(&m_id);
00613       m_protocol->convert_to_string(&m_id, &L_tmp_id_value);
00614 
00615       L_id_value = &m_id ;
00616     }
00617     break ;
00618     case C_ProtocolBinary::E_MSG_ID_BODY:
00619       GEN_DEBUG(1, "Body Id : nb value is " << m_nb_body_values << " ");
00620 
00621       L_found = false ;
00622       for (L_i=0 ; L_i < m_nb_body_values ; L_i++) {
00623 
00624         GEN_DEBUG(1, "Body Id [" << L_i << "] = " << m_body_val[L_i].m_id << " ");
00625         if (m_body_val[L_i].m_id == L_id) { L_found=true; break; }
00626       }
00627       if (L_found == true) {
00628         m_protocol->reset_value_data(&m_id);
00629         m_protocol->get_body_value(&m_id, &m_body_val[L_i]) ;
00630         L_id_value = &m_id ;
00631 
00632         GEN_DEBUG(1, "value :\n  m_id :" << L_id_value->m_id << 
00633                    "\n  m_type: " << L_id_value->m_type << " ");
00634       }
00635       break ;
00636   }
00637   GEN_DEBUG(1, "C_MessageBinary::get_out_of_session_id() end");
00638   
00639  return (L_id_value) ;
00640 }
00641 
00642 bool C_MessageBinary::check(C_MessageFrame    *P_ref, 
00643                             unsigned int       P_levelMask,
00644                             T_CheckBehaviour   P_behave) {
00645 
00646   bool                       L_ret   = true  ;
00647   int                        L_nb            ;
00648   int                        L_i, L_j, L_id  ;
00649   bool                       L_found = false ;
00650 
00651   C_MessageBinary  *L_ref ;
00652 
00653   C_ProtocolBinary::T_pHeaderBodyValue L_descr         ;
00654   C_ProtocolBinary::T_pHeaderValue L_descrVal      ; 
00655 
00656   L_ref = dynamic_cast<C_MessageBinary*>(P_ref);
00657   
00658   // check body
00659   L_nb = L_ref->m_nb_body_values ;
00660   
00661   if (P_levelMask & _check_level_mask[E_CHECK_LEVEL_FIELD_PRESENCE]) {
00662     // check that the fields of the scenario are present
00663     for (L_i = 0 ; L_i < L_nb; L_i++) {
00664       L_found = false ;
00665       L_id = L_ref->m_body_val[L_i].m_id ;
00666       for(L_j=0; L_j <m_nb_body_values; L_j++) {
00667         if (m_body_val[L_j].m_id == L_id) {
00668           L_found = true ;
00669           break ;
00670         }
00671       }
00672       if (L_found == false) {
00673         L_ret = false ;
00674         L_descr = m_protocol->get_header_body_value_description(L_id);
00675         if (L_descr != NULL) {
00676           L_descrVal = m_protocol->get_header_value_description(m_header_id);
00677 
00678           GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00679                             "check failed in [" 
00680                             << m_protocol -> get_header_name() 
00681                             << "] ["
00682                             << L_descrVal->m_name
00683                             << "]");
00684           GEN_LOG_EVENT_NO_DATE(_check_behaviour_mask[P_behave],
00685                             "                [" 
00686                             << m_protocol->get_header_body_name()
00687                             << "] [" << L_descr->m_name << "] not found");
00688         }
00689       } else {
00690         // check of the value to be done here
00691       }
00692     }
00693   }
00694 
00695 
00696 
00697   if (P_levelMask & _check_level_mask[E_CHECK_LEVEL_FIELD_ADDED]) {
00698     
00699     // check that there is no field added from the scenario
00700     for (L_i = 0 ; L_i < m_nb_body_values; L_i++) {
00701       L_found = false ;
00702       L_id = m_body_val[L_i].m_id ;
00703       for(L_j=0; L_j <m_nb_body_values; L_j++) {
00704         if (L_ref->m_body_val[L_j].m_id == L_id) {
00705           L_found = true ;
00706           break ;
00707         }
00708       }
00709       if (L_found == false) {
00710         L_ret = false ;
00711         L_descr = m_protocol->get_header_body_value_description(L_id);
00712         if (L_descr != NULL) {
00713           L_descrVal = m_protocol->get_header_value_description(m_header_id);
00714           
00715 
00716           GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00717                             "check failed in [" 
00718                             << m_protocol -> get_header_name() 
00719                             << "] ["
00720                             << L_descrVal->m_name
00721                             << "]");
00722           GEN_LOG_EVENT_NO_DATE(_check_behaviour_mask[P_behave], 
00723                             "     additional ["
00724                             << m_protocol->get_header_body_name()
00725                             << "] [" 
00726                             << L_descr->m_name << "] found");
00727 
00728         }
00729       }
00730     }
00731   }
00732 
00733   return (L_ret) ;
00734 }
00735 
00736 bool C_MessageBinary::check_field_presence (int              P_id,
00737                                             T_CheckBehaviour P_behave,
00738                                             int              P_instance,
00739                                             int              P_sub_id) {
00740   bool                                 L_ret   = true  ;
00741   int                                  L_i ;
00742   bool                                 L_found = false ;
00743   C_ProtocolBinary::T_pHeaderBodyValue L_descr         ;
00744   C_ProtocolBinary::T_pHeaderValue     L_descrVal      ; 
00745   unsigned long                        L_max_nb_field_header ;
00746 
00747 
00748   L_max_nb_field_header = m_protocol->get_m_max_nb_field_header () ;
00749 
00750   if (P_id < (int)L_max_nb_field_header) { return (true) ; }
00751 
00752   // check that the fields of the scenario are present
00753   for (L_i = 0 ; L_i < m_nb_body_values; L_i++) {
00754     if ((m_body_val[L_i].m_id + (int)L_max_nb_field_header) == P_id) {
00755       L_found = true ;
00756       break ;
00757     }
00758   }
00759 
00760   if (L_found == false) {
00761     L_ret = false ;
00762     L_descr = m_protocol->get_header_body_value_description(P_id - L_max_nb_field_header);
00763     if (L_descr != NULL) {
00764       L_descrVal = m_protocol->get_header_value_description(m_header_id);
00765       
00766       if (L_descrVal != NULL) {
00767         GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00768                               "check failed [" 
00769                               << m_protocol -> get_header_name() 
00770                               << "] ["
00771                               << L_descrVal->m_name
00772                               << "]");
00773       } else {
00774         GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00775                               "check failed [" 
00776                               << m_protocol -> get_header_name() 
00777                               << "] ["
00778                               << m_protocol->message_name(m_header_id)
00779                               << "]");
00780       }
00781       
00782       GEN_LOG_EVENT_NO_DATE(_check_behaviour_mask[P_behave],
00783                             "                [" 
00784                             << m_protocol->get_header_body_name()
00785                             << "] [" << L_descr->m_name << "] not found");
00786     }
00787   }
00788 
00789   return (L_ret) ;
00790 }
00791 
00792 bool C_MessageBinary::check_field_value (C_MessageFrame   *P_ref,
00793                                          int               P_id,
00794                                          T_CheckBehaviour  P_behave,
00795                                          int               P_instance,
00796                                          int               P_sub_id) {
00797 
00798   GEN_DEBUG(1, "C_MessageBinary::check_field_value() start");
00799 
00800   C_MessageBinary                     *L_ref                 ;
00801   unsigned long                        L_max_nb_field_header ;
00802   int                                  L_id     = P_id       ;
00803   bool                                 L_check  = false      ;
00804 
00805   T_ValueData                          L_value_ref           ;
00806   T_ValueData                          L_value               ;
00807 
00808 
00809   C_ProtocolBinary::T_pHeaderBodyValue L_descr               ;
00810   C_ProtocolBinary::T_pHeaderField     L_headerField         ;
00811 
00812 
00813   L_ref                 = dynamic_cast<C_MessageBinary*>(P_ref)    ;
00814   L_max_nb_field_header = m_protocol->get_m_max_nb_field_header () ;
00815 
00816   if (L_id >= (int) L_max_nb_field_header) {
00817     // case body
00818     L_id -= L_max_nb_field_header ;
00819     L_ref->get_body_value (&L_value_ref, L_id);
00820     get_body_value (&L_value, L_id);
00821     L_check = (L_value_ref == L_value) ;
00822   } else {
00823     // case header
00824     L_check = (L_ref->m_header_values[L_id] == m_header_values[L_id]) ;
00825   }
00826 
00827   if (L_check == false) {
00828     if (P_id <  (int) L_max_nb_field_header) {
00829       L_headerField = m_protocol->get_header_field_description(L_id);
00830       if (L_headerField != NULL) {
00831         GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00832                               "check failed in [" 
00833                               <<  m_protocol->message_name(L_ref->m_header_id) 
00834                               << "] " << m_protocol->message_name() 
00835                               << ", value of field" 
00836                               << " ["
00837                               << L_headerField->m_name
00838                               << "] is incorrect. Expected ["
00839                               << L_value_ref 
00840                               << "] but got ["
00841                               << "L_value" << "]");
00842       }
00843     } else {
00844       L_descr = m_protocol->get_header_body_value_description(L_id);
00845       if (L_descr != NULL) {
00846         GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00847                               "check failed in [" 
00848                               <<  m_protocol->message_name(L_ref->m_header_id) 
00849                               << "] " << m_protocol->message_name() 
00850                               << ", value of " << m_protocol->message_component_name ()
00851                               << " ["
00852                               << L_descr->m_name
00853                               << "]. Expected ["
00854                               << L_value_ref
00855                               << "] but got ["
00856                               << L_value << "]");
00857       } else {
00858         GEN_LOG_EVENT        (_check_behaviour_mask[P_behave], 
00859                               "check failed in [" 
00860                               <<  m_protocol->message_name(L_ref->m_header_id) 
00861                               << "] " << m_protocol->message_name() 
00862                               << ". Expected ["
00863                               << L_value_ref
00864                               << "], but got ["
00865                               << L_value << "]");
00866       }
00867     }
00868   } // if (L_check == false)
00869 
00870   GEN_DEBUG(1, "C_MessageBinary::check_field_value() end ret: " << L_check);
00871 
00872   return (L_check) ;
00873 }
00874 
00875 bool C_MessageBinary::check_field_order (int              P_id,
00876                                          T_CheckBehaviour P_behave,
00877                                          int              P_position) {
00878   bool                                 L_ret   = true  ;
00879 
00880   GEN_DEBUG(1, "C_MessageBinary::check_field_order() start");
00881   GEN_DEBUG(1, "C_MessageBinary::check_field_order() P_id:       " << P_id);
00882   GEN_DEBUG(1, "C_MessageBinary::check_field_order() P_behave:   " << P_behave);
00883   GEN_DEBUG(1, "C_MessageBinary::check_field_order() P_position: " 
00884                   << P_position);
00885   GEN_DEBUG(1, "C_MessageBinary::check_field_order() end ret: " << L_ret);
00886 
00887   return (L_ret) ;
00888 }
00889 // field management
00890 bool C_MessageBinary::set_field_value(T_pValueData P_value, 
00891                                       int P_id,
00892                                       int P_instance,
00893                                       int P_sub_id) {
00894 
00895   bool                          L_found = true ;
00896 
00897   C_ProtocolBinary::T_MsgIdType L_id_type ;
00898   int                           L_id = m_protocol->retrieve_field_id(P_id, &L_id_type);
00899 
00900   switch (L_id_type) {
00901   case C_ProtocolBinary::E_MSG_ID_HEADER:
00902     set_header_value(L_id, P_value);
00903     break ;
00904   case C_ProtocolBinary::E_MSG_ID_BODY:
00905     set_body_value(L_id, P_value);
00906     break ;
00907   }
00908 
00909   return (L_found) ;
00910 }
00911 
00912 bool C_MessageBinary::get_field_value(int P_id, 
00913                                       int P_instance,
00914                                       int P_sub_id,
00915                                       T_pValueData P_value) {
00916   bool                          L_found = true ;
00917   C_ProtocolBinary::T_MsgIdType L_id_type ;
00918   int                           L_id = m_protocol->retrieve_field_id(P_id, &L_id_type);
00919 
00920   GEN_DEBUG(1 , "C_MessageBinary::get_field_value() start ");
00921   GEN_DEBUG(1 , "C_MessageBinary::get_field_value() L_id_type = " 
00922                   << L_id_type << " (0 = hd, 1 = bd)");
00923 
00924   switch (L_id_type) {
00925   case C_ProtocolBinary::E_MSG_ID_HEADER:
00926     get_header_value (P_value, L_id);
00927     break ;
00928   case C_ProtocolBinary::E_MSG_ID_BODY:
00929     get_body_value (P_value, L_id);
00930     break ;
00931   }
00932   
00933   GEN_DEBUG(1 , "C_MessageBinary::get_field_value() end ret = " << L_found);
00934   return (L_found);
00935 }
00936 
00937 T_TypeType C_MessageBinary::get_field_type (int P_id,
00938                                             int P_sub_id) {
00939   return (m_protocol->get_field_type(P_id,P_sub_id));
00940 }
00941 
00942 void C_MessageBinary::dump(iostream_output& P_stream) {
00943   GEN_DEBUG(1, "C_MessageBinary::dump() start");
00944 
00945   P_stream << *this << iostream_endl ;
00946 
00947   GEN_DEBUG(1, "C_MessageBinary::dump() end");
00948 }
00949 
00950 char* C_MessageBinary::name() {
00951 //  GEN_DEBUG(1, "C_MessageBinary::name() name:[" 
00952 //                <<  m_protocol -> message_name(m_header_id) << "]");
00953   return( m_protocol -> message_name(m_header_id));
00954 }
00955 
00956 int C_MessageBinary::get_id_message(){
00957   return (m_header_id) ;
00958 }
00959 
00960 
00961 
00962 bool C_MessageBinary::get_field_value(int P_id, 
00963                                     C_RegExp *P_reg,
00964                                     T_pValueData P_value) {
00965   return (true) ;
00966 }
00967 
00968 
00969 void   C_MessageBinary::update_message_stats  () {
00970 }
00971 
00972 int    C_MessageBinary::get_buffer (T_pValueData P_dest,
00973                                     T_MessagePartType P_header_body_type) {
00974   return (0) ;
00975 }

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