Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cppcheck warnings in dds code #11489

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 31 additions & 59 deletions .github/workflows/cppcheck_run.log

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions .github/workflows/cppcheck_run.parsed.log
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
E uninitvar src/context.cpp+803 Uninitialized variables: prof.bpp, prof.intrinsics
E danglingTempReference src/context.cpp+843 Using reference to dangling temporary.
E danglingTempReference src/context.cpp+844 Using reference to dangling temporary.
E danglingTempReference src/context.cpp+845 Using reference to dangling temporary.
E danglingTempReference src/context.cpp+846 Using reference to dangling temporary.
E danglingTempReference src/context.cpp+847 Using reference to dangling temporary.
E danglingTempReference src/context.cpp+848 Using reference to dangling temporary.
4 changes: 2 additions & 2 deletions scripts/pr_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ if [[ $1 == *"help"* ]]; then
echo " --fix Try to auto-fix defects"
exit 0
fi

cd ..
check_folder include $1
check_folder src $1
check_folder examples $1
check_folder third-party/libtm $1
check_folder third-party/realdds $1
check_folder tools $1
cd scripts

Expand Down
29 changes: 17 additions & 12 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ namespace librealsense
to_rs2_video_stream( rs2_stream const stream_type,
sid_index const & sidx,
std::shared_ptr< realdds::dds_video_stream_profile > const & profile,
const std::set< realdds::video_intrinsics > & intrinsics)
const std::set< realdds::video_intrinsics > & intrinsics )
{
rs2_video_stream prof;
prof.type = stream_type;
Expand All @@ -783,11 +783,13 @@ namespace librealsense
prof.height = profile->height();
prof.fps = profile->frequency();
prof.fmt = static_cast< rs2_format >( profile->format().to_rs2() );
prof.bpp = 0;

//Handle intrinsics
auto intr = std::find_if( intrinsics.begin(), intrinsics.end(), [profile]( const realdds::video_intrinsics & intr ) {
return profile->width() == intr.width && profile->height() == intr.height;
} );
// Handle intrinsics
auto intr = std::find_if( intrinsics.begin(),
intrinsics.end(),
[profile]( const realdds::video_intrinsics & intr )
{ return profile->width() == intr.width && profile->height() == intr.height; } );
if( intr != intrinsics.end() ) //Some profiles don't have intrinsics
{
prof.intrinsics.width = intr->width;
Expand All @@ -799,6 +801,10 @@ namespace librealsense
prof.intrinsics.model = static_cast< rs2_distortion >( intr->distortion_model );
memcpy( prof.intrinsics.coeffs, intr->distortion_coeffs.data(), sizeof( prof.intrinsics.coeffs ) );
}
else
{
memset( &prof.intrinsics, 0, sizeof( prof.intrinsics ) );
}

return prof;
}
Expand Down Expand Up @@ -839,13 +845,12 @@ namespace librealsense
, _dds_dev( dev )
{
LOG_DEBUG( "=====> dds-device-proxy " << this << " created on top of dds-device " << _dds_dev.get() );
auto & dev_info = dev->device_info();
register_info( RS2_CAMERA_INFO_NAME, dev_info.name );
register_info( RS2_CAMERA_INFO_SERIAL_NUMBER, dev_info.serial );
register_info( RS2_CAMERA_INFO_PRODUCT_LINE, dev_info.product_line );
register_info( RS2_CAMERA_INFO_PRODUCT_ID, dev_info.product_id );
register_info( RS2_CAMERA_INFO_PHYSICAL_PORT, dev_info.topic_root );
register_info( RS2_CAMERA_INFO_CAMERA_LOCKED, dev_info.locked ? "YES" : "NO" );
register_info( RS2_CAMERA_INFO_NAME, dev->device_info().name );
register_info( RS2_CAMERA_INFO_SERIAL_NUMBER, dev->device_info().serial );
register_info( RS2_CAMERA_INFO_PRODUCT_LINE, dev->device_info().product_line );
register_info( RS2_CAMERA_INFO_PRODUCT_ID, dev->device_info().product_id );
register_info( RS2_CAMERA_INFO_PHYSICAL_PORT, dev->device_info().topic_root );
register_info( RS2_CAMERA_INFO_CAMERA_LOCKED, dev->device_info().locked ? "YES" : "NO" );

//Assumes dds_device initialization finished
struct sensor_info
Expand Down
96 changes: 48 additions & 48 deletions third-party/realdds/include/realdds/dds-log-consumer.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.
#pragma once
#include <fastdds/dds/log/Log.hpp>
#include <memory>
namespace realdds {
// Convert FastDDS Log::Entry to EasyLogging log (see ELPP_WRITE_LOG)
#define LOG_DDS_ENTRY( ENTRY, LEVEL, ... ) \
do \
{ \
char const * filename = ( ENTRY ).context.filename; \
char const * func = ( ENTRY ).context.function; \
if( ! func ) \
func = "n/a"; \
if( ! filename ) \
filename = func; \
el::base::Writer writer( el::Level::LEVEL, filename, ( ENTRY ).context.line, func ); \
writer.construct( 1, "librealsense" ); \
writer << __VA_ARGS__; \
writer << " [DDS]"; \
if( ( ENTRY ).context.category ) \
writer << "[" << ( ENTRY ).context.category << "]"; \
} \
while( false )
struct log_consumer : eprosima::fastdds::dds::LogConsumer
{
static std::unique_ptr< eprosima::fastdds::dds::LogConsumer > create()
{
return std::unique_ptr< eprosima::fastdds::dds::LogConsumer >( new log_consumer );
}
void Consume( const eprosima::fastdds::dds::Log::Entry & e ) override;
private:
log_consumer() = default;
};
} // namespace realdds
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#pragma once


#include <fastdds/dds/log/Log.hpp>
#include <memory>


namespace realdds {


// Convert FastDDS Log::Entry to EasyLogging log (see ELPP_WRITE_LOG)
#define LOG_DDS_ENTRY( ENTRY, LEVEL, ... ) \
do \
{ \
char const * filename = ( ENTRY ).context.filename; \
char const * func = ( ENTRY ).context.function; \
if( ! func ) \
func = "n/a"; \
if( ! filename ) \
filename = func; \
el::base::Writer writer( el::Level::LEVEL, filename, ( ENTRY ).context.line, func ); \
writer.construct( 1, "librealsense" ); \
writer << __VA_ARGS__; \
writer << " [DDS]"; \
if( ( ENTRY ).context.category ) \
writer << "[" << ( ENTRY ).context.category << "]"; \
} \
while( false )


struct log_consumer : eprosima::fastdds::dds::LogConsumer
{
static std::unique_ptr< eprosima::fastdds::dds::LogConsumer > create()
{
return std::unique_ptr< eprosima::fastdds::dds::LogConsumer >( new log_consumer );
}

void Consume( const eprosima::fastdds::dds::Log::Entry & e ) override;

private:
log_consumer() = default;
};


} // namespace realdds
180 changes: 90 additions & 90 deletions third-party/realdds/include/realdds/dds-topic-reader.h
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.
#pragma once
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <functional>
#include <memory>
namespace eprosima {
namespace fastdds {
namespace dds {
class Subscriber;
} // namespace dds
} // namespace fastdds
} // namespace eprosima
namespace realdds {
class dds_topic;
class dds_subscriber;
// The 'reader' is the entity used to subscribe to updated values of data in a topic. It is bound at creation to this
// topic.
//
// You may choose to create one via a 'subscriber' that manages the activities of several readers.
// on_data_available callback will be called when a sample is received.
//
class dds_topic_reader : public eprosima::fastdds::dds::DataReaderListener
{
std::shared_ptr< dds_topic > const _topic;
std::shared_ptr < dds_subscriber > const _subscriber;
eprosima::fastdds::dds::DataReader * _reader = nullptr;
public:
dds_topic_reader( std::shared_ptr< dds_topic > const & topic );
dds_topic_reader( std::shared_ptr< dds_topic > const & topic, std::shared_ptr< dds_subscriber > const & subscriber );
~dds_topic_reader();
eprosima::fastdds::dds::DataReader * get() const { return _reader; }
eprosima::fastdds::dds::DataReader * operator->() const { return get(); }
bool is_running() const { return ( get() != nullptr ); }
std::shared_ptr< dds_topic > const & topic() const { return _topic; }
typedef std::function< void() > on_data_available_callback;
typedef std::function< void( eprosima::fastdds::dds::SubscriptionMatchedStatus const & ) >
on_subscription_matched_callback;
void on_data_available( on_data_available_callback callback ) { _on_data_available = std::move( callback ); }
void on_subscription_matched( on_subscription_matched_callback callback )
{
_on_subscription_matched = std::move( callback );
}
class qos : public eprosima::fastdds::dds::DataReaderQos
{
using super = eprosima::fastdds::dds::DataReaderQos;
public:
qos( eprosima::fastdds::dds::ReliabilityQosPolicyKind reliability
= eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS, // default
eprosima::fastdds::dds::DurabilityQosPolicyKind durability
= eprosima::fastdds::dds::VOLATILE_DURABILITY_QOS ); // default is transient local
};
// The callbacks should be set before we actually create the underlying DDS objects, so the reader does not
void run( qos const & = qos() );
// DataReaderListener
protected:
void on_subscription_matched( eprosima::fastdds::dds::DataReader *,
eprosima::fastdds::dds::SubscriptionMatchedStatus const & info ) override;
void on_data_available( eprosima::fastdds::dds::DataReader * ) override;
private:
on_data_available_callback _on_data_available;
on_subscription_matched_callback _on_subscription_matched;
};
} // namespace realdds
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#pragma once

#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>

#include <functional>
#include <memory>


namespace eprosima {
namespace fastdds {
namespace dds {
class Subscriber;
} // namespace dds
} // namespace fastdds
} // namespace eprosima


namespace realdds {


class dds_topic;
class dds_subscriber;

// The 'reader' is the entity used to subscribe to updated values of data in a topic. It is bound at creation to this
// topic.
//
// You may choose to create one via a 'subscriber' that manages the activities of several readers.
// on_data_available callback will be called when a sample is received.
//
class dds_topic_reader : public eprosima::fastdds::dds::DataReaderListener
{
std::shared_ptr< dds_topic > const _topic;
std::shared_ptr < dds_subscriber > const _subscriber;

eprosima::fastdds::dds::DataReader * _reader = nullptr;

public:
dds_topic_reader( std::shared_ptr< dds_topic > const & topic );
dds_topic_reader( std::shared_ptr< dds_topic > const & topic, std::shared_ptr< dds_subscriber > const & subscriber );
~dds_topic_reader();

eprosima::fastdds::dds::DataReader * get() const { return _reader; }
eprosima::fastdds::dds::DataReader * operator->() const { return get(); }

bool is_running() const { return ( get() != nullptr ); }

std::shared_ptr< dds_topic > const & topic() const { return _topic; }

typedef std::function< void() > on_data_available_callback;
typedef std::function< void( eprosima::fastdds::dds::SubscriptionMatchedStatus const & ) >
on_subscription_matched_callback;

void on_data_available( on_data_available_callback callback ) { _on_data_available = std::move( callback ); }
void on_subscription_matched( on_subscription_matched_callback callback )
{
_on_subscription_matched = std::move( callback );
}

class qos : public eprosima::fastdds::dds::DataReaderQos
{
using super = eprosima::fastdds::dds::DataReaderQos;

public:
qos( eprosima::fastdds::dds::ReliabilityQosPolicyKind reliability
= eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS, // default
eprosima::fastdds::dds::DurabilityQosPolicyKind durability
= eprosima::fastdds::dds::VOLATILE_DURABILITY_QOS ); // default is transient local
};

// The callbacks should be set before we actually create the underlying DDS objects, so the reader does not
void run( qos const & = qos() );

// DataReaderListener
protected:
void on_subscription_matched( eprosima::fastdds::dds::DataReader *,
eprosima::fastdds::dds::SubscriptionMatchedStatus const & info ) override;

void on_data_available( eprosima::fastdds::dds::DataReader * ) override;

private:
on_data_available_callback _on_data_available;
on_subscription_matched_callback _on_subscription_matched;
};


} // namespace realdds
Loading