Skip to content

Commit

Permalink
make rclcpp into a library
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed Oct 29, 2015
1 parent b6d2033 commit 4761732
Show file tree
Hide file tree
Showing 52 changed files with 3,044 additions and 2,105 deletions.
70 changes: 56 additions & 14 deletions rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,66 @@ project(rclcpp)
find_package(ament_cmake REQUIRED)
find_package(rcl_interfaces REQUIRED)

find_package(rmw REQUIRED)

if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
endif()

include_directories(include)

set(${PROJECT_NAME}_SRCS
src/rclcpp/any_executable.cpp
src/rclcpp/callback_group.cpp
src/rclcpp/client.cpp
src/rclcpp/context.cpp
src/rclcpp/contexts/default_context.cpp
src/rclcpp/executor.cpp
src/rclcpp/executors.cpp
src/rclcpp/executors/multi_threaded_executor.cpp
src/rclcpp/executors/single_threaded_executor.cpp
src/rclcpp/intra_process_manager.cpp
src/rclcpp/intra_process_manager_state.cpp
src/rclcpp/memory_strategies.cpp
src/rclcpp/memory_strategy.cpp
src/rclcpp/parameter.cpp
src/rclcpp/parameter_client.cpp
src/rclcpp/parameter_service.cpp
src/rclcpp/publisher.cpp
src/rclcpp/node.cpp
src/rclcpp/service.cpp
src/rclcpp/subscription.cpp
src/rclcpp/timer.cpp
src/rclcpp/utilities.cpp
)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SRCS})
ament_target_dependencies(${PROJECT_NAME} "rmw" "rcl_interfaces")
if(APPLE)
# Since the rmw_* symbols are unresolved at the time of building librclcpp,
# tell the linker on OS X to dynamically look them up at runtime.
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()

ament_export_dependencies(rmw)
ament_export_dependencies(rcl_interfaces)

ament_export_include_directories(include)

ament_export_libraries(${PROJECT_NAME})

