Skip to content

Commit

Permalink
fix coverity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SamerKhshiboun committed Jan 11, 2024
1 parent c47b582 commit cac763c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 53 deletions.
1 change: 0 additions & 1 deletion realsense2_camera/include/base_realsense_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ namespace realsense2_camera
std::map<stream_index_pair, rclcpp::Publisher<sensor_msgs::msg::CameraInfo>::SharedPtr> _depth_aligned_info_publisher;
std::map<stream_index_pair, std::shared_ptr<image_publisher>> _depth_aligned_image_publishers;
std::map<std::string, rs2::region_of_interest> _auto_exposure_roi;
std::map<rs2_stream, bool> _is_first_frame;

std::shared_ptr<std::thread> _monitoring_t;
std::shared_ptr<std::thread> _monitoring_pc; //pc = profile changes
Expand Down
3 changes: 1 addition & 2 deletions realsense2_camera/include/profile_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ namespace realsense2_camera
private:
std::string _module_name;
std::map<stream_index_pair, rs2_format> _formats;
int _fps;
int _fps;
int _width, _height;
bool _is_profile_exist;
bool _force_image_default_qos;
};

Expand Down
3 changes: 0 additions & 3 deletions realsense2_camera/include/ros_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ namespace realsense2_camera
~RosSensor();
void registerSensorParameters();
bool getUpdatedProfiles(std::vector<rs2::stream_profile>& wanted_profiles);
void runFirstFrameInitialization();
virtual bool start(const std::vector<rs2::stream_profile>& profiles);
void stop();
rmw_qos_profile_t getQOS(const stream_index_pair& sip) const;
Expand Down Expand Up @@ -114,8 +113,6 @@ namespace realsense2_camera
std::function<void(rs2::frame)> _frame_callback;
SensorParams _params;
std::function<void()> _update_sensor_func, _hardware_reset_func;
bool _is_first_frame;
std::vector<std::function<void()> > _first_frame_functions_stack;
std::vector<std::shared_ptr<ProfilesManager> > _profile_managers;
rs2::region_of_interest _auto_exposure_roi;
std::vector<std::string> _parameters_names;
Expand Down
1 change: 1 addition & 0 deletions realsense2_camera/src/base_realsense_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void SyncedImuPublisher::PublishPendingMessages()
_pending_messages.pop();
}
}

size_t SyncedImuPublisher::getNumSubscribers()
{
if (!_publisher) return 0;
Expand Down
19 changes: 10 additions & 9 deletions realsense2_camera/src/profile_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ void ProfilesManager::clearParameters()
std::string applyTemplateName(std::string template_name, stream_index_pair sip)
{
const std::string stream_name(create_graph_resource_name(STREAM_NAME(sip)));
char* param_name = new char[template_name.size() + stream_name.size()];
sprintf(param_name, template_name.c_str(), stream_name.c_str());
return std::string(param_name);
return template_name + stream_name;
}

void ProfilesManager::registerSensorQOSParam(std::string template_name,
Expand Down Expand Up @@ -120,7 +118,7 @@ std::map<stream_index_pair, rs2::stream_profile> ProfilesManager::getDefaultProf
if (_all_profiles.empty())
throw std::runtime_error("Wrong commands sequence. No profiles set.");

for (auto profile : _all_profiles)
for (auto& profile : _all_profiles)
{
stream_index_pair sip(profile.stream_type(), profile.stream_index());
if (profile.is_default() && (sip_default_profiles.find(sip) == sip_default_profiles.end()))
Expand Down Expand Up @@ -219,7 +217,10 @@ VideoProfilesManager::VideoProfilesManager(std::shared_ptr<Parameters> parameter
const std::string& module_name, rclcpp::Logger logger, bool force_image_default_qos):
ProfilesManager(parameters, logger),
_module_name(module_name),
_force_image_default_qos(force_image_default_qos)
_force_image_default_qos(force_image_default_qos),
_fps(0),
_width(0),
_height(0)
{

}
Expand Down Expand Up @@ -354,13 +355,13 @@ void VideoProfilesManager::registerVideoSensorParams(std::set<stream_index_pair>
_fps = video_profile.fps();

// Set the stream formats
for (auto sip : sips)
for (auto& sip : sips)
{
registerVideoSensorProfileFormat(sip);
}

// Overwrite the _formats with default values queried from LibRealsense
for (auto sip_default_profile : sip_default_profiles)
for (auto& sip_default_profile : sip_default_profiles)
{
stream_index_pair sip = sip_default_profile.first;

Expand Down Expand Up @@ -431,7 +432,7 @@ void VideoProfilesManager::registerVideoSensorParams(std::set<stream_index_pair>
}, crnt_descriptor);
_parameters_names.push_back(param_name);

for (auto sip : sips)
for (auto& sip : sips)
{
std::string param_name(_module_name + "." + STREAM_NAME(sip) + "_format");
std::string param_value = rs2_format_to_string(_formats[sip]);
Expand Down Expand Up @@ -528,7 +529,7 @@ void MotionProfilesManager::registerFPSParams()

// Overwrite with default values:
std::map<stream_index_pair, rs2::stream_profile> sip_default_profiles = getDefaultProfiles();
for (auto sip_default_profile : sip_default_profiles)
for (auto& sip_default_profile : sip_default_profiles)
{
stream_index_pair sip = sip_default_profile.first;
*(_fps[sip]) = sip_default_profile.second.as<rs2::motion_stream_profile>().fps();
Expand Down
40 changes: 2 additions & 38 deletions realsense2_camera/src/ros_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ RosSensor::RosSensor(rs2::sensor sensor,
{
_frame_callback = [this](rs2::frame frame)
{
runFirstFrameInitialization();
auto stream_type = frame.get_profile().stream_type();
auto stream_index = frame.get_profile().stream_index();
stream_index_pair sip{stream_type, stream_index};
Expand Down Expand Up @@ -204,41 +203,6 @@ void RosSensor::registerSensorParameters()
}
}

void RosSensor::runFirstFrameInitialization()
{
if (_is_first_frame)
{
ROS_DEBUG_STREAM("runFirstFrameInitialization: " << _first_frame_functions_stack.size());
_is_first_frame = false;
if (!_first_frame_functions_stack.empty())
{
std::thread t = std::thread([=]()
{
try
{
while (!_first_frame_functions_stack.empty())
{
_first_frame_functions_stack.back()();
_first_frame_functions_stack.pop_back();
}
}
catch(const std::exception& e)
{
std::cerr << "runFirstFrameInitialization(): " << e.what() << '\n';
throw e;
}
catch(...)
{
std::cerr << "runFirstFrameInitialization()!!!" << std::endl;
throw;
}

});
t.detach();
}
}
}

bool RosSensor::start(const std::vector<stream_profile>& profiles)
{
if (get_active_streams().size() > 0)
Expand Down Expand Up @@ -352,7 +316,7 @@ bool RosSensor::getUpdatedProfiles(std::vector<stream_profile>& wanted_profiles)
{
wanted_profiles.clear();
std::vector<stream_profile> active_profiles = get_active_streams();
for (auto profile_manager : _profile_managers)
for (auto& profile_manager : _profile_managers)
{
profile_manager->addWantedProfiles(wanted_profiles);
}
Expand Down Expand Up @@ -441,7 +405,7 @@ void RosSensor::registerAutoExposureROIOptions()

void RosSensor::clearParameters()
{
for (auto profile_manager : _profile_managers)
for (auto& profile_manager : _profile_managers)
{
profile_manager->clearParameters();
}
Expand Down

0 comments on commit cac763c

Please sign in to comment.