ADTF  3.13.0
requestable_writer< BaseWriter >

Writer that registers a request broker (cRequestBroker) at the connected sample stream. More...

Inheritance diagram for requestable_writer< BaseWriter >:
[legend]

Public Member Functions

 requestable_writer ()
 Default constructor.
 
tVoid SetCallbacks (std::function< void(tUInt32, const base::IProperties *)> fnEnable, std::function< void(tUInt32)> fnDisable)
 Sets the callbacks for activating and deactivating substreams. More...
 
tResult SetType (const ucom::ant::iobject_ptr< const ant::IStreamType > &pType) override
 
tResult ChangeType (const ucom::ant::iobject_ptr< const ant::IStreamType > &pType) override
 
tResult ChangeType (const ucom::ant::iobject_ptr< const ant::IStreamType > &pType, tBool bDisableCurrentRequests, tBool bCallDisableCallback)
 Writes a new Stream Type to the Sample Stream. More...
 
- Public Member Functions inherited from writer_with_request_broker< BaseWriter >
tVoid SetBroker (const ucom::ant::iobject_ptr< IStreamingRequests > &pBroker)
 Use this to set the broker instance after the writer has been created. More...
 
tResult BeginStreaming (streaming::ant::ISampleStream &oSampleStream) override
 
tResult EndStreaming () override
 

Private Attributes

ucom::ant::object_ptr< cRequestBrokerm_pBroker
 

Detailed Description

template<typename BaseWriter = adtf::streaming::cSampleWriter>
class adtf::streaming::hollow::requestable_writer< BaseWriter >

Writer that registers a request broker (cRequestBroker) at the connected sample stream.

Example Usage

#include <set>
#include <mutex>
class cMyFilter: public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cMyFilter, "my_filter.filter.example.cid", "My Filter");
cMyFilter()
{
CreateRunner("generate_samples");
m_pWriter = CreateOutputPin<adtf::streaming::requestable_writer<>>("output", oSubStreams);
m_pWriter->SetCallbacks([this](tUInt32 nSubStreamId, const adtf::base::IProperties*)
{
if (nSubStreamId > 2)
{
THROW_ERROR_DESC(ERR_INVALID_ARG, "No Substream with id %d available", nSubStreamId);
}
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
m_oEnabledSubStreams.insert(nSubStreamId);
},
[this](tUInt32 nSubStreamId)
{
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
m_oEnabledSubStreams.erase(nSubStreamId);
});
}
tResult Process(adtf::base::tNanoSeconds tmTrigger, adtf::streaming::IRunner* /*pRunner*/) override
{
++m_nTriggerCounter;
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
for (const auto& nSubStreamId: m_oEnabledSubStreams)
{
adtf::streaming::output_sample_data<tUInt32> oNewData(tmTrigger, m_nTriggerCounter, nSubStreamId);
m_pWriter->Write(oNewData.Release());
}
}
private:
std::mutex m_oSubStreamsLock;
std::set<tUInt32> m_oEnabledSubStreams;
tUInt32 m_nTriggerCounter = 0;
};

Definition at line 125 of file requestable_writer.h.

Member Function Documentation

◆ ChangeType()

tResult ChangeType ( const ucom::ant::iobject_ptr< const ant::IStreamType > &  pType,
tBool  bDisableCurrentRequests,
tBool  bCallDisableCallback 
)
inline

Writes a new Stream Type to the Sample Stream.

Parameters
[in]pTypeThe new Stream Type.
[in]bDisableCurrentRequestsIf true, current requests will be disabled.
[in]bCallDisableCallbackIf bDisableCurrentRequests was true, whether or not to call the disable callback for all ongoing requests.
Returns
Standard result.

Definition at line 171 of file requestable_writer.h.

◆ SetCallbacks()

tVoid SetCallbacks ( std::function< void(tUInt32, const base::IProperties *)>  fnEnable,
std::function< void(tUInt32)>  fnDisable 
)
inline

Sets the callbacks for activating and deactivating substreams.

Example Usage

#include <set>
#include <mutex>
class cMyFilter: public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cMyFilter, "my_filter.filter.example.cid", "My Filter");
cMyFilter()
{
CreateRunner("generate_samples");
m_pWriter = CreateOutputPin<adtf::streaming::requestable_writer<>>("output", oSubStreams);
m_pWriter->SetCallbacks([this](tUInt32 nSubStreamId, const adtf::base::IProperties*)
{
if (nSubStreamId > 2)
{
THROW_ERROR_DESC(ERR_INVALID_ARG, "No Substream with id %d available", nSubStreamId);
}
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
m_oEnabledSubStreams.insert(nSubStreamId);
},
[this](tUInt32 nSubStreamId)
{
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
m_oEnabledSubStreams.erase(nSubStreamId);
});
}
tResult Process(adtf::base::tNanoSeconds tmTrigger, adtf::streaming::IRunner* /*pRunner*/) override
{
++m_nTriggerCounter;
std::lock_guard<std::mutex> oGuard(m_oSubStreamsLock);
for (const auto& nSubStreamId: m_oEnabledSubStreams)
{
adtf::streaming::output_sample_data<tUInt32> oNewData(tmTrigger, m_nTriggerCounter, nSubStreamId);
m_pWriter->Write(oNewData.Release());
}
}
private:
std::mutex m_oSubStreamsLock;
std::set<tUInt32> m_oEnabledSubStreams;
tUInt32 m_nTriggerCounter = 0;
};
Parameters
[in,out]fnEnableCalled when the first consumer request samples of a substream.
[in,out]fnDisableCalled when the last consumer cancels its request for samples of a substream.

Definition at line 145 of file requestable_writer.h.


Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Tue Sep 28 2021 by doxygen 1.8.14)