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

Add system to an entity through Component Inspector #1549

Merged
merged 58 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0896ac1
Added more tests
Feb 11, 2022
60be532
merged with ign-gazebo6
Feb 11, 2022
2770692
Change clone
Feb 16, 2022
4a9822b
Use sdf::Plugin instead of sdf::ElementPtr
Feb 16, 2022
f32555b
Address review comments
Feb 16, 2022
171d745
Merge branch 'ign-gazebo6' into server-config-root-dom
mjcarroll Feb 16, 2022
7d33cf0
Fix linter, and added tests
Feb 16, 2022
7fedd8d
Merge branch 'server-config-root-dom' of github.com:ignitionrobotics/…
Feb 16, 2022
756e818
Merge branch 'ign-gazebo6' into use_sdf_plugin
Feb 28, 2022
087225e
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Feb 28, 2022
f2ad40b
Merge branch 'ign-gazebo6' into use_sdf_plugin
Mar 8, 2022
f27ec9c
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Mar 8, 2022
713f3ba
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 8, 2022
711761d
Update branch
Mar 9, 2022
1b48c9d
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Mar 9, 2022
7ac1b4e
Merged with server-config-root-dom
Mar 9, 2022
d60d34a
Tweaks
Mar 9, 2022
bb3d2a6
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 14, 2022
1469cd3
Merge branch 'server-config-root-dom' into use_sdf_plugin
Mar 14, 2022
ae00505
Updates to match garden forward port
Mar 14, 2022
f23935c
Updated documentation and minor cleanup
Mar 14, 2022
0402553
Merge branch 'ign-gazebo6' into server-config-root-dom
ahcorde Mar 15, 2022
146ecf9
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 15, 2022
71ee327
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 15, 2022
d0695a4
use sdf 12.4
Mar 16, 2022
977847e
Merge branch 'ign-gazebo6' into server-config-root-dom
nkoenig Mar 18, 2022
3af47f1
Merge branch 'ign-gazebo6' into server-config-root-dom
Mar 24, 2022
c6cd141
Merge branch 'server-config-root-dom' into use_sdf_plugin
Mar 24, 2022
e0d90ce
Merged from ign-gazebo6
Apr 4, 2022
aa28fec
Merge branch 'ign-gazebo6' into use_sdf_plugin
nkoenig Apr 7, 2022
3ae56ea
merged with ign-gazebo6
Apr 21, 2022
611e9aa
Merge branch 'use_sdf_plugin' of github.com:ignitionrobotics/ign-gaze…
Apr 21, 2022
a1b5953
Merge branch 'ign-gazebo6' into use_sdf_plugin
May 13, 2022
fd2b9b1
resolve some comments
May 13, 2022
61fcf05
Resolve issue #1363
May 13, 2022
15d31a9
Merge branch 'ign-gazebo6' into use_sdf_plugin
Jun 8, 2022
c3dbeb7
Remove components::VisualPlugins
Jun 8, 2022
cd39a3d
Merge branch 'ign-gazebo6' into use_sdf_plugin
nkoenig Jun 15, 2022
a78dc39
add system to entity
iche033 Jun 7, 2022
780a569
add integration test
iche033 Jun 7, 2022
b88aa15
remove debug msgs
iche033 Jun 7, 2022
ce0cbd1
doc
iche033 Jun 7, 2022
38beefc
doc
iche033 Jun 7, 2022
278579d
add test world
iche033 Jun 7, 2022
1e22d2c
use new LoadPlugin function
iche033 Jun 15, 2022
0ec7ad1
remove line
iche033 Jun 15, 2022
4695b88
check empty plugins, update issue url
iche033 Jun 15, 2022
8335ebd
keep node namespace
iche033 Jun 16, 2022
9dcbaf9
add button in component inspector for adding system to a model
iche033 Jun 22, 2022
da4f16a
model -> entity
iche033 Jun 23, 2022
6cbf8fb
merged from ign-gazebo6
chapulina Jun 23, 2022
0dba7aa
Merge branch 'ign-gazebo6' into entity_system_add_gui
chapulina Jun 23, 2022
d7503c5
add world
iche033 Jun 25, 2022
b247ce4
Merge branch 'ign-gazebo6' into entity_system_add_gui
iche033 Jun 25, 2022
0811e9c
Merge branch 'ign-gazebo6' into entity_system_add_gui
iche033 Jul 7, 2022
e4217d9
Merge branch 'ign-gazebo6' into entity_system_add_gui
chapulina Jul 28, 2022
e58ac69
Populate Add System dialog's filename list (#1581)
iche033 Jul 29, 2022
f14b79c
cppcheck
chapulina Jul 29, 2022
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
8 changes: 7 additions & 1 deletion include/ignition/gazebo/SystemLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef IGNITION_GAZEBO_SYSTEMLOADER_HH_
#define IGNITION_GAZEBO_SYSTEMLOADER_HH_