if(AMENT_ENABLE_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(rmw REQUIRED)

if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
endif()

include_directories(include)

ament_add_gtest(test_function_traits test/test_function_traits.cpp)
ament_add_gtest(test_mapped_ring_buffer test/test_mapped_ring_buffer.cpp)
ament_add_gtest(test_intra_process_manager test/test_intra_process_manager.cpp)
if(TARGET test_intra_process_manager)
target_include_directories(test_intra_process_manager PUBLIC
"${rcl_interfaces_INCLUDE_DIRS}"
"${rmw_INCLUDE_DIRS}")
endif()
# ament_add_gtest(test_intra_process_manager test/test_intra_process_manager.cpp)
# if(TARGET test_intra_process_manager)
# target_include_directories(test_intra_process_manager PUBLIC
# "${rcl_interfaces_INCLUDE_DIRS}"
# "${rmw_INCLUDE_DIRS}")
# target_link_libraries(test_intra_process_manager ${PROJECT_NAME})
# endif()
endif()

ament_package(
Expand All @@ -45,3 +80,10 @@ install(
DIRECTORY src/
DESTINATION src/rclcpp
)

install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
10 changes: 5 additions & 5 deletions rclcpp/include/rclcpp/any_executable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <memory>

#include <rclcpp/macros.hpp>
#include <rclcpp/node.hpp>
#include "rclcpp/macros.hpp"
#include "rclcpp/node.hpp"

namespace rclcpp
{
Expand All @@ -28,9 +28,9 @@ namespace executor
struct AnyExecutable
{
RCLCPP_SMART_PTR_DEFINITIONS(AnyExecutable);
AnyExecutable()
: subscription(0), timer(0), callback_group(0), node(0)
{}

AnyExecutable();

// Only one of the following pointers will be set.
rclcpp::subscription::SubscriptionBase::SharedPtr subscription;
rclcpp::subscription::SubscriptionBase::SharedPtr subscription_intra_process;
Expand Down
5 changes: 3 additions & 2 deletions rclcpp/include/rclcpp/any_service_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
#ifndef RCLCPP_RCLCPP_ANY_SERVICE_CALLBACK_HPP_
#define RCLCPP_RCLCPP_ANY_SERVICE_CALLBACK_HPP_

#include <rclcpp/function_traits.hpp>

#include <functional>
#include <memory>
#include <stdexcept>
#include <type_traits>

#include <rmw/types.h>

#include "rclcpp/function_traits.hpp"

namespace rclcpp
{

Expand Down
1 change: 1 addition & 0 deletions rclcpp/include/rclcpp/any_subscription_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <functional>
#include <memory>
#include <stdexcept>
#include <type_traits>

#include "rclcpp/allocator/allocator_common.hpp"
Expand Down
93 changes: 31 additions & 62 deletions rclcpp/include/rclcpp/callback_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#include <string>
#include <vector>

#include <rclcpp/subscription.hpp>
#include <rclcpp/timer.hpp>
#include <rclcpp/service.hpp>
#include <rclcpp/client.hpp>
#include "rclcpp/client.hpp"
#include "rclcpp/service.hpp"
#include "rclcpp/subscription.hpp"
#include "rclcpp/timer.hpp"

namespace rclcpp
{
Expand All @@ -49,77 +49,46 @@ class CallbackGroup
public:
RCLCPP_SMART_PTR_DEFINITIONS(CallbackGroup);

CallbackGroup(CallbackGroupType group_type)
: type_(group_type), can_be_taken_from_(true)
{}

const std::vector<subscription::SubscriptionBase::WeakPtr> &
get_subscription_ptrs() const
{
return subscription_ptrs_;
}

const std::vector<timer::TimerBase::WeakPtr> &
get_timer_ptrs() const
{
return timer_ptrs_;
}

const std::vector<service::ServiceBase::SharedPtr> &
get_service_ptrs() const
{
return service_ptrs_;
}

const std::vector<client::ClientBase::SharedPtr> &
get_client_ptrs() const
{
return client_ptrs_;
}

std::atomic_bool & can_be_taken_from()
{
return can_be_taken_from_;
}

const CallbackGroupType & type() const
{
return type_;
}
CallbackGroup(CallbackGroupType group_type);

const std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> &
get_subscription_ptrs() const;

const std::vector<rclcpp::timer::TimerBase::WeakPtr> &
get_timer_ptrs() const;

const std::vector<rclcpp::service::ServiceBase::SharedPtr> &
get_service_ptrs() const;

const std::vector<rclcpp::client::ClientBase::SharedPtr> &
get_client_ptrs() const;

std::atomic_bool &
can_be_taken_from();

const CallbackGroupType &
type() const;

private:
RCLCPP_DISABLE_COPY(CallbackGroup);

void
add_subscription(
const subscription::SubscriptionBase::SharedPtr subscription_ptr)
{
subscription_ptrs_.push_back(subscription_ptr);
}
add_subscription(const rclcpp::subscription::SubscriptionBase::SharedPtr subscription_ptr);

void
add_timer(const timer::TimerBase::SharedPtr timer_ptr)
{
timer_ptrs_.push_back(timer_ptr);
}
add_timer(const rclcpp::timer::TimerBase::SharedPtr timer_ptr);

void
add_service(const service::ServiceBase::SharedPtr service_ptr)
{
service_ptrs_.push_back(service_ptr);
}
add_service(const rclcpp::service::ServiceBase::SharedPtr service_ptr);

void
add_client(const client::ClientBase::SharedPtr client_ptr)
{
client_ptrs_.push_back(client_ptr);
}
add_client(const rclcpp::client::ClientBase::SharedPtr client_ptr);

CallbackGroupType type_;
std::vector<subscription::SubscriptionBase::WeakPtr> subscription_ptrs_;
std::vector<timer::TimerBase::WeakPtr> timer_ptrs_;
std::vector<service::ServiceBase::SharedPtr> service_ptrs_;
std::vector<client::ClientBase::SharedPtr> client_ptrs_;
std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> subscription_ptrs_;
std::vector<rclcpp::timer::TimerBase::WeakPtr> timer_ptrs_;
std::vector<rclcpp::service::ServiceBase::SharedPtr> service_ptrs_;
std::vector<rclcpp::client::ClientBase::SharedPtr> client_ptrs_;
std::atomic_bool can_be_taken_from_;

};
Expand Down
31 changes: 8 additions & 23 deletions rclcpp/include/rclcpp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define RCLCPP_RCLCPP_CLIENT_HPP_

#include <future>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
Expand All @@ -25,8 +24,8 @@
#include <rmw/error_handling.h>
#include <rmw/rmw.h>

#include <rclcpp/macros.hpp>
#include <rclcpp/utilities.hpp>
#include "rclcpp/macros.hpp"
#include "rclcpp/utilities.hpp"

namespace rclcpp
{
Expand All @@ -43,29 +42,15 @@ class ClientBase
ClientBase(
std::shared_ptr<rmw_node_t> node_handle,
rmw_client_t * client_handle,
const std::string & service_name)
: node_handle_(node_handle), client_handle_(client_handle), service_name_(service_name)
{}
const std::string & service_name);

virtual ~ClientBase()
{
if (client_handle_) {
if (rmw_destroy_client(client_handle_) != RMW_RET_OK) {
fprintf(stderr,
"Error in destruction of rmw client handle: %s\n", rmw_get_error_string_safe());
}
}
}
virtual ~ClientBase();

const std::string & get_service_name() const
{
return this->service_name_;
}
const std::string &
get_service_name() const;

const rmw_client_t * get_client_handle() const
{
return this->client_handle_;
}
const rmw_client_t *
get_client_handle() const;

virtual std::shared_ptr<void> create_response() = 0;
virtual std::shared_ptr<void> create_request_header() = 0;
Expand Down
6 changes: 3 additions & 3 deletions rclcpp/include/rclcpp/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#ifndef RCLCPP_RCLCPP_CONTEXT_HPP_
#define RCLCPP_RCLCPP_CONTEXT_HPP_

#include <rclcpp/macros.hpp>

#include <iostream>

#include <memory>
Expand All @@ -27,6 +25,8 @@

#include <rmw/rmw.h>

#include "rclcpp/macros.hpp"

namespace rclcpp
{

Expand All @@ -38,7 +38,7 @@ class Context
public:
RCLCPP_SMART_PTR_DEFINITIONS(Context);

Context() {}
Context();

template<typename SubContext, typename ... Args>
std::shared_ptr<SubContext>
Expand Down
8 changes: 2 additions & 6 deletions rclcpp/include/rclcpp/contexts/default_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ class DefaultContext : public rclcpp::context::Context
public:
RCLCPP_SMART_PTR_DEFINITIONS(DefaultContext);

DefaultContext() {}
DefaultContext();

};

DefaultContext::SharedPtr
get_global_default_context()
{
static DefaultContext::SharedPtr default_context = DefaultContext::make_shared();
return default_context;
}
get_global_default_context();

} // namespace default_context
} // namespace contexts
Expand Down
Loading

0 comments on commit 4761732

Please sign in to comment.