Skip to content

Commit bc97923

Browse files
committed
update style to match latest uncrustify
1 parent 4444f34 commit bc97923

12 files changed

Lines changed: 193 additions & 171 deletions

File tree

composition/src/api_composition.cpp

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -82,76 +82,78 @@ int main(int argc, char * argv[])
8282
const std::shared_ptr<rmw_request_id_t>,
8383
const std::shared_ptr<composition::srv::LoadNode::Request> request,
8484
std::shared_ptr<composition::srv::LoadNode::Response> response)
85-
{
86-
// get node plugin resource from package
87-
std::string content;
88-
std::string base_path;
89-
if (!ament_index_cpp::get_resource("node_plugin", request->package_name, content, &base_path)) {
90-
fprintf(stderr, "Could not find requested resource in ament index\n");
91-
response->success = false;
92-
return;
93-
}
94-
95-
std::vector<std::string> lines = split(content, '\n', true);
96-
for (auto line : lines) {
97-
std::vector<std::string> parts = split(line, ';');
98-
if (parts.size() != 2) {
99-
fprintf(stderr, "Invalid resource entry\n");
85+
{
86+
// get node plugin resource from package
87+
std::string content;
88+
std::string base_path;
89+
if (
90+
!ament_index_cpp::get_resource("node_plugin", request->package_name, content, &base_path))
91+
{
92+
fprintf(stderr, "Could not find requested resource in ament index\n");
10093
response->success = false;
10194
return;
10295
}
103-
// match plugin name with the same rmw suffix as this executable
104-
if (parts[0] != request->plugin_name) {
105-
continue;
106-
}
10796

108-
std::string class_name = parts[0];
97+
std::vector<std::string> lines = split(content, '\n', true);
98+
for (auto line : lines) {
99+
std::vector<std::string> parts = split(line, ';');
100+
if (parts.size() != 2) {
101+
fprintf(stderr, "Invalid resource entry\n");
102+
response->success = false;
103+
return;
104+
}
105+
// match plugin name with the same rmw suffix as this executable
106+
if (parts[0] != request->plugin_name) {
107+
continue;
108+
}
109109

110-
// load node plugin
111-
std::string library_path = parts[1];
112-
if (!fs::path(library_path).is_absolute()) {
113-
library_path = base_path + "/" + library_path;
114-
}
115-
printf("Load library %s\n", library_path.c_str());
116-
class_loader::ClassLoader * loader;
117-
try {
118-
loader = new class_loader::ClassLoader(library_path);
119-
} catch (const std::exception & ex) {
120-
fprintf(stderr, "Failed to load library: %s\n", ex.what());
121-
response->success = false;
122-
return;
123-
} catch (...) {
124-
fprintf(stderr, "Failed to load library\n");
125-
response->success = false;
126-
return;
127-
}
128-
auto classes = loader->getAvailableClasses<rclcpp::Node>();
129-
for (auto clazz : classes) {
130-
if (clazz == class_name) {
131-
printf("Instantiate class %s\n", clazz.c_str());
132-
auto node = loader->createInstance<rclcpp::Node>(clazz);
133-
exec.add_node(node);
134-
nodes.push_back(node);
135-
loaders.push_back(loader);
136-
response->success = true;
110+
std::string class_name = parts[0];
111+
112+
// load node plugin
113+
std::string library_path = parts[1];
114+
if (!fs::path(library_path).is_absolute()) {
115+
library_path = base_path + "/" + library_path;
116+
}
117+
printf("Load library %s\n", library_path.c_str());
118+
class_loader::ClassLoader * loader;
119+
try {
120+
loader = new class_loader::ClassLoader(library_path);
121+
} catch (const std::exception & ex) {
122+
fprintf(stderr, "Failed to load library: %s\n", ex.what());
123+
response->success = false;
124+
return;
125+
} catch (...) {
126+
fprintf(stderr, "Failed to load library\n");
127+
response->success = false;
137128
return;
138129
}
139-
}
130+
auto classes = loader->getAvailableClasses<rclcpp::Node>();
131+
for (auto clazz : classes) {
132+
if (clazz == class_name) {
133+
printf("Instantiate class %s\n", clazz.c_str());
134+
auto node = loader->createInstance<rclcpp::Node>(clazz);
135+
exec.add_node(node);
136+
nodes.push_back(node);
137+
loaders.push_back(loader);
138+
response->success = true;
139+
return;
140+
}
141+
}
140142

141-
// no matching class found in loader
142-
delete loader;
143+
// no matching class found in loader
144+
delete loader;
145+
fprintf(
146+
stderr, "Failed to find class with the requested plugin name '%s' in "
147+
"the loaded library\n",
148+
request->plugin_name.c_str());
149+
response->success = false;
150+
return;
151+
}
143152
fprintf(
144-
stderr, "Failed to find class with the requested plugin name '%s' in "
145-
"the loaded library\n",
146-
request->plugin_name.c_str());
153+
stderr, "Failed to find plugin name '%s' in prefix '%s'\n",
154+
request->plugin_name.c_str(), base_path.c_str());
147155
response->success = false;
148-
return;
149-
}
150-
fprintf(
151-
stderr, "Failed to find plugin name '%s' in prefix '%s'\n",
152-
request->plugin_name.c_str(), base_path.c_str());
153-
response->success = false;
154-
});
156+
});
155157

