Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FileSystemDataSource Class Reference

#include <FileSystemDataSource.h>

Inheritance diagram for FileSystemDataSource:

List of all members.


Detailed Description

Manages the loading of a series of files from disk.

Can handle an index file listing other data files and their timestamps, a directory holding a set of files, or a single explicit file.

Definition at line 16 of file FileSystemDataSource.h.


Public Member Functions

 FileSystemDataSource (LoggedDataDriver &p, const std::string &filter)
 constructor
 ~FileSystemDataSource ()
 destructor
virtual unsigned int nextTimestamp ()
 returns the simulator time of the next data segment
virtual const std::string & nextName ()
 returns a descriptive name of the next data segment for user feedback
virtual unsigned int getData (const char *&payload, unsigned int &payloadSize, unsigned int &timestamp, std::string &name)
 called to retrieve the most recent data segment, or blocking until new data is available
virtual void setDataSourceThread (LoadDataThread *th)
 called by the LoadDataThread subclass, allows you to register for properties which your subclass may care about
virtual void setDataSourceFramerate (float fr)
 called by LoadDataThread whenever the expected framerate changes (LoadDataThread::framerate)
virtual void setFrame (unsigned int f, unsigned int numPreload=2)
 sets the next frame to be sent (e.g. pass 0 to reset to the first frame)
virtual void nextFrame (unsigned int numPreload=2)
 increments curfile to the next frame, preparing (pre-loads) numPreload frames from the new curfile onward
virtual float getLoopTime (bool actual=true) const
 returns the total time taken to loop over the files
virtual void setLoopTime (float t)
 adds time to the final frame to increase total sequence time to t milliseconds
virtual bool usingIndexFile () const
 returns indexed
void clearFiles ()
 empties files
virtual void plistValueChanged (const plist::PrimitiveBase &pl)
virtual void loadXML (xmlNode *node)
virtual const std::string & getUsedPath () const
 returns the target path, either path, or parent.path if path is empty
virtual void loadFileList (bool clearCurrent=true, bool reportMissing=true)
 call this to (re)load the list of available file names from disk

Public Attributes

plist::Primitive< std::string > path
 The directory, data file, or index file from which to load via call to loadFileListFromDirectory(), loadSingleFile(), or loadFileListFromIndex().
plist::Primitive< std::string > filenameFilter
 a regular expression (POSIX.2 extended format) to select which files to load from path, if path is a directory or index file
plist::Primitive< bool > loop
 controls whether to restart curfile at the beginning of files when it reaches the end

Protected Types

typedef std::list< FileInfo * > files_t
 type of files, the list of files to load

Protected Member Functions

virtual void doFreeze ()
 user hook for when frozen is set to true
virtual void doUnfreeze ()
 user hook for when frozen is set to false
virtual void updateProvidingOutputs ()
 if thread is NULL, mark all outputs as ignored, and if thread is non-NULL, mark them all as provided
virtual void loadSingleFile (const std::string &file)
 load a single file
virtual void loadFileListFromDirectory ()
 load a list of files from a directory specified by path
virtual bool loadFileListFromIndex ()
 load a list of files from an index file specified by path
virtual float calcLoopTime () const
 adds up the lifetime of all files, plus initialDelay
virtual char * loadData (const std::string &file)
 does the actual work of loading and processing data from disk, subclasses should override this if they want to decompress/pre-parse the data
virtual void enqueueFile (const std::string &name, float lifetime)
 creates a new entry on files, virtual to allow subclasses to use a FileInfo subclass with more meta data (e.g. see FileSystemImageSource::ImageInfo)

Protected Attributes

files_t files
files_t::iterator curfile
 an iterator referencing files -- indicates next file to send
float initialDelay
 milliseconds to wait before sending first frame
float nextTime
 timestamp that curfile should be sent
bool indexed
 true if the file list was specified by an index file
unsigned int sn
 frame serial number, incremented by getData()
unsigned int freezeTime
 time at which doFreeze was called
LoggedDataDriverparent
 device driver this is a member of
