Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LoadDataThread Class Reference

#include <LoadDataThread.h>

Inheritance diagram for LoadDataThread:

List of all members.


Detailed Description

Provides resources for loading time-based data from disk.

Runs in a separate thread, preloads data into shared memory buffers, and then sends the buffer when the time is right. Thread doesn't start until you set the source or call loadFileList().

Definition at line 18 of file LoadDataThread.h.


Public Types

typedef void(DeviceDriver::* getDataSources_t )(std::map< std::string, DataSource * > &)
 member function pointer to call on DeviceDriver to get the data sources available for this thread

Public Member Functions

 LoadDataThread (getDataSources_t getDS, float fps, MessageQueueBase &messages)
 constructor
 ~LoadDataThread ()
 destructor
virtual bool advanceFrame (bool forceQueue)
 sends the next frame as soon as possible, blocking until sent
virtual void plistValueChanged (const plist::PrimitiveBase &pl)
virtual void plistCollectionEntryAdded (Collection &, ObjectBase &)
virtual void plistCollectionEntryRemoved (Collection &, ObjectBase &)
virtual void plistCollectionEntriesChanged (Collection &)
virtual void start ()
virtual void stop ()
virtual unsigned int nextTimestamp ()
virtual const std::string & nextName ()
virtual DataSourcegetDataSource ()
 returns curDS
virtual void dataSourcesUpdated ()
 destructor
std::string getAvailableDataSources ()
 called from constructor to build list of available data source names, resets the source help text
virtual void loadXML (xmlNode *node)

Static Public Member Functions

static char * deserializeHeader (char *buf, unsigned int size, unsigned int *verbose, unsigned int *sn, std::string *filename, bool *dataInQueue, unsigned int *payloadSize)
 recovers data from serialized IPC message, returns beginning of payload, or NULL if there's an error

Public Attributes

plist::Primitive< std::string > source
 Names the device driver from which the DataSource will be taken.
plist::Primitive< float > framerate
 frames per second to send -- this is only a suggestion to hardware devices, which generally use their 'native' framerate, but may use this to limit data flow
plist::Primitive< int > verbose
 Controls how much feedback to give on the console regarding progress.
plist::Primitive< bool > heartbeat
 if enabled, an empty "heartbeat" message is sent at the appropriate framerate, even if no data is being processed (i.e. no data loaded or out of frames); this will cause an update event within the simulator, repeating processing on the previous data.
plist::Primitive< bool > frozen
 if true, no frames will be sent, except via explicit (external) calls to advanceFrame(); if false, the thread will run and send messages at the requested times

Protected Types

enum  { INTERFRAME, GET_FRAME, GOT_FRAME, ADVANCE_FRAME }
typedef std::list< RCRegion * > msgbuf_t
 type of collection of shared data regions

Protected Member Functions

virtual void setDataSource (DeviceDriver *dd, DataSource *ds)
 Makes a data source eligible for providing data.
virtual unsigned int runloop ()
 monitor msgr, send new messages when their timestamp indicates they are due, then load upcoming messages
virtual RCRegionfirstUnusedRegion ()
 removes and returns first region in regions with only one reference, or NULL if none exists
virtual char * setupRegion (RCRegion *&region, const std::string &file, unsigned int payload, bool hasMoreData)
 sets up some header info in the specified RCRegion, reallocating if the suggested region is not large enough (or is NULL), returns pointer to end of header info in the region
virtual void freeRegion (RCRegion *rcr)
 removes our reference to a region created by loadFile()
virtual void sendHeartbeat ()
 sends an empty heartbeat message indicating previous data should be reused
virtual void sendHeartbeat (unsigned int curt)
 sends an empty heartbeat message indicating previous data should be reused, assuming that curt is the current time
unsigned int calcNextHeartbeat (unsigned int curt) const
 returns time of next heartbeat
unsigned int calcSleepTime ()

Protected Attributes

msgbuf_t regions
 for efficiency, reuse old buffers -- oldest at front, most recently used at back
getDataSources_t getDataSources
 member function pointer to be called on DeviceDriver to get its available data sources
