Skip to content

Commit 711072d

Browse files
author
Minggang Wang
committed
Format the codebase by npm run format
Fix #None
1 parent 25a3055 commit 711072d

25 files changed

+524
-582
lines changed

src/addon.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ void InitModule(v8::Local<v8::Object> exports) {
2929

3030
for (uint32_t i = 0;
3131
i < rclnodejs::GetBindingMethodsCount(rclnodejs::binding_methods); i++) {
32-
Nan::Set(exports,
33-
Nan::New(rclnodejs::binding_methods[i].name).ToLocalChecked(),
32+
Nan::Set(
33+
exports, Nan::New(rclnodejs::binding_methods[i].name).ToLocalChecked(),
3434
Nan::New<v8::FunctionTemplate>(rclnodejs::binding_methods[i].function)
35-
->GetFunction(context).ToLocalChecked());
35+
->GetFunction(context)
36+
.ToLocalChecked());
3637
}
3738

38-
for (uint32_t i = 0; i < rclnodejs::GetBindingMethodsCount(
39-
rclnodejs::action_binding_methods); i++) {
40-
Nan::Set(exports,
39+
for (uint32_t i = 0;
40+
i < rclnodejs::GetBindingMethodsCount(rclnodejs::action_binding_methods);
41+
i++) {
42+
Nan::Set(
43+
exports,
4144
Nan::New(rclnodejs::action_binding_methods[i].name).ToLocalChecked(),
4245
Nan::New<v8::FunctionTemplate>(
4346
rclnodejs::action_binding_methods[i].function)
44-
->GetFunction(context).ToLocalChecked());
47+
->GetFunction(context)
48+
.ToLocalChecked());
4549
}
4650

4751
rclnodejs::ShadowNode::Init(exports);

src/executor.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "executor.hpp"
1616

1717
#include <rcl/error_handling.h>
18+
1819
#include <stdexcept>
1920
#include <string>
2021

@@ -23,9 +24,9 @@
2324
#include "spdlog/spdlog.h"
2425

2526
#ifdef WIN32
26-
#define UNUSED
27+
#define UNUSED
2728
#else
28-
#define UNUSED __attribute__((unused))
29+
#define UNUSED __attribute__((unused))
2930
#endif
3031

3132
namespace rclnodejs {
@@ -64,16 +65,14 @@ void Executor::SpinOnce(rcl_context_t* context, int32_t time_out) {
6465
if (!running_.load()) {
6566
try {
6667
rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set();
67-
rcl_ret_t ret =
68-
rcl_wait_set_init(&wait_set, 0, 2, 0, 0, 0, 0, context,
69-
rcl_get_default_allocator());
68+
rcl_ret_t ret = rcl_wait_set_init(&wait_set, 0, 2, 0, 0, 0, 0, context,
69+
rcl_get_default_allocator());
7070
if (ret != RCL_RET_OK) {
7171
throw std::runtime_error(std::string("Init waitset failed: ") +
7272
rcl_get_error_string().str);
7373
}
7474

75-
if (WaitForReadyCallbacks(&wait_set, time_out))
76-
ExecuteReadyHandles();
75+
if (WaitForReadyCallbacks(&wait_set, time_out)) ExecuteReadyHandles();
7776

7877
if (rcl_wait_set_fini(&wait_set) != RCL_RET_OK) {
7978
std::string error_message =
@@ -105,8 +104,7 @@ void Executor::Stop() {
105104
delete async;
106105
handle_closed = true;
107106
});
108-
while (!handle_closed)
109-
uv_run(uv_default_loop(), UV_RUN_ONCE);
107+
while (!handle_closed) uv_run(uv_default_loop(), UV_RUN_ONCE);
110108

111109
SPDLOG_DEBUG(spdlog::get("rclnodejs"), "Background thread stopped.");
112110
}
@@ -158,10 +156,9 @@ void Executor::Run(void* arg) {
158156
}
159157
}
160158

161-
bool Executor::WaitForReadyCallbacks(
162-
rcl_wait_set_t* wait_set, int32_t time_out) {
163-
if (handle_manager_->is_empty())
164-
return false;
159+
bool Executor::WaitForReadyCallbacks(rcl_wait_set_t* wait_set,
160+
int32_t time_out) {
161+
if (handle_manager_->is_empty()) return false;
165162

166163
size_t num_subscriptions = 0u;
167164
size_t num_guard_conditions = 0u;
@@ -170,19 +167,15 @@ bool Executor::WaitForReadyCallbacks(
170167
size_t num_services = 0u;
171168

172169
if (!handle_manager_->GetEntityCounts(&num_subscriptions,
173-
&num_guard_conditions,
174-
&num_timers,
175-
&num_clients,
176-
&num_services)) {
170+
&num_guard_conditions, &num_timers,
171+
&num_clients, &num_services)) {
177172
std::string error_message = std::string("Failed to get entity counts: ") +
178173
std::string(rcl_get_error_string().str);
179174
throw std::runtime_error(error_message);
180175
}
181176

182177
if (rcl_wait_set_resize(wait_set, num_subscriptions,
183-
num_guard_conditions + 1u,
184-
num_timers,
185-
num_clients,
178+
num_guard_conditions + 1u, num_timers, num_clients,
186179
num_services,
187180
// TODO(minggang): support events.
188181
0u) != RCL_RET_OK) {
@@ -196,15 +189,15 @@ bool Executor::WaitForReadyCallbacks(
196189
}
197190

198191
int ignored UNUSED =
199-
rcl_wait_set_add_guard_condition(wait_set, g_sigint_gc, nullptr);
192+
rcl_wait_set_add_guard_condition(wait_set, g_sigint_gc, nullptr);
200193

201194
time_out = time_out < 0 ? -1 : RCL_MS_TO_NS(time_out);
202195

203196
rcl_ret_t status = rcl_wait(wait_set, time_out);
204197
if (status == RCL_RET_WAIT_SET_EMPTY) {
205198
} else if (status != RCL_RET_OK && status != RCL_RET_TIMEOUT) {
206199
throw std::runtime_error(std::string("rcl_wait() failed: ") +
207-
rcl_get_error_string().str);
200+
rcl_get_error_string().str);
208201
} else {
209202
if (wait_set->size_of_guard_conditions == 1 &&
210203
wait_set->guard_conditions[0]) {
@@ -220,9 +213,8 @@ bool Executor::WaitForReadyCallbacks(
220213
}
221214

222215
if (rcl_wait_set_clear(wait_set) != RCL_RET_OK) {
223-
std::string error_message =
224-
std::string("Failed to clear wait set: ") +
225-
std::string(rcl_get_error_string().str);
216+
std::string error_message = std::string("Failed to clear wait set: ") +
217+
std::string(rcl_get_error_string().str);
226218
throw std::runtime_error(error_message);
227219
}
228220

src/executor.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef RCLNODEJS_EXECUTOR_HPP_
1616
#define RCLNODEJS_EXECUTOR_HPP_
1717

18-
#include <uv.h>
1918
#include <rcl/wait.h>
19+
#include <uv.h>
2020

2121
#include <atomic>
2222
#include <exception>
@@ -34,8 +34,7 @@ class Executor {
3434
public:
3535
class Delegate {
3636
public:
37-
virtual void Execute(
38-
const std::vector<rclnodejs::RclHandle *>& handles) = 0;
37+
virtual void Execute(const std::vector<rclnodejs::RclHandle*>& handles) = 0;
3938
virtual void CatchException(std::exception_ptr e_ptr) = 0;
4039
};
4140

src/handle_manager.cpp

Lines changed: 44 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "handle_manager.hpp"
1616

1717
#include <rcl_action/rcl_action.h>
18+
1819
#include <vector>
1920

2021
#include "spdlog/spdlog.h"
@@ -80,15 +81,11 @@ void HandleManager::CollectHandles(const v8::Local<v8::Object> node) {
8081
is_synchronizing_.store(false);
8182
uv_sem_post(&sem_);
8283

83-
SPDLOG_DEBUG(
84-
spdlog::get("rclnodejs"),
85-
"Add {0:d} timers, {1:d} subscriptions, {2:d} clients, " +
86-
"{3:d} services, {4:d} guards.",
87-
timers_.size(),
88-
subscriptions_.size(),
89-
clients_.size(),
90-
services_.size(),
91-
guard_conditions_.size());
84+
SPDLOG_DEBUG(spdlog::get("rclnodejs"),
85+
"Add {0:d} timers, {1:d} subscriptions, {2:d} clients, " +
86+
"{3:d} services, {4:d} guards.",
87+
timers_.size(), subscriptions_.size(), clients_.size(),
88+
services_.size(), guard_conditions_.size());
9289
}
9390

9491
bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {
@@ -98,7 +95,7 @@ bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {
9895
return false;
9996
}
10097
for (auto& subscription : subscriptions_) {
101-
rcl_subscription_t* rcl_subscription =
98+
rcl_subscription_t* rcl_subscription =
10299
reinterpret_cast<rcl_subscription_t*>(subscription->ptr());
103100
if (rcl_wait_set_add_subscription(wait_set, rcl_subscription, nullptr) !=
104101
RCL_RET_OK)
@@ -118,22 +115,22 @@ bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {
118115
for (auto& guard_condition : guard_conditions_) {
119116
rcl_guard_condition_t* rcl_guard_condition =
120117
reinterpret_cast<rcl_guard_condition_t*>(guard_condition->ptr());
121-
if (rcl_wait_set_add_guard_condition(wait_set, rcl_guard_condition, nullptr)
122-
!= RCL_RET_OK)
118+
if (rcl_wait_set_add_guard_condition(wait_set, rcl_guard_condition,
119+
nullptr) != RCL_RET_OK)
123120
return false;
124121
}
125122
for (auto& action_client : action_clients_) {
126123
rcl_action_client_t* rcl_action_client =
127124
reinterpret_cast<rcl_action_client_t*>(action_client->ptr());
128125
if (rcl_action_wait_set_add_action_client(wait_set, rcl_action_client,
129-
nullptr, nullptr) != RCL_RET_OK)
126+
nullptr, nullptr) != RCL_RET_OK)
130127
return false;
131128
}
132129
for (auto& action_server : action_servers_) {
133130
rcl_action_server_t* rcl_action_server =
134131
reinterpret_cast<rcl_action_server_t*>(action_server->ptr());
135132
if (rcl_action_wait_set_add_action_server(wait_set, rcl_action_server,
136-
nullptr) != RCL_RET_OK)
133+
nullptr) != RCL_RET_OK)
137134
return false;
138135
}
139136

@@ -143,36 +140,25 @@ bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {
143140
bool HandleManager::CollectReadyHandles(rcl_wait_set_t* wait_set) {
144141
ready_handles_.clear();
145142

146-
CollectReadyHandlesByType(
147-
wait_set->subscriptions,
148-
wait_set->size_of_subscriptions,
149-
subscriptions_);
150-
CollectReadyHandlesByType(
151-
wait_set->clients,
152-
wait_set->size_of_clients,
153-
clients_);
154-
CollectReadyHandlesByType(
155-
wait_set->services,
156-
wait_set->size_of_services,
157-
services_);
158-
CollectReadyHandlesByType(
159-
wait_set->timers,
160-
wait_set->size_of_timers,
161-
timers_);
162-
CollectReadyHandlesByType(
163-
wait_set->guard_conditions,
164-
wait_set->size_of_guard_conditions,
165-
guard_conditions_);
143+
CollectReadyHandlesByType(wait_set->subscriptions,
144+
wait_set->size_of_subscriptions, subscriptions_);
145+
CollectReadyHandlesByType(wait_set->clients, wait_set->size_of_clients,
146+
clients_);
147+
CollectReadyHandlesByType(wait_set->services, wait_set->size_of_services,
148+
services_);
149+
CollectReadyHandlesByType(wait_set->timers, wait_set->size_of_timers,
150+
timers_);
151+
CollectReadyHandlesByType(wait_set->guard_conditions,
152+
wait_set->size_of_guard_conditions,
153+
guard_conditions_);
166154

167155
return CollectReadyActionHandles(wait_set);
168156
}
169157

170-
bool HandleManager::GetEntityCounts(
171-
size_t *subscriptions_size,
172-
size_t *guard_conditions_size,
173-
size_t *timers_size,
174-
size_t *clients_size,
175-
size_t *services_size) {
158+
bool HandleManager::GetEntityCounts(size_t* subscriptions_size,
159+
size_t* guard_conditions_size,
160+
size_t* timers_size, size_t* clients_size,
161+
size_t* services_size) {
176162
size_t num_subscriptions = 0u;
177163
size_t num_guard_conditions = 0u;
178164
size_t num_timers = 0u;
@@ -183,12 +169,8 @@ bool HandleManager::GetEntityCounts(
183169
rcl_action_client_t* rcl_action_client =
184170
reinterpret_cast<rcl_action_client_t*>(action_client->ptr());
185171
rcl_ret_t ret = rcl_action_client_wait_set_get_num_entities(
186-
rcl_action_client,
187-
&num_subscriptions,
188-
&num_guard_conditions,
189-
&num_timers,
190-
&num_clients,
191-
&num_services);
172+
rcl_action_client, &num_subscriptions, &num_guard_conditions,
173+
&num_timers, &num_clients, &num_services);
192174
if (ret != RCL_RET_OK) {
193175
return false;
194176
}
@@ -204,12 +186,8 @@ bool HandleManager::GetEntityCounts(
204186
rcl_action_server_t* rcl_action_server =
205187
reinterpret_cast<rcl_action_server_t*>(action_server->ptr());
206188
rcl_ret_t ret = rcl_action_server_wait_set_get_num_entities(
207-
rcl_action_server,
208-
&num_subscriptions,
209-
&num_guard_conditions,
210-
&num_timers,
211-
&num_clients,
212-
&num_services);
189+
rcl_action_server, &num_subscriptions, &num_guard_conditions,
190+
&num_timers, &num_clients, &num_services);
213191
if (ret != RCL_RET_OK) {
214192
return false;
215193
}
@@ -246,13 +224,16 @@ void HandleManager::CollectHandlesByType(
246224
Nan::HandleScope scope;
247225

248226
if (typeObject->IsArray()) {
249-
uint32_t length = Nan::To<uint32_t>(
250-
Nan::Get(typeObject, Nan::New("length").ToLocalChecked())
251-
.ToLocalChecked()).FromJust();
227+
uint32_t length =
228+
Nan::To<uint32_t>(
229+
Nan::Get(typeObject, Nan::New("length").ToLocalChecked())
230+
.ToLocalChecked())
231+
.FromJust();
252232

253233
for (uint32_t index = 0; index < length; index++) {
254-
v8::Local<v8::Object> obj = Nan::To<v8::Object>(
255-
Nan::Get(typeObject, index).ToLocalChecked()).ToLocalChecked();
234+
v8::Local<v8::Object> obj =
235+
Nan::To<v8::Object>(Nan::Get(typeObject, index).ToLocalChecked())
236+
.ToLocalChecked();
256237
Nan::MaybeLocal<v8::Value> handle =
257238
Nan::Get(obj, Nan::New("_handle").ToLocalChecked());
258239
rclnodejs::RclHandle* rcl_handle =
@@ -263,10 +244,9 @@ void HandleManager::CollectHandlesByType(
263244
}
264245
}
265246

266-
template<typename T>
247+
template <typename T>
267248
void HandleManager::CollectReadyHandlesByType(
268-
const T** struct_ptr,
269-
size_t size,
249+
const T** struct_ptr, size_t size,
270250
const std::vector<rclnodejs::RclHandle*>& handles) {
271251
for (size_t idx = 0; idx < size; ++idx) {
272252
if (struct_ptr[idx]) {
@@ -290,12 +270,8 @@ bool HandleManager::CollectReadyActionHandles(rcl_wait_set_t* wait_set) {
290270
rcl_action_client_t* rcl_action_client =
291271
reinterpret_cast<rcl_action_client_t*>(action_client->ptr());
292272
rcl_ret_t ret = rcl_action_client_wait_set_get_entities_ready(
293-
wait_set,
294-
rcl_action_client,
295-
&is_feedback_ready,
296-
&is_status_ready,
297-
&is_goal_response_ready,
298-
&is_cancel_response_ready,
273+
wait_set, rcl_action_client, &is_feedback_ready, &is_status_ready,
274+
&is_goal_response_ready, &is_cancel_response_ready,
299275
&is_result_response_ready);
300276
if (ret != RCL_RET_OK) {
301277
return false;
@@ -325,12 +301,8 @@ bool HandleManager::CollectReadyActionHandles(rcl_wait_set_t* wait_set) {
325301
rcl_action_server_t* rcl_action_server =
326302
reinterpret_cast<rcl_action_server_t*>(action_server->ptr());
327303
rcl_ret_t ret = rcl_action_server_wait_set_get_entities_ready(
328-
wait_set,
329-
rcl_action_server,
330-
&is_goal_request_ready,
331-
&is_cancel_request_ready,
332-
&is_result_request_ready,
333-
&is_goal_expired);
304+
wait_set, rcl_action_server, &is_goal_request_ready,
305+
&is_cancel_request_ready, &is_result_request_ready, &is_goal_expired);
334306
if (ret != RCL_RET_OK) {
335307
return false;
336308
}

0 commit comments

Comments
 (0)