float actualLoopTime
 time it would take to run through all of the loaded frames
float naturalLoopTime
 time it would take to run through all of the frames as set immediately after load (i.e. no setLoopTime())

Static Protected Attributes

static const unsigned int MAX_LOAD = 4000
 maximum number of data elements to try to keep 'active'. If there's more than this in files, we'll only load one at time, and immediately release it afterward

Classes

struct  FileInfo
 stores basic information regarding each file in the queue, including routines for loading to and from disk More...

Member Typedef Documentation

typedef std::list<FileInfo*> files_t [protected]

type of files, the list of files to load

Definition at line 131 of file FileSystemDataSource.h.


Constructor & Destructor Documentation

FileSystemDataSource ( LoggedDataDriver p,
const std::string &  filter 
) [inline]

constructor

Definition at line 19 of file FileSystemDataSource.h.

destructor

Definition at line 20 of file FileSystemDataSource.cc.


Member Function Documentation

unsigned int nextTimestamp (  )  [virtual]

returns the simulator time of the next data segment

should be in the future if nothing new since last data segment, otherwise should be the timestamp of the most recent data segment (older segments are skipped), return -1U if there is no more data

See also:
timestamp argument of getData()

Implements DataSource.

Definition at line 24 of file FileSystemDataSource.cc.

const std::string & nextName (  )  [virtual]

returns a descriptive name of the next data segment for user feedback

See also:
name argument of getData()

Implements DataSource.

Definition at line 28 of file FileSystemDataSource.cc.

unsigned int getData ( const char *&  payload,
unsigned int &  payloadSize,
unsigned int &  timestamp,
std::string &  name 
) [virtual]

called to retrieve the most recent data segment, or blocking until new data is available

