MIRA
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PolymorphicChannelBuffer Class Reference

A channel buffer for polymorphic types (classes derived from mira::Object) More...

#include <fw/ChannelBuffer.h>

Inheritance diagram for PolymorphicChannelBuffer:
Inheritance graph
[legend]

Public Types

typedef Stamped< Object * > ValueType
 

Public Member Functions

 PolymorphicChannelBuffer ()
 Constructor. More...
 
void promote (const Class *promotionClass)
 Promotes the polymorphic type of the channel to the given class type. More...
 
void cloneParameters (const ChannelBufferBase &other)
 Copies the parameters of other to this. More...
 
void setStorageDuration (const Duration &storageDuration)
 Sets the desired storage duration (the history). More...
 
void setAutoIncreaseStorageDuration (bool increase)
 Sets whether the storage duration is automatically increased on read accesses. More...
 
void setMinSlots (std::size_t minSlots)
 Sets the desired min. More...
 
void setMaxSlots (std::size_t maxSlots)
 Sets the max. More...
 
std::size_t getSize () const
 Returns the size of the buffer. More...
 
std::size_t getMaxSlots () const
 Returns the size of the max number of slots. More...
 
std::size_t getMinSlots () const
 Returns the size of the min number of slots. More...
 
Duration getStorageDuration () const
 Returns the storage duration. More...
 
bool isAutoIncreasingStorageDuration () const
 Returns whether the storage duration is automatically increased. More...
 
TypeMetaPtr getTypeMeta () const
 Returns the meta information for the slots type. More...
 
void setTypeMeta (TypeMetaPtr meta)
 Sets the meta information of the slot's type. More...
 
SlotrequestWriteSlot ()
 Returns a slot for writing, where the shared_mutex is already write locked. More...
 
bool finishWriteSlot (Slot *n, bool *dropped=nullptr)
 Adds written slot into buffer at the right time position. More...
 
void discardWriteSlot (Slot *n)
 Discards written slot. More...
 
SlotreadNewestSlot ()
 Returns the newest(latest) slot for reading, where the shared_mutex is already read locked. More...
 
SlotreadSlotAtTime (const Time &timestamp, SlotQueryMode mode, bool keepStorageDuration)
 Returns a slot at the given time according to mode. More...
 
void readInterval (const Time &timestamp, std::size_t nrSlots, std::size_t olderSlots, std::size_t newerSlots, IntervalFillMode fillMode, std::list< Slot *> &oSlots, bool keepStorageDuration)
 Reads an interval of slots. More...
 
void readInterval (const Time &from, const Time &to, std::list< Slot *> &oSlots, bool keepStorageDuration)
 Reads an interval of slots. More...
 
template<typename TargetType >
ChannelBufferBasepromote ()
 Promotes this buffer to the specified target type (if required). More...
 
void dbgDump (const std::string &prefix, bool brief=true)
 
void dbgCheckIntegrity ()
 
Implementation of TypedChannelBufferBase<Object*>
bool isPolymorphic () const override
 Returns true if the channel has a polymorphic type. More...
 
int getTypeId () const override
 Returns typeid of the slot values, the allocator creates. More...
 
Typename getTypename () const override
 Returns the Typename of the slot values, in contrast to getTypeId() the Typename is portable and unique between different processes and operating systems. More...
 
ChannelBufferBase::SlotallocateSlot () override
 Creates and returns a new slot. More...
 
void freeSlot (ChannelBufferBase::Slot *s) override
 Called to destroy the slot and free the used memory. More...
 
void fixateType () override
 Calling this method will fix the type of the ChannelBuffer. More...
 
void writeSerializedValue (ChannelBufferBase::Slot *s, Buffer< uint8 > data) override
 Write the given buffer (that contains binary serialized data WITHOUT the StampedHeader) to the slot. More...
 
Implementation of ChannelBufferBase
bool isTyped () const override
 Returns true, if the channel is typed and false, if it is untyped. More...
 
void setTypename (const Typename &name) override
 Sets the Typename of the slot values. More...
 
TypeMetaPtr createTypeMeta (ChannelBufferBase::Slot *s, MetaTypeDatabase &ioDB) override
 Creates meta information for data in slot and stores all meta information in the given database. More...
 
StampedHeadergetStampedHeader (ChannelBufferBase::Slot *s) override
 Returns a reference to the stamped header information. More...
 
const Buffer< uint8 > & readSerializedValue (ChannelBufferBase::Slot *s) override
 Returns a buffer containing the binary serialized data of the slot. More...
 
const Buffer< uint8 > & readSerializedValue (ChannelBufferBase::Slot *s, uint8 formatVersion, bool orLower) override
 Returns a buffer containing the binary serialized data of the slot. More...
 
