Skip to content

Commit 223afab

Browse files
committed
graph_manager is now exported as library
1 parent 52abdf5 commit 223afab

File tree

5 files changed

+503
-45
lines changed

5 files changed

+503
-45
lines changed

micro_ros_agent/CMakeLists.txt

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,84 +50,115 @@ find_package(ament_cmake_gtest REQUIRED)
5050

5151
find_package(micro_ros_msgs REQUIRED)
5252

53-
add_executable(${PROJECT_NAME}
54-
src/main.cpp
55-
src/agent/Agent.cpp
53+
set(GRAPH_MANAGER_LIB ${PROJECT_NAME}_graph_manager)
54+
55+
add_library(${GRAPH_MANAGER_LIB} STATIC
5656
src/agent/graph_manager/graph_manager.cpp
57+
src/agent/graph_manager/graph_manager_plugin.cpp
5758
src/agent/graph_manager/graph_typesupport.cpp
5859
src/agent/utils/demangle.cpp
59-
)
60+
)
61+
62+
target_include_directories(${GRAPH_MANAGER_LIB}
63+
PUBLIC
64+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
65+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
66+
)
67+
68+
target_link_libraries(${GRAPH_MANAGER_LIB}
69+
PUBLIC
70+
${micro_ros_msgs_TARGETS}
71+
${rmw_dds_common_TARGETS}
72+
rmw::rmw
73+
rmw_dds_common::rmw_dds_common_library
74+
rmw_fastrtps_shared_cpp::rmw_fastrtps_shared_cpp
75+
rosidl_runtime_cpp::rosidl_runtime_cpp
76+
rosidl_typesupport_cpp::rosidl_typesupport_cpp
77+
rosidl_typesupport_fastrtps_cpp::rosidl_typesupport_fastrtps_cpp
78+
microxrcedds_agent
79+
fastcdr
80+
fastrtps
81+
)
82+
83+
set_target_properties(${GRAPH_MANAGER_LIB} PROPERTIES
84+
CXX_STANDARD 14
85+
CXX_STANDARD_REQUIRED YES
86+
POSITION_INDEPENDENT_CODE ON
87+
)
88+
89+
add_executable(${PROJECT_NAME}
90+
src/main.cpp
91+
src/agent/Agent.cpp
92+
)
6093

6194
target_include_directories(${PROJECT_NAME}
6295
PRIVATE
6396
include
64-
)
65-
66-
ament_target_dependencies(${PROJECT_NAME}
67-
rosidl_typesupport_fastrtps_cpp
68-
rosidl_runtime_cpp
69-
rosidl_typesupport_cpp
70-
fastcdr
71-
fastrtps
72-
rmw_dds_common
73-
rmw
74-
rmw_fastrtps_shared_cpp
75-
micro_ros_msgs
76-
)
97+
)
7798

7899
target_link_libraries(${PROJECT_NAME}
100+
${GRAPH_MANAGER_LIB}
79101
microxrcedds_agent
80102
fastcdr
81103
fastrtps
82104
$<$<BOOL:$<PLATFORM_ID:Linux>>:rt>
83105
$<$<BOOL:$<PLATFORM_ID:Linux>>:dl>
84-
)
85-
86-
target_compile_options(${PROJECT_NAME}
87-
PRIVATE
88-
$<$<C_COMPILER_ID:GNU>:-Wall>
89-
$<$<C_COMPILER_ID:GNU>:-Wextra>
90-
$<$<C_COMPILER_ID:GNU>:-pedantic>
91-
)
92-
93-
set_target_properties(${PROJECT_NAME} PROPERTIES
94-
CXX_STANDARD
95-
14
96-
CXX_STANDARD_REQUIRED
97-
YES
98-
)
106+
)
99107

100108
set_target_properties(${PROJECT_NAME} PROPERTIES
101-
CXX_STANDARD
102-
14
103-
CXX_STANDARD_REQUIRED
104-
YES
105-
)
109+
CXX_STANDARD 14
110+
CXX_STANDARD_REQUIRED YES
111+
)
106112

107113
target_compile_options(${PROJECT_NAME}
108114
PRIVATE
109115
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall>
110116
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wextra>
111117
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wpedantic>
112-
)
118+
)
113119

114-
ament_export_dependencies(microxrcedds_agent)
120+
ament_export_targets(export_${GRAPH_MANAGER_LIB} HAS_LIBRARY_TARGET)
121+
ament_export_dependencies(
122+
microxrcedds_agent
123+
rosidl_typesupport_fastrtps_cpp
124+
rosidl_runtime_cpp
125+
rosidl_typesupport_cpp
126+
fastcdr
127+
fastrtps
128+
rmw_dds_common
129+
rmw
130+
rmw_fastrtps_shared_cpp
131+
micro_ros_msgs
132+
)
115133

116134
ament_package()
117135

136+
install(
137+
TARGETS ${GRAPH_MANAGER_LIB}
138+
EXPORT export_${GRAPH_MANAGER_LIB}
139+
ARCHIVE DESTINATION lib
140+
LIBRARY DESTINATION lib
141+
RUNTIME DESTINATION bin
142+
)
143+
144+
install(
145+
DIRECTORY include/
146+
DESTINATION include/${PROJECT_NAME}
147+
)
148+
118149
install(
119150
TARGETS
120151
${PROJECT_NAME}
121152
DESTINATION
122153
lib/${PROJECT_NAME}
123-
)
154+
)
124155

125156
install(
126157
DIRECTORY
127158
launch
128159
DESTINATION
129160
share/${PROJECT_NAME}
130-
)
161+
)
131162

132163
if(UROSAGENT_GENERATE_PROFILE)
133164
set(_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/python")

micro_ros_agent/include/agent/graph_manager/graph_manager.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <agent/graph_manager/graph_typesupport.hpp>
6262
#include <agent/utils/demangle.hpp>
6363

64+
#include <atomic>
6465
#include <condition_variable>
6566
#include <string>
6667
#include <memory>
@@ -84,9 +85,15 @@ class GraphManager
8485
GraphManager(eprosima::fastdds::dds::DomainId_t domain_id);
8586

8687
/**
87-
* @brief Default destructor.
88+
* @brief Destructor - signals thread to stop and joins it.
8889
*/
89-
~GraphManager() = default;
90+
~GraphManager();
91+
92+
/**
93+
* @brief Signal the graph manager to stop (called before destruction).
94+
* Safe to call multiple times.
95+
*/
96+
void shutdown();
9097

9198
/**
9299
* @brief Implementation of the notification logic that updates the micro-ROS graph.
@@ -283,6 +290,7 @@ class GraphManager
283290
eprosima::fastdds::dds::DomainId_t domain_id_;
284291
bool graph_changed_;
285292
bool display_on_change_;
293+
std::atomic<bool> shutdown_requested_{false};
286294
std::thread microros_graph_publisher_;
287295
std::mutex mtx_;
288296
std::condition_variable cv_;

0 commit comments

Comments
 (0)