Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DataStreamDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_DataStreamDriver_h_
00003 #define INCLUDED_DataStreamDriver_h_
00004 
00005 #include "local/DeviceDriver.h"
00006 #include "local/DataSource.h"
00007 #include "local/CommPort.h"
00008 
00009 //! A generic base class for drivers which are receiving a stream of data through a comm port, also providing an interface to be used as a data source in another driver
00010 class DataStreamDriver : public virtual DeviceDriver, public DataSource, public virtual plist::PrimitiveListener, protected Thread  {
00011 public:
00012   explicit DataStreamDriver(const std::string& className, const std::string& localName)
00013   : DeviceDriver(className,localName), DataSource(),
00014   commName(), srcFrameRate(0), paceInput(false),
00015   timestamp(0), frameNumber(0), registered(false), realtime(false)
00016   {
00017     addEntry("CommPort",commName,"The name of the comm port from which data will be read.");
00018     addEntry("SourceFPS",srcFrameRate,"The expected source framerate, used to regulate buffering");
00019     addEntry("PaceInput",paceInput,"If set to false, the driver will attempt to detect and run through any backlog on the comm port; if true, the driver will process each image in turn, enforcing SourceFPS.\nThis mainly comes up if you do something like 'mkfifo pipe; cat *.jpg > pipe', and then open 'pipe' as the input for ImageStreamDriver... if PaceInput is turned off, you'll only get the last image.\nHowever, using PaceInput on 'live' sources may cause a backlog to form.");
00020   }
00021   
00022   virtual unsigned int nextTimestamp();
00023   virtual const std::string& nextName() { return instanceName; }
00024   virtual bool advance();
00025   virtual void registerSource();
00026   virtual void deregisterSource();
00027   
00028   //! The name of the comm port from which data will be read
00029   plist::Primitive<std::string> commName;
00030   
00031   //! The expected source framerate, used to regulate buffering
00032   plist::Primitive<float> srcFrameRate;
00033   
00034   //! If set to false, the driver will attempt to detect and run through any backlog on the comm port; if true, the driver will process each image in turn, enforcing SourceFPS.
00035   /*! This mainly comes up if you do something like 'mkfifo pipe; cat *.jpg > pipe', and then open 'pipe' as the input
00036    *  for ImageStreamDriver... if paceInput is turned off, you'll only get the last image.
00037    *  However, using PaceInput on 'live' sources may cause a backlog to form.*/
00038   plist::Primitive<bool> paceInput;
00039   
00040 protected:
00041   virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00042   
00043   virtual void* run();
00044   
00045   void doFreeze();
00046   void doUnfreeze();
00047   
00048   //! Called when data should be read from the specified data stream and then provided to the framework
00049   /*! If #paceInput is set, your implementation should use readsome() to skim through
00050    *  to the last available data packet, and provide only that data to the framework */
00051   virtual bool readData(std::istream& is)=0;
00052   
00053   //! allows subclasses to override the commport lookup
00054   virtual CommPort * getComm(const std::string& name) { return CommPort::getRegistry().getInstance(name); }
00055   //! called when connection initialization is required (opens comm port, etc.)
00056   virtual void connect(CommPort* comm);
00057   //! called when connection destruction is required (closes comm port, etc.)
00058   virtual void disconnect(CommPort* comm);
00059   //! called if no image data is readily available, should return true if thread should block for frame
00060   virtual bool requestFrame(CommPort& comm) { return false; }
00061   
00062   unsigned int timestamp; //!< timestamp of last data received
00063   unsigned int frameNumber; //!< image frame number
00064   
00065   bool registered; //!< true if registerSource has been called and deregisterSource has not
00066   bool realtime; //!< true if enteringRealtime has been called more recently than leavingRealtime
00067   
00068 private:
00069   //! holds the class name, set via registration with the DeviceDriver registry
00070   static const std::string autoRegisterDriver;
00071   DataStreamDriver(const DataStreamDriver&); //!< don't call
00072   DataStreamDriver& operator=(const DataStreamDriver&); //!< don't call
00073 };
00074 
00075 /*! @file
00076  * @brief Describes DataStreamDriver, a generic base class for drivers which are receiving a stream of data through a comm port, also providing an interface to be used as a data source in another driver
00077  * @author Ethan Tira-Thompson (ejt) (Creator)
00078  */
00079 
00080 #endif

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:38 2016 by Doxygen 1.6.3