Inheritance diagram for C_ProtocolBinary:
Definition at line 33 of file C_ProtocolBinary.hpp.
|
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 }
|
|
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 }
|
|
Encode a binary message
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 }
|