Skip to content
NemoInterface.h 3.47 KiB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#pragma once

#include <QGeoCoordinate>
#include <QObject>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#include <QVariant>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#include <future>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#include <memory>

#include "IDArray.h"
#include "LogicalArray.h"
#include "TileArray.h"
#include "TilePtrArray.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
#include "geometry/ProgressArray.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
class NemointerfaceFactory;

class Nemointerface : public QObject {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Q_OBJECT
  class Impl;
  using PImpl = std::unique_ptr<Impl>;

Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Nemointerface(const QString &connectionString);
  Nemointerface(Nemointerface &other) = delete;

  friend class NemointerfaceFactory;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  ~Nemointerface() override;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  enum class STATUS {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    NOT_CONNECTED,
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    SYNC,
Valentin Platzgummer's avatar
Valentin Platzgummer committed
    READY,
    WEBSOCKET_DETECTED,
    TIMEOUT,
  Q_PROPERTY(STATUS status READ status NOTIFY statusChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Q_PROPERTY(QString statusString READ statusString NOTIFY statusChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Q_PROPERTY(QString infoString READ infoString NOTIFY infoStringChanged)
  Q_PROPERTY(
      QString warningString READ warningString NOTIFY warningStringChanged)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Q_PROPERTY(QString editorQml READ editorQml CONSTANT)
  Q_PROPERTY(bool running READ running NOTIFY runningChanged)

Valentin Platzgummer's avatar
Valentin Platzgummer committed
  QString editorQml();

Valentin Platzgummer's avatar
Valentin Platzgummer committed
  Q_INVOKABLE void start();
  Q_INVOKABLE void stop();

Valentin Platzgummer's avatar
Valentin Platzgummer committed
  // Tile editing.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  //!
  //! \brief addTiles
  //! \param tileArray
  //! \return Returns a QVariant containing a boolean value, indicating if the
  //! requested operation was successfull.
  //!
  std::shared_future<QVariant> addTiles(const TileArray &tileArray);
  std::shared_future<QVariant> addTiles(const TilePtrArray &tileArray);
  //!
  //! \brief removeTiles
  //! \param idArray
  //! \return Returns a QVariant containing a boolean value, indicating if the
  //! requested operation was successfull.
  //!
  std::shared_future<QVariant> removeTiles(const IDArray &idArray);
  //!
  //! \brief clearTiles
  //! \return Returns a QVariant containing a boolean value, indicating if the
  //! requested operation was successfull.
  //!
  std::shared_future<QVariant> clearTiles();

  TileArray getTiles(const IDArray &idArray) const;
  TileArray getAllTiles() const;
  LogicalArray containsTiles(const IDArray &idArray) const;
  std::size_t size() const;
  bool empty() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  // Progress.
  ProgressArray getProgress() const;
  ProgressArray getProgress(const IDArray &idArray) const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed

  // Status.
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  QString statusString() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  QString infoString() const;
  QString warningString() const;
  bool running() const;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  QString connectionString();
Valentin Platzgummer's avatar
Valentin Platzgummer committed

signals:
  void statusChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  void infoStringChanged();
  void warningStringChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  void progressChanged(const ProgressArray &progressArray);
  void tilesChanged();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
  void runningChanged();

private:
  PImpl pImpl;
};
Valentin Platzgummer's avatar
Valentin Platzgummer committed
// Singelton class used for nemo interface creation.
class NemointerfaceFactory {
  NemointerfaceFactory();
  NemointerfaceFactory(const NemointerfaceFactory &other) = delete;
  static NemointerfaceFactory *createInstance();

public:
  ~NemointerfaceFactory();
  static NemointerfaceFactory *instance();

  // Creates a interface with a connection string connectionString.
  // Two different interfaces can't share the same connection string.
  std::shared_ptr<Nemointerface> create(const QString &connectionString);
  // Returns true if an interface with connection string connectionString can
  // be created (i.e. doesn't exist yet), returns false either.
  bool isCreatable(const QString &connectionString);

private:
  std::map<QString, std::weak_ptr<Nemointerface>> _map;
};

#define pNemoInterfaceFactory NemointerfaceFactory::instance()