22
22
#include < sdf/World.hh>
23
23
24
24
#include < ignition/common/Console.hh>
25
+ #include < ignition/common/Util.hh>
25
26
26
27
#include < ignition/fuel_tools/Interface.hh>
27
28
28
29
#include < ignition/gui/Application.hh>
29
30
31
+ #include " ignition/gazebo/Util.hh"
30
32
#include " SimulationRunner.hh"
31
33
32
34
using namespace ignition ;
@@ -384,7 +386,26 @@ void ServerPrivate::CreateEntities()
384
386
void ServerPrivate::SetupTransport ()
385
387
{
386
388
// Advertise available worlds.
387
- this ->node .Advertise (" /gazebo/worlds" , &ServerPrivate::WorldsService, this );
389
+ std::string worldsService{" /gazebo/worlds" };
390
+ this ->node .Advertise (worldsService, &ServerPrivate::WorldsService, this );
391
+
392
+ ignmsg << " Serving world names on [" << worldsService << " ]" << std::endl;
393
+
394
+ // Resource path management
395
+ std::string addPathService{" /gazebo/resource_paths/add" };
396
+ this ->node .Advertise (addPathService,
397
+ &ServerPrivate::AddResourcePathsService, this );
398
+
399
+ std::string getPathService{" /gazebo/resource_paths/get" };
400
+ this ->node .Advertise (getPathService,
401
+ &ServerPrivate::ResourcePathsService, this );
402
+
403
+ std::string pathTopic{" /gazebo/resource_paths" };
404
+ this ->pathPub = this ->node .Advertise <msgs::StringMsg_V>(pathTopic);
405
+
406
+ ignmsg << " Resource path interfaces on [" << addPathService
407
+ << " ], [" << getPathService << " ], and [" << pathTopic << " ]."
408
+ << std::endl;
388
409
}
389
410
390
411
// ////////////////////////////////////////////////
@@ -402,6 +423,49 @@ bool ServerPrivate::WorldsService(ignition::msgs::StringMsg_V &_res)
402
423
return true ;
403
424
}
404
425
426
+ // ////////////////////////////////////////////////
427
+ void ServerPrivate::AddResourcePathsService (
428
+ const ignition::msgs::StringMsg_V &_req)
429
+ {
430
+ std::vector<std::string> paths;
431
+ for (int i = 0 ; i < _req.data_size (); ++i)
432
+ {
433
+ paths.push_back (_req.data (i));
434
+ }
435
+ addResourcePaths (paths);
436
+
437
+ // Notify new paths
438
+ msgs::StringMsg_V msg;
439
+ auto gzPaths = resourcePaths ();
440
+ for (const auto &path : gzPaths)
441
+ {
442
+ if (!path.empty ())
443
+ msg.add_data (path);
444
+ }
445
+
446
+ this ->pathPub .Publish (msg);
447
+ }
448
+
449
+ // ////////////////////////////////////////////////
450
+ bool ServerPrivate::ResourcePathsService (
451
+ ignition::msgs::StringMsg_V &_res)
452
+ {
453
+ _res.Clear ();
454
+
455
+ // Update paths
456
+ addResourcePaths ();
457
+
458
+ // Get paths
459
+ auto gzPaths = resourcePaths ();
460
+ for (const auto &path : gzPaths)
461
+ {
462
+ if (!path.empty ())
463
+ _res.add_data (path);
464
+ }
465
+
466
+ return true ;
467
+ }
468
+
405
469
// ////////////////////////////////////////////////
406
470
std::string ServerPrivate::FetchResource (const std::string &_uri)
407
471
{
0 commit comments