ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
samplewriter.h
Go to the documentation of this file.
1
7#pragma once
8#include "samplestream_intf.h"
10#include "sample_intf.h"
11#include "streamtype_intf.h"
12#include "samplestreamer_intf.h"
13#include "pin.h"
14#include "sample.h"
15#include "samplereader.h"
17
19
20
21namespace adtf
22{
23namespace streaming
24{
25namespace ant
26{
34class cSampleWriter : public sample_streamer<ISampleWriter, cOutPin>
35{
36protected:
39
42
43protected:
45
46public:
49 {
50 }
51
53 {
54 }
55
58 cSampleWriter(const char* strName, const ucom::ant::iobject_ptr<const IStreamType>& pStreamType):
59 base_type(strName, pStreamType)
60 {
61 }
62
63 tResult BeginStreaming(ISampleStream& oSampleStream) override
64 {
66
68
69 if (pConstType)
70 {
71 RETURN_IF_FAILED(m_pOutStream->Write(pConstType));
72 }
73
74 if (_runtime)
75 {
76 _runtime->GetObject(_clock);
77 }
78
80 }
81
83 {
84 _clock.Reset();
85 m_pOutStream.Reset();
87 }
88
89public: //Streaming Functions for
96 {
97 if (m_pOutStream)
98 {
99 return m_pOutStream->Write(pSample);
100 }
101 else
102 {
103 RETURN_ERROR(ERR_INVALID_STATE);
104 }
105 }
106
113 {
114 if (m_pOutStream)
115 {
116 return m_pOutStream->Write(pType);
117 }
118 else
119 {
120 return SetType(pType);
121 }
122 }
123
128 virtual tResult Flush()
129 {
130 if (m_pOutStream)
131 {
132 return m_pOutStream->Flush();
133 }
134 else
135 {
136 RETURN_ERROR(ERR_INVALID_STATE);
137 }
138 }
139
146 {
147 if (m_pOutStream)
148 {
149 return m_pOutStream->SetStreamError(oErr);
150 }
151 else
152 {
153 RETURN_ERROR(ERR_INVALID_STATE);
154 }
155 }
156
165 {
166 if (m_poPin)
167 {
168 tTimeStamp tmTime = _clock ? _clock->GetStreamTime() : adtf::util::cSystem::GetTime();
169 return m_poPin->Run(tmTime, base::ant::IRunnable::RUN_TRIGGER, nullptr, 0);
170 }
171 RETURN_ERROR(ERR_NOT_INITIALIZED);
172 }
173};
174
185{
186 oSampleWriter.Transmit(pSample);
187 return oSampleWriter;
188}
189
199{
200 oSampleWriter.Transmit(ucom::ucom_object_ptr_cast<const ISample>(pSample));
201 return oSampleWriter;
202}
203
212{
213 oSampleWriter.ChangeType(pType);
214 return oSampleWriter;
215}
216
224inline cSampleWriter& operator<<(cSampleWriter& oSampleWriter, cSampleWriter& (*pStreamfunc)(cSampleWriter&) )
225{
226 return pStreamfunc(oSampleWriter);
227}
228
236inline cSampleWriter& operator<<(cSampleWriter& oSampleWriter, const tResult& oError)
237{
238 oSampleWriter.SetStreamError(oError);
239 return oSampleWriter;
240}
241
246template<typename DATA_TYPE>
248{
249public:
290 tResult Transmit(const DATA_TYPE& oSampleData)
291 {
294 tTimeStamp tmTime = _clock ? _clock->GetStreamTime() : adtf_util::cSystem::GetTime();
295 RETURN_IF_FAILED(pSample->Set(tmTime, &oSampleData, sizeof(DATA_TYPE)));
297 }
298};
299
309template<typename DATA_TYPE>
310ADTF3_DEPRECATED("Writing data with no concrete sample time is deprecated. Use sample_writer<DATA_TYPE>::Write(tmTime, oSampleData) instead.")
311sample_writer<DATA_TYPE>& operator<<(sample_writer<DATA_TYPE>& oSampleWriter, const DATA_TYPE& oSampleData)
312{
313 oSampleWriter.Transmit(oSampleData);
314 return oSampleWriter;
315}
316
324inline cSampleReader& operator>>(cSampleReader& oSampleReader, cSampleWriter& oSampleWriter)
325{
327 while (IS_OK(oSampleReader.GetNextSample(pSample)))
328 {
329 oSampleWriter << pSample;
330 };
331 return oSampleReader;
332}
333
341 const char* strNameOfWriter,
343{
344 oWriter.SetName(strNameOfWriter);
345 return oWriter.SetType(pStreamType);
346}
347
348} //namespace ant
349
350namespace flash
351{
355class cSampleWriter : public ISampleWriter
356{
357public:
358 cSampleWriter();
359 ~cSampleWriter() override;
360
361 void SetName(const char* strName) override;
362 tResult GetName(base::ant::IString&& strName) override;
363
366
367 tResult BeginStreaming(ISampleStream& oSampleStream) override;
369
371
373
379
381 tResult Flush() override;
384
385protected:
386 class cImplementation;
387 std::unique_ptr<cImplementation> m_pImplementation;
388};
389
390inline tResult make_sample_writer(ISampleWriter& oWriter,
391 const char* strNameOfWriter,
393{
394 oWriter.SetName(strNameOfWriter);
395 return oWriter.SetType(pStreamType);
396}
397
407{
408 THROW_IF_FAILED(oSampleWriter.Write(pSample));
409 return oSampleWriter;
410}
411
421{
422 THROW_IF_FAILED(oSampleWriter.ChangeType(pType));
423 return oSampleWriter;
424}
425
434inline ISampleWriter& operator<<(ISampleWriter& oSampleWriter, ISampleWriter& (*pStreamfunc)(ISampleWriter&) )
435{
436 return pStreamfunc(oSampleWriter);
437}
438
447inline ISampleWriter& operator<<(ISampleWriter& oSampleWriter, const tResult& oError)
448{
449 THROW_IF_FAILED(oSampleWriter.SetStreamError(oError));
450 return oSampleWriter;
451}
452
462template<typename DATA_TYPE>
463inline ISampleWriter& operator<<(ISampleWriter& oSampleWriter, output_sample_data<DATA_TYPE>&& oOutputSampleData)
464{
465 THROW_IF_FAILED(oSampleWriter.Write(oOutputSampleData.Release()));
466 return oSampleWriter;
467}
468
469inline ISampleReader& operator>>(ISampleReader& oSampleReader, ISampleWriter& oSampleWriter)
470{
472 while (IS_OK(oSampleReader.GetNextSample(pSample)))
473 {
474 oSampleWriter << pSample;
475 };
476 return oSampleReader;
477}
478
488template<typename DATA_TYPE, typename BASE = cSampleWriter>
489class sample_writer : public BASE
490{
491public:
497 {
498 _runtime->GetObject(m_pClock);
499 }
500
501 using BASE::Write;
502 using BASE::Transmit;
503
512 ADTF3_DEPRECATED("Writing data with no concrete sample time is deprecated. Use "
513 "sample_writer<DATA_TYPE>::Write(tmTime, oSampleData) instead.")
514 tResult Write(const DATA_TYPE& oSampleData)
515 {
516 auto tmTime = m_pClock ? m_pClock->GetStreamTimeNs() : base::flash::duration_cast<base::flash::tNanoSeconds>(adtf_util::cSystem::GetTime());
517 return Write(tmTime, oSampleData);
518 }
519
520 tResult Write(tTimeStamp tmTime, const DATA_TYPE& oSampleData)
521 {
522 return Write(base::flash::duration_cast<base::flash::tNanoSeconds>(tmTime), oSampleData);
523 }
524
525 tResult Write(base::flash::tNanoSeconds tmTime, const DATA_TYPE& oSampleData)
526 {
527 static_assert(!std::is_pointer_v<DATA_TYPE>,
528 "pointer types are not allowed for sample writing. To support this you need to specialize the sample_writer template");
529
532 ucom::ant::object_ptr<ISample> pFlashSample(pSample);
533 RETURN_IF_POINTER_NULL(pFlashSample);
534 RETURN_IF_FAILED(pFlashSample->SetTime(tmTime));
535 {
537 const adtf::base::adtf_memory<const DATA_TYPE> oMemory(&oSampleData);
538 RETURN_IF_FAILED(pFlashSample->WriteLock(pSampleBuffer, oMemory.GetSize()));
539 pSampleBuffer->Write(oMemory);
540 }
541 return BASE::Write(pSample);
542 }
543
544 ADTF3_DEPRECATED("Writing data with no concrete sample time is deprecated. Use "
545 "sample_writer<DATA_TYPE>::Write(tmTime, oSampleData) instead.")
546 tResult Transmit(const DATA_TYPE& oSampleData)
547 {
548 return Write(oSampleData);
549 }
550
551 tResult Transmit(tTimeStamp tmTime, const DATA_TYPE& oSampleData)
552 {
553 return Write(base::flash::duration_cast<base::flash::tNanoSeconds>(tmTime), oSampleData);
554 }
555
556 tResult Transmit(base::flash::tNanoSeconds tmTime, const DATA_TYPE& oSampleData)
557 {
558 return Write(tmTime, oSampleData);
559 }
560
561protected:
562 ucom::ant::object_ptr<services::flash::IReferenceClock> m_pClock;
563};
564
565template<typename DATA_TYPE>
566ADTF3_DEPRECATED("Writing data with no concrete sample time is deprecated. Use "
567 "sample_writer<DATA_TYPE>::Write(tmTime, oSampleData) instead.")
568sample_writer<DATA_TYPE>& operator<<(sample_writer<DATA_TYPE>& oSampleWriter,
569 const DATA_TYPE& oSampleData)
570{
571 THROW_IF_FAILED(oSampleWriter.Write(oSampleData));
572 return oSampleWriter;
573}
574
575} // namespace flash
576
579using flash::make_sample_writer;
580
581} //namespace streaming
582} //namespace adtf
Copyright © Audi Electronics Venture GmbH.
#define ADTF3_DEPRECATED(_depr_message_)
Mark a function or variable as deprecated.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
@ RUN_TRIGGER
Trigger run call.
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition string_intf.h:28
Template class implementation for the IRawMemory interface (see Supported types for adtf_memory<T> fo...
@ PushRead
PushRead Operation mode for the ISampleStream::Open. See PushRead Mode - Synchronous Data Pipes.
Interface of the SampleStream.
virtual tResult Open(const char *strName, adtf::ucom::ant::iobject_ptr< ISampleInStream > &pInStream, const adtf::ucom::ant::iobject_ptr< const IStreamType > &pInitialAcceptedStreamType, IPushReadEventSink *&pPushEventSink, ISampleStreamAccess::tMode ui32Mode, size_t szQueueSize)=0
Opens The SampleStream for reading access.
The default Sample Reader will read the incomung Stream of a IInPin.
virtual tResult GetNextSample(ucom::ant::iobject_ptr< const ISample > &pSample)
Gets the next Sample within internal queue which not has been read.
This base implementation of a sample writer is able to write to one Sample Stream which is connected ...
sample_streamer< ISampleWriter, cOutPin > base_type
base type
ucom::object_ptr< ISampleOutStream > m_pOutStream
The SampleOutStream which is opened while BeginStreaming.
cSampleWriter(const char *strName, const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
CTOR with name and type.
virtual tResult Transmit(const ucom::ant::iobject_ptr< const ISample > &pSample)
Transmits and writes a sample reference to the opened ISampleOutStream.
tResult EndStreaming() override
Sample Stream disconnected.
virtual tResult ChangeType(const ucom::ant::iobject_ptr< const IStreamType > &pType)
Changes and writes a stream type reference to the opened ISampleOutStream.
tResult ManualTrigger()
This is to Run a trigger call manually.
virtual tResult Flush()
Flushes a the opened ISampleOutStream.
tResult BeginStreaming(ISampleStream &oSampleStream) override
BeginStreaming will open the given Sample Stream for Writing while a connection is establishing.
virtual tResult SetStreamError(tResult oErr)
Writes an error to the opened ISampleOutStream.
void SetName(const char *strName)
Sets the name of the streamer.
tResult SetType(const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
Specialized Sample Writer to write DATA of type DATA_TYPE.
tResult Transmit(const DATA_TYPE &oSampleData)
Interface for sample reads that read from sample streams via input pins.
virtual tResult GetNextSample(ucom::ant::iobject_ptr< const ant::ISample > &pSample)=0
Reads the next available sample from the associated sample stream.
virtual void SetName(const char *strName)=0
Sets the name of the streamer.
virtual tResult SetType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pStreamType)=0
Sets the initial stream type of a streamer.
Interface for sample writers that write to sample streams via output pins.
This base implementation of a sample writer is samples and types to the given pin set at SetStreamerP...
virtual tResult Transmit(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
For compatibility purposes, call Write() instead.
tResult GetType(ucom::ant::iobject_ptr< const ant::IStreamType > &pStreamType) const override
Returns the initial stream type of the streamer.
tResult ManualTrigger(base::flash::tNanoSeconds tmActivationTime=base::flash::tNanoSeconds {-1}) override
Calls all connected runners synchronously in this call.
tResult ChangeType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pType) override
Communicates a type change for all following samples.
void SetName(const char *strName) override
Sets the name of the streamer.
tResult GetName(base::ant::IString &&strName) override
Retrieves the name of the streamer.
tResult EndStreaming() override
End streaming.
tResult SetStreamError(tResult oError) override
Reports and handles an error via the sample stream.
tResult Flush() override
Flushes the writer.
tResult SetStreamerPin(const ucom::ant::iobject_ptr< IStreamerPin > &pStreamerPin) override
Sets the pin that the streamer is associated with.
tResult SetType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pStreamType) override
Sets the initial stream type of a streamer.
tResult BeginStreaming(ISampleStream &oSampleStream) override
Begin streaming on the given sample stream.
tResult Write(const ucom::ant::iobject_ptr< const ant::ISample > &pSample) override
Writes a sample to the connected sample stream.
Wrapper class that facilitates the handling of output samples.
Definition sample.h:353
Specialized Sample Writer to write data of a given type DATA_TYPE (see Supported types for adtf_memor...
ADTF3_DEPRECATED("Writing data with no concrete sample time is deprecated. Use " "sample_writer<DATA_TYPE>::Write(tmTime, oSampleData) instead.") tResult Write(const DATA_TYPE &oSampleData)
Writes Data of the given DATA_TYPE.
Base object pointer to realize binary compatible reference counting in interface methods.
Implementation for a exclusive lock guard.
DestinationTimeStamp duration_cast(const SourceTimeStamp &)
Duration cast base template to converted between different time resolution.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
tResult make_sample_writer(cSampleWriter &oWriter, const char *strNameOfWriter, const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
ISampleOutStream & operator<<(ISampleOutStream &oStreamWriter, const adtf::ucom::ant::iobject_ptr< const ISample > &pSample)
Streaming Operator<< to write a sample to a writers queue of the ISampleStream.
const ISampleInStream & operator>>(const ISampleInStream &oStreamReader, IStreamItem &oItem)
Streaming Operator>> to read a sample from the readers queue.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the IRuntime.
ISampleWriter & operator<<(ISampleWriter &oSampleWriter, const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
streaming operator to write a sample to the sample writer
Namespace for the ADTF Streaming SDK.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSample)
Helper Function to get a ISample Instance through the IRuntime.
object_ptr< T > ucom_object_ptr_cast(object_ptr< T > oCasted)
Alias always bringing the latest version of ant::ucom_object_ptr_cast() into scope.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult