C_ProtocolBinary Class Reference

Inheritance diagram for C_ProtocolBinary:

C_ProtocolBinaryFrame C_ProtocolFrame C_ProtocolBinaryBodyNotInterpreted C_ProtocolBinarySeparator List of all members.

Public Types

typedef enum C_ProtocolBinary::_enum_msg_id_type T_MsgIdType
typedef enum C_ProtocolBinary::_enum_msg_id_typeT_pMsgIdType
typedef C_ProtocolBinary::_cond_value T_CondPresence
typedef C_ProtocolBinary::_cond_valueT_pCondPresence
typedef map_t< string_t, int > T_IdMap
typedef map_t< string_t, int > * T_pIdMap
typedef map_t< unsigned long,
int > 
T_DecodeMap
typedef map_t< unsigned long,
int > * 
T_pDecodeMap
typedef C_ProtocolBinary::_struct_header_field T_HeaderField
typedef C_ProtocolBinary::_struct_header_fieldT_pHeaderField
typedef C_ProtocolBinary::_struct_header_value T_HeaderValue
typedef C_ProtocolBinary::_struct_header_valueT_pHeaderValue
typedef C_ProtocolBinary::_struct_header_body_value T_HeaderBodyValue
typedef C_ProtocolBinary::_struct_header_body_valueT_pHeaderBodyValue
typedef C_ProtocolBinary::_struct_body_value T_BodyValue
typedef C_ProtocolBinary::_struct_body_valueT_pBodyValue
typedef C_ProtocolBinary::_struct_body_def T_BodyValueDef
typedef C_ProtocolBinary::_struct_body_defT_pBodyValueDef
typedef C_ProtocolBinary::_struct_management_session_id T_ManagementSessionId
typedef C_ProtocolBinary::_struct_management_session_idT_pManagementSessionId
typedef list_t< T_ManagementSessionIdT_ManagementSessionIdList
typedef list_t< T_ManagementSessionId > * T_pManagementSessionIdList
enum  _enum_msg_id_type { E_MSG_ID_HEADER = 0, E_MSG_ID_BODY }

Public Member Functions

 C_ProtocolBinary ()
virtual void construction_data (C_XmlData *P_def, char **P_name, T_pContructorResult P_res)
 ~C_ProtocolBinary ()
virtual C_MessageFramedecode_message (unsigned char *P_buffer, size_t *P_size, C_ProtocolFrame::T_pMsgError P_error)
C_ProtocolFrame::T_MsgError encode_message (C_MessageFrame *P_msg, unsigned char *P_buffer, size_t *P_buffer_size)
virtual C_MessageFramecreate_new_message (C_MessageFrame *P_msg)
virtual C_MessageFramecreate_new_message (void *P_xml, T_pInstanceDataList P_list, int *P_nb_value)
char * message_name ()
char * message_component_name ()
T_pNameAndIdList message_name_list ()
T_pNameAndIdList message_component_name_list ()
char * message_name (int P_headerId)
void log_buffer (char *P_header, unsigned char *P_buf, size_t P_size)
int find_field (char *P_name)
T_TypeType get_field_type (int P_id, int P_sub_id)
bool check_sub_entity_needed (int P_id)
int retrieve_field_id (int P_id, T_pMsgIdType P_type)
void update_stats (T_ProtocolStatDataType P_type, T_ProtocolStatDataAction P_action, int P_id)
T_MsgIdType get_msg_id_type ()
int get_msg_id ()
T_TypeType get_msg_id_value_type ()
T_MsgIdType get_out_of_session_id_type ()
int get_out_of_session_id ()
unsigned long decode_msg_size (unsigned char *P_buffer, unsigned long P_size)
int get_header_type_id_body ()
int get_header_type_id ()
int get_header_length_id ()
int get_header_length_index ()
unsigned long get_nb_field_header ()
unsigned long get_header_size ()
T_pHeaderField get_header_field_description (int P_id)
T_pHeaderField get_header_field_description (char *P_name)
T_pHeaderValue get_header_value_description (int P_id)
T_pTypeDef get_type_description (int P_id)
T_pTypeDef get_type_description (char *P_name)
int get_header_body_type_id ()
int get_header_body_length_id ()
int get_header_body_length_index ()
unsigned long get_nb_field_header_body ()
unsigned long get_header_body_size ()
T_pHeaderField get_header_body_field_description (int P_id)
T_pHeaderField get_header_body_field_description (char *P_name)
T_pHeaderBodyValue get_header_body_value_description (int P_id)
unsigned long get_m_max_nb_field_header ()
char * get_header_name ()
char * get_header_body_name ()
int get_header_value_id (char *P_name)
int get_header_body_value_id (char *P_name)
int set_body_value (int P_id, char *P_value, int P_nb, T_pBodyValue P_res, bool *P_del=NULL)
int set_body_sub_value (int P_index, int P_id, char *P_value, T_pBodyValue P_res)
void set_body_value (T_pBodyValue P_res, T_pBodyValue P_val)
void delete_header_value (T_pValueData P_res)
void delete_body_value (T_pBodyValue P_res)
void reset_grouped_body_value (T_pBodyValue P_res)
void encode_header (int P_id, unsigned char *P_buf, size_t *P_size)
void encode_header (int P_id, T_pValueData P_headerVal, unsigned char *P_buf, size_t *P_size, C_ProtocolFrame::T_pMsgError P_error)
virtual C_ProtocolFrame::T_MsgError encode_body (int P_nbVal, T_pBodyValue P_val, unsigned char *P_buf, size_t *P_size)
int decode_header (unsigned char *P_buf, size_t P_size, T_pValueData P_valDec)
virtual int decode_body (unsigned char *P_buf, size_t P_size, T_pBodyValue P_valDec, int *P_nbValDec, int *P_headerId)
void update_length (unsigned char *P_buf, size_t P_size)
int find_header_field_id (char *P_name)
int find_header_body_id (char *P_name)
int find_body_value_id (char *P_name)
void get_header_values (int P_id, T_pValueData P_val)
void set_header_values (T_pValueData P_dest, T_pValueData P_orig)
void set_header_value (int P_id, T_pValueData P_dest, T_pValueData P_orig)
void set_body_values (int P_nb, T_pBodyValue P_dest, T_pBodyValue P_orig)
void reset_header_values (int P_nb, T_pValueData P_val)
void reset_body_values (int P_nb, T_pBodyValue P_val)
void get_body_values (int P_id, T_pBodyValue P_val, int *P_nbVal)
virtual void get_body_value (T_pValueData P_dest, T_pBodyValue P_orig)
virtual void set_body_value (T_pBodyValue P_dest, T_pValueData P_orig)
virtual T_ManagementSessionIdget_manage_session_elt (int P_id)
virtual int get_nb_management_session ()
virtual bool check_present_session (int P_msg_id, int P_id)
virtual bool find_present_session (int P_msg_id, int P_id)
iostream_output & print_header (iostream_output &P_stream, int P_headerId, T_pValueData P_val)
virtual iostream_output & print_body (iostream_output &P_stream, int P_nb, T_pBodyValue P_val, int P_level=0)
T_TypeType get_body_value_type (int P_id)
T_TypeType get_header_value_type (int P_id)
void reset_value_data (T_pValueData P_val)
void convert_to_string (T_pValueData P_res, T_pValueData P_val)
void set_padding (unsigned long P_value)
bool get_header_length_excluded ()
unsigned long get_msg_length_start ()
bool get_msg_length_start_detected ()
bool get_complex_header_presence ()
char * get_header_body_field_separator ()
int analyze_setfield (C_XmlData *P_data, int *P_fieldId, unsigned long *P_fieldValueUl)

Protected Member Functions

