Skip to content

Commit

Permalink
(roseus_bt) define result_ member as Document to avoid having the all…
Browse files Browse the repository at this point in the history
…ocator go out of scope
  • Loading branch information
Affonso-Gui committed Nov 14, 2022
1 parent c2e9ba7 commit b137462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 3 additions & 5 deletions roseus_bt/include/roseus_bt/ws_action_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RosbridgeActionClient
RosbridgeActionClient(const std::string& master, int port, const std::string& server_name, const std::string& action_type):
rbc_(fmt::format("{}:{}", master, std::to_string(port))),
server_name_(server_name),
result_(rapidjson::kObjectType),
is_active_(false)
{
if (server_name_.front() != '/') {
Expand Down Expand Up @@ -89,7 +90,7 @@ class RosbridgeActionClient
RosbridgeWsClient rbc_;

bool is_active_;
rapidjson::Value result_;
rapidjson::Document result_;

std::string server_name_;
std::string goal_topic_;
Expand All @@ -108,10 +109,7 @@ class RosbridgeActionClient
std::cout << "resultCallback(): Message Received: " << message << std::endl;
#endif

rapidjson::Document document(rapidjson::kObjectType);
document.Parse(message.c_str());
rapidjson::Value res(document, document.GetAllocator());
result_ = res;
result_.Parse(message.c_str());

is_active_ = false;
}
Expand Down
10 changes: 5 additions & 5 deletions roseus_bt/include/roseus_bt/ws_service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RosbridgeServiceClient
RosbridgeServiceClient(const std::string& master, int port, const std::string& service_name):
rbc_(fmt::format("{}:{}", master, std::to_string(port))),
service_name_(service_name),
result_(rapidjson::kObjectType),
is_active_(false)
{
if (service_name_.front() != '/') {
Expand Down Expand Up @@ -46,7 +47,9 @@ class RosbridgeServiceClient
}

void waitForResult() {
#ifdef DEBUG
std::cout << "RemoteService: waiting for result: " << service_name_ << std::endl;
#endif
while (is_active_) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
Expand All @@ -58,7 +61,7 @@ class RosbridgeServiceClient
RosbridgeWsClient rbc_;

bool is_active_;
rapidjson::Value result_;
rapidjson::Document result_;

std::string service_name_;

Expand All @@ -71,10 +74,7 @@ class RosbridgeServiceClient
std::cout << "serviceResponseCallback(): Message Received: " << message << std::endl;
#endif

rapidjson::Document document(rapidjson::kObjectType);
document.Parse(message.c_str());
rapidjson::Value res(document, document.GetAllocator());
result_ = res;
result_.Parse(message.c_str());

is_active_ = false;
connection->send_close(1000);
Expand Down

0 comments on commit b137462

Please sign in to comment.