Buffer< uint8readSerializedValue (ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs) override
 Returns a buffer containing the binary serialized data of the slot. More...
 
Buffer< uint8readSerializedValue (ChannelBufferBase::Slot *s, std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower) override
 Returns a buffer containing the binary serialized data of the slot. More...
 
void readJSON (ChannelBufferBase::Slot *s, JSONValue &oValue) override
 Reads data of that slot as json representation using a default-instantiated JSONSerializer. More...
 
void readJSON (ChannelBufferBase::Slot *s, JSONValue &oValue, JSONSerializer &serializer) override
 Reads data of that slot as json representation using the provided JSONSerializer. More...
 
void writeJSON (ChannelBufferBase::Slot *s, const JSONValue &value) override
 Writes data in json representation into the slot, using a default-instantiated JSONDeserializer. More...
 
void writeJSON (ChannelBufferBase::Slot *s, JSONDeserializer &deserializer) override
 Writes data from an initialized json deserializer into the slot. More...
 
void writeXML (ChannelBufferBase::Slot *s, const XMLDom::const_iterator &node) override
 Writes data in xml representation into the slot, using a default-instantiated XMLDeserializer and the name of the provided node. More...
 

Static Public Member Functions

static void dbgCheckListIntegrity (const ListItem &list)
 

Protected Member Functions

SlotcastSlot (ChannelBufferBase::Slot *s)
 Cast an abstract slot to a typed slot. More...
 
void clear ()
 Deletes all slots in all lists and therefore clears the whole buffer. More...
 

Protected Attributes

const ClassmMostDerivedClass
 
const ClassmFixatedClass
 

Detailed Description

A channel buffer for polymorphic types (classes derived from mira::Object)

Member Typedef Documentation

◆ ValueType

typedef Stamped<Object * > ValueType
inherited

Constructor & Destructor Documentation

◆ PolymorphicChannelBuffer()

Constructor.

Member Function Documentation

◆ isPolymorphic()

bool isPolymorphic ( ) const
inlineoverridevirtual

Returns true if the channel has a polymorphic type.

Implements ChannelBufferBase.

◆ getTypeId()

int getTypeId ( ) const
overridevirtual

Returns typeid of the slot values, the allocator creates.

Implements ChannelBufferBase.

◆ getTypename()

Typename getTypename ( ) const
overridevirtual

Returns the Typename of the slot values, in contrast to getTypeId() the Typename is portable and unique between different processes and operating systems.

Implements ChannelBufferBase.

◆ allocateSlot()

ChannelBufferBase::Slot* allocateSlot ( )
overridevirtual

Creates and returns a new slot.

Implements ChannelBufferBase.

◆ freeSlot()

void freeSlot ( ChannelBufferBase::Slot s)
overridevirtual

Called to destroy the slot and free the used memory.

Implements ChannelBufferBase.

◆ fixateType()

void fixateType ( )
overridevirtual

Calling this method will fix the type of the ChannelBuffer.

This method currently is used by the polymorphic buffer only. It will set the type of the buffer to the type that the buffer currently has, hence it fixates the type of the buffer and the buffer can not be promoted to any other type of a derived class.

Implements ChannelBufferBase.

◆ writeSerializedValue()

void writeSerializedValue ( ChannelBufferBase::Slot s,
Buffer< uint8 data 
)
overridevirtual

Write the given buffer (that contains binary serialized data WITHOUT the StampedHeader) to the slot.

Implements ChannelBufferBase.

◆ promote() [1/2]

void promote ( const Class promotionClass)

Promotes the polymorphic type of the channel to the given class type.

◆ castSlot()

Slot* castSlot ( ChannelBufferBase::Slot s)
inlineprotectedinherited

Cast an abstract slot to a typed slot.

◆ isTyped()

bool isTyped ( ) const
inlineoverridevirtualinherited

Returns true, if the channel is typed and false, if it is untyped.

Implements ChannelBufferBase.

◆ setTypename()

void setTypename ( const Typename name)
inlineoverridevirtualinherited

Sets the Typename of the slot values.

Implements ChannelBufferBase.

◆ createTypeMeta()

TypeMetaPtr createTypeMeta ( ChannelBufferBase::Slot s,
MetaTypeDatabase ioDB 
)
inlineoverridevirtualinherited

Creates meta information for data in slot and stores all meta information in the given database.

Implements ChannelBufferBase.

◆ getStampedHeader()

StampedHeader& getStampedHeader ( ChannelBufferBase::Slot s)
inlineoverridevirtualinherited

Returns a reference to the stamped header information.

Implements ChannelBufferBase.

◆ readSerializedValue() [1/4]

const Buffer<uint8>& readSerializedValue ( ChannelBufferBase::Slot s)
inlineoverridevirtualinherited