int add_counter (char *P_name, unsigned long P_init)
int add_type (char *P_name, T_TypeType P_type, unsigned long P_size)
int add_header_field (char *P_name, unsigned long P_size, unsigned long *P_nb_field, unsigned long *P_header_size, T_pHeaderField P_field_table, T_pIdMap P_map, T_pCondPresence P_condPresence=NULL, long P_type_id=-1)
void set_header_type_id (int P_id)
void set_header_length_id (int P_id)
void set_header_body_type_id (int P_id)
void set_header_body_length_id (int P_id)
int get_header_from_xml (C_XmlData *P_def)
int get_types_from_xml (C_XmlData *P_def)
virtual int xml_interpretor (C_XmlData *P_def)
virtual int analyze_header_from_xml (C_XmlData *P_def)
virtual int analyze_types_from_xml (C_XmlData *P_def)
virtual int analyze_body_from_xml (C_XmlData *P_def)
int analyze_dictionnary_from_xml (C_XmlData *P_def)
virtual int analyze_sessions_id_from_xml (C_XmlData *P_def)
virtual int get_header_body_values_from_xml (C_XmlData *P_def)
virtual int get_header_values_from_xml (C_XmlData *P_def)
int get_header_body_from_xml (C_XmlData *P_def)
int get_header_body_optional_from_xml (C_XmlData *P_def)
int get_counter_from_xml (C_XmlData *P_def)
bool check_presence_needed (T_pCondPresence P_condition, unsigned long *P_values)
int process_grouped_type (C_XmlData *P_bodyData, int P_body_grouped_val_id, T_pBodyValue P_pBodyVal)

Protected Attributes

char * m_header_name
T_pHeaderField m_header_field_table
T_pIdMap m_header_id_map
char * m_header_type_name
int m_header_type_id_body
int m_header_type_id
int m_header_length_id
int m_header_length_index
unsigned long m_nb_field_header
unsigned long m_max_nb_field_header
unsigned long m_header_size
int m_transport_type
unsigned long m_msg_length_start
bool m_msg_length_start_detected
char * m_header_body_name
T_pHeaderField m_header_body_field_table
T_pIdMap m_header_body_id_map
int m_header_body_type_id
int m_header_body_length_id
int m_header_body_length_index
unsigned long m_nb_field_header_body
unsigned long m_max_nb_field_header_body
unsigned long m_header_body_size
int m_header_body_start_optional_id
bool m_header_complex_type_presence
T_pNameAndIdList m_message_name_list
T_pNameAndIdList m_message_comp_name_list
char * m_header_body_field_separator
int m_session_id_position
T_pTypeDef m_type_def_table
unsigned long m_nb_types
unsigned long m_max_nb_types
T_pIdMap m_type_id_map
unsigned long m_nb_header_values
T_pHeaderValue m_header_value_table
T_pIdMap m_header_value_id_map
T_pDecodeMap m_header_decode_map
T_pBodyValueDef m_body_value_table
unsigned long m_nb_header_body_values
T_pHeaderBodyValue m_header_body_value_table
T_pIdMap m_header_body_value_id_map
T_pDecodeMap m_header_body_decode_map
T_MsgIdType m_msg_id_type
int m_msg_id_id
T_TypeType m_msg_id_value_type
T_MsgIdType m_type_id_out_of_session
int m_id_out_of_session
unsigned long m_padding_value
bool m_header_length_excluded
list_t< C_MessageFrame * > * m_messageList

Classes

struct  _cond_value
struct  _struct_body_def
struct  _struct_body_value
struct  _struct_header_body_value
struct  _struct_header_field
struct  _struct_header_value
struct  _struct_management_session_id

Detailed Description

Definition at line 33 of file C_ProtocolBinary.hpp.


Member Function Documentation

C_MessageFrame * C_ProtocolBinary::create_new_message void *  P_xml,
T_pInstanceDataList  P_list,
int *  P_nb_value
[virtual]
 

Create a new message

Implements C_ProtocolFrame.

Reimplemented in C_ProtocolBinaryBodyNotInterpreted, and C_ProtocolBinarySeparator.

Definition at line 4844 of file C_ProtocolBinary.cpp.

