Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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: 8 additions & 0 deletions src/SimulationRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ SimulationRunner::SimulationRunner(const sdf::World &_world,

this->node = std::make_unique<transport::Node>(opts);

std::vector<transport::MessagePublisher> pubs;
std::vector<transport::MessagePublisher> subs;
this->node->TopicInfo("/world/" + this->worldName + "/stats", pubs, subs);
if (!pubs.empty())
{
gzerr << "Another world of the same name is running" << std::endl;
}

// Create the system manager
this->systemMgr = std::make_unique<SystemManager>(
_systemLoader, &this->entityCompMgr, &this->eventMgr, validNs,
Expand Down
17 changes: 17 additions & 0 deletions src/gui/QuickStartHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,27 @@
#include "QuickStartHandler.hh"

#include "gz/sim/InstallationDirectories.hh"
#include <gz/transport/Node.hh>
#include <gz/common/Console.hh>

using namespace gz;
using namespace sim::gui;

QuickStartHandler::QuickStartHandler()
{
// Create the node if needed
this->node = std::make_unique<gz::transport::Node>();

std::vector<transport::MessagePublisher> publishers;
std::vector<transport::MessagePublisher> subscribers;
this->node->TopicInfo("/stats", publishers, subscribers);
if (!publishers.empty())
{
gzwarn << "Detected an already running world on start" << std::endl;
return;
}
}

/////////////////////////////////////////////////
QString QuickStartHandler::WorldsPath() const
{
Expand Down
12 changes: 12 additions & 0 deletions src/gui/QuickStartHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include "gz/sim/config.hh"
#include "gz/sim/gui/Export.hh"

#include <gz/transport/Node.hh>
#include <gz/common/Console.hh>

#include <memory>
#include <vector>

namespace gz
{
namespace sim
Expand All @@ -36,6 +42,9 @@ class GZ_SIM_GUI_VISIBLE QuickStartHandler : public QObject
{
Q_OBJECT

// Explicitly declare the constructor
public: QuickStartHandler();

/// \brief Get worlds path
/// \return worlds directory path
public: Q_INVOKABLE QString WorldsPath() const;
Expand Down Expand Up @@ -69,6 +78,9 @@ class GZ_SIM_GUI_VISIBLE QuickStartHandler : public QObject

/// \brief Get starting world url.
private: std::string startingWorld{""};

// Add a member for the transport node
private: std::unique_ptr<gz::transport::Node> node;
};
}
}
Expand Down
Loading