#ifndef PPPRUN_H
#define PPPRUN_H

#include <deque>
#include <vector>
#include <QtCore>

#include "GPSDecoder.h"
#include "pppOptions.h"
#include "pppClient.h"

class t_rnxObsFile;
class t_rnxNavFile;
class t_corrFile;

namespace BNC_PPP {

class t_pppRun : public QObject {
 Q_OBJECT
 public:
  t_pppRun(const t_pppOptions* opt);
  ~t_pppRun();

  void processFiles();

 signals:
  void newMessage(QByteArray msg, bool showOnScreen);
  void newPosition(bncTime time, QVector<double> xx);
  void newNMEAstr(QByteArray str);
  void progress(int);
  void finished();

 public slots:
  void slotNewEphGPS(gpsephemeris gpseph);
  void slotNewEphGlonass(glonassephemeris gloeph);
  void slotNewEphGalileo(galileoephemeris galeph);
  void slotNewCorrections(QStringList corrList);
  void slotNewObs(QByteArray staID, QList<t_obs> obsList);
  void slotSetSpeed(int speed);

 private:
  class t_epoData {
   public:
    t_epoData() {}
    ~t_epoData() {
      for (unsigned ii = 0; ii < _satObs.size(); ii++) {
        delete _satObs[ii];
      }
    }
    bncTime                _time;
    std::vector<t_satObs*> _satObs;
  };

  QMutex                 _mutex;
  const t_pppOptions*    _opt;
  t_pppClient*           _pppClient;
  std::deque<t_epoData*> _epoData;
  int                    _lastOrbCorrIOD[t_prn::MAXPRN+1];
  double                 _lastClkCorrValue[t_prn::MAXPRN+1];
  bncTime                _lastClkCorrTime;

  t_rnxObsFile* _rnxObsFile;
  t_rnxNavFile* _rnxNavFile;
  t_corrFile*   _corrFile;
  int           _maxSpeed;
  int           _speed;
};

}

#endif
