ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sample.h
Go to the documentation of this file.
1
7#pragma once
8#include "sample_intf.h"
9
11#include <adtfucom3/object.h>
12#include <adtfbase/chrono.h>
16
17#include <cstring>
18#include <cinttypes>
19
20namespace adtf
21{
22namespace streaming
23{
24namespace ant
25{
26
52class cSample :
53 public adtf::ucom::catwo::object<ant::ISample,
54 flash::ISample,
55 hollow::ISample,
56 ucom::ant::IClassInfo>
57{
58private:
61
62public:
64 ADTF_CLASS_ID_NAME(cSample, "sample.streaming.adtf.cid", "ADTF Default Sample");
66 UCOM_RESOLVE(IObject, ISample)
67
69
70
74 ADTF3_DEPRECATED("The class 'cSample' is deprecated. Please use 'alloc_sample()' instead.")
81 ADTF3_DEPRECATED("The class 'cSample' is deprecated. Please use 'alloc_sample()' instead.")
82 cSample(const ucom::ant::iobject_ptr<ISampleBufferFactory>& oSampleFactory);
83
87 virtual ~cSample();
88
89private: //no copy, no assignment allowed - Samples will be treated only by ISample inferface !
91 cSample(const cSample&) = delete;
93 cSample(cSample&&) = delete;
95 cSample& operator=(const cSample&) = delete;
97 cSample& operator=(cSample&&) = delete;
98
99public: //implements ant::ISample
100 tResult Lock(ucom::ant::iobject_ptr_shared_locked<const adtf::streaming::ant::ISampleBuffer>& oSampleBuffer) const override;
101 tResult WriteLock(ucom::ant::iobject_ptr_locked<ISampleBuffer>& oSampleBuffer, size_t szPreAllocateSize) override;
102 tResult Set(const ant::ISample& oSample) override;
103 tResult Get(ant::ISample& oSample) const override;
104 tResult Reset() override;
105 tTimeStamp GetTime() const;
106 tResult SetTime(tTimeStamp tmTimeStamp);
107 uint32_t GetFlags() const override;
108 tResult SetFlags(uint32_t ui32Flags) override;
109 tResult Set(tTimeStamp tmTime,
110 const void* pData,
111 size_t nSize,
112 uint32_t ui32Flags=0) override;
113
114 tResult GetSampleBufferFactory(ucom::ant::iobject_ptr<ISampleBufferFactory>& oFactory) const override;
115 tResult GetSampleInfo(ucom::ant::iobject_ptr<const ISampleInfo>& oSampleInfo) const override;
116 tResult GetSampleInfo(ucom::ant::iobject_ptr<ISampleInfo>& oSampleInfo) override;
117 tResult GetSampleLog(ucom::ant::iobject_ptr<ISampleLog>& oSampleLog) const override;
118
119public: //implements flash::ISample
120 base::flash::tNanoSeconds GetTimeNs() const override;
121 tResult SetTime(base::flash::tNanoSeconds tmTimeStamp) override;
122 tResult Set(base::flash::tNanoSeconds tmTimeStamp,
123 const void* pData,
124 size_t szSize,
125 uint32_t ui32Flags=0) override;
126
127public: //implements hollow::ISample
128 uint32_t GetSubStreamId() const override;
129 void SetSubStreamId(uint32_t nSubStreamId) override;
130
131public:
142
143 tResult SetSampleInfo(const ucom::ant::iobject_ptr<ISampleInfo>& oInfo);
144 tResult SetSampleLog(const ucom::ant::iobject_ptr<ISampleLog>& oLog);
145};
146
154{
155 public:
160 ADTF3_DEPRECATED("The class 'cReferenceSample' is deprecated because it is inherently unsafe. Please use 'alloc_sample()' in combination with 'ISample::SetSampleBuffer()' instead.")
162};
163
164//helper functions for Sampleallocation
176tResult alloc_sample(ucom::ant::iobject_ptr<ucom::ant::IObject>& pSampleObject, const char* strSampleCID);
177
190tResult alloc_sample(ucom::ant::iobject_ptr<ucom::ant::IObject>& pSample, const char* strSampleCID, tTimeStamp nTimeStamp);
191
201tResult alloc_sample(ucom::ant::iobject_ptr<ISample>& pSample);
202
213tResult alloc_sample(ucom::ant::iobject_ptr<ISample>& pSample, tTimeStamp nTimeStamp);
214
215} // namespace ant
216
217namespace hollow
218{
219
224uint32_t get_sample_substream_id(const ant::ISample& oSample);
225
231{
232 return get_sample_substream_id(*pSample.Get());
233}
234
240void set_sample_substream_id(ant::ISample& oSample, uint32_t nSubStreamId);
241
247inline void set_sample_substream_id(const ucom::ant::iobject_ptr<ant::ISample>& pSample, uint32_t nSubStreamId)
248{
249 set_sample_substream_id(*pSample.Get(), nSubStreamId);
250}
251
252}
253
254namespace flash
255{
256
267
279
291
304
318
331tResult alloc_sample(ucom::ant::iobject_ptr<ucom::ant::IObject>& pSample, const char* strSampleCID, tTimeStamp nTimeStamp);
332
341
351template <typename T>
353{
354 static_assert(std::is_trivially_copyable<T>::value,
355 "You can only use plain types or structs without pointers or complex members.");
356
357 public:
370 {
371 THROW_IF_FAILED(alloc_sample(m_pSample, tmSampleTime));
372 THROW_IF_FAILED(m_pSample->WriteLock(m_pBuffer, sizeof(T)));
373 }
374
380 explicit output_sample_data(tTimeStamp tmSampleTime)
381 {
382 THROW_IF_FAILED(alloc_sample(m_pSample, tmSampleTime));
383 THROW_IF_FAILED(m_pSample->WriteLock(m_pBuffer, sizeof(T)));
384 }
385
397 const T& oValue):
398 output_sample_data(tmSampleTime)
399 {
400 AssignValue(oValue);
401 }
402
404 const T& oValue,
405 uint32_t nSubStreamId):
406 output_sample_data(tmSampleTime)
407 {
410 pSample->SetTime(tmSampleTime);
411 pSample->SetSubStreamId(nSubStreamId);
412 m_pSample = pSample;
413 THROW_IF_FAILED(m_pSample->WriteLock(m_pBuffer, sizeof(T)));
414 AssignValue(oValue);
415 }
416
424 const T& oValue):
425 output_sample_data(tmSampleTime)
426 {
427 AssignValue(oValue);
428 }
429
439 explicit output_sample_data(const ant::ISample& oSampleToCopy)
440 {
441 THROW_IF_FAILED(alloc_sample(m_pSample));
442 THROW_IF_FAILED(m_pSample->Set(oSampleToCopy));
443 THROW_IF_FAILED(m_pSample->WriteLock(m_pBuffer, 0));
444 if (m_pBuffer->GetSize() != sizeof(T))
445 {
446 THROW_ERROR_DESC(ERR_INVALID_ARG, "The sample passed to output_sample_data (%zu), does not match the size of the requested type (%zu).",
447 m_pBuffer->GetSize(),
448 sizeof(T));
449 }
450 }
451
458 output_sample_data(*pSampleToCopy.Get())
459 {
460 }
461
463 output_sample_data& operator=(output_sample_data&&) = default;
464
465 virtual ~output_sample_data() = default;
466
471 void SetSubStreamId(uint32_t nSubStreamId)
472 {
473 hollow::set_sample_substream_id(m_pSample, nSubStreamId);
474 }
475
481 {
482 return const_cast<T*>(const_cast<const output_sample_data*>(this)->GetDataPtr());
483 }
484
489 const T* GetDataPtr() const
490 {
491 if (!m_pBuffer)
492 {
493 THROW_ERROR_DESC(ERR_INVALID_STATE,
494 "This output_sample_data instance is not valid. Maybe you tried to access it after you called Release()");
495 }
496
497 return reinterpret_cast<T*>(m_pBuffer->GetPtr());
498 }
499
504 {
505 return GetDataPtr();
506 }
507
511 const T* operator->() const
512 {
513 return GetDataPtr();
514 }
515
521 {
522 return *GetDataPtr();
523 }
524
529 const T& GetData() const
530 {
531 return *GetDataPtr();
532 }
533
538 {
539 return GetData();
540 }
541
545 const T& operator*() const
546 {
547 return GetData();
548 }
549
555 {
556 AssignValue(oValue);
557 return *this;
558 }
559
564 operator T&()
565 {
566 return GetData();
567 }
568
573 operator const T&() const
574 {
575 return GetData();
576 }
577
589 {
590 if (!m_pBuffer)
591 {
592 THROW_ERROR_DESC(ERR_INVALID_STATE,
593 "This output_sample_data instance is not valid. Maybe you tried to access it after you called Release()");
594 }
595
596 m_pBuffer = nullptr;
597 ucom::ant::object_ptr<ant::ISample> pSample(std::move(m_pSample));
598 m_pSample.Reset();
599 return pSample;
600 }
601
609 tResult SetSampleInfo(const ISampleInfo::tHashKey& oHash, const adtf::util::cVariant oValue)
610 {
611 return ant::set_sample_info(*m_pSample, oHash, oValue);
612 }
613
614 protected:
617
618 private:
619 inline void AssignValue(const T& oValue)
620 {
621 std::memcpy(this->GetDataPtr(), &oValue, sizeof(T));
622 }
623
624 output_sample_data(const output_sample_data&) = delete;
625 output_sample_data& operator=(const output_sample_data&) = delete;
626};
627
628}
629
630namespace giant
631{
632
641
650
659
660}
661
662using ant::cSample;
671
672} // namespace streaming
673} // namespace adtf
674
Copyright © Audi Electronics Venture GmbH.
#define ADTF3_DEPRECATED(_depr_message_)
Mark a function or variable as deprecated.
#define UCOM_RESOLVE(...)
Resolve a path to a base class which is inherited multiple times.
Definition adtf_iid.h:45
Copyright © Audi Electronics Venture GmbH.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define ADTF_CLASS_INFO_IMPL(_class)
Common macro to implement correct treatment of IClassInfo.
Definition class_id.h:57
adtf::util::cStringUtil::tHashKey32 tHashKey
Type for the HashKey of the Value.
The SampleBuffer factory manages and can create SampleBuffers.
The SampleBuffer is the memory block object for the data of a ISample.
The ISample interface sets and retrieves properties on samples .
Definition sample_intf.h:36
Interface for additional sample information on a Additional Sample Information.
The ISampleLog interface defines an interface to trace and store Sample data- and timing flow.
Sample that uses samples buffers that do not copy the data, but only keep a reference to it.
Definition sample.h:154
ADTF3_DEPRECATED("The class 'cReferenceSample' is deprecated because it is inherently unsafe. Please use 'alloc_sample()' in combination with 'ISample::SetSampleBuffer()' instead.") cReferenceSample()
CTOR.
The cSample class implements a basic sample which contains streaming data.
Definition sample.h:57
tResult SetSampleBufferFactory(const ucom::ant::iobject_ptr< ISampleBufferFactory > &pFactory)
Sets the reference to the buffer factory, which will be used to create the user data content in ISamp...
ADTF_CLASS_ID_NAME(cSample, "sample.streaming.adtf.cid", "ADTF Default Sample")
private d pointer
cSample()
resolver for multiple inheritance on IObject
Wrapper class that facilitates the handling of output samples.
Definition sample.h:353
output_sample_data(const ant::ISample &oSampleToCopy)
Initializes the data from an existing sample.
Definition sample.h:439
output_sample_data & operator=(const T &oValue)
Assigns a new value to the data.
Definition sample.h:554
tResult SetSampleInfo(const ISampleInfo::tHashKey &oHash, const adtf::util::cVariant oValue)
Sets a variant value for the hash key oHash into the current samples sample information.
Definition sample.h:609
void SetSubStreamId(uint32_t nSubStreamId)
Sets the Substream id of the generated sample.
Definition sample.h:471
output_sample_data(base::flash::tNanoSeconds tmSampleTime, const T &oValue)
Initializes the data timestamp and value.
Definition sample.h:396
ucom::ant::object_ptr< ant::ISample > Release()
Returns a sample that contains the data and resets all internal data.
Definition sample.h:588
output_sample_data(tTimeStamp tmSampleTime, const T &oValue)
Initializes the data timestamp and value.
Definition sample.h:423
output_sample_data(base::flash::tNanoSeconds tmSampleTime)
Initializes the data timestamp.
Definition sample.h:369
output_sample_data(const ucom::ant::iobject_ptr< const ant::ISample > &pSampleToCopy)
Initializes the data from an existing sample.
Definition sample.h:457
output_sample_data(tTimeStamp tmSampleTime)
Initializes the data timestamp.
Definition sample.h:380
virtual T * Get() const =0
Get raw pointer to shared object.
Base object pointer to realize binary compatible reference counting in interface methods.
Implementation for a exclusive lock guard.
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition object.h:397
#define A_UTILS_D(__pclassname_)
Helper macro for d-pattern definitions.
Definition d_ptr.h:270
Namespace for the ADTF Base SDK.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
tResult set_sample_info(ISampleInfo &oSampleInfo, const ISampleInfo::tHashKey &oHash, const adtf::util::cVariant oValue)
Sets a variant value for the hash key oHash into the sample information oSampleInfo.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the IRuntime.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.5.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSample)
Helper Function to get a ISample Instance through the IRuntime.
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Returns the sample time stamp with nanosecond precision.
void set_sample_time(const ucom::ant::iobject_ptr< ant::ISample > &pSample, base::flash::tNanoSeconds tmTimeStamp)
Sets the sample timestamp with nanosecond precision.
base::flash::tNanoSeconds get_sample_time(const ant::ISample &oSample)
Returns the sample timestamp with nanosecond precision.
Namespace for all functionality of the ADTF Streaming SDK provided since v3.7.
uint32_t get_sample_substream_id(const ant::ISample &oSample)
void set_sample_substream_id(ant::ISample &oSample, uint32_t nSubStreamId)
Sets the substream id of a given sample.
Namespace for the ADTF Streaming SDK.
uint32_t get_sample_substream_id(const ant::ISample &oSample)
void set_sample_substream_id(ant::ISample &oSample, uint32_t nSubStreamId)
Sets the substream id of a given sample.
Namespace for the ADTF uCOM3 SDK.
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.
#define THROW_ERROR_DESC(_code,...)
throws a tResult exception
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult