Skip to content

Commit

Permalink
Remove dynamic allocations (eProsima#1179)
Browse files Browse the repository at this point in the history
* Refs #8253. Moved ParameterList headers to src

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8253. Templating readParameterListfromCDRMsg.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8253. Solved build errors with cout and endl.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8253. Solved allocation when participant not secure.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8253. Solved allocation on WriterProxy::send.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8256. Include order and format cleanup.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8256. Removed endl from logs.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs #8256. Removed unnecessary try..catch

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany authored Apr 30, 2020
1 parent 9c28edc commit 7e72a28
Show file tree
Hide file tree
Showing 40 changed files with 238 additions and 243 deletions.
2 changes: 1 addition & 1 deletion examples/C++/RTPSTest_persistent/TestWriterPersistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

using namespace std;

TestWriterPersistent::TestWriterPersistent()
: mp_participant(nullptr)
Expand Down
2 changes: 1 addition & 1 deletion examples/C++/RTPSTest_registered/TestWriterRegistered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

using namespace eprosima::fastrtps;
using namespace eprosima::fastrtps::rtps;

using namespace std;

TestWriterRegistered::TestWriterRegistered()
: mp_participant(nullptr)
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/builtin/data/ParticipantProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define _FASTDDS_RTPS_BUILTIN_DATA_PARTICIPANTPROXYDATA_H_

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#include <fastrtps/qos/ParameterList.h>
#include <fastrtps/qos/QosPolicies.h>

#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/builtin/data/ReaderProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <fastrtps/attributes/TopicAttributes.h>
#include <fastrtps/qos/ParameterList.h>
#include <fastrtps/qos/ReaderQos.h>

#include <fastdds/rtps/attributes/WriterAttributes.h>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/builtin/data/WriterProxyData.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <fastrtps/qos/WriterQos.h>
#include <fastrtps/attributes/TopicAttributes.h>
#include <fastrtps/qos/ParameterList.h>

#include <fastrtps/utils/fixed_size_string.hpp>
#include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/builtin/liveliness/WLPListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <fastdds/rtps/common/InstanceHandle.h>

#include <fastrtps/qos/QosPolicies.h>
#include <fastrtps/qos/ParameterList.h>

namespace eprosima {
namespace fastrtps{
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/messages/MessageReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <fastdds/rtps/common/all_common.h>
#include <fastrtps/qos/ParameterList.h>

#include <unordered_map>
#include <mutex>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/messages/RTPSMessageGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <fastdds/rtps/messages/RTPSMessageSenderInterface.hpp>
#include <fastdds/rtps/messages/RTPSMessageCreator.h>
#include <fastrtps/qos/ParameterList.h>
#include <fastdds/rtps/common/FragmentNumber.h>

#include <vector>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/rtps_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include <fastrtps/utils/IPFinder.h>
#include <fastrtps/utils/TimeConversion.h>

#include <fastrtps/qos/ParameterList.h>
#include <fastrtps/qos/QosPolicies.h>

#include <fastdds/dds/log/Log.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/fastdds/rtps/transport/tcp/RTCPMessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

#include <fastrtps/qos/ParameterList.h>
#include <fastdds/rtps/common/all_common.h>
#include <fastdds/rtps/writer/StatelessWriter.h>
#include <fastdds/rtps/writer/StatefulWriter.h>
Expand Down
1 change: 0 additions & 1 deletion include/fastrtps/fastrtps_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <fastrtps/utils/IPFinder.h>
#include <fastrtps/utils/TimeConversion.h>

#include <fastrtps/qos/ParameterList.h>
#include <fastrtps/qos/QosPolicies.h>

#include <fastrtps/log/Log.h>
Expand Down
41 changes: 0 additions & 41 deletions include/fastrtps/qos/ParameterList.h

This file was deleted.

181 changes: 54 additions & 127 deletions src/cpp/fastdds/core/policy/ParameterList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

#include <fastdds/dds/core/policy/ParameterList.hpp>
#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include "ParameterList.hpp"
#include "ParameterSerializer.hpp"

#include <functional>
Expand Down Expand Up @@ -49,146 +49,73 @@ bool ParameterList::updateCacheChangeFromInlineQos(
fastrtps::rtps::CDRMessage_t* msg,
uint32_t& qos_size)
{
auto parameter_process = [&](fastrtps::rtps::CDRMessage_t* msg, const ParameterId_t pid, uint16_t plength)
auto parameter_process = [&](
fastrtps::rtps::CDRMessage_t* msg,
const ParameterId_t pid,
uint16_t plength)
{
switch (pid)
{
case PID_KEY_HASH:
{
switch (pid)
ParameterKey_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterKey_t>::read_from_cdr_message(p, msg, plength))
{
case PID_KEY_HASH:
{
ParameterKey_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterKey_t>::read_from_cdr_message(p, msg, plength))
{
return false;
}

change.instanceHandle = p.key;
break;
}

case PID_RELATED_SAMPLE_IDENTITY:
{
if (plength >= 24)
{
ParameterSampleIdentity_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterSampleIdentity_t>::read_from_cdr_message(p,
msg, plength))
{
return false;
}
return false;
}

change.write_params.sample_identity(p.sample_id);
}
break;
}
change.instanceHandle = p.key;
break;
}

case PID_STATUS_INFO:
case PID_RELATED_SAMPLE_IDENTITY:
{
if (plength >= 24)
{
ParameterSampleIdentity_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterSampleIdentity_t>::read_from_cdr_message(p,
msg, plength))
{
ParameterStatusInfo_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterStatusInfo_t>::read_from_cdr_message(p, msg,
plength))
{
return false;
}

if (p.status == 1)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED;
}
else if (p.status == 2)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_UNREGISTERED;
}
else if (p.status == 3)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED_UNREGISTERED;
}
break;
return false;
}

