INTRODUCTION Overview Download and Install Quick Start Documentation Publications NONFRAMEWORK CODE Driver Interfaces Drivers Libraries Utilities FRAMEWORK CODE Interfaces Components Libraries Utilities Full Software Listings DEVELOPER Tutorials Examples Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
replayconductor.h00001 #ifndef LOGPLAYER_REPLAYCONDUCTOR_H 00002 #define LOGPLAYER_REPLAYCONDUCTOR_H 00003 00004 #include <orcaice/subsystemthread.h> 00005 #include <orcaice/context.h> 00006 #include <orcalog/orcalog.h> 00007 #include <IceUtil/IceUtil.h> 00008 #include "replayclock.h" 00009 #include <queue> 00010 00011 namespace logplayer { 00012 00013 // 00014 // @brief Orchestrates replaying of the log. 00015 // This thing is a thread, so it can play continuously. 00016 // It's thread-safe so that replay-rate etc can be adjusted during operation. 00017 // 00018 // @author Alex Brooks 00019 // 00020 class ReplayConductor : public orcaice::SubsystemThread 00021 { 00022 00023 public: 00024 00025 // beginTime is relative to the start of the log (not absolute) 00026 ReplayConductor( orcalog::MasterFileReader &masterFileReader, 00027 std::vector<orcalog::Replayer*> &replayers, 00028 const IceUtil::Time &beginTime, 00029 double replayRate, 00030 const orcaice::Context &context ); 00031 00032 // 'rate' is a multiple of real-time (ie >1.0 means faster-than-real-time) 00033 void setReplayRate( double rate ); 00034 00035 // Commence continuous playing (at the specified rate) 00036 // Equivalent to 'unpause'. 00037 void startPlaying(); 00038 00039 // Stop playing and remember current position 00040 void pausePlaying(); 00041 00042 // false if paused, not yet started, or at end of log 00043 // the 'aboutToStart' case is if we've received a Play event 00044 // but haven't processed it yet. 00045 bool isPlayingOrAboutToStart(); 00046 00047 // Step forward by one. Only valid when not playing. 00048 void stepForward(); 00049 00050 // Step backward by one. Only valid when not playing. 00051 void stepBackward(); 00052 00053 // Go forwards by the prescribed (relative) amount 00054 void fastForward( const IceUtil::Time &time ); 00055 00056 // go to the end of the log 00057 void fastForwardToEnd(); 00058 00059 // Go backwards by the prescribed (relative) amount 00060 void rewind( const IceUtil::Time &time ); 00061 00062 // Rewind to the start of the log and don't start playing again yet. 00063 void rewindToStartAndStop(); 00064 00065 // gets the time of the item we're about to play. 00066 // returns 'cursorValid' (is invalid at end of log) 00067 bool getCursorTime( int &sec, int &usec ); 00068 00069 void timeOfFirstItem( int &sec, int &usec ) const 00070 { sec = firstItemSec_; usec = firstItemUsec_; } 00071 00072 private: 00073 00074 // This is the main thread function. 00075 virtual void work(); 00076 00078 00079 enum EventType { 00080 SetReplayRate, 00081 Start, 00082 Pause, 00083 StepForward, 00084 StepBackward, 00085 FastForward, 00086 FastForwardToEnd, 00087 Rewind, 00088 RewindToStartAndStop 00089 }; 00090 // Helper class to represent events that are waiting to be 00091 // processed. The member variables are only valid for certain 00092 // event types. 00093 class Event { 00094 public: 00095 Event( EventType eventType ) 00096 : type_(eventType) 00097 {} 00098 Event( EventType eventType, double replayRate ) 00099 : type_(eventType), 00100 replayRate_(replayRate) 00101 {} 00102 Event( EventType eventType, const IceUtil::Time &t ) 00103 : type_(eventType), 00104 time_(t) 00105 {} 00106 EventType type() const { return type_; } 00107 double replayRate() const 00108 { 00109 assert( type_ == SetReplayRate ); 00110 return replayRate_; 00111 } 00112 const IceUtil::Time &time() const 00113 { 00114 assert( type_ == FastForward || type_ == Rewind ); 00115 return time_; 00116 } 00117 private: 00118 const EventType type_; 00119 double replayRate_; 00120 IceUtil::Time time_; 00121 }; 00122 00124 00125 // Convenience function which pushes the event and prints a message. 00126 void addEvent( const Event &e ); 00127 00128 void handleEvents(); 00129 // Returns: 00130 // 0: got time OK 00131 // -1: couldn't get time (eg because at end of file) 00132 int getTimeOfNextItem( IceUtil::Time &timeNextItem ); 00133 00134 void handleSetReplayRate( double rate ); 00135 void handleStart(); 00136 void handlePause(); 00137 void handleRewindToStartAndStop(); 00138 void handleFastForwardToEnd(); 00139 void handleRewind( const IceUtil::Time &deltaT ); 00140 void handleFastForward( const IceUtil::Time &deltaT ); 00141 void handleStepForward(); 00142 void handleStepBackward(); 00143 00144 // Catches its own exceptions. 00145 void replayData( int id, int index ); 00146 00147 bool isPlaying(); 00148 00149 std::string toString( EventType e ); 00150 std::string toString( const Event &e ); 00151 std::string toString( const IceUtil::Time &t ); 00152 00153 // Handles high-level commands 00154 std::queue<Event> eventQueue_; 00155 00156 IceUtil::Mutex mutex_; 00157 00158 // This is if we actually are playing 00159 bool isPlaying_; 00160 00161 // This is for outsiders: if we're either playing or have received 00162 // a Play event that's not processed yet. 00163 bool isPlayingOrAboutToStart_; 00164 00165 // The time of the first item 00166 int firstItemSec_, firstItemUsec_; 00167 00168 // The clock by which replay occurs (might not run in real-time). 00169 ReplayClock clock_; 00170 00171 orcalog::MasterFileReader &masterFileReader_; 00172 std::vector<orcalog::Replayer*> &replayers_; 00173 orcaice::Context context_; 00174 }; 00175 00176 } 00177 00178 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)