ADTF
Loading...
Searching...
No Matches
interface_binding_proxy.h
Go to the documentation of this file.
1
7#pragma once
11
12namespace adtf
13{
14namespace streaming
15{
16namespace ant
17{
18
25template<typename INTERFACE, bool INTERFACE_CHECK=true>
26class binding_proxy: public named_graph_object<IBindingProxy>
27{
28
29protected:
36
37public:
40 {
41 }
42
44 binding_proxy(const char* strName)
45 {
47 }
48
57
60 {
61 }
62
73public: //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 {
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 }
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 {
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,
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
217class cDefaultBindingProxy : public binding_proxy<adtf::ucom::ant::IObject, false>
218{
219
220 public:
222 ADTF_CLASS_ID_NAME(cDefaultBindingProxy,
223 "default_binding_proxy.streaming.adtf.cid",
224 "Binding Proxy");
225
226 public:
227 cDefaultBindingProxy() {};
228 cDefaultBindingProxy(const char* strName)
229 {
231 }
232 virtual ~cDefaultBindingProxy() = default;
233
234};
235
236} //namespace ant
237
239using ant::binding_proxy;
240
242using ant::cDefaultBindingProxy;
243} //namespace streaming
244} //namespace adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
Definition result.h:44
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Definition result.h:42
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
Definition result.h:49
adtf::ucom::object_ptr< IBindingType > m_pBindingType
Type of the Server interface this proxy will provided.
Definition interface_binding_proxy.h:33
tResult SetBindingType(const adtf::ucom::iobject_ptr< const IBindingType > &pBindingType)
Definition interface_binding_proxy.h:67
adtf::ucom::object_list< IBindingProxy > m_lstBindingRoutes
List of attached Routes.
Definition interface_binding_proxy.h:35
binding_proxy(const char *strName, const adtf::ucom::iobject_ptr< const IBindingType > &pBindingType)
Definition interface_binding_proxy.h:52
adtf::ucom::object_ptr< INTERFACE > m_pServerObject
Server interface this proxy will provided.
Definition interface_binding_proxy.h:31
virtual ~binding_proxy()
DTOR.
Definition interface_binding_proxy.h:59
binding_proxy()
CTOR.
Definition interface_binding_proxy.h:39
binding_proxy(const char *strName)
Definition interface_binding_proxy.h:44
Definition interface_binding_proxy.h:218
ADTF_CLASS_ID_NAME(cDefaultBindingProxy, "default_binding_proxy.streaming.adtf.cid", "Binding Proxy")
Implements the adtf::ucom::IClassInfo.
tResult SetName(const char *strName) override
Definition named_graph_object.h:64
named_graph_object(const named_graph_object &)=delete
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.
Definition object_ptr.h:384
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
Definition bindingproxyoutport.h:16
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
object_enum< T, INTERFACE_TYPE, std::list > object_list
Definition object_list.h:402
tResult reset_object_ptr(iobject_ptr< const T > &o_oDest, const iobject_ptr< U > &i_oSrc)
Alias always bringing the latest version of ant::reset_object_ptr() into scope.
Definition object_ptr_utilities.h:166
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.
Definition object_ptr_utilities.h:104
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Definition object_ptr_intf.h:437
object_ptr< Implementation > make_object_ptr(Args &&... args)
Alias always bringing the latest version of ant::make_object_ptr() into scope.
Definition object_ptr_utilities.h:129
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14