References analyze_setfield(), delete_body_value(), C_XmlData::find_value(), get_body_value_type(), get_header_body_name(), get_header_body_value_id(), get_header_name(), get_header_value_id(), C_XmlData::get_name(), m_header_body_field_separator, C_ProtocolBinary::_struct_body_value::m_id, _struct_value::m_id, C_ProtocolBinary::_struct_body_value::m_sub_val, _struct_value::m_type, C_ProtocolBinary::_struct_body_value::m_value, _struct_value::m_value, process_grouped_type(), reset_grouped_body_value(), set_body_value(), C_MessageBinary::set_body_value(), C_MessageBinary::set_header_id_value(), and C_MessageBinary::set_header_value().

04846                                                                                       {
04847 
04848 
04849   C_XmlData *L_Xml = (C_XmlData*) P_xml ;
04850 
04851   bool                            L_msgOk = true ;
04852 
04853   C_MessageBinary                 *L_msg ;
04854   char                            *L_currentName ;
04855   
04856   //   C_ProtocolBinaryFrame::T_MsgError L_decode_result ;
04857   C_ProtocolFrame::T_MsgError L_decode_result ;
04858   
04859   unsigned char            *L_buf ;
04860   size_t                    L_size ;
04861   
04862   int                       L_header_val_id ;
04863   int                       L_body_val_id   ;
04864   
04865   GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() start: xml");
04866   
04867   // Allocate a new message
04868   NEW_VAR(L_msg, C_MessageBinary(this));
04869 
04870   // two cases: direct buffer to be decoded or
04871   //            direct message definition
04872 
04873   // Get the message name from XML definition
04874   L_currentName = L_Xml -> get_name () ;
04875 
04876   GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() msg xml name is "
04877             << L_currentName );
04878       
04879   if (strcmp(L_currentName, (char*)"CDATA") == 0) {
04880         
04881     // direct buffer data definition
04882     // unsigned long L_ret_decode ;
04883     L_currentName = L_Xml->find_value((char*)"value");
04884     
04885     L_buf = convert_hexa_char_to_bin(L_currentName, &L_size);
04886     (void) L_msg -> decode(L_buf, L_size, &L_decode_result);
04887     
04888     //    if (L_decode_result != C_ProtocolBinaryFrame::E_MSG_OK) 
04889     if (L_decode_result != C_ProtocolFrame::E_MSG_OK) {
04890       GEN_ERROR(E_GEN_FATAL_ERROR, 
04891                 "Error while decoding direct data buffer ["
04892                 << L_currentName << "]");
04893       L_msgOk = false ;
04894     }
04895         
04896   } else if (strcmp(L_currentName, get_header_name()) == 0) {
04897         
04898     // message decoding
04899     L_currentName = L_Xml -> find_value ((char*) "name") ;
04900     if (L_currentName == NULL) {
04901       GEN_ERROR(E_GEN_FATAL_ERROR, 
04902                 "name value is mandatory for ["
04903                 << get_header_name()
04904                 << "]");
04905       L_msgOk = false ;
04906     } else {
04907       GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " 
04908                 << "the name of this message is " << L_currentName );
04909 
04910       L_header_val_id = get_header_value_id(L_currentName) ;
04911 
04912       GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " 
04913                 << "L_header_val_id = " << L_header_val_id );
04914 
04915       if (L_header_val_id == -1) {
04916         GEN_ERROR(E_GEN_FATAL_ERROR,
04917                   "unknown name ["
04918                   << L_currentName << "] for [" << get_header_name() << "]");
04919         L_msgOk = false ;
04920 
04921       } else { 
04922 
04923         // now search for body values
04924         T_pXmlData_List           L_listBodyVal ;
04925         T_XmlData_List::iterator  L_bodyValIt ;
04926         C_XmlData                *L_bodyData ;
04927         // int                       L_nbBodyVal ;
04928         char                     *L_bodyName, *L_bodyValue ;
04929         C_ProtocolBinary::T_BodyValue   L_bodyVal ;
04930         T_TypeType                L_type ; 
04931 
04932         L_msg->set_header_id_value(L_header_val_id);
04933         
04934         L_listBodyVal = L_Xml -> get_sub_data() ;
04935         if (L_listBodyVal != NULL) {
04936           // L_nbBodyVal = L_listBodyVal->size() ;
04937           for (L_bodyValIt  = L_listBodyVal->begin() ;
04938                L_bodyValIt != L_listBodyVal->end() ;
04939                L_bodyValIt++) {
04940             L_bodyData = *L_bodyValIt ;
04941             
04942             // GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " << 
04943                       // "L_bodyData name is [" << L_bodyData->get_name() << "]");
04944             // GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " << 
04945                       // "get_header_body_name() is [" 
04946                       // << get_header_body_name() << "]");
04947               
04948             if (strcmp(L_bodyData->get_name(), 
04949                        get_header_body_name())==0) {
04950               
04951               L_bodyName = L_bodyData->find_value((char*)"name");
04952               if (L_bodyName == NULL) {
04953                 GEN_ERROR(E_GEN_FATAL_ERROR,
04954                           "name value is mandatory for ["
04955                           << get_header_body_name()
04956                           << "] definition");
04957                 L_msgOk = false ;
04958               }
04959                 
04960               GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() "
04961                         << "L_bodyName is    [" << L_bodyName << "]");
04962 
04963               L_body_val_id = get_header_body_value_id(L_bodyName) ;
04964               if (L_body_val_id == -1) {
04965                 GEN_ERROR(E_GEN_FATAL_ERROR,
04966                           "No definition found for ["
04967                           << L_bodyName << "]");
04968                 L_msgOk = false ;
04969                 break ;
04970               } 
04971                 
04972               GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " 
04973                         << "L_body_val_id is " 
04974                         << L_body_val_id );
04975               
04976               L_type = get_body_value_type (L_body_val_id) ;
04977               if (L_type 
04978                   == E_TYPE_GROUPED) {
04979 
04980                 GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " 
04981                              << L_bodyName << " is  grouped element" );
04982 
04983 
04984                 if (process_grouped_type(L_bodyData, L_body_val_id, 
04985                                          &L_bodyVal) != 0) {
04986                   GEN_ERROR(E_GEN_FATAL_ERROR,
04987                             "Grouped Type processing Error for "
04988                             << L_bodyName);
04989                   L_msgOk = false ;
04990                   break ;
04991                 }
04992 
04993 
04994                 // Add the grouped value in message
04995                 L_msg->set_body_value(&L_bodyVal);
04996 
04997                 // Now do not forget to clean L_bodyVal
04998                 reset_grouped_body_value(&L_bodyVal);
04999                 FREE_TABLE(L_bodyVal.m_sub_val);
05000               } else { 
05001                 bool L_toBeDelete = false;
05002 
05003                 // not grouped value
05004                 L_bodyValue = L_bodyData->find_value((char*)"value");
05005                 if (L_bodyValue == NULL) {
05006                   GEN_ERROR(E_GEN_FATAL_ERROR,
05007                             "value is mandatory for ["
05008                             << get_header_body_name()
05009                             << "] definition");
05010                   L_msgOk = false ;
05011                   break ;
05012                 }
05013                 
05014                 GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() " 
05015                           << "L_bodyValue is \"" << L_bodyValue << "\"" );
05016                 
05017                 if (set_body_value(L_body_val_id, 
05018                                    L_bodyValue,
05019                                    1,
05020                                    &L_bodyVal,
05021                                    &L_toBeDelete) == 0) {
05022 
05023                   if (m_header_body_field_separator == NULL) {
05024                     L_msg->set_body_value(&L_bodyVal);
05025                   } else {
05026                     T_ValueData L_tmp_value ;
05027                     bool        L_exist     ;
05028                     L_tmp_value.m_value = L_bodyVal.m_value ;
05029                     L_tmp_value.m_id = L_bodyVal.m_id ;
05030                     L_tmp_value.m_type = L_type;
05031                     L_exist = L_msg->set_body_value(L_body_val_id,&L_tmp_value);
05032                     if (L_exist == false) {
05033                       L_msg->set_body_value(&L_bodyVal);
05034                     }
05035                   }
05036 
05037                   if (L_toBeDelete) {
05038                     // Now do not forget to clean L_bodyVal
05039                    delete_body_value(&L_bodyVal);
05040                   }
05041 
05042                 } else {
05043                   GEN_ERROR(E_GEN_FATAL_ERROR,
05044                             "Bad format for ["
05045                             << L_bodyValue << "]");
05046                   L_msgOk = false ;
05047                   break ;
05048                 }
05049               } // end to else not grouped
05050             } else if (strcmp(L_bodyData->get_name(),
05051                               (char*)"setfield")==0) {
05052               unsigned long   L_val_setfield = 0 ;
05053               int             L_id_setfield   = 0 ;
05054               L_msgOk = (analyze_setfield(L_bodyData, &L_id_setfield ,&L_val_setfield) == -1) 
05055                 ? false : true  ;
05056               if (L_msgOk) {
05057                 L_msg->set_header_value(L_id_setfield, L_val_setfield);
05058               }
05059               
05060             } else {
05061               GEN_ERROR(E_GEN_FATAL_ERROR, 
05062                         "Unkown section ["
05063                         << L_bodyData->get_name()
05064                         << "]");
05065               L_msgOk = false;
05066               break ;
05067             }
05068             if (L_msgOk == false) break ;
05069           } // for (L_bodyValIt
05070         } // if (L_listBodyVal != NULL)
05071       }
05072     }
05073   }
05074 
05075   // TO-REMOVE
05076   if (L_msgOk == false) {
05077     DELETE_VAR(L_msg);
05078   } else {
05079     // Store the description message in list
05080     m_messageList->push_back(L_msg);
05081   }
05082 
05083   GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() end: xml");
05084 
05085   return (L_msg);
05086 }

