20 #ifndef RTC_RINGBUFFER_H 21 #define RTC_RINGBUFFER_H 27 #include <coil/TimeValue.h> 28 #include <coil/Mutex.h> 29 #include <coil/Guard.h> 30 #include <coil/Condition.h> 31 #include <coil/stringutil.h> 36 #define RINGBUFFER_DEFAULT_LENGTH 8 88 template <
class DataType>
247 return ::RTC::BufferStatus::BUFFER_OK;
279 return ::RTC::BufferStatus::BUFFER_OK;
305 virtual DataType*
wptr(
long int n = 0)
345 (n < 0 && n < static_cast<long int>(-
m_fillcount)))
353 return ::RTC::BufferStatus::BUFFER_OK;
386 return ::RTC::BufferStatus::BUFFER_OK;
431 long int sec = -1,
long int nsec = 0)
448 if (overwrite && !timedwrite)
452 else if (!overwrite && !timedwrite)
454 return ::RTC::BufferStatus::BUFFER_FULL;
456 else if (!overwrite && timedwrite)
466 return ::RTC::BufferStatus::TIMEOUT;
491 return ::RTC::BufferStatus::BUFFER_OK;
567 virtual DataType*
rptr(
long int n = 0)
603 if ((n > 0 && n > static_cast<long int>(
m_fillcount)) ||
611 return ::RTC::BufferStatus::BUFFER_OK;
642 return ::RTC::BufferStatus::BUFFER_OK;
663 virtual DataType&
get()
712 long int sec = -1,
long int nsec = 0)
730 if (readback && !timedread)
734 return ::RTC::BufferStatus::BUFFER_EMPTY;
738 else if (!readback && !timedread)
740 return ::RTC::BufferStatus::BUFFER_EMPTY;
742 else if (!readback && timedread)
752 return ::RTC::BufferStatus::TIMEOUT;
777 return ::RTC::BufferStatus::BUFFER_OK;
838 if (!prop[
"length"].
empty())
853 std::string policy(prop[
"write.full_policy"]);
855 if (policy ==
"overwrite")
860 else if (policy ==
"do_nothing")
865 else if (policy ==
"block")
883 std::string policy(prop[
"read.empty_policy"]);
884 if (policy ==
"readback")
889 else if (policy ==
"do_nothing")
894 else if (policy ==
"block")
1057 #endif // RTC_RINGBUFFER_H bool m_overwrite
Overwrite flag.
coil::Mutex m_posmutex
mutex for position variable
size_t m_length
Buffer length.
void initReadPolicy(const coil::Properties &prop)
void initLength(const coil::Properties &prop)
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
bool m_timedread
Timedread flag.
virtual DataType * rptr(long int n=0)
Get the buffer length.
virtual ~RingBuffer(void)
Virtual destractor.
long int sec() const
Get value of second time scale.
virtual ReturnCode read(DataType &value, long int sec=-1, long int nsec=0)
Readout data from the buffer.
bool stringTo(To &val, const char *str)
Convert the given std::string to object.
virtual ReturnCode length(size_t n)
Get the buffer length.
std::vector< DataType > m_buffer
baffer array
#define RINGBUFFER_DEFAULT_LENGTH
virtual void init(const coil::Properties &prop)
Set the buffer.
virtual DataType * wptr(long int n=0)
Get the buffer length.
Enum
DataPortStatus return codes.
virtual ReturnCode reset()
Get the buffer length.
RingBuffer(long int length=RINGBUFFER_DEFAULT_LENGTH)
Constructor.
coil::TimeValue m_rtimeout
Timeout time of reading.
coil::Condition< coil::Mutex > cond
virtual bool full(void) const
Check on whether the buffer is full.
#define BUFFERSTATUS_ENUM
Importing RTC::BufferStatus macro.
BUFFERSTATUS_ENUM typedef coil::Guard< coil::Mutex > Guard
bool m_readback
Readback flag.
coil::TimeValue m_wtimeout
Timeout time for writing.
Buffer status enum definition.
virtual ReturnCode advanceWptr(long int n=1)
Get the buffer length.
void initWritePolicy(const coil::Properties &prop)
virtual ReturnCode write(const DataType &value, long int sec=-1, long int nsec=0)
Write data into the buffer.
prop
Organization::get_organization_property ();.
virtual size_t readable() const
Write data into the buffer.
virtual ReturnCode advanceRptr(long int n=1)
Get the buffer length.
condition m_empty
empty condition variable
Class represents a set of properties.
size_t m_wpos
pointer to write
struct for condition variable
bool m_timedwrite
Timedwrite flag.
virtual ReturnCode put(const DataType &value)
Write data into the buffer.
virtual size_t length(void) const
Get the buffer length.
size_t m_rpos
poitner to read
virtual bool empty(void) const
Check on whether the buffer is empty.
long int usec() const
Get value of micro second time scale.
size_t m_wcount
Counter for writing.
BufferBase abstract class.
size_t m_fillcount
Fill count.
virtual size_t writable() const
Write data into the buffer.
condition m_full
full condition variable