ADTF
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1
7#pragma once
9#include "graph_intf.h"
10
11namespace adtf
12{
13namespace streaming
14{
15namespace ant
16{
20class cGraph
21{
22 private:
24 std::map<adtf_util::cString, ucom::object_ptr<INamedGraphObject>> m_oGraphObjects;
26 std::multimap<int32_t, ucom::object_ptr<INamedGraphObject>> m_oObjectOrder;
27
28 public:
30 cGraph() = default;
32 virtual ~cGraph();
33
34 public: //implements IGraph
35 tResult GetNamedGraphObject(const char* strName, ucom::ant::iobject_ptr<ucom::ant::IObject>& pObject) const;
36 tResult GetNamedGraphObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const;
37
38 public:
56 int32_t ui32OrderNumber);
63 tResult RemoveNamedGraphObject(const char* strName);
64
73
74 protected:
75 tResult CheckName(const adtf_util::cString& strObjectName);
76
77 template <typename OBJECT_INTERFACE>
78 tResult AddObject(const ucom::ant::iobject_ptr<OBJECT_INTERFACE>& pGraphObject, int32_t ui32OrderNumber)
79 {
80 adtf::ucom::ant::object_ptr<INamedGraphObject> pNamedObject = pGraphObject;
81 RETURN_IF_POINTER_NULL(pNamedObject);
82 return AddNamedGraphObject(pNamedObject, ui32OrderNumber);
83 }
84
85 // tResult RemoveConnection(const adtf::ucom::ant::iobject_ptr<IGraphConnection>& pConnection);
86 tResult RemoveAllConnectionsFrom(const INamedGraphObject* pObj);
87
88 tResult AddAlias(const char* strAliasName, const ucom::ant::iobject_ptr<INamedGraphObject>& pGraphObject);
89 tResult GetAliasObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const;
90
91 private:
92 template <typename OBJECT_INTERFACE>
93 tResult EraseObject(const ucom::ant::iobject_ptr<OBJECT_INTERFACE>& pGraphObject);
94};
95
100template <typename INTERFACE = IGraph>
101class graph : public cGraph,
102 public ucom::catwo::object<IGraph, INTERFACE>
103{
104public:
106 graph() = default;
108 virtual ~graph() = default;
109
110public:
111 tResult GetNamedGraphObject(const char* strName, ucom::ant::iobject_ptr<adtf::ucom::ant::IObject>& pObject) const override
112 {
113 return cGraph::GetNamedGraphObject(strName, pObject);
114 }
115 tResult GetNamedGraphObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const override
116 {
117 return cGraph::GetNamedGraphObjects(lstItems);
118 }
119
121 int32_t ui32OrderNumber) override
122 {
123 RETURN_IF_FAILED(cGraph::AddNamedGraphObject(pGraphObject, ui32OrderNumber));
124 pGraphObject.Get()->SetParent(static_cast<ucom::ant::IObject*>(static_cast<INamedGraphObject*>(this)));
126 }
127};
128
129template<typename CONNECTOR,
130 typename INTERFACE = IGraphConnection>
131class graph_connection : public ucom::catwo::object<IGraphConnection, named_graph_object<INTERFACE>>
132{
133protected:
134 bool m_bConnected = false;
135
138 adtf_util::cString m_strSourceName;
139 adtf_util::cString m_strSourceConnectorName;
140 adtf_util::cString m_strDestinationName;
141 adtf_util::cString m_strDestinationConnectorName;
142 bool m_bConnectRunner;
143
144protected:
145 graph_connection(const graph_connection&) = delete;
146 graph_connection(graph_connection&&) = delete;
147 graph_connection& operator=(const graph_connection&) = delete;
148 graph_connection& operator=(graph_connection&&) = delete;
149
150public:
151 graph_connection() = default;
152
153 graph_connection(const char* strName,
154 const char* strSource,
155 const char* strSourceConnector,
156 const char* strDest,
157 const char* strDestConnector,
160 bool bConnectRunner)
161 {
162 THROW_IF_FAILED_DESC(CONNECTOR::IsSupported(pSource,
163 strSourceConnector,
164 pDest,
165 strDestConnector),
166 "The connection from %s.%s to %s.%s is not supported.",
167 strSource,
168 strSourceConnector,
169 strDest,
170 strDestConnector);
171
173 m_strSourceName = strSource;
174 m_strSourceConnectorName = strSourceConnector;
175 m_strDestinationName = strDest;
176 m_strDestinationConnectorName = strDestConnector;
177 m_pSource = pSource;
178 m_pDest = pDest;
179 m_bConnectRunner = bConnectRunner;
180
181 LOG_DUMP("Init CONNECTION %s.%s -> %s.%s ", strSource, strSourceConnector, strDest, strDestConnector);
182 }
183
184 virtual ~graph_connection()
185 {
186 if (m_bConnected)
187 {
188 Disconnect();
189 }
190 }
191
192 tResult Connect() override
193 {
194 auto pSource = m_pSource.Lock();
195 auto pDest = m_pDest.Lock();
196 if (pSource && pDest)
197 {
198 adtf_util::cString oSourceName;
199 pSource->GetName(adtf_string_intf(oSourceName));
200
201 adtf_util::cString oDestName;
202 pDest->GetName(adtf_string_intf(oDestName));
203 LOG_DETAIL("Connecting CONNECTION %s.%s -> %s.%s ",
204 oSourceName.GetPtr(),
205 m_strSourceConnectorName.GetPtr(),
206 oDestName.GetPtr(),
207 m_strDestinationConnectorName.GetPtr());
208
209 tResult nRes = CONNECTOR::Connect(pSource,
210 m_strSourceConnectorName,
211 pDest,
212 m_strDestinationConnectorName,
213 m_bConnectRunner);
214 if (IS_FAILED(nRes))
215 {
217 "Can not connect %s.%s with %s.%s - %s",
218 m_strSourceName.GetPtr(),
219 m_strSourceConnectorName.GetPtr(),
220 m_strDestinationName.GetPtr(),
221 m_strDestinationConnectorName.GetPtr(),
222 nRes.GetDescription());
223 }
224 }
225 else
226 {
227 RETURN_ERROR_DESC(ERR_NOT_FOUND,
228 "Can not connect %s.%s with %s.%s, "
229 "a connection point disappeared ??",
230 m_strSourceName.GetPtr(),
231 m_strSourceConnectorName.GetPtr(),
232 m_strDestinationName.GetPtr(),
233 m_strDestinationConnectorName.GetPtr());
234 }
235 m_bConnected = true;
237 }
238
239 tResult Disconnect() override
240 {
241 //we set the state to disconnected also if it fails
242 m_bConnected = false;
243 auto pSource = m_pSource.Lock();
244 auto pDest = m_pDest.Lock();
245
246 if (pSource && pDest)
247 {
248 RETURN_IF_FAILED(CONNECTOR::Disconnect(pSource,
249 m_strSourceConnectorName,
250 pDest,
251 m_strDestinationConnectorName,
252 m_bConnectRunner));
253 }
255 }
256
257 tResult GetSource(ucom::ant::iobject_ptr<INamedGraphObject>& pSource) const override
258 {
259 auto pNO = m_pSource.Lock();
260 if (pNO)
261 {
262 return pSource.Reset(pNO);
263 }
264 RETURN_ERROR(ERR_NOT_FOUND);
265 }
266 tResult GetSourceName(base::ant::IString&& strName) const override
267 {
268 return strName.Set(m_strSourceName);
269 }
270
271 tResult GetSourceConnectorName(base::ant::IString&& strName) const override
272 {
273 return strName.Set(m_strSourceConnectorName);
274 }
275
276 tResult GetDestination(ucom::ant::iobject_ptr<INamedGraphObject>& pDestination) const override
277 {
278 auto pNO = m_pDest.Lock();
279 if (pNO)
280 {
281 return pDestination.Reset(pNO);
282 }
283 RETURN_ERROR(ERR_NOT_FOUND);
284 }
285
286 tResult GetDestinationName(base::ant::IString&& strName) const override
287 {
288 return strName.Set(m_strDestinationName);
289 }
290
291 tResult GetDestinationConnectorName(base::ant::IString&& strName) const override
292 {
293 return strName.Set(m_strDestinationConnectorName);
294 }
295
296 bool IsConnected() const override
297 {
298 return m_bConnected;
299 }
300};
301
302
313
321adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject& oGraphObject);
322
331adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject& oGraphObject, const char* strSeperator);
332
333
334} //namespace ant
335
337using ant::cGraph;
338using ant::graph;
339
341
344
345
346}
347}
#define LOG_DETAIL(...)
Logs additional information.
Definition log.h:386
#define LOG_DUMP(...)
Logs a dump message.
Definition log.h:382
#define IS_FAILED(s)
Check if result is failed.
Definition result.h:20
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 THROW_IF_FAILED_DESC(s,...)
throws if the expression returns a failed tResult and ammends the error message.
Definition result.h:98
#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
const tChar * GetDescription() const noexcept
Get user provided error description.
tErrorCode GetErrorCode() const noexcept
Get error code.
Definition string_intf.h:29
Definition graph_intf.h:24
Definition graph_intf.h:103
Definition named_graph_object_intf.h:25
Definition graph.h:21
virtual tResult RemoveNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject)
Removes a Named Graph Object by instance. This virtual function must be overwritten by any derived cl...
tResult RemoveNamedGraphObject(const char *strName)
virtual tResult AddNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject, int32_t ui32OrderNumber)
Definition graph.h:103
tResult AddNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject, int32_t ui32OrderNumber) override
Definition graph.h:120
virtual ~graph()=default
DTOR.
tResult SetName(const char *strName) override
Definition named_graph_object.h:64
Definition object_intf.h:33
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.
Definition object_ptr_intf.h:112
Definition object_ptr.h:384
Definition object.h:397
Namespace for all functionality of the ADTF Streaming SDK provided since v3.0.
Definition bindingproxyoutport.h:16
tResult get_named_graph_object_from_graph(IGraph &oGraph, const char *strName, ucom::ant::iobject_ptr< ucom::ant::IObject > &pObjectFound)
adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject &oGraphObject)
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
iobject_enum< T > iobject_list
Definition object_list.h:387
ant::weak_object_ptr< T > weak_object_ptr
Alias always bringing the latest version of ant::weak_object_ptr into scope.
Definition weak_object_ptr.h:232
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14
#define adtf_string_intf(__string__)
Definition string_intf.h:465