C_MessageFrame * C_ProtocolBinary::create_new_message C_MessageFrame P_msg  )  [virtual]
 

Create a new message

Implements C_ProtocolFrame.

Reimplemented in C_ProtocolBinaryBodyNotInterpreted, and C_ProtocolBinarySeparator.

Definition at line 4831 of file C_ProtocolBinary.cpp.

Referenced by decode_message().

04831                                                                           {
04832 
04833   C_MessageBinary *L_msg ;
04834 
04835   GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() start: msg pt");
04836   NEW_VAR(L_msg, C_MessageBinary(this));
04837   if (P_msg != NULL) {
04838     (*L_msg) = *((C_MessageBinary*)P_msg) ;
04839   }
04840   GEN_DEBUG(1, "C_ProtocolBinary::create_new_message() end: msg pt");
04841   return (L_msg);
04842 }

C_ProtocolFrame::T_MsgError C_ProtocolBinary::encode_message C_MessageFrame P_msg,
unsigned char *  P_buffer,
size_t *  P_buffer_size
[virtual]
 

Encode a binary message

Parameters:
P_msg points to the message the message to be coded
P_buffer The destination buffer
P_buffer_size The destination buffer size
Returns:
E_MSG_OK if OK

Implements C_ProtocolBinaryFrame.

Definition at line 4810 of file C_ProtocolBinary.cpp.

04812                                                                 {
04813 
04814   C_ProtocolFrame::T_MsgError  L_error =  C_ProtocolFrame::E_MSG_OK;
04815   C_MessageBinary             *L_msg   = (C_MessageBinary*) P_msg ;
04816 
04817 
04818   L_msg -> encode (P_buffer, P_buffer_size, &L_error) ;
04819 
04820   if (L_error == C_ProtocolFrame::E_MSG_OK) {
04821     GEN_LOG_EVENT(LOG_LEVEL_MSG, 
04822                   "Send [" << *L_msg << "]");
04823   } else {
04824     GEN_LOG_EVENT(LOG_LEVEL_TRAFFIC_ERR,
04825                   "Error while sending [" << *L_msg << "]");
04826   }
04827 
04828   return (L_error);
04829 }


The documentation for this class was generated from the following files:
Generated on Wed Mar 7 14:57:55 2007 for Seagull by  doxygen 1.4.6