@@ -41,11 +41,23 @@ uint32_t received_results_ = 0;
4141std::vector<std::pair<eprosima::ddsenabler::participants::UUID , std::string>> received_requests_;
4242std::mutex app_mutex_;
4343std::condition_variable app_cv_;
44+ bool stop_app_ = false ;
4445
4546const std::string REQUESTS_SUBDIR = " goals" ;
4647const std::string TYPES_SUBDIR = " types" ;
4748const std::string ACTION_SUBDIR = " actions" ;
4849
50+ void signal_handler (
51+ int signum)
52+ {
53+ std::cout << " Signal " << CLIParser::parse_signal (signum) << " received, stopping..." << std::endl;
54+ {
55+ std::lock_guard<std::mutex> lock (app_mutex_);
56+ stop_app_ = true ;
57+ }
58+ app_cv_.notify_all ();
59+ }
60+
4961// Static log callback
5062void test_log_callback (
5163 const char * file_name,
@@ -268,10 +280,10 @@ bool wait_for_action_discovery(
268280 std::condition_variable& app_cv)
269281{
270282 std::unique_lock<std::mutex> lock (app_mutex);
271- if (!app_cv.wait_for (lock, std::chrono::seconds (timeout),
283+ if (stop_app_ || !app_cv.wait_for (lock, std::chrono::seconds (timeout),
272284 []()
273285 {
274- return action_discovered_;
286+ return stop_app_ || action_discovered_;
275287 }))
276288 {
277289 std::cerr << " Timeout waiting for service discovery." << std::endl;
@@ -288,10 +300,10 @@ bool wait_for_action_request(
288300 std::string& goal_json)
289301{
290302 std::unique_lock<std::mutex> lock (app_mutex);
291- if (!app_cv.wait_for (lock, std::chrono::seconds (timeout),
303+ if (stop_app_ || !app_cv.wait_for (lock, std::chrono::seconds (timeout),
292304 []()
293305 {
294- return !received_requests_.empty ();
306+ return stop_app_ || !received_requests_.empty ();
295307 }))
296308 {
297309 std::cerr << " Timeout waiting for service request." << std::endl;
@@ -311,10 +323,10 @@ bool wait_for_action_result(
311323 uint32_t sent_requests)
312324{
313325 std::unique_lock<std::mutex> lock (app_mutex);
314- if (!app_cv.wait_for (lock, std::chrono::seconds (timeout),
326+ if (stop_app_ || !app_cv.wait_for (lock, std::chrono::seconds (timeout),
315327 [&sent_requests]()
316328 {
317- return received_results_ >= sent_requests;
329+ return stop_app_ || received_results_ >= sent_requests;
318330 }))
319331 {
320332 std::cerr << " Timeout waiting for action result." << std::endl;
@@ -452,7 +464,7 @@ bool server_routine(
452464
453465 std::cout << " Action announced: " << action_name << std::endl;
454466
455- while (true )
467+ while (!stop_app_ )
456468 {
457469 eprosima::ddsenabler::participants::UUID request_id;
458470 std::string goal_json;
@@ -477,10 +489,10 @@ bool server_routine(
477489 return false ;
478490 }
479491
480- // Check if we have received the expected number of requests
492+ // Check if we have received the expected number of requests (or run indefinitely if expected_requests is 0)
481493 {
482494 std::lock_guard<std::mutex> lock (app_mutex_);
483- if (++received_results_ >= expected_requests)
495+ if (expected_requests != 0 && ++received_results_ >= expected_requests)
484496 {
485497 break ;
486498 }
@@ -537,7 +549,12 @@ int main(
537549 };
538550
539551 std::shared_ptr<DDSEnabler> enabler;
540- if (!create_dds_enabler (config.config_file_path .c_str (), callbacks, enabler))
552+ bool enabler_created = false ;
553+ if (config.config_file_path .empty ())
554+ enabler_created = create_dds_enabler (yaml::EnablerConfiguration (" " ), callbacks, enabler);
555+ else
556+ enabler_created = create_dds_enabler (config.config_file_path .c_str (), callbacks, enabler);
557+ if (!enabler_created)
541558 {
542559 std::cerr << " Failed to create DDSEnabler instance." << std::endl;
543560 return EXIT_FAILURE ;
@@ -552,17 +569,13 @@ int main(
552569 }
553570 else
554571 {
555- std::string goal_path;
556- if (!config.goals_path .empty ())
572+ if (config.goals_path .empty ())
557573 {
558- goal_path = config.goals_path ;
574+ std::cerr << " Request path is not set." << std::endl;
575+ return EXIT_FAILURE ;
559576 }
560- else
561- {
562- goal_path = config.persistence_path .empty () ? std::string () :
563- (std::filesystem::path (config.persistence_path ) / REQUESTS_SUBDIR ).string ();
564- }
565- ret = client_routine (enabler, config.action_name , goal_path, config.timeout , config.request_initial_wait ,
577+
578+ ret = client_routine (enabler, config.action_name , config.goals_path , config.timeout , config.request_initial_wait ,
566579 config.cancel_requests );
567580 }
568581
0 commit comments