MIRA
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
ChannelWrite< T > Class Template Reference

An object that allows exclusive write access to data of a channel. More...

#include <fw/ChannelReadWrite.h>

Inheritance diagram for ChannelWrite< T >:
Inheritance graph
[legend]

Public Types

typedef boost::shared_ptr< SharedSharedPtr
 
typedef Shared::ChannelType ChannelType
 

Public Member Functions

 ChannelWrite ()
 Default constructor that constructs a ChannelWrite object that is invalid at the beginning and contains no data. More...
 
 ChannelWrite (ChannelTypePtr channel, Slot *slot)
 Is called by Channel to construct a valid ChannelWrite object with the corresponding data. More...
 
 operator ValueType & ()
 Allows to cast Reading Data from Channels and Writing to Channels easily into a reference of the wrapped data type. More...
 
ValueTypeoperator* ()
 Returns a reference on the data. More...
 
const ValueTypeoperator= (const ValueType &value)
 
ValueTypeoperator-> ()
 Returns a pointer on the data. More...
 
void writeSerializedValue (Buffer< uint8 > data)
 
void writeJSON (const JSONValue &value)
 
void writeJSON (JSONDeserializer &deserializer)
 
void finish ()
 Releases the lock explicitly and informs the Channel to signal all Subscribers that new data is available. More...
 
void discard ()
 Releases the lock explicitly WITHOUT informing the Channel and without signaling the subscribers. More...
 
Channel< T > getChannel ()
 Returns a write-only channel proxy object of the underlying channel. More...
 
bool isValid () const
 Returns true, if data was assigned to the ChannelRead or ChannelWrite and if this data is locked. More...
 
const std::string & getChannelID ()
 
std::string getTypename () const
 
TypeMetaPtr getTypeMeta () const
 
const TimegetTimestamp () const
 
int getUseCount () const
 Returns the number of shared instances for this data, may be useful for debugging purposes. More...
 
uint32 getFlags () const
 For internal use only. More...
 
void addFlags (uint32 moreFlags) const
 For internal use only. More...
 

Protected Types

typedef ChannelReadWriteBase< ChannelWrite< T >, T > Base
 
typedef Base::Shared Shared
 
typedef Base::ChannelTypePtr ChannelTypePtr
 
typedef Base::Slot Slot
 
typedef Base::ValueType ValueType
 

Protected Member Functions

ValueTypeinternalValue ()
 Returns a reference on the data. More...
 
const ValueTypeinternalValue () const
 Returns a const reference on the data. More...
 
void checkValid () const
 checks if we are still locked, if not it throws a XAccessViolation More...
 
const Buffer< uint8 > & readSerializedValue ()
 
const Buffer< uint8 > & readSerializedValue (uint8 formatVersion, bool orLower)
 
Buffer< uint8 > readSerializedValue (std::list< BinarySerializerCodecPtr > &codecs)
 Same as above, but allows to specify codecs for serialization. More...
 
Buffer< uint8 > readSerializedValue (std::list< BinarySerializerCodecPtr > &codecs, uint8 formatVersion, bool orLower)
 
void readJSON (JSONValue &oValue)
 
void readJSON (JSONValue &oValue, JSONSerializer &serializer)
 

Static Protected Member Functions

static void finish (Shared *shared)
 
static void discard (Shared *shared)
 

Protected Attributes

SharedPtr shared
 

Friends

class ChannelReadWriteShared< ChannelWrite< T > >
 

Detailed Description

template<typename T>
class mira::ChannelWrite< T >

An object that allows exclusive write access to data of a channel.

Use Channel::write() to obtain access to data of a channel.

The ChannelWrite automatically take care that the data is unlocked if the ChannelWrite object is no longer used and went out of scope. To explicitly release the data by calling the finish() method.

After the ChannelWrite released the lock to the data it automatically informs the channel that new data is available. The channel itself will then inform all subscribers of that channel.

You can freely copy and reassign the ChannelWrite object to other ChannelWrite variables. The ChannelWrite contains an internal reference counting mechanism. The lock is freed only after all copies have been destroyed or one copy called the finish() method.

Examples:
tutorials/MeanCalculator.C, and tutorials/MeanCalculatorWithProperties.C.

Member Typedef Documentation

◆ Base

typedef ChannelReadWriteBase<ChannelWrite<T>, T> Base
protected

◆ Shared

typedef Base::Shared Shared
protected

◆ ChannelTypePtr

◆ Slot

typedef Base::Slot Slot
protected

◆ ValueType

typedef Base::ValueType ValueType
protected

◆ SharedPtr

typedef boost::shared_ptr<Shared> SharedPtr
inherited

◆ ChannelType

typedef Shared::ChannelType ChannelType
inherited

Constructor & Destructor Documentation

◆ ChannelWrite() [1/2]

ChannelWrite ( )
inline

Default constructor that constructs a ChannelWrite object that is invalid at the beginning and contains no data.

Before you can use the object you need to assign a valid ChannelWrite object that was obtained using Channel::write().

You can use the isValid() method to check if a ChannelWrite object is valid and contains locked data.

◆ ChannelWrite() [2/2]

ChannelWrite ( ChannelTypePtr  channel,
Slot slot 
)
inline

Is called by Channel to construct a valid ChannelWrite object with the corresponding data.

Note
You should never need to use this constructor directly!

Member Function Documentation

◆ operator ValueType &()

operator ValueType & ( )
inline

Allows to cast Reading Data from Channels and Writing to Channels easily into a reference of the wrapped data type.

Exceptions
XRuntime,ifthe lock on the data was lost, e.g. by calling the finish() method

◆ operator*()

ValueType& operator* ( )
inline

Returns a reference on the data.

This is essentially the same as calling internalValue() but simplifies the usage similar to STL-iterators.

Exceptions
XRuntime,ifthe lock on the data was lost, e.g. by calling the finish() method

◆ operator=()

const ValueType& operator= ( const ValueType value)
inline

◆ operator->()

ValueType* operator-> ( )
inline

Returns a pointer on the data.

This simplifies the usage similar to STL-iterators:

stuct MyClass {
void foo();
}
ChannelRead<MyClass> data = ...;
data->foo(); // directly calls foo() of MyClass
Exceptions
XRuntime,ifthe lock on the data was lost, e.g. by calling the finish() method

◆ writeSerializedValue()

void writeSerializedValue ( Buffer< uint8 >  data)
inline

◆ writeJSON() [1/2]

void writeJSON ( const JSONValue value)
inline

◆ writeJSON() [2/2]

void writeJSON ( JSONDeserializer deserializer)
inline

◆ finish() [1/2]

void finish ( )
inline

Releases the lock explicitly and informs the Channel to signal all Subscribers that new data is available.

Note
After calling this method accessing the data results in an XRuntime exception.

◆ discard() [1/2]

void discard ( )
inline

Releases the lock explicitly WITHOUT informing the Channel and without signaling the subscribers.

Hence the content that was written will be ignored and discarded. You can use this method, e.g. if you notice an error while writing into the WriteChannel data and want to abort the whole writing process.

◆ getChannel()

Channel<T> getChannel ( )

Returns a write-only channel proxy object of the underlying channel.

◆ finish() [2/2]

static void finish ( Shared shared)
inlinestaticprotected

◆ discard() [2/2]

static void discard ( Shared shared)
inlinestaticprotected

◆ internalValue() [1/2]

ValueType& internalValue ( )
inlineprotectedinherited

Returns a reference on the data.

Exceptions
ThrowsXRuntime, if the lock on the data was lost, e.g. by calling the finish() method

◆ internalValue() [2/2]

const ValueType& internalValue ( ) const
inlineprotectedinherited

Returns a const reference on the data.

Exceptions
ThrowsXRuntime, if the lock on the data was lost, e.g. by calling the finish() method

◆ isValid()

bool isValid ( ) const
inlineinherited

Returns true, if data was assigned to the ChannelRead or ChannelWrite and if this data is locked.

If this method returns true, you can safely access the underlying data.

If this method returns false, no data was assigned to the ChannelRead / ChannelWrite or the lock on the data was lost. Hence, it is not safe to access the underlying data. If you try to access the data anyway you will get an XRuntime exception.

◆ getChannelID()

const std::string& getChannelID ( )
inlineinherited

◆ getTypename()

std::string getTypename ( ) const
inlineinherited

◆ getTypeMeta()

TypeMetaPtr getTypeMeta ( ) const
inlineinherited

◆ getTimestamp()

const Time& getTimestamp ( ) const
inlineinherited

◆ getUseCount()

int getUseCount ( ) const
inlineinherited

Returns the number of shared instances for this data, may be useful for debugging purposes.

◆ getFlags()

uint32 getFlags ( ) const
inlineinherited

For internal use only.

Used by remote components of the framework and by player and recorder. Returns current flags of this slot;

◆ addFlags()

void addFlags ( uint32  moreFlags) const
inlineinherited

For internal use only.

Used by remote components of the framework and by player and recorder. Add additional flags to the slots flags.

◆ checkValid()

void checkValid ( ) const
inlineprotectedinherited

checks if we are still locked, if not it throws a XAccessViolation

◆ readSerializedValue() [1/4]

const Buffer<uint8>& readSerializedValue ( )
inlineprotectedinherited

◆ readSerializedValue() [2/4]

const Buffer<uint8>& readSerializedValue ( uint8  formatVersion,
bool  orLower 
)
inlineprotectedinherited

◆ readSerializedValue() [3/4]

Buffer<uint8> readSerializedValue ( std::list< BinarySerializerCodecPtr > &  codecs)
inlineprotectedinherited

Same as above, but allows to specify codecs for serialization.

◆ readSerializedValue() [4/4]

Buffer<uint8> readSerializedValue ( std::list< BinarySerializerCodecPtr > &  codecs,
uint8  formatVersion,
bool  orLower 
)
inlineprotectedinherited

◆ readJSON() [1/2]

void readJSON ( JSONValue oValue)
inlineprotectedinherited

◆ readJSON() [2/2]

void readJSON ( JSONValue oValue,
JSONSerializer serializer 
)
inlineprotectedinherited

Friends And Related Function Documentation

◆ ChannelReadWriteShared< ChannelWrite< T > >

friend class ChannelReadWriteShared< ChannelWrite< T > >
friend

Member Data Documentation

◆ shared

SharedPtr shared
protectedinherited

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