156158
exec.spin();
157159

demo_nodes_cpp/src/timers/one_off_timer.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ class OneOffTimerNode : public rclcpp::Node
2626
OneOffTimerNode()
2727
: rclcpp::Node("one_off_timer"), count(0)
2828
{
29-
periodic_timer = this->create_wall_timer(2s, [this]() {
30-
printf("in periodic_timer callback\n");
31-
if (this->count++ % 3 == 0) {
32-
printf(" resetting one off timer\n");
33-
this->one_off_timer = this->create_wall_timer(1s, [this]() {
34-
printf("in one_off_timer callback\n");
35-
this->one_off_timer->cancel();
36-
});
37-
} else {
38-
printf(" not resetting one off timer\n");
39-
}
40-
});
29+
periodic_timer = this->create_wall_timer(
30+
2s,
31+
[this]() {
32+
printf("in periodic_timer callback\n");
33+
if (this->count++ % 3 == 0) {
34+
printf(" resetting one off timer\n");
35+
this->one_off_timer = this->create_wall_timer(1s, [this]() {
36+
printf("in one_off_timer callback\n");
37+
this->one_off_timer->cancel();
38+
});
39+
} else {
40+
printf(" not resetting one off timer\n");
41+
}
42+
});
4143
}
4244

4345
rclcpp::TimerBase::SharedPtr periodic_timer;

demo_nodes_cpp/src/timers/reuse_timer.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,26 @@ class OneOffTimerNode : public rclcpp::Node
2626
OneOffTimerNode()
2727
: rclcpp::Node("reuse_timer"), count(0)
2828
{
29-
one_off_timer = this->create_wall_timer(1s, [this]() {
30-
printf("in one_off_timer callback\n");
31-
this->one_off_timer->cancel();
32-
});
29+
one_off_timer = this->create_wall_timer(
30+
1s,
31+
[this]() {
32+
printf("in one_off_timer callback\n");
33+
this->one_off_timer->cancel();
34+
});
3335
// cancel immediately to prevent it running the first time.
3436
one_off_timer->cancel();
3537

36-
periodic_timer = this->create_wall_timer(2s, [this]() {
37-
printf("in periodic_timer callback\n");
38-
if (this->count++ % 3 == 0) {
39-
printf(" resetting one off timer\n");
40-
this->one_off_timer->reset();
41-
} else {
42-
printf(" not resetting one off timer\n");
43-
}
44-
});
38+
periodic_timer = this->create_wall_timer(
39+
2s,
40+
[this]() {
41+
printf("in periodic_timer callback\n");
42+
if (this->count++ % 3 == 0) {
43+
printf(" resetting one off timer\n");
44+
this->one_off_timer->reset();
45+
} else {
46+
printf(" not resetting one off timer\n");
47+
}
48+
});
4549
}
4650