default:
break;
change.write_params.sample_identity(p.sample_id);
}
break;
}

return true;
};
try
{
return readParameterListfromCDRMsg(*msg, parameter_process, false, qos_size);
}
catch (std::bad_alloc& ba)
{
std::cerr << "bad_alloc caught: " << ba.what() << '\n';
return false;
}
}

bool ParameterList::readParameterListfromCDRMsg(
fastrtps::rtps::CDRMessage_t& msg,
std::function<bool(fastrtps::rtps::CDRMessage_t*, const ParameterId_t, uint16_t)> processor,
bool use_encapsulation,
uint32_t& qos_size)
{
qos_size = 0;

if (use_encapsulation)
{
// Read encapsulation
msg.pos += 1;
fastrtps::rtps::octet encapsulation = 0;
fastrtps::rtps::CDRMessage::readOctet(&msg, &encapsulation);
if (encapsulation == PL_CDR_BE)
{
msg.msg_endian = fastrtps::rtps::Endianness_t::BIGEND;
}
else if (encapsulation == PL_CDR_LE)
{
msg.msg_endian = fastrtps::rtps::Endianness_t::LITTLEEND;
}
else
{
return false;
}
// Skip encapsulation options
msg.pos += 2;
}

uint32_t original_pos = msg.pos;
bool is_sentinel = false;
while (!is_sentinel)
{
msg.pos = original_pos + qos_size;
case PID_STATUS_INFO:
{
ParameterStatusInfo_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterStatusInfo_t>::read_from_cdr_message(p, msg,
plength))
{
return false;
}

ParameterId_t pid;
uint16_t plength = 0;
bool valid = true;
valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, (uint16_t*)&pid);
valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, &plength);
if (p.status == 1)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED;
}
else if (p.status == 2)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_UNREGISTERED;
}
else if (p.status == 3)
{
change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED_UNREGISTERED;
}
break;
}

if (pid == PID_SENTINEL)
{
// PID_SENTINEL is always considered of length 0
plength = 0;
is_sentinel = true;
default:
break;
}

qos_size += (4 + plength);

// Align to 4 byte boundary and prepare for next iteration
qos_size = (qos_size + 3) & ~3;
return true;
};

if (!valid || ((msg.pos + plength) > msg.length))
{
return false;
}
else if (!is_sentinel)
{
if (!processor(&msg, pid, plength))
{
return false;
}
}
}
return true;
return readParameterListfromCDRMsg(*msg, parameter_process, false, qos_size);
}

bool ParameterList::read_guid_from_cdr_msg(
Expand Down
Loading

0 comments on commit 7e72a28

Please sign in to comment.