#include <list>
#include <memory>
#include <optional>
#include <string>
Expand Down Expand Up @@ -61,7 +62,8 @@ namespace ignition

/// \brief Load and instantiate system plugin from name/filename.
/// \param[in] _filename Shared library filename to load plugin from.
/// \param[in] _name Class name to be instantiated.
/// \param[in] _name Class name to be instantiated. If empty, the first
/// plugin in the shared library will be loaded.
/// \param[in] _sdf SDF Element describing plugin instance to be loaded.
/// \returns Shared pointer to system instance or nullptr.
/// \note This will be deprecated in Gazebo 7 (Garden), please the use
Expand All @@ -81,6 +83,10 @@ namespace ignition
/// \returns A pretty string
public: std::string PrettyStr() const;

/// \brief Get the plugin search paths used for loading system plugins
/// \return Paths to search for plugins
public: std::list<std::string> PluginPaths() const;

/// \brief Pointer to private data.
private: std::unique_ptr<SystemLoaderPrivate> dataPtr;
};
Expand Down
1 change: 1 addition & 0 deletions src/ServerConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ignition::gazebo::ServerConfig::PluginInfoPrivate

/// \brief XML elements associated with this plugin
public: sdf::ElementPtr sdf = nullptr;

};

//////////////////////////////////////////////////
Expand Down
43 changes: 32 additions & 11 deletions src/SystemLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class ignition::gazebo::SystemLoaderPrivate
public: explicit SystemLoaderPrivate() = default;

//////////////////////////////////////////////////
public: bool InstantiateSystemPlugin(const sdf::Plugin &_sdfPlugin,
ignition::plugin::PluginPtr &_gzPlugin)
public: std::list<std::string> PluginPaths() const
{
ignition::common::SystemPaths systemPaths;
systemPaths.SetPluginPathEnv(pluginPathEnv);
Expand All @@ -52,9 +51,24 @@ class ignition::gazebo::SystemLoaderPrivate

std::string homePath;
ignition::common::env(IGN_HOMEDIR, homePath);
systemPaths.AddPluginPaths(homePath + "/.ignition/gazebo/plugins");
systemPaths.AddPluginPaths(common::joinPaths(
homePath, ".ignition", "gazebo", "plugins"));
systemPaths.AddPluginPaths(IGN_GAZEBO_PLUGIN_INSTALL_DIR);

return systemPaths.PluginPaths();
}

