BaseMessageUtils.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "BaseMessageUtils.h"
00007
00008 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00009
00010 namespace OpenDDS {
00011 namespace RTPS {
00012
00013 int locator_to_address(ACE_INET_Addr& dest,
00014 const DCPS::Locator_t& locator,
00015 bool map )
00016 {
00017 switch (locator.kind) {
00018 #ifdef ACE_HAS_IPV6
00019 case LOCATOR_KIND_UDPv6:
00020 dest.set_type(AF_INET6);
00021 if (dest.set_address(reinterpret_cast<const char*>(locator.address),
00022 16, 0 ) == -1) {
00023 return -1;
00024 }
00025 dest.set_port_number(locator.port);
00026 return 0;
00027 #endif
00028 case LOCATOR_KIND_UDPv4:
00029 #if !defined (ACE_HAS_IPV6) || !defined (IPV6_V6ONLY)
00030 ACE_UNUSED_ARG(map);
00031 #endif
00032 dest.set_type(AF_INET);
00033 if (dest.set_address(reinterpret_cast<const char*>(locator.address)
00034 + 12, 4, 0
00035 #if defined (ACE_HAS_IPV6) && defined (IPV6_V6ONLY)
00036 , map ? 1 : 0
00037 #endif
00038 ) == -1) {
00039 return -1;
00040 }
00041 dest.set_port_number(locator.port);
00042 return 0;
00043 default:
00044 return -1;
00045 }
00046
00047 return -1;
00048 }
00049
00050 DDS::ReturnCode_t blob_to_locators(const DCPS::TransportBLOB& blob,
00051 DCPS::LocatorSeq& locators,
00052 bool* requires_inline_qos,
00053 unsigned int* pBytesRead)
00054 {
00055 ACE_Data_Block db(blob.length(), ACE_Message_Block::MB_DATA,
00056 reinterpret_cast<const char*>(blob.get_buffer()),
00057 0 , 0 , ACE_Message_Block::DONT_DELETE, 0 );
00058 ACE_Message_Block mb(&db, ACE_Message_Block::DONT_DELETE, 0 );
00059 mb.wr_ptr(mb.space());
00060
00061 DCPS::Serializer ser(&mb, ACE_CDR_BYTE_ORDER, DCPS::Serializer::ALIGN_CDR);
00062 if (!(ser >> locators)) {
00063 ACE_ERROR_RETURN((LM_ERROR,
00064 ACE_TEXT("(%P|%t) blob_to_locators: ")
00065 ACE_TEXT("Failed to deserialize blob's locators\n")),
00066 DDS::RETCODE_ERROR);
00067 }
00068
00069 if (requires_inline_qos) {
00070 if (!(ser >> ACE_InputCDR::to_boolean(*requires_inline_qos))) {
00071 ACE_ERROR_RETURN((LM_ERROR,
00072 ACE_TEXT("(%P|%t) blob_to_locators: ")
00073 ACE_TEXT("Failed to deserialize blob inline QoS flag\n")),
00074 DDS::RETCODE_ERROR);
00075 }
00076 } else {
00077 if (!ser.skip(1)) {
00078 ACE_ERROR_RETURN((LM_ERROR,
00079 ACE_TEXT("(%P|%t) blob_to_locators: ")
00080 ACE_TEXT("Failed to skip blob inline QoS flag\n")),
00081 DDS::RETCODE_ERROR);
00082 }
00083 }
00084
00085 if (pBytesRead) {
00086 *pBytesRead = blob.length() - mb.length();
00087 }
00088 return DDS::RETCODE_OK;
00089 }
00090
00091 void locators_to_blob(const DCPS::LocatorSeq& locators,
00092 DCPS::TransportBLOB& blob)
00093 {
00094 using OpenDDS::DCPS::Serializer;
00095 size_t size_locator = 0, padding_locator = 0;
00096 DCPS::gen_find_size(locators, size_locator, padding_locator);
00097 ACE_Message_Block mb_locator(size_locator + padding_locator + 1);
00098 Serializer ser_loc(&mb_locator, ACE_CDR_BYTE_ORDER, Serializer::ALIGN_CDR);
00099 ser_loc << locators;
00100
00101
00102
00103 ser_loc << ACE_OutputCDR::from_boolean(false);
00104 message_block_to_sequence(mb_locator, blob);
00105 }
00106
00107 }
00108 }
00109
00110 OPENDDS_END_VERSIONED_NAMESPACE_DECL