[31] | 1 | /**
|
---|
| 2 | *
|
---|
| 3 | * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
|
---|
| 4 | * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * See the LICENSE file for more information or a copy at:
|
---|
| 7 | * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
[3] | 10 |
|
---|
[31] | 11 | #ifndef DEF_PACPUS_DBTPLYENGINE_H
|
---|
| 12 | #define DEF_PACPUS_DBTPLYENGINE_H
|
---|
[3] | 13 |
|
---|
[31] | 14 | #include <QSemaphore>
|
---|
[3] | 15 |
|
---|
[31] | 16 | #include <Pacpus/kernel/ComponentBase.h>
|
---|
| 17 | #include <Pacpus/kernel/ComponentFactory.h>
|
---|
| 18 | #include <Pacpus/DbitePlayer/DbitePlayerConfig.h>
|
---|
| 19 | #include <Pacpus/DbitePlayer/DbtPlyEngineStateChart.h>
|
---|
| 20 | #include <Pacpus/DbitePlayer/DbtPlyUserInterface.h>
|
---|
[3] | 21 |
|
---|
| 22 | namespace pacpus {
|
---|
| 23 |
|
---|
| 24 | class DbtPlyEngineStateChart;
|
---|
| 25 | class DbtPlyEngineState;
|
---|
| 26 |
|
---|
| 27 | enum PlayMode
|
---|
| 28 | {
|
---|
| 29 | PlayModeLastData = 1, // replay_mode="1"
|
---|
| 30 | PlayModeAllData = 2 // replay_mode="2"
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | /// XML config properties:
|
---|
| 34 | /// datadir PATH root data directory,
|
---|
| 35 | /// e.g. datadir="/home/user/dbt_data"
|
---|
| 36 | /// replay_mode STRING {1}|2
|
---|
| 37 | /// e.g. replay_mode="2"
|
---|
| 38 | class DBITE_PLAYER_API DbtPlyEngine
|
---|
| 39 | : public QThread
|
---|
| 40 | , public ComponentBase
|
---|
| 41 | {
|
---|
| 42 | Q_OBJECT
|
---|
| 43 |
|
---|
| 44 | public:
|
---|
| 45 | /// Constructor
|
---|
| 46 | DbtPlyEngine(QString name);
|
---|
| 47 | /// Destructor
|
---|
| 48 | ~DbtPlyEngine();
|
---|
| 49 |
|
---|
| 50 | /// @returns the directory where the data are stored
|
---|
| 51 | QString getDataDir();
|
---|
| 52 |
|
---|
| 53 | /// @returns the current replay time
|
---|
| 54 | road_time_t getTime()
|
---|
| 55 | {
|
---|
| 56 | return tDbt_;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /// @returns true if the player is playing
|
---|
| 60 | bool isPlaying();
|
---|
| 61 | /// Accessor to playmode
|
---|
| 62 | int replayMode()
|
---|
| 63 | {
|
---|
| 64 | return replayMode_;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | const DbtPlyEngineState * getState();
|
---|
| 68 | void setState(DbtPlyEngineState * newState);
|
---|
| 69 |
|
---|
| 70 | /// Goes back to the beginning, sets speed to initial value
|
---|
| 71 | void reset();
|
---|
| 72 |
|
---|
[61] | 73 | /// @todo Documentation
|
---|
[3] | 74 | void speedUp();
|
---|
[61] | 75 | /// @todo Documentation
|
---|
[3] | 76 | void speedDown();
|
---|
[61] | 77 | /// @todo Documentation
|
---|
[3] | 78 | void setLastTNow(road_time_t newTNow)
|
---|
| 79 | {
|
---|
| 80 | this->lastTNow_= newTNow;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | protected:
|
---|
[61] | 84 | /// @todo Documentation
|
---|
[3] | 85 | virtual void startActivity();
|
---|
[61] | 86 | /// @todo Documentation
|
---|
[3] | 87 | virtual void stopActivity();
|
---|
[61] | 88 | /// @todo Documentation
|
---|
[3] | 89 | virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
| 90 |
|
---|
| 91 | /// Thread main loop
|
---|
| 92 | virtual void run();
|
---|
| 93 |
|
---|
| 94 | private:
|
---|
| 95 | DbtPlyEngineState * mCurrentState;
|
---|
| 96 | float mSpeed;
|
---|
| 97 | bool mIsReverse;
|
---|
| 98 |
|
---|
| 99 | /// The state chart of the engine (speed, state and direction)
|
---|
| 100 | DbtPlyEngineStateChart * stateChart_;
|
---|
| 101 |
|
---|
| 102 | /// A semaphore of protection of the critical section
|
---|
| 103 | QSemaphore * tMinMaxSem_;
|
---|
| 104 | /// tmin and tmax regarding to all the DBT files replayed
|
---|
| 105 | road_time_t tDbtMin_, tDbtMax_;
|
---|
| 106 |
|
---|
| 107 | /// tNow_ = the current time when the trigger alerts the engine
|
---|
| 108 | road_time_t tNow_;
|
---|
| 109 | /// lastTNow_ = previous tNow_
|
---|
| 110 | road_time_t lastTNow_;
|
---|
| 111 | /// tDbt_ = the DBT time at which the data have to be replayed corresponding the state of the engine
|
---|
| 112 | road_time_t tDbt_;
|
---|
| 113 | /// lastTDbt_ = previous tDbt_
|
---|
| 114 | road_time_t lastTDbt_;
|
---|
| 115 |
|
---|
| 116 | /// the direction of reading: forward=1 or backward=-1 used to compute the tDbt that must be replayed
|
---|
| 117 | short direction_;
|
---|
| 118 |
|
---|
| 119 | /// the synchronization semaphore with the trigger
|
---|
| 120 | QSemaphore * sync_;
|
---|
| 121 |
|
---|
| 122 | /// where the data are stored
|
---|
| 123 | QString dataDir_;
|
---|
| 124 |
|
---|
| 125 | /// mode
|
---|
| 126 | PlayMode replayMode_;
|
---|
| 127 |
|
---|
| 128 | Q_SIGNALS:
|
---|
[61] | 129 | /// @todo Documentation
|
---|
[3] | 130 | void play(road_time_t timeToPlay, road_time_t actualTime, bool direction);
|
---|
[61] | 131 | /// @todo Documentation
|
---|
[3] | 132 | void stopfile();
|
---|
[61] | 133 | /// @todo Documentation
|
---|
[3] | 134 | void displayStateSig(DbtPlyEngineState * state, float speed);
|
---|
[61] | 135 | /// @todo Documentation
|
---|
[3] | 136 | void timeMinMax(road_time_t tMin, road_time_t tMax);
|
---|
[61] | 137 | /// @todo Documentation
|
---|
[3] | 138 | void curReplayTime(road_time_t time);
|
---|
| 139 |
|
---|
| 140 | public Q_SLOTS:
|
---|
[61] | 141 | /// @todo Documentation
|
---|
[3] | 142 | void engReceiver();
|
---|
[61] | 143 | /// @todo Documentation
|
---|
[3] | 144 | void changeDirection(bool reverse);
|
---|
[61] | 145 | /// @todo Documentation
|
---|
[3] | 146 | void tMinMax(road_time_t tMin, road_time_t tMax);
|
---|
| 147 |
|
---|
[61] | 148 | /// @todo Documentation
|
---|
[3] | 149 | void playEvent();
|
---|
[61] | 150 | /// @todo Documentation
|
---|
[3] | 151 | void pauseEvent();
|
---|
[61] | 152 | /// @todo Documentation
|
---|
[3] | 153 | void stopEvent();
|
---|
[61] | 154 | /// @todo Documentation
|
---|
[3] | 155 | void speedUpEvent();
|
---|
[61] | 156 | /// @todo Documentation
|
---|
[3] | 157 | void speedDownEvent();
|
---|
| 158 | };
|
---|
| 159 |
|
---|
| 160 | } // namespace pacpus
|
---|
| 161 |
|
---|
[31] | 162 | #endif // DEF_PACPUS_DBTPLYENGINE_H
|
---|