Parameters:
[out] payload on return, should point to beginning of data segment, or NULL if none available
[out] payloadSize on return, should indicate size in bytes of data segment as payload
[in] timestamp the suggested return time; if multiple samples may be taken in the interval, they should be skipped until this time
[out] timestamp on return, should contain the time at which the data arrived (real time stream) or was scheduled to be sent (log on disk)
[out] name on return, a human-readable name for the frame -- e.g. filename for a data file loaded from disk
Returns:
frame serial number, used to tell when frames from the data source have been dropped (indicated by the return value incrementing by more than one)
If no more data is available, set payload to NULL, and return the current frame (i.e. don't increment serial number).

This call should block until data is available. Other functions may be called asynchronously from other threads while in this function, see ThreadNS::Lock to implement mutual exclusion locks if needed.

The input value of timestamp is a suggestion from the user's requested framerate -- try to return the frame closest to it. If it is already past (e.g. 0 on 'advance'), return the current data! If you return a timestamp in the future, the LoadDataThread will sleep until the appropriate time.

Note that this can be called when the source is frozen, which means you should unfreeze, get the current (unread) data or block until the next data, freeze again, and return the data.

Implements DataSource.

Definition at line 37 of file FileSystemDataSource.cc.

void setDataSourceThread ( LoadDataThread th  )  [virtual]

called by the LoadDataThread subclass, allows you to register for properties which your subclass may care about

a pointer to the LoadDataThread is passed when this is becoming the current data source; NULL will be passed when the data source is no longer being used

Reimplemented from DataSource.

Definition at line 67 of file FileSystemDataSource.cc.

void setDataSourceFramerate ( float  fr  )  [virtual]

called by LoadDataThread whenever the expected framerate changes (LoadDataThread::framerate)

Reimplemented from DataSource.

Definition at line 75 of file FileSystemDataSource.cc.

void setFrame ( unsigned int  f,
unsigned int  numPreload = 2 
) [virtual]

sets the next frame to be sent (e.g. pass 0 to reset to the first frame)

prepares (pre-loads) numPreload frames from the new curfile onward

Definition at line 133 of file FileSystemDataSource.cc.

void nextFrame ( unsigned int  numPreload = 2  )  [virtual]

increments curfile to the next frame, preparing (pre-loads) numPreload frames from the new curfile onward

Definition at line 151 of file FileSystemDataSource.cc.

Referenced by getData().

virtual float getLoopTime ( bool  actual = true  )  const [inline, virtual]

returns the total time taken to loop over the files

Parameters:
actual if false, will return the "natural" time of a loop, ignoring setLoopTime() effects

Definition at line 47 of file FileSystemDataSource.h.

Referenced by getData(), nextFrame(), LoggedDataDriver::plistValueChanged(), and setLoopTime().

void setLoopTime ( float  t  )  [virtual]

adds time to the final frame to increase total sequence time to t milliseconds

Definition at line 181 of file FileSystemDataSource.cc.

Referenced by LoggedDataDriver::plistValueChanged().

virtual bool usingIndexFile (  )  const [inline, virtual]

returns indexed

Definition at line 50 of file FileSystemDataSource.h.

Referenced by setDataSourceFramerate().

void clearFiles (  ) 

empties files

Definition at line 193 of file FileSystemDataSource.cc.

Referenced by loadFileList(), and ~FileSystemDataSource().

void plistValueChanged ( const plist::PrimitiveBase pl  )  [virtual]

Implements PrimitiveListener.

Definition at line 203 of file FileSystemDataSource.cc.

Referenced by loadXML().

void loadXML ( xmlNode node  )  [virtual]

Reimplemented from DictionaryBase.

Definition at line 211 of file FileSystemDataSource.cc.

const std::string & getUsedPath (  )  const [virtual]

returns the target path, either path, or parent.path if path is empty

Definition at line 90 of file FileSystemDataSource.cc.

Referenced by loadFileList(), loadFileListFromDirectory(), loadFileListFromIndex(), and LoggedDataDriver::plistValueChanged().

void loadFileList ( bool  clearCurrent = true,
bool  reportMissing = true 
) [virtual]

call this to (re)load the list of available file names from disk

If clearCurrent is set, then the current file list will be cleared; otherwise, the loaded files will be appended to the current queue

Definition at line 92 of file FileSystemDataSource.cc.

Referenced by LoggedDataDriver::plistValueChanged(), and plistValueChanged().

virtual void doFreeze (  )  [inline, protected, virtual]

user hook for when frozen is set to true

Reimplemented from DataSource.

Definition at line 78 of file FileSystemDataSource.h.

virtual void doUnfreeze (  )  [inline, protected, virtual]

user hook for when frozen is set to false

Reimplemented from DataSource.

Definition at line 79 of file FileSystemDataSource.h.

void updateProvidingOutputs (  )  [protected, virtual]

if thread is NULL, mark all outputs as ignored, and if thread is non-NULL, mark them all as provided

Reimplemented in FileSystemImageSource.

Definition at line 218 of file FileSystemDataSource.cc.

Referenced by setDataSourceThread().

void loadSingleFile ( const std::string &  file  )  [protected, virtual]

load a single file

Definition at line 228 of file FileSystemDataSource.cc.

Referenced by loadFileList().

void loadFileListFromDirectory (  )  [protected, virtual]

load a list of files from a directory specified by path

Definition at line 233 of file FileSystemDataSource.cc.

Referenced by loadFileList().

bool loadFileListFromIndex (  )  [protected, virtual]

load a list of files from an index file specified by path

This supports either the format produced by VisionGUI, or a simplier 'filename [<tab> time]\n' format, where if time is unspecified, the frame's time is incremented by the framerate from the previously listed file. Filenames should either be either absolute paths or relative to the directory which contains the index file.

Definition at line 295 of file FileSystemDataSource.cc.

Referenced by loadFileList().

float calcLoopTime (  )  const [protected, virtual]

adds up the lifetime of all files, plus initialDelay

Definition at line 173 of file FileSystemDataSource.cc.

Referenced by loadFileList().

char * loadData ( const std::string &  file  )  [protected, virtual]

does the actual work of loading and processing data from disk, subclasses should override this if they want to decompress/pre-parse the data

This implementation merely loads the data directly into memory with no processing or parsing.

Parameters:
[in] file full path of file to load
Returns:
pointer to the data, or NULL if error

Definition at line 362 of file FileSystemDataSource.cc.

virtual void enqueueFile ( const std::string &  name,
float  lifetime 
) [inline, protected, virtual]

creates a new entry on files, virtual to allow subclasses to use a FileInfo subclass with more meta data (e.g. see FileSystemImageSource::ImageInfo)

Reimplemented in FileSystemImageSource.

Definition at line 128 of file FileSystemDataSource.h.

Referenced by loadFileListFromDirectory(), loadFileListFromIndex(), and loadSingleFile().


Member Data Documentation

plist::Primitive<std::string> path

The directory, data file, or index file from which to load via call to loadFileListFromDirectory(), loadSingleFile(), or loadFileListFromIndex().

A single file can be either a single data file (e.g. sensor or camera image), or an index file as output by VisionGUI, or in the format 'filename <tab> time', where 'filename' is an absolute path or relative to the directory containing the index file, and 'time' is in milliseconds, relative to the time at which the index file is loaded.
In the future, this could also be network addresses for teleoperation and remote processing.

Definition at line 69 of file FileSystemDataSource.h.

Referenced by FileSystemDataSource(), getUsedPath(), loadXML(), LoggedDataDriver::LoggedDataDriver(), LoggedDataDriver::plistValueChanged(), plistValueChanged(), and setDataSourceFramerate().

a regular expression (POSIX.2 extended format) to select which files to load from path, if path is a directory or index file

Definition at line 72 of file FileSystemDataSource.h.

Referenced by FileSystemDataSource(), loadFileList(), loadFileListFromDirectory(), and loadFileListFromIndex().

controls whether to restart curfile at the beginning of files when it reaches the end

Definition at line 75 of file FileSystemDataSource.h.

Referenced by FileSystemDataSource(), loadFileList(), nextFrame(), and setFrame().

const unsigned int MAX_LOAD = 4000 [static, protected]

maximum number of data elements to try to keep 'active'. If there's more than this in files, we'll only load one at time, and immediately release it afterward

Definition at line 130 of file FileSystemDataSource.h.

Referenced by nextFrame(), and setFrame().

files_t::iterator curfile [protected]

an iterator referencing files -- indicates next file to send

Definition at line 133 of file FileSystemDataSource.h.

Referenced by clearFiles(), getData(), loadFileList(), nextFrame(), nextName(), nextTimestamp(), setDataSourceFramerate(), and setFrame().

float initialDelay [protected]

milliseconds to wait before sending first frame

Definition at line 134 of file FileSystemDataSource.h.

Referenced by calcLoopTime(), clearFiles(), loadFileListFromIndex(), and nextFrame().

bool indexed [protected]

true if the file list was specified by an index file

Definition at line 136 of file FileSystemDataSource.h.

Referenced by loadFileListFromDirectory(), loadFileListFromIndex(), loadSingleFile(), and usingIndexFile().

unsigned int sn [protected]

frame serial number, incremented by getData()

Definition at line 137 of file FileSystemDataSource.h.

Referenced by getData().

unsigned int freezeTime [protected]

time at which doFreeze was called

Definition at line 138 of file FileSystemDataSource.h.

Referenced by doFreeze(), doUnfreeze(), loadFileList(), and setFrame().

LoggedDataDriver& parent [protected]

device driver this is a member of

Definition at line 139 of file FileSystemDataSource.h.

Referenced by getUsedPath(), and setDataSourceFramerate().

float actualLoopTime [protected]

time it would take to run through all of the loaded frames

Definition at line 140 of file FileSystemDataSource.h.

Referenced by clearFiles(), getLoopTime(), loadFileList(), and setLoopTime().

float naturalLoopTime [protected]

time it would take to run through all of the frames as set immediately after load (i.e. no setLoopTime())

Definition at line 141 of file FileSystemDataSource.h.

Referenced by clearFiles(), getLoopTime(), and loadFileList().


The documentation for this class was generated from the following files:

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:01:21 2007 by Doxygen 1.5.4