DUDS
Distributed Update of Data from Something
duds::hardware::interface::Conversation Class Reference

Represents a two-way conversation with a device. More...

#include <Conversation.hpp>

Collaboration diagram for duds::hardware::interface::Conversation:

Public Types

typedef std::vector< std::unique_ptr< ConversationPart > > PartVector
 The storage type for the ConversationPart objects. More...
 

Public Member Functions

 Conversation ()=default
 
template<class CP >
void add (std::unique_ptr< CP > &cp)
 Adds an already constructed conversation part to the end of the conversation. More...
 
template<class CP >
CP & add (const CP &cp)
 Adds a copy of an existing conversation part to the end of the conversation. More...
 
ConversationExternaladdInputBuffer (char *a, std::size_t len)
 Adds a conversation part that will write input into the given buffer. More...
 
template<typename T , std::size_t N>
ConversationExternaladdInputBuffer (T(&a)[N])
 Adds a conversation part that will write input into the given array. More...
 
ConversationVectoraddInputVector (std::size_t len)
 Creates a new ConversationVector for fixed length input and initializes it with the given length. More...
 
template<class LengthType >
ConversationVectoraddInputVector (std::size_t len, LengthType lt)
 Creates a new ConversationVector for fixed or variable length input and initializes it with the given length. More...
 
ConversationExternaladdOutputBuffer (const char *a, std::size_t len)
 Adds a conversation part that will use the given buffer for output. More...
 
template<typename T , std::size_t N>
ConversationExternaladdOutputBuffer (const T(&a)[N])
 Adds a conversation part that will use the given array for output. More...
 
ConversationVectoraddOutputVector ()
 Creates a new ConversationVector for output and returns it for modification. More...
 
PartVector::iterator begin ()
 An iterator to the first ConversationPart that allows modification. More...
 
PartVector::const_iterator cbegin () const
 An iterator to the first ConversationPart that does not allow modification. More...
 
PartVector::const_iterator cend () const
 An iterator to the end of ConversationPart vector. More...
 
void clear ()
 Makes the conversation empty. More...
 
bool empty () const
 Returns true if the conversation has no parts. More...
 
PartVector::iterator end ()
 An iterator to the end of ConversationPart vector. More...
 
ConversationExtractor extract () const
 Returns an extraction object that can be used to read all the conversation data marked extractible. More...
 
std::size_t size () const
 Returns the number of parts within this conversation. More...
 

Protected Attributes

PartVector parts
 The container of the parts that make up the full conversation. More...
 

Detailed Description

Represents a two-way conversation with a device.

Output data is written prior to transmission, and input space is pre-allocated. The data is held in ConversationPart objects; there is no hard limit on the number of parts that can be added.

A Conversation can be used multiple times. Each time, input data will be overwritten. Output data can be reused rather than rewritten.

After using a Conversation for a transmission, the input is read using a ConversationExtractor object. It references the data held in the Conversation object rather than copy it, so the source Conversation must not be modified while the ConversationExtractor object is in use. The ConversationExtractor can outlive the Conversation, but it must not be used to read data from a destructed Conversation.

Author
Jeff Jackowski

Definition at line 52 of file Conversation.hpp.

Member Typedef Documentation

◆ PartVector

The storage type for the ConversationPart objects.

Definition at line 57 of file Conversation.hpp.

Constructor & Destructor Documentation

◆ Conversation()

duds::hardware::interface::Conversation::Conversation ( )
default

Member Function Documentation

◆ add() [1/2]

template<class CP >
void duds::hardware::interface::Conversation::add ( std::unique_ptr< CP > &  cp)
inline

Adds an already constructed conversation part to the end of the conversation.

Template Parameters
CPThe class of the conversation part.
Parameters
cpThe conversation part to add. The Conversation object will assume responsibility for the part.
Postcondition
cp will no longer hold the part object.

Definition at line 139 of file Conversation.hpp.

◆ add() [2/2]

template<class CP >
CP& duds::hardware::interface::Conversation::add ( const CP &  cp)
inline

Adds a copy of an existing conversation part to the end of the conversation.

Template Parameters
CPThe class of the conversation part. It must be derived from ConversationPart.
Parameters
cpThe conversation part to copy.
Returns
The added conversation part.

