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

export symbols in laser_proc component #8

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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ament_target_dependencies(laser_proc
rclcpp
sensor_msgs
)
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME}
PRIVATE "LASER_PROC_BUILDING_LIBRARY")

## Laser Proc component
add_library(laser_proc_component SHARED src/laser_proc_component.cpp)
Expand Down
5 changes: 5 additions & 0 deletions include/laser_proc/laser_proc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@
#include "sensor_msgs/msg/laser_scan.hpp"
#include "sensor_msgs/msg/multi_echo_laser_scan.hpp"

#include "visibility_control.hpp"

namespace laser_proc
{
class LaserProc
{
public:
LASER_PROC_PUBLIC
static sensor_msgs::msg::LaserScan getFirstScan(
const sensor_msgs::msg::MultiEchoLaserScan & msg);

LASER_PROC_PUBLIC
static sensor_msgs::msg::LaserScan getLastScan(
const sensor_msgs::msg::MultiEchoLaserScan & msg);

LASER_PROC_PUBLIC
static sensor_msgs::msg::LaserScan getMostIntenseScan(
const sensor_msgs::msg::MultiEchoLaserScan & msg);

Expand Down
15 changes: 14 additions & 1 deletion include/laser_proc/laser_publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@

#include "sensor_msgs/msg/multi_echo_laser_scan.hpp"

#include "visibility_control.hpp"

namespace laser_proc
{

class LaserPublisher
{
public:
LASER_PROC_PUBLIC
explicit LaserPublisher(
rclcpp::Node::SharedPtr & nh, uint32_t queue_size, bool publish_echoes = true);

LASER_PROC_PUBLIC
explicit LaserPublisher(
std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface> topics_interface,
uint32_t queue_size,
Expand All @@ -62,31 +66,40 @@ class LaserPublisher
*
* Returns sum of all child publishers.
*/
uint32_t getNumSubscribers() const;
LASER_PROC_PUBLIC
size_t getNumSubscribers() const;

/*!
* \brief Returns the topics of this LaserPublisher.
*/
LASER_PROC_PUBLIC
std::vector<std::string> getTopics() const;

/*!
* \brief Publish a MultiEchoLaserScan on the topics associated with this LaserPublisher.
*/
LASER_PROC_PUBLIC
void publish(const sensor_msgs::msg::MultiEchoLaserScan & msg) const;

/*!
* \brief Publish a MultiEchoLaserScan on the topics associated with this LaserPublisher.
*/
LASER_PROC_PUBLIC
void publish(sensor_msgs::msg::MultiEchoLaserScan::ConstSharedPtr msg) const;

/*!
* \brief Shutdown the advertisements associated with this Publisher.
*/
LASER_PROC_PUBLIC
void shutdown();

LASER_PROC_PUBLIC
operator void *() const;
LASER_PROC_PUBLIC
bool operator<(const LaserPublisher & rhs) const {return impl_ < rhs.impl_;}
LASER_PROC_PUBLIC
bool operator!=(const LaserPublisher & rhs) const {return impl_ != rhs.impl_;}
LASER_PROC_PUBLIC
bool operator==(const LaserPublisher & rhs) const {return impl_ == rhs.impl_;}

private:
Expand Down
56 changes: 56 additions & 0 deletions include/laser_proc/visibility_control.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2015 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* This header must be included by all rclcpp headers which declare symbols
* which are defined in the rclcpp library. When not building the rclcpp
* library, i.e. when using the headers in other package's code, the contents
* of this header change the visibility of certain symbols which the rclcpp
* library cannot have, but the consuming code must have inorder to link.
*/

#ifndef LASER_PROC__VISIBILITY_CONTROL_HPP_
#define LASER_PROC__VISIBILITY_CONTROL_HPP_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define LASER_PROC_EXPORT __attribute__ ((dllexport))
#define LASER_PROC_IMPORT __attribute__ ((dllimport))
#else
#define LASER_PROC_EXPORT __declspec(dllexport)
#define LASER_PROC_IMPORT __declspec(dllimport)
#endif
#ifdef LASER_PROC_BUILDING_LIBRARY
#define LASER_PROC_PUBLIC LASER_PROC_EXPORT
#else
#define LASER_PROC_PUBLIC LASER_PROC_IMPORT
#endif
#define LASER_PROC_PUBLIC_TYPE LASER_PROC_PUBLIC
#define LASER_PROC_LOCAL
#else
#define LASER_PROC_EXPORT __attribute__ ((visibility("default")))
#define LASER_PROC_IMPORT
#if __GNUC__ >= 4
#define LASER_PROC_PUBLIC __attribute__ ((visibility("default")))
#define LASER_PROC_LOCAL __attribute__ ((visibility("hidden")))
#else
#define LASER_PROC_PUBLIC
#define LASER_PROC_LOCAL
#endif
#define LASER_PROC_PUBLIC_TYPE
#endif

#endif // LASER_PROC__VISIBILITY_CONTROL_HPP_
4 changes: 2 additions & 2 deletions src/laser_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ LaserPublisher::LaserPublisher(
impl_->functs_.push_back(laser_proc::LaserProc::getMostIntenseScan);
}

uint32_t LaserPublisher::getNumSubscribers() const
size_t LaserPublisher::getNumSubscribers() const
{
uint32_t num = 0;
size_t num = 0;

if (impl_ && impl_->isValid()) {
num += impl_->echo_pub_->get_subscription_count();
Expand Down