AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T > Class Template Reference

#include <Writer.h>


struct  Error

Public Types

using Policy = WriterPolicy
 Specifies the policy to use for writing to the stream. More...

Public Member Functions

 Writer (Policy policy, std::shared_ptr< BufferLayout > bufferLayout)
 ~Writer ()
 This destructor detaches the Writer from a BufferLayout. More...
ssize_t write (const void *buf, size_t nWords, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Index tell () const
void close ()
size_t getWordSize () const

Static Public Member Functions

static std::string errorToString (Error error)

Detailed Description

template<typename T>
class alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >

This is a nested class in SharedDataStream which provides an interface for writing (producing) data to the stream.

This class is primarily intended to be used from a single thread. The Writer as a whole is thread-safe in the sense that Writer and Readers can all live in different threads, but individual member functions of a Writer instance should not be called from multiple threads except where specifically noted in function documentation below.

Member Typedef Documentation

◆ Policy

Specifies the policy to use for writing to the stream.

Constructor & Destructor Documentation

◆ Writer()

template<typename T >
alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::Writer ( Policy  policy,
std::shared_ptr< BufferLayout bufferLayout 

Constructs a new Writer which produces data for the provided SharedDataStream.

policyThe policy to use for reading from the stream.
streamThe BufferLayout to use for writing stream data.

◆ ~Writer()

This destructor detaches the Writer from a BufferLayout.

Member Function Documentation

◆ close()

template<typename T >
void alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::close ( )

This function closes the Writer, such that Readers will return 0 when they catch up with the Writer, and subsequent calls to write() will return 0.

◆ errorToString()

template<typename T >
std::string alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::errorToString ( Error  error)

Returns the text of an error code.

Text of the specified error.

◆ getWordSize()

template<typename T >
size_t alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::getWordSize ( ) const

This function returns the word size (in bytes). All SharedDataStream operations that work with data or position in the stream are quantified in words.

The size (in bytes) of words for this Writer's SharedDataStream.

◆ tell()

template<typename T >
SharedDataStream< T >::Index alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::tell ( ) const

This function reports the current position of the Writer in the stream.

The Writer's position (in wordSize words) in the stream.

◆ write()

template<typename T >
ssize_t alexaClientSDK::avsCommon::utils::sds::SharedDataStream::Writer< T >::write ( const void *  buf,
size_t  nWords,
std::chrono::milliseconds  timeout = std::chrono::milliseconds(0) 

This function adds new data to the stream by copying it from the provided buffer.

bufA buffer to copy the data from.
nWordsThe maximum number of wordSize words to copy.
timeoutThe maximum time to wait (if policy is BLOCKING) for space to write into. If this parameter is zero, there is no timeout and blocking writes will wait forever. If policy is not BLOCKING, this parameter is ignored.
The number of wordSize words copied, or zero if the stream has closed, or a negative Error code if the stream is still open, but no data could be written.
A stream is closed for the Writer if Writer::close() has been called.
If policy is BLOCKING and timeout is 0, this function will only unblock when a Reader read()s some data or seek()s forward. Applications which use this combination of parameters must use Readers to drain some data from the SharedDataStream if they need to unblock the Writer.

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

AlexaClientSDK 3.0.0 - Copyright 2016-2022, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0