Returns a buffer containing the binary serialized data of the slot.

The serialized data does NOT contain any StampedHeader information.

Implements ChannelBufferBase.

◆ readSerializedValue() [2/4]

const Buffer<uint8>& readSerializedValue ( ChannelBufferBase::Slot s,
uint8  formatVersion,
bool  orLower 
)
inlineoverridevirtualinherited

Returns a buffer containing the binary serialized data of the slot.

The serialized data does NOT contain any StampedHeader information.

Parameters
formatVersionThe binary format version requested

Implements ChannelBufferBase.

◆ readSerializedValue() [3/4]

Buffer<uint8> readSerializedValue ( ChannelBufferBase::Slot s,
std::list< BinarySerializerCodecPtr > &  codecs 
)
inlineoverridevirtualinherited

Returns a buffer containing the binary serialized data of the slot.

The serialized data does NOT contain any StampedHeader information. For serialization it will use the specified codecs.

Implements ChannelBufferBase.

◆ readSerializedValue() [4/4]

Buffer<uint8> readSerializedValue ( ChannelBufferBase::Slot s,
std::list< BinarySerializerCodecPtr > &  codecs,
uint8  formatVersion,
bool  orLower 
)
inlineoverridevirtualinherited

Returns a buffer containing the binary serialized data of the slot.

The serialized data does NOT contain any StampedHeader information. For serialization it will use the specified codecs.

Parameters
formatVersionThe binary format version requested

Implements ChannelBufferBase.

◆ readJSON() [1/2]

void readJSON ( ChannelBufferBase::Slot s,
JSONValue oValue 
)
inlineoverridevirtualinherited

Reads data of that slot as json representation using a default-instantiated JSONSerializer.

Exceptions
XNotImplementedif not supported by the channel
Note
This method is only supported by typed channels or untyped channels with valid metadata.

Implements ChannelBufferBase.

◆ readJSON() [2/2]

void readJSON ( ChannelBufferBase::Slot s,
JSONValue oValue,
JSONSerializer serializer 
)
inlineoverridevirtualinherited

Reads data of that slot as json representation using the provided JSONSerializer.

Exceptions
XNotImplementedif not supported by the channel
Note
This method is only supported by typed channels or untyped channels with valid metadata.

Implements ChannelBufferBase.

◆ writeJSON() [1/2]

void writeJSON ( ChannelBufferBase::Slot s,
const JSONValue value 
)
inlineoverridevirtualinherited

Writes data in json representation into the slot, using a default-instantiated JSONDeserializer.

Exceptions
XNotImplementedif not supported by the channel
Note
That this method is only supported by typed channels or untyped channels with valid metadata.

Implements ChannelBufferBase.

◆ writeJSON() [2/2]

void writeJSON ( ChannelBufferBase::Slot s,
JSONDeserializer deserializer 
)
inlineoverridevirtualinherited

Writes data from an initialized json deserializer into the slot.

Exceptions
XNotImplementedif not supported by the channel
Note
That this method is only supported by typed channels or untyped channels with valid metadata.

Implements ChannelBufferBase.

◆ writeXML()

void writeXML ( ChannelBufferBase::Slot s,
const XMLDom::const_iterator node 
)
inlineoverridevirtualinherited

Writes data in xml representation into the slot, using a default-instantiated XMLDeserializer and the name of the provided node.

Exceptions
XNotImplementedif not supported by the channel
Note
That this method is only supported by typed channels

Implements ChannelBufferBase.

◆ cloneParameters()

void cloneParameters ( const ChannelBufferBase other)
inlineinherited

Copies the parameters of other to this.

◆ setStorageDuration()

void setStorageDuration ( const Duration storageDuration)
inherited

Sets the desired storage duration (the history).

This method can increase the duration only: if the specified duration is smaller than a previously set duration, the call will be ignored.

Note
Retaining slots for a desired duration means new slots must be created on all write requests before that duration has expired. New slots can only be created up to the slot number limit. If there is a conflict between the desired storage duration and the slot limit, the storage duration will not be guaranteed! Use setMaxSlots() to increase maximum number of slots.

◆ setAutoIncreaseStorageDuration()

void setAutoIncreaseStorageDuration ( bool  increase)
inherited

Sets whether the storage duration is automatically increased on read accesses.

If true, any read access specifying a timestamp will automatically increase the storage duration to the time difference between the timestamp and the most recent data (trying to ensure data is kept long enough for further such requests). The default is true.

◆ setMinSlots()

void setMinSlots ( std::size_t  minSlots)
inherited

Sets the desired min.

number of slots for storing the history of a channel. This method can increase the min. number of slots only. Instead of specifying the min. number of slots you can also specify the desired storage duration using the setStorageDuration() method.

Note
The desired number of slots can be increased until the maximum number of slots is reached. Use setMaxSlots() to increase maximum number of slots.

◆ setMaxSlots()

void setMaxSlots ( std::size_t  maxSlots)
inherited

Sets the max.

number of slots that are used for storing the history of a channel. maxSlots must at least be 1. The default is 100.

Note
There will only be as many slots as needed depending on the number of publishers and subscribers. The number of slots will also grow (history) if a storage duration is specified via setStorageDuration()

◆ getSize()

std::size_t getSize ( ) const
inherited

Returns the size of the buffer.

◆ getMaxSlots()

std::size_t getMaxSlots ( ) const
inherited

Returns the size of the max number of slots.

◆ getMinSlots()

std::size_t getMinSlots ( ) const
inherited

Returns the size of the min number of slots.

◆ getStorageDuration()

Duration getStorageDuration ( ) const
inherited

Returns the storage duration.

◆ isAutoIncreasingStorageDuration()

bool isAutoIncreasingStorageDuration ( ) const
inherited

Returns whether the storage duration is automatically increased.

◆ getTypeMeta()

TypeMetaPtr getTypeMeta ( ) const
inlineinherited

Returns the meta information for the slots type.

◆ setTypeMeta()

void setTypeMeta ( TypeMetaPtr  meta)
inlineinherited

Sets the meta information of the slot's type.

◆ requestWriteSlot()

Slot* requestWriteSlot ( )
inherited

Returns a slot for writing, where the shared_mutex is already write locked.

Implementation details:

Cycle of a slot:
newly created (requestWriteSlot, Step ..)
|
v
writing list
|finish |
v |discard
ring buffer |
|read |
v v
mWaitingOrFree
|
v

◆ finishWriteSlot()

bool finishWriteSlot ( Slot n,
bool *  dropped = nullptr 
)
inherited

Adds written slot into buffer at the right time position.

Returns true, if the new Slot value is now the newest value in the buffer. dropped is set to true, if a slot with the same timestamp already exists and hence the slot was discarded.

Note
The lock of the slot is unlocked.

◆ discardWriteSlot()

void discardWriteSlot ( Slot n)
inherited

Discards written slot.

Note
The lock of the slot is unlocked.

◆ readNewestSlot()

Slot* readNewestSlot ( )
inherited

Returns the newest(latest) slot for reading, where the shared_mutex is already read locked.

Returns NULL if no slot for reading is available.

◆ readSlotAtTime()

Slot* readSlotAtTime ( const Time timestamp,
SlotQueryMode  mode,
bool  keepStorageDuration 
)
inherited

Returns a slot at the given time according to mode.

Returns NULL if no slot exists. See mira::Channel::read() for more informations. Increases storage duration (history) automatically to serve future requests (if mAutoIncreaseStorageDuration is true and keepStorageDuration is false).

◆ readInterval() [1/2]

void readInterval ( const Time timestamp,
std::size_t  nrSlots,
std::size_t  olderSlots,
std::size_t  newerSlots,
IntervalFillMode  fillMode,
std::list< Slot *> &  oSlots,
bool  keepStorageDuration 
)
inherited

Reads an interval of slots.

See mira::Channel::readInterval for more information. Increases storage duration (history) automatically to serve future requests (if mAutoIncreaseStorageDuration is true and keepStorageDuration is false).

Exceptions
XInvalidReadif not enough data slots available in channel

◆ readInterval() [2/2]

void readInterval ( const Time from,
const Time to,
std::list< Slot *> &  oSlots,
bool  keepStorageDuration 
)
inherited

Reads an interval of slots.

See mira::Channel::readInterval for more informations. Increases storage duration (history) automatically to serve future requests (if mAutoIncreaseStorageDuration is true and keepStorageDuration is false).

Exceptions
XInvalidParameterif from > to

◆ promote() [2/2]

ChannelBufferBase * promote ( )
inherited

Promotes this buffer to the specified target type (if required).

This method may create and return a new ChannelBuffer of the desired TargetType. In this case the original buffer should be destroyed by the caller. In some other cases when no new buffer needs to be created the method returns a pointer to this buffer itself.

◆ clear()

void clear ( )
protectedinherited

Deletes all slots in all lists and therefore clears the whole buffer.

◆ dbgDump()

void dbgDump ( const std::string &  prefix,
bool  brief = true 
)
inherited

◆ dbgCheckListIntegrity()

static void dbgCheckListIntegrity ( const ListItem list)
staticinherited

◆ dbgCheckIntegrity()

void dbgCheckIntegrity ( )
inherited

Member Data Documentation

◆ mMostDerivedClass

const Class* mMostDerivedClass
protected

◆ mFixatedClass

const Class* mFixatedClass
protected

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