11 #ifndef GBXICEUTILACFR_BUFFER_H 12 #define GBXICEUTILACFR_BUFFER_H 15 #include <gbxutilacfr/exceptions.h> 17 #include <IceUtil/Monitor.h> 18 #include <IceUtil/Mutex.h> 19 #include <IceUtil/Time.h> 45 class Buffer :
public IceUtil::Monitor<IceUtil::Mutex>
86 void push(
const Type & obj );
100 void get( Type & obj )
const;
106 void get( Type & obj,
unsigned int n )
const;
134 std::deque<Type> queue_;
137 virtual void internalGet( Type & obj )
const ;
140 virtual void internalGet( Type & obj,
unsigned int n )
const ;
143 virtual void internalPush(
const Type & obj );
157 void getWithInfiniteWait( Type & obj );
183 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
192 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
200 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
207 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
214 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
215 return queue_.empty();
221 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
222 return queue_.size();
228 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
229 if ( queue_.empty() ) {
239 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
240 if ( !queue_.empty() )
253 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
254 if ( queue_.empty() ){
257 else if( n >= queue_.size()){
261 internalGet( obj ,n );
268 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
269 if ( !queue_.empty() )
284 if ( timeoutMs == -1 )
286 getWithInfiniteWait( obj );
291 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
294 if ( !queue_.empty() )
302 if ( this->timedWait( IceUtil::Time::milliSeconds( timeoutMs ) ) )
306 if ( !queue_.empty() )
325 int ret = getWithTimeout( obj, timeoutMs );
336 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
340 while ( queue_.empty() )
352 IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*
this);
355 if ( (
int)queue_.size() < depth_ || depth_<0 )
378 obj = queue_.front();
390 queue_.push_back( obj );
A thread-safe data pipe with buffer semantics.
Definition: buffer.h:45
void getAndPop(Type &obj)
Definition: buffer.h:266
Base class for all GbxUtilAcfr exceptions.
Definition: gbxutilacfr/exceptions.h:65
void pop()
Definition: buffer.h:226
int getWithTimeout(Type &obj, int timeoutMs=-1)
Definition: buffer.h:281
int depth() const
Returns buffer depth.
Definition: buffer.h:190
void configure(int depth, BufferType type=BufferTypeCircular)
Definition: buffer.h:178
void push(const Type &obj)
Definition: buffer.h:350
bool isEmpty() const
Returns FALSE if there's something in the buffer.
Definition: buffer.h:212
void purge()
Deletes all entries, makes the buffer empty.
Definition: buffer.h:205
Utility namespace (part of SICK-ACFR driver)
Definition: buffer.h:21
int size() const
Returns the number of items in the buffer.
Definition: buffer.h:219
int getAndPopWithTimeout(Type &obj, int timeoutMs=-1)
Definition: buffer.h:323
BufferType type() const
Returns buffer type.
Definition: buffer.h:198
BufferType
Buffer type defines behavior when the buffer is full
Definition: buffer.h:24
Buffer(int depth=-1, BufferType type=BufferTypeQueue)
Definition: buffer.h:165