4751
rclcpp::TimerBase::SharedPtr periodic_timer;

demo_nodes_cpp/src/topics/allocator_tutorial.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ struct MyAllocator
7373
};
7474

7575
template<typename T, typename U>
76-
constexpr bool operator==(const MyAllocator<T> &,
76+
constexpr bool operator==(
77+
const MyAllocator<T> &,
7778
const MyAllocator<U> &) noexcept
7879
{
7980
return true;
8081
}
8182

8283
template<typename T, typename U>
83-
constexpr bool operator!=(const MyAllocator<T> &,
84+
constexpr bool operator!=(
85+
const MyAllocator<T> &,
8486
const MyAllocator<U> &) noexcept
8587
{
8688
return false;
@@ -163,9 +165,9 @@ int main(int argc, char ** argv)
163165
// Create a custom allocator and pass the allocator to the publisher and subscriber.
164166
auto alloc = std::make_shared<MyAllocator<void>>();
165167
auto publisher = node->create_publisher<std_msgs::msg::UInt32>("allocator_tutorial", 10, alloc);
166-
auto msg_mem_strat =
167-
std::make_shared<rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::UInt32,
168-
MyAllocator<>>>(alloc);
168+
auto msg_mem_strat = std::make_shared<
169+
rclcpp::message_memory_strategy::MessageMemoryStrategy<
170+
std_msgs::msg::UInt32, MyAllocator<>>>(alloc);
169171
auto subscriber = node->create_subscription<std_msgs::msg::UInt32>(
170172
"allocator_tutorial", 10, callback, nullptr, false, msg_mem_strat, alloc);
171173

demo_nodes_cpp/src/topics/listener_best_effort.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ int main(int argc, char * argv[])
2323
rclcpp::init(argc, argv);
2424
auto node = rclcpp::Node::make_shared("listener");
2525
auto sub = node->create_subscription<std_msgs::msg::String>(
26-
"chatter", [](const std_msgs::msg::String::SharedPtr msg) -> void {
27-
printf("I heard: [%s]\n", msg->data.c_str());
28-
}, rmw_qos_profile_sensor_data);
26+
"chatter",
27+
[](const std_msgs::msg::String::SharedPtr msg) -> void {
28+
printf("I heard: [%s]\n", msg->data.c_str());
29+
},
30+
rmw_qos_profile_sensor_data);
2931
rclcpp::spin(node);
3032
return 0;
3133
}

intra_process_demo/include/image_pipeline/camera_node.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
class CameraNode : public rclcpp::Node
3232
{
3333
public:
34-
CameraNode(const std::string & output, const std::string & node_name = "camera_node",
34+
CameraNode(
35+
const std::string & output, const std::string & node_name = "camera_node",
3536
bool watermark = true, int device = 0, int width = 320, int height = 240)
3637
: Node(node_name, "", true), canceled_(false), watermark_(watermark)
3738
{

intra_process_demo/include/image_pipeline/image_view_node.hpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,34 @@ class ImageViewNode : public rclcpp::Node
3434
{
3535
// Create a subscription on the input topic.
3636
sub_ = this->create_subscription<sensor_msgs::msg::Image>(
37-
input, [node_name, watermark](const sensor_msgs::msg::Image::SharedPtr msg) {
38-
// Create a cv::Mat from the image message (without copying).
39-
cv::Mat cv_mat(
40-
msg->height, msg->width,
41-
encoding2mat_type(msg->encoding),
42-
msg->data.data());
43-
if (watermark) {
44-
// Annotate with the pid and pointer address.
45-
std::stringstream ss;
46-
ss << "pid: " << GETPID() << ", ptr: " << msg.get();
47-
draw_on_image(cv_mat, ss.str(), 60);
48-
}
49-
// Show the image.
50-
CvMat c_mat = cv_mat;
51-
cvShowImage(node_name.c_str(), &c_mat);
52-
char key = cv::waitKey(1); // Look for key presses.
53-
if (key == 27 /* ESC */ || key == 'q') {
54-
rclcpp::shutdown();
55-
}
56-
if (key == ' ') { // If <space> then pause until another <space>.
57-
key = '\0';
58-
while (key != ' ') {
59-
key = cv::waitKey(1);
37+
input,
38+
[node_name, watermark](const sensor_msgs::msg::Image::SharedPtr msg) {
39+
// Create a cv::Mat from the image message (without copying).
40+
cv::Mat cv_mat(
41+
msg->height, msg->width,
42+
encoding2mat_type(msg->encoding),
43+
msg->data.data());
44+
if (watermark) {
45+
// Annotate with the pid and pointer address.
46+
std::stringstream ss;
47+
ss << "pid: " << GETPID() << ", ptr: " << msg.get();
48+
draw_on_image(cv_mat, ss.str(), 60);
6049
}
61-
}
62-
}, rmw_qos_profile_sensor_data);
50+
// Show the image.
51+
CvMat c_mat = cv_mat;
52+
cvShowImage(node_name.c_str(), &c_mat);
53+
char key = cv::waitKey(1); // Look for key presses.
54+
if (key == 27 /* ESC */ || key == 'q') {
55+
rclcpp::shutdown();
56+
}
57+
if (key == ' ') { // If <space> then pause until another <space>.
58+
key = '\0';
59+
while (key != ' ') {
60+
key = cv::waitKey(1);
61+
}
62+
}
63+
},
64+
rmw_qos_profile_sensor_data);
6365
}
6466

6567
private:

intra_process_demo/include/image_pipeline/watermark_node.hpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,24 @@ class WatermarkNode : public rclcpp::Node
3939
std::weak_ptr<std::remove_pointer<decltype(pub_.get())>::type> captured_pub = pub_;
4040
// Create a subscription on the output topic.
4141
sub_ = this->create_subscription<sensor_msgs::msg::Image>(
42-
input, [captured_pub, text](sensor_msgs::msg::Image::UniquePtr msg) {
43-
auto pub_ptr = captured_pub.lock();
44-
if (!pub_ptr) {
45-
return;
46-
}
47-
// Create a cv::Mat from the image message (without copying).
48-
cv::Mat cv_mat(
49-
msg->height, msg->width,
50-
encoding2mat_type(msg->encoding),
51-
msg->data.data());
52-
// Annotate the image with the pid, pointer address, and the watermark text.
53-
std::stringstream ss;
54-
ss << "pid: " << GETPID() << ", ptr: " << msg.get() << " " << text;
55-
draw_on_image(cv_mat, ss.str(), 40);
56-
pub_ptr->publish(msg); // Publish it along.
57-
}, qos);
42+
input,
43+
[captured_pub, text](sensor_msgs::msg::Image::UniquePtr msg) {
44+
auto pub_ptr = captured_pub.lock();
45+
if (!pub_ptr) {
46+
return;
47+
}
48+
// Create a cv::Mat from the image message (without copying).
49+
cv::Mat cv_mat(
50+
msg->height, msg->width,
51+
encoding2mat_type(msg->encoding),
52+
msg->data.data());
53+
// Annotate the image with the pid, pointer address, and the watermark text.
54+
std::stringstream ss;
55+
ss << "pid: " << GETPID() << ", ptr: " << msg.get() << " " << text;
56+
draw_on_image(cv_mat, ss.str(), 40);
57+
pub_ptr->publish(msg); // Publish it along.
58+
},
59+
qos);
5860
}
5961

6062
private:

0 commit comments

Comments
 (0)