ADTF  3.18.2
interface_binding_proxy.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "named_graph_object.h"
10 #include "interface_binding_type.h"
11 
12 namespace adtf
13 {
14 namespace streaming
15 {
16 namespace ant
17 {
18 
25 template<typename INTERFACE, bool INTERFACE_CHECK=true>
26 class binding_proxy: public named_graph_object<IBindingProxy>
27 {
28 
29 protected:
35  adtf::ucom::object_list<IBindingProxy> m_lstBindingRoutes;
36 
37 public:
40  {
41  }
44  binding_proxy(const char* strName)
45  {
47  }
48 
52  binding_proxy(const char* strName, const adtf::ucom::iobject_ptr<const IBindingType>& pBindingType)
53  {
55  m_pBindingType = adtf::ucom::make_object_ptr<cBindingType>(*pBindingType.Get());
56  }
57 
59  virtual ~binding_proxy()
60  {
61  }
68  {
69  m_pBindingType = adtf::ucom::make_object_ptr<cBindingType>(*pBindingType.Get());
72  }
73 public: //interface IBindingProxy
74 
75  tResult GetBindingType(adtf::ucom::iobject_ptr<const IBindingType>& pBindingType) const override
76  {
78  if (!pBindingType.Get())
79  {
80  RETURN_ERROR_DESC(ERR_POINTER, "Binding proxy has not connected to a binding server");
81  }
83  }
84 
85  tResult GetServerObject(adtf::ucom::iobject_ptr<adtf::ucom::IObject>& pBindingServer) const override
86  {
87  if (m_pServerObject)
88  {
89  pBindingServer.Reset(m_pServerObject);
91  }
92  else
93  {
94  RETURN_ERROR(ERR_INVALID_STATE);
95  }
96  }
97 
98  tResult BindServerObject(const adtf::ucom::iobject_ptr<adtf::ucom::IObject>& pBindingServer,
99  const adtf::ucom::iobject_ptr<const IBindingType>& pBindingType) override
100  {
101  if (m_pServerObject)
102  {
103  RETURN_ERROR_DESC(ERR_DEVICE_IN_USE, "This binding proxy has already been bound to a server.");
104  }
105 
106  if (INTERFACE_CHECK)
107  {
108  adtf::ucom::object_ptr<INTERFACE> pCheckServer = pBindingServer;
109  if (pCheckServer)
110  {
111  //interface is valid
112  }
113  else
114  {
115  RETURN_ERROR(ERR_INVALID_INTERFACE);
116  }
117  }
118  if (m_pBindingType)
119  {
120  if (!m_pBindingType->IsEqual(*pBindingType.Get()))
121  {
122  RETURN_ERROR(ERR_INVALID_TYPE);
123  }
124  }
125  m_pBindingType = adtf::ucom::make_object_ptr<cBindingType>(*pBindingType.Get());
126  m_pServerObject = pBindingServer;
127 
128  //Bind to the forwarded proxies
129  //Usually this list should be synchronized, but at common the initialization is sequential AND while RL_Running prohibited
130  for (auto it : m_lstBindingRoutes)
131  {
132  it->BindServerObject(m_pServerObject, adtf::ucom::ucom_object_ptr_cast<const IBindingType>(m_pBindingType));
133  }
135  }
136 
137  tResult UnbindServerObject(const adtf::ucom::iobject_ptr<adtf::ucom::IObject>& pBindingServer) override
138  {
139  if (INTERFACE_CHECK)
140  {
141  adtf::ucom::object_ptr<INTERFACE> pCheckServer = pBindingServer;
142  if (pCheckServer && pCheckServer == m_pServerObject)
143  {
144  //interface is valid
145  }
146  else
147  {
148  RETURN_ERROR(ERR_INVALID_INTERFACE);
149  }
150  }
151  else
152  {
153  if (m_pServerObject == pBindingServer)
154  {
155  //interface is valid
156  }
157  else
158  {
159  RETURN_ERROR(ERR_INVALID_INTERFACE);
160  }
161  }
162 
163  //unbind on forwards
164  for (auto it : m_lstBindingRoutes)
165  {
166  it->UnbindServerObject(m_pServerObject);
167  }
168 
169  m_pServerObject = nullptr;
170  m_pBindingType = nullptr;
172  }
173 
174  tResult AttachRouting(const adtf::ucom::iobject_ptr<IBindingProxy>& pBindingTo) override
175  {
176  auto it = std::find(m_lstBindingRoutes.begin(), m_lstBindingRoutes.end(), pBindingTo);
177  if (it != m_lstBindingRoutes.end())
178  {
179  //already forwarding
181  }
182  else
183  {
184  if (m_pServerObject)
185  {
186  RETURN_IF_FAILED(pBindingTo->BindServerObject(m_pServerObject,
187  adtf::ucom::ucom_object_ptr_cast<const IBindingType>(m_pBindingType)));
188  }
189  m_lstBindingRoutes.PushBack(pBindingTo);
191  }
192  }
193 
194  tResult DetachRouting(const adtf::ucom::iobject_ptr<IBindingProxy>& pBindingTo) override
195  {
196  auto it = std::find(m_lstBindingRoutes.begin(), m_lstBindingRoutes.end(), pBindingTo);
197  if (it != m_lstBindingRoutes.end())
198  {
199  //already forwarding
200  RETURN_ERROR(ERR_NOT_FOUND);
201  }
202  else
203  {
204  m_lstBindingRoutes.DeleteObject(pBindingTo);
205  if (m_pServerObject)
206  {
207  RETURN_IF_FAILED(pBindingTo->UnbindServerObject(m_pServerObject));
208  }
210  }
211  }
212 };
213 
218 class cDefaultBindingProxy : public binding_proxy<adtf::ucom::ant::IObject, false>
219 {
220 
221  public:
224  "default_binding_proxy.streaming.adtf.cid",
225  "Binding Proxy");
226 
227  public:
229  cDefaultBindingProxy(const char* strName)
230  {
232  }
233  virtual ~cDefaultBindingProxy() = default;
234 
235 };
236 
237 } //namespace ant
238 
240 using ant::binding_proxy;
241 
243 using ant::cDefaultBindingProxy;
244 } //namespace streaming
245 } //namespace adtf
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#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...
This default class implementation will halp to define a Default InterfaceBindingProxy.
adtf::ucom::object_ptr< INTERFACE > m_pServerObject
Server interface this proxy will provided.
binding_proxy(const char *strName, const adtf::ucom::iobject_ptr< const IBindingType > &pBindingType)
CTOR which initializes the binding type.
adtf::ucom::object_list< IBindingProxy > m_lstBindingRoutes
List of attached Routes.
adtf::ucom::object_ptr< IBindingType > m_pBindingType
Type of the Server interface this proxy will provided.
binding_proxy(const char *strName)
CTOR which initializes the name.
tResult SetBindingType(const adtf::ucom::iobject_ptr< const IBindingType > &pBindingType)
Sets the binding type of the proxy.
The Default implementation of the IBindingProxy interface.
ADTF_CLASS_ID_NAME(cDefaultBindingProxy, "default_binding_proxy.streaming.adtf.cid", "Binding Proxy")
Implements the adtf::ucom::IClassInfo.
Default convenient implementation for INamedGraphObject.
tResult SetName(const char *strName) override
Sets the Name of the object.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Reset this object_ptr<> with the content of another iobject_ptr<>
virtual T * Get() const =0
Get raw pointer to shared object.
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
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
tResult reset_object_ptr(TDest< const T > &o_oDest, const TSrc< U > &i_oSrc)
Reset an iobject_ptr with const T.
Namespace for entire ADTF SDK.