MessageQueueBasemsgr
 the MessageQueue through which to send the data
Thread::Lock lock
 allows mutual exclusion over this object's member variables
float lastSent
 timestamp of most recently sent message (or heartbeat); -1 if hasn't sent any from current source
unsigned int frameSN
 serial number of next message to send
unsigned int sourceSN
 serial number of the last data from curDS; 0 if hasn't received any from current source
bool enabled
 set to true by start(), false by stop(), but reset if we call start or stop ourselves based on changes to freeze or heartbeat
enum LoadDataThread:: { ... }  runloopState
DataSourcecurDS
 pointer to the current data source
DeviceDriverdsDriver
 pointer to the data source's driver

Private Member Functions

 LoadDataThread (const LoadDataThread &)
 do not call
LoadDataThreadoperator= (const LoadDataThread &)
 do not call

Member Typedef Documentation

typedef void(DeviceDriver::* getDataSources_t)(std::map< std::string, DataSource * > &)

member function pointer to call on DeviceDriver to get the data sources available for this thread

typedef std::list<RCRegion* > msgbuf_t [protected]

type of collection of shared data regions

Definition at line 137 of file LoadDataThread.h.


Member Enumeration Documentation

anonymous enum [protected]

Enumerator:
INTERFRAME  runloop() is waiting between frames (usually heartbeats)
GET_FRAME  runloop() is getting a frame, should not be interrupted
GOT_FRAME  runloop() has gotten a frame and is waiting until its timestamp has arrived
ADVANCE_FRAME  runloop() was in GOT_FRAME, but advanceFrame() was called, frame should be sent *now*

Definition at line 149 of file LoadDataThread.h.


Constructor & Destructor Documentation

LoadDataThread ( getDataSources_t  getDS,
float  fps,
MessageQueueBase messages 
) [inline]

constructor

Parameters:
getDS a DeviceDriver member function callback, which will be used to query drivers for the data sources of they type being loaded by this thread
fps frames per second, see framerate
messages the MessageQueue through which to send the data
For example, there are sensor sources and camera/image sources, each managed by a different function of DeviceDriver (DeviceDriver::getSensorSources vs. DeviceDriver::getImageSources). The LoadDataThread is initialized to call one of these functions to acquire data sources based on which driver is referenced by source.

Definition at line 34 of file LoadDataThread.h.

~LoadDataThread (  ) 

destructor

Definition at line 16 of file LoadDataThread.cc.

LoadDataThread ( const LoadDataThread  )  [private]

do not call


Member Function Documentation

bool advanceFrame ( bool  forceQueue  )  [virtual]

sends the next frame as soon as possible, blocking until sent

Parameters:
forceQueue pass true to force a new data frame to be sent, otherwise will send a heartbeat if frozen
Returns:
true if there was a frame to send; will send heartbeat if configured, but returns false for heartbeats

safe to force the next frame ourselves

Definition at line 28 of file LoadDataThread.cc.

Referenced by Simulator::incrementTime().

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

Implements PrimitiveListener.

Definition at line 74 of file LoadDataThread.cc.

Referenced by dataSourcesUpdated(), and getAvailableDataSources().

virtual void plistCollectionEntryAdded ( Collection ,
ObjectBase  
) [inline, virtual]

Definition at line 85 of file LoadDataThread.h.

virtual void plistCollectionEntryRemoved ( Collection ,
ObjectBase  
) [inline, virtual]

Definition at line 86 of file LoadDataThread.h.

virtual void plistCollectionEntriesChanged ( Collection  )  [inline, virtual]

Definition at line 87 of file LoadDataThread.h.

void start (  )  [virtual]

Reimplemented from PollThread.

Definition at line 127 of file LoadDataThread.cc.

Referenced by plistValueChanged(), Simulator::resetSpeedMode(), and setDataSource().

void stop (  )  [virtual]

Reimplemented from Thread.

Definition at line 132 of file LoadDataThread.cc.

Referenced by plistValueChanged(), Simulator::resetSpeedMode(), Simulator::run(), and setDataSource().

