Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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

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