//////////////////////////////////////////////////
public: bool InstantiateSystemPlugin(const sdf::Plugin &_sdfPlugin,
ignition::plugin::PluginPtr &_gzPlugin)
{
std::list<std::string> paths = this->PluginPaths();
common::SystemPaths systemPaths;
for (const auto &p : paths)
{
systemPaths.AddPluginPaths(p);
}

auto pathToLib = systemPaths.FindSharedLibrary(_sdfPlugin.Filename());
if (pathToLib.empty())
{
Expand Down Expand Up @@ -85,7 +99,11 @@ class ignition::gazebo::SystemLoaderPrivate
return false;
}

_gzPlugin = this->loader.Instantiate(_sdfPlugin.Name());
// use the first plugin name in the library if not specified
std::string pluginToInstantiate = _sdfPlugin.Name().empty() ?
pluginName : _sdfPlugin.Name();

_gzPlugin = this->loader.Instantiate(pluginToInstantiate);
if (!_gzPlugin)
{
ignerr << "Failed to load system plugin [" << _sdfPlugin.Name() <<
Expand Down Expand Up @@ -129,6 +147,12 @@ SystemLoader::SystemLoader()
//////////////////////////////////////////////////
SystemLoader::~SystemLoader() = default;

//////////////////////////////////////////////////
std::list<std::string> SystemLoader::PluginPaths() const
{
return this->dataPtr->PluginPaths();
}

//////////////////////////////////////////////////
void SystemLoader::AddSystemPluginPath(const std::string &_path)
{
Expand All @@ -141,11 +165,10 @@ std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(
const std::string &_name,
const sdf::ElementPtr &_sdf)
{
if (_filename == "" || _name == "")
if (_filename == "")
{
ignerr << "Failed to instantiate system plugin: empty argument "
"[(filename): " << _filename << "] " <<
"[(name): " << _name << "]." << std::endl;
"[(filename): " << _filename << "] " << std::endl;
return {};
}

Expand Down Expand Up @@ -175,18 +198,16 @@ std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(
{
ignition::plugin::PluginPtr plugin;

if (_plugin.Filename() == "" || _plugin.Name() == "")
if (_plugin.Filename() == "")
{
ignerr << "Failed to instantiate system plugin: empty argument "
"[(filename): " << _plugin.Filename() << "] " <<
"[(name): " << _plugin.Name() << "]." << std::endl;
"[(filename): " << _plugin.Filename() << "] " << std::endl;
return {};
}

auto ret = this->dataPtr->InstantiateSystemPlugin(_plugin, plugin);
if (ret && plugin)
return plugin;

return {};
}

Expand Down
36 changes: 36 additions & 0 deletions src/SystemLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ignition/gazebo/test_config.hh" // NOLINT(build/include)

using namespace ignition;
using namespace gazebo;

/////////////////////////////////////////////////
TEST(SystemLoader, Constructor)
Expand Down Expand Up @@ -67,3 +68,38 @@ TEST(SystemLoader, EmptyNames)
auto system = sm.LoadPlugin(plugin);
ASSERT_FALSE(system.has_value());
}

/////////////////////////////////////////////////
TEST(SystemLoader, PluginPaths)
{
SystemLoader sm;

// verify that there should exist some default paths
std::list<std::string> paths = sm.PluginPaths();
unsigned int pathCount = paths.size();
EXPECT_LT(0u, pathCount);

// Add test path and verify that the loader now contains this path
auto testBuildPath = common::joinPaths(
std::string(PROJECT_BINARY_PATH), "lib");
sm.AddSystemPluginPath(testBuildPath);
paths = sm.PluginPaths();

// Number of paths should increase by 1
EXPECT_EQ(pathCount + 1, paths.size());

// verify newly added paths exists
bool hasPath = false;
for (const auto &s : paths)
{
// the returned path string may not be exact match due to extra '/'
// appended at the end of the string. So use absPath to generate
// a path string that matches the format returned by joinPaths
if (common::absPath(s) == testBuildPath)
{
hasPath = true;
break;
}
}
EXPECT_TRUE(hasPath);
}
60 changes: 57 additions & 3 deletions src/SystemManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*
*/

#include <list>
#include <set>

#include <ignition/common/StringUtils.hh>

#include "ignition/gazebo/components/SystemPluginInfo.hh"
#include "ignition/gazebo/Conversions.hh"
#include "SystemManager.hh"
Expand All @@ -34,11 +39,15 @@ SystemManager::SystemManager(const SystemLoaderPtr &_systemLoader,
transport::NodeOptions opts;
opts.SetNameSpace(_namespace);
this->node = std::make_unique<transport::Node>(opts);
std::string entitySystemService{"entity/system/add"};
this->node->Advertise(entitySystemService,
std::string entitySystemAddService{"entity/system/add"};
this->node->Advertise(entitySystemAddService,
&SystemManager::EntitySystemAddService, this);
ignmsg << "Serving entity system service on ["
<< "/" << entitySystemService << "]" << std::endl;
<< "/" << entitySystemAddService << "]" << std::endl;

std::string entitySystemInfoService{"system/info"};
this->node->Advertise(entitySystemInfoService,
&SystemManager::EntitySystemInfoService, this);
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -215,6 +224,51 @@ bool SystemManager::EntitySystemAddService(const msgs::EntityPlugin_V &_req,
return true;
}

//////////////////////////////////////////////////
bool SystemManager::EntitySystemInfoService(const msgs::Empty &,
msgs::EntityPlugin_V &_res)
{
// loop through all files in paths and populate the list of
// plugin libraries.
std::list<std::string> paths = this->systemLoader->PluginPaths();
std::set<std::string> filenames;
for (const auto &p : paths)
{
if (common::exists(p))
{
for (common::DirIter file(p);
file != common::DirIter(); ++file)
{
std::string current(*file);
std::string filename = common::basename(current);
if (common::isFile(current) &&
(common::EndsWith(filename, ".so") ||
common::EndsWith(filename, ".dll") ||
common::EndsWith(filename, ".dylib")))
{
// remove extension and lib prefix
size_t extensionIndex = filename.rfind(".");
std::string nameWithoutExtension =
filename.substr(0, extensionIndex);
if (common::StartsWith(nameWithoutExtension, "lib"))
{
nameWithoutExtension = nameWithoutExtension.substr(3);
}
filenames.insert(nameWithoutExtension);
}
}
}
}

for (const auto &fn : filenames)
{
auto plugin = _res.add_plugins();
plugin->set_filename(fn);
}

return true;
}

//////////////////////////////////////////////////
void SystemManager::ProcessPendingEntitySystems()
{
Expand Down
8 changes: 8 additions & 0 deletions src/SystemManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ namespace ignition
private: bool EntitySystemAddService(const msgs::EntityPlugin_V &_req,
msgs::Boolean &_res);

/// \brief Callback for entity info system service.
/// \param[in] _req Empty request message
/// \param[out] _res Response containing a list of plugin names
/// and filenames
/// \return True if request received.
private: bool EntitySystemInfoService(const msgs::Empty &_req,
msgs::EntityPlugin_V &_res);

/// \brief All the systems.
private: std::vector<SystemInternal> systems;

Expand Down
Loading