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

Adding visibility macros to demos #381

Merged
merged 10 commits into from
Aug 8, 2019
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
6 changes: 4 additions & 2 deletions demo_nodes_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

find_package(ament_cmake REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
Expand All @@ -21,6 +19,8 @@ find_package(rcutils)
find_package(rmw REQUIRED)
find_package(std_msgs REQUIRED)

include_directories(include)

function(custom_executable subfolder target)
add_executable(${target} src/${subfolder}/${target}.cpp)
ament_target_dependencies(${target}
Expand All @@ -33,6 +33,8 @@ function(custom_executable subfolder target)
endfunction()

function(add_dependencies library)
target_compile_definitions(${library}
PRIVATE "DEMO_NODES_CPP_BUILDING_DLL")
ament_target_dependencies(${library}
"example_interfaces"
"rclcpp"
Expand Down
58 changes: 58 additions & 0 deletions demo_nodes_cpp/include/demo_nodes_cpp/visibility_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2016 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.

#ifndef DEMO_NODES_CPP__VISIBILITY_CONTROL_H_
skucheria marked this conversation as resolved.
Show resolved Hide resolved
#define DEMO_NODES_CPP__VISIBILITY_CONTROL_H_

#ifdef __cplusplus
extern "C"
{
#endif

// 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 DEMO_NODES_CPP_EXPORT __attribute__ ((dllexport))
#define DEMO_NODES_CPP_IMPORT __attribute__ ((dllimport))
#else
#define DEMO_NODES_CPP_EXPORT __declspec(dllexport)
#define DEMO_NODES_CPP_IMPORT __declspec(dllimport)
#endif
#ifdef DEMO_NODES_CPP_BUILDING_DLL
#define DEMO_NODES_CPP_PUBLIC DEMO_NODES_CPP_EXPORT
#else
#define DEMO_NODES_CPP_PUBLIC DEMO_NODES_CPP_IMPORT
#endif
#define DEMO_NODES_CPP_PUBLIC_TYPE DEMO_NODES_CPP_PUBLIC
#define DEMO_NODES_CPP_LOCAL
#else
#define DEMO_NODES_CPP_EXPORT __attribute__ ((visibility("default")))
#define DEMO_NODES_CPP_IMPORT
#if __GNUC__ >= 4
#define DEMO_NODES_CPP_PUBLIC __attribute__ ((visibility("default")))
#define DEMO_NODES_CPP_LOCAL __attribute__ ((visibility("hidden")))
#else
#define DEMO_NODES_CPP_PUBLIC
#define DEMO_NODES_CPP_LOCAL
#endif
#define DEMO_NODES_CPP_PUBLIC_TYPE
#endif

#ifdef __cplusplus
}
#endif

#endif // DEMO_NODES_CPP__VISIBILITY_CONTROL_H_
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/parameters/even_parameters_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"
skucheria marked this conversation as resolved.
Show resolved Hide resolved

namespace demo_nodes_cpp
{
class EvenParameterNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit EvenParameterNode(const rclcpp::NodeOptions options)
: Node("even_parameters_node", options)
{
Expand Down
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/parameters/list_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
Expand All @@ -26,6 +28,7 @@ namespace demo_nodes_cpp
class ListParameters : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ListParameters(const rclcpp::NodeOptions & options)
: Node("list_paramters", options)
{
Expand Down
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/parameters/parameter_blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"

namespace demo_nodes_cpp
{

class ParameterBlackboard : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ParameterBlackboard(
const rclcpp::NodeOptions & options = (
rclcpp::NodeOptions()
Expand Down
7 changes: 6 additions & 1 deletion demo_nodes_cpp/src/parameters/parameter_events_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;
using SetParametersResult =
std::shared_future<std::vector<rcl_interfaces::msg::SetParametersResult>>;
Expand All @@ -28,6 +30,7 @@ namespace demo_nodes_cpp
class ParameterEventsAsyncNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ParameterEventsAsyncNode(const rclcpp::NodeOptions & options)
: Node("parameter_events", options)
{
Expand Down Expand Up @@ -74,7 +77,9 @@ class ParameterEventsAsyncNode : public rclcpp::Node
});
}

private:
// Set several different types of parameters.
DEMO_NODES_CPP_LOCAL
void queue_first_set_parameter_request()
skucheria marked this conversation as resolved.
Show resolved Hide resolved
{
timer_->cancel(); // Prevent another request from being queued by the timer.
Expand Down Expand Up @@ -105,6 +110,7 @@ class ParameterEventsAsyncNode : public rclcpp::Node
}

// Change the value of some of them.
DEMO_NODES_CPP_LOCAL
void queue_second_set_parameter_request()
{
auto response_received_callback = [this](SetParametersResult future) {
Expand All @@ -128,7 +134,6 @@ class ParameterEventsAsyncNode : public rclcpp::Node
}, response_received_callback);
}

private:
rclcpp::AsyncParametersClient::SharedPtr parameters_client_;
rclcpp::Subscription<rcl_interfaces::msg::ParameterEvent>::SharedPtr parameter_event_sub_;
rclcpp::TimerBase::SharedPtr timer_;
Expand Down
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/parameters/set_and_get_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
Expand All @@ -27,6 +29,7 @@ namespace demo_nodes_cpp
class SetAndGetParameters : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit SetAndGetParameters(const rclcpp::NodeOptions & options)
: Node("set_and_get_parameters", options)
{
Expand Down
9 changes: 8 additions & 1 deletion demo_nodes_cpp/src/services/add_two_ints_client_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@

#include "example_interfaces/srv/add_two_ints.hpp"

#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
{
class ClientNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ClientNode(const rclcpp::NodeOptions & options)
: Node("add_two_ints_client", options)
{
Expand All @@ -50,6 +53,7 @@ class ClientNode : public rclcpp::Node
}
}

DEMO_NODES_CPP_PUBLIC
void queue_async_request()
{
while (!client_->wait_for_service(1s)) {
Expand Down Expand Up @@ -77,6 +81,8 @@ class ClientNode : public rclcpp::Node
auto future_result = client_->async_send_request(request, response_received_callback);
}

private:
DEMO_NODES_CPP_LOCAL
void print_usage()
{
printf("Usage for add_two_ints_client app:\n");
Expand All @@ -86,11 +92,13 @@ class ClientNode : public rclcpp::Node
printf("-s service_name : Specify the service name for client. Defaults to add_two_ints.\n");
}

DEMO_NODES_CPP_LOCAL
bool find_command_option(const std::vector<std::string> & args, const std::string & option)
{
return std::find(args.begin(), args.end(), option) != args.end();
}

DEMO_NODES_CPP_LOCAL
std::string get_command_option(const std::vector<std::string> & args, const std::string & option)
{
auto it = std::find(args.begin(), args.end(), option);
Expand All @@ -100,7 +108,6 @@ class ClientNode : public rclcpp::Node
return std::string();
}

private:
rclcpp::Client<example_interfaces::srv::AddTwoInts>::SharedPtr client_;
std::string service_name_ = "add_two_ints";
};
Expand Down
28 changes: 17 additions & 11 deletions demo_nodes_cpp/src/services/add_two_ints_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

#include "example_interfaces/srv/add_two_ints.hpp"

#include "demo_nodes_cpp/visibility_control.h"

namespace demo_nodes_cpp
{

class ServerNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ServerNode(const rclcpp::NodeOptions & options)
: Node("add_two_ints_server", options)
{
Expand All @@ -45,18 +48,9 @@ class ServerNode : public rclcpp::Node
}
execute();
}
// Create a callback function for when service requests are received.
}

void print_usage()
{
printf("Uage for add_two_ints_server app:\n");
printf("add_two_ints_server [-s service_name] [-h]\n");
printf("options:\n");
printf("-h : Print this help function\n");
printf("-s service_name : Specify the service name for this sever. Defaults to add_two_ints\n");
}

DEMO_NODES_CPP_PUBLIC
void execute()
{
auto handle_add_two_ints =
Expand All @@ -73,11 +67,24 @@ class ServerNode : public rclcpp::Node
srv_ = create_service<example_interfaces::srv::AddTwoInts>(service_name_, handle_add_two_ints);
}

private:
DEMO_NODES_CPP_LOCAL
void print_usage()
{
printf("Usage for add_two_ints_server app:\n");
printf("add_two_ints_server [-s service_name] [-h]\n");
printf("options:\n");
printf("-h : Print this help function.\n");
printf("-s service_name : Specify the service name for server. Defaults to add_two_ints.\n");
}

DEMO_NODES_CPP_LOCAL
bool find_command_option(const std::vector<std::string> & args, const std::string & option)
{
return std::find(args.begin(), args.end(), option) != args.end();
}

DEMO_NODES_CPP_LOCAL
std::string get_command_option(const std::vector<std::string> & args, const std::string & option)
{
auto it = std::find(args.begin(), args.end(), option);
Expand All @@ -87,7 +94,6 @@ class ServerNode : public rclcpp::Node
return std::string();
}

private:
rclcpp::Service<example_interfaces::srv::AddTwoInts>::SharedPtr srv_;
std::string service_name_ = "add_two_ints";
};
Expand Down
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/timers/one_off_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
Expand All @@ -27,6 +29,7 @@ namespace demo_nodes_cpp
class OneOffTimerNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit OneOffTimerNode(const rclcpp::NodeOptions & options)
: Node("one_off_timer", options), count(0)
{
Expand Down
3 changes: 3 additions & 0 deletions demo_nodes_cpp/src/timers/reuse_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"
#include "demo_nodes_cpp/visibility_control.h"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
Expand All @@ -26,6 +28,7 @@ namespace demo_nodes_cpp
class ReuseTimerNode : public rclcpp::Node
{
public:
DEMO_NODES_CPP_PUBLIC
explicit ReuseTimerNode(const rclcpp::NodeOptions & options)
: Node("reuse_timer", options), count(0)
{
Expand Down
Loading