char * deserializeHeader ( char *  buf,
unsigned int  size,
unsigned int *  verbose,
unsigned int *  sn,
std::string *  filename,
bool *  dataInQueue,
unsigned int *  payloadSize 
) [static]

recovers data from serialized IPC message, returns beginning of payload, or NULL if there's an error

each parameter can be a pointer where to store the field, or NULL if you don't care

Definition at line 170 of file LoadDataThread.cc.

Referenced by Main::gotCamera().

virtual unsigned int nextTimestamp (  )  [inline, virtual]

Definition at line 95 of file LoadDataThread.h.

Referenced by Simulator::getNextFrame().

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

Definition at line 96 of file LoadDataThread.h.

virtual DataSource* getDataSource (  )  [inline, virtual]

returns curDS

Definition at line 98 of file LoadDataThread.h.

virtual void dataSourcesUpdated (  )  [inline, virtual]

destructor

indicates a data source has been added or removed

Implements DeviceDriver::SourceListener.

Definition at line 100 of file LoadDataThread.h.

std::string getAvailableDataSources (  ) 

called from constructor to build list of available data source names, resets the source help text

Definition at line 210 of file LoadDataThread.cc.

Referenced by LoadDataThread(), loadXML(), plistCollectionEntriesChanged(), plistCollectionEntryAdded(), and plistCollectionEntryRemoved().

virtual void loadXML ( xmlNode node  )  [inline, virtual]

Reimplemented from DictionaryBase.

Definition at line 105 of file LoadDataThread.h.

void setDataSource ( DeviceDriver dd,
DataSource ds 
) [protected, virtual]

Makes a data source eligible for providing data.

This is protected because you shouldn't be calling it directly. Instead, set source to the driver instance name, which will cause this to be called via plistValueChanged

Definition at line 235 of file LoadDataThread.cc.

Referenced by plistValueChanged().

unsigned int runloop (  )  [protected, virtual]

monitor msgr, send new messages when their timestamp indicates they are due, then load upcoming messages

Reimplemented from Thread.

Definition at line 271 of file LoadDataThread.cc.

RCRegion * firstUnusedRegion (  )  [protected, virtual]

removes and returns first region in regions with only one reference, or NULL if none exists

Definition at line 138 of file LoadDataThread.cc.

Referenced by advanceFrame(), runloop(), and sendHeartbeat().

char * setupRegion ( RCRegion *&  region,
const std::string &  file,
unsigned int  payload,
bool  hasMoreData 
) [protected, virtual]

sets up some header info in the specified RCRegion, reallocating if the suggested region is not large enough (or is NULL), returns pointer to end of header info in the region

Definition at line 149 of file LoadDataThread.cc.

Referenced by advanceFrame(), runloop(), and sendHeartbeat().

virtual void freeRegion ( RCRegion rcr  )  [inline, protected, virtual]

removes our reference to a region created by loadFile()

Definition at line 125 of file LoadDataThread.h.

Referenced by setupRegion(), and ~LoadDataThread().

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

sends an empty heartbeat message indicating previous data should be reused

Definition at line 128 of file LoadDataThread.h.

Referenced by advanceFrame(), and runloop().

void sendHeartbeat ( unsigned int  curt  )  [protected, virtual]

sends an empty heartbeat message indicating previous data should be reused, assuming that curt is the current time

Definition at line 193 of file LoadDataThread.cc.

unsigned int calcNextHeartbeat ( unsigned int  curt  )  const [protected]

returns time of next heartbeat

Definition at line 205 of file LoadDataThread.cc.

Referenced by calcSleepTime().

unsigned int calcSleepTime (  )  [inline, protected]

Definition at line 135 of file LoadDataThread.h.

Referenced by runloop().

LoadDataThread& operator= ( const LoadDataThread  )  [private]

do not call


Member Data Documentation

plist::Primitive<std::string> source

Names the device driver from which the DataSource will be taken.

If you simply provide a device driver name, the first entry of the appropriate data queue will be used. Alternatively, use drivername.entryname to specify a specific data source entry in case the driver has multiple data sources for the queue type.

