Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource env var, with transport interface #172

Merged
merged 25 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
73ec648
Move test Relay to its own file
chapulina Jun 4, 2020
d09cca3
Resource env var, with transport interface
chapulina Jun 2, 2020
53f38e4
backport resources.md without changes
chapulina Jun 3, 2020
840b173
Update resources tutorial
chapulina Jun 3, 2020
d1869fe
merged from ign-gazebo2
chapulina Jun 12, 2020
45e76f4
Also add paths for client, needs tests
chapulina Jun 14, 2020
ad8b3b5
Add path tests for the GUI
chapulina Jun 15, 2020
899d538
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jun 15, 2020
f023b26
fix OSX
chapulina Jun 16, 2020
0630001
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 1, 2020
e2979ef
subscribe to path updates
chapulina Jul 1, 2020
0fe84c4
PR feedback
chapulina Jul 8, 2020
d66efe2
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 8, 2020
a086574
remove global node for now
chapulina Jul 9, 2020
7e679e9
Fix running ign gazebo, more PR feedback, more tests
chapulina Jul 11, 2020
cc84c74
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 13, 2020
956354f
Fix spelling
Jul 15, 2020
eeb9778
Woops 😅
chapulina Jul 15, 2020
cac4042
debug OSX segfault on Jenkins
chapulina Jul 15, 2020
4cf32e1
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 16, 2020
bc60887
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 27, 2020
eb53dc7
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 27, 2020
bf8dd0c
cppcheck
chapulina Jul 27, 2020
1d0610f
Merge branch 'ign-gazebo2' into chapulina/resource_path
chapulina Jul 30, 2020
3d035b3
more debugging, ubuntu tests also fail locally, not sure about the ex…
chapulina Aug 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/ignition/gazebo/Server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ namespace ignition
/// 1. /world/<world_name>/scene/info(none) : ignition::msgs::Scene
/// + Returns the current scene information.
///
/// 2. /gazebo/resource_paths/get : ignition::msgs::StringMsg_V
/// + Get list of resource paths.
///
/// 3. /gazebo/resource_paths/add : ignition::msgs::Empty
/// + Add new resource paths.
///
/// ## Topics
///
/// The following are topics provided by the Server.
Expand All @@ -95,6 +101,9 @@ namespace ignition
/// 2. /world/<world_name>/stats : ignition::msgs::WorldStatistics
/// + This topic is throttled to 5Hz.
///
/// 3. /gazebo/resource_paths : ignition::msgs::StringMsg_V
/// + Updated list of resource paths.
///
class IGNITION_GAZEBO_VISIBLE Server
{
/// \brief Construct the server using the parameters specified in a
Expand Down
20 changes: 19 additions & 1 deletion include/ignition/gazebo/Util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,26 @@ namespace ignition
/// paths.
/// \param[in] _filePath The path to a file in disk.
/// \return The full path URI.
std::string asFullPath(const std::string &_uri,
std::string IGNITION_GAZEBO_VISIBLE asFullPath(const std::string &_uri,
const std::string &_filePath);

/// \brief Get resource paths based on latest environment variables.
/// \return All paths in the IGN_GAZEBO_RESOURCE_PATH variable.
std::vector<std::string> IGNITION_GAZEBO_VISIBLE resourcePaths();

/// \brief Add resource paths based on latest environment variables.
/// This will update the SDF and Ignition environment variables, and
/// optionally add more paths to the list.
/// \param[in] _paths Optional paths to add.
void IGNITION_GAZEBO_VISIBLE addResourcePaths(
const std::vector<std::string> &_paths = {});

/// \brief Environment variable holding resource paths.
const std::string kResourcePathEnv{"IGN_GAZEBO_RESOURCE_PATH"};

/// \brief Environment variable used by SDFormat to find URIs inside
/// `<include>`
const std::string kSdfPathEnv{"SDF_PATH"};
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/
#include "ignition/gazebo/Server.hh"
#include "ignition/gazebo/Util.hh"

#include <ignition/common/SystemPaths.hh>
#include <ignition/fuel_tools/Interface.hh>
Expand All @@ -23,6 +24,7 @@
#include <sdf/Error.hh>

#include "ignition/gazebo/config.hh"
#include "ignition/gazebo/Util.hh"
#include "ServerPrivate.hh"
#include "SimulationRunner.hh"

Expand Down Expand Up @@ -98,6 +100,8 @@ Server::Server(const ServerConfig &_config)
sdf::setFindCallback(std::bind(&ServerPrivate::FetchResource,
this->dataPtr.get(), std::placeholders::_1));

addResourcePaths();

sdf::Errors errors;

// Load a world if specified. Check SDF string first, then SDF file
Expand All @@ -118,7 +122,7 @@ Server::Server(const ServerConfig &_config)
else if (!_config.SdfFile().empty())
{
common::SystemPaths systemPaths;
systemPaths.SetFilePathEnv("IGN_GAZEBO_RESOURCE_PATH");
systemPaths.SetFilePathEnv(kResourcePathEnv);
systemPaths.AddFilePaths(IGN_GAZEBO_WORLD_INSTALL_DIR);
std::string filePath = systemPaths.FindFile(_config.SdfFile());
ignmsg << "Loading SDF world file[" << filePath << "].\n";
Expand Down
66 changes: 65 additions & 1 deletion src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
#include <sdf/World.hh>

#include <ignition/common/Console.hh>
#include <ignition/common/Util.hh>

#include <ignition/fuel_tools/Interface.hh>

#include <ignition/gui/Application.hh>

#include "ignition/gazebo/Util.hh"
#include "SimulationRunner.hh"

using namespace ignition;
Expand Down Expand Up @@ -384,7 +386,26 @@ void ServerPrivate::CreateEntities()
void ServerPrivate::SetupTransport()
{
// Advertise available worlds.
this->node.Advertise("/gazebo/worlds", &ServerPrivate::WorldsService, this);
std::string worldsService{"/gazebo/worlds"};
this->node.Advertise(worldsService, &ServerPrivate::WorldsService, this);

ignmsg << "Serving world names on [" << worldsService << "]" << std::endl;

// Resource path management
std::string addPathService{"/gazebo/resource_paths/add"};
this->node.Advertise(addPathService,
&ServerPrivate::AddResourcePathsService, this);

std::string getPathService{"/gazebo/resource_paths/get"};
this->node.Advertise(getPathService,
&ServerPrivate::ResourcePathsService, this);

std::string pathTopic{"/gazebo/resource_paths"};
this->pathPub = this->node.Advertise<msgs::StringMsg_V>(pathTopic);

ignmsg << "Resource path interfaces on [" << addPathService
<< "], [" << getPathService << "], and [" << pathTopic << "]."
<< std::endl;
}

//////////////////////////////////////////////////
Expand All @@ -402,6 +423,49 @@ bool ServerPrivate::WorldsService(ignition::msgs::StringMsg_V &_res)
return true;
}

//////////////////////////////////////////////////
void ServerPrivate::AddResourcePathsService(
const ignition::msgs::StringMsg_V &_req)
{
std::vector<std::string> paths;
for (int i = 0; i < _req.data_size(); ++i)
{
paths.push_back(_req.data(i));
}
addResourcePaths(paths);

// Notify new paths
msgs::StringMsg_V msg;
auto gzPaths = resourcePaths();
for (const auto &path : gzPaths)
{
if (!path.empty())
msg.add_data(path);
}

this->pathPub.Publish(msg);
}

//////////////////////////////////////////////////
bool ServerPrivate::ResourcePathsService(
ignition::msgs::StringMsg_V &_res)
{
_res.Clear();

// Update paths
addResourcePaths();

// Get paths
auto gzPaths = resourcePaths();
for (const auto &path : gzPaths)
{
if (!path.empty())
_res.add_data(path);
}

return true;
}

//////////////////////////////////////////////////
std::string ServerPrivate::FetchResource(const std::string &_uri)
{
Expand Down
13 changes: 13 additions & 0 deletions src/ServerPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ namespace ignition
/// \return True if successful.
private: bool WorldsService(ignition::msgs::StringMsg_V &_res);

/// \brief Callback for add resource paths service.
/// \param[out] _req Request containing the paths to be added.
private: void AddResourcePathsService(
const ignition::msgs::StringMsg_V &_req);

/// \brief Callback for get resource paths service.
/// \param[out] _res Response filled with all current paths.
/// \return True if successful.
private: bool ResourcePathsService(ignition::msgs::StringMsg_V &_res);

/// \brief A pool of worker threads.
public: common::WorkerPool workerPool{2};

Expand Down Expand Up @@ -143,6 +153,9 @@ namespace ignition

/// \brief Node for transport.
private: transport::Node node;

/// \brief Publisher of resrouce paths.
private: transport::Node::Publisher pathPub;
};
}
}
Expand Down
Loading