Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BufferSource.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BufferSource_h_
00003 #define INCLUDED_BufferSource_h_
00004 
00005 #include "local/DataSource.h"
00006 #include "IPC/Thread.h"
00007 #include <vector>
00008 #include <string>
00009 
00010 //! description of BufferSource
00011 class BufferSource : public virtual DataSource {
00012 public:
00013   //! constructor
00014   BufferSource()
00015   : DataSource(), timestamp(-1U), name("BufferSource"), buffer(), reqTime(-1U),
00016   swapLock(), readySignal(), readyTimestamp(-1U), readyName(), readyBuffer(), isReady(false),
00017   frame(0)
00018   {}
00019   
00020   unsigned int timestamp; //!< value to return as timestamp of #buffer (or nextTimestamp())
00021   std::string name; //!< value to return as name of #buffer (or nextName())
00022   std::vector<char> buffer; //!< pointer to buffer for writing
00023   unsigned int reqTime; //!< requested timestamp by last call to getData(), or -1U if not called or no LoadDataThread registered
00024   
00025   virtual unsigned int nextTimestamp() { return timestamp; }
00026   virtual const std::string& nextName() { return name; }
00027   virtual unsigned int getData(const char *& payload, unsigned int& payloadSize, unsigned int& t, std::string& n);
00028   
00029   virtual void signalReady(); //!< swaps timestamp, name, and buffer with their "ready" counterparts
00030   
00031   virtual void setDataSourceThread(LoadDataThread* th) {
00032     if(th==NULL)
00033       reqTime=-1U;
00034     DataSource::setDataSourceThread(th);
00035   }
00036   
00037 protected:
00038   Thread::Lock swapLock; //!< lock while swapping during signalReady()
00039   Thread::Condition readySignal; //!< used to wake up sleeping thread in getData()
00040   unsigned int readyTimestamp; //!< the timestamp to report for #readyBuffer in getData()
00041   std::string readyName; //!< the name to report for #readyBuffer in getData()
00042   std::vector<char> readyBuffer; //!< the payload data to return in getData()
00043   bool isReady; //!< set to true when signalReady() is called, cleared by getData()
00044   unsigned int frame; //!< incremented for each call to signalReady();
00045 };
00046 
00047 /*! @file
00048  * @brief 
00049  * @author Ethan Tira-Thompson (ejt) (Creator)
00050  */
00051 
00052 #endif

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