Definition at line 60 of file LoadDataThread.h.

Referenced by dataSourcesUpdated(), getAvailableDataSources(), LoadDataThread(), plistValueChanged(), and Simulator::run().

frames per second to send -- this is only a suggestion to hardware devices, which generally use their 'native' framerate, but may use this to limit data flow

Definition at line 63 of file LoadDataThread.h.

Referenced by calcNextHeartbeat(), LoadDataThread(), plistValueChanged(), runloop(), setDataSource(), and ~LoadDataThread().

Controls how much feedback to give on the console regarding progress.

0 - none
1 - report when message is sent
2 - also report when message is dropped
3 - also report when heartbeat is sent/dropped, and when loop occurs
4 - also report when each message is preloaded

Definition at line 71 of file LoadDataThread.h.

Referenced by advanceFrame(), LoadDataThread(), plistValueChanged(), runloop(), sendHeartbeat(), setDataSource(), setupRegion(), and ~LoadDataThread().

if enabled, an empty "heartbeat" message is sent at the appropriate framerate, even if no data is being processed (i.e. no data loaded or out of frames); this will cause an update event within the simulator, repeating processing on the previous data.

Definition at line 74 of file LoadDataThread.h.

Referenced by advanceFrame(), Simulator::getNextFrame(), LoadDataThread(), plistValueChanged(), runloop(), and start().

if true, no frames will be sent, except via explicit (external) calls to advanceFrame(); if false, the thread will run and send messages at the requested times

Definition at line 77 of file LoadDataThread.h.

Referenced by advanceFrame(), Simulator::getNextFrame(), LoadDataThread(), plistValueChanged(), runloop(), setDataSource(), start(), and ~LoadDataThread().

msgbuf_t regions [protected]

for efficiency, reuse old buffers -- oldest at front, most recently used at back

Definition at line 138 of file LoadDataThread.h.

Referenced by advanceFrame(), firstUnusedRegion(), runloop(), sendHeartbeat(), and ~LoadDataThread().

member function pointer to be called on DeviceDriver to get its available data sources

Definition at line 141 of file LoadDataThread.h.

Referenced by getAvailableDataSources(), and plistValueChanged().

MessageQueueBase& msgr [protected]

the MessageQueue through which to send the data

Definition at line 143 of file LoadDataThread.h.

Referenced by advanceFrame(), plistValueChanged(), runloop(), and sendHeartbeat().

Thread::Lock lock [protected]

allows mutual exclusion over this object's member variables

Definition at line 144 of file LoadDataThread.h.

Referenced by advanceFrame(), plistValueChanged(), runloop(), and ~LoadDataThread().

float lastSent [protected]

timestamp of most recently sent message (or heartbeat); -1 if hasn't sent any from current source

Definition at line 145 of file LoadDataThread.h.

Referenced by advanceFrame(), calcNextHeartbeat(), runloop(), sendHeartbeat(), and setDataSource().

unsigned int frameSN [protected]

serial number of next message to send

Definition at line 146 of file LoadDataThread.h.

Referenced by setupRegion().

unsigned int sourceSN [protected]

serial number of the last data from curDS; 0 if hasn't received any from current source

Definition at line 147 of file LoadDataThread.h.

Referenced by advanceFrame(), runloop(), and setDataSource().

bool enabled [protected]

set to true by start(), false by stop(), but reset if we call start or stop ourselves based on changes to freeze or heartbeat

Definition at line 148 of file LoadDataThread.h.

Referenced by plistValueChanged(), setDataSource(), start(), and stop().

enum { ... } runloopState [protected]

Referenced by advanceFrame(), runloop(), and stop().

DataSource* curDS [protected]

pointer to the current data source

Definition at line 156 of file LoadDataThread.h.

Referenced by advanceFrame(), getDataSource(), nextName(), nextTimestamp(), plistValueChanged(), runloop(), sendHeartbeat(), and setDataSource().

DeviceDriver* dsDriver [protected]

pointer to the data source's driver

Definition at line 157 of file LoadDataThread.h.

Referenced by setDataSource().


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

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