ADTF  3.18.2
graph.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "named_graph_object.h"
9 #include "graph_intf.h"
10 
11 namespace adtf
12 {
13 namespace streaming
14 {
15 namespace ant
16 {
21 class cGraph
22 {
23  private:
25  std::map<adtf_util::cString, ucom::object_ptr<INamedGraphObject>> m_oGraphObjects;
27  std::multimap<int32_t, ucom::object_ptr<INamedGraphObject>> m_oObjectOrder;
28 
29  public:
31  cGraph() = default;
33  virtual ~cGraph();
34 
35  public: //implements IGraph
36  tResult GetNamedGraphObject(const char* strName, ucom::ant::iobject_ptr<ucom::ant::IObject>& pObject) const;
37  tResult GetNamedGraphObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const;
38 
39  public:
57  int32_t ui32OrderNumber);
64  tResult RemoveNamedGraphObject(const char* strName);
65 
74 
75  protected:
76  tResult CheckName(const adtf_util::cString& strObjectName);
77 
78  template <typename OBJECT_INTERFACE>
79  tResult AddObject(const ucom::ant::iobject_ptr<OBJECT_INTERFACE>& pGraphObject, int32_t ui32OrderNumber)
80  {
81  adtf::ucom::ant::object_ptr<INamedGraphObject> pNamedObject = pGraphObject;
82  RETURN_IF_POINTER_NULL(pNamedObject);
83  return AddNamedGraphObject(pNamedObject, ui32OrderNumber);
84  }
85 
86  // tResult RemoveConnection(const adtf::ucom::ant::iobject_ptr<IGraphConnection>& pConnection);
87  tResult RemoveAllConnectionsFrom(const INamedGraphObject* pObj);
88 
89  tResult AddAlias(const char* strAliasName, const ucom::ant::iobject_ptr<INamedGraphObject>& pGraphObject);
90  tResult GetAliasObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const;
91 
92  private:
93  template <typename OBJECT_INTERFACE>
94  tResult EraseObject(const ucom::ant::iobject_ptr<OBJECT_INTERFACE>& pGraphObject);
95 };
96 
101 template <typename INTERFACE = IGraph>
102 class graph : public cGraph,
103  public ucom::catwo::object<IGraph, INTERFACE>
104 {
105 public:
107  graph() = default;
109  virtual ~graph() = default;
110 
111 public:
112  tResult GetNamedGraphObject(const char* strName, ucom::ant::iobject_ptr<adtf::ucom::ant::IObject>& pObject) const override
113  {
114  return cGraph::GetNamedGraphObject(strName, pObject);
115  }
116  tResult GetNamedGraphObjects(ucom::ant::iobject_list<INamedGraphObject>& lstItems) const override
117  {
118  return cGraph::GetNamedGraphObjects(lstItems);
119  }
120 
122  int32_t ui32OrderNumber) override
123  {
124  RETURN_IF_FAILED(cGraph::AddNamedGraphObject(pGraphObject, ui32OrderNumber));
125  pGraphObject.Get()->SetParent(static_cast<ucom::ant::IObject*>(static_cast<INamedGraphObject*>(this)));
127  }
128 };
129 
130 template<typename CONNECTOR,
131  typename INTERFACE = IGraphConnection>
132 class graph_connection : public ucom::catwo::object<IGraphConnection, named_graph_object<INTERFACE>>
133 {
134 protected:
135  bool m_bConnected = false;
136 
139  adtf_util::cString m_strSourceName;
140  adtf_util::cString m_strSourceConnectorName;
141  adtf_util::cString m_strDestinationName;
142  adtf_util::cString m_strDestinationConnectorName;
143  bool m_bConnectRunner;
144 
145 protected:
146  graph_connection(const graph_connection&) = delete;
148  graph_connection& operator=(const graph_connection&) = delete;
149  graph_connection& operator=(graph_connection&&) = delete;
150 
151 public:
152  graph_connection() = default;
153 
154  graph_connection(const char* strName,
155  const char* strSource,
156  const char* strSourceConnector,
157  const char* strDest,
158  const char* strDestConnector,
161  bool bConnectRunner)
162  {
163  THROW_IF_FAILED_DESC(CONNECTOR::IsSupported(pSource,
164  strSourceConnector,
165  pDest,
166  strDestConnector),
167  "The connection from %s.%s to %s.%s is not supported.",
168  strSource,
169  strSourceConnector,
170  strDest,
171  strDestConnector);
172 
174  m_strSourceName = strSource;
175  m_strSourceConnectorName = strSourceConnector;
176  m_strDestinationName = strDest;
177  m_strDestinationConnectorName = strDestConnector;
178  m_pSource = pSource;
179  m_pDest = pDest;
180  m_bConnectRunner = bConnectRunner;
181 
182  LOG_DUMP("Init CONNECTION %s.%s -> %s.%s ", strSource, strSourceConnector, strDest, strDestConnector);
183  }
184 
185  virtual ~graph_connection()
186  {
187  if (m_bConnected)
188  {
189  Disconnect();
190  }
191  }
192 
193  tResult Connect() override
194  {
195  auto pSource = m_pSource.Lock();
196  auto pDest = m_pDest.Lock();
197  if (pSource && pDest)
198  {
199  adtf_util::cString oSourceName;
200  pSource->GetName(adtf_string_intf(oSourceName));
201 
202  adtf_util::cString oDestName;
203  pDest->GetName(adtf_string_intf(oDestName));
204  LOG_DETAIL("Connecting CONNECTION %s.%s -> %s.%s ",
205  oSourceName.GetPtr(),
206  m_strSourceConnectorName.GetPtr(),
207  oDestName.GetPtr(),
208  m_strDestinationConnectorName.GetPtr());
209 
210  tResult nRes = CONNECTOR::Connect(pSource,
211  m_strSourceConnectorName,
212  pDest,
213  m_strDestinationConnectorName,
214  m_bConnectRunner);
215  if (IS_FAILED(nRes))
216  {
218  "Can not connect %s.%s with %s.%s - %s",
219  m_strSourceName.GetPtr(),
220  m_strSourceConnectorName.GetPtr(),
221  m_strDestinationName.GetPtr(),
222  m_strDestinationConnectorName.GetPtr(),
223  nRes.GetDescription());
224  }
225  }
226  else
227  {
228  RETURN_ERROR_DESC(ERR_NOT_FOUND,
229  "Can not connect %s.%s with %s.%s, "
230  "a connection point disappeared ??",
231  m_strSourceName.GetPtr(),
232  m_strSourceConnectorName.GetPtr(),
233  m_strDestinationName.GetPtr(),
234  m_strDestinationConnectorName.GetPtr());
235  }
236  m_bConnected = true;
238  }
239 
240  tResult Disconnect() override
241  {
242  //we set the state to disconnected also if it fails
243  m_bConnected = false;
244  auto pSource = m_pSource.Lock();
245  auto pDest = m_pDest.Lock();
246 
247  if (pSource && pDest)
248  {
249  RETURN_IF_FAILED(CONNECTOR::Disconnect(pSource,
250  m_strSourceConnectorName,
251  pDest,
252  m_strDestinationConnectorName,
253  m_bConnectRunner));
254  }
256  }
257 
258  tResult GetSource(ucom::ant::iobject_ptr<INamedGraphObject>& pSource) const override
259  {
260  auto pNO = m_pSource.Lock();
261  if (pNO)
262  {
263  return pSource.Reset(pNO);
264  }
265  RETURN_ERROR(ERR_NOT_FOUND);
266  }
267  tResult GetSourceName(base::ant::IString&& strName) const override
268  {
269  return strName.Set(m_strSourceName);
270  }
271 
272  tResult GetSourceConnectorName(base::ant::IString&& strName) const override
273  {
274  return strName.Set(m_strSourceConnectorName);
275  }
276 
277  tResult GetDestination(ucom::ant::iobject_ptr<INamedGraphObject>& pDestination) const override
278  {
279  auto pNO = m_pDest.Lock();
280  if (pNO)
281  {
282  return pDestination.Reset(pNO);
283  }
284  RETURN_ERROR(ERR_NOT_FOUND);
285  }
286 
287  tResult GetDestinationName(base::ant::IString&& strName) const override
288  {
289  return strName.Set(m_strDestinationName);
290  }
291 
292  tResult GetDestinationConnectorName(base::ant::IString&& strName) const override
293  {
294  return strName.Set(m_strDestinationConnectorName);
295  }
296 
297  bool IsConnected() const override
298  {
299  return m_bConnected;
300  }
301 };
302 
303 
314 
323 
332 adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject& oGraphObject, const char* strSeperator);
333 
334 
335 } //namespace ant
336 
338 using ant::cGraph;
339 using ant::graph;
340 
342 
345 
346 
347 }
348 }
#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...
const tChar * GetDescription() const
Get user provided error description.
tErrorCode GetErrorCode() const
Get error code.
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition: string_intf.h:28
Interface to describe a connection within the IGraph.
Definition: graph_intf.h:24
Defines the Interface used to connect Items to each other.
Definition: graph_intf.h:104
Interface for a NamedGraphObject which can be added to the FilterGraph.
Default implementation for the IFilterGraph interface.
Definition: graph.h:22
std::multimap< int32_t, ucom::object_ptr< INamedGraphObject > > m_oObjectOrder
Graph Object Registry.
Definition: graph.h:27
virtual tResult AddNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject, int32_t ui32OrderNumber)
This is to intialize and build an FilterGraph.
virtual tResult RemoveNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject)
Removes a Named Graph Object by instance.
tResult RemoveNamedGraphObject(const char *strName)
Removes a named Object from the Filter Graph.
std::map< adtf_util::cString, ucom::object_ptr< INamedGraphObject > > m_oGraphObjects
Graph Object Registry.
Definition: graph.h:25
Generator Template to create a graph implementation.
Definition: graph.h:104
virtual ~graph()=default
DTOR.
tResult AddNamedGraphObject(const ucom::ant::iobject_ptr< INamedGraphObject > &pGraphObject, int32_t ui32OrderNumber) override
This is to intialize and build an FilterGraph.
Definition: graph.h:121
tResult SetName(const char *strName) override
Sets the Name of the object.
Base class for every interface type within the uCOM.
Definition: object_intf.h:31
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
Implementation of a weak pointer for usage with iobject_ptr and object_ptr.
object_ptr< T > Lock() const
Create an object_ptr<> from *this weak pointer (thread safe).
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.
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
tResult get_named_graph_object_from_graph(IGraph &oGraph, const char *strName, ucom::ant::iobject_ptr< ucom::ant::IObject > &pObjectFound)
Helper function to retrieve a graph object from a graph with fully qualified unique name of an object...
adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject &oGraphObject)
Helper function to retrieve a full qualified unique name of an object registered in IFilterGraph.
Namespace for entire ADTF SDK.
#define adtf_string_intf(__string__)
The adtf_string_intf Macro helps to easily create a rvalue reference of a adtf::util::cString.
Definition: string_intf.h:371
#define THROW_IF_FAILED_DESC(s,...)
throws if the expression returns a failed tResult and ammends the error message.