ADTF  3.18.2
requestable_writer.h
Go to the documentation of this file.
1 
7 #pragma once
12 #include <adtfucom3/adtf_ucom3.h>
13 #include <adtf_utils.h>
14 #include <memory>
15 #include <functional>
16 
17 namespace adtf
18 {
19 namespace streaming
20 {
21 namespace hollow
22 {
23 
27 class cRequestBroker: public ucom::object<IStreamingRequests>
28 {
29  public:
34  cRequestBroker(cSampleWriter* pWriter = nullptr);
35 
39  ~cRequestBroker() override;
40 
46  void SetCallbacks(std::function<void(uint32_t, const base::IProperties*)> fnEnable,
47  std::function<void(uint32_t)> fnDisable);
48 
54 
59  void DisableCurrentRequests(bool bCallDisableCallback = false);
60 
61  // IStreamingRequests implementation
62  tResult RequestSamples(ucom::ant::iobject_ptr<IStreamingRequest>& pRequest,
63  uint32_t nSubStreamId,
64  const base::ant::IProperties* pRequestProperties = nullptr) override;
65  void RegisterStreamTypeHandler(IStreamTypeHandler& oHandler) override;
66  void UnregisterStreamTypeHandler(IStreamTypeHandler& oHandler) override;
67 
68  private:
69  class cImplementation;
70  std::unique_ptr<cImplementation> m_pImplementation;
71 };
72 
77 template <typename BaseWriter = adtf::streaming::cSampleWriter>
79  public BaseWriter
80 {
81  public:
87  {
88  m_pBroker.Reset(pBroker);
89  }
90 
92  {
93  auto pHollowStream = ucom::ucom_cast<IInternalBindingProxy*>(&oSampleStream);
94  RETURN_IF_POINTER_NULL_DESC(pHollowStream, "Sample Stream does not implement IInternalBindingProxy");
95  RETURN_IF_FAILED(pHollowStream->GetInternalBindingProxy(m_pProxy));
96  ucom::object_ptr<IBindingType> pType = ucom::make_object_ptr<binding_type<IStreamingRequests>>();
97  RETURN_IF_FAILED(m_pProxy->BindServerObject(m_pBroker, pType));
98 
99  return BaseWriter::BeginStreaming(oSampleStream);
100  }
101 
103  {
104  BaseWriter::EndStreaming();
105  if (m_pProxy)
106  {
107  m_pProxy->UnbindServerObject(m_pBroker);
108  m_pProxy.Reset();
109  }
111  }
112 
113  private:
116 };
117 
124 template <typename BaseWriter = adtf::streaming::cSampleWriter>
126 {
127  public:
132  m_pBroker(ucom::make_object_ptr<cRequestBroker>(this))
133  {
134  writer_with_request_broker<BaseWriter>::SetBroker(ucom::ucom_object_ptr_cast<IStreamingRequests>(m_pBroker));
135  }
136 
145  void SetCallbacks(std::function<void(uint32_t, const base::IProperties*)> fnEnable,
146  std::function<void(uint32_t)> fnDisable)
147  {
148  m_pBroker->SetCallbacks(fnEnable, fnDisable);
149  }
150 
152  {
153  m_pBroker->UpdateType(pType);
154  return BaseWriter::SetType(pType);
155  }
156 
158  {
159  return ChangeType(pType, true, false);
160  }
161 
172  bool bDisableCurrentRequests,
173  bool bCallDisableCallback)
174  {
175  RETURN_IF_FAILED(ChangeType(pType, bDisableCurrentRequests, bCallDisableCallback, true));
176  RETURN_IF_FAILED(ChangeType(pType, false, false, false));
178  }
179 
181  bool bDisableCurrentRequests,
182  bool bCallDisableCallback,
183  bool bSync)
184  {
185  if (bDisableCurrentRequests)
186  {
187  m_pBroker->DisableCurrentRequests(bCallDisableCallback);
188  }
189 
190  if (bSync)
191  {
192  m_pBroker->UpdateType(pType);
193  }
194  else
195  {
196  RETURN_IF_FAILED(BaseWriter::ChangeType(pType));
197  }
198 
200  }
201 
202  private:
203  ucom::ant::object_ptr<cRequestBroker> m_pBroker;
204 
205 };
206 
207 }
208 
209 using hollow::requestable_writer;
210 
211 }
212 }
213 
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define RETURN_IF_POINTER_NULL_DESC(_ptr,...)
Return ERR_POINTER with description if _ptr is nullptr, which requires the calling function's return ...
#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.
Defintion of a property set container interface.
Interface of the SampleStream.
This base implementation of a sample writer is samples and types to the given pin set at adtf::stream...
Definition: samplewriter.h:364
Interface for reacting synchrounously to stream type changes.
This is the default implementation of IStreamingRequests used by requestable_writer.
void UpdateType(const ucom::ant::iobject_ptr< const IStreamType > &pType)
Call this when you updated your Substreams type.
void DisableCurrentRequests(bool bCallDisableCallback=false)
This will disable all current requests.
cRequestBroker(cSampleWriter *pWriter=nullptr)
Default constructor.
void SetCallbacks(std::function< void(uint32_t, const base::IProperties *)> fnEnable, std::function< void(uint32_t)> fnDisable)
Sets the callbacks for enabling and disabling specific Substreams.
Writer that registers a request broker (cRequestBroker) at the connected sample stream.
tResult ChangeType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pType) override
Communicates a type change for all following samples.
tResult ChangeType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pType, bool bDisableCurrentRequests, bool bCallDisableCallback)
Writes a new Stream Type to the Sample Stream.
tResult SetType(const ucom::ant::iobject_ptr< const ant::IStreamType > &pType) override
Sets the initial stream type of a streamer.
void SetCallbacks(std::function< void(uint32_t, const base::IProperties *)> fnEnable, std::function< void(uint32_t)> fnDisable)
Sets the callbacks for activating and deactivating substreams.
Template that will register a request broker (an implementation of IStreamingRequests) at the connect...
tResult BeginStreaming(streaming::ant::ISampleStream &oSampleStream) override
Begin streaming on the given sample stream.
void SetBroker(const ucom::ant::iobject_ptr< IStreamingRequests > &pBroker)
Use this to set the broker instance after the writer has been created.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition: object.h:379
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
std::enable_if< !std::is_base_of< enable_object_ptr_from_this< typename std::remove_cv< Implementation >::type >, typename std::remove_cv< Implementation >::type >::value, object_ptr< Implementation > >::type make_object_ptr(Args &&... args)
Create an instance of type object_ptr with Implementation as the shared resource.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.