AudioManager  7.6.6
Native Application Runtime Environment
CAmRouter.h
Go to the documentation of this file.
1 
25 #ifndef ROUTER_H_
26 #define ROUTER_H_
27 
28 #include <assert.h>
29 #include <vector>
30 #include <iomanip>
31 #include <functional>
32 #include "audiomanagertypes.h"
33 #include "CAmGraph.h"
34 #include "CAmDatabaseHandlerMap.h"
35 
36 namespace am
37 {
38 
50 #undef TRACE_GRAPH
51 
55 #ifndef MAX_ROUTING_PATHS
56 #define MAX_ROUTING_PATHS 5
57 #endif
58 
67 #ifndef MAX_ALLOWED_DOMAIN_CYCLES
68 #define MAX_ALLOWED_DOMAIN_CYCLES 1
69 #endif
70 
71  class CAmRouter;
72 
77  {
78  typedef enum
79  :int
82  am_NodeDataType_e type;
83  union
84  {
89  } data;
90 
92  type(SINK)
93  {
94  }
95 
96  bool operator==(const am_RoutingNodeData_s & anotherObject) const
97  {
98  bool result = false;
99  if (type == anotherObject.type)
100  {
101  result = true;
102  if (type == SINK)
103  result &= (data.sink->sinkID == anotherObject.data.sink->sinkID);
104  else if (type == SOURCE)
105  result &= (data.source->sourceID == anotherObject.data.source->sourceID);
106  else if (type == GATEWAY)
107  result &= (data.gateway->gatewayID == anotherObject.data.gateway->gatewayID);
108  else if (type == CONVERTER)
109  result &= (data.converter->converterID == anotherObject.data.converter->converterID);
110  }
111  return result;
112  }
113  ;
114 
115 #ifdef TRACE_GRAPH
116 #define COUT_NODE(HEAD, NAME, ID) \
117  std::cout << HEAD << "(" << std::setfill('0') << std::setw(4) << ID << " " << NAME << ")";
118 
119  void trace() const
120  {
121  if(type==SINK)
122  COUT_NODE("SI", data.sink->name, data.sink->sinkID )
123  else if(type==SOURCE)
124  COUT_NODE("SO", data.source->name, data.source->sourceID )
125  else if(type==GATEWAY)
126  COUT_NODE("GA", data.gateway->name, data.gateway->gatewayID )
127  else if(type==CONVERTER)
128  COUT_NODE("CO", data.converter->name, data.converter->converterID )
129  };
130 #endif
131 
133  {
134  if (type == SINK)
135  return data.sink->domainID;
136  else if (type == SOURCE)
137  return data.source->domainID;
138  else if (type == GATEWAY)
139  return data.gateway->controlDomainID;
140  else if (type == CONVERTER)
141  return data.converter->domainID;
142  return 0;
143  }
144  ;
145  };
146 
151  typedef std::list<CAmRoutingVertex> CAmRoutingListVertices;
152  typedef std::vector<CAmRoutingListVertices*> CAmRoutingVertexReferenceList;
153 
154  class CAmControlSender;
155 
160  {
161  IAmDatabaseHandler* mpDatabaseHandler;
162  CAmControlSender* mpControlSender;
163  bool mUpdateGraphNodesAction;
164  unsigned mMaxAllowedCycles;
165  unsigned mMaxPathCount;
166  CAmRoutingGraph mRoutingGraph;
167  std::map<am_domainID_t, std::vector<CAmRoutingNode*>> mNodeListSources;
168  std::map<am_domainID_t, std::vector<CAmRoutingNode*>> mNodeListSinks;
169  std::map<am_domainID_t, std::vector<CAmRoutingNode*>> mNodeListGateways;
170  std::map<am_domainID_t, std::vector<CAmRoutingNode*>> mNodeListConverters;
171 
177  template<class Component> bool isComponentConnected(const Component & comp)
178  {
179  return mpDatabaseHandler->isComponentConnected(comp);
180  }
181 
186  void constructConverterConnections();
187 
192  void constructGatewayConnections();
193 
198  void constructSourceSinkConnections();
199 
203  void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list);
204 
208  void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list);
209 
213  void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list);
214 
218  void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list);
219 
223  void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list);
224 
230  am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector<CAmRoutingNode*> & nodes, std::vector<am_Route_s> & result);
231  am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, std::vector<CAmRoutingNode*> & route,
232  std::vector<am_RoutingElement_s>::iterator routingElementIterator, std::vector<CAmRoutingNode*>::iterator routeIterator,
233  std::vector<am_Route_s> & result);
234  am_Error_e cfPermutationsForPath(am_Route_s shortestRoute, std::vector<CAmRoutingNode*> resultNodesPath, std::vector<am_Route_s>& resultPath);
235 
239  static int insertPostion(const std::vector<CAmRoutingNode*>& path, const std::vector<std::vector<CAmRoutingNode*> >& nodes);
240 
241  public:
242  CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender);
243  ~CAmRouter();
244 
246  {
247  return mMaxAllowedCycles;
248  }
249  void setMaxAllowedCycles(unsigned count)
250  {
251  mMaxAllowedCycles = count;
252  }
253 
254  unsigned getMaxPathCount()
255  {
256  return mMaxPathCount;
257  }
258  void setMaxPathCount(unsigned count)
259  {
260  mMaxPathCount = count;
261  }
262 
264  {
265  return mUpdateGraphNodesAction;
266  }
267 
277  am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s>& returnList);
278  am_Error_e getRoute(const bool onlyfree, const am_Source_s & source, const am_Sink_s & sink, std::vector<am_Route_s> & listRoutes);
279 
289  am_Error_e getRouteFromLoadedNodes(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s> & returnList);
290  am_Error_e getRouteFromLoadedNodes(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<am_Route_s> & listRoutes);
291 
303  am_Error_e getFirstNShortestPaths(const bool onlyfree, const unsigned cycles, const unsigned maxPathCount, CAmRoutingNode & source,
304  CAmRoutingNode & sink, std::vector<am_Route_s> & resultPath);
305 
315  am_Error_e getShortestPath(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector<am_Route_s> & resultPath);
316 
317  static bool getAllowedFormatsFromConvMatrix(const std::vector<bool> & convertionMatrix,
318  const std::vector<am_CustomConnectionFormat_t> & listSourceFormats, const std::vector<am_CustomConnectionFormat_t> & listSinkFormats,
319  std::vector<am_CustomConnectionFormat_t> & sourceFormats, std::vector<am_CustomConnectionFormat_t> & sinkFormats);
320  static void listPossibleConnectionFormats(std::vector<am_CustomConnectionFormat_t> & inListSourceFormats,
321  std::vector<am_CustomConnectionFormat_t> & inListSinkFormats, std::vector<am_CustomConnectionFormat_t> & outListFormats);
322  static bool getRestrictedOutputFormats(const std::vector<bool> & convertionMatrix, const std::vector<am_CustomConnectionFormat_t> & listSourceFormats,
323  const std::vector<am_CustomConnectionFormat_t> & listSinkFormats, const am_CustomConnectionFormat_t connectionFormat,
324  std::vector<am_CustomConnectionFormat_t> & listFormats);
325  static am_Error_e getSourceSinkPossibleConnectionFormats(std::vector<CAmRoutingNode*>::iterator iteratorSource,
326  std::vector<CAmRoutingNode*>::iterator iteratorSink, std::vector<am_CustomConnectionFormat_t> & outConnectionFormats);
327 
328  static bool shouldGoInDomain(const std::vector<am_domainID_t> & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber);
329  bool shouldGoInDomain(const std::vector<am_domainID_t> & visitedDomains, const am_domainID_t nodeDomainID);
336  CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID);
337  CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID);
338 
345  CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID);
346  CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID);
347 
355  CAmRoutingNode* converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID);
356 
363  CAmRoutingNode* gatewayNodeWithSinkID(const am_sinkID_t sinkID);
364 
365  void load();
366  void clear();
367 
371  public:
372  am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector<am_Route_s> & resultPath,
373  std::vector<std::vector<CAmRoutingNode*>> & resultNodesPath, const bool includeCycles = false,
374  const bool onlyFree = false)
375  __attribute__((deprecated("You should use am_Error_e getFirstNShortestPaths(const bool onlyFree, CAmRoutingNode &, CAmRoutingNode &, std::vector<am_Route_s> &) instead!")));
376  };
377 } /* namespace am */
378 #endif /* ROUTER_H_ */
379 
std::vector< CAmRoutingListVertices * > CAmRoutingVertexReferenceList
Definition: CAmRouter.h:152
am_domainID_t domainID() const
Definition: CAmRouter.h:132
am_converterID_t converterID
This is the ID of the converter, it is unique in the system.
A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects...
am_Error_e
the errors of the audiomanager.
This struct describes the attribiutes of a sink.
am_sinkID_t sinkID
This is the ID of the sink, it is unique in the system.
Implements autorouting algorithm for connecting sinks and sources via different audio domains...
Definition: CAmRouter.h:159
am_NodeDataType_e type
data type:sink, source, gateway or converter
Definition: CAmRouter.h:82
virtual bool isComponentConnected(const am_Gateway_s &gateway) const =0
uint16_t am_CustomConnectionFormat_t
This type classifies the format in which data is exchanged within a connection.
union am::am_RoutingNodeData_s::@0 data
union pointer to sink, source, gateway or converter
STL namespace.
am_gatewayID_t gatewayID
This is the ID of the gateway, it is unique in the system.
am_Source_s * source
Definition: CAmRouter.h:85
SPDX license identifier: MPL-2.0.
am_Gateway_s * gateway
Definition: CAmRouter.h:87
uint16_t am_sourceID_t
a source ID
am_RoutingNodeData_s::am_NodeDataType_e CAmNodeDataType
Definition: CAmRouter.h:147
CAmGraph< am_RoutingNodeData_s, uint16_t > CAmRoutingGraph
Definition: CAmRouter.h:149
sends data to the commandInterface, takes the file of the library that needs to be loaded ...
This class handles and abstracts the database.
bool getUpdateGraphNodesAction()
Definition: CAmRouter.h:263
This struct describes the attributes of a converter.
CAmNode< am_RoutingNodeData_s > CAmRoutingNode
Definition: CAmRouter.h:148
a list of routing elements that lead from source to sink
am_sourceID_t sourceID
This is the ID of the source, it is unique in the system.
am_Converter_s * converter
Definition: CAmRouter.h:88
std::list< CAmRoutingVertex > CAmRoutingListVertices
Definition: CAmRouter.h:151
Copyright (C) 2012 - 2014, BMW AG.
unsigned getMaxPathCount()
Definition: CAmRouter.h:254
SPDX license identifier: MPL-2.0.
void setMaxPathCount(unsigned count)
Definition: CAmRouter.h:258
This struct describes the attributes of a gateway.
uint16_t am_domainID_t
a domain ID
void setMaxAllowedCycles(unsigned count)
Definition: CAmRouter.h:249
unsigned getMaxAllowedCycles()
Definition: CAmRouter.h:245
This struct describes the attribiutes of a source.
uint16_t am_sinkID_t
a sink ID
CAmVertex< am_RoutingNodeData_s, uint16_t > CAmRoutingVertex
Definition: CAmRouter.h:150
bool operator==(const am_RoutingNodeData_s &anotherObject) const
Definition: CAmRouter.h:96
A structure used as user data in the graph nodes.
Definition: CAmRouter.h:76