root/juggler/branches/2.2/modules/gadgeteer/gadget/InputLogger.h

Revision 19729, 5.1 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #ifndef _GADGET_INPUT_LOGGER_H_
28 #define _GADGET_INPUT_LOGGER_H_
29
30 #include <gadget/gadgetConfig.h>
31 #include <vector>
32
33 #include <boost/smart_ptr.hpp>
34 #include <cppdom/cppdom.h>
35
36 #include <vpr/vpr.h>
37 #include <jccl/Config/ConfigElementPtr.h>
38
39 #include <gadget/Type/DigitalInterface.h>
40 #include <gadget/InputLoggerPtr.h>
41
42
43 namespace gadget
44 {
45
46 /** \class InputLogger InputLogger.h gadget/InputLogger.h
47  *
48  * Input data logger.
49  */
50 class GADGET_CLASS_API InputLogger
51 {
52 public:
53    InputLogger()
54       : mCurState(Inactive), mSleepFramesLeft(0), mLimitFrameRate(false)
55    {;}
56
57    /** Destructor. */
58    virtual ~InputLogger()
59    {;}
60
61    /** Configures the logger. */
62    virtual bool config(jccl::ConfigElementPtr element);
63
64    /**
65     * Processing function.
66     * This method is called by the input manager each update frame
67     * to allow the logger to do any processing that it needs
68     * to complete.
69     */
70    void process();
71
72 public:
73    /** @name Recording interface */
74    //@{
75    void startRecording();
76
77    void stopRecording();
78
79    /** Collect a stamp in the recording. */
80    void stampRecord();
81    //@}
82
83 public:
84    /** @name Playback interface */
85    //@{
86    /**
87     * Load a log file.
88     * @param logFilename The name of the log file to load.
89     */
90    void load(std::string logFilename);
91
92    /** Play the currently active log. */
93    void play();
94
95    /** Stop playing a log. */
96    void stop();
97
98    /** Pause log playback. */
99    void pause();
100
101    /** Get the stamp for the most recent sample
102    * @return Returns empty string if no active stamp.
103    */
104    std::string getStamp();
105    //@}
106
107 public:
108    /** @name Query methods */
109    //@{
110    bool getState()
111    {  return mCurState; }
112    //@}
113
114 protected:
115    /** @name Internal helpers */
116    //@{
117
118    void addRecordingSample();
119
120    void playNextSample();
121
122    /**
123     * Limit the framerate to the speed configured.
124     *
125     * @pre mLimitFrameRate == true
126     * @post Method will sleep until enough time passed to slow to configured
127     *       framerate.
128     */
129    void limitFramerate();
130    //@}
131
132    /**
133     * Eliminates duplicates in the current sampled data.
134     * It ignores the timestamp attribute.
135     */
136    void compressSamples();
137
138 public:
139    /** List of states that the Logger can be in. */
140    enum State
141    {
142       Inactive,   /**< The Logger is Inactive to be told what to do (i.e., doing nothing). */
143       Recording,  /**< The Logger is current recording. */
144       Playing,    /**< The Logger is currently playing. */
145       Paused      /**< The Logger is currently paused. */
146    };
147
148 private:
149    State       mCurState;        /**< The current state of the logger */
150
151    /**
152     * When the state becomes inactive, this is the number of frames that
153     * we wait before processing any input.
154     */
155    unsigned    mSleepFramesLeft;
156    std::string mActiveStamp;     /**< The active stamp for this frame */
157
158    unsigned                   mCompressFactor;  /**< Compression factor.  This is the number of duplicate frames to allow in a row */
159    std::vector<std::string>   mIgnoreElems;     /**< Elements to ignore when compressing */
160    std::vector<std::string>   mIgnoreAttribs;   /**< Attributes to ignore when compressing */
161
162    cppdom::NodePtr   mRootNode;           /**< Root node of the data */
163    std::string       mRecordingFilename;  /**< Filename to use for the recording */
164
165    bool              mLimitFrameRate;     /**< Flag. true - we should limit the framerate while logging */
166    vpr::Interval     mMinFrameTime;       /**< Minimum time we are to allow a frame to take */
167    vpr::Interval     mPrevFrameTimestamp; /**< Timestamp to use for calculating the current frame rate */
168
169    cppdom::NodeListIterator   mNextSample_i;    /**< Iterator pointing to the next sample to play */
170    cppdom::NodeListIterator   mEndSample_i;     /**< The end of the sample list to play */
171
172    gadget::DigitalInterface   mStartStopButton;    /**< Button for stopping and starting the logger */
173    gadget::DigitalInterface   mStampButton;        /**< Button for setting a stamp */
174 };
175
176 } // namespace gadget
177
178
179 #endif
Note: See TracBrowser for help on using the browser.