Definition at line 151 of file Conversation.hpp.

◆ addInputBuffer() [1/2]

ConversationExternal & duds::hardware::interface::Conversation::addInputBuffer ( char *  a,
std::size_t  len 
)

Adds a conversation part that will write input into the given buffer.

Parameters
aThe start of the buffer.
lenThe length of the buffer in bytes. The current implementation requires this length to be fixed rather than the maximum amount of a variable length input.

Definition at line 53 of file Conversation.cpp.

Referenced by addOutputBuffer().

◆ addInputBuffer() [2/2]

template<typename T , std::size_t N>
ConversationExternal& duds::hardware::interface::Conversation::addInputBuffer ( T(&)  a[N])
inline

Adds a conversation part that will write input into the given array.

Template Parameters
TThe element type of the array.
NThe length of the buffer in elements of T. The current implementation requires this length to be fixed rather than the maximum amount of a variable length input.
Parameters
aThe array.

Definition at line 216 of file Conversation.hpp.

◆ addInputVector() [1/2]

◆ addInputVector() [2/2]

template<class LengthType >
ConversationVector& duds::hardware::interface::Conversation::addInputVector ( std::size_t  len,
LengthType  lt 
)
inline

Creates a new ConversationVector for fixed or variable length input and initializes it with the given length.

Template Parameters
LengthTypeEither ConversationVector::FixedLength or ConversationVector::VaribleLength.
Parameters
lenThe length of the input in bytes.
ltThe length type object.

Definition at line 176 of file Conversation.hpp.

◆ addOutputBuffer() [1/2]

ConversationExternal & duds::hardware::interface::Conversation::addOutputBuffer ( const char *  a,
std::size_t  len 
)

Adds a conversation part that will use the given buffer for output.

Parameters
aThe start of the buffer.
lenThe length of the buffer in bytes.

Definition at line 44 of file Conversation.cpp.

Referenced by addInputVector().

◆ addOutputBuffer() [2/2]

template<typename T , std::size_t N>
ConversationExternal& duds::hardware::interface::Conversation::addOutputBuffer ( const T(&)  a[N])
inline

Adds a conversation part that will use the given array for output.

Template Parameters
TThe element type of the array.
NThe length of the array in elements of T.
Parameters
aThe array.

Definition at line 194 of file Conversation.hpp.

◆ addOutputVector()

ConversationVector & duds::hardware::interface::Conversation::addOutputVector ( )

◆ begin()

PartVector::iterator duds::hardware::interface::Conversation::begin ( )
inline

An iterator to the first ConversationPart that allows modification.

Definition at line 90 of file Conversation.hpp.

Referenced by duds::hardware::interface::linux::DevI2c::converse(), and duds::hardware::interface::MasterSyncSerial::converseAlreadyOpen().

◆ cbegin()

PartVector::const_iterator duds::hardware::interface::Conversation::cbegin ( ) const
inline

An iterator to the first ConversationPart that does not allow modification.

Definition at line 103 of file Conversation.hpp.

Referenced by duds::hardware::interface::ConversationExtractor::set().

◆ cend()

PartVector::const_iterator duds::hardware::interface::Conversation::cend ( ) const
inline

◆ clear()

◆ empty()

bool duds::hardware::interface::Conversation::empty ( ) const
inline

◆ end()

PartVector::iterator duds::hardware::interface::Conversation::end ( )
inline

◆ extract()

ConversationExtractor duds::hardware::interface::Conversation::extract ( ) const

Returns an extraction object that can be used to read all the conversation data marked extractible.

Postcondition
This Conversation object is not changed until the returned object is no longer used to read from this conversation.

Definition at line 59 of file Conversation.cpp.

Referenced by addInputBuffer().

◆ size()

std::size_t duds::hardware::interface::Conversation::size ( ) const
inline

Returns the number of parts within this conversation.

Definition at line 115 of file Conversation.hpp.

Referenced by duds::hardware::interface::linux::DevI2c::converse().

Member Data Documentation

◆ parts

PartVector duds::hardware::interface::Conversation::parts
protected

The container of the parts that make up the full conversation.

Definition at line 62 of file Conversation.hpp.

Referenced by addInputBuffer(), addInputVector(), addOutputBuffer(), and addOutputVector().


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