...
 
Commits (2)
...@@ -41,6 +41,7 @@ const char *variantNamesKey = "VariantNames"; ...@@ -41,6 +41,7 @@ const char *variantNamesKey = "VariantNames";
const char *generatorArrayKey = "GeneratorArray"; const char *generatorArrayKey = "GeneratorArray";
const char *variantArrayKey = "VariantArray"; const char *variantArrayKey = "VariantArray";
const char *generatorIndexKey = "GeneratorIndex"; const char *generatorIndexKey = "GeneratorIndex";
const char *connectionsStringKey = "ConnectionString";
} // namespace } // namespace
MeasurementComplexItem::MeasurementComplexItem( MeasurementComplexItem::MeasurementComplexItem(
...@@ -55,7 +56,8 @@ MeasurementComplexItem::MeasurementComplexItem( ...@@ -55,7 +56,8 @@ MeasurementComplexItem::MeasurementComplexItem(
_variantIndex(settingsGroup, _metaDataMap[variantIndexKey]), _variantIndex(settingsGroup, _metaDataMap[variantIndexKey]),
_pAreaData(new AreaData(this)), _pEditorData(new AreaData(this)), _pAreaData(new AreaData(this)), _pEditorData(new AreaData(this)),
_pCurrentData(_pAreaData), _holdProgress(false), _pGenerator(nullptr), _pCurrentData(_pAreaData), _holdProgress(false), _pGenerator(nullptr),
_pWorker(new RoutingThread(this)) { _pWorker(new RoutingThread(this)),
_nemoCString(settingsGroup, _metaDataMap[connectionsStringKey]) {
// Setup altitude. // Setup altitude.
_altitude.setRawValue(qgcApp() _altitude.setRawValue(qgcApp()
...@@ -91,17 +93,17 @@ MeasurementComplexItem::MeasurementComplexItem( ...@@ -91,17 +93,17 @@ MeasurementComplexItem::MeasurementComplexItem(
&MeasurementComplexItem::_storeRoutingData); &MeasurementComplexItem::_storeRoutingData);
// Connect coordinate and exitCoordinate. // Connect coordinate and exitCoordinate.
connect(this, &MeasurementComplexItem::routeChanged, connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->coordinateChanged(this->coordinate()); }); [this] { emit this->coordinateChanged(this->coordinate()); });
connect(this, &MeasurementComplexItem::routeChanged, connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->exitCoordinateChanged(this->exitCoordinate()); }); [this] { emit this->exitCoordinateChanged(this->exitCoordinate()); });
connect(this, &MeasurementComplexItem::routeChanged, [this] { connect(this, &MeasurementComplexItem::routeChanged, this, [this] {
emit this->exitCoordinateSameAsEntryChanged( emit this->exitCoordinateSameAsEntryChanged(
this->exitCoordinateSameAsEntry()); this->exitCoordinateSameAsEntry());
}); });
// Connect isIncomplete. // Connect isIncomplete.
connect(this, &MeasurementComplexItem::idleChanged, [this] { connect(this, &MeasurementComplexItem::idleChanged, this, [this] {
if (this->idle()) { if (this->idle()) {
if (this->route().size() > 0 && this->_isIncomplete == true) { if (this->route().size() > 0 && this->_isIncomplete == true) {
this->_isIncomplete = false; this->_isIncomplete = false;
...@@ -124,14 +126,14 @@ MeasurementComplexItem::MeasurementComplexItem( ...@@ -124,14 +126,14 @@ MeasurementComplexItem::MeasurementComplexItem(
&MeasurementComplexItem::_updateFlightpathSegments); &MeasurementComplexItem::_updateFlightpathSegments);
// Connect complexDistance. // Connect complexDistance.
connect(this, &MeasurementComplexItem::routeChanged, connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->complexDistanceChanged(); }); [this] { emit this->complexDistanceChanged(); });
resetGenerators(); resetGenerators();
startEditing(); startEditing();
// connect to nemo interface // connect to nemo interface
connect(pNemoInterface, &NemoInterface::progressChanged, this, connect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress); &MeasurementComplexItem::_onNewProgress);
} }
...@@ -773,6 +775,17 @@ void MeasurementComplexItem::_onAltitudeChanged() { ...@@ -773,6 +775,17 @@ void MeasurementComplexItem::_onAltitudeChanged() {
} }
} }
QString MeasurementComplexItem::nemoError() const { return _nemoError; }
void MeasurementComplexItem::_setNemoError(const QString &nemoError) {
if (_nemoError != nemoError) {
_nemoError = nemoError;
emit nemoErrorChanged();
}
}
Fact *MeasurementComplexItem::nemoCString() { return &_nemoCString; }
bool MeasurementComplexItem::holdProgress() const { return _holdProgress; } bool MeasurementComplexItem::holdProgress() const { return _holdProgress; }
void MeasurementComplexItem::setHoldProgress(bool holdProgress) { void MeasurementComplexItem::setHoldProgress(bool holdProgress) {
...@@ -781,10 +794,10 @@ void MeasurementComplexItem::setHoldProgress(bool holdProgress) { ...@@ -781,10 +794,10 @@ void MeasurementComplexItem::setHoldProgress(bool holdProgress) {
emit holdProgressChanged(); emit holdProgressChanged();
if (_holdProgress) { if (_holdProgress) {
disconnect(pNemoInterface, &NemoInterface::progressChanged, this, disconnect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress); &MeasurementComplexItem::_onNewProgress);
} else { } else {
connect(pNemoInterface, &NemoInterface::progressChanged, this, connect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress); &MeasurementComplexItem::_onNewProgress);
_onNewProgress(pNemoInterface->getProgress()); _onNewProgress(pNemoInterface->getProgress());
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
class RoutingThread; class RoutingThread;
class RoutingResult; class RoutingResult;
class Nemointerface;
namespace routing { namespace routing {
class GeneratorBase; class GeneratorBase;
...@@ -51,6 +52,8 @@ public: ...@@ -51,6 +52,8 @@ public:
Q_PROPERTY(int generatorIndex READ generatorIndex NOTIFY generatorChanged) Q_PROPERTY(int generatorIndex READ generatorIndex NOTIFY generatorChanged)
Q_PROPERTY(AreaData *areaData READ areaData NOTIFY areaDataChanged) Q_PROPERTY(AreaData *areaData READ areaData NOTIFY areaDataChanged)
Q_PROPERTY(QVariantList route READ route NOTIFY routeChanged) Q_PROPERTY(QVariantList route READ route NOTIFY routeChanged)
Q_PROPERTY(QString nemoError READ nemoError NOTIFY nemoErrorChanged)
Q_PROPERTY(Fact *nemoCString READ nemoCString CONSTANT)
Q_INVOKABLE void reverseRoute(void); Q_INVOKABLE void reverseRoute(void);
...@@ -224,6 +227,10 @@ public: ...@@ -224,6 +227,10 @@ public:
bool holdProgress() const; bool holdProgress() const;
void setHoldProgress(bool holdProgress); void setHoldProgress(bool holdProgress);
QString nemoError() const;
Fact *nemoCString();
signals: signals:
void variantNamesChanged(); void variantNamesChanged();
...@@ -238,6 +245,8 @@ signals: ...@@ -238,6 +245,8 @@ signals:
void routeChanged(); void routeChanged();
void holdProgressChanged(); void holdProgressChanged();
void nemoErrorChanged();
private slots: private slots:
// Worker functions. // Worker functions.
...@@ -257,6 +266,7 @@ private: ...@@ -257,6 +266,7 @@ private:
static bool _idle(STATE state); static bool _idle(STATE state);
void _updateFlightpathSegments(); void _updateFlightpathSegments();
void _onAltitudeChanged(); void _onAltitudeChanged();
void _setNemoError(const QString &nemoError);
// Hirarcical stuff. // Hirarcical stuff.
int _sequenceNumber; int _sequenceNumber;
...@@ -285,4 +295,9 @@ private: ...@@ -285,4 +295,9 @@ private:
QVector<Variant> _variantVector; QVector<Variant> _variantVector;
Variant _route; Variant _route;
PtrWorker _pWorker; PtrWorker _pWorker;
// NemoInterface
std::shared_ptr<Nemointerface> _pNemointerface;
QString _nemoError;
SettingsFact _nemoCString;
}; };
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QQmlEngine>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
...@@ -52,7 +53,7 @@ ...@@ -52,7 +53,7 @@
Q_DECLARE_METATYPE(ProgressArray) Q_DECLARE_METATYPE(ProgressArray)
QGC_LOGGING_CATEGORY(NemoInterfaceLog, "NemoInterfaceLog") QGC_LOGGING_CATEGORY(NemointerfaceLog, "NemointerfaceLog")
#define NO_HEARTBEAT_TIMEOUT 5000 // ms #define NO_HEARTBEAT_TIMEOUT 5000 // ms
#define RESTART_INTERVAl 600000 // ms == 10 min #define RESTART_INTERVAl 600000 // ms == 10 min
...@@ -98,7 +99,7 @@ typedef ros_bridge::messages::nemo_msgs::heartbeat::Heartbeat Heartbeat; ...@@ -98,7 +99,7 @@ typedef ros_bridge::messages::nemo_msgs::heartbeat::Heartbeat Heartbeat;
typedef nemo_interface::TaskDispatcher Dispatcher; typedef nemo_interface::TaskDispatcher Dispatcher;
typedef std::unique_lock<std::mutex> Lock; typedef std::unique_lock<std::mutex> Lock;
class NemoInterface::Impl { class Nemointerface::Impl {
enum class STATE { enum class STATE {
STOPPED, STOPPED,
START_BRIDGE, START_BRIDGE,
...@@ -113,7 +114,7 @@ class NemoInterface::Impl { ...@@ -113,7 +114,7 @@ class NemoInterface::Impl {
}; };
public: public:
Impl(NemoInterface *p); Impl(const QString &connectionString, Nemointerface *p);
~Impl(); ~Impl();
void start(); void start();
...@@ -136,12 +137,13 @@ public: ...@@ -136,12 +137,13 @@ public:
ProgressArray getProgress() const; ProgressArray getProgress() const;
ProgressArray getProgress(const IDArray &idArray) const; ProgressArray getProgress(const IDArray &idArray) const;
NemoInterface::STATUS status() const; Nemointerface::STATUS status() const;
bool running() const; // thread safe bool running() const; // thread safe
bool ready() const; // thread safe bool ready() const; // thread safe
const QString &infoString() const; const QString &infoString() const;
const QString &warningString() const; const QString &warningString() const;
const QString &connectionString() const;
private: private:
void _doSetup(); void _doSetup();
...@@ -167,9 +169,9 @@ private: ...@@ -167,9 +169,9 @@ private:
static bool _userSyncNotSafe(STATE s); static bool _userSyncNotSafe(STATE s);
static bool _sysSyncNotSafe(STATE s); static bool _sysSyncNotSafe(STATE s);
static bool _runningNotSafe(STATE s); static bool _runningNotSafe(STATE s);
static NemoInterface::STATUS _status(STATE state); static Nemointerface::STATUS _status(STATE state);
static QString _toString(STATE s); static QString _toString(STATE s);
static QString _toString(NemoInterface::STATUS s); static QString _toString(Nemointerface::STATUS s);
// impl functions // impl functions
bool _addTilesImpl( bool _addTilesImpl(
...@@ -201,10 +203,11 @@ private: ...@@ -201,10 +203,11 @@ private:
// static and const members // static and const members
static const char *_localVersion; static const char *_localVersion;
NemoInterface *const _parent; Nemointerface *const _parent;
const QString _connectionString;
// thread safe members // thread safe members
ROSBridgePtr _pRosbridge; Rosbridge _rosbridge;
Dispatcher _dispatcher; Dispatcher _dispatcher;
// protected by mutex // protected by mutex
...@@ -221,51 +224,33 @@ private: ...@@ -221,51 +224,33 @@ private:
QTimer _restartTimer; QTimer _restartTimer;
}; };
const char *NemoInterface::Impl::_localVersion("V_1.0"); const char *Nemointerface::Impl::_localVersion("V_1.0");
using StatusMap = std::map<NemoInterface::STATUS, QString>; using StatusMap = std::map<Nemointerface::STATUS, QString>;
static StatusMap statusMap{ static StatusMap statusMap{
std::make_pair<NemoInterface::STATUS, QString>( std::make_pair<Nemointerface::STATUS, QString>(
NemoInterface::STATUS::NOT_CONNECTED, "Not Connected"), Nemointerface::STATUS::NOT_CONNECTED, "Not Connected"),
std::make_pair<NemoInterface::STATUS, QString>(NemoInterface::STATUS::ERROR, std::make_pair<Nemointerface::STATUS, QString>(Nemointerface::STATUS::ERROR,
"ERROR"), "ERROR"),
std::make_pair<NemoInterface::STATUS, QString>(NemoInterface::STATUS::SYNC, std::make_pair<Nemointerface::STATUS, QString>(Nemointerface::STATUS::SYNC,
"Synchronizing"), "Synchronizing"),
std::make_pair<NemoInterface::STATUS, QString>(NemoInterface::STATUS::READY, std::make_pair<Nemointerface::STATUS, QString>(Nemointerface::STATUS::READY,
"Ready"), "Ready"),
std::make_pair<NemoInterface::STATUS, QString>( std::make_pair<Nemointerface::STATUS, QString>(
NemoInterface::STATUS::TIMEOUT, "Timeout"), Nemointerface::STATUS::TIMEOUT, "Timeout"),
std::make_pair<NemoInterface::STATUS, QString>( std::make_pair<Nemointerface::STATUS, QString>(
NemoInterface::STATUS::WEBSOCKET_DETECTED, "Websocket Detected")}; Nemointerface::STATUS::WEBSOCKET_DETECTED, "Websocket Detected")};
NemoInterface::Impl::Impl(NemoInterface *p)
: _parent(p), _state(STATE::STOPPED) {
// ROS Bridge.
WimaSettings *wimaSettings =
qgcApp()->toolbox()->settingsManager()->wimaSettings();
auto connectionStringFact = wimaSettings->rosbridgeConnectionString();
auto setConnectionString = [connectionStringFact, this] {
auto connectionString = connectionStringFact->rawValue().toString();
bool wasRunning = this->running();
this->stop();
this->_pRosbridge = std::make_shared<Rosbridge>(
QUrl(QString("ws://") + connectionString.toLocal8Bit().data()));
if (wasRunning) {
this->start();
}
};
connect(connectionStringFact, &SettingsFact::rawValueChanged, Nemointerface::Impl::Impl(const QString &connectionString, Nemointerface *p)
setConnectionString); : _parent(p), _connectionString(connectionString),
setConnectionString(); _rosbridge(QUrl(QString("ws://") + connectionString)),
_state(STATE::STOPPED) {
// Heartbeat timeout. // Heartbeat timeout.
connect(&this->_timeoutTimer, &QTimer::timeout, connect(&this->_timeoutTimer, &QTimer::timeout,
std::bind(&Impl::_onHeartbeatTimeout, this)); std::bind(&Impl::_onHeartbeatTimeout, this));
connect(this->_pRosbridge.get(), &Rosbridge::stateChanged, this->_parent, connect(&this->_rosbridge, &Rosbridge::stateChanged, this->_parent,
[this] { this->_onRosbridgeStateChanged(); }); [this] { this->_onRosbridgeStateChanged(); });
connect(&this->_restartTimer, &QTimer::timeout, this->_parent, connect(&this->_restartTimer, &QTimer::timeout, this->_parent,
...@@ -278,9 +263,9 @@ NemoInterface::Impl::Impl(NemoInterface *p) ...@@ -278,9 +263,9 @@ NemoInterface::Impl::Impl(NemoInterface *p)
std::call_once(flag, [] { qRegisterMetaType<ProgressArray>(); }); std::call_once(flag, [] { qRegisterMetaType<ProgressArray>(); });
} }
NemoInterface::Impl::~Impl() { this->_pRosbridge->stop(); } Nemointerface::Impl::~Impl() { this->_rosbridge.stop(); }
void NemoInterface::Impl::start() { void Nemointerface::Impl::start() {
Lock lk(this->_m); Lock lk(this->_m);
if (!_runningNotSafe(this->_state)) { if (!_runningNotSafe(this->_state)) {
this->_setStateNotSafe(STATE::START_BRIDGE); this->_setStateNotSafe(STATE::START_BRIDGE);
...@@ -288,7 +273,7 @@ void NemoInterface::Impl::start() { ...@@ -288,7 +273,7 @@ void NemoInterface::Impl::start() {
} }
} }
void NemoInterface::Impl::stop() { void Nemointerface::Impl::stop() {
Lock lk(this->_m); Lock lk(this->_m);
if (_runningNotSafe(this->_state)) { if (_runningNotSafe(this->_state)) {
this->_setStateNotSafe(STATE::STOPPED); this->_setStateNotSafe(STATE::STOPPED);
...@@ -297,7 +282,7 @@ void NemoInterface::Impl::stop() { ...@@ -297,7 +282,7 @@ void NemoInterface::Impl::stop() {
} }
std::shared_future<QVariant> std::shared_future<QVariant>
NemoInterface::Impl::addTiles(const TilePtrArray &tileArray) { Nemointerface::Impl::addTiles(const TilePtrArray &tileArray) {
using namespace nemo_interface; using namespace nemo_interface;
// qDebug() << "addTiles called"; // qDebug() << "addTiles called";
...@@ -320,7 +305,7 @@ NemoInterface::Impl::addTiles(const TilePtrArray &tileArray) { ...@@ -320,7 +305,7 @@ NemoInterface::Impl::addTiles(const TilePtrArray &tileArray) {
pTileArray->push_back(pTileCopy); pTileArray->push_back(pTileCopy);
pIdArray->push_back(id); pIdArray->push_back(id);
} else { } else {
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "addTiles(): tile with id: " << pTile->id() << "already added."; << "addTiles(): tile with id: " << pTile->id() << "already added.";
} }
} }
...@@ -364,7 +349,7 @@ NemoInterface::Impl::addTiles(const TilePtrArray &tileArray) { ...@@ -364,7 +349,7 @@ NemoInterface::Impl::addTiles(const TilePtrArray &tileArray) {
} }
std::shared_future<QVariant> std::shared_future<QVariant>
NemoInterface::Impl::removeTiles(const IDArray &idArray) { Nemointerface::Impl::removeTiles(const IDArray &idArray) {
using namespace nemo_interface; using namespace nemo_interface;
// qDebug() << "removeTiles called"; // qDebug() << "removeTiles called";
...@@ -382,7 +367,7 @@ NemoInterface::Impl::removeTiles(const IDArray &idArray) { ...@@ -382,7 +367,7 @@ NemoInterface::Impl::removeTiles(const IDArray &idArray) {
_localTiles.erase(it); _localTiles.erase(it);
pIdArray->push_back(id); pIdArray->push_back(id);
} else { } else {
qCDebug(NemoInterfaceLog) << "removeTiles(): unknown id: " << id << "."; qCDebug(NemointerfaceLog) << "removeTiles(): unknown id: " << id << ".";
} }
} }
if (pIdArray->size() > 0) { if (pIdArray->size() > 0) {
...@@ -426,7 +411,7 @@ NemoInterface::Impl::removeTiles(const IDArray &idArray) { ...@@ -426,7 +411,7 @@ NemoInterface::Impl::removeTiles(const IDArray &idArray) {
return p.get_future(); return p.get_future();
} }
std::shared_future<QVariant> NemoInterface::Impl::clearTiles() { std::shared_future<QVariant> Nemointerface::Impl::clearTiles() {
using namespace nemo_interface; using namespace nemo_interface;
// qDebug() << "clearTiles called"; // qDebug() << "clearTiles called";
...@@ -472,7 +457,7 @@ std::shared_future<QVariant> NemoInterface::Impl::clearTiles() { ...@@ -472,7 +457,7 @@ std::shared_future<QVariant> NemoInterface::Impl::clearTiles() {
} }
} }
TileArray NemoInterface::Impl::getTiles(const IDArray &idArray) const { TileArray Nemointerface::Impl::getTiles(const IDArray &idArray) const {
TileArray tileArray; TileArray tileArray;
Lock lk(this->_m); Lock lk(this->_m);
...@@ -503,7 +488,7 @@ TileArray NemoInterface::Impl::getTiles(const IDArray &idArray) const { ...@@ -503,7 +488,7 @@ TileArray NemoInterface::Impl::getTiles(const IDArray &idArray) const {
return tileArray; return tileArray;
} }
TileArray NemoInterface::Impl::getAllTiles() const { TileArray Nemointerface::Impl::getAllTiles() const {
TileArray tileArray; TileArray tileArray;
Lock lk(this->_m); Lock lk(this->_m);
...@@ -531,7 +516,7 @@ TileArray NemoInterface::Impl::getAllTiles() const { ...@@ -531,7 +516,7 @@ TileArray NemoInterface::Impl::getAllTiles() const {
return tileArray; return tileArray;
} }
LogicalArray NemoInterface::Impl::containsTiles(const IDArray &idArray) const { LogicalArray Nemointerface::Impl::containsTiles(const IDArray &idArray) const {
LogicalArray logicalArray; LogicalArray logicalArray;
Lock lk(this->_m); Lock lk(this->_m);
...@@ -543,18 +528,18 @@ LogicalArray NemoInterface::Impl::containsTiles(const IDArray &idArray) const { ...@@ -543,18 +528,18 @@ LogicalArray NemoInterface::Impl::containsTiles(const IDArray &idArray) const {
return logicalArray; return logicalArray;
} }
std::size_t NemoInterface::Impl::size() const { std::size_t Nemointerface::Impl::size() const {
Lock lk(this->_m); Lock lk(this->_m);
return _localTiles.size(); return _localTiles.size();
} }
bool NemoInterface::Impl::empty() const { bool Nemointerface::Impl::empty() const {
Lock lk(this->_m); Lock lk(this->_m);
return _localTiles.empty(); return _localTiles.empty();
} }
ProgressArray NemoInterface::Impl::getProgress() const { ProgressArray Nemointerface::Impl::getProgress() const {
ProgressArray progressArray; ProgressArray progressArray;
Lock lk(this->_m); Lock lk(this->_m);
...@@ -573,7 +558,7 @@ ProgressArray NemoInterface::Impl::getProgress() const { ...@@ -573,7 +558,7 @@ ProgressArray NemoInterface::Impl::getProgress() const {
return progressArray; return progressArray;
} }
ProgressArray NemoInterface::Impl::getProgress(const IDArray &idArray) const { ProgressArray Nemointerface::Impl::getProgress(const IDArray &idArray) const {
ProgressArray progressArray; ProgressArray progressArray;
Lock lk(this->_m); Lock lk(this->_m);
...@@ -598,34 +583,34 @@ ProgressArray NemoInterface::Impl::getProgress(const IDArray &idArray) const { ...@@ -598,34 +583,34 @@ ProgressArray NemoInterface::Impl::getProgress(const IDArray &idArray) const {
return progressArray; return progressArray;
} }
NemoInterface::STATUS NemoInterface::Impl::status() const { Nemointerface::STATUS Nemointerface::Impl::status() const {
Lock lk(this->_m); Lock lk(this->_m);
return _status(this->_state); return _status(this->_state);
} }
bool NemoInterface::Impl::running() const { bool Nemointerface::Impl::running() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _runningNotSafe(this->_state); return _runningNotSafe(this->_state);
} }
bool NemoInterface::Impl::ready() const { bool Nemointerface::Impl::ready() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _readyNotSafe(this->_state); return _readyNotSafe(this->_state);
} }
bool NemoInterface::Impl::_sysSync() const { bool Nemointerface::Impl::_sysSync() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _sysSyncNotSafe(this->_state); return _sysSyncNotSafe(this->_state);
} }
void NemoInterface::Impl::_onHeartbeatTimeout() { void Nemointerface::Impl::_onHeartbeatTimeout() {
Lock lk1(this->_m); Lock lk1(this->_m);
this->_setStateNotSafe(STATE::HEARTBEAT_TIMEOUT); this->_setStateNotSafe(STATE::HEARTBEAT_TIMEOUT);
this->_doActionNotSafe(); this->_doActionNotSafe();
} }
void NemoInterface::Impl::_onRosbridgeStateChanged() { void Nemointerface::Impl::_onRosbridgeStateChanged() {
auto rbState = this->_pRosbridge->state(); auto rbState = this->_rosbridge.state();
if (rbState == Rosbridge::STATE::CONNECTED) { if (rbState == Rosbridge::STATE::CONNECTED) {
Lock lk1(this->_m); Lock lk1(this->_m);
if (this->_state == STATE::START_BRIDGE || if (this->_state == STATE::START_BRIDGE ||
...@@ -644,22 +629,26 @@ void NemoInterface::Impl::_onRosbridgeStateChanged() { ...@@ -644,22 +629,26 @@ void NemoInterface::Impl::_onRosbridgeStateChanged() {
} }
} }
bool NemoInterface::Impl::_userSync() const { bool Nemointerface::Impl::_userSync() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _userSyncNotSafe(this->_state); return _userSyncNotSafe(this->_state);
} }
const QString &NemoInterface::Impl::infoString() const { const QString &Nemointerface::Impl::infoString() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _infoString; return _infoString;
} }
const QString &NemoInterface::Impl::warningString() const { const QString &Nemointerface::Impl::warningString() const {
Lock lk1(this->_m); Lock lk1(this->_m);
return _warningString; return _warningString;
} }
bool NemoInterface::Impl::_updateProgress(const ProgressArray &pArray) { const QString &Nemointerface::Impl::connectionString() const {
return this->_connectionString;
}
bool Nemointerface::Impl::_updateProgress(const ProgressArray &pArray) {
ProgressArray copy; ProgressArray copy;
bool error = false; bool error = false;
...@@ -673,7 +662,7 @@ bool NemoInterface::Impl::_updateProgress(const ProgressArray &pArray) { ...@@ -673,7 +662,7 @@ bool NemoInterface::Impl::_updateProgress(const ProgressArray &pArray) {
it->second->setProgress(itLP->progress()); it->second->setProgress(itLP->progress());
copy.push_back(*itLP); copy.push_back(*itLP);
} else { } else {
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "_updateProgress(): tile with id " << itLP->id() << " not found."; << "_updateProgress(): tile with id " << itLP->id() << " not found.";
error = true; error = true;
} }
...@@ -687,7 +676,7 @@ bool NemoInterface::Impl::_updateProgress(const ProgressArray &pArray) { ...@@ -687,7 +676,7 @@ bool NemoInterface::Impl::_updateProgress(const ProgressArray &pArray) {
return !error; return !error;
} }
void NemoInterface::Impl::_onHeartbeatReceived(const QNemoHeartbeat &) { void Nemointerface::Impl::_onHeartbeatReceived(const QNemoHeartbeat &) {
INVM(this->_parent, INVM(this->_parent,
([this]() mutable { this->_timeoutTimer.start(NO_HEARTBEAT_TIMEOUT); })) ([this]() mutable { this->_timeoutTimer.start(NO_HEARTBEAT_TIMEOUT); }))
...@@ -699,7 +688,7 @@ void NemoInterface::Impl::_onHeartbeatReceived(const QNemoHeartbeat &) { ...@@ -699,7 +688,7 @@ void NemoInterface::Impl::_onHeartbeatReceived(const QNemoHeartbeat &) {
} }
} }
void NemoInterface::Impl::_setInfoStringNotSafe(const QString &info) { void Nemointerface::Impl::_setInfoStringNotSafe(const QString &info) {
if (_infoString != info) { if (_infoString != info) {
_infoString = info; _infoString = info;
...@@ -709,7 +698,7 @@ void NemoInterface::Impl::_setInfoStringNotSafe(const QString &info) { ...@@ -709,7 +698,7 @@ void NemoInterface::Impl::_setInfoStringNotSafe(const QString &info) {
} }
} }
void NemoInterface::Impl::_setWarningStringNotSafe(const QString &warning) { void Nemointerface::Impl::_setWarningStringNotSafe(const QString &warning) {
if (_warningString != warning) { if (_warningString != warning) {
_warningString = warning; _warningString = warning;
...@@ -719,20 +708,20 @@ void NemoInterface::Impl::_setWarningStringNotSafe(const QString &warning) { ...@@ -719,20 +708,20 @@ void NemoInterface::Impl::_setWarningStringNotSafe(const QString &warning) {
} }
} }
void NemoInterface::Impl::_setInfoString(const QString &info) { void Nemointerface::Impl::_setInfoString(const QString &info) {
Lock lk(this->_m); Lock lk(this->_m);
_setInfoStringNotSafe(info); _setInfoStringNotSafe(info);
} }
void NemoInterface::Impl::_setWarningString(const QString &warning) { void Nemointerface::Impl::_setWarningString(const QString &warning) {
Lock lk(this->_m); Lock lk(this->_m);
_setWarningStringNotSafe(warning); _setWarningStringNotSafe(warning);
} }
void NemoInterface::Impl::_doSetup() { void Nemointerface::Impl::_doSetup() {
// create task // create task
auto pTask = std::make_unique<nemo_interface::Task>([this] { auto pTask = std::make_unique<nemo_interface::Task>([this] {
auto rb = this->_pRosbridge; auto &rb = this->_rosbridge;
auto &disp = this->_dispatcher; auto &disp = this->_dispatcher;
// check if required services are available // check if required services are available
...@@ -742,7 +731,7 @@ void NemoInterface::Impl::_doSetup() { ...@@ -742,7 +731,7 @@ void NemoInterface::Impl::_doSetup() {
this->_setInfoString("Waiting for required service " + s); this->_setInfoString("Waiting for required service " + s);
auto available = rb->waitForService(cc, cond); auto available = rb.waitForService(cc, cond);
if (!available) { if (!available) {
return QVariant(false); return QVariant(false);
} }
...@@ -750,7 +739,7 @@ void NemoInterface::Impl::_doSetup() { ...@@ -750,7 +739,7 @@ void NemoInterface::Impl::_doSetup() {
// check if version is compatible{ // check if version is compatible{
this->_setInfoString("Checking version."); this->_setInfoString("Checking version.");
auto version = _callGetVersion(disp, *rb); auto version = _callGetVersion(disp, rb);
if (version != _localVersion) { if (version != _localVersion) {
this->_setWarningString( this->_setWarningString(
"Version checking failed. Local protocol version (" + "Version checking failed. Local protocol version (" +
...@@ -763,14 +752,14 @@ void NemoInterface::Impl::_doSetup() { ...@@ -763,14 +752,14 @@ void NemoInterface::Impl::_doSetup() {
for (const auto &cc : requiredTopics) { for (const auto &cc : requiredTopics) {
QString s(cc); QString s(cc);
this->_setInfoString("Waiting for required topic " + s); this->_setInfoString("Waiting for required topic " + s);
auto available = rb->waitForTopic(cc, cond); auto available = rb.waitForTopic(cc, cond);
if (!available) { if (!available) {
return QVariant(false); return QVariant(false);
} }
} }
// subscribe topics // subscribe topics
rb->subscribeTopic(progressTopic, [this](const QJsonObject &o) { rb.subscribeTopic(progressTopic, [this](const QJsonObject &o) {
ros_bridge::messages::nemo_msgs::progress_array::ProgressArray ros_bridge::messages::nemo_msgs::progress_array::ProgressArray
progressArray; progressArray;
if (ros_bridge::messages::nemo_msgs::progress_array::fromJson( if (ros_bridge::messages::nemo_msgs::progress_array::fromJson(
...@@ -789,7 +778,7 @@ void NemoInterface::Impl::_doSetup() { ...@@ -789,7 +778,7 @@ void NemoInterface::Impl::_doSetup() {
} }
if (rangeError) { if (rangeError) {
qCWarning(NemoInterfaceLog) << progressTopic qCWarning(NemointerfaceLog) << progressTopic
<< " progress out " << " progress out "
"of range, value was set to: " "of range, value was set to: "
<< lp.progress(); << lp.progress();
...@@ -799,7 +788,7 @@ void NemoInterface::Impl::_doSetup() { ...@@ -799,7 +788,7 @@ void NemoInterface::Impl::_doSetup() {
if (!ret) if (!ret)
this->_setWarningString("Progress update failed."); this->_setWarningString("Progress update failed.");
} else { } else {
qCWarning(NemoInterfaceLog) << progressTopic qCWarning(NemointerfaceLog) << progressTopic
<< " not able to " << " not able to "
"create ProgressArray form json: " "create ProgressArray form json: "
<< o; << o;
...@@ -807,12 +796,12 @@ void NemoInterface::Impl::_doSetup() { ...@@ -807,12 +796,12 @@ void NemoInterface::Impl::_doSetup() {
}); });
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
rb->subscribeTopic(heartbeatTopic, [this](const QJsonObject &o) { rb.subscribeTopic(heartbeatTopic, [this](const QJsonObject &o) {
nemo_msgs::heartbeat::Heartbeat heartbeat; nemo_msgs::heartbeat::Heartbeat heartbeat;
if (nemo_msgs::heartbeat::fromJson(o, heartbeat)) { if (nemo_msgs::heartbeat::fromJson(o, heartbeat)) {
this->_onHeartbeatReceived(heartbeat); this->_onHeartbeatReceived(heartbeat);
} else { } else {
qCWarning(NemoInterfaceLog) << heartbeatTopic qCWarning(NemointerfaceLog) << heartbeatTopic
<< " not able to " << " not able to "
"create Heartbeat form json: " "create Heartbeat form json: "
<< o; << o;
...@@ -832,7 +821,7 @@ void NemoInterface::Impl::_doSetup() { ...@@ -832,7 +821,7 @@ void NemoInterface::Impl::_doSetup() {
Q_UNUSED(f); Q_UNUSED(f);
} }
void NemoInterface::Impl::_synchronize() { void Nemointerface::Impl::_synchronize() {
Lock lk(this->_m); Lock lk(this->_m);
if (this->_state == STATE::READY || this->_state == STATE::SYNC_ERROR) { if (this->_state == STATE::READY || this->_state == STATE::SYNC_ERROR) {
...@@ -848,11 +837,11 @@ void NemoInterface::Impl::_synchronize() { ...@@ -848,11 +837,11 @@ void NemoInterface::Impl::_synchronize() {
// create cmd. // create cmd.
auto pTask = std::make_unique<nemo_interface::Task>([this, pTileArray] { auto pTask = std::make_unique<nemo_interface::Task>([this, pTileArray] {
auto rb = this->_pRosbridge; auto &rb = this->_rosbridge;
auto &disp = this->_dispatcher; auto &disp = this->_dispatcher;
// are _localTiles and _remoteTiles synced? // are _localTiles and _remoteTiles synced?
auto remoteTiles = this->_callGetAllTiles(disp, *rb); auto remoteTiles = this->_callGetAllTiles(disp, rb);
// create tile map; // create tile map;
std::map<QString, std::shared_ptr<Tile>> tempMap; std::map<QString, std::shared_ptr<Tile>> tempMap;
...@@ -861,7 +850,7 @@ void NemoInterface::Impl::_synchronize() { ...@@ -861,7 +850,7 @@ void NemoInterface::Impl::_synchronize() {
if (Q_LIKELY(it == tempMap.end())) { if (Q_LIKELY(it == tempMap.end())) {
tempMap.insert(std::make_pair(pTile->id(), pTile)); tempMap.insert(std::make_pair(pTile->id(), pTile));
} else { } else {
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "_synchronizeIfNeccessary(): remoteTiles contains " << "_synchronizeIfNeccessary(): remoteTiles contains "
"duplicate id"; "duplicate id";
} }
...@@ -918,7 +907,7 @@ void NemoInterface::Impl::_synchronize() { ...@@ -918,7 +907,7 @@ void NemoInterface::Impl::_synchronize() {
this->_doActionNotSafe(); this->_doActionNotSafe();
lk.unlock(); lk.unlock();
this->_setWarningString("Getting progress failed."); this->_setWarningString("Getting progress failed.");
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "_addTilesImpl(): _updateProgress failed: unknown id."; << "_addTilesImpl(): _updateProgress failed: unknown id.";
return QVariant(false); return QVariant(false);
} }
...@@ -947,7 +936,7 @@ void NemoInterface::Impl::_synchronize() { ...@@ -947,7 +936,7 @@ void NemoInterface::Impl::_synchronize() {
} }
} }
void NemoInterface::Impl::_tryRestart() { void Nemointerface::Impl::_tryRestart() {
if (this->running()) { if (this->running()) {
if (_dispatcher.idle()) { if (_dispatcher.idle()) {
qDebug() << "_tryRestart: restarting"; qDebug() << "_tryRestart: restarting";
...@@ -960,19 +949,19 @@ void NemoInterface::Impl::_tryRestart() { ...@@ -960,19 +949,19 @@ void NemoInterface::Impl::_tryRestart() {
} }
} }
bool NemoInterface::Impl::_isSynchronizedNotSafe() const { bool Nemointerface::Impl::_isSynchronizedNotSafe() const {
return _localTiles.size() == _remoteTiles.size() && return _localTiles.size() == _remoteTiles.size() &&
std::equal( std::equal(
_localTiles.begin(), _localTiles.end(), _remoteTiles.begin(), _localTiles.begin(), _localTiles.end(), _remoteTiles.begin(),
[](const auto &a, const auto &b) { return a.first == b.first; }); [](const auto &a, const auto &b) { return a.first == b.first; });
} }
bool NemoInterface::Impl::_isSynchronized() const { bool Nemointerface::Impl::_isSynchronized() const {
Lock lk(this->_m); Lock lk(this->_m);
return _isSynchronizedNotSafe(); return _isSynchronizedNotSafe();
} }
void NemoInterface::Impl::_doActionNotSafe() { void Nemointerface::Impl::_doActionNotSafe() {
static bool resetDone = false; static bool resetDone = false;
switch (this->_state) { switch (this->_state) {
case STATE::STOPPED: { case STATE::STOPPED: {
...@@ -983,8 +972,8 @@ void NemoInterface::Impl::_doActionNotSafe() { ...@@ -983,8 +972,8 @@ void NemoInterface::Impl::_doActionNotSafe() {
this->_syncTimer.stop(); this->_syncTimer.stop();
})) }))
if (this->_pRosbridge->state() != Rosbridge::STATE::STOPPED) { if (this->_rosbridge.state() != Rosbridge::STATE::STOPPED) {
this->_pRosbridge->stop(); this->_rosbridge.stop();
} }
_dispatcher.stop(); _dispatcher.stop();
_dispatcher.clear(); _dispatcher.clear();
...@@ -998,7 +987,7 @@ void NemoInterface::Impl::_doActionNotSafe() { ...@@ -998,7 +987,7 @@ void NemoInterface::Impl::_doActionNotSafe() {
INVM(this->_parent, INVM(this->_parent,
([this]() mutable { this->_restartTimer.start(RESTART_INTERVAl); })) ([this]() mutable { this->_restartTimer.start(RESTART_INTERVAl); }))
this->_pRosbridge->start(); this->_rosbridge.start();
} break; } break;
case STATE::WEBSOCKET_DETECTED: case STATE::WEBSOCKET_DETECTED:
resetDone = false; resetDone = false;
...@@ -1036,8 +1025,8 @@ void NemoInterface::Impl::_doActionNotSafe() { ...@@ -1036,8 +1025,8 @@ void NemoInterface::Impl::_doActionNotSafe() {
if (!resetDone) { if (!resetDone) {
resetDone = true; resetDone = true;
this->_pRosbridge->stop(); this->_rosbridge.stop();
this->_pRosbridge->start(); this->_rosbridge.start();
} }
_dispatcher.stop(); _dispatcher.stop();
_dispatcher.clear(); _dispatcher.clear();
...@@ -1048,7 +1037,7 @@ void NemoInterface::Impl::_doActionNotSafe() { ...@@ -1048,7 +1037,7 @@ void NemoInterface::Impl::_doActionNotSafe() {
}; };
} }
bool NemoInterface::Impl::_callAddTiles( bool Nemointerface::Impl::_callAddTiles(
const QVector<std::shared_ptr<const Tile>> &tileArray, Dispatcher &d, const QVector<std::shared_ptr<const Tile>> &tileArray, Dispatcher &d,
Rosbridge &rb) { Rosbridge &rb) {
...@@ -1060,7 +1049,7 @@ bool NemoInterface::Impl::_callAddTiles( ...@@ -1060,7 +1049,7 @@ bool NemoInterface::Impl::_callAddTiles(
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
QJsonObject jsonTile; QJsonObject jsonTile;
if (!nemo_msgs::tile::toJson(*tile, jsonTile)) { if (!nemo_msgs::tile::toJson(*tile, jsonTile)) {
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "addTiles(): not able to create json object: tile id: " << "addTiles(): not able to create json object: tile id: "
<< tile->id() << " progress: " << tile->progress() << tile->id() << " progress: " << tile->progress()
<< " points: " << tile->tile(); << " points: " << tile->tile();
...@@ -1079,7 +1068,7 @@ bool NemoInterface::Impl::_callAddTiles( ...@@ -1079,7 +1068,7 @@ bool NemoInterface::Impl::_callAddTiles(
if (o.contains("success") && o["success"].isBool()) { if (o.contains("success") && o["success"].isBool()) {
promise_response->set_value(o["success"].toBool()); promise_response->set_value(o["success"].toBool());
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< addTilesService << " no \"success\" key or wrong type: " << o; << addTilesService << " no \"success\" key or wrong type: " << o;
promise_response->set_value(false); promise_response->set_value(false);
} }
...@@ -1101,7 +1090,7 @@ bool NemoInterface::Impl::_callAddTiles( ...@@ -1101,7 +1090,7 @@ bool NemoInterface::Impl::_callAddTiles(
d.isInterruptionRequested()); d.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "addTiles(): Websocket not responding to request."; << "addTiles(): Websocket not responding to request.";
return false; return false;
} }
...@@ -1115,7 +1104,7 @@ bool NemoInterface::Impl::_callAddTiles( ...@@ -1115,7 +1104,7 @@ bool NemoInterface::Impl::_callAddTiles(
return true; return true;
} }
bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray, bool Nemointerface::Impl::_callRemoveTiles(const IDArray &pIdArray,
Dispatcher &disp, Rosbridge &rb) { Dispatcher &disp, Rosbridge &rb) {
// qDebug() << "_callRemoveTiles called"; // qDebug() << "_callRemoveTiles called";
...@@ -1137,7 +1126,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray, ...@@ -1137,7 +1126,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray,
if (o.contains("success") && o["success"].isBool()) { if (o.contains("success") && o["success"].isBool()) {
promise_response->set_value(o["success"].toBool()); promise_response->set_value(o["success"].toBool());
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< removeTilesService << " no \"success\" key or wrong type: " << msg; << removeTilesService << " no \"success\" key or wrong type: " << msg;
promise_response->set_value(false); promise_response->set_value(false);
} }
...@@ -1159,7 +1148,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray, ...@@ -1159,7 +1148,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray,
disp.isInterruptionRequested()); disp.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "remove_tiles(): Websocket not responding to request."; << "remove_tiles(): Websocket not responding to request.";
return false; return false;
} }
...@@ -1172,7 +1161,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray, ...@@ -1172,7 +1161,7 @@ bool NemoInterface::Impl::_callRemoveTiles(const IDArray &pIdArray,
return true; return true;
} }
bool NemoInterface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) { bool Nemointerface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) {
// create response handler. // create response handler.
auto promise_response = std::make_shared<std::promise<bool>>(); auto promise_response = std::make_shared<std::promise<bool>>();
...@@ -1198,7 +1187,7 @@ bool NemoInterface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1198,7 +1187,7 @@ bool NemoInterface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) {
disp.isInterruptionRequested()); disp.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) << "Websocket not responding to request."; qCWarning(NemointerfaceLog) << "Websocket not responding to request.";
return false; return false;
} }
...@@ -1210,7 +1199,7 @@ bool NemoInterface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1210,7 +1199,7 @@ bool NemoInterface::Impl::_callClearTiles(Dispatcher &disp, Rosbridge &rb) {
return true; return true;
} }
ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray, ProgressArray Nemointerface::Impl::_callGetProgress(const IDArray &pIdArray,
Dispatcher &disp, Dispatcher &disp,
Rosbridge &rb) { Rosbridge &rb) {
// qDebug() << "_callGetProgress called"; // qDebug() << "_callGetProgress called";
...@@ -1238,7 +1227,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray, ...@@ -1238,7 +1227,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray,
*pArray = std::move(progressArrayMsg.progress_array()); *pArray = std::move(progressArrayMsg.progress_array());
promise_response->set_value(pArray); promise_response->set_value(pArray);
} else { } else {
qCWarning(NemoInterfaceLog) << getProgressService qCWarning(NemointerfaceLog) << getProgressService
<< " error while creating ProgressArray " << " error while creating ProgressArray "
"from json."; "from json.";
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
...@@ -1261,7 +1250,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray, ...@@ -1261,7 +1250,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray,
disp.isInterruptionRequested()); disp.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "all_remove_tiles(): Websocket not responding to request."; << "all_remove_tiles(): Websocket not responding to request.";
return ProgressArray(); return ProgressArray();
} }
...@@ -1270,7 +1259,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray, ...@@ -1270,7 +1259,7 @@ ProgressArray NemoInterface::Impl::_callGetProgress(const IDArray &pIdArray,
return *future_response.get(); return *future_response.get();
} }
ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp, ProgressArray Nemointerface::Impl::_callGetAllProgress(Dispatcher &disp,
Rosbridge &rb) { Rosbridge &rb) {
// qDebug() << "_callGetAllProgress called"; // qDebug() << "_callGetAllProgress called";
...@@ -1288,7 +1277,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp, ...@@ -1288,7 +1277,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp,
*pArray = std::move(progressArrayMsg.progress_array()); *pArray = std::move(progressArrayMsg.progress_array());
promise_response->set_value(pArray); promise_response->set_value(pArray);
} else { } else {
qCWarning(NemoInterfaceLog) << getAllProgressService qCWarning(NemointerfaceLog) << getAllProgressService
<< " error while creating ProgressArray " << " error while creating ProgressArray "
"from json. msg: " "from json. msg: "
<< o; << o;
...@@ -1312,7 +1301,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp, ...@@ -1312,7 +1301,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp,
disp.isInterruptionRequested()); disp.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "_callGetAllProgress(): Websocket not responding to request."; << "_callGetAllProgress(): Websocket not responding to request.";
return ProgressArray(); return ProgressArray();
} }
...@@ -1322,7 +1311,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp, ...@@ -1322,7 +1311,7 @@ ProgressArray NemoInterface::Impl::_callGetAllProgress(Dispatcher &disp,
} }
QVector<std::shared_ptr<Tile>> QVector<std::shared_ptr<Tile>>
NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) { Nemointerface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) {
// qDebug() << "_callGetAllProgress called"; // qDebug() << "_callGetAllProgress called";
// create response handler. // create response handler.
...@@ -1343,12 +1332,12 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1343,12 +1332,12 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) {
if (ros_bridge::messages::nemo_msgs::tile::fromJson(o, *tile)) { if (ros_bridge::messages::nemo_msgs::tile::fromJson(o, *tile)) {
pArray->push_back(tile); pArray->push_back(tile);
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< getAllTilesService << " error while creating tile."; << getAllTilesService << " error while creating tile.";
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
} }
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< getAllTilesService << " json array does not contain objects."; << getAllTilesService << " json array does not contain objects.";
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
} }
...@@ -1356,7 +1345,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1356,7 +1345,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) {
// success! // success!
promise_response->set_value(pArray); promise_response->set_value(pArray);
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< getAllTilesService << " no tile_array key or wrong type."; << getAllTilesService << " no tile_array key or wrong type.";
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
} }
...@@ -1378,7 +1367,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1378,7 +1367,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) {
disp.isInterruptionRequested()); disp.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "all_remove_tiles(): Websocket not responding to request."; << "all_remove_tiles(): Websocket not responding to request.";
return QVector<std::shared_ptr<Tile>>(); return QVector<std::shared_ptr<Tile>>();
} }
...@@ -1386,7 +1375,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) { ...@@ -1386,7 +1375,7 @@ NemoInterface::Impl::_callGetAllTiles(Dispatcher &disp, Rosbridge &rb) {
return *future_response.get(); return *future_response.get();
} }
QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) { QString Nemointerface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) {
// create response handler. // create response handler.
typedef QString ResponseType; typedef QString ResponseType;
...@@ -1400,7 +1389,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) { ...@@ -1400,7 +1389,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) {
const auto version = o[versionKey].toString(); const auto version = o[versionKey].toString();
promise_response->set_value(version); promise_response->set_value(version);
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< getVersionService << " no version key or wrong type."; << getVersionService << " no version key or wrong type.";
promise_response->set_value("error!"); promise_response->set_value("error!");
} }
...@@ -1422,7 +1411,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) { ...@@ -1422,7 +1411,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) {
d.isInterruptionRequested()); d.isInterruptionRequested());
if (abort) { if (abort) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "all_remove_tiles(): Websocket not responding to request."; << "all_remove_tiles(): Websocket not responding to request.";
return "unknown_version"; return "unknown_version";
} }
...@@ -1437,7 +1426,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) { ...@@ -1437,7 +1426,7 @@ QString NemoInterface::Impl::_callGetVersion(Dispatcher &d, Rosbridge &rb) {
return version; return version;
} }
bool NemoInterface::Impl::_addTilesRemote( bool Nemointerface::Impl::_addTilesRemote(
const QVector<std::shared_ptr<const Tile>> tileArray) { const QVector<std::shared_ptr<const Tile>> tileArray) {
// qDebug() << "_addTilesRemote called"; // qDebug() << "_addTilesRemote called";
...@@ -1449,7 +1438,7 @@ bool NemoInterface::Impl::_addTilesRemote( ...@@ -1449,7 +1438,7 @@ bool NemoInterface::Impl::_addTilesRemote(
return _addTilesRemote(copy); return _addTilesRemote(copy);
} }
bool NemoInterface::Impl::_addTilesRemote( bool Nemointerface::Impl::_addTilesRemote(
const QVector<std::shared_ptr<Tile>> &tileArray) { const QVector<std::shared_ptr<Tile>> &tileArray) {
bool error = false; bool error = false;
...@@ -1466,7 +1455,7 @@ bool NemoInterface::Impl::_addTilesRemote( ...@@ -1466,7 +1455,7 @@ bool NemoInterface::Impl::_addTilesRemote(
Q_UNUSED(ret); Q_UNUSED(ret);
} else { } else {
if (pTile->tile() != it->second->tile()) { if (pTile->tile() != it->second->tile()) {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "_addTilesRemote: tiles differ but have the same id."; << "_addTilesRemote: tiles differ but have the same id.";
error = true; error = true;
} }
...@@ -1481,7 +1470,7 @@ bool NemoInterface::Impl::_addTilesRemote( ...@@ -1481,7 +1470,7 @@ bool NemoInterface::Impl::_addTilesRemote(
return !error; return !error;
} }
void NemoInterface::Impl::_removeTilesRemote(const IDArray &idArray) { void Nemointerface::Impl::_removeTilesRemote(const IDArray &idArray) {
// qDebug() << "_removeTilesRemote called"; // qDebug() << "_removeTilesRemote called";
bool anyChange = false; bool anyChange = false;
...@@ -1492,7 +1481,7 @@ void NemoInterface::Impl::_removeTilesRemote(const IDArray &idArray) { ...@@ -1492,7 +1481,7 @@ void NemoInterface::Impl::_removeTilesRemote(const IDArray &idArray) {
_remoteTiles.erase(it); _remoteTiles.erase(it);
anyChange = true; anyChange = true;
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemointerfaceLog)
<< "_removeTilesRemote: tile with unknown id " << id << "."; << "_removeTilesRemote: tile with unknown id " << id << ".";
} }
} }
...@@ -1502,24 +1491,24 @@ void NemoInterface::Impl::_removeTilesRemote(const IDArray &idArray) { ...@@ -1502,24 +1491,24 @@ void NemoInterface::Impl::_removeTilesRemote(const IDArray &idArray) {
} }
} }
void NemoInterface::Impl::_clearTilesRemote() { void Nemointerface::Impl::_clearTilesRemote() {
Lock lk(this->_m); Lock lk(this->_m);
_clearTilesRemoteNotSafe(); _clearTilesRemoteNotSafe();
} }
void NemoInterface::Impl::_clearTilesRemoteNotSafe() { void Nemointerface::Impl::_clearTilesRemoteNotSafe() {
// qDebug() << "_clearTilesRemote called"; // qDebug() << "_clearTilesRemote called";
if (_remoteTiles.size() > 0) { if (_remoteTiles.size() > 0) {
_remoteTiles.clear(); _remoteTiles.clear();
} }
} }
bool NemoInterface::Impl::_setStateNotSafe(STATE newState) { bool Nemointerface::Impl::_setStateNotSafe(STATE newState) {
if (newState != this->_state) { if (newState != this->_state) {
auto oldState = this->_state; auto oldState = this->_state;
this->_state = newState; this->_state = newState;
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "state: " << _toString(oldState) << " -> " << _toString(newState); << "state: " << _toString(oldState) << " -> " << _toString(newState);
auto oldStatus = _status(oldState); auto oldStatus = _status(oldState);
auto newStatus = _status(newState); auto newStatus = _status(newState);
...@@ -1541,58 +1530,58 @@ bool NemoInterface::Impl::_setStateNotSafe(STATE newState) { ...@@ -1541,58 +1530,58 @@ bool NemoInterface::Impl::_setStateNotSafe(STATE newState) {
} }
} }
bool NemoInterface::Impl::_readyNotSafe(NemoInterface::Impl::STATE s) { bool Nemointerface::Impl::_readyNotSafe(Nemointerface::Impl::STATE s) {
return s == STATE::READY; return s == STATE::READY;
} }
bool NemoInterface::Impl::_userSyncNotSafe(NemoInterface::Impl::STATE s) { bool Nemointerface::Impl::_userSyncNotSafe(Nemointerface::Impl::STATE s) {
return s == STATE::USER_SYNC; return s == STATE::USER_SYNC;
} }
bool NemoInterface::Impl::_sysSyncNotSafe(NemoInterface::Impl::STATE s) { bool Nemointerface::Impl::_sysSyncNotSafe(Nemointerface::Impl::STATE s) {
return s == STATE::SYS_SYNC; return s == STATE::SYS_SYNC;
} }
bool NemoInterface::Impl::_runningNotSafe(NemoInterface::Impl::STATE s) { bool Nemointerface::Impl::_runningNotSafe(Nemointerface::Impl::STATE s) {
return s != STATE::STOPPED; return s != STATE::STOPPED;
} }
NemoInterface::STATUS Nemointerface::STATUS
NemoInterface::Impl::_status(NemoInterface::Impl::STATE state) { Nemointerface::Impl::_status(Nemointerface::Impl::STATE state) {
NemoInterface::STATUS status; Nemointerface::STATUS status;
switch (state) { switch (state) {
case STATE::STOPPED: case STATE::STOPPED:
status = NemoInterface::STATUS::NOT_CONNECTED; status = Nemointerface::STATUS::NOT_CONNECTED;
break; break;
case STATE::START_BRIDGE: case STATE::START_BRIDGE:
status = NemoInterface::STATUS::NOT_CONNECTED; status = Nemointerface::STATUS::NOT_CONNECTED;
break; break;
case STATE::WEBSOCKET_DETECTED: case STATE::WEBSOCKET_DETECTED:
status = NemoInterface::STATUS::WEBSOCKET_DETECTED; status = Nemointerface::STATUS::WEBSOCKET_DETECTED;
break; break;
case STATE::TRY_SETUP: case STATE::TRY_SETUP:
status = NemoInterface::STATUS::WEBSOCKET_DETECTED; status = Nemointerface::STATUS::WEBSOCKET_DETECTED;
break; break;
case STATE::READY: case STATE::READY:
status = NemoInterface::STATUS::READY; status = Nemointerface::STATUS::READY;
break; break;
case STATE::USER_SYNC: case STATE::USER_SYNC:
case STATE::SYS_SYNC: case STATE::SYS_SYNC:
status = NemoInterface::STATUS::SYNC; status = Nemointerface::STATUS::SYNC;
break; break;
case STATE::SYNC_ERROR: case STATE::SYNC_ERROR:
status = NemoInterface::STATUS::ERROR; status = Nemointerface::STATUS::ERROR;
break; break;
case STATE::WEBSOCKET_TIMEOUT: case STATE::WEBSOCKET_TIMEOUT:
case STATE::HEARTBEAT_TIMEOUT: case STATE::HEARTBEAT_TIMEOUT:
status = NemoInterface::STATUS::TIMEOUT; status = Nemointerface::STATUS::TIMEOUT;
break; break;
} }
return status; return status;
} }
QString NemoInterface::Impl::_toString(NemoInterface::Impl::STATE s) { QString Nemointerface::Impl::_toString(Nemointerface::Impl::STATE s) {
switch (s) { switch (s) {
case STATE::STOPPED: case STATE::STOPPED:
return QString("STOPPED"); return QString("STOPPED");
...@@ -1618,32 +1607,32 @@ QString NemoInterface::Impl::_toString(NemoInterface::Impl::STATE s) { ...@@ -1618,32 +1607,32 @@ QString NemoInterface::Impl::_toString(NemoInterface::Impl::STATE s) {
return "unknown state!"; return "unknown state!";
} }
QString NemoInterface::Impl::_toString(NemoInterface::STATUS s) { QString Nemointerface::Impl::_toString(Nemointerface::STATUS s) {
switch (s) { switch (s) {
case NemoInterface::STATUS::NOT_CONNECTED: case Nemointerface::STATUS::NOT_CONNECTED:
return QString("NOT_CONNECTED"); return QString("NOT_CONNECTED");
case NemoInterface::STATUS::ERROR: case Nemointerface::STATUS::ERROR:
return QString("ERROR"); return QString("ERROR");
case NemoInterface::STATUS::READY: case Nemointerface::STATUS::READY:
return QString("READY"); return QString("READY");
case NemoInterface::STATUS::TIMEOUT: case Nemointerface::STATUS::TIMEOUT:
return QString("TIMEOUT"); return QString("TIMEOUT");
case NemoInterface::STATUS::WEBSOCKET_DETECTED: case Nemointerface::STATUS::WEBSOCKET_DETECTED:
return QString("WEBSOCKET_DETECTED"); return QString("WEBSOCKET_DETECTED");
case NemoInterface::STATUS::SYNC: case Nemointerface::STATUS::SYNC:
return QString("SYNC"); return QString("SYNC");
} }
return "unknown state!"; return "unknown state!";
} }
bool NemoInterface::Impl::_addTilesImpl( bool Nemointerface::Impl::_addTilesImpl(
std::shared_ptr<QVector<std::shared_ptr<const Tile>>> pTileArray, std::shared_ptr<QVector<std::shared_ptr<const Tile>>> pTileArray,
std::shared_ptr<const IDArray> pIdArray) { std::shared_ptr<const IDArray> pIdArray) {
auto rb = this->_pRosbridge; auto &rb = this->_rosbridge;
auto &disp = this->_dispatcher; auto &disp = this->_dispatcher;
// add tiles // add tiles
bool success = this->_callAddTiles(*pTileArray, disp, *rb); bool success = this->_callAddTiles(*pTileArray, disp, rb);
if (!success) { if (!success) {
this->_setWarningString( this->_setWarningString(
"Adding tiles failed. This might indicate a poor connection."); "Adding tiles failed. This might indicate a poor connection.");
...@@ -1657,13 +1646,13 @@ bool NemoInterface::Impl::_addTilesImpl( ...@@ -1657,13 +1646,13 @@ bool NemoInterface::Impl::_addTilesImpl(
this->_doActionNotSafe(); this->_doActionNotSafe();
lk.unlock(); lk.unlock();
this->_setWarningString("Adding tiles failed."); this->_setWarningString("Adding tiles failed.");
qCDebug(NemoInterfaceLog) << "_addTilesImpl(): _addTilesRemote return " qCDebug(NemointerfaceLog) << "_addTilesImpl(): _addTilesRemote return "
"false: different tiles with same id."; "false: different tiles with same id.";
return false; return false;
} }
// fetch progress // fetch progress
auto array = this->_callGetProgress(*pIdArray, disp, *rb); auto array = this->_callGetProgress(*pIdArray, disp, rb);
if (array.size() != pIdArray->size()) { if (array.size() != pIdArray->size()) {
Lock lk(this->_m); Lock lk(this->_m);
this->_setStateNotSafe(STATE::SYNC_ERROR); this->_setStateNotSafe(STATE::SYNC_ERROR);
...@@ -1681,7 +1670,7 @@ bool NemoInterface::Impl::_addTilesImpl( ...@@ -1681,7 +1670,7 @@ bool NemoInterface::Impl::_addTilesImpl(
this->_doActionNotSafe(); this->_doActionNotSafe();
lk.unlock(); lk.unlock();
this->_setWarningString("Getting progress failed."); this->_setWarningString("Getting progress failed.");
qCDebug(NemoInterfaceLog) qCDebug(NemointerfaceLog)
<< "_addTilesImpl(): _updateProgress failed: unknown id."; << "_addTilesImpl(): _updateProgress failed: unknown id.";
return false; return false;
} }
...@@ -1689,12 +1678,12 @@ bool NemoInterface::Impl::_addTilesImpl( ...@@ -1689,12 +1678,12 @@ bool NemoInterface::Impl::_addTilesImpl(
return true; return true;
} }
bool NemoInterface::Impl::_removeTilesImpl( bool Nemointerface::Impl::_removeTilesImpl(
std::shared_ptr<const IDArray> pIdArray) { std::shared_ptr<const IDArray> pIdArray) {
auto rb = this->_pRosbridge; auto &rb = this->_rosbridge;
auto &disp = this->_dispatcher; auto &disp = this->_dispatcher;
auto success = this->_callRemoveTiles(*pIdArray, disp, *rb); auto success = this->_callRemoveTiles(*pIdArray, disp, rb);
if (!success) { if (!success) {
Lock lk(this->_m); Lock lk(this->_m);
this->_setStateNotSafe(STATE::SYNC_ERROR); this->_setStateNotSafe(STATE::SYNC_ERROR);
...@@ -1709,11 +1698,11 @@ bool NemoInterface::Impl::_removeTilesImpl( ...@@ -1709,11 +1698,11 @@ bool NemoInterface::Impl::_removeTilesImpl(
return true; return true;
} }
bool NemoInterface::Impl::_clearTilesImpl() { bool Nemointerface::Impl::_clearTilesImpl() {
auto rb = this->_pRosbridge; auto &rb = this->_rosbridge;
auto &disp = this->_dispatcher; auto &disp = this->_dispatcher;
auto success = this->_callClearTiles(disp, *rb); auto success = this->_callClearTiles(disp, rb);
if (!success) { if (!success) {
Lock lk(this->_m); Lock lk(this->_m);
this->_setStateNotSafe(STATE::SYNC_ERROR); this->_setStateNotSafe(STATE::SYNC_ERROR);
...@@ -1730,24 +1719,18 @@ bool NemoInterface::Impl::_clearTilesImpl() { ...@@ -1730,24 +1719,18 @@ bool NemoInterface::Impl::_clearTilesImpl() {
// =============================================================== // ===============================================================
// NemoInterface // NemoInterface
NemoInterface::NemoInterface() Nemointerface::Nemointerface(const QString &connectionString)
: QObject(), pImpl(std::make_unique<NemoInterface::Impl>(this)) {} : QObject(),
pImpl(std::make_unique<Nemointerface::Impl>(connectionString, this)) {}
NemoInterface *NemoInterface::createInstance() { return new NemoInterface(); } Nemointerface::~Nemointerface() {}
NemoInterface *NemoInterface::instance() { void Nemointerface::start() { this->pImpl->start(); }
return GenericSingelton<NemoInterface>::instance(
NemoInterface::createInstance);
}
NemoInterface::~NemoInterface() {}
void NemoInterface::start() { this->pImpl->start(); }
void NemoInterface::stop() { this->pImpl->stop(); } void Nemointerface::stop() { this->pImpl->stop(); }
std::shared_future<QVariant> std::shared_future<QVariant>
NemoInterface::addTiles(const TileArray &tileArray) { Nemointerface::addTiles(const TileArray &tileArray) {
TilePtrArray ptrArray; TilePtrArray ptrArray;
for (const auto &tile : tileArray) { for (const auto &tile : tileArray) {
ptrArray.push_back(const_cast<MeasurementTile *>(&tile)); ptrArray.push_back(const_cast<MeasurementTile *>(&tile));
...@@ -1756,59 +1739,130 @@ NemoInterface::addTiles(const TileArray &tileArray) { ...@@ -1756,59 +1739,130 @@ NemoInterface::addTiles(const TileArray &tileArray) {
} }
std::shared_future<QVariant> std::shared_future<QVariant>
NemoInterface::addTiles(const TilePtrArray &tileArray) { Nemointerface::addTiles(const TilePtrArray &tileArray) {
return this->pImpl->addTiles(tileArray); return this->pImpl->addTiles(tileArray);
} }
std::shared_future<QVariant> std::shared_future<QVariant>
NemoInterface::removeTiles(const IDArray &idArray) { Nemointerface::removeTiles(const IDArray &idArray) {
return this->pImpl->removeTiles(idArray); return this->pImpl->removeTiles(idArray);
} }
std::shared_future<QVariant> NemoInterface::clearTiles() { std::shared_future<QVariant> Nemointerface::clearTiles() {
return this->pImpl->clearTiles(); return this->pImpl->clearTiles();
} }
TileArray NemoInterface::getTiles(const IDArray &idArray) const { TileArray Nemointerface::getTiles(const IDArray &idArray) const {
return this->pImpl->getTiles(idArray); return this->pImpl->getTiles(idArray);
} }
TileArray NemoInterface::getAllTiles() const { TileArray Nemointerface::getAllTiles() const {
return this->pImpl->getAllTiles(); return this->pImpl->getAllTiles();
} }
LogicalArray NemoInterface::containsTiles(const IDArray &idArray) const { LogicalArray Nemointerface::containsTiles(const IDArray &idArray) const {
return this->pImpl->containsTiles(idArray); return this->pImpl->containsTiles(idArray);
} }
std::size_t NemoInterface::size() const { return this->pImpl->size(); } std::size_t Nemointerface::size() const { return this->pImpl->size(); }
bool NemoInterface::empty() const { return this->pImpl->empty(); } bool Nemointerface::empty() const { return this->pImpl->empty(); }
ProgressArray NemoInterface::getProgress() const { ProgressArray Nemointerface::getProgress() const {
return this->pImpl->getProgress(); return this->pImpl->getProgress();
} }
ProgressArray NemoInterface::getProgress(const IDArray &idArray) const { ProgressArray Nemointerface::getProgress(const IDArray &idArray) const {
return this->pImpl->getProgress(idArray<