From b9161ce995cd59512086a0713ab6f58bbb2047f1 Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Wed, 11 Jan 2017 10:58:58 -0800 Subject: fix proper log level checking Signed-off-by: Christian Linke --- AudioManagerUtilities/src/CAmDltWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AudioManagerUtilities/src/CAmDltWrapper.cpp b/AudioManagerUtilities/src/CAmDltWrapper.cpp index 4b82e33..dc594af 100644 --- a/AudioManagerUtilities/src/CAmDltWrapper.cpp +++ b/AudioManagerUtilities/src/CAmDltWrapper.cpp @@ -424,7 +424,7 @@ bool CAmDltWrapper::initNoDlt(DltLogLevelType loglevel, DltContext* context) if (!context) context = &mDltContext; - if(dlt_user_log_write_start(context, &mDltContextData, loglevel) < 0) + if(dlt_user_log_write_start(context, &mDltContextData, loglevel) <= 0) { pthread_mutex_unlock(&mMutex); return false; -- cgit v1.2.1 From 17c439ae25beec19fba090faa360d6ef04336a4c Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Wed, 18 Jan 2017 05:00:44 -0800 Subject: Return all routes with all possible connection formats Removed obsolete sqlite interface handling Signed-off-by: Christian Linke Change-Id: I380f6d4ce1dab2efa47620164e72a30fa144afdd --- AudioManagerCore/include/CAmRouter.h | 28 ++-- AudioManagerCore/src/CAmRouter.cpp | 139 +++++++++---------- .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 151 +++++++++++++++++---- 3 files changed, 200 insertions(+), 118 deletions(-) diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h index 7e52b7c..705fb4a 100644 --- a/AudioManagerCore/include/CAmRouter.h +++ b/AudioManagerCore/include/CAmRouter.h @@ -27,6 +27,7 @@ #include #include +#include #include #include "audiomanagertypes.h" #include "CAmGraph.h" @@ -35,7 +36,6 @@ namespace am { -#define ROUTING_BUILD_CONNECTIONS 1 /** * Optimal path search between a source and a sink is implemented with a graph which contains nodes - sinks, sources, gateways, converters. @@ -105,20 +105,19 @@ struct am_RoutingNodeData_s }; #ifdef TRACE_GRAPH +#define COUT_NODE(HEAD, NAME, ID) \ + std::cout << HEAD << "(" << std::setfill('0') << std::setw(4) << ID << " " << NAME << ")"; + void trace() const { if(type==SINK) - std::cout << "[SINK:" << data.sink->sinkID << ":" << data.sink->name << "(" << data.sink->domainID << ")" - << "]"; + COUT_NODE("SI", data.sink->name, data.sink->sinkID ) else if(type==SOURCE) - std::cout << "[SOUR:" << data.source->sourceID << ":" << data.source->name << "(" << data.source->domainID << ")" - << "]"; + COUT_NODE("SO", data.source->name, data.source->sourceID ) else if(type==GATEWAY) - std::cout << "[GATE:" << data.gateway->gatewayID << ":" << data.gateway->name << "(" << data.gateway->controlDomainID << ")" - << "]"; + COUT_NODE("GA", data.gateway->name, data.gateway->gatewayID ) else if(type==CONVERTER) - std::cout << "[CONV:" << data.converter->converterID << ":" << data.converter->name << "(" << data.converter->domainID << ")" - << "]"; + COUT_NODE("CO", data.converter->name, data.converter->converterID ) }; #endif @@ -160,11 +159,12 @@ class CAmRouter std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access std::map> mNodeListConverters;//!< map with pointers to nodes with converters, used for quick access - am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes); + am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & route, - std::vector::iterator routingElementIterator, - std::vector::iterator routeIterator); + std::vector & route, + std::vector::iterator routingElementIterator, + std::vector::iterator routeIterator, + std::vector & result); /** @@ -270,7 +270,7 @@ public: const std::vector & listSinkFormats, const am_CustomConnectionFormat_t connectionFormat, std::vector & listFormats); - static void getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, + static am_Error_e getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, std::vector::iterator iteratorSink, std::vector & outConnectionFormats); diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index f98bf11..f59af24 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -108,15 +108,19 @@ am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, #ifdef TRACE_GRAPH mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { - std::cout << "Node " << node.getIndex() << " :"; + std::cout << "Node " << node.getIndex() << ":"; ((CAmRoutingNode &)node).getData().trace(); - std::cout << "-->"; + std::cout << "-->["; + int count = 0; std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ am::CAmNode* data = refVertex->getNode(); - std::cout << "Node " << data->getIndex() << " :"; + if(count>0) + std::cout << ", "; + std::cout << "Node " << data->getIndex() << ":"; data->getData().trace(); + count++; }); - std::cout << std::endl; + std::cout << "]" << std::endl; }); #endif @@ -130,54 +134,28 @@ void CAmRouter::load(const bool onlyFree) clear(); mOnlyFreeConversionNodes = onlyFree; -#if defined (WITH_DATABASE_STORAGE) - std::deque listSources; - std::deque listSinks; - std::deque listGateways; - std::deque listConverters; -#endif am_RoutingNodeData_s nodeDataSrc; nodeDataSrc.type = CAmNodeDataType::SOURCE; mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listSources.push_back(obj); - nodeDataSrc.data.source = &listSources.back(); -#else nodeDataSrc.data.source = (am_Source_s*)&obj; -#endif mNodeListSources[nodeDataSrc.data.source->domainID].push_back(&mRoutingGraph.addNode(nodeDataSrc)); - }); + }); am_RoutingNodeData_s nodeDataSink; nodeDataSink.type = CAmNodeDataType::SINK; mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listSinks.push_back(obj); - nodeDataSrc.data.sink = &listSinks.back(); -#else nodeDataSink.data.sink = (am_Sink_s*)&obj; -#endif mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(&mRoutingGraph.addNode(nodeDataSink)); - }); + }); am_RoutingNodeData_s nodeDataGateway; nodeDataGateway.type = CAmNodeDataType::GATEWAY; mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listGateways.push_back(obj); - nodeDataSrc.data.gateway = &listGateways.back(); -#else nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; -#endif mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(&mRoutingGraph.addNode(nodeDataGateway)); }); am_RoutingNodeData_s nodeDataConverter; nodeDataConverter.type = CAmNodeDataType::CONVERTER; mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){ -#if defined (WITH_DATABASE_STORAGE) - listConverters.push_back(obj); - nodeDataSrc.data.converter = &listConverters.back(); -#else nodeDataConverter.data.converter = (am_Converter_s*)&obj; -#endif mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(&mRoutingGraph.addNode(nodeDataConverter)); }); @@ -494,19 +472,20 @@ void CAmRouter::getVerticesForNode( #endif -am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes) +am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result) { std::vector::iterator routingElementIterator = routeObjects.route.begin(); std::vector::iterator nodeIterator = nodes.begin(); if( routingElementIterator!= routeObjects.route.end() && nodeIterator!=nodes.end() ) - return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator); + return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator, result); return E_OK; } am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector::iterator routingElementIterator, - std::vector::iterator nodeIterator) + std::vector::iterator nodeIterator, + std::vector & result) { am_Error_e returnError = E_NOT_POSSIBLE; std::vector listConnectionFormats; @@ -520,7 +499,8 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, std::vector listConnectionFormats; std::vector::iterator tempIterator = (currentRoutingElementIterator-1); CAmRoutingNode * currentNode = *currentNodeIterator; - getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats); + if((returnError = getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats))!=E_OK) + return returnError; if(currentNode->getData().type==CAmNodeDataType::GATEWAY) { @@ -532,29 +512,34 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, am_Converter_s *converter = currentNode->getData().data.converter; getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); } + else + return (E_UNKNOWN); currentNodeIterator+=3; } else { CAmRoutingNode * currentNode = *currentNodeIterator; - assert(currentNode->getData().type==CAmNodeDataType::SOURCE); - + if(currentNode->getData().type!=CAmNodeDataType::SOURCE) + return (E_UNKNOWN); currentNodeIterator++; - assert(currentNodeIterator!=nodes.end()); + + if(currentNodeIterator==nodes.end()) + return (E_UNKNOWN); CAmRoutingNode * nodeSink = *currentNodeIterator; - assert(nodeSink->getData().type==CAmNodeDataType::SINK); + if(nodeSink->getData().type!=CAmNodeDataType::SINK) + return (E_UNKNOWN); am_Source_s *source = currentNode->getData().data.source; am_Sink_s *sink = nodeSink->getData().data.sink; listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats); currentNodeIterator+=1; //now we are on the next converter/gateway } - //let the controller decide: std::vector listPriorityConnectionFormats; - mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects, - listMergeConnectionFormats, listPriorityConnectionFormats); + if((returnError = mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects, + listMergeConnectionFormats, listPriorityConnectionFormats))!= E_OK) + return (returnError); //we have the list sorted after priors - now we try one after the other with the next part of the route std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); @@ -564,22 +549,25 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, { if (!listPriorityConnectionFormats.empty()) { - currentRoutingElementIterator->connectionFormat = listPriorityConnectionFormats.front(); + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + { + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + result.push_back(routeObjects); + } return (E_OK); } else return (E_NOT_POSSIBLE); } - - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + else { - currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; - if ((returnError = doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator)) == E_OK) + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) { - break; + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator, result); } + return (E_OK); } - return (returnError); } #ifdef ROUTING_BUILD_CONNECTIONS @@ -642,8 +630,7 @@ am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, uint8_t errorsCount = 0, successCount = 0; generateAllPaths(aSource, aSink, cycles, [&](const std::vector & path) { resultNodesPath.push_back(path); - resultPath.emplace_back(); - am_Route_s & nextRoute = resultPath.back(); + am_Route_s nextRoute; nextRoute.sinkID = aSink.getData().data.sink->sinkID; nextRoute.sourceID = aSource.getData().data.source->sourceID; am_RoutingElement_s * element; @@ -665,35 +652,37 @@ am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, element->connectionFormat = CF_UNKNOWN; } } - - am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector &)path); - if(err!=E_OK) + std::vector result; + am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector &)path, result); + if(err==E_UNKNOWN) { errorsCount++; - auto last = resultPath.end()-1; - resultPath.erase(last); #ifdef TRACE_GRAPH std::cout<<"Error by determining connection formats for path from source:"<" - <" + < & convertionM } -void CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, +am_Error_e CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, std::vector::iterator iteratorSink, std::vector & outConnectionFormats) { CAmRoutingNode * nodeSink = *iteratorSink; - assert(nodeSink->getData().type==CAmNodeDataType::SINK); + if(nodeSink->getData().type!=CAmNodeDataType::SINK) + return (E_UNKNOWN); CAmRoutingNode * nodeSource = *iteratorSource; - assert(nodeSource->getData().type==CAmNodeDataType::SOURCE); + if(nodeSource->getData().type!=CAmNodeDataType::SOURCE) + return (E_UNKNOWN); am_Source_s *source = nodeSource->getData().data.source; am_Sink_s *sink = nodeSink->getData().data.sink; listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats); + return (E_OK); } - } diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp index 465995f..9dd23af 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -175,7 +175,7 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const am_Source_s & aSource ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, aSource, aSink, listRoutes)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); - std::cout << "getRoute did find " << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; + std::cout << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; std::cout.flags (oldflags); std::cout.precision (oldprecision); @@ -189,7 +189,7 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceI ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, sourceID, sinkID, returnList)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); - std::cout << "getRoute by id did find " << returnList.size() <<" routes from " << sourceID << " to " << sinkID; + std::cout << returnList.size() <<" routes from " << sourceID << " to " << sinkID; std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; std::cout.flags (oldflags); std::cout.precision (oldprecision); @@ -207,7 +207,7 @@ void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, ASSERT_EQ(E_OK, pRouter.getAllPaths(aSource, aSink, resultPath, resultNodesPath, includeCycles)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); - std::cout << "getAllPaths did find " << resultPath.size() + std::cout << resultPath.size() << " routes from " << aSource.getData().data.source->sourceID << " to " << aSink.getData().data.sink->sinkID; std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; @@ -3365,18 +3365,18 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) am_sourceID_t gwSourceID22; enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22); - am_sourceID_t gwSourceID5; - enterSourceDB("gwSource5", domainID3, cfStereo, gwSourceID5); - am_sinkID_t gwSinkID5; - enterSinkDB("gwSink5", domainID3, cfAnalog, gwSinkID5); - am_sourceID_t gwSourceID3; - enterSourceDB("gwSource3", domainID3, cfAnalog, gwSourceID3); - am_sinkID_t gwSinkID3; - enterSinkDB("gwSink3", domainID3, cfAuto, gwSinkID3); - am_sourceID_t gwSourceID4; - enterSourceDB("gwSource4", domainID3, cfStereo, gwSourceID4); - am_sinkID_t gwSinkID4; - enterSinkDB("gwSink4", domainID3, cfAnalog, gwSinkID4); + am_sourceID_t cSourceID5; + enterSourceDB("cSource5", domainID3, cfStereo, cSourceID5); + am_sinkID_t cSinkID5; + enterSinkDB("cSink5", domainID3, cfAnalog, cSinkID5); + am_sourceID_t cSourceID3; + enterSourceDB("cSource3", domainID3, cfAnalog, cSourceID3); + am_sinkID_t cSinkID3; + enterSinkDB("cSinkID3", domainID3, cfAuto, cSinkID3); + am_sourceID_t cSourceID4; + enterSourceDB("cSource4", domainID3, cfStereo, cSourceID4); + am_sinkID_t cSinkID4; + enterSinkDB("cSink4", domainID3, cfAnalog, cSinkID4); am_sinkID_t sinkID; enterSinkDB("sink1", domainID3, cfStereo, sinkID); @@ -3389,11 +3389,11 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) am_gatewayID_t gatewayID21; enterGatewayDB("gateway21", domainID3, domainID1, cfAuto, cfStereo, matrix, gwSourceID21, gwSinkID21, gatewayID21); am_converterID_t converterID1; - enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, gwSourceID3, gwSinkID3, converterID1); + enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, cSourceID3, cSinkID3, converterID1); am_converterID_t converterID2; - enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, gwSourceID4, gwSinkID4, converterID2); + enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, cSourceID4, cSinkID4, converterID2); am_converterID_t converterID3; - enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, gwSourceID5, gwSinkID5, converterID3); + enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, cSourceID5, cSinkID5, converterID3); am::am_Source_s source; am::am_Sink_s sink; @@ -3411,34 +3411,34 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) compareRoute1.sourceID = sourceID; compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); compareRoute1.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute1.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute1.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute1.route.push_back({cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute1.route.push_back({cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); am_Route_s compareRoute2; compareRoute2.sinkID = sinkID; compareRoute2.sourceID = sourceID; compareRoute2.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); compareRoute2.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute2.route.push_back({gwSourceID22, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute2.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute2.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + compareRoute2.route.push_back({gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute2.route.push_back({cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute2.route.push_back({cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); am_Route_s compareRoute3; compareRoute3.sinkID = sinkID; compareRoute3.sourceID = sourceID; compareRoute3.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute3.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute3.route.push_back({gwSourceID3, gwSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute3.route.push_back({gwSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); + compareRoute3.route.push_back({gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute3.route.push_back({cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG}); + compareRoute3.route.push_back({cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); am_Route_s compareRoute4; compareRoute4.sinkID = sinkID; compareRoute4.sourceID = sourceID; compareRoute4.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute4.route.push_back({gwSourceID21, gwSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute4.route.push_back({gwSourceID3, gwSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute4.route.push_back({gwSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); + compareRoute4.route.push_back({gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO}); + compareRoute4.route.push_back({cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG}); + compareRoute4.route.push_back({cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| pCF.compareRoute(compareRoute1,listRoutes[1])|| @@ -3461,6 +3461,97 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) pCF.compareRoute(compareRoute4,listRoutes[3])); } +TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_SourceClass_s sourceclass; + + sourceclass.name="sClass"; + sourceclass.sourceClassID=5; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + + am_SinkClass_s sinkclass; + sinkclass.sinkClassID=5; + sinkclass.name="sname"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + + std::vector matrix; + matrix.push_back(true); + matrix.push_back(false); + matrix.push_back(false); + matrix.push_back(true); + + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + + std::vector cfMulti; + cfMulti.push_back(CF_GENIVI_STEREO); + cfMulti.push_back(CF_GENIVI_ANALOG); + + + am_sourceID_t tunerID; + enterSourceDB("Tuner", domainID1, cfStereo, tunerID); + + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMulti, gwSourceID1); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfMulti, cfMulti, matrix, gwSourceID1, gwSinkID1, gatewayID1); + + am_sinkID_t rseLeftID; + enterSinkDB("RSE Left", domainID2, cfMulti, rseLeftID); + am_sinkID_t rseRightID; + enterSinkDB("RSE Right", domainID2, cfMulti, rseRightID); + am_sinkID_t rseHeadphoneID; + enterSinkDB("Headphone", domainID2, cfMulti, rseHeadphoneID); + + am::am_Source_s source; + am::am_Sink_s sink; + pDatabaseHandler.getSinkInfoDB(rseLeftID, sink); + pDatabaseHandler.getSourceInfoDB(tunerID, source); + + std::vector listRoutes; + getRoute(false, source, sink, listRoutes); + ASSERT_EQ(listRoutes.size(), static_cast(1)); + + am_Route_s compareRoute1; + compareRoute1.sinkID = rseLeftID; + compareRoute1.sourceID = tunerID; + compareRoute1.route.push_back({tunerID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gwSourceID1, rseLeftID, domainID2, CF_GENIVI_STEREO}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + + listRoutes.clear(); + + am::am_Source_s gwSource; + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(rseHeadphoneID, sink2); + pDatabaseHandler.getSourceInfoDB(gwSourceID1, gwSource); + getRoute(false, gwSource, sink2, listRoutes); + ASSERT_GT(listRoutes.size(), static_cast(0)); + + am_Route_s compareRoute2; + compareRoute2.sinkID = rseHeadphoneID; + compareRoute2.sourceID = gwSourceID1; + compareRoute2.route.push_back({gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_STEREO}); + am_Route_s compareRoute3; + compareRoute3.sinkID = rseHeadphoneID; + compareRoute3.sourceID = gwSourceID1; + compareRoute3.route.push_back({gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_ANALOG}); + + ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); + ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])||pCF.compareRoute(compareRoute3,listRoutes[1])); +} + int main(int argc, char **argv) { try -- cgit v1.2.1 From 277a638bf1d27ba6c3da37ff82d2fd06e718e7ca Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Mon, 23 Jan 2017 15:18:21 +0100 Subject: * Max count of the returned routes and max allowed domain cycles Signed-off-by: Christian Linke --- AudioManagerCore/include/CAmGraph.h | 129 +++-- AudioManagerCore/include/CAmRouter.h | 172 ++++--- AudioManagerCore/src/CAmRouter.cpp | 518 +++++++++++++-------- .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 271 ++++++++--- .../test/AmRouterMapTest/CAmRouterMapTest.h | 10 +- 5 files changed, 723 insertions(+), 377 deletions(-) diff --git a/AudioManagerCore/include/CAmGraph.h b/AudioManagerCore/include/CAmGraph.h index ff4a09c..a27d512 100644 --- a/AudioManagerCore/include/CAmGraph.h +++ b/AudioManagerCore/include/CAmGraph.h @@ -89,6 +89,7 @@ namespace am * Setters and getters. */ NodeData & getData() { return mData; } + const NodeData & getData() const { return mData; } uint16_t getIndex() const { return mIndex; } void setIndex(uint16_t index) { mIndex = index; } }; @@ -120,13 +121,13 @@ namespace am typedef typename std::vector*> CAmListNodePtrs; typedef typename std::list> CAmListVertices; typedef typename std::list>::iterator CAmListVerticesItr; - typedef typename std::list>::const_iterator CAmListVerticesItrConst; - typedef typename std::list CAmNodesAdjList; - typedef typename std::list::iterator CAmNodesAdjListItr; - typedef typename std::list::const_iterator CAmNodesAdjListItrConst; - typedef typename std::list> CAmListNodes; - typedef typename std::list>::iterator CAmListNodesItr; - typedef typename std::list>::const_iterator CAmListNodesItrConst; + typedef typename std::list>::const_iterator CAmListVerticesItrConst; + typedef typename std::list CAmNodesAdjList; + typedef typename std::list::iterator CAmNodesAdjListItr; + typedef typename std::list::const_iterator CAmNodesAdjListItrConst; + typedef typename std::list> CAmListNodes; + typedef typename std::list>::iterator CAmListNodesItr; + typedef typename std::list>::const_iterator CAmListNodesItrConst; typedef typename std::vector*> CAmNodeReferenceList; typedef typename std::vector CAmVertexReferenceList; @@ -136,6 +137,24 @@ namespace am CAmVertexReferenceList mPointersAdjList; //!< CAmVertexReferenceList vector with pointers to vertices for direct access bool mIsCyclic; //!< bool the graph has cycles or not + struct IterateThroughAllNodesDelegate + { + CAmNode * source; + CAmNode * destination; + CAmNodeReferenceList visited; + std::function * )> shouldVisitNode; + std::function *)> willVisitNode; + std::function *)> didVisitNode; + std::function didFindPath; + }; + + struct VisitNodeDelegate + { + CAmNode * source; + CAmNode * destination; + std::function &)> visitedNode; + }; + /** * Updates the node indexes after adding or removing nodes. * @@ -162,7 +181,7 @@ namespace am typedef uint16_t vertex_t; typedef uint16_t weight_t; - void findShortestsPathsFromNode(const CAmNode & node, std::vector &minDistance, std::vector *> &previous) + void findShortestPathsFromNode(const CAmNode & node, std::vector &minDistance, std::vector *> &previous) { typename CAmListVertices::const_iterator nIter; CAmListVertices * neighbors; @@ -256,32 +275,40 @@ namespace am } /** - * Generates list with all possible paths to given destination node after findShortestsPathsFromNode has been called. - * Finding paths is observed through the callback. The caller is informed after a new path has been found. + * Iterate through the nodes and generate all paths to given node. * * @param dst end node. * @param visited vector with current path. - * @param cb callback which is mostly used for constructing. + * @param delegate enumeration delegate. */ - void goThroughAllPaths(const CAmNode & dst, std::vector*> & visited, std::function cb) + void findAllPaths(IterateThroughAllNodesDelegate & delegate) { - CAmListVertices * nodes = mPointersAdjList[visited.back()->getIndex()]; + CAmListVertices * nodes = mPointersAdjList[delegate.visited.back()->getIndex()]; CAmListVerticesItrConst vItr(nodes->begin()); + + CAmVertex * pNextVertex; + CAmNode * pNextNode; for (; vItr != nodes->end(); ++vItr) { - const CAmVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED) + pNextVertex = (CAmVertex *)&(*vItr); + pNextNode = pNextVertex->getNode(); + if( + pNextNode->getStatus()!=GES_NOT_VISITED || + !delegate.shouldVisitNode(pNextNode) + ) continue; - if (vertex.getNode()==&dst) + if (pNextNode==delegate.destination) { - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); + delegate.willVisitNode(pNextNode); + pNextNode->setStatus(GES_IN_PROGRESS); + delegate.visited.push_back(pNextNode); //notify observer - cb(visited); + delegate.didFindPath(delegate.visited); //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - vertex.getNode()->setStatus(GES_NOT_VISITED); + auto last = delegate.visited.end()-1; + delegate.visited.erase(last); + pNextNode->setStatus(GES_NOT_VISITED); + delegate.didVisitNode(pNextNode); break; } } @@ -289,20 +316,28 @@ namespace am //bfs like loop for (; vItr != nodes->end(); ++vItr) { - const CAmVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED||vertex.getNode()==&dst) + pNextVertex = (CAmVertex *)&(*vItr); + pNextNode = pNextVertex->getNode(); + + if(pNextNode->getStatus()!=GES_NOT_VISITED || + pNextNode==delegate.destination || + !delegate.shouldVisitNode(pNextNode) + ) continue; - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - goThroughAllPaths(dst, visited, cb); + delegate.willVisitNode(pNextNode); + pNextNode->setStatus(GES_IN_PROGRESS); + delegate.visited.push_back(pNextNode); + findAllPaths(delegate); //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - vertex.getNode()->setStatus(GES_NOT_VISITED); + auto last = delegate.visited.end()-1; + delegate.visited.erase(last); + pNextNode->setStatus(GES_NOT_VISITED); + delegate.didVisitNode(pNextNode); } } public: + explicit CAmGraph(const std::vector &v):mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList() { typedef typename std::vector::const_iterator inItr; @@ -524,7 +559,7 @@ namespace am std::vector min_distance; std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); + findShortestPathsFromNode(source, min_distance, previous); for(auto it=listTargets.begin(); it!=listTargets.end(); it++) { @@ -554,7 +589,7 @@ namespace am return; std::vector min_distance; std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); + findShortestPathsFromNode(source, min_distance, previous); constructShortestPathTo(destination, previous, resultPath); } @@ -576,7 +611,7 @@ namespace am std::vector min_distance; std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); + findShortestPathsFromNode(source, min_distance, previous); for(auto it=listTargets.begin(); it!=listTargets.end(); it++) { @@ -603,7 +638,7 @@ namespace am std::vector min_distance; std::vector*> previous; - findShortestsPathsFromNode(source, min_distance, previous); + findShortestPathsFromNode(source, min_distance, previous); constructShortestPathTo(destination, previous, cb); } @@ -613,15 +648,29 @@ namespace am * * @param src start node. * @param dst destination node. - * @param cb callabck. + * @param cbShouldVisitNode ask the delegate if we should proceed with the current node. + * @param cbWillVisitNode tell the delegate the current node will be visited. + * @param cbDidVisitNode tell the delegate the current node was visited. + * @param cbDidFindPath return the path to the delegate. */ - void getAllPaths(const CAmNode & src, const CAmNode & dst, std::function cb) + void getAllPaths(CAmNode & src, + CAmNode & dst, + std::function * )> cbShouldVisitNode, + std::function *)> cbWillVisitNode, + std::function *)> cbDidVisitNode, + std::function cbDidFindPath) { - CAmNodeReferenceList visited; - visited.push_back((CAmNode*)&src); + IterateThroughAllNodesDelegate delegate; + delegate.source = &src; + delegate.destination = &dst; + delegate.shouldVisitNode = cbShouldVisitNode; + delegate.willVisitNode = cbWillVisitNode; + delegate.didVisitNode = cbDidVisitNode; + delegate.didFindPath = cbDidFindPath; + delegate.visited.push_back((CAmNode*)&src); ((CAmNode*)&src)->setStatus(GES_VISITED); - goThroughAllPaths(dst, visited, cb); - reset(); + findAllPaths(delegate); + ((CAmNode*)&src)->setStatus(GES_NOT_VISITED); } }; diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h index 705fb4a..f4955d6 100644 --- a/AudioManagerCore/include/CAmRouter.h +++ b/AudioManagerCore/include/CAmRouter.h @@ -38,7 +38,7 @@ namespace am { /** - * Optimal path search between a source and a sink is implemented with a graph which contains nodes - sinks, sources, gateways, converters. + * Optimal path search is implemented with graph which contains nodes - sinks, sources, gateways, converters. * The nodes are identified by sinkID, sourceID, gatewayID, converterID. * A possible connection between two nodes represents the facts that the nodes can be connected with one or more connectionFormats (Node[id=1] ---> Node[id=2]). * It is assumption that the two nodes can be connected. The controller itself decides later whether the connection is possible or not. @@ -48,22 +48,25 @@ namespace am /** * Trace on/off. */ -#if !defined(ROUTING_BUILD_CONNECTIONS) - #undef TRACE_GRAPH -#endif +#undef TRACE_GRAPH /** - * Default behavior is to do the search in one step without connections, which are identified during the search. - * Alternatively the search can be done in two steps. + * Max paths count returned to the controller */ -#if !defined(ROUTING_BUILD_CONNECTIONS) - #undef ROUTING_BUILD_CONNECTIONS -#endif - -#if defined(TRACE_GRAPH) -#if !defined(ROUTING_BUILD_CONNECTIONS) -#warning "You should define ROUTING_BUILD_CONNECTIONS in order to be able to see the connections in the trace." +#ifndef MAX_ROUTING_PATHS +#define MAX_ROUTING_PATHS 5 #endif +/** + * How many times the routing algorithm should look back into domains. + * + * 0 - no cycles are allowed + * 1 - default is one cycle + * ... + * UINT_MAX - set this define to UINT_MAX in order to allow cycles. + * + */ +#ifndef MAX_ALLOWED_DOMAIN_CYCLES +#define MAX_ALLOWED_DOMAIN_CYCLES 1 #endif class CAmRouter; @@ -150,23 +153,17 @@ class CAmControlSender; */ class CAmRouter { - IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler - CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route - bool mOnlyFreeConversionNodes; //!< bool flag whether only disconnected elements should be considered or not - CAmRoutingGraph mRoutingGraph; //!< graph object - std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access - std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access - std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access + IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler + CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route + bool mOnlyFreeConversionNodes; //!< bool flag whether only disconnected elements should be considered or not + unsigned mMaxAllowedCycles; //!< max allowed cycles, default is 1 + unsigned mMaxPathCount; //!< max paths count returned to the controller, default is 5 + CAmRoutingGraph mRoutingGraph; //!< graph object + std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access + std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access + std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access std::map> mNodeListConverters;//!< map with pointers to nodes with converters, used for quick access - am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); - am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & route, - std::vector::iterator routingElementIterator, - std::vector::iterator routeIterator, - std::vector & result); - - /** * Check whether given converter or gateway has been connected. * @@ -176,86 +173,119 @@ class CAmRouter { return mpDatabaseHandler->isComponentConnected(comp); } - void generateAllPaths(const CAmRoutingNode & src, - const CAmRoutingNode & dst, - const bool includeCycles, - std::function & path)> cb); - void goThroughAllPaths(const CAmRoutingNode & dst, - std::vector & visited, - std::vector & visitedDomains, - std::function & path)> cb); - -#ifdef ROUTING_BUILD_CONNECTIONS + /** - * Connects all converters to its sink and sources if possible. + * Connect all converters to its sink and sources if possible. * */ void constructConverterConnections(); /** - * Connects all gateways to its sink and sources if possible. + * Connect all gateways to its sink and sources if possible. * */ void constructGatewayConnections(); /** - * Connects all sources to the sinks if possible. + * Connect all sources to the sinks if possible. * */ void constructSourceSinkConnections(); -#else + /** - * Construct a list with all vertices + * Construct list with all vertices */ void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list); /** - * Construct a list with all vertices from given source. + * Construct list with all vertices from given source. */ void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list); /** - * Construct a list with all vertices from given sink. + * Construct list with all vertices from given sink. */ void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list); /** - * Construct a list with all vertices from given converter. + * Construct list with all vertices from given converter. */ void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list); /** - * Construct a list with all vertices from given gateway. + * Construct list with all vertices from given gateway. */ void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list); -#endif + + /** + * Connection format permutations. + */ + am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); + am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, + std::vector & route, + std::vector::iterator routingElementIterator, + std::vector::iterator routeIterator, + std::vector & result); + am_Error_e cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath); + + /** + * Helper method. + */ + static int insertPostion(const std::vector& path, const std::vector >& nodes) ; + public: CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); ~CAmRouter(); + unsigned getMaxAllowedCycles() { return mMaxAllowedCycles; } + void setMaxAllowedCycles(unsigned count) { mMaxAllowedCycles = count; } + + unsigned getMaxPathCount() { return mMaxPathCount; } + void setMaxPathCount(unsigned count) { mMaxPathCount = count; } + /** - * Finds all possible paths between given source and sink. + * Find first mMaxPathCount paths between given source and sink. * * @param onlyfree only disconnected elements should be included or not. - * @param sourceID starting point. - * @param sinkID ending point. + * @param sourceID start point. + * @param sinkID end point. * @param returnList list with all possible paths * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. */ am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - am_Error_e getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); + am_Error_e getRoute(const bool onlyfree, const am_Source_s & source, const am_Sink_s & sink, std::vector & listRoutes); - am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, - std::vector & resultPath, std::vector> & resultNodesPath, -#if !defined(ROUTING_BUILD_CONNECTIONS) - __attribute__((unused)) -#endif - const bool includeCycles = false); -#ifdef ROUTING_BUILD_CONNECTIONS - void getShortestPath(const CAmRoutingNode & source, const CAmRoutingNode & destination, std::vector & resultPath); - void getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & resultPath, std::vector & resultNodesPath); -#endif + /** + * Find first mMaxPathCount paths between given source and sink after the nodes have been loaded. + * + * @param sourceID start point. + * @param sinkID end point. + * @param returnList list with all possible paths + * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + */ + am_Error_e getRouteFromLoadedNodes(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList); + am_Error_e getRouteFromLoadedNodes(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); + + /** + * Find first mMaxPathCount paths between given source and sink. This method should be called only after 'load' has been called. + * + * @param source start point. + * @param sink end point. + * @param returnList list with all possible paths. + * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + */ + am_Error_e getFirstNShortestPaths(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); + + /** + * Find the shortest path between given source and sink. This method should be called only after 'load' has been called. + * + * @param source start point. + * @param sink end point. + * @param returnList list with the connection format permutations of the shortest path. + * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + */ + am_Error_e getShortestPath(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); static bool getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, const std::vector & listSourceFormats, @@ -274,8 +304,8 @@ public: std::vector::iterator iteratorSink, std::vector & outConnectionFormats); - static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); - + static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber); + bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); /** * Returns a sink node with given sinkID. * @@ -313,6 +343,20 @@ public: void load(const bool onlyFree); void clear(); + + /** + * DEPRECATED! + */ +public: + am_Error_e getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector & resultPath, + std::vector> & resultNodesPath, + const bool includeCycles = false) + __attribute__((deprecated("You should use am_Error_e getFirstNShortestPaths(CAmRoutingNode &, CAmRoutingNode &, std::vector &) instead!"))); + + void getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & resultPath, std::vector & resultNodesPath) + __attribute__((deprecated("You should use am_Error_e getShortestPath(CAmRoutingNode &, CAmRoutingNode &, std::vector &) instead!"))); }; } /* namespace am */ #endif /* ROUTER_H_ */ diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index f59af24..7ee71ba 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -57,6 +57,8 @@ CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSe mpDatabaseHandler(iDatabaseHandler), // mpControlSender(iSender), mOnlyFreeConversionNodes(false), + mMaxAllowedCycles(MAX_ALLOWED_DOMAIN_CYCLES), + mMaxPathCount(MAX_ROUTING_PATHS), mRoutingGraph(), mNodeListSources(), mNodeListSinks(), @@ -81,52 +83,51 @@ CAmRouter::~CAmRouter() */ am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) { - returnList.clear(); - am_Source_s source; - am_Sink_s sink; - am_Error_e error = mpDatabaseHandler->getSourceInfoDB(sourceID, source); - if(error!=E_OK) - return error; - error = mpDatabaseHandler->getSinkInfoDB(sinkID, sink); - if(error!=E_OK) - return error; - error = getRoute(onlyfree, source, sink, returnList); - return error; + load(onlyfree); + return getRouteFromLoadedNodes(sourceID, sinkID, returnList); } am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) { - am_Error_e error; - load(onlyfree); + return getRoute(onlyfree, aSource.sourceID, aSink.sinkID, listRoutes); +} - CAmRoutingNode* pRootSource = sourceNodeWithID(aSource.sourceID); - CAmRoutingNode* pRootSink = sinkNodeWithID(aSink.sinkID); +am_Error_e CAmRouter::getRouteFromLoadedNodes(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) +{ + returnList.clear(); - assert(pRootSource); - assert(pRootSink); + CAmRoutingNode* pRootSource = sourceNodeWithID(sourceID); + CAmRoutingNode* pRootSink = sinkNodeWithID(sinkID); -#ifdef TRACE_GRAPH - mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { - std::cout << "Node " << node.getIndex() << ":"; - ((CAmRoutingNode &)node).getData().trace(); - std::cout << "-->["; - int count = 0; - std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ - am::CAmNode* data = refVertex->getNode(); - if(count>0) - std::cout << ", "; - std::cout << "Node " << data->getIndex() << ":"; - data->getData().trace(); - count++; - }); - std::cout << "]" << std::endl; - }); -#endif + if(!pRootSource || !pRootSink) + return E_NON_EXISTENT; - std::vector> pathNodes; - error = getAllPaths(*pRootSource, *pRootSink, listRoutes, pathNodes); - return error; + //try to find paths without cycles + const unsigned cycles = mMaxAllowedCycles; + mMaxAllowedCycles = 0; + + am_Error_e error = getFirstNShortestPaths(*pRootSource, *pRootSink, returnList); + + mMaxAllowedCycles = cycles; + + //if no paths have been found, we start a second search with cycles. + if( !returnList.size() && cycles>0 ) + { + error = getFirstNShortestPaths(*pRootSource, *pRootSink, returnList); + } + + /* For shortest path use the following call: + * + * error = getShortestPath(*pRootSource, *pRootSink, listRoutes); + */ + return error; +} + + +am_Error_e CAmRouter::getRouteFromLoadedNodes(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) +{ + return getRouteFromLoadedNodes(aSource.sourceID, aSink.sinkID, listRoutes); } void CAmRouter::load(const bool onlyFree) @@ -138,32 +139,53 @@ void CAmRouter::load(const bool onlyFree) nodeDataSrc.type = CAmNodeDataType::SOURCE; mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){ nodeDataSrc.data.source = (am_Source_s*)&obj; - mNodeListSources[nodeDataSrc.data.source->domainID].push_back(&mRoutingGraph.addNode(nodeDataSrc)); - }); + auto node = &mRoutingGraph.addNode(nodeDataSrc); + mNodeListSources[nodeDataSrc.data.source->domainID].push_back(node); + }); am_RoutingNodeData_s nodeDataSink; nodeDataSink.type = CAmNodeDataType::SINK; mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){ nodeDataSink.data.sink = (am_Sink_s*)&obj; - mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(&mRoutingGraph.addNode(nodeDataSink)); - }); + auto node = &mRoutingGraph.addNode(nodeDataSink); + mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(node); + }); am_RoutingNodeData_s nodeDataGateway; nodeDataGateway.type = CAmNodeDataType::GATEWAY; mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){ nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; - mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(&mRoutingGraph.addNode(nodeDataGateway)); + auto node = &mRoutingGraph.addNode(nodeDataGateway); + mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(node); }); am_RoutingNodeData_s nodeDataConverter; nodeDataConverter.type = CAmNodeDataType::CONVERTER; mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){ nodeDataConverter.data.converter = (am_Converter_s*)&obj; - mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(&mRoutingGraph.addNode(nodeDataConverter)); + auto node = &mRoutingGraph.addNode(nodeDataConverter); + mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(node); }); -#ifdef ROUTING_BUILD_CONNECTIONS constructConverterConnections(); constructGatewayConnections(); constructSourceSinkConnections(); + +#ifdef TRACE_GRAPH + mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { + std::cout << "Node " << node.getIndex() << ":"; + ((CAmRoutingNode &)node).getData().trace(); + std::cout << "-->["; + int count = 0; + std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ + am::CAmNode* data = refVertex->getNode(); + if(count>0) + std::cout << ", "; + std::cout << "Node " << data->getIndex() << ":"; + data->getData().trace(); + count++; + }); + std::cout << "]" << std::endl; + }); #endif + } void CAmRouter::clear() @@ -249,8 +271,6 @@ CAmRoutingNode* CAmRouter::gatewayNodeWithSinkID(const am_sinkID_t sinkID) return NULL; } -#ifdef ROUTING_BUILD_CONNECTIONS - void CAmRouter::constructSourceSinkConnections() { std::vector intersection; @@ -353,7 +373,6 @@ void CAmRouter::constructConverterConnections() } } } -#else void CAmRouter::getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list) { @@ -470,8 +489,6 @@ void CAmRouter::getVerticesForNode( } } -#endif - am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result) { std::vector::iterator routingElementIterator = routeObjects.route.begin(); @@ -570,31 +587,66 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, } } -#ifdef ROUTING_BUILD_CONNECTIONS - -void CAmRouter::getShortestPath(const CAmRoutingNode & source, - const CAmRoutingNode & destination, - std::vector & resultPath) +am_Error_e CAmRouter::cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath) { - mRoutingGraph.getShortestPath(source, destination, resultPath); + std::vector result; + am_Error_e err = determineConnectionFormatsForPath(shortestRoute, resultNodesPath, result); + if (err != E_UNKNOWN) + { + resultPath.insert(resultPath.end(), result.begin(), result.end()); +#ifdef TRACE_GRAPH + std::cout + << "Successfully determined connection formats for path from source:" + << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID + << "\n"; + for (auto routeConnectionFormats : result) + { + std::cout << "["; + for (auto it = routeConnectionFormats.route.begin();it != routeConnectionFormats.route.end(); it++) + { + am_RoutingElement_s& routingElement = *it; + if (it - routeConnectionFormats.route.begin() > 0) + std::cout << " -> "; + + std::cout << routingElement.sourceID << ":" + << routingElement.sinkID << " CF:" + << routingElement.connectionFormat << " D:" + << routingElement.domainID; + } + std::cout << "]\n"; + } +#endif + } +#ifdef TRACE_GRAPH + else + { + std::cout + << "Error by determining connection formats for path from source:" + << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID + << "\n"; + } +#endif + return err; } -void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, - am_Route_s & resultPath, std::vector & resultNodesPath) +am_Error_e CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath) { - am_RoutingElement_s * element; + am_Error_e err = E_OK; + am_Route_s shortestRoute; + std::vector resultNodesPath; am_RoutingNodeData_s & sinkNodeData = aSink.getData(); am_RoutingNodeData_s & sourceNodeData = aSource.getData(); - resultPath.sinkID = sinkNodeData.data.sink->sinkID; - resultPath.sourceID = sourceNodeData.data.source->sourceID; + shortestRoute.sinkID = sinkNodeData.data.sink->sinkID; + shortestRoute.sourceID = sourceNodeData.data.source->sourceID; - std::function cb = [&](const am_GraphPathPosition_e, CAmRoutingNode & object) - { + mRoutingGraph.getShortestPath(aSource, aSink, [&shortestRoute, &resultNodesPath](const am_GraphPathPosition_e position, CAmRoutingNode & object){ + am_RoutingElement_s * element; + //reverse order resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); am_RoutingNodeData_s & routingData = object.getData(); if(routingData.type==CAmNodeDataType::SINK) { - auto iter = resultPath.route.emplace(resultPath.route.begin()); + auto iter = shortestRoute.route.emplace(shortestRoute.route.begin()); element = &(*iter); element->domainID = routingData.data.sink->domainID; element->sinkID = routingData.data.sink->sinkID; @@ -606,87 +658,195 @@ void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink element->sourceID = routingData.data.source->sourceID; element->connectionFormat = CF_UNKNOWN; } - }; - mRoutingGraph.getShortestPath(aSource, aSink, cb); -} + }); -#endif + if(shortestRoute.route.size()) + { + err = cfPermutationsForPath(shortestRoute, resultNodesPath, resultPath); + } + return err; +} -am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles) -{ -#ifndef ROUTING_BUILD_CONNECTIONS - bool cycles = false; -#else - bool cycles = includeCycles; -#endif - if(((CAmRoutingNode*)&aSource)->getData().type!=CAmNodeDataType::SOURCE || - ((CAmRoutingNode*)&aSink)->getData().type!=CAmNodeDataType::SINK) - return E_NOT_POSSIBLE; +void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & path, std::vector & resultNodesPath) +{ + am_Route_s shortestRoute; + am_RoutingNodeData_s & sinkNodeData = aSink.getData(); + am_RoutingNodeData_s & sourceNodeData = aSource.getData(); + shortestRoute.sinkID = sinkNodeData.data.sink->sinkID; + shortestRoute.sourceID = sourceNodeData.data.source->sourceID; - uint8_t errorsCount = 0, successCount = 0; - generateAllPaths(aSource, aSink, cycles, [&](const std::vector & path) { - resultNodesPath.push_back(path); - am_Route_s nextRoute; - nextRoute.sinkID = aSink.getData().data.sink->sinkID; - nextRoute.sourceID = aSource.getData().data.source->sourceID; + mRoutingGraph.getShortestPath(aSource, aSink, [&shortestRoute, &resultNodesPath](const am_GraphPathPosition_e position, CAmRoutingNode & object){ am_RoutingElement_s * element; - for(auto it = path.begin(); it!=path.end(); it++) + //reverse order + resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); + am_RoutingNodeData_s & routingData = object.getData(); + if(routingData.type==CAmNodeDataType::SINK) { - am_RoutingNodeData_s & routingData = (*it)->getData(); - if(routingData.type==CAmNodeDataType::SOURCE) - { - auto iter = nextRoute.route.emplace(nextRoute.route.end()); - element = &(*iter); - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SINK) - { - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } + auto iter = shortestRoute.route.emplace(shortestRoute.route.begin()); + element = &(*iter); + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; } - std::vector result; - am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector &)path, result); - if(err==E_UNKNOWN) + else if(routingData.type==CAmNodeDataType::SOURCE) { - errorsCount++; -#ifdef TRACE_GRAPH - std::cout<<"Error by determining connection formats for path from source:"<domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + }); + + if(shortestRoute.route.size()) + { + std::vector resultPath; + cfPermutationsForPath(shortestRoute, resultNodesPath, resultPath); + if(resultPath.size()) + path = resultPath.front(); + } +} + +int CAmRouter::insertPostion(const std::vector& path, const std::vector >& nodes) +{ + int index = 0; + if (!nodes.empty()) { + auto itNodes = nodes.begin(); + for (; itNodes != nodes.end(); itNodes++) { + if (itNodes->size() > path.size()) + break; } + if (itNodes == nodes.end()) + index = nodes.size(); + else + index = itNodes - nodes.begin(); + } + return index; +} + +am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, + CAmRoutingNode & aSink, + std::vector & resultPath, + std::vector> & resultNodesPath, + const bool includeCycles) +{ + + if( aSource.getData().type!=CAmNodeDataType::SOURCE || aSink.getData().type!=CAmNodeDataType::SINK ) + return E_NOT_POSSIBLE; + + unsigned cycles; + if(includeCycles) + cycles = UINT_MAX; + else + cycles = 0; + + uint8_t errorsCount = 0, successCount = 0; + const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; + const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; + std::vector paths; + std::vector visitedDomains; + visitedDomains.push_back(((CAmRoutingNode*)&aSource)->getData().domainID()); + mRoutingGraph.getAllPaths(aSource, + aSink, + [&visitedDomains, &cycles](const CAmRoutingNode * node)->bool{ return CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles); }, + [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.push_back(node->getData().domainID()); }, + [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.erase(visitedDomains.end()-1); }, + [&resultPath, &resultNodesPath, &paths, &errorsCount, &successCount, &sinkID, &sourceID](const std::vector & path) { + int index = CAmRouter::insertPostion(path, resultNodesPath); + resultNodesPath.emplace(resultNodesPath.begin()+index); + paths.emplace(paths.begin()+index); + resultNodesPath[index] = path; + am_Route_s & nextRoute = paths[index]; + nextRoute.sinkID = sinkID; + nextRoute.sourceID = sourceID; + am_RoutingElement_s * element; + for(auto it = path.begin(); it!=path.end(); it++) + { + am_RoutingNodeData_s & routingData = (*it)->getData(); + if(routingData.type==CAmNodeDataType::SOURCE) + { + auto iter = nextRoute.route.emplace(nextRoute.route.end()); + element = &(*iter); + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SINK) + { + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + } + }); + + for(auto it = paths.begin(); successCount" - < & resultPath) +{ + if( aSource.getData().type!=CAmNodeDataType::SOURCE || aSink.getData().type!=CAmNodeDataType::SINK ) + return E_NOT_POSSIBLE; + const unsigned cycles = mMaxAllowedCycles; + uint8_t errorsCount = 0, successCount = 0; + const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; + const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; + std::vector paths; + std::vector> nodes; + std::vector visitedDomains; + visitedDomains.push_back(((CAmRoutingNode*)&aSource)->getData().domainID()); + mRoutingGraph.getAllPaths(aSource, + aSink, + [&visitedDomains, &cycles](const CAmRoutingNode * node)->bool{ return CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles); }, + [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.push_back(node->getData().domainID()); }, + [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.erase(visitedDomains.end()-1); }, + [&resultPath, &nodes, &paths, &errorsCount, &successCount, &sinkID, &sourceID](const std::vector & path) { + int index = CAmRouter::insertPostion(path, nodes); + nodes.emplace(nodes.begin()+index); + paths.emplace(paths.begin()+index); + nodes[index] = path; + am_Route_s & nextRoute = paths[index]; + nextRoute.sinkID = sinkID; + nextRoute.sourceID = sourceID; + am_RoutingElement_s * element; + for(auto it = path.begin(); it!=path.end(); it++) + { + am_RoutingNodeData_s & routingData = (*it)->getData(); + if(routingData.type==CAmNodeDataType::SOURCE) + { + auto iter = nextRoute.route.emplace(nextRoute.route.end()); + element = &(*iter); + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SINK) + { + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + } }); + + for(auto it = paths.begin(); successCount & visitedDomains, const am_domainID_t nodeDomainID) +bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber) { + unsigned recourseCounter(0); if(visitedDomains.size()) { if(visitedDomains.back()==nodeDomainID) return true; - - for(auto it=visitedDomains.begin();it!=visitedDomains.end()-1; it++) + unsigned count = 0; + am_domainID_t lastDomain = 0; + for(auto it=visitedDomains.begin(); it!=visitedDomains.end()-1; it++) { - if(nodeDomainID==*it) - return false; + if(lastDomain!=*it) + { + if(nodeDomainID==*it) + { + recourseCounter++; + if (recourseCounter>maxCyclesNumber) + return false; + } + lastDomain=*it; + } } } return true; } -void CAmRouter::generateAllPaths(const CAmRoutingNode & src, - const CAmRoutingNode & dst, - const bool includeCycles, - std::function & path)> cb) -{ - if(!includeCycles) - { - std::vector visited; - std::vector visitedDomains; - visited.push_back((CAmRoutingNode*)&src); - visitedDomains.push_back(((CAmRoutingNode*)&src)->getData().domainID()); - ((CAmRoutingNode*)&src)->setStatus(GES_VISITED); - goThroughAllPaths(dst, visited, visitedDomains, cb); - } - else - mRoutingGraph.getAllPaths(src, dst, cb); -} - -void CAmRouter::goThroughAllPaths(const CAmRoutingNode & dst, - std::vector & visited, - std::vector & visitedDomains, - std::function & path)> cb) +bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID) { -#ifndef ROUTING_BUILD_CONNECTIONS - CAmRoutingListVertices vertices; - getVerticesForNode(*visited.back(), vertices); - const CAmRoutingListVertices * nodes = &vertices; -#else - const CAmRoutingListVertices * nodes = mRoutingGraph.getVertexList()[visited.back()->getIndex()]; -#endif - CAmRoutingListVertices::const_iterator vItr(nodes->begin()); - for (; vItr != nodes->end(); ++vItr) - { - const CAmRoutingVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED || !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) - continue; - if (vertex.getNode()==&dst) - { - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - visitedDomains.push_back(vertex.getNode()->getData().domainID()); - //notify observer - cb(visited); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - visitedDomains.erase(visitedDomains.end()-1); - vertex.getNode()->setStatus(GES_NOT_VISITED); - break; - } - } - vItr = nodes->begin(); - //bfs like loop - for (; vItr != nodes->end(); ++vItr) - { - const CAmRoutingVertex & vertex = (*vItr); - if(vertex.getNode()->getStatus()!=GES_NOT_VISITED - ||vertex.getNode()==&dst || - !shouldGoInDomain(visitedDomains, vertex.getNode()->getData().domainID())) - continue; - vertex.getNode()->setStatus(GES_IN_PROGRESS); - visited.push_back(vertex.getNode()); - visitedDomains.push_back(vertex.getNode()->getData().domainID()); - goThroughAllPaths(dst, visited, visitedDomains, cb); - //remove last node from the list - auto last = visited.end()-1; - visited.erase(last); - visitedDomains.erase(visitedDomains.end()-1); - vertex.getNode()->setStatus(GES_NOT_VISITED); - } + return CAmRouter::shouldGoInDomain(visitedDomains, nodeDomainID, mMaxAllowedCycles); } bool CAmRouter::getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, @@ -872,4 +975,5 @@ am_Error_e CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector & listRoutes) +void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles, const unsigned pathsCount) { + pRouter.setMaxAllowedCycles(countCycles); + pRouter.setMaxPathCount(pathsCount); std::ios_base::fmtflags oldflags = std::cout.flags(); std::streamsize oldprecision = std::cout.precision(); auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, aSource, aSink, listRoutes)); + if(shouldReload) + pRouter.load(onlyfree); + ASSERT_EQ(E_OK, pRouter.getRouteFromLoadedNodes(aSource, aSink, listRoutes)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; @@ -181,12 +185,16 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const am_Source_s & aSource std::cout.precision (oldprecision); } -void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList) +void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles, const unsigned pathsCount) { + pRouter.setMaxAllowedCycles(countCycles); + pRouter.setMaxPathCount(pathsCount); std::ios_base::fmtflags oldflags = std::cout.flags(); std::streamsize oldprecision = std::cout.precision(); auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getRoute(onlyfree, sourceID, sinkID, returnList)); + if(shouldReload) + pRouter.load(onlyfree); + ASSERT_EQ(E_OK, pRouter.getRouteFromLoadedNodes(sourceID, sinkID, returnList)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << returnList.size() <<" routes from " << sourceID << " to " << sinkID; @@ -195,16 +203,14 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const am_sourceID_t sourceI std::cout.precision (oldprecision); } -void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles) +void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles, const unsigned pathsCount) { + pRouter.setMaxAllowedCycles(countCycles); + pRouter.setMaxPathCount(pathsCount); std::ios_base::fmtflags oldflags = std::cout.flags(); std::streamsize oldprecision = std::cout.precision(); auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getAllPaths(aSource, aSink, resultPath, resultNodesPath, includeCycles)); + ASSERT_EQ(E_OK, pRouter.getFirstNShortestPaths(aSource, aSink, resultPath)); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << resultPath.size() @@ -218,19 +224,19 @@ void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, TEST_F(CAmRouterMapTest,checkInsertedDomain) { std::vector domains; - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50, 0)); domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60, 0)); } //test that checks just sinks and source in a domain but connectionformats do not match @@ -304,7 +310,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); + getRoute(true, true, sourceDb, sinkDb, listRoutes); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -379,7 +385,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); + getRoute(true, true, sourceDb, sinkDb, listRoutes); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -498,7 +504,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(true,sourceID,sinkID,listRoutes); + getRoute(true, true,sourceID,sinkID,listRoutes); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -633,11 +639,11 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); + getRoute(true, true, sourceDb, sinkDb, listRoutes); ASSERT_EQ(static_cast(0), listRoutes.size()); listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -784,7 +790,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, sourceDb, sinkDb, listRoutes); + getRoute(true, true, sourceDb, sinkDb, listRoutes); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -957,7 +963,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1124,12 +1130,11 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } - //test that checks 3 domains, one sink one source, longer lists of connectionformats. TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) { @@ -1287,12 +1292,11 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } - //test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) { @@ -1534,7 +1538,7 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(2), listRoutes.size()); bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { @@ -1702,9 +1706,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); } + //test that checks just 2 domains, one sink one source with only one connection format each TEST_F(CAmRouterMapTest,simpleRoute2Domains) { @@ -1820,7 +1825,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1917,7 +1922,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -2076,7 +2081,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2275,7 +2280,7 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, sourceDb, sinkDb, listRoutes); + getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2400,7 +2405,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2485,7 +2490,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) compareRoute.sinkID = sinkID1; compareRoute.sourceID = sourceID; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2600,7 +2605,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) compareRoute1.sinkID = sinkID; compareRoute1.sourceID = sourceID; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(2), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); @@ -2665,7 +2670,7 @@ TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) pDatabaseHandler.getSourceInfoDB(sourceID, source); std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2741,7 +2746,7 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2822,7 +2827,7 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) std::vector listRoutes; - getRoute(false, source, sink1, listRoutes); + getRoute(false, true, source, sink1, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2834,7 +2839,7 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); listRoutes.clear(); - getRoute(false, source, sink2, listRoutes); + getRoute(false, true, source, sink2, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -2900,13 +2905,13 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); pDatabaseHandler.getSourceInfoDB(sourceID, source); - getRoute(false, source, sink1, listRoutes); + getRoute(false, true, source, sink1, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); - getRoute(false, source, sink2, listRoutes); + getRoute(false, true, source, sink2, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2993,12 +2998,12 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink1; pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); - getRoute(false, source, sink1, listRoutes); + getRoute(false, true, source, sink1, listRoutes, 0); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -3107,12 +3112,12 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes, 0); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); - pRouter.getRoute(false, source, sink2, listRoutes); + getRoute(false, true, source, sink2, listRoutes, 0); ASSERT_EQ(static_cast(2), listRoutes.size()); am_Route_s compareRoute1; @@ -3217,7 +3222,6 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) ASSERT_TRUE(sinkNode); std::vector listRoutes; - std::vector> resultNodesPath; am_Route_s compareRoute1; compareRoute1.sinkID = sink1ID; @@ -3231,8 +3235,7 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) ASSERT_TRUE(didMatch); \ } -#ifdef ROUTING_BUILD_CONNECTIONS - getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, true); + getAllPaths(*sourceNode, *sinkNode, listRoutes, UINT_MAX, 10); ASSERT_EQ(static_cast(9), listRoutes.size()); compareRoute1.route.clear(); @@ -3303,19 +3306,169 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); DO_ASSERT() -#else + + listRoutes.clear(); + + getAllPaths(*sourceNode, *sinkNode, listRoutes, 1, 10); + ASSERT_EQ(static_cast(5), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); + DO_ASSERT() + compareRoute1.route.clear(); compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); -#endif + DO_ASSERT() listRoutes.clear(); - resultNodesPath.clear(); - getAllPaths(*sourceNode, *sinkNode, listRoutes, resultNodesPath, false); + + getAllPaths(*sourceNode, *sinkNode, listRoutes); ASSERT_EQ(static_cast(1), listRoutes.size()); DO_ASSERT() } +TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles2) +{ + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + am_SourceClass_s sourceclass; + + sourceclass.name="sClass"; + sourceclass.sourceClassID=5; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + + am_SinkClass_s sinkclass; + sinkclass.sinkClassID=5; + sinkclass.name="sname"; + + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + + am_domainID_t domain1ID, domain2ID, domain3ID; + enterDomainDB("domain1", domain1ID); + enterDomainDB("domain2", domain2ID); + enterDomainDB("domain3", domain3ID); + + //just make so many cycles as possible + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfOther; + cfOther.push_back(CF_GENIVI_AUTO); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + + am_sourceID_t source1ID; + enterSourceDB("source1", domain1ID, cfMono, source1ID); + am_sinkID_t gw1SinkID; + enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); + am_sinkID_t gw2SinkID; + enterSinkDB("gw2Sink", domain1ID, cfMono, gw2SinkID); + am_sourceID_t gw3SourceID; + enterSourceDB("gw3Source", domain1ID, cfStereo, gw3SourceID); + am_sourceID_t gw4SourceID; + enterSourceDB("gw4Source", domain1ID, cfStereo, gw4SourceID); + am_sinkID_t gw5SinkID; + enterSinkDB("gw5Sink", domain1ID, cfStereo, gw5SinkID); + + am_sourceID_t gw1SourceID; + enterSourceDB("gw1Source", domain2ID, cfStereo, gw1SourceID); + am_sourceID_t gw2SourceID; + enterSourceDB("gw2Source", domain2ID, cfStereo, gw2SourceID); + am_sinkID_t gw3SinkID; + enterSinkDB("gw3Sink", domain2ID, cfStereo, gw3SinkID); + am_sinkID_t gw4SinkID; + enterSinkDB("gw4Sink", domain2ID, cfStereo, gw4SinkID); + + am_sourceID_t gw5SourceID; + enterSourceDB("gw5Source", domain3ID, cfOther, gw5SourceID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domain3ID, cfOther, sink1ID); + + std::vector matrixT; + matrixT.push_back(true); + std::vector matrixF; + matrixF.push_back(false); + + am_gatewayID_t gateway1ID; + enterGatewayDB("gateway1", domain2ID, domain1ID, cfStereo, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); + am_gatewayID_t gateway2ID; + enterGatewayDB("gateway2", domain2ID, domain1ID, cfStereo, cfMono, matrixT, gw2SourceID, gw2SinkID, gateway2ID); + am_gatewayID_t gateway3ID; + enterGatewayDB("gateway3", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw3SourceID, gw3SinkID, gateway3ID); + am_gatewayID_t gateway4ID; + enterGatewayDB("gateway4", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw4SourceID, gw4SinkID, gateway4ID); + am_gatewayID_t gateway5ID; + enterGatewayDB("gateway5", domain3ID, domain1ID, cfOther, cfStereo, matrixT, gw5SourceID, gw5SinkID, gateway5ID); + + pRouter.load(false); + + CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); + CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); + + ASSERT_TRUE(sourceNode); + ASSERT_TRUE(sinkNode); + + std::vector listRoutes; + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink1ID; + compareRoute1.sourceID = source1ID; + +#define DO_ASSERT() \ + {\ + bool didMatch = false; \ + for(auto it = listRoutes.begin(); it!=listRoutes.end(); it++) \ + didMatch|=pCF.compareRoute(compareRoute1,*it); \ + ASSERT_TRUE(didMatch); \ + } + + getRoute(false, false, source1ID, sink1ID, listRoutes, 0, 10); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + getRoute(false, false, source1ID, sink1ID, listRoutes, 1, 10); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO}); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO}); + compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); + compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO}); + DO_ASSERT() +} + TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) { EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); @@ -3403,7 +3556,7 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes); ASSERT_EQ(static_cast(4), listRoutes.size()); am_Route_s compareRoute1; @@ -3519,7 +3672,7 @@ TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) pDatabaseHandler.getSourceInfoDB(tunerID, source); std::vector listRoutes; - getRoute(false, source, sink, listRoutes); + getRoute(false, true, source, sink, listRoutes); ASSERT_EQ(listRoutes.size(), static_cast(1)); am_Route_s compareRoute1; @@ -3536,7 +3689,7 @@ TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(rseHeadphoneID, sink2); pDatabaseHandler.getSourceInfoDB(gwSourceID1, gwSource); - getRoute(false, gwSource, sink2, listRoutes); + getRoute(false, true, gwSource, sink2, listRoutes); ASSERT_GT(listRoutes.size(), static_cast(0)); am_Route_s compareRoute2; diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h index 65ff97b..2fc7a46 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -94,13 +94,9 @@ public: const am_sourceID_t & sourceID, const am_sinkID_t & sinkID, am_converterID_t & converterID); - void getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - void getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); - void getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles); + void getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); + void getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); + void getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); }; } -- cgit v1.2.1 From 1fec58235fa9c3c273e244b11ee6b3b77922b6bf Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Wed, 25 Jan 2017 16:02:20 +0100 Subject: * Max count of the returned routes tweaked up. Signed-off-by: Christian Linke --- AudioManagerCore/src/CAmRouter.cpp | 25 ++++--- .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 81 +++++++++++----------- .../test/AmRouterMapTest/CAmRouterMapTest.h | 6 +- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index 7ee71ba..1796fe6 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -596,7 +596,7 @@ am_Error_e CAmRouter::cfPermutationsForPath(am_Route_s shortestRoute, std::vecto resultPath.insert(resultPath.end(), result.begin(), result.end()); #ifdef TRACE_GRAPH std::cout - << "Successfully determined connection formats for path from source:" + << "Determined connection formats for path from source:" << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID << "\n"; for (auto routeConnectionFormats : result) @@ -798,7 +798,6 @@ am_Error_e CAmRouter::getFirstNShortestPaths(CAmRoutingNode & aSource, CAmRoutin if( aSource.getData().type!=CAmNodeDataType::SOURCE || aSink.getData().type!=CAmNodeDataType::SINK ) return E_NOT_POSSIBLE; const unsigned cycles = mMaxAllowedCycles; - uint8_t errorsCount = 0, successCount = 0; const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; std::vector paths; @@ -810,7 +809,7 @@ am_Error_e CAmRouter::getFirstNShortestPaths(CAmRoutingNode & aSource, CAmRoutin [&visitedDomains, &cycles](const CAmRoutingNode * node)->bool{ return CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles); }, [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.push_back(node->getData().domainID()); }, [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.erase(visitedDomains.end()-1); }, - [&resultPath, &nodes, &paths, &errorsCount, &successCount, &sinkID, &sourceID](const std::vector & path) { + [&resultPath, &nodes, &paths, &sinkID, &sourceID](const std::vector & path) { int index = CAmRouter::insertPostion(path, nodes); nodes.emplace(nodes.begin()+index); paths.emplace(paths.begin()+index); @@ -838,20 +837,20 @@ am_Error_e CAmRouter::getFirstNShortestPaths(CAmRoutingNode & aSource, CAmRoutin } } }); - - for(auto it = paths.begin(); successCount0); + } } - - if(successCount) + if(pathsFound) return E_OK; - if(errorsCount) + else return E_NOT_POSSIBLE; - return E_OK; } bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber) diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp index ad886f4..d656373 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -167,7 +167,7 @@ void CAmRouterMapTest::enterConverterDB(const std::string & gwName, ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter,converterID)); } -void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles, const unsigned pathsCount) { pRouter.setMaxAllowedCycles(countCycles); pRouter.setMaxPathCount(pathsCount); @@ -176,16 +176,17 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, co auto t_start = std::chrono::high_resolution_clock::now(); if(shouldReload) pRouter.load(onlyfree); - ASSERT_EQ(E_OK, pRouter.getRouteFromLoadedNodes(aSource, aSink, listRoutes)); + am_Error_e error = pRouter.getRouteFromLoadedNodes(aSource, aSink, listRoutes); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; std::cout.flags (oldflags); std::cout.precision (oldprecision); + return error; } -void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles, const unsigned pathsCount) { pRouter.setMaxAllowedCycles(countCycles); pRouter.setMaxPathCount(pathsCount); @@ -194,23 +195,24 @@ void CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, co auto t_start = std::chrono::high_resolution_clock::now(); if(shouldReload) pRouter.load(onlyfree); - ASSERT_EQ(E_OK, pRouter.getRouteFromLoadedNodes(sourceID, sinkID, returnList)); + am_Error_e error = pRouter.getRouteFromLoadedNodes(sourceID, sinkID, returnList); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << returnList.size() <<" routes from " << sourceID << " to " << sinkID; std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; std::cout.flags (oldflags); std::cout.precision (oldprecision); + return error; } -void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles, const unsigned pathsCount) { pRouter.setMaxAllowedCycles(countCycles); pRouter.setMaxPathCount(pathsCount); std::ios_base::fmtflags oldflags = std::cout.flags(); std::streamsize oldprecision = std::cout.precision(); auto t_start = std::chrono::high_resolution_clock::now(); - ASSERT_EQ(E_OK, pRouter.getFirstNShortestPaths(aSource, aSink, resultPath)); + am_Error_e error = pRouter.getFirstNShortestPaths(aSource, aSink, resultPath); auto t_end = std::chrono::high_resolution_clock::now(); std::cout << std::fixed << std::setprecision(2); std::cout << resultPath.size() @@ -219,6 +221,7 @@ void CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aS std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; std::cout.flags (oldflags); std::cout.precision (oldprecision); + return error; } TEST_F(CAmRouterMapTest,checkInsertedDomain) @@ -310,7 +313,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -385,7 +388,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -504,7 +507,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(true, true,sourceID,sinkID,listRoutes); + ASSERT_EQ(getRoute(true, true,sourceID,sinkID,listRoutes), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -639,11 +642,11 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); listRoutes.clear(); - getRoute(false, true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -790,7 +793,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(true, true, sourceDb, sinkDb, listRoutes); + ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -963,7 +966,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1130,7 +1133,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1292,7 +1295,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1538,7 +1541,7 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(2), listRoutes.size()); bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { @@ -1706,7 +1709,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -1825,7 +1828,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -1922,7 +1925,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) am::am_Sink_s sinkDb; pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -2081,7 +2084,7 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2280,7 +2283,7 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); listRoutes.clear(); - getRoute(false, true, sourceDb, sinkDb, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2405,7 +2408,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2490,7 +2493,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) compareRoute.sinkID = sinkID1; compareRoute.sourceID = sourceID; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); } @@ -2605,7 +2608,7 @@ TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) compareRoute1.sinkID = sinkID; compareRoute1.sourceID = sourceID; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(2), listRoutes.size()); ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); @@ -2670,7 +2673,7 @@ TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) pDatabaseHandler.getSourceInfoDB(sourceID, source); std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2746,7 +2749,7 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2827,7 +2830,7 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) std::vector listRoutes; - getRoute(false, true, source, sink1, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2839,7 +2842,7 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); listRoutes.clear(); - getRoute(false, true, source, sink2, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -2905,13 +2908,13 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); pDatabaseHandler.getSourceInfoDB(sourceID, source); - getRoute(false, true, source, sink1, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); - getRoute(false, true, source, sink2, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -2998,12 +3001,12 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink1; pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); - getRoute(false, true, source, sink1, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); am_Route_s compareRoute1; @@ -3112,12 +3115,12 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); - getRoute(false, true, source, sink2, listRoutes, 0); + ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_OK); ASSERT_EQ(static_cast(2), listRoutes.size()); am_Route_s compareRoute1; @@ -3448,10 +3451,10 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles2) ASSERT_TRUE(didMatch); \ } - getRoute(false, false, source1ID, sink1ID, listRoutes, 0, 10); + ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 0, 10), E_NOT_POSSIBLE); ASSERT_EQ(static_cast(0), listRoutes.size()); - getRoute(false, false, source1ID, sink1ID, listRoutes, 1, 10); + ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 1, 10), E_OK); ASSERT_EQ(static_cast(2), listRoutes.size()); compareRoute1.route.clear(); @@ -3556,7 +3559,7 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes), E_OK); ASSERT_EQ(static_cast(4), listRoutes.size()); am_Route_s compareRoute1; @@ -3672,7 +3675,7 @@ TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) pDatabaseHandler.getSourceInfoDB(tunerID, source); std::vector listRoutes; - getRoute(false, true, source, sink, listRoutes); + ASSERT_EQ(getRoute(false, true, source, sink, listRoutes), E_OK); ASSERT_EQ(listRoutes.size(), static_cast(1)); am_Route_s compareRoute1; @@ -3689,7 +3692,7 @@ TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(rseHeadphoneID, sink2); pDatabaseHandler.getSourceInfoDB(gwSourceID1, gwSource); - getRoute(false, true, gwSource, sink2, listRoutes); + ASSERT_EQ(getRoute(false, true, gwSource, sink2, listRoutes), E_OK); ASSERT_GT(listRoutes.size(), static_cast(0)); am_Route_s compareRoute2; diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h index 2fc7a46..a3cead1 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -94,9 +94,9 @@ public: const am_sourceID_t & sourceID, const am_sinkID_t & sinkID, am_converterID_t & converterID); - void getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); - void getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); - void getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); + am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); + am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); + am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); }; } -- cgit v1.2.1 From f7ef940971df9f938bed059824e5bf1d7eab8d65 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Thu, 26 Jan 2017 10:09:13 +0100 Subject: * CAmRouterTest adoptions. Signed-off-by: Christian Linke --- AudioManagerCore/include/CAmRouter.h | 11 +++++++---- AudioManagerCore/src/CAmRouter.cpp | 16 ++++++---------- AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp | 8 ++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h index f4955d6..1242824 100644 --- a/AudioManagerCore/include/CAmRouter.h +++ b/AudioManagerCore/include/CAmRouter.h @@ -219,6 +219,8 @@ class CAmRouter /** * Connection format permutations. + * + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. */ am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, @@ -251,7 +253,7 @@ public: * @param sourceID start point. * @param sinkID end point. * @param returnList list with all possible paths - * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. */ am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); am_Error_e getRoute(const bool onlyfree, const am_Source_s & source, const am_Sink_s & sink, std::vector & listRoutes); @@ -262,7 +264,7 @@ public: * @param sourceID start point. * @param sinkID end point. * @param returnList list with all possible paths - * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. */ am_Error_e getRouteFromLoadedNodes(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList); am_Error_e getRouteFromLoadedNodes(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); @@ -273,17 +275,18 @@ public: * @param source start point. * @param sink end point. * @param returnList list with all possible paths. - * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. */ am_Error_e getFirstNShortestPaths(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); /** * Find the shortest path between given source and sink. This method should be called only after 'load' has been called. + * This method do not pay attention on the parameter mMaxAllowedCycles and go through all possible paths. * * @param source start point. * @param sink end point. * @param returnList list with the connection format permutations of the shortest path. - * @return E_OK on success(0 or more paths) or E_NOT_POSSIBLE on failure. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. */ am_Error_e getShortestPath(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index 1796fe6..002bd9d 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -558,23 +558,19 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, listMergeConnectionFormats, listPriorityConnectionFormats))!= E_OK) return (returnError); + if (listPriorityConnectionFormats.empty()) + return (E_NOT_POSSIBLE); //we have the list sorted after priors - now we try one after the other with the next part of the route std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); //here we need to check if we are at the end and stop std::vector::iterator nextIterator = currentRoutingElementIterator + 1;//next pair source and sink if (nextIterator == routeObjects.route.end()) { - if (!listPriorityConnectionFormats.empty()) + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) { - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) - { - currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; - result.push_back(routeObjects); - } - return (E_OK); + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + result.push_back(routeObjects); } - else - return (E_NOT_POSSIBLE); } else { @@ -583,8 +579,8 @@ am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator, result); } - return (E_OK); } + return (E_OK); } am_Error_e CAmRouter::cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath) diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp index e1acd65..b4ab247 100644 --- a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp @@ -143,7 +143,7 @@ TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(E_NOT_POSSIBLE, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); ASSERT_EQ(static_cast(0), listRoutes.size()); } @@ -435,7 +435,7 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFreeNotFree) ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); - ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(E_NOT_POSSIBLE, pRouter.getRoute(true,sourceID,sinkID,listRoutes)); ASSERT_EQ(static_cast(0), listRoutes.size()); ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); @@ -1416,7 +1416,7 @@ TEST_F(CAmRouterTest,simpleRoute3DomainsNoConnection) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(E_NOT_POSSIBLE, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); ASSERT_EQ(static_cast(0), listRoutes.size()); } //test that checks just 2 domains, one sink one source with only one connection format each @@ -1629,7 +1629,7 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsNoMatchConnectionFormats) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(E_NOT_POSSIBLE, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); ASSERT_EQ(static_cast(0), listRoutes.size()); } -- cgit v1.2.1 From 728b43a9289716e62871e21d58c33595e091eef8 Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Wed, 8 Feb 2017 08:33:53 -0800 Subject: update license graphs Signed-off-by: Christian Linke --- docx/images/dependencies.png | Bin 38376 -> 35437 bytes docx/images/dependencies_test.png | Bin 59908 -> 59372 bytes docx/images/dependency_created.png | Bin 119569 -> 34858 bytes 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 docx/images/dependencies.png mode change 100644 => 100755 docx/images/dependencies_test.png mode change 100644 => 100755 docx/images/dependency_created.png diff --git a/docx/images/dependencies.png b/docx/images/dependencies.png old mode 100644 new mode 100755 index 30d272f..6755869 Binary files a/docx/images/dependencies.png and b/docx/images/dependencies.png differ diff --git a/docx/images/dependencies_test.png b/docx/images/dependencies_test.png old mode 100644 new mode 100755 index 870bc26..c6ba903 Binary files a/docx/images/dependencies_test.png and b/docx/images/dependencies_test.png differ diff --git a/docx/images/dependency_created.png b/docx/images/dependency_created.png old mode 100644 new mode 100755 index 7eabbf8..8a17fd2 Binary files a/docx/images/dependency_created.png and b/docx/images/dependency_created.png differ -- cgit v1.2.1 From b616ca1e864f7530b9dfce4c38f9d24a9f0809c9 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Fri, 10 Feb 2017 11:12:42 +0100 Subject: * many database observers can be registred now by the database handler. Signed-off-by: Christian Linke --- AudioManagerCore/CMakeLists.txt | 1 - AudioManagerCore/include/CAmCommandSender.h | 13 +- AudioManagerCore/include/CAmDatabaseHandlerMap.h | 168 ++++++---- AudioManagerCore/include/CAmDatabaseObserver.h | 87 ----- AudioManagerCore/include/CAmRouter.h | 6 +- AudioManagerCore/include/CAmRoutingSender.h | 5 +- AudioManagerCore/include/IAmDatabaseHandler.h | 34 +- AudioManagerCore/src/CAmCommandSender.cpp | 94 +++++- AudioManagerCore/src/CAmDatabaseHandlerMap.cpp | 325 +++++++++++-------- AudioManagerCore/src/CAmDatabaseObserver.cpp | 241 -------------- AudioManagerCore/src/CAmRouter.cpp | 1 + AudioManagerCore/src/CAmRoutingSender.cpp | 253 ++++++++------- .../CAmControlInterfaceTest.cpp | 6 +- .../CAmControlInterfaceTest.h | 3 - .../test/AmMapHandlerTest/CAmMapHandlerTest.cpp | 352 ++++++++++++++------- .../test/AmMapHandlerTest/CAmMapHandlerTest.h | 20 +- .../AmMapHandlerTest/CAmTestDatabaseObserver.cpp | 129 ++++---- .../AmMapHandlerTest/CAmTestDatabaseObserver.h | 53 ++++ .../test/AmMapHandlerTest/MockDatabaseObserver.h | 2 +- .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 8 +- .../test/AmRouterMapTest/CAmRouterMapTest.h | 2 - .../test/AmRouterTest/CAmRouterTest.cpp | 8 +- AudioManagerCore/test/AmRouterTest/CAmRouterTest.h | 2 - .../CAmRoutingInterfaceTest.cpp | 6 +- .../CAmRoutingInterfaceTest.h | 2 - AudioManagerCore/test/CMakeLists.txt | 2 +- AudioManagerDaemon/src/main.cpp | 12 +- 27 files changed, 953 insertions(+), 882 deletions(-) delete mode 100644 AudioManagerCore/include/CAmDatabaseObserver.h delete mode 100644 AudioManagerCore/src/CAmDatabaseObserver.cpp create mode 100644 AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.h diff --git a/AudioManagerCore/CMakeLists.txt b/AudioManagerCore/CMakeLists.txt index 464a934..7be36e9 100644 --- a/AudioManagerCore/CMakeLists.txt +++ b/AudioManagerCore/CMakeLists.txt @@ -46,7 +46,6 @@ set(AUDIOMAN_CORE_SRCS_CXX src/CAmCommandSender.cpp src/CAmControlReceiver.cpp src/CAmControlSender.cpp - src/CAmDatabaseObserver.cpp src/CAmRoutingReceiver.cpp src/CAmRoutingSender.cpp src/CAmRouter.cpp diff --git a/AudioManagerCore/include/CAmCommandSender.h b/AudioManagerCore/include/CAmCommandSender.h index 82363de..caa72ad 100644 --- a/AudioManagerCore/include/CAmCommandSender.h +++ b/AudioManagerCore/include/CAmCommandSender.h @@ -29,21 +29,24 @@ #endif #include "IAmCommand.h" +#include "CAmDatabaseHandlerMap.h" +#include "CAmSerializer.h" namespace am { class CAmCommandReceiver; +class CAmCommandSender; /** * This class is used to send data to the CommandInterface. * All loaded plugins will be called when a callback is invoked. */ -class CAmCommandSender +class CAmCommandSender: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks { public: - CAmCommandSender(const std::vector& listOfPluginDirectories); + CAmCommandSender(const std::vector& listOfPluginDirectories, CAmSocketHandler *iSocketHandler); ~CAmCommandSender(); am_Error_e startupInterfaces(CAmCommandReceiver* iCommandReceiver); void setCommandReady(); @@ -78,14 +81,18 @@ public: friend class IAmCommandBackdoor; //this is to get access to the loaded plugins and be able to exchange the interfaces #endif private: + void unloadLibraries(void); //!< unload the shared libraries std::vector mListInterfaces; //!< list of all interfaces std::vector mListLibraryHandles; //!< list of all library handles. This information is used to unload the plugins correctly. std::vector mListLibraryNames; //!< list of all library names. This information is used for getListPlugins. - + CAmCommandReceiver *mCommandReceiver; + CAmSerializer mSerializer; }; + + } #endif /* COMMANDSENDER_H_ */ diff --git a/AudioManagerCore/include/CAmDatabaseHandlerMap.h b/AudioManagerCore/include/CAmDatabaseHandlerMap.h index 05443b1..3909b05 100644 --- a/AudioManagerCore/include/CAmDatabaseHandlerMap.h +++ b/AudioManagerCore/include/CAmDatabaseHandlerMap.h @@ -74,6 +74,51 @@ class CAmDatabaseHandlerMap : public IAmDatabaseHandler public: CAmDatabaseHandlerMap(); virtual ~CAmDatabaseHandlerMap(); + + /** + * Database observer. + */ + struct AmDatabaseObserverCallbacks: public IAmDatabaseObserver + { + protected: + std::function dboNumberOfSinkClassesChanged; + std::function dboNumberOfSourceClassesChanged; + std::function dboNewSink; + std::function dboNewSource; + std::function dboNewDomain; + std::function dboNewGateway; + std::function dboNewConverter; + std::function dboNewCrossfader; + std::function dboNewMainConnection; + std::function dboRemovedMainConnection; + std::function dboRemovedSink; + std::function dboRemovedSource; + std::function dboRemoveDomain; + std::function dboRemoveGateway; + std::function dboRemoveConverter; + std::function dboRemoveCrossfader; + std::function dboMainConnectionStateChanged; + std::function dboMainSinkSoundPropertyChanged; + std::function dboMainSourceSoundPropertyChanged; + std::function dboSinkAvailabilityChanged; + std::function dboSourceAvailabilityChanged; + std::function dboVolumeChanged; + std::function dboSinkMuteStateChanged; + std::functiondboSystemPropertyChanged; + std::functiondboTimingInformationChanged; + std::function& , const bool )>dboSinkUpdated; + std::function& , const bool )>dboSourceUpdated; + std::function dboSinkMainNotificationConfigurationChanged; + std::function dboSourceMainNotificationConfigurationChanged; + public: + friend class CAmDatabaseHandlerMap; + AmDatabaseObserverCallbacks():IAmDatabaseObserver(), mpDatabaseHandler(nullptr) {} + virtual ~AmDatabaseObserverCallbacks(){ if(mpDatabaseHandler) mpDatabaseHandler->unregisterObserver(this);} + protected: + CAmDatabaseHandlerMap *mpDatabaseHandler; + + }; + am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID); am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID); am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID); @@ -196,7 +241,6 @@ public: bool existConverter(const am_converterID_t converterID) const; bool existSinkClass(const am_sinkClass_t sinkClassID) const; bool existSourceClass(const am_sourceClass_t sourceClassID) const; - void registerObserver(CAmDatabaseObserver *iObserver); bool sourceVisible(const am_sourceID_t sourceID) const; bool sinkVisible(const am_sinkID_t sinkID) const; bool isComponentConnected(const am_Gateway_s & gateway) const; @@ -206,6 +250,11 @@ public: am_Error_e enumerateSinks(std::function cb) const; am_Error_e enumerateGateways(std::function cb) const; am_Error_e enumerateConverters(std::function cb) const; + + bool registerObserver(IAmDatabaseObserver * iObserver); + bool unregisterObserver(IAmDatabaseObserver * iObserver); + unsigned countObservers(); + /** * The following structures extend the base structures with the field 'reserved'. */ @@ -276,55 +325,55 @@ public: AM_SUBCLASS_COPY_OP_END()\ AM_SUBCLASS_OP(Subclass, Class)\ - +private: AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Domain_Database_s,am_Domain_s) - AM_SUBCLASS_END(CAmDomain) + AM_SUBCLASS_END(AmDomain) AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Sink_Database_s,am_Sink_s) void getSinkType(am_SinkType_s & sinkType) const;\ - AM_SUBCLASS_END(CAmSink) + AM_SUBCLASS_END(AmSink) AM_TYPEDEF_SUBCLASS_SOUND_PROPERTIES_BEGIN(am_Source_Database_s,am_Source_s) void getSourceType(am_SourceType_s & sourceType) const;\ - AM_SUBCLASS_END(CAmSource) + AM_SUBCLASS_END(AmSource) AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Connection_Database_s,am_Connection_s) - AM_SUBCLASS_END(CAmConnection) + AM_SUBCLASS_END(AmConnection) /** * The following structures extend the base structures with print capabilities. */ AM_TYPEDEF_SUBCLASS_BEGIN(am_MainConnection_Database_s, am_MainConnection_s) void getMainConnectionType(am_MainConnectionType_s & connectionType) const;\ - AM_SUBCLASS_END(CAmMainConnection) + AM_SUBCLASS_END(AmMainConnection) AM_TYPEDEF_SUBCLASS_BEGIN(am_SourceClass_Database_s, am_SourceClass_s) - AM_SUBCLASS_END(CAmSourceClass) + AM_SUBCLASS_END(AmSourceClass) AM_TYPEDEF_SUBCLASS_BEGIN(am_SinkClass_Database_s, am_SinkClass_s) - AM_SUBCLASS_END(CAmSinkClass) + AM_SUBCLASS_END(AmSinkClass) AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s) - AM_SUBCLASS_END(CAmGateway) + AM_SUBCLASS_END(AmGateway) AM_TYPEDEF_SUBCLASS_BEGIN(am_Converter_Database_s, am_Converter_s) - AM_SUBCLASS_END(CAmConverter) + AM_SUBCLASS_END(AmConverter) AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s) - AM_SUBCLASS_END(CAmCrossfader) - - private: - typedef std::unordered_map CAmMapDomain; - typedef std::unordered_map CAmMapSourceClass; - typedef std::unordered_map CAmMapSinkClass; - typedef std::unordered_map CAmMapSink; - typedef std::unordered_map CAmMapSource; - typedef std::unordered_map CAmMapGateway; - typedef std::unordered_map CAmMapConverter; - typedef std::unordered_map CAmMapCrossfader; - typedef std::unordered_map CAmMapConnection; - typedef std::unordered_map CAmMapMainConnection; - typedef std::vector CAmVectorSystemProperties; + AM_SUBCLASS_END(AmCrossfader) + + + typedef std::unordered_map AmMapDomain; + typedef std::unordered_map AmMapSourceClass; + typedef std::unordered_map AmMapSinkClass; + typedef std::unordered_map AmMapSink; + typedef std::unordered_map AmMapSource; + typedef std::unordered_map AmMapGateway; + typedef std::unordered_map AmMapConverter; + typedef std::unordered_map AmMapCrossfader; + typedef std::unordered_map AmMapConnection; + typedef std::unordered_map AmMapMainConnection; + typedef std::vector AmVectorSystemProperties; /** * The following structure groups the map objects needed for the implementation. * Every map object is coupled with an identifier, which hold the current value. @@ -332,46 +381,46 @@ public: * The IDs can be increased through the method increaseID(...), which follows the AudioManager logic. * For more information about the static and dynamic IDs, please see the documentation. */ - typedef struct CAmMappedData + struct AmMappedData { /** * The structure encapsulates the id boundary and the current id value. * It defines a range within the id can vary. */ - struct am_Identifier_s + struct AmIdentifier { int16_t mMin; //!< min possible value int16_t mMax; //!< max possible value int16_t mCurrentValue; //!< current value - am_Identifier_s():mMin(DYNAMIC_ID_BOUNDARY), mMax(SHRT_MAX), mCurrentValue(mMin){}; - am_Identifier_s(const int16_t & min, const int16_t & max):mMin(min), mMax(max), mCurrentValue(mMin){assert(min::const_iterator iter = t.begin(); for(; iter!=t.end(); iter++) - CAmMappedData::print(iter->second, output); + AmMappedData::print(iter->second, output); } private: - template bool getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, + template bool getNextConnectionID(int16_t & resultID, AmIdentifier & sourceID, const std::unordered_map & map); - } CAmMappedData; + }; + /* * Helper methods. */ @@ -469,9 +519,9 @@ public: } ); } - CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer ListConnectionFormat mListConnectionFormat; //!< list of connection formats - CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class + AmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class + std::vector mDatabaseObservers; #ifdef UNIT_TEST public: diff --git a/AudioManagerCore/include/CAmDatabaseObserver.h b/AudioManagerCore/include/CAmDatabaseObserver.h deleted file mode 100644 index 7d18be4..0000000 --- a/AudioManagerCore/include/CAmDatabaseObserver.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseObserver.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef DATABASEOBSERVER_H_ -#define DATABASEOBSERVER_H_ - -#include "audiomanagertypes.h" -#include -#include "CAmSerializer.h" - -namespace am -{ - -class CAmTelnetServer; -class CAmCommandSender; -class CAmRoutingSender; -class CAmSocketHandler; - -/** - * This class observes the Database and notifies other classes about important events, mainly the CommandSender. - */ -class CAmDatabaseObserver -{ -public: - CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler); - CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler, CAmTelnetServer *iTelnetServer); - ~CAmDatabaseObserver(); - void numberOfSinkClassesChanged(); - void numberOfSourceClassesChanged(); - void newSink(const am_Sink_s& sink); - void newSource(const am_Source_s& source); - void newDomain(const am_Domain_s& domain); - void newGateway(const am_Gateway_s& gateway); - void newConverter(const am_Converter_s& coverter); - void newCrossfader(const am_Crossfader_s& crossfader); - void newMainConnection(const am_MainConnectionType_s& mainConnection); - void removedMainConnection(const am_mainConnectionID_t mainConnection); - void removedSink(const am_sinkID_t sinkID, const bool visible); - void removedSource(const am_sourceID_t sourceID, const bool visible); - void removeDomain(const am_domainID_t domainID); - void removeGateway(const am_gatewayID_t gatewayID); - void removeConverter(const am_converterID_t converterID); - void removeCrossfader(const am_crossfaderID_t crossfaderID); - void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState); - void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty); - void mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty); - void sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability); - void sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability); - void volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume); - void sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState); - void systemPropertyChanged(const am_SystemProperty_s& SystemProperty); - void timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time); - void sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible); - void sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible); - void sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration); - void sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration); - -private: - CAmCommandSender *mCommandSender; //!< pointer to the comandSender - CAmRoutingSender* mRoutingSender; //!< pointer to the routingSender - CAmTelnetServer* mTelnetServer; //!< pointer to the telnetserver - CAmSerializer mSerializer; //!< serializer to handle the CommandInterface via the mainloop -}; - -} - -#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h index 1242824..7543abc 100644 --- a/AudioManagerCore/include/CAmRouter.h +++ b/AudioManagerCore/include/CAmRouter.h @@ -31,7 +31,7 @@ #include #include "audiomanagertypes.h" #include "CAmGraph.h" -#include "IAmDatabaseHandler.h" +#include "CAmDatabaseHandlerMap.h" namespace am @@ -151,7 +151,7 @@ class CAmControlSender; /** * Implements an autorouting algorithm for connecting sinks and sources via different audio domains. */ -class CAmRouter +class CAmRouter: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks { IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route @@ -281,7 +281,7 @@ public: /** * Find the shortest path between given source and sink. This method should be called only after 'load' has been called. - * This method do not pay attention on the parameter mMaxAllowedCycles and go through all possible paths. + * This method do not pay attention on the parameter mMaxAllowedCycles and goes through all possible paths. * * @param source start point. * @param sink end point. diff --git a/AudioManagerCore/include/CAmRoutingSender.h b/AudioManagerCore/include/CAmRoutingSender.h index 8804d90..8d8a063 100644 --- a/AudioManagerCore/include/CAmRoutingSender.h +++ b/AudioManagerCore/include/CAmRoutingSender.h @@ -32,16 +32,17 @@ #include "../test/IAmRoutingBackdoor.h" #endif +#include "CAmDatabaseHandlerMap.h" + namespace am { class CAmRoutingReceiver; -class IAmDatabaseHandler; /** * Implements the RoutingSendInterface. Loads all plugins and dispatches calls to the plugins */ -class CAmRoutingSender +class CAmRoutingSender: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks { public: CAmRoutingSender(const std::vector& listOfPluginDirectories, IAmDatabaseHandler* databaseHandler); diff --git a/AudioManagerCore/include/IAmDatabaseHandler.h b/AudioManagerCore/include/IAmDatabaseHandler.h index aa275db..f4fe8a1 100644 --- a/AudioManagerCore/include/IAmDatabaseHandler.h +++ b/AudioManagerCore/include/IAmDatabaseHandler.h @@ -30,18 +30,14 @@ #include #include #include +#include +#include +#include #include "audiomanagerconfig.h" namespace am { -class CAmDatabaseObserver; -class CAmRoutingTree; -class CAmRoutingTreeItem; - - -//enum { DYNAMIC_ID_BOUNDARY = 100 }; //!< the value below is reserved for staticIDs, the value above will be assigned to dynamically registered items - //todo: check the enum values before entering & changing in the database. //todo: change asserts for dynamic boundary checks into failure answers.# //todo: check autoincrement boundary and set to 16bit limits @@ -59,8 +55,12 @@ typedef std::map > ListConnectionFormat; //!< class IAmDatabaseHandler { public: - IAmDatabaseHandler () {}; - virtual ~IAmDatabaseHandler () {}; + IAmDatabaseHandler (){} + virtual ~IAmDatabaseHandler (){} + + /** + * The following interface methods must be implemented by the subclass. + */ virtual am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID) = 0; virtual am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID) = 0; virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) = 0; @@ -117,7 +117,7 @@ public: virtual am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const = 0; virtual am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; virtual am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const = 0; - virtual am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const =0; + virtual am_Error_e getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector& listSoundproperties) const =0; virtual am_Error_e getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector& listSoundproperties) const =0; virtual am_Error_e getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; virtual am_Error_e getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const = 0; @@ -166,7 +166,6 @@ public: virtual am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector& listSourceConnectionFormats, const std::vector& listSinkConnectionFormats, const std::vector& convertionMatrix) = 0; virtual am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration) = 0; virtual am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration) = 0; - virtual bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const = 0; virtual bool existCrossFader(const am_crossfaderID_t crossfaderID) const = 0; virtual bool existConnection(const am_Connection_s & connection) const = 0; @@ -181,7 +180,6 @@ public: virtual bool existGateway(const am_gatewayID_t gatewayID) const = 0; virtual bool existSinkClass(const am_sinkClass_t sinkClassID) const = 0; virtual bool existSourceClass(const am_sourceClass_t sourceClassID) const = 0; - virtual void registerObserver(CAmDatabaseObserver *iObserver) = 0; virtual bool sourceVisible(const am_sourceID_t sourceID) const = 0; virtual bool sinkVisible(const am_sinkID_t sinkID) const = 0; virtual bool isComponentConnected(const am_Gateway_s & gateway) const = 0; @@ -192,7 +190,19 @@ public: virtual am_Error_e enumerateSinks(std::function cb) const = 0 ; virtual am_Error_e enumerateGateways(std::function cb) const = 0 ; virtual am_Error_e enumerateConverters(std::function cb) const = 0 ; + /** + * Database observer protocol + */ + class IAmDatabaseObserver + { + public: + IAmDatabaseObserver() {} + virtual ~IAmDatabaseObserver(){} + }; + virtual bool registerObserver(IAmDatabaseObserver * iObserver) = 0; + virtual bool unregisterObserver(IAmDatabaseObserver * iObserver) = 0; + virtual unsigned countObservers() = 0; }; diff --git a/AudioManagerCore/src/CAmCommandSender.cpp b/AudioManagerCore/src/CAmCommandSender.cpp index 2e60109..ea0d749 100644 --- a/AudioManagerCore/src/CAmCommandSender.cpp +++ b/AudioManagerCore/src/CAmCommandSender.cpp @@ -51,11 +51,13 @@ namespace am (*iter)->__VA_ARGS__; \ } -CAmCommandSender::CAmCommandSender(const std::vector& listOfPluginDirectories) : +CAmCommandSender::CAmCommandSender(const std::vector& listOfPluginDirectories, CAmSocketHandler *iSocketHandler) : + CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks(), mListInterfaces(), // mListLibraryHandles(), // mListLibraryNames(), // - mCommandReceiver() + mCommandReceiver(), + mSerializer(iSocketHandler) { if (listOfPluginDirectories.empty()) { @@ -159,6 +161,93 @@ CAmCommandSender::CAmCommandSender(const std::vector& listOfPluginD mListLibraryHandles.push_back(tempLibHandle); mListLibraryNames.push_back(iter->c_str()); } + + dboNewMainConnection = [&](const am_MainConnectionType_s& mainConnection) { + mSerializer.asyncCall(this, &CAmCommandSender::cbNewMainConnection, mainConnection); + }; + dboRemovedMainConnection = [&](const am_mainConnectionID_t mainConnection) { + mSerializer.asyncCall(this, &CAmCommandSender::cbRemovedMainConnection, mainConnection); + }; + dboNewSink = [&](const am_Sink_s& sink) { + if (sink.visible) + { + am_SinkType_s s; + s.availability = sink.available; + s.muteState = sink.muteState; + s.name = sink.name; + s.sinkClassID = sink.sinkClassID; + s.sinkID = sink.sinkID; + s.volume = sink.mainVolume; + mSerializer.asyncCall(this, &CAmCommandSender::cbNewSink, s); + } + }; + dboNewSource = [&](const am_Source_s& source) { + if (source.visible) + { + am_SourceType_s s; + s.availability = source.available; + s.name = source.name; + s.sourceClassID = source.sourceClassID; + s.sourceID = source.sourceID; + mSerializer.asyncCall(this, &CAmCommandSender::cbNewSource, s); + } + }; + + dboRemovedSink = [&](const am_sinkID_t sinkID, const bool visible) { + if (visible) + mSerializer.asyncCall(this, &CAmCommandSender::cbRemovedSink, sinkID); + }; + dboRemovedSource = [&](const am_sourceID_t sourceID, const bool visible) { + if (visible) + mSerializer.asyncCall(this, &CAmCommandSender::cbRemovedSource, sourceID); + }; + dboNumberOfSinkClassesChanged = [&]() { + mSerializer.asyncCall(this, &CAmCommandSender::cbNumberOfSinkClassesChanged); + }; + dboNumberOfSourceClassesChanged = [&]() { + mSerializer.asyncCall(this, &CAmCommandSender::cbNumberOfSourceClassesChanged); + }; + dboMainConnectionStateChanged = [&](const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) { + mSerializer.asyncCall(this, &CAmCommandSender::cbMainConnectionStateChanged, connectionID, connectionState); + }; + dboMainSinkSoundPropertyChanged = [&](const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) { + mSerializer.asyncCall(this, &CAmCommandSender::cbMainSinkSoundPropertyChanged, sinkID, SoundProperty); + }; + dboMainSourceSoundPropertyChanged = [&](const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) { + mSerializer.asyncCall(this, &CAmCommandSender::cbMainSourceSoundPropertyChanged, sourceID, SoundProperty); + }; + dboSinkAvailabilityChanged = [&](const am_sinkID_t sinkID, const am_Availability_s & availability) { + mSerializer.asyncCall(this, &CAmCommandSender::cbSinkAvailabilityChanged, sinkID, availability); + }; + dboSourceAvailabilityChanged = [&](const am_sourceID_t sourceID, const am_Availability_s & availability) { + mSerializer.asyncCall(this, &CAmCommandSender::cbSourceAvailabilityChanged, sourceID, availability); + }; + dboVolumeChanged = [&](const am_sinkID_t sinkID, const am_mainVolume_t volume) { + mSerializer.asyncCall(this, &CAmCommandSender::cbVolumeChanged, sinkID, volume); + }; + dboSinkMuteStateChanged = [&](const am_sinkID_t sinkID, const am_MuteState_e muteState) { + mSerializer.asyncCall(this, &CAmCommandSender::cbSinkMuteStateChanged, sinkID, muteState); + }; + dboSystemPropertyChanged = [&](const am_SystemProperty_s& SystemProperty) { + mSerializer.asyncCall(this, &CAmCommandSender::cbSystemPropertyChanged, SystemProperty); + }; + dboTimingInformationChanged = [&](const am_mainConnectionID_t mainConnection, const am_timeSync_t time) { + mSerializer.asyncCall(this, &CAmCommandSender::cbTimingInformationChanged, mainConnection, time); + }; + dboSinkUpdated = [&](const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) { + if (visible) + mSerializer.asyncCall >(this, &CAmCommandSender::cbSinkUpdated, sinkID, sinkClassID, listMainSoundProperties); + }; + dboSourceUpdated = [&](const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) { + if (visible) + mSerializer.asyncCall >(this, &CAmCommandSender::cbSinkUpdated, sourceID, sourceClassID, listMainSoundProperties); + }; + dboSinkMainNotificationConfigurationChanged = [&](const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) { + mSerializer.asyncCall (this, &CAmCommandSender::cbSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration); + }; + dboSourceMainNotificationConfigurationChanged = [&](const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) { + mSerializer.asyncCall(this, &CAmCommandSender::cbSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration); + }; } CAmCommandSender::~CAmCommandSender() @@ -366,4 +455,5 @@ void CAmCommandSender::unloadLibraries(void) } mListLibraryHandles.clear(); } + } diff --git a/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp index fa7f5fc..83419b9 100644 --- a/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp +++ b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp @@ -30,7 +30,6 @@ #include #include #include "CAmDatabaseHandlerMap.h" -#include "CAmDatabaseObserver.h" #include "CAmRouter.h" #include "CAmDltWrapper.h" @@ -56,6 +55,30 @@ (true) #endif +#define NOTIFY_OBSERVERS(CALL)\ + for(AmDatabaseObserverCallbacks * nextObserver: mDatabaseObservers)\ + if(nextObserver->CALL)\ + nextObserver->CALL(); + +#define NOTIFY_OBSERVERS1(CALL, ARG1)\ + for(AmDatabaseObserverCallbacks * nextObserver: mDatabaseObservers)\ + if(nextObserver->CALL)\ + nextObserver->CALL(ARG1); + +#define NOTIFY_OBSERVERS2(CALL, ARG1, ARG2)\ + for(AmDatabaseObserverCallbacks * nextObserver: mDatabaseObservers)\ + if(nextObserver->CALL)\ + nextObserver->CALL(ARG1, ARG2); + +#define NOTIFY_OBSERVERS3(CALL, ARG1, ARG2, ARG3)\ + for(AmDatabaseObserverCallbacks * nextObserver: mDatabaseObservers)\ + if(nextObserver->CALL)\ + nextObserver->CALL(ARG1, ARG2, ARG3); + +#define NOTIFY_OBSERVERS4(CALL, ARG1, ARG2, ARG3, ARG4)\ + for(AmDatabaseObserverCallbacks * nextObserver: mDatabaseObservers)\ + if(nextObserver->CALL)\ + nextObserver->CALL(ARG1, ARG2, ARG3, ARG4); namespace am { @@ -117,7 +140,7 @@ template const TReturn * objectMatchingPr /* Domain */ -void CAmDatabaseHandlerMap::CAmDomain::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmDomain::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Domain(" << name.c_str() << ") id(" << domainID << ")" << std::endl << @@ -133,7 +156,7 @@ void CAmDatabaseHandlerMap::CAmDomain::getDescription (std::string & outString) /* Source */ -void CAmDatabaseHandlerMap::CAmSource::getSourceType(am_SourceType_s & sourceType) const +void CAmDatabaseHandlerMap::AmSource::getSourceType(am_SourceType_s & sourceType) const { sourceType.name = name; sourceType.sourceClassID = sourceClassID; @@ -141,7 +164,7 @@ void CAmDatabaseHandlerMap::CAmSource::getSourceType(am_SourceType_s & sourceTyp sourceType.sourceID = sourceID; } -void CAmDatabaseHandlerMap::CAmSource::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmSource::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Source(" << name.c_str() << ") id(" << sourceID << ")" << std::endl << @@ -179,7 +202,7 @@ void CAmDatabaseHandlerMap::CAmSource::getDescription (std::string & outString) /* Sink */ -void CAmDatabaseHandlerMap::CAmSink::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmSink::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Sink(" << name.c_str() << ") id(" << sinkID << ")" << std::endl << @@ -215,7 +238,7 @@ void CAmDatabaseHandlerMap::CAmSink::getDescription (std::string & outString) co outString = fmt.str(); } -void CAmDatabaseHandlerMap::CAmSink::getSinkType(am_SinkType_s & sinkType) const +void CAmDatabaseHandlerMap::AmSink::getSinkType(am_SinkType_s & sinkType) const { sinkType.name = name; sinkType.sinkID = sinkID; @@ -227,7 +250,7 @@ void CAmDatabaseHandlerMap::CAmSink::getSinkType(am_SinkType_s & sinkType) const /* Connection */ -void CAmDatabaseHandlerMap::CAmConnection::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmConnection::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Connection id(" << connectionID << ") " << std::endl << @@ -241,7 +264,7 @@ void CAmDatabaseHandlerMap::CAmConnection::getDescription (std::string & outStri /* Main Connection */ -void CAmDatabaseHandlerMap::CAmMainConnection::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmMainConnection::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "MainConnection id(" << mainConnectionID << ") " << std::endl << @@ -268,7 +291,7 @@ void CAmDatabaseHandlerMap::am_MainConnection_Database_s::getMainConnectionType( /* Source Class */ -void CAmDatabaseHandlerMap::CAmSourceClass::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmSourceClass::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Source class(" << name.c_str() << ") id(" << sourceClassID << ")\n" << @@ -282,7 +305,7 @@ void CAmDatabaseHandlerMap::CAmSourceClass::getDescription (std::string & outStr /* Sink Class */ -void CAmDatabaseHandlerMap::CAmSinkClass::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmSinkClass::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Sink class(" << name.c_str() << ") id(" << sinkClassID << ")\n" << @@ -297,7 +320,7 @@ void CAmDatabaseHandlerMap::CAmSinkClass::getDescription (std::string & outStrin /* Gateway */ -void CAmDatabaseHandlerMap::CAmGateway::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmGateway::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Gateway(" << name.c_str() << ") id(" << gatewayID << ")\n" << @@ -322,9 +345,34 @@ void CAmDatabaseHandlerMap::CAmGateway::getDescription (std::string & outString) outString = fmt.str(); } +/* Converter */ + +void CAmDatabaseHandlerMap::AmConverter::getDescription (std::string & outString) const +{ + std::ostringstream fmt; + fmt << "Converter(" << name.c_str() << ") id(" << converterID << ")\n" << + "sinkID(" << sinkID << + ") sourceID(" << sourceID << + ") domainSinkID(" << domainID << + ") listSourceFormats ("; + std::for_each(listSourceFormats.begin(), listSourceFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") listSinkFormats ("; + std::for_each(listSinkFormats.begin(), listSinkFormats.end(), [&](const am_CustomConnectionFormat_t & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ") convertionMatrix ("; + std::for_each(convertionMatrix.begin(), convertionMatrix.end(), [&](const bool & ref) { + fmt << "[" << ref << "]"; + }); + fmt << ")" << std::endl; + outString = fmt.str(); +} + /* Crossfader */ -void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outString) const +void CAmDatabaseHandlerMap::AmCrossfader::getDescription (std::string & outString) const { std::ostringstream fmt; fmt << "Crossfader(" << name.c_str() << ") id(" << crossfaderID << ")\n" << @@ -336,7 +384,7 @@ void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outStri outString = fmt.str(); } -bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t & resultID, am_Identifier_s & sourceID, +bool CAmDatabaseHandlerMap::AmMappedData::increaseID(int16_t & resultID, AmIdentifier & sourceID, int16_t const desiredStaticID = 0) { if( desiredStaticID > 0 && desiredStaticID < sourceID.mMin ) @@ -356,7 +404,7 @@ bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t & resultID, am_Ide } } -template bool CAmDatabaseHandlerMap::CAmMappedData::getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID, +template bool CAmDatabaseHandlerMap::AmMappedData::getNextConnectionID(int16_t & resultID, AmIdentifier & sourceID, const std::unordered_map & map) { TMapKey nextID; @@ -393,27 +441,28 @@ template bool CAmDatabaseHandlerMap::CAmMapp return true; } -bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t & resultID) +bool CAmDatabaseHandlerMap::AmMappedData::increaseMainConnectionID(int16_t & resultID) { return getNextConnectionID(resultID, mCurrentMainConnectionID, mMainConnectionMap); } -bool CAmDatabaseHandlerMap::CAmMappedData::increaseConnectionID(int16_t & resultID) +bool CAmDatabaseHandlerMap::AmMappedData::increaseConnectionID(int16_t & resultID) { return getNextConnectionID(resultID, mCurrentConnectionID, mConnectionMap); } -CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), // - mFirstStaticSource(true), // - mFirstStaticGateway(true), // - mFirstStaticConverter(true), // - mFirstStaticSinkClass(true), // - mFirstStaticSourceClass(true), // - mFirstStaticCrossfader(true), // - mpDatabaseObserver(NULL), // - mListConnectionFormat(), // - mMappedData() +CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): IAmDatabaseHandler(), + mFirstStaticSink(true), // + mFirstStaticSource(true), // + mFirstStaticGateway(true), // + mFirstStaticConverter(true), // + mFirstStaticSinkClass(true), // + mFirstStaticSourceClass(true), // + mFirstStaticCrossfader(true), // + mListConnectionFormat(), // + mMappedData(), + mDatabaseObservers() { logVerbose(__METHOD_NAME__,"Init "); } @@ -421,7 +470,8 @@ CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), // CAmDatabaseHandlerMap::~CAmDatabaseHandlerMap() { logVerbose(__METHOD_NAME__,"Destroy"); - mpDatabaseObserver = NULL; + for(AmDatabaseObserverCallbacks * ptr: mDatabaseObservers) + ptr->mpDatabaseHandler=nullptr; } am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID) @@ -442,7 +492,7 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, return (E_NOT_POSSIBLE); } //first check for a reserved domain - am_Domain_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const CAmDomain & obj){ + am_Domain_s const *reservedDomain = objectMatchingPredicate(mMappedData.mDomainMap, [&](const AmDomain & obj){ return domainData.name.compare(obj.name)==0; }); @@ -456,8 +506,9 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, mMappedData.mDomainMap[nextID].domainID = nextID; mMappedData.mDomainMap[nextID].reserved = 0; logVerbose("DatabaseHandler::enterDomainDB entered reserved domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "reserved ID:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); + + NOTIFY_OBSERVERS1(dboNewDomain, mMappedData.mDomainMap[nextID]) + return (E_OK); } else @@ -468,8 +519,9 @@ am_Error_e CAmDatabaseHandlerMap::enterDomainDB(const am_Domain_s & domainData, mMappedData.mDomainMap[nextID] = domainData; mMappedData.mDomainMap[nextID].domainID = nextID; logVerbose("DatabaseHandler::enterDomainDB entered new domain with name=", domainData.name, "busname=", domainData.busname, "nodename=", domainData.nodename, "assigned ID:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->newDomain(mMappedData.mDomainMap[nextID]); + + NOTIFY_OBSERVERS1(dboNewDomain, mMappedData.mDomainMap[nextID]) + return (E_OK); } else @@ -543,12 +595,14 @@ am_Error_e CAmDatabaseHandlerMap::enterMainConnectionDB(const am_MainConnection_ delay = calculateDelayForRoute(mainConnectionData.listConnectionID); logVerbose("DatabaseHandler::enterMainConnectionDB entered new mainConnection with sourceID", mainConnectionData.sourceID, "sinkID:", mainConnectionData.sinkID, "delay:", delay, "assigned ID:", connectionID); - if (mpDatabaseObserver) + + if (mDatabaseObservers.size()) { - am_MainConnectionType_s mainConnection; - mMappedData.mMainConnectionMap[nextID].getMainConnectionType(mainConnection); - mpDatabaseObserver->newMainConnection(mainConnection); - mpDatabaseObserver->mainConnectionStateChanged(connectionID, mMappedData.mMainConnectionMap[nextID].connectionState); + am_MainConnectionType_s mainConnection; + mMappedData.mMainConnectionMap[nextID].getMainConnectionType(mainConnection); + + NOTIFY_OBSERVERS1(dboNewMainConnection, mainConnection) + NOTIFY_OBSERVERS2(dboMainConnectionStateChanged, connectionID, mMappedData.mMainConnectionMap[nextID].connectionState) } //finally, we update the delay value for the maintable @@ -615,7 +669,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sin am_sinkID_t temp_SinkID = 0; am_sinkID_t temp_SinkIndex = 0; //if sinkID is zero and the first Static Sink was already entered, the ID is created - am_Sink_s const *reservedDomain = objectMatchingPredicate(mMappedData.mSinkMap, [&](const CAmSink & obj){ + am_Sink_s const *reservedDomain = objectMatchingPredicate(mMappedData.mSinkMap, [&](const AmSink & obj){ return true==obj.reserved && obj.name.compare(sinkData.name)==0; }); if( NULL!=reservedDomain ) @@ -654,11 +708,9 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkDB(const am_Sink_s & sinkData, am_sin am_Sink_s & sink = mMappedData.mSinkMap[temp_SinkID]; logVerbose("DatabaseHandler::enterSinkDB entered new sink with name", sink.name, "domainID:", sink.domainID, "classID:", sink.sinkClassID, "volume:", sink.volume, "assigned ID:", sink.sinkID); - if (mpDatabaseObserver != NULL) - { - sink.sinkID=sinkID; - mpDatabaseObserver->newSink(sink); - } + sink.sinkID=sinkID; + NOTIFY_OBSERVERS1(dboNewSink, sink) + return (E_OK); } @@ -744,8 +796,8 @@ am_Error_e CAmDatabaseHandlerMap::enterCrossfaderDB(const am_Crossfader_s & cros crossfaderID = temp_CrossfaderID; logVerbose("DatabaseHandler::enterCrossfaderDB entered new crossfader with name=", crossfaderData.name, "sinkA= ", crossfaderData.sinkID_A, "sinkB=", crossfaderData.sinkID_B, "source=", crossfaderData.sourceID, "assigned ID:", crossfaderID); - if (mpDatabaseObserver) - mpDatabaseObserver->newCrossfader(mMappedData.mCrossfaderMap[temp_CrossfaderIndex]); + NOTIFY_OBSERVERS1(dboNewCrossfader, mMappedData.mCrossfaderMap[temp_CrossfaderIndex]) + return (E_OK); } @@ -819,8 +871,8 @@ am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayDat gatewayID = temp_GatewayID; logVerbose("DatabaseHandler::enterGatewayDB entered new gateway with name", gatewayData.name, "sourceID:", gatewayData.sourceID, "sinkID:", gatewayData.sinkID, "assigned ID:", gatewayID); - if (mpDatabaseObserver) - mpDatabaseObserver->newGateway(mMappedData.mGatewayMap[temp_GatewayIndex]); + + NOTIFY_OBSERVERS1(dboNewGateway, mMappedData.mGatewayMap[temp_GatewayIndex]) return (E_OK); } @@ -905,24 +957,24 @@ am_Error_e CAmDatabaseHandlerMap::enterConverterDB(const am_Converter_s & conver converterID = tempID; logVerbose("DatabaseHandler::enterConverterDB entered new converter with name", converterData.name, "sourceID:", converterData.sourceID, "sinkID:", converterData.sinkID, "assigned ID:", converterID); - if (mpDatabaseObserver) - mpDatabaseObserver->newConverter(mMappedData.mConverterMap[tempIndex]); + NOTIFY_OBSERVERS1(dboNewConverter, mMappedData.mConverterMap[tempIndex]) + return (E_OK); } void CAmDatabaseHandlerMap::dump( std::ostream & output ) const { output << std::endl << "****************** DUMP START ******************" << std::endl; - CAmMappedData::printMap(mMappedData.mDomainMap, output); - CAmMappedData::printMap(mMappedData.mSourceMap, output); - CAmMappedData::printMap(mMappedData.mSinkMap, output); - CAmMappedData::printMap(mMappedData.mSourceClassesMap, output); - CAmMappedData::printMap(mMappedData.mSinkClassesMap, output); - CAmMappedData::printMap(mMappedData.mConnectionMap, output); - CAmMappedData::printMap(mMappedData.mMainConnectionMap, output); - CAmMappedData::printMap(mMappedData.mCrossfaderMap, output); - CAmMappedData::printMap(mMappedData.mGatewayMap, output); - CAmVectorSystemProperties::const_iterator iter = mMappedData.mSystemProperties.begin(); + AmMappedData::printMap(mMappedData.mDomainMap, output); + AmMappedData::printMap(mMappedData.mSourceMap, output); + AmMappedData::printMap(mMappedData.mSinkMap, output); + AmMappedData::printMap(mMappedData.mSourceClassesMap, output); + AmMappedData::printMap(mMappedData.mSinkClassesMap, output); + AmMappedData::printMap(mMappedData.mConnectionMap, output); + AmMappedData::printMap(mMappedData.mMainConnectionMap, output); + AmMappedData::printMap(mMappedData.mCrossfaderMap, output); + AmMappedData::printMap(mMappedData.mGatewayMap, output); + AmVectorSystemProperties::const_iterator iter = mMappedData.mSystemProperties.begin(); output << "System properties" << "\n"; for(; iter!=mMappedData.mSystemProperties.end(); iter++) output << "[type:" << iter->type << " value:" << iter->value << "]"; @@ -981,7 +1033,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData, bool isFirstStatic = sourceData.sourceID == 0 && mFirstStaticSource; am_sourceID_t temp_SourceID = 0; am_sourceID_t temp_SourceIndex = 0; - CAmSource const *reservedSource = objectMatchingPredicate(mMappedData.mSourceMap, [&](const CAmSource & obj){ + AmSource const *reservedSource = objectMatchingPredicate(mMappedData.mSourceMap, [&](const AmSource & obj){ return true==obj.reserved && obj.name.compare(sourceData.name)==0; }); if( NULL != reservedSource ) @@ -1020,8 +1072,8 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceDB(const am_Source_s & sourceData, logVerbose("DatabaseHandler::enterSourceDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); - if (mpDatabaseObserver) - mpDatabaseObserver->newSource(mMappedData.mSourceMap[temp_SourceIndex]); + NOTIFY_OBSERVERS1(dboNewSource, mMappedData.mSourceMap[temp_SourceIndex]) + return (E_OK); } @@ -1124,8 +1176,7 @@ am_Error_e CAmDatabaseHandlerMap::enterSinkClassDB(const am_SinkClass_s & sinkCl //todo:change last_insert implementations for multithreaded usage... logVerbose("DatabaseHandler::enterSinkClassDB entered new sinkClass"); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSinkClassesChanged(); + NOTIFY_OBSERVERS(dboNumberOfSinkClassesChanged) return (E_OK); } @@ -1192,8 +1243,8 @@ am_Error_e CAmDatabaseHandlerMap::enterSourceClassDB(am_sourceClass_t & sourceCl logVerbose("DatabaseHandler::enterSourceClassDB entered new sourceClass"); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSourceClassesChanged(); + NOTIFY_OBSERVERS(dboNumberOfSourceClassesChanged) + return (E_OK); } @@ -1260,8 +1311,7 @@ am_Error_e CAmDatabaseHandlerMap::changeMainConnectionStateDB(const am_mainConne DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[mainconnectionID].connectionState, connectionState); logVerbose("DatabaseHandler::changeMainConnectionStateDB changed mainConnectionState of MainConnection:", mainconnectionID, "to:", connectionState); - if (mpDatabaseObserver) - mpDatabaseObserver->mainConnectionStateChanged(mainconnectionID, connectionState); + NOTIFY_OBSERVERS2(dboMainConnectionStateChanged, mainconnectionID, connectionState) return (E_OK); } @@ -1277,8 +1327,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkMainVolumeDB(const am_mainVolume_t m logVerbose("DatabaseHandler::changeSinkMainVolumeDB changed mainVolume of sink:", sinkID, "to:", mainVolume); - if (mpDatabaseObserver) - mpDatabaseObserver->volumeChanged(sinkID, mainVolume); + NOTIFY_OBSERVERS2(dboVolumeChanged, sinkID, mainVolume) return (E_OK); } @@ -1301,8 +1350,10 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkAvailabilityDB(const am_Availability logVerbose("DatabaseHandler::changeSinkAvailabilityDB changed sinkAvailability of sink:", sinkID, "to:", availability.availability, "Reason:", availability.availabilityReason); - if (mpDatabaseObserver && sinkVisible(sinkID)) - mpDatabaseObserver->sinkAvailabilityChanged(sinkID, availability); + if (sinkVisible(sinkID)) + { + NOTIFY_OBSERVERS2(dboSinkAvailabilityChanged,sinkID, availability) + } return (E_OK); } @@ -1346,8 +1397,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkMuteStateDB(const am_MuteState_e mut logVerbose("DatabaseHandler::changeSinkMuteStateDB changed sinkMuteState of sink:", sinkID, "to:", muteState); - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMuteStateChanged(sinkID, muteState); + NOTIFY_OBSERVERS2(dboSinkMuteStateChanged, sinkID, muteState) return (E_OK); } @@ -1374,8 +1424,7 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSinkSoundPropertyDB(const am_MainSou } logVerbose("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - if (mpDatabaseObserver) - mpDatabaseObserver->mainSinkSoundPropertyChanged(sinkID, soundProperty); + NOTIFY_OBSERVERS2(dboMainSinkSoundPropertyChanged, sinkID, soundProperty) return (E_OK); } @@ -1402,8 +1451,7 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainS logVerbose("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - if (mpDatabaseObserver) - mpDatabaseObserver->mainSourceSoundPropertyChanged(sourceID, soundProperty); + NOTIFY_OBSERVERS2(dboMainSourceSoundPropertyChanged, sourceID, soundProperty) return (E_OK); } @@ -1425,8 +1473,10 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceAvailabilityDB(const am_Availabili logVerbose("DatabaseHandler::changeSourceAvailabilityDB changed changeSourceAvailabilityDB of source:", sourceID, "to:", availability.availability, "Reason:", availability.availabilityReason); - if (mpDatabaseObserver && sourceVisible(sourceID)) - mpDatabaseObserver->sourceAvailabilityChanged(sourceID, availability); + if (sourceVisible(sourceID)) + { + NOTIFY_OBSERVERS2(dboSourceAvailabilityChanged, sourceID, availability) + } return (E_OK); } @@ -1441,8 +1491,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSystemPropertyDB(const am_SystemProperty logVerbose("DatabaseHandler::changeSystemPropertyDB changed system property"); - if (mpDatabaseObserver) - mpDatabaseObserver->systemPropertyChanged(property); + NOTIFY_OBSERVERS1(dboSystemPropertyChanged, property) return (E_OK); } @@ -1459,11 +1508,10 @@ am_Error_e CAmDatabaseHandlerMap::removeMainConnectionDB(const am_mainConnection mMappedData.mMainConnectionMap.erase(mainConnectionID); logVerbose("DatabaseHandler::removeMainConnectionDB removed:", mainConnectionID); - if (mpDatabaseObserver) - { - mpDatabaseObserver->mainConnectionStateChanged(mainConnectionID, CS_DISCONNECTED); - mpDatabaseObserver->removedMainConnection(mainConnectionID); - } + + NOTIFY_OBSERVERS2(dboMainConnectionStateChanged, mainConnectionID, CS_DISCONNECTED) + NOTIFY_OBSERVERS1(dboRemovedMainConnection, mainConnectionID) + return (E_OK); } @@ -1483,8 +1531,7 @@ am_Error_e CAmDatabaseHandlerMap::removeSinkDB(const am_sinkID_t sinkID) //if visible is true then delete SinkMainSoundProperty and SinkMainNotificationConfiguration ???? logVerbose("DatabaseHandler::removeSinkDB removed:", sinkID); - if (mpDatabaseObserver != NULL) - mpDatabaseObserver->removedSink(sinkID, visible); + NOTIFY_OBSERVERS2(dboRemovedSink, sinkID, visible) return (E_OK); } @@ -1506,8 +1553,7 @@ am_Error_e CAmDatabaseHandlerMap::removeSourceDB(const am_sourceID_t sourceID) //if visible is true then delete SourceMainSoundProperty and SourceMainNotificationConfiguration ???? logVerbose("DatabaseHandler::removeSourceDB removed:", sourceID); - if (mpDatabaseObserver) - mpDatabaseObserver->removedSource(sourceID, visible); + NOTIFY_OBSERVERS2(dboRemovedSource, sourceID, visible) return (E_OK); } @@ -1523,8 +1569,7 @@ am_Error_e CAmDatabaseHandlerMap::removeGatewayDB(const am_gatewayID_t gatewayID mMappedData.mGatewayMap.erase(gatewayID); logVerbose("DatabaseHandler::removeGatewayDB removed:", gatewayID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeGateway(gatewayID); + NOTIFY_OBSERVERS1(dboRemoveGateway, gatewayID) return (E_OK); } @@ -1540,8 +1585,7 @@ am_Error_e CAmDatabaseHandlerMap::removeConverterDB(const am_converterID_t conve mMappedData.mConverterMap.erase(converterID); logVerbose("DatabaseHandler::removeConverterDB removed:", converterID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeConverter(converterID); + NOTIFY_OBSERVERS1(dboRemoveConverter, converterID) return (E_OK); } @@ -1556,8 +1600,8 @@ am_Error_e CAmDatabaseHandlerMap::removeCrossfaderDB(const am_crossfaderID_t cro mMappedData.mCrossfaderMap.erase(crossfaderID); logVerbose("DatabaseHandler::removeCrossfaderDB removed:", crossfaderID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeCrossfader(crossfaderID); + NOTIFY_OBSERVERS1(dboRemoveCrossfader, crossfaderID) + return (E_OK); } @@ -1572,8 +1616,8 @@ am_Error_e CAmDatabaseHandlerMap::removeDomainDB(const am_domainID_t domainID) mMappedData.mDomainMap.erase(domainID); logVerbose("DatabaseHandler::removeDomainDB removed:", domainID); - if (mpDatabaseObserver) - mpDatabaseObserver->removeDomain(domainID); + NOTIFY_OBSERVERS1(dboRemoveDomain, domainID) + return (E_OK); } @@ -1589,9 +1633,7 @@ am_Error_e CAmDatabaseHandlerMap::removeSinkClassDB(const am_sinkClass_t sinkCla mMappedData.mSinkClassesMap.erase(sinkClassID); logVerbose("DatabaseHandler::removeSinkClassDB removed:", sinkClassID); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSinkClassesChanged(); - + NOTIFY_OBSERVERS(dboNumberOfSinkClassesChanged) return (E_OK); } @@ -1606,8 +1648,7 @@ am_Error_e CAmDatabaseHandlerMap::removeSourceClassDB(const am_sourceClass_t sou mMappedData.mSourceClassesMap.erase(sourceClassID); logVerbose("DatabaseHandler::removeSourceClassDB removed:", sourceClassID); - if (mpDatabaseObserver) - mpDatabaseObserver->numberOfSourceClassesChanged(); + NOTIFY_OBSERVERS(dboNumberOfSourceClassesChanged) return (E_OK); } @@ -1825,7 +1866,7 @@ am_Error_e CAmDatabaseHandlerMap::getListSourcesOfDomain(const am_domainID_t dom logWarning(__METHOD_NAME__,"domainID must exist"); return (E_NON_EXISTENT); } - CAmMapSource::const_iterator elementIterator = mMappedData.mSourceMap.begin(); + AmMapSource::const_iterator elementIterator = mMappedData.mSourceMap.begin(); for (;elementIterator != mMappedData.mSourceMap.end(); ++elementIterator) { if (0==elementIterator->second.reserved && domainID==elementIterator->second.domainID) @@ -1844,12 +1885,12 @@ am_Error_e CAmDatabaseHandlerMap::getListCrossfadersOfDomain(const am_domainID_t return (E_NON_EXISTENT); } - CAmMapSource::const_iterator sourceIterator = mMappedData.mSourceMap.begin(); + AmMapSource::const_iterator sourceIterator = mMappedData.mSourceMap.begin(); for (;sourceIterator != mMappedData.mSourceMap.end(); ++sourceIterator) { if (domainID==sourceIterator->second.domainID) { - CAmMapCrossfader::const_iterator elementIterator = mMappedData.mCrossfaderMap.begin(); + AmMapCrossfader::const_iterator elementIterator = mMappedData.mCrossfaderMap.begin(); for (;elementIterator != mMappedData.mCrossfaderMap.end(); ++elementIterator) { if ( sourceIterator->second.sourceID==elementIterator->second.sourceID ) @@ -1871,7 +1912,7 @@ am_Error_e CAmDatabaseHandlerMap::getListGatewaysOfDomain(const am_domainID_t do return (E_NON_EXISTENT); } - CAmMapGateway::const_iterator elementIterator = mMappedData.mGatewayMap.begin(); + AmMapGateway::const_iterator elementIterator = mMappedData.mGatewayMap.begin(); for (;elementIterator != mMappedData.mGatewayMap.end(); ++elementIterator) { if (domainID==elementIterator->second.controlDomainID) @@ -1889,7 +1930,7 @@ am_Error_e CAmDatabaseHandlerMap::getListConvertersOfDomain(const am_domainID_t return (E_NON_EXISTENT); } - CAmMapConverter::const_iterator elementIterator = mMappedData.mConverterMap.begin(); + AmMapConverter::const_iterator elementIterator = mMappedData.mConverterMap.begin(); for (;elementIterator != mMappedData.mConverterMap.end(); ++elementIterator) { if (domainID==elementIterator->second.domainID) @@ -1902,7 +1943,7 @@ am_Error_e CAmDatabaseHandlerMap::getListMainConnections(std::vectorsecond); @@ -1915,7 +1956,7 @@ am_Error_e CAmDatabaseHandlerMap::getListDomains(std::vector & list { listDomains.clear(); - CAmMapDomain::const_iterator elementIterator = mMappedData.mDomainMap.begin(); + AmMapDomain::const_iterator elementIterator = mMappedData.mDomainMap.begin(); for (;elementIterator != mMappedData.mDomainMap.end(); ++elementIterator) { if( 0==elementIterator->second.reserved ) @@ -1929,7 +1970,7 @@ am_Error_e CAmDatabaseHandlerMap::getListConnections(std::vectorsecond.reserved ) @@ -1943,7 +1984,7 @@ am_Error_e CAmDatabaseHandlerMap::getListConnectionsReserved(std::vectorsecond.reserved ) @@ -2205,8 +2246,7 @@ am_Error_e CAmDatabaseHandlerMap::changeDelayMainConnection(const am_timeSync_t return E_NON_EXISTENT; } DB_COND_UPDATE_RIE(mMappedData.mMainConnectionMap[connectionID].delay, delay); - if (mpDatabaseObserver) - mpDatabaseObserver->timingInformationChanged(connectionID, delay); + NOTIFY_OBSERVERS2(dboTimingInformationChanged, connectionID, delay) return (E_OK); } @@ -2263,7 +2303,7 @@ bool CAmDatabaseHandlerMap::existSourceName(const std::string & name) const bool CAmDatabaseHandlerMap::existSink(const am_sinkID_t sinkID) const { bool returnVal = false; - CAmMapSink::const_iterator elementIterator = mMappedData.mSinkMap.begin(); + AmMapSink::const_iterator elementIterator = mMappedData.mSinkMap.begin(); for (;elementIterator != mMappedData.mSinkMap.end(); ++elementIterator) { if( 0==elementIterator->second.reserved && @@ -2429,7 +2469,7 @@ am_Error_e CAmDatabaseHandlerMap::changeConnectionTimingInformation(const am_con //first get all route tables for all mainconnections am_Error_e error = E_OK; - CAmMapMainConnection::const_iterator iter = mMappedData.mMainConnectionMap.begin(); + AmMapMainConnection::const_iterator iter = mMappedData.mMainConnectionMap.begin(); for(; iter != mMappedData.mMainConnectionMap.end(); ++iter) { const am_MainConnection_s & mainConnection = iter->second; @@ -2477,11 +2517,6 @@ am_timeSync_t CAmDatabaseHandlerMap::calculateMainConnectionDelay(const am_mainC * registers the Observer at the Database * @param iObserver pointer to the observer */ -void CAmDatabaseHandlerMap::registerObserver(CAmDatabaseObserver *iObserver) -{ - assert(iObserver!=NULL); - mpDatabaseObserver = iObserver; -} /** * gives information about the visibility of a source @@ -3038,10 +3073,8 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceDB(const am_sourceID_t sourceID, c { logVerbose("DatabaseHandler::changeSource changed changeSource of source:", sourceID); - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sourceUpdated(sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID)); - } + NOTIFY_OBSERVERS4(dboSourceUpdated, sourceID,sourceClassOut,listMainSoundPropertiesOut,sourceVisible(sourceID)) + } return (E_OK); @@ -3109,10 +3142,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkDB(const am_sinkID_t sinkID, const a { logVerbose("DatabaseHandler::changeSink changed changeSink of sink:", sinkID); - if (mpDatabaseObserver != NULL) - { - mpDatabaseObserver->sinkUpdated(sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID)); - } + NOTIFY_OBSERVERS4(dboSinkUpdated, sinkID,sinkClassOut,listMainSoundPropertiesOut,sinkVisible(sinkID)) } return (E_OK); @@ -3179,8 +3209,8 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSinkNotificationConfigurationDB(cons logVerbose("DatabaseHandler::changeMainSinkNotificationConfigurationDB changed MainNotificationConfiguration of source:", sinkID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - if (mpDatabaseObserver) - mpDatabaseObserver->sinkMainNotificationConfigurationChanged(sinkID, mainNotificationConfiguration); + NOTIFY_OBSERVERS2(dboSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration) + return (E_OK); } @@ -3198,8 +3228,8 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSourceNotificationConfigurationDB(co logVerbose("DatabaseHandler::changeMainSourceNotificationConfigurationDB changed MainNotificationConfiguration of source:", sourceID, "type:", mainNotificationConfiguration.type, "to status=", mainNotificationConfiguration.status, "and parameter=",mainNotificationConfiguration.parameter); - if (mpDatabaseObserver) - mpDatabaseObserver->sourceMainNotificationConfigurationChanged(sourceID, mainNotificationConfiguration); + NOTIFY_OBSERVERS2(dboSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration) + return (E_OK); } @@ -3358,4 +3388,31 @@ am_Error_e CAmDatabaseHandlerMap::enumerateConverters(std::function(iObserver)), dynamic_cast(iObserver)->mpDatabaseHandler = + nullptr; + return true; + } + return false; +} +bool CAmDatabaseHandlerMap::unregisterObserver(IAmDatabaseObserver * iObserver) { + assert(iObserver!=NULL); + auto it = std::find(mDatabaseObservers.begin(), mDatabaseObservers.end(), + iObserver); + if (it != mDatabaseObservers.end()) { + mDatabaseObservers.erase(it), dynamic_cast(iObserver)->mpDatabaseHandler = + nullptr; + return true; + } + return false; +} + +unsigned CAmDatabaseHandlerMap::countObservers() { + return mDatabaseObservers.size(); +} + } diff --git a/AudioManagerCore/src/CAmDatabaseObserver.cpp b/AudioManagerCore/src/CAmDatabaseObserver.cpp deleted file mode 100644 index d9ced92..0000000 --- a/AudioManagerCore/src/CAmDatabaseObserver.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * - * \file CAmDatabaseObserver.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmDatabaseObserver.h" -#include -#include -#include -#include -#include -#include "CAmCommandSender.h" -#include "CAmRoutingSender.h" -#include "CAmDltWrapper.h" -#include "CAmSerializer.h" - -namespace am { - -CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : - mCommandSender(iCommandSender), // - mRoutingSender(iRoutingSender), // - mTelnetServer(NULL), // - mSerializer(iSocketHandler) // -{ - assert(mCommandSender!=0); - assert(mRoutingSender!=0); - assert(iSocketHandler!=0); -} - -CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler, CAmTelnetServer *iTelnetServer) : - mCommandSender(iCommandSender), // - mRoutingSender(iRoutingSender), // - mTelnetServer(iTelnetServer), // - mSerializer(iSocketHandler) // -{ - assert(mTelnetServer!=0); - assert(mCommandSender!=0); - assert(mRoutingSender!=0); - assert(iSocketHandler!=0); -} - -CAmDatabaseObserver::~CAmDatabaseObserver() -{ -} - -void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewMainConnection, mainConnection); -} - -void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedMainConnection, mainConnection); -} - -void CAmDatabaseObserver::newSink(const am_Sink_s& sink) -{ - mRoutingSender->addSinkLookup(sink); - if (sink.visible) - { - am_SinkType_s s; - s.availability = sink.available; - s.muteState = sink.muteState; - s.name = sink.name; - s.sinkClassID = sink.sinkClassID; - s.sinkID = sink.sinkID; - s.volume = sink.mainVolume; - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewSink, s); - } -} - -void CAmDatabaseObserver::newSource(const am_Source_s& source) -{ - mRoutingSender->addSourceLookup(source); - if (source.visible) - { - am_SourceType_s s; - s.availability = source.available; - s.name = source.name; - s.sourceClassID = source.sourceClassID; - s.sourceID = source.sourceID; - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNewSource, s); - } -} - -void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) -{ - mRoutingSender->addDomainLookup(domain); -} - -void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) -{ - (void) gateway; - //todo: implement something -} - -void CAmDatabaseObserver::newConverter(const am_Converter_s& coverter) -{ - (void) coverter; - //todo: implement something -} - -void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) -{ - mRoutingSender->addCrossfaderLookup(crossfader); -} - -void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) -{ - mRoutingSender->removeSinkLookup(sinkID); - - if (visible) - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedSink, sinkID); -} - -void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) -{ - mRoutingSender->removeSourceLookup(sourceID); - - if (visible) - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbRemovedSource, sourceID); -} - -void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) -{ - mRoutingSender->removeDomainLookup(domainID); -} - -void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) -{ - (void) gatewayID; - //todo: implement something? -} - -void CAmDatabaseObserver::removeConverter(const am_converterID_t converterID) -{ - (void) converterID; - //todo: implement something? -} - -void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) -{ - mRoutingSender->removeCrossfaderLookup(crossfaderID); -} - -void CAmDatabaseObserver::numberOfSinkClassesChanged() -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNumberOfSinkClassesChanged); -} - -void CAmDatabaseObserver::numberOfSourceClassesChanged() -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbNumberOfSourceClassesChanged); -} - -void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainConnectionStateChanged, connectionID, connectionState); -} - -void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainSinkSoundPropertyChanged, sinkID, SoundProperty); -} - -void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbMainSourceSoundPropertyChanged, sourceID, SoundProperty); -} - -void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSinkAvailabilityChanged, sinkID, availability); -} - -void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSourceAvailabilityChanged, sourceID, availability); -} - -void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbVolumeChanged, sinkID, volume); -} - -void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSinkMuteStateChanged, sinkID, muteState); -} - -void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSystemPropertyChanged, SystemProperty); -} - -void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbTimingInformationChanged, mainConnection, time); -} - -void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) -{ - if (visible) - mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sinkID, sinkClassID, listMainSoundProperties); -} - -void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) -{ - if (visible) - mSerializer.asyncCall >(mCommandSender, &CAmCommandSender::cbSinkUpdated, sourceID, sourceClassID, listMainSoundProperties); -} - -void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - mSerializer.asyncCall (mCommandSender, &CAmCommandSender::cbSinkMainNotificationConfigurationChanged, sinkID, mainNotificationConfiguration); -} - -void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ - mSerializer.asyncCall(mCommandSender, &CAmCommandSender::cbSourceMainNotificationConfigurationChanged, sourceID, mainNotificationConfiguration); -} - -} diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index 002bd9d..5edd6d5 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -54,6 +54,7 @@ template void getMergeConnectionFormats(const X * element, CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : + CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks(), mpDatabaseHandler(iDatabaseHandler), // mpControlSender(iSender), mOnlyFreeConversionNodes(false), diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp index fc0953f..0e25e68 100644 --- a/AudioManagerCore/src/CAmRoutingSender.cpp +++ b/AudioManagerCore/src/CAmRoutingSender.cpp @@ -45,133 +45,160 @@ namespace am #define __METHOD_NAME__ std::string (std::string("CAmRoutingSender::") + __func__) -CAmRoutingSender::CAmRoutingSender(const std::vector& listOfPluginDirectories, IAmDatabaseHandler* databaseHandler) : - mHandleCount(0), // - mlistActiveHandles(), // - mListInterfaces(), // - mMapConnectionInterface(), // - mMapCrossfaderInterface(), // - mMapDomainInterface(), // - mMapSinkInterface(), // - mMapSourceInterface(), // - mpRoutingReceiver(), // - mpDatabaseHandler(databaseHandler) -{ +CAmRoutingSender::CAmRoutingSender( + const std::vector& listOfPluginDirectories, + IAmDatabaseHandler* databaseHandler) : + mHandleCount(0), // + mlistActiveHandles(), // + mListInterfaces(), // + mMapConnectionInterface(), // + mMapCrossfaderInterface(), // + mMapDomainInterface(), // + mMapSinkInterface(), // + mMapSourceInterface(), // + mpRoutingReceiver(), // + mpDatabaseHandler(databaseHandler) { + + if (listOfPluginDirectories.empty()) { + logError(__METHOD_NAME__,"List of routingplugins is empty"); + } - if (listOfPluginDirectories.empty()) - { - logError(__METHOD_NAME__,"List of routingplugins is empty"); - } + std::vector sharedLibraryNameList; + std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); + std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); - std::vector sharedLibraryNameList; - std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); - std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); + // search communicator plugins in configured directories + for (; dirIter < dirIterEnd; ++dirIter) + { + const char* directoryName = dirIter->c_str(); + logInfo(__METHOD_NAME__,"Searching for HookPlugins in", directoryName); + DIR *directory = opendir(directoryName); - // search communicator plugins in configured directories - for (; dirIter < dirIterEnd; ++dirIter) - { - const char* directoryName = dirIter->c_str(); - logInfo(__METHOD_NAME__,"Searching for HookPlugins in", directoryName); - DIR *directory = opendir(directoryName); + if (!directory) + { + logError(__METHOD_NAME__,"Error opening directory: ", directoryName); + continue; + } - if (!directory) - { - logError(__METHOD_NAME__,"Error opening directory: ", directoryName); - continue; - } + // iterate content of directory + struct dirent *itemInDirectory = 0; + while ((itemInDirectory = readdir(directory))) + { + unsigned char entryType = itemInDirectory->d_type; + std::string entryName = itemInDirectory->d_name; + std::string fullName = *dirIter + "/" + entryName; + + bool regularFile = (entryType == DT_REG || entryType == DT_LNK); + bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); + + // Handle cases where readdir() could not determine the file type + if (entryType == DT_UNKNOWN) { + struct stat buf; + + if (stat(fullName.c_str(), &buf)) { + logInfo(__METHOD_NAME__,"Failed to stat file: ", entryName, errno); + continue; + } + + regularFile = S_ISREG(buf.st_mode); + } + + if (regularFile && sharedLibExtension) + { + logInfo(__METHOD_NAME__,"adding file: ", entryName); + std::string name(directoryName); + sharedLibraryNameList.push_back(name + "/" + entryName); + } + else + { + logInfo(__METHOD_NAME__, "plugin search ignoring file :", entryName); + } + } - // iterate content of directory - struct dirent *itemInDirectory = 0; - while ((itemInDirectory = readdir(directory))) - { - unsigned char entryType = itemInDirectory->d_type; - std::string entryName = itemInDirectory->d_name; - std::string fullName = *dirIter + "/" + entryName; - - bool regularFile = (entryType == DT_REG || entryType == DT_LNK); - bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1)); - - // Handle cases where readdir() could not determine the file type - if (entryType == DT_UNKNOWN) { - struct stat buf; - - if (stat(fullName.c_str(), &buf)) { - logInfo(__METHOD_NAME__,"Failed to stat file: ", entryName, errno); - continue; - } - - regularFile = S_ISREG(buf.st_mode); - } - - if (regularFile && sharedLibExtension) - { - logInfo(__METHOD_NAME__,"adding file: ", entryName); - std::string name(directoryName); - sharedLibraryNameList.push_back(name + "/" + entryName); - } - else - { - logInfo(__METHOD_NAME__, "plugin search ignoring file :", entryName); - } - } + closedir(directory); + } - closedir(directory); - } + // iterate all communicator plugins and start them + std::vector::iterator iter = sharedLibraryNameList.begin(); + std::vector::iterator iterEnd = sharedLibraryNameList.end(); + + for (; iter != iterEnd; ++iter) + { + logInfo(__METHOD_NAME__,"try loading: ", *iter); - // iterate all communicator plugins and start them - std::vector::iterator iter = sharedLibraryNameList.begin(); - std::vector::iterator iterEnd = sharedLibraryNameList.end(); + IAmRoutingSend* (*createFunc)(); + void* tempLibHandle = NULL; + createFunc = getCreateFunction(*iter, tempLibHandle); - for (; iter != iterEnd; ++iter) - { - logInfo(__METHOD_NAME__,"try loading: ", *iter); + if (!createFunc) + { + logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found"); + continue; + } - IAmRoutingSend* (*createFunc)(); - void* tempLibHandle = NULL; - createFunc = getCreateFunction(*iter, tempLibHandle); + IAmRoutingSend* router = createFunc(); - if (!createFunc) - { - logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found"); - continue; - } + if (!router) + { + logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable"); + dlclose(tempLibHandle); + continue; + } - IAmRoutingSend* router = createFunc(); + InterfaceNamePairs routerInterface; + routerInterface.routingInterface = router; - if (!router) - { - logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable"); - dlclose(tempLibHandle); - continue; - } + //check libversion + std::string version, cVersion(RoutingVersion); + router->getInterfaceVersion(version); + uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion; + std::istringstream(version.substr(0, 1)) >> majorVersion; + std::istringstream(version.substr(2, 1)) >> minorVersion; + std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion; + std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion; - InterfaceNamePairs routerInterface; - routerInterface.routingInterface = router; - - //check libversion - std::string version, cVersion(RoutingVersion); - router->getInterfaceVersion(version); - uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion; - std::istringstream(version.substr(0, 1)) >> majorVersion; - std::istringstream(version.substr(2, 1)) >> minorVersion; - std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion; - std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion; - - - - if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion))) - { - logError(__METHOD_NAME__,"Routing initialization failed. Version of Interface to old"); - dlclose(tempLibHandle); - continue; - } + if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion))) + { + logError(__METHOD_NAME__,"Routing initialization failed. Version of Interface to old"); + dlclose(tempLibHandle); + continue; + } - //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain.... - router->returnBusName(routerInterface.busName); - assert(!routerInterface.busName.empty()); - mListInterfaces.push_back(routerInterface); - mListLibraryHandles.push_back(tempLibHandle); - } + //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain.... + router->returnBusName(routerInterface.busName); + assert(!routerInterface.busName.empty()); + mListInterfaces.push_back(routerInterface); + mListLibraryHandles.push_back(tempLibHandle); + } + + dboNewSink = [&](const am_Sink_s& sink) { + addSinkLookup(sink); + }; + dboNewSource = [&](const am_Source_s& source) { + addSourceLookup(source); + }; + dboNewDomain = [&](const am_Domain_s& domain) { + addDomainLookup(domain); + }; + //todo: newGateway implement something + //todo: newConverter implement something + dboNewCrossfader = [&](const am_Crossfader_s& crossfader) { + addCrossfaderLookup(crossfader); + }; + dboRemovedSink = [&](const am_sinkID_t sinkID, const bool visible) { + removeSinkLookup(sinkID); + }; + dboRemovedSource = [&](const am_sourceID_t sourceID, const bool visible) { + removeSourceLookup(sourceID); + }; + dboRemoveDomain = [&](const am_domainID_t domainID) { + removeDomainLookup(domainID); + }; + //todo: removeGateway implement something + //todo: removeConverter implement something + dboRemoveCrossfader = [&](const am_crossfaderID_t crossfaderID) { + removeCrossfaderLookup(crossfaderID); + }; } CAmRoutingSender::~CAmRoutingSender() diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp index 9c09deb..27ed2b6 100644 --- a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.cpp @@ -51,7 +51,7 @@ CAmControlInterfaceTest::CAmControlInterfaceTest() : plistRoutingPluginDirs(), // pDatabaseHandler(), // pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), //RoutingReceiver - pCommandSender(plistCommandPluginDirs), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // pMockControlInterface(), // pMockRoutingInterface(), // pRoutingInterfaceBackdoor(), // @@ -59,11 +59,11 @@ CAmControlInterfaceTest::CAmControlInterfaceTest() : pControlInterfaceBackdoor(), // pControlSender(), // pRouter(&pDatabaseHandler,&pControlSender), // - pDatabaseObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler) { - pDatabaseHandler.registerObserver(&pDatabaseObserver); + pDatabaseHandler.registerObserver(&pRoutingSender); + pDatabaseHandler.registerObserver(&pCommandSender); pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockRoutingInterface, "mock"); diff --git a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h index 3e645fb..9ebcec7 100644 --- a/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h +++ b/AudioManagerCore/test/AmControlInterfaceTest/CAmControlInterfaceTest.h @@ -26,11 +26,9 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" -//#include "CAmDatabaseHandlerSQLite.h" #include "CAmDatabaseHandlerMap.h" #include "CAmControlReceiver.h" #include "CAmRoutingReceiver.h" -#include "CAmDatabaseObserver.h" #include "CAmControlSender.h" #include "CAmRoutingSender.h" #include "CAmRouter.h" @@ -65,7 +63,6 @@ public: IAmControlBackdoor pControlInterfaceBackdoor; CAmControlSender pControlSender; CAmRouter pRouter; - CAmDatabaseObserver pDatabaseObserver; CAmControlReceiver pControlReceiver; CAmRoutingReceiver pRoutingReceiver; CAmCommonFunctions pCF; diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp index 559764d..fe2f68a 100644 --- a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.cpp @@ -47,18 +47,18 @@ TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daem CAmMapBasicTest::CAmMapBasicTest() : + pDatabaseHandler(), // plistRoutingPluginDirs(), // plistCommandPluginDirs(), // - pSocketHandler(),// - pDatabaseHandler(), // + pSocketHandler(),// pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), // - pCommandSender(plistCommandPluginDirs), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // pControlSender(), // pRouter(&pDatabaseHandler, &pControlSender), // pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pCF() + pCF() { } @@ -96,7 +96,8 @@ void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConn connection.delay = -1; connection.connectionFormat = CF_GENIVI_ANALOG; connection.connectionID = 0; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); @@ -114,6 +115,9 @@ void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConn mainConnection.delay = -1; //enter mainconnection in database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); ASSERT_NE(0, mainConnectionID); @@ -135,10 +139,8 @@ void CAmMapBasicTest::createMainConnectionSetup(am_mainConnectionID_t & mainConn void CAmMapBasicTest::SetUp() { - ::testing::FLAGS_gmock_verbose = "error"; - - am_Domain_s domain; - pCF.createDomain(domain); + am_Domain_s domain; + pCF.createDomain(domain); am_domainID_t forgetDomain; am_sinkClass_t forgetSinkClassID; am_SinkClass_s sinkClass; @@ -149,6 +151,9 @@ void CAmMapBasicTest::SetUp() sourceClass.name="TestSourceClass"; sourceClass.sourceClassID=1; domain.domainID=4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,forgetDomain)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkClassDB(sinkClass,forgetSinkClassID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceClassDB(forgetSourceClassID,sourceClass)); @@ -156,16 +161,16 @@ void CAmMapBasicTest::SetUp() void CAmMapBasicTest::TearDown() { - ::testing::FLAGS_gmock_verbose = "warning"; + Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject()); } CAmMapHandlerTest::CAmMapHandlerTest() : pMockInterface(), // - pObserver(&pCommandSender,&pRoutingSender, &pSocketHandler) + mMockObserver() { - pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.registerObserver(&mMockObserver); pDatabaseHandler.setConnectionIDRange(1, TEST_MAX_CONNECTION_ID); pDatabaseHandler.setMainConnectionIDRange(1, TEST_MAX_MAINCONNECTION_ID); pDatabaseHandler.setSinkIDRange(DYNAMIC_ID_BOUNDARY, DYNAMIC_ID_BOUNDARY+TEST_MAX_SINK_ID); @@ -174,6 +179,7 @@ CAmMapHandlerTest::CAmMapHandlerTest() : CAmMapHandlerTest::~CAmMapHandlerTest() { + pDatabaseHandler.unregisterObserver(&mMockObserver); } TEST_F(CAmMapHandlerTest,getMainConnectionInfo) @@ -200,7 +206,8 @@ TEST_F(CAmMapHandlerTest,getSinkInfo) pCF.createSink(staticSink); staticSink.sinkID = 4; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(3); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) << "ERROR: database error"; ASSERT_EQ(staticSink.sinkID,staticSinkID) @@ -270,7 +277,8 @@ TEST_F(CAmMapHandlerTest,getSourceInfo) staticSource.sourceID = 4; staticSource.name = "Static"; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(3); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) << "ERROR: database error"; ASSERT_EQ(staticSource.sourceID,staticSourceID) @@ -344,7 +352,7 @@ TEST_F(CAmMapHandlerTest, peekSourceID) sourceClass.name = sourceName; sourceClass.sourceClassID = 0; sourceClass.listClassProperties.push_back(classProperty); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); //first we peek without an existing class ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); @@ -368,7 +376,7 @@ TEST_F(CAmMapHandlerTest, peekSinkID) sinkClass.name = sinkName; sinkClass.sinkClassID = 0; sinkClass.listClassProperties.push_back(classProperty); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); //first we peek without an existing class ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); @@ -392,7 +400,9 @@ TEST_F(CAmMapHandlerTest,crossfaders) pCF.createSink(sinkB); sinkB.name = "sinkB"; pCF.createSource(source); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newCrossfader(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkA,sinkAID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sinkB,sinkBID)); @@ -419,9 +429,6 @@ TEST_F(CAmMapHandlerTest,crossfaders) TEST_F(CAmMapHandlerTest,crossfadersGetFromDomain) { - - - am_Crossfader_s crossfader; am_crossfaderID_t crossfaderID; am_Sink_s sinkA, sinkB; @@ -435,6 +442,12 @@ TEST_F(CAmMapHandlerTest,crossfadersGetFromDomain) pCF.createDomain(domain); sinkB.name = "sinkB"; pCF.createSource(source); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newCrossfader(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); source.domainID = domainID; sinkA.domainID = domainID; @@ -469,7 +482,7 @@ TEST_F(CAmMapHandlerTest,sourceState) source.sourceState = SS_OFF; //prepare the test - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); //change the source state @@ -489,7 +502,7 @@ TEST_F(CAmMapHandlerTest,sourceInterruptState) source.interruptState = IS_OFF; //prepare the test - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); //change the source interrupt state @@ -509,7 +522,7 @@ TEST_F(CAmMapHandlerTest,sinkVolumeChange) sink.volume = 23; //prepare the test - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); //change the volume and check the read out @@ -527,7 +540,7 @@ TEST_F(CAmMapHandlerTest,sourceVolumeChange) source.volume = 23; //prepare test - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); //change the volume and check the read out @@ -543,9 +556,8 @@ TEST_F(CAmMapHandlerTest, peekSource) am_sourceID_t sourceID, source2ID, source3ID; am_Source_s source; pCF.createSource(source); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); //peek a source that does not exits - ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); //make sure it is not in the list @@ -591,7 +603,7 @@ TEST_F(CAmMapHandlerTest, peekSourceDouble) pCF.createSource(source); //peek a source that does not exits - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.peekSource(std::string("newsource"),sourceID)); //peek a second source that does not exits @@ -626,7 +638,7 @@ TEST_F(CAmMapHandlerTest, peekSink) pCF.createSink(sink); //peek a sink that does not exits - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); //make sure it is not in the list @@ -668,7 +680,7 @@ TEST_F(CAmMapHandlerTest, peekSinkDouble) pCF.createSink(sink); //peek a sink that does not exits - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.peekSink(std::string("newsink"),sinkID)); //peek again @@ -712,6 +724,7 @@ TEST_F(CAmMapHandlerTest,changeConnectionTimingInformationCheckMainConnection) std::vector::iterator iteratorConnectionList = connectionList.begin(); for (; iteratorConnectionList < connectionList.end(); ++iteratorConnectionList) { + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_,_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->connectionID,24)); } @@ -732,7 +745,10 @@ TEST_F(CAmMapHandlerTest,changeConnectionTimingInformation) pCF.createConnection(connection); pCF.createSink(sink); pCF.createSource(source); - + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkid)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceid)); @@ -769,7 +785,8 @@ TEST_F(CAmMapHandlerTest,getSinkClassOfSink) sinkClass.listClassProperties = classPropertyList; pCF.createSink(sink); sink.sinkClassID = 4; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); //prepare test ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); @@ -808,7 +825,9 @@ TEST_F(CAmMapHandlerTest,getSourceClassOfSource) sourceClass.listClassProperties = classPropertyList; pCF.createSource(source); source.sourceClassID=8; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); @@ -838,7 +857,7 @@ TEST_F(CAmMapHandlerTest,removeSourceClass) sourceClass.name = "test"; sourceClass.sourceClassID = 3; sourceClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); @@ -870,7 +889,7 @@ TEST_F(CAmMapHandlerTest,updateSourceClass) changedClass = sourceClass; changedClass.listClassProperties[1].value = 6; changedPropertyList = changedClass.listClassProperties; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); changedClass.sourceClassID = sourceClassID; ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); @@ -901,7 +920,7 @@ TEST_F(CAmMapHandlerTest,enterSourceClass) sourceClass.sourceClassID = 0; sourceClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); ASSERT_EQ(sourceClassList[0].name, sourceClass.name); @@ -926,7 +945,7 @@ TEST_F(CAmMapHandlerTest,enterSourceClassStatic) sourceClass.sourceClassID = 3; sourceClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSourceClasses(sourceClassList)); ASSERT_EQ(sourceClassList[0].name, sourceClass.name); @@ -950,7 +969,7 @@ TEST_F(CAmMapHandlerTest,removeSinkClass) sinkClass.name = "test"; sinkClass.sinkClassID = 0; sinkClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); @@ -982,7 +1001,7 @@ TEST_F(CAmMapHandlerTest,updateSinkClass) changedClass = sinkClass; changedClass.listClassProperties[1].value = 6; changedPropertyList = changedClass.listClassProperties; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); changedClass.sinkClassID = sinkClassID; ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); @@ -1012,7 +1031,7 @@ TEST_F(CAmMapHandlerTest,enterSinkClass) sinkClass.name = "test"; sinkClass.sinkClassID = 0; sinkClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); @@ -1038,7 +1057,7 @@ TEST_F(CAmMapHandlerTest,enterSinkClassStatic) sinkClass.sinkClassID = 4; sinkClass.listClassProperties = classPropertyList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSinkClasses(sinkClassList)); ASSERT_EQ(sinkClassList[0].name, sinkClass.name); @@ -1054,6 +1073,7 @@ TEST_F(CAmMapHandlerTest, changeSystemProperty) systemProperty.type = SYP_UNKNOWN; systemProperty.value = 33; listSystemProperties.push_back(systemProperty); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), systemPropertyChanged(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSystemProperties(listSystemProperties)); systemProperty.value = 444; ASSERT_EQ(E_OK, pDatabaseHandler.changeSystemPropertyDB(systemProperty)); @@ -1088,7 +1108,7 @@ TEST_F(CAmMapHandlerTest,enterSourcesCorrect) staticSource.sourceID = 4; staticSource.name = "Static"; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(3); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) << "ERROR: database error"; ASSERT_EQ(staticSource.sourceID,staticSourceID) @@ -1142,6 +1162,8 @@ TEST_F(CAmMapHandlerTest, changeSinkMuteState) am_sinkID_t sinkID; pCF.createSink(sink); am_MuteState_e muteState = MS_MUTED; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMuteStateChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); @@ -1159,6 +1181,8 @@ TEST_F(CAmMapHandlerTest, changeSourceMainSoundProperty) am_MainSoundProperty_s property; property.type = MSP_UNKNOWN; property.value = 33; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainSourceSoundPropertyChanged(_, _)).Times(2); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); @@ -1191,7 +1215,8 @@ TEST_F(CAmMapHandlerTest, changeSinkMainSoundProperty) property.type = MSP_UNKNOWN; property.value = 33; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainSinkSoundPropertyChanged(_, _)).Times(2); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeMainSinkSoundPropertyDB(property,sinkID)); @@ -1222,7 +1247,7 @@ TEST_F(CAmMapHandlerTest, changeSourceSoundProperty) am_SoundProperty_s property; property.type = SP_GENIVI_MID; property.value = 33; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceSoundPropertyDB(property,sourceID)); @@ -1254,7 +1279,7 @@ TEST_F(CAmMapHandlerTest, changeSinkSoundProperty) property.type = SP_GENIVI_MID; property.value = 33; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkSoundPropertyDB(property,sinkID)); @@ -1283,6 +1308,7 @@ TEST_F(CAmMapHandlerTest, peekDomain) am_domainID_t domainID; am_domainID_t domain2ID; pCF.createDomain(domain); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domainID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); ASSERT_FALSE(listDomains.empty()); @@ -1302,6 +1328,7 @@ TEST_F(CAmMapHandlerTest, peekDomainFirstEntered) am_domainID_t domain2ID; pCF.createDomain(domain); domain.name = "newdomain"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); ASSERT_EQ(E_OK, pDatabaseHandler.peekDomain(std::string("newdomain"),domain2ID)); ASSERT_EQ(domainID, domain2ID); @@ -1316,6 +1343,7 @@ TEST_F(CAmMapHandlerTest, changeDomainState) am_domainID_t domainID; pCF.createDomain(domain); am_DomainState_e newState = DS_INDEPENDENT_STARTUP; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain(_)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeDomainStateDB(newState,domainID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); @@ -1328,7 +1356,7 @@ TEST_F(CAmMapHandlerTest, changeMainConnectionState) am_MainConnection_s mainConnection; std::vector listMainConnections; createMainConnectionSetup(mainConnectionID, mainConnection); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionStateDB(1,CS_DISCONNECTING)); ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(listMainConnections)); ASSERT_EQ(CS_DISCONNECTING, listMainConnections[0].connectionState); @@ -1343,7 +1371,8 @@ TEST_F(CAmMapHandlerTest, changeSinkAvailability) am_Availability_s availability; availability.availability = A_UNKNOWN; availability.availabilityReason = AR_GENIVI_TEMPERATURE; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkAvailabilityChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkAvailabilityDB(availability,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); @@ -1361,7 +1390,8 @@ TEST_F(CAmMapHandlerTest, changeSourceAvailability) availability.availability = A_UNKNOWN; availability.availabilityReason = AR_GENIVI_TEMPERATURE; source.visible = true; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceAvailabilityChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeSourceAvailabilityDB(availability,sourceID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSources(listSources)); @@ -1376,7 +1406,7 @@ TEST_F(CAmMapHandlerTest,changeMainConnectionRoute) std::vector originalList; std::vector newList; createMainConnectionSetup(mainConnectionID, mainConnection); - + //fill the connection database am_Connection_s connection; am_Source_s source; @@ -1405,12 +1435,15 @@ TEST_F(CAmMapHandlerTest,changeMainConnectionRoute) source.name = "source" + int2string(i + 30); source.domainID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,forgetSource)); ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); listConnectionID.push_back(connectionID); } - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(originalList)); ASSERT_EQ(E_OK, pDatabaseHandler.changeMainConnectionRouteDB(mainConnectionID,listConnectionID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListMainConnections(newList)); @@ -1424,7 +1457,8 @@ TEST_F(CAmMapHandlerTest,changeMainSinkVolume) am_mainVolume_t newVol = 20; std::vector listSinks; pCF.createSink(sink); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), volumeChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.changeSinkMainVolumeDB(newVol,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListSinks(listSinks)); @@ -1438,7 +1472,7 @@ TEST_F(CAmMapHandlerTest,getMainSourceSoundProperties) pCF.createSource(source); std::vector mainSoundProperties = source.listMainSoundProperties; std::vector listMainSoundProperties; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSourceSoundProperties(sourceID,listMainSoundProperties)); ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); @@ -1451,7 +1485,7 @@ TEST_F(CAmMapHandlerTest,getMainSinkSoundProperties) pCF.createSink(sink); std::vector mainSoundProperties = sink.listMainSoundProperties; std::vector listMainSoundProperties; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListMainSinkSoundProperties(sinkID,listMainSoundProperties)); ASSERT_TRUE(std::equal(mainSoundProperties.begin(),mainSoundProperties.end(),listMainSoundProperties.begin(),equalMainSoundProperty)); @@ -1470,7 +1504,7 @@ TEST_F(CAmMapHandlerTest,getMainSources) source1.visible = false; std::vector listMainSources; std::vector listSources; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); source.sourceID = sourceID; ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source1,sourceID)); @@ -1499,7 +1533,7 @@ TEST_F(CAmMapHandlerTest,getMainSinks) sink1.visible = false; std::vector listMainSinks; std::vector listSinks; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); sink.sinkID = sinkID; ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink1,sinkID)); @@ -1521,7 +1555,7 @@ TEST_F(CAmMapHandlerTest,getVisibleMainConnections) am_mainConnectionID_t mainConnectionID; am_MainConnection_s mainConnection; createMainConnectionSetup(mainConnectionID, mainConnection); - + std::vector listVisibleMainConnections; std::vector listMainConnections; ASSERT_EQ(E_OK, pDatabaseHandler.getListVisibleMainConnections(listVisibleMainConnections)); @@ -1552,7 +1586,8 @@ TEST_F(CAmMapHandlerTest,getListSourcesOfDomain) domain.domainID=0; domain.name="dynDomain"; sourceCheckList.push_back(1); //sink.sinkID); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(2); ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) << "ERROR: database error"; @@ -1582,6 +1617,8 @@ TEST_F(CAmMapHandlerTest,getListSinksOfDomain) domain.domainID=0; domain.name="dyndomain"; sinkCheckList.push_back(1); //sink.sinkID); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(2); ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) @@ -1606,7 +1643,10 @@ TEST_F(CAmMapHandlerTest,getListGatewaysOfDomain) am_Sink_s sink; am_Source_s source; std::vector gatewayList, gatewayCheckList; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway( _)).Times(2); pCF.createDomain(domain); domain.domainID=0; domain.name="dyndomain"; @@ -1679,6 +1719,12 @@ TEST_F(CAmMapHandlerTest,getListConvertersOfDomain) pCF.createDomain(domain); domain.domainID=6; domain.name="sdfsd"; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter( _)).Times(2); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); am_sinkID_t sinkID1; @@ -1743,6 +1789,10 @@ TEST_F(CAmMapHandlerTest,removeDomain) am_domainID_t domainID; std::vector listDomains; pCF.createDomain(domain); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeDomain( _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) << "ERROR: database error"; ASSERT_EQ(E_OK,pDatabaseHandler.removeDomainDB(domainID)) @@ -1766,6 +1816,11 @@ TEST_F(CAmMapHandlerTest,removeGateway) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeGateway( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); @@ -1792,6 +1847,12 @@ TEST_F(CAmMapHandlerTest,removeConverter) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeConverter( _)).Times(1); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID)) @@ -1810,6 +1871,9 @@ TEST_F(CAmMapHandlerTest,removeSink) std::vector listSinks; pCF.createSink(sink); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(_, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)) << "ERROR: database error"; ASSERT_EQ(E_OK,pDatabaseHandler.removeSinkDB(sinkID)) @@ -1826,7 +1890,10 @@ TEST_F(CAmMapHandlerTest,removeSource) am_sourceID_t sourceID; std::vector listSources; pCF.createSource(source); - + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSource(_, _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)) << "ERROR: database error"; ASSERT_EQ(E_OK,pDatabaseHandler.removeSourceDB(sourceID)) @@ -1841,7 +1908,8 @@ TEST_F(CAmMapHandlerTest, removeMainConnection) am_mainConnectionID_t mainConnectionID; am_MainConnection_s mainConnection; createMainConnectionSetup(mainConnectionID, mainConnection); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(_)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(1); ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) << "ERROR: database error"; } @@ -1895,6 +1963,11 @@ TEST_F(CAmMapHandlerTest,registerGatewayCorrect) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway( _)).Times(3); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) @@ -1954,6 +2027,11 @@ TEST_F(CAmMapHandlerTest,registerConverterCorrect) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter( _)).Times(3); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID)) @@ -2015,6 +2093,11 @@ TEST_F(CAmMapHandlerTest,getGatewayInfo) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newGateway( _)).Times(3); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterGatewayDB(gateway,gatewayID)) @@ -2079,6 +2162,9 @@ TEST_F(CAmMapHandlerTest,getConverterInfo) pCF.createSource(source); sink.sinkID = 1; source.sourceID = 2; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter( _)).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID)) @@ -2133,8 +2219,8 @@ TEST_F(CAmMapHandlerTest,enterSinkThatAlreadyExistFail) pCF.createSink(staticSink); staticSink.sinkID = 43; staticSink.name = "Static"; - - + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) << "ERROR: database error"; ASSERT_EQ(staticSink.sinkID,staticSinkID) @@ -2156,6 +2242,7 @@ TEST_F(CAmMapHandlerTest,enterSourcesThatAlreadyExistFail) pCF.createSource(staticSource); staticSource.sourceID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(staticSource,staticSourceID)) << "ERROR: database error"; @@ -2176,6 +2263,8 @@ TEST_F(CAmMapHandlerTest,registerDomainCorrect) am_Domain_s domain; am_domainID_t domainID = 0; pCF.createDomain(domain); + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) << "ERROR: database error"; @@ -2204,6 +2293,7 @@ TEST_F(CAmMapHandlerTest,registerDomainPredefined) am_domainID_t domainID = 10; pCF.createDomain(domain); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(1); ASSERT_EQ(E_OK,pDatabaseHandler.enterDomainDB(domain,domainID)) << "ERROR: database error"; ASSERT_NE(10,domainID) @@ -2240,11 +2330,14 @@ TEST_F(CAmMapHandlerTest,registerConnectionCorrect) sink.sinkID=connection.sinkID; pCF.createSource(source); source.sourceID=connection.sourceID; + + + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(sink,sinkID)); ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(source,sourceID)); - - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID)) << "ERROR: database error"; ASSERT_NE(0,connectionID) @@ -2283,6 +2376,7 @@ TEST_F(CAmMapHandlerTest,enterSinksCorrect) pCF.createSink(staticSink); staticSink.sinkID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(3); ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(staticSink,staticSinkID)) << "ERROR: database error"; @@ -2341,6 +2435,7 @@ TEST_F(CAmMapHandlerTest,enterNotificationConfigurationCorrect) notify.status=NS_CHANGE; notify.parameter=25; testSinkData.listNotificationConfigurations.push_back(notify); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) @@ -2377,6 +2472,7 @@ TEST_F(CAmMapHandlerTest,enterMainNotificationConfigurationCorrect) notify.parameter=25; testSinkData.listMainNotificationConfigurations.push_back(notify); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) @@ -2405,8 +2501,10 @@ TEST_F(CAmMapHandlerTest,removeNotificationsSink) notify.parameter=25; testSinkData.listMainNotificationConfigurations.push_back(notify); - - //enter the sink in the database + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(_, _)).Times(1); + + //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) << "ERROR: database error"; @@ -2437,6 +2535,9 @@ TEST_F(CAmMapHandlerTest,removeNotificationsSource) testSourceData.listMainNotificationConfigurations.push_back(notify); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSource(_, _)).Times(1); + //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) << "ERROR: database error"; @@ -2475,7 +2576,7 @@ TEST_F(CAmMapHandlerTest,getMainNotificationsSink) notify1.parameter=5; testSinkData.listMainNotificationConfigurations.push_back(notify1); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) << "ERROR: database error"; @@ -2510,7 +2611,7 @@ TEST_F(CAmMapHandlerTest,getMainNotificationsSources) notify1.parameter=5; testSourceData.listMainNotificationConfigurations.push_back(notify1); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) << "ERROR: database error"; @@ -2531,7 +2632,8 @@ TEST_F(CAmMapHandlerTest,changeMainNotificationsSources) am_sourceID_t sourceID; std::vector listSources; std::vectorreturnList,returnList1; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sourceMainNotificationConfigurationChanged(_, _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceDB(testSourceData,sourceID)) << "ERROR: database error"; @@ -2572,7 +2674,8 @@ TEST_F(CAmMapHandlerTest,changeMainNotificationsSink) am_sinkID_t sinkID; std::vector listSinks; std::vectorreturnList,returnList1; - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), sinkMainNotificationConfigurationChanged(_, _)).Times(1); //enter the sink in the database ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkDB(testSinkData,sinkID)) << "ERROR: database error"; @@ -2617,7 +2720,7 @@ TEST_F(CAmMapHandlerTest, peekDomain_2) ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); ASSERT_TRUE(listDomains.size()==1); ASSERT_EQ(domainID, DYNAMIC_ID_BOUNDARY); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newDomain( _)).Times(2); domain2.name = "anotherdomain"; ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domain2ID)); ASSERT_EQ(E_OK, pDatabaseHandler.getListDomains(listDomains)); @@ -2654,6 +2757,8 @@ TEST_F(CAmMapHandlerTest, connectionIDBoundary) source.sourceID = 0; source.name = "source" + int2string(i); source.domainID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); connection.sinkID = forgetSink; @@ -2683,6 +2788,8 @@ TEST_F(CAmMapHandlerTest, connectionIDBoundary) sink.name="77"; source.sourceID=77; source.name="77"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); @@ -2713,16 +2820,18 @@ TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) source.sourceID = 0; source.name = "source" + int2string(i); source.domainID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); connection.sinkID = forgetSink; connection.sourceID = forgetSource; if( i < TEST_MAX_CONNECTION_ID ) { - ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); - ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); - ASSERT_EQ(i, connectionID); - connectionIDList.push_back(i); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection,connectionID)); + ASSERT_EQ(E_OK, pDatabaseHandler.changeConnectionFinal(connectionID)); + ASSERT_EQ(i, connectionID); + connectionIDList.push_back(i); } } std::vector connectionList; @@ -2744,9 +2853,16 @@ TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) { mainConnection.sinkID = DYNAMIC_ID_BOUNDARY + i; mainConnection.sourceID = DYNAMIC_ID_BOUNDARY + i; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); ASSERT_EQ(i, mainConnectionID); } + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_, _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedMainConnection(_)).Times(2); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(3); ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(10)); ASSERT_EQ(E_OK, pDatabaseHandler.removeMainConnectionDB(12)); ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); @@ -2757,6 +2873,11 @@ TEST_F(CAmMapHandlerTest, mainConnectionIDBoundary) sink.name="77"; source.sourceID=77; source.name="77"; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection( _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(_, _)).Times(1); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(_, _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, forgetSink)); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, forgetSource)); ASSERT_EQ(E_OK, pDatabaseHandler.enterMainConnectionDB(mainConnection,mainConnectionID)); @@ -2775,11 +2896,12 @@ TEST_F(CAmMapHandlerTest, increaseID) sink.sinkID = 0; sink.name = "sink" + int2string(i); sink.domainID = 4; + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink( _)).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); ASSERT_EQ(DYNAMIC_ID_BOUNDARY+i, sinkID); } ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); - + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removedSink(_,_)).Times(2); ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+10)); ASSERT_EQ(E_OK, pDatabaseHandler.removeSinkDB(DYNAMIC_ID_BOUNDARY+12)); @@ -2788,17 +2910,6 @@ TEST_F(CAmMapHandlerTest, increaseID) ASSERT_EQ(E_UNKNOWN, pDatabaseHandler.enterSinkDB(sink, sinkID)); } - -CAmMapHandlerObserverCallbacksTest::CAmMapHandlerObserverCallbacksTest() : - mMockObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) -{ - pDatabaseHandler.registerObserver(&mMockObserver); -} - -CAmMapHandlerObserverCallbacksTest::~CAmMapHandlerObserverCallbacksTest() -{ -} - MATCHER_P(IsDomainDataEqualTo, value, "") { auto lh = arg; return lh.domainID == value.domainID && @@ -2809,7 +2920,30 @@ MATCHER_P(IsDomainDataEqualTo, value, "") { lh.state == value.state; } -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_removeDomain) +TEST_F(CAmMapHandlerTest, dbo_addAndRemoveObservers) +{ + CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks observer1; + CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks observer2; + ASSERT_EQ(pDatabaseHandler.registerObserver(&observer1), true); + ASSERT_EQ(pDatabaseHandler.countObservers(), 2); + ASSERT_EQ(pDatabaseHandler.registerObserver(&observer2), true); + ASSERT_EQ(pDatabaseHandler.countObservers(), 3); + + pDatabaseHandler.unregisterObserver(&observer1); + ASSERT_EQ(pDatabaseHandler.countObservers(), 2); + pDatabaseHandler.unregisterObserver(&observer2); + ASSERT_EQ(pDatabaseHandler.countObservers(), 1); + pDatabaseHandler.unregisterObserver(&observer2); + ASSERT_EQ(pDatabaseHandler.countObservers(), 1); + + ASSERT_EQ(pDatabaseHandler.registerObserver(&observer2), true); + ASSERT_EQ(pDatabaseHandler.registerObserver(&observer2), false); + ASSERT_EQ(pDatabaseHandler.countObservers(), 2); + pDatabaseHandler.unregisterObserver(&observer2); + ASSERT_EQ(pDatabaseHandler.countObservers(), 1); +} + +TEST_F(CAmMapHandlerTest, dbo_peek_enter_removeDomain) { std::vector listDomains; am_Domain_s domain; @@ -2844,7 +2978,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_removeDomain) EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); } -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSource) +TEST_F(CAmMapHandlerTest, dbo_peek_enter_update_removeSource) { std::vector listSources; am_sourceID_t sourceID; @@ -2909,7 +3043,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSource) EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); } -TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSink) +TEST_F(CAmMapHandlerTest, dbo_peek_enter_update_removeSink) { std::vector listSinks; am_sinkID_t sinkID; @@ -2973,7 +3107,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peek_enter_update_removeSink) EXPECT_TRUE(Mock::VerifyAndClearExpectations(MockDatabaseObserver::getMockObserverObject())); } -TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) +TEST_F(CAmMapHandlerTest, dbo_peekSourceClassID) { std::string sourceName("myClassID"); am_sourceClass_t sourceClassID, peekID; @@ -2989,7 +3123,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); //now we enter the class into the database - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(13); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSourceClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); //first we peek without an existing class @@ -2997,7 +3131,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peekSourceClassID) ASSERT_EQ(sourceClassID, peekID); } -TEST_F(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) +TEST_F(CAmMapHandlerTest, dbo_peekSinkClassID) { std::string sinkName("myClassID"); am_sinkClass_t sinkClassID, peekID; @@ -3013,7 +3147,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); //now we enter the class into the database - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(12); + EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), numberOfSinkClassesChanged()).Times(1); ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); //first we peek without an existing class @@ -3021,7 +3155,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, peekSinkClassID) ASSERT_EQ(sinkClassID, peekID); } -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeGateway) +TEST_F(CAmMapHandlerTest, dbo_enter_removeGateway) { //initialize gateway std::vector returnList; @@ -3056,7 +3190,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeGateway) ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID2))<< "ERROR: database error"; } -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter) +TEST_F(CAmMapHandlerTest, dbo_enter_removeConverter) { //initialize gateway std::vector returnList; @@ -3091,7 +3225,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter) ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID2))<< "ERROR: database error"; } -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader) +TEST_F(CAmMapHandlerTest, dbo_enter_removeCrossfader) { am_Crossfader_s crossfader; am_crossfaderID_t crossfaderID; @@ -3125,19 +3259,11 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader) ASSERT_EQ(E_OK,pDatabaseHandler.removeCrossfaderDB(crossfaderID))<< "ERROR: database error"; } -TEST_F(CAmMapHandlerObserverCallbacksTest, enter_update_removeMainConnection) +TEST_F(CAmMapHandlerTest, dbo_enter_update_removeMainConnection) { am_mainConnectionID_t mainConnectionID; am_MainConnection_s mainConnection; - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(9); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(9); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newMainConnection(Field(&am_MainConnectionType_s::mainConnectionID, 1))).Times(1); - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), mainConnectionStateChanged(1, CS_CONNECTED)).Times(1); -#ifndef WITH_DATABASE_CHANGE_CHECK - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(1); -#else - EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), timingInformationChanged(1, _)).Times(0); -#endif + createMainConnectionSetup(mainConnectionID, mainConnection); //change delay of first connection @@ -3161,7 +3287,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, enter_update_removeMainConnection) ASSERT_EQ(E_OK,pDatabaseHandler.removeMainConnectionDB(mainConnectionID)) << "ERROR: database error"; } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkAvailability) +TEST_F(CAmMapHandlerTest, dbo_changeSinkAvailability) { std::vector listSinks; am_Sink_s sink; @@ -3187,7 +3313,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkAvailability) #endif } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeSourceAvailability) +TEST_F(CAmMapHandlerTest, dbo_changeSourceAvailability) { std::vector listSources; am_Source_s source; @@ -3214,7 +3340,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, changeSourceAvailability) #endif } -TEST_F(CAmMapHandlerObserverCallbacksTest,changeMainSinkVolume) +TEST_F(CAmMapHandlerTest, dbo_changeMainSinkVolume) { am_Sink_s sink; am_sinkID_t sinkID; @@ -3236,7 +3362,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest,changeMainSinkVolume) #endif } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkMuteState) +TEST_F(CAmMapHandlerTest, dbo_changeSinkMuteState) { std::vector listSinks; am_Sink_s sink; @@ -3258,7 +3384,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, changeSinkMuteState) #endif } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeSystemProperty) +TEST_F(CAmMapHandlerTest, dbo_changeSystemProperty) { std::vector listSystemProperties, listReturn; am_SystemProperty_s systemProperty; @@ -3282,7 +3408,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, changeSystemProperty) #endif } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSink) +TEST_F(CAmMapHandlerTest, dbo_changeMainNotificationsSink) { am_Sink_s testSinkData; pCF.createSink(testSinkData); @@ -3329,7 +3455,7 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSink) ASSERT_EQ(E_OK,pDatabaseHandler.changeMainSinkNotificationConfigurationDB(sinkID,notify2)); } -TEST_F(CAmMapHandlerObserverCallbacksTest, changeMainNotificationsSources) +TEST_F(CAmMapHandlerTest, dbo_changeMainNotificationsSources) { am_Source_s testSourceData; diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h index e3cc0ef..32add3d 100644 --- a/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmMapHandlerTest.h @@ -33,16 +33,17 @@ #include "CAmDatabaseHandlerMap.h" #include "CAmControlReceiver.h" #include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" +#include "CAmTestDatabaseObserver.h" #include "CAmRoutingSender.h" #include "CAmRouter.h" #include "CAmControlSender.h" +#include "MockDatabaseObserver.h" #include "../IAmControlBackdoor.h" #include "../IAmCommandBackdoor.h" #include "../CAmCommonFunctions.h" #include "../MockIAmControlSend.h" #include "../MockIAmCommandSend.h" -#include "MockDatabaseObserver.h" + namespace am { @@ -50,15 +51,15 @@ namespace am class CAmMapBasicTest : public ::testing::Test { public: - CAmMapBasicTest(); + CAmMapBasicTest(); ~CAmMapBasicTest(); + CAmSocketHandler pSocketHandler; std::vector plistRoutingPluginDirs; std::vector plistCommandPluginDirs; CAmRoutingSender pRoutingSender; CAmCommandSender pCommandSender; IAmRoutingBackdoor pRoutingInterfaceBackdoor; IAmCommandBackdoor pCommandInterfaceBackdoor; - CAmSocketHandler pSocketHandler; CAmDatabaseHandlerMap pDatabaseHandler; CAmControlSender pControlSender; CAmRouter pRouter; @@ -75,18 +76,9 @@ public: CAmMapHandlerTest(); ~CAmMapHandlerTest(); MockIAmCommandSend pMockInterface; - CAmDatabaseObserver pObserver; + CAmDatabaseObserver mMockObserver; }; -class CAmMapHandlerObserverCallbacksTest : public CAmMapBasicTest -{ -public: - CAmMapHandlerObserverCallbacksTest(); - ~CAmMapHandlerObserverCallbacksTest(); - CAmDatabaseObserver mMockObserver; -}; - - } #endif /* MAPHANDLERTEST_H_ */ diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp index a035cee..ddf0abb 100644 --- a/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp @@ -21,78 +21,75 @@ * */ -#include "CAmDatabaseObserver.h" +#include "CAmTestDatabaseObserver.h" #include "MockDatabaseObserver.h" namespace am { -CAmDatabaseObserver::CAmDatabaseObserver(CAmCommandSender *iCommandSender, CAmRoutingSender *iRoutingSender, CAmSocketHandler *iSocketHandler) : -mCommandSender(iCommandSender), // -mRoutingSender(iRoutingSender), // -mTelnetServer(NULL), // -mSerializer(iSocketHandler) // -{} +CAmDatabaseObserver::CAmDatabaseObserver() +{ + dboNumberOfSinkClassesChanged = [&]() + { MockDatabaseObserver::getMockObserverObject()->numberOfSinkClassesChanged(); }; + dboNumberOfSourceClassesChanged = [&]() + { MockDatabaseObserver::getMockObserverObject()->numberOfSourceClassesChanged(); }; + dboNewSink = [&](const am_Sink_s& sink) + { MockDatabaseObserver::getMockObserverObject()->newSink(sink); }; + dboNewSource = [&](const am_Source_s& source) + { MockDatabaseObserver::getMockObserverObject()->newSource(source); }; + dboNewDomain = [&](const am_Domain_s& domain) + { MockDatabaseObserver::getMockObserverObject()->newDomain(domain); }; + dboNewGateway = [&](const am_Gateway_s& gateway) + { MockDatabaseObserver::getMockObserverObject()->newGateway(gateway); }; + dboNewConverter = [&](const am_Converter_s& coverter) + { MockDatabaseObserver::getMockObserverObject()->newConverter(coverter); }; + dboNewCrossfader = [&](const am_Crossfader_s& crossfader) + { MockDatabaseObserver::getMockObserverObject()->newCrossfader(crossfader); }; + dboNewMainConnection = [&](const am_MainConnectionType_s& mainConnection) + { MockDatabaseObserver::getMockObserverObject()->newMainConnection(mainConnection); }; + dboRemovedMainConnection = [&](const am_mainConnectionID_t mainConnection) + { MockDatabaseObserver::getMockObserverObject()->removedMainConnection(mainConnection); }; + dboRemovedSink = [&](const am_sinkID_t sinkID, const bool visible) + { MockDatabaseObserver::getMockObserverObject()->removedSink(sinkID, visible); }; + dboRemovedSource = [&](const am_sourceID_t sourceID, const bool visible) + { MockDatabaseObserver::getMockObserverObject()->removedSource(sourceID, visible); }; + dboRemoveDomain = [&](const am_domainID_t domainID) + { MockDatabaseObserver::getMockObserverObject()->removeDomain(domainID); }; + dboRemoveGateway = [&](const am_gatewayID_t gatewayID) + { MockDatabaseObserver::getMockObserverObject()->removeGateway(gatewayID); }; + dboRemoveConverter = [&](const am_converterID_t converterID) + { MockDatabaseObserver::getMockObserverObject()->removeConverter(converterID); }; + dboRemoveCrossfader = [&](const am_crossfaderID_t crossfaderID) + { MockDatabaseObserver::getMockObserverObject()->removeCrossfader(crossfaderID); }; + dboMainConnectionStateChanged = [&](const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) + { MockDatabaseObserver::getMockObserverObject()->mainConnectionStateChanged(connectionID, connectionState); }; + dboMainSinkSoundPropertyChanged = [&](const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) + { MockDatabaseObserver::getMockObserverObject()->mainSinkSoundPropertyChanged(sinkID, SoundProperty); }; + dboMainSourceSoundPropertyChanged = [&](const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) + { MockDatabaseObserver::getMockObserverObject()->mainSourceSoundPropertyChanged(sourceID, SoundProperty); }; + dboSinkAvailabilityChanged = [&](const am_sinkID_t sinkID, const am_Availability_s& availability) + { MockDatabaseObserver::getMockObserverObject()->sinkAvailabilityChanged(sinkID, availability); }; + dboSourceAvailabilityChanged = [&](const am_sourceID_t sourceID, const am_Availability_s& availability) + { MockDatabaseObserver::getMockObserverObject()->sourceAvailabilityChanged(sourceID, availability); }; + dboVolumeChanged = [&](const am_sinkID_t sinkID, const am_mainVolume_t volume) + { MockDatabaseObserver::getMockObserverObject()->volumeChanged(sinkID, volume); }; + dboSinkMuteStateChanged = [&](const am_sinkID_t sinkID, const am_MuteState_e muteState) + { MockDatabaseObserver::getMockObserverObject()->sinkMuteStateChanged(sinkID, muteState); }; + dboSystemPropertyChanged = [&](const am_SystemProperty_s& SystemProperty) + { MockDatabaseObserver::getMockObserverObject()->systemPropertyChanged(SystemProperty); }; + dboTimingInformationChanged = [&](const am_mainConnectionID_t mainConnection, const am_timeSync_t time) + { MockDatabaseObserver::getMockObserverObject()->timingInformationChanged(mainConnection,time); }; + dboSinkUpdated = [&](const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) + { MockDatabaseObserver::getMockObserverObject()->sinkUpdated(sinkID,sinkClassID,listMainSoundProperties, visible); }; + dboSourceUpdated = [&](const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) + { MockDatabaseObserver::getMockObserverObject()->sourceUpdated(sourceID,sourceClassID,listMainSoundProperties, visible); }; + dboSinkMainNotificationConfigurationChanged = [&](const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) + { MockDatabaseObserver::getMockObserverObject()->sinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration); }; + dboSourceMainNotificationConfigurationChanged = [&](const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) + { MockDatabaseObserver::getMockObserverObject()->sourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration); }; -CAmDatabaseObserver::~CAmDatabaseObserver() {} +} +CAmDatabaseObserver::~CAmDatabaseObserver() {} -void CAmDatabaseObserver::numberOfSinkClassesChanged() -{ MockDatabaseObserver::getMockObserverObject()->numberOfSinkClassesChanged(); } -void CAmDatabaseObserver::numberOfSourceClassesChanged() -{ MockDatabaseObserver::getMockObserverObject()->numberOfSourceClassesChanged(); } -void CAmDatabaseObserver::newSink(const am_Sink_s& sink) -{ MockDatabaseObserver::getMockObserverObject()->newSink(sink); } -void CAmDatabaseObserver::newSource(const am_Source_s& source) -{ MockDatabaseObserver::getMockObserverObject()->newSource(source); } -void CAmDatabaseObserver::newDomain(const am_Domain_s& domain) -{ MockDatabaseObserver::getMockObserverObject()->newDomain(domain); } -void CAmDatabaseObserver::newGateway(const am_Gateway_s& gateway) -{ MockDatabaseObserver::getMockObserverObject()->newGateway(gateway); } -void CAmDatabaseObserver::newConverter(const am_Converter_s& coverter) -{ MockDatabaseObserver::getMockObserverObject()->newConverter(coverter); } -void CAmDatabaseObserver::newCrossfader(const am_Crossfader_s& crossfader) -{ MockDatabaseObserver::getMockObserverObject()->newCrossfader(crossfader); } -void CAmDatabaseObserver::newMainConnection(const am_MainConnectionType_s& mainConnection) -{ MockDatabaseObserver::getMockObserverObject()->newMainConnection(mainConnection); } -void CAmDatabaseObserver::removedMainConnection(const am_mainConnectionID_t mainConnection) -{ MockDatabaseObserver::getMockObserverObject()->removedMainConnection(mainConnection); } -void CAmDatabaseObserver::removedSink(const am_sinkID_t sinkID, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->removedSink(sinkID, visible); } -void CAmDatabaseObserver::removedSource(const am_sourceID_t sourceID, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->removedSource(sourceID, visible); } -void CAmDatabaseObserver::removeDomain(const am_domainID_t domainID) -{ MockDatabaseObserver::getMockObserverObject()->removeDomain(domainID); } -void CAmDatabaseObserver::removeGateway(const am_gatewayID_t gatewayID) -{ MockDatabaseObserver::getMockObserverObject()->removeGateway(gatewayID); } -void CAmDatabaseObserver::removeConverter(const am_converterID_t converterID) -{ MockDatabaseObserver::getMockObserverObject()->removeConverter(converterID); } -void CAmDatabaseObserver::removeCrossfader(const am_crossfaderID_t crossfaderID) -{ MockDatabaseObserver::getMockObserverObject()->removeCrossfader(crossfaderID); } -void CAmDatabaseObserver::mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) -{ MockDatabaseObserver::getMockObserverObject()->mainConnectionStateChanged(connectionID, connectionState); } -void CAmDatabaseObserver::mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) -{ MockDatabaseObserver::getMockObserverObject()->mainSinkSoundPropertyChanged(sinkID, SoundProperty); } -void CAmDatabaseObserver::mainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s& SoundProperty) -{ MockDatabaseObserver::getMockObserverObject()->mainSourceSoundPropertyChanged(sourceID, SoundProperty); } -void CAmDatabaseObserver::sinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s& availability) -{ MockDatabaseObserver::getMockObserverObject()->sinkAvailabilityChanged(sinkID, availability); } -void CAmDatabaseObserver::sourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s& availability) -{ MockDatabaseObserver::getMockObserverObject()->sourceAvailabilityChanged(sourceID, availability); } -void CAmDatabaseObserver::volumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume) -{ MockDatabaseObserver::getMockObserverObject()->volumeChanged(sinkID, volume); } -void CAmDatabaseObserver::sinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState) -{ MockDatabaseObserver::getMockObserverObject()->sinkMuteStateChanged(sinkID, muteState); } -void CAmDatabaseObserver::systemPropertyChanged(const am_SystemProperty_s& SystemProperty) -{ MockDatabaseObserver::getMockObserverObject()->systemPropertyChanged(SystemProperty); } -void CAmDatabaseObserver::timingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time) -{ MockDatabaseObserver::getMockObserverObject()->timingInformationChanged(mainConnection,time); } -void CAmDatabaseObserver::sinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector& listMainSoundProperties, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->sinkUpdated(sinkID,sinkClassID,listMainSoundProperties, visible); } -void CAmDatabaseObserver::sourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector& listMainSoundProperties, const bool visible) -{ MockDatabaseObserver::getMockObserverObject()->sourceUpdated(sourceID,sourceClassID,listMainSoundProperties, visible); } -void CAmDatabaseObserver::sinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ MockDatabaseObserver::getMockObserverObject()->sinkMainNotificationConfigurationChanged(sinkID,mainNotificationConfiguration); } -void CAmDatabaseObserver::sourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) -{ MockDatabaseObserver::getMockObserverObject()->sourceMainNotificationConfigurationChanged(sourceID,mainNotificationConfiguration); } } diff --git a/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.h b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.h new file mode 100644 index 0000000..12ba32e --- /dev/null +++ b/AudioManagerCore/test/AmMapHandlerTest/CAmTestDatabaseObserver.h @@ -0,0 +1,53 @@ +/** + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * + * \file CAmDatabaseObserver.h + * For further information see http://www.genivi.org/. + * + */ + +#ifndef DATABASEOBSERVER_H_ +#define DATABASEOBSERVER_H_ + +#include "audiomanagertypes.h" +#include +#include +#include +#include "CAmDatabaseHandlerMap.h" + + +namespace am +{ + + +/** + * This class observes the Database and notifies other classes about important events, mainly the CommandSender. + */ + +class CAmDatabaseObserver: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks +{ +public: + explicit CAmDatabaseObserver(); + ~CAmDatabaseObserver(); + +private: +}; + +} + +#endif /* DATABASEOBSERVER_H_ */ diff --git a/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h index da1b3b4..82e1ea4 100644 --- a/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h +++ b/AudioManagerCore/test/AmMapHandlerTest/MockDatabaseObserver.h @@ -27,7 +27,7 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" -#include "CAmDatabaseObserver.h" +#include "CAmTestDatabaseObserver.h" class CAmCommandSender; class CAmRoutingSender; diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp index d656373..fbba011 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -41,16 +41,16 @@ CAmRouterMapTest::CAmRouterMapTest() : pDatabaseHandler(), pRouter(&pDatabaseHandler, &pControlSender), // pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), // - pCommandSender(plistCommandPluginDirs), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // pMockInterface(), // pMockControlInterface(), // pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // pControlInterfaceBackdoor(), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // - pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter) { - pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.registerObserver(&pRoutingSender); + pDatabaseHandler.registerObserver(&pCommandSender); pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); } diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h index a3cead1..879f47c 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -34,7 +34,6 @@ #include "CAmDatabaseHandlerMap.h" #include "CAmControlReceiver.h" #include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" #include "CAmRoutingSender.h" #include "CAmRouter.h" #include "CAmSocketHandler.h" @@ -67,7 +66,6 @@ public: IAmCommandBackdoor pCommandInterfaceBackdoor; IAmControlBackdoor pControlInterfaceBackdoor; CAmControlReceiver pControlReceiver; - CAmDatabaseObserver pObserver; CAmCommonFunctions pCF; void SetUp(); void TearDown(); diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp index b4ab247..ea1f452 100644 --- a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.cpp @@ -38,16 +38,16 @@ CAmRouterTest::CAmRouterTest() : pDatabaseHandler(), pRouter(&pDatabaseHandler, &pControlSender), // pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), // - pCommandSender(plistCommandPluginDirs), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // pMockInterface(), // pMockControlInterface(), // pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // pControlInterfaceBackdoor(), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter), // - pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler) + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter) { - pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.registerObserver(&pRoutingSender); + pDatabaseHandler.registerObserver(&pCommandSender); pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); } diff --git a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h index 4a4e35b..ad3ed68 100644 --- a/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h +++ b/AudioManagerCore/test/AmRouterTest/CAmRouterTest.h @@ -35,7 +35,6 @@ #include "CAmDatabaseHandlerMap.h" #include "CAmControlReceiver.h" #include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" #include "CAmRoutingSender.h" #include "CAmRouter.h" #include "CAmSocketHandler.h" @@ -68,7 +67,6 @@ public: IAmCommandBackdoor pCommandInterfaceBackdoor; IAmControlBackdoor pControlInterfaceBackdoor; CAmControlReceiver pControlReceiver; - CAmDatabaseObserver pObserver; CAmCommonFunctions pCF; void SetUp(); void TearDown(); diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp index 2a166cf..2cd2b55 100644 --- a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -35,17 +35,17 @@ CAmRoutingInterfaceTest::CAmRoutingInterfaceTest() : pSocketHandler(), // pDatabaseHandler(), // pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), // - pCommandSender(plistCommandPluginDirs), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // pControlSender(), // pRouter(&pDatabaseHandler, &pControlSender), // pMockInterface(), // pRoutingInterfaceBackdoor(), // pCommandInterfaceBackdoor(), // pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter), // - pObserver(&pCommandSender, &pRoutingSender, &pSocketHandler), // pRoutingReceiver(&pDatabaseHandler, &pRoutingSender, &pControlSender, &pSocketHandler) { - pDatabaseHandler.registerObserver(&pObserver); + pDatabaseHandler.registerObserver(&pRoutingSender); + pDatabaseHandler.registerObserver(&pCommandSender); pRoutingInterfaceBackdoor.unloadPlugins(&pRoutingSender); pRoutingInterfaceBackdoor.injectInterface(&pRoutingSender, &pMockInterface, "mock"); pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h index 6233c17..78497ca 100644 --- a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.h @@ -33,7 +33,6 @@ #include "CAmControlReceiver.h" #include "CAmRoutingReceiver.h" #include "CAmControlSender.h" -#include "CAmDatabaseObserver.h" #include "CAmRouter.h" #include "../IAmRoutingBackdoor.h" #include "../IAmCommandBackdoor.h" @@ -66,7 +65,6 @@ public: IAmCommandBackdoor pCommandInterfaceBackdoor; IAmControlBackdoor pControlInterfaceBackdoor; CAmControlReceiver pControlReceiver; - CAmDatabaseObserver pObserver; CAmCommonFunctions pCF; void SetUp(); void TearDown(); diff --git a/AudioManagerCore/test/CMakeLists.txt b/AudioManagerCore/test/CMakeLists.txt index 47658b4..4459e14 100644 --- a/AudioManagerCore/test/CMakeLists.txt +++ b/AudioManagerCore/test/CMakeLists.txt @@ -21,7 +21,7 @@ cmake_minimum_required(VERSION 3.0) set(EXECUTABLE_OUTPUT_PATH ${TEST_EXECUTABLE_OUTPUT_PATH}) #make aunt google stop complaining -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager -Wno-unused-local-typedefs -lz -ldl") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST=1 -DDLT_CONTEXT=AudioManager -Wno-unused-local-typedefs -lz -ldl -g -O0") add_subdirectory (AmControlInterfaceTest) add_subdirectory (AmMapHandlerTest) diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index 6f5c273..26d7cea 100755 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -55,7 +55,6 @@ #include "CAmRoutingReceiver.h" #include "CAmCommandReceiver.h" #include "CAmControlReceiver.h" -#include "CAmDatabaseObserver.h" #include "CAmDltWrapper.h" #include "CAmSocketHandler.h" #include "CAmCommandLineSingleton.h" @@ -284,10 +283,10 @@ void mainProgram(int argc, char *argv[]) //later when the plugins are started, the commandline is already parsed and the objects defined before can be used to get the neccesary information CAmDatabaseHandlerMap iDatabaseHandler; - IAmDatabaseHandler *pDatabaseHandler = dynamic_cast( &iDatabaseHandler ); + IAmDatabaseHandler *pDatabaseHandler = dynamic_cast( &iDatabaseHandler ); CAmRoutingSender iRoutingSender(listRoutingPluginDirs,pDatabaseHandler); - CAmCommandSender iCommandSender(listCommandPluginDirs); + CAmCommandSender iCommandSender(listCommandPluginDirs, &iSocketHandler); CAmControlSender iControlSender(controllerPlugin.getValue(),&iSocketHandler); try @@ -332,11 +331,10 @@ CAmRouter iRouter(pDatabaseHandler, &iControlSender); #endif /*WITH_DBUS_WRAPPER*/ CAmControlReceiver iControlReceiver(pDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler, &iRouter); -CAmDatabaseObserver iObserver(&iCommandSender,&iRoutingSender, &iSocketHandler); - - -iDatabaseHandler.registerObserver(&iObserver); +iDatabaseHandler.registerObserver(&iRoutingSender); +iDatabaseHandler.registerObserver(&iCommandSender); +iDatabaseHandler.registerObserver(&iRouter); //startup all the Plugins and Interfaces //at this point, commandline arguments can be parsed iControlSender.startupController(&iControlReceiver); -- cgit v1.2.1 From 9ad6f67f6c39ec4ff49c382d5beaf9006f664fcb Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Wed, 15 Feb 2017 01:47:24 -0800 Subject: handle overflow of handles correctly Signed-off-by: Christian Linke --- AudioManagerCore/src/CAmRoutingSender.cpp | 33 ++++++-- .../CAmRoutingInterfaceTest.cpp | 97 ++++++++++++++++++++++ 2 files changed, 121 insertions(+), 9 deletions(-) diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp index 0e25e68..9cc013d 100644 --- a/AudioManagerCore/src/CAmRoutingSender.cpp +++ b/AudioManagerCore/src/CAmRoutingSender.cpp @@ -813,17 +813,32 @@ am_Error_e CAmRoutingSender::getListHandles(std::vector & listHandl am_Handle_s CAmRoutingSender::createHandle(std::shared_ptr handleData, const am_Handle_e type) { am_Handle_s handle; - if (++mHandleCount>=1024) //defined by 10 bit (out if structure!) - mHandleCount=1; - handle.handle = mHandleCount; handle.handleType = type; - mlistActiveHandles.insert(std::make_pair(handle, handleData)); - if ((mlistActiveHandles.size()%100) == 0) - { - logInfo("CAmRoutingSender::createHandle warning: too many open handles, number of handles: ", mlistActiveHandles.size()); + + for (int checkOverflow=0;checkOverflow<1024;checkOverflow++) + { + if (++mHandleCount>=1024) //defined by 10 bit (out if structure!) + { + mHandleCount=1; + } + handle.handle = mHandleCount; + + if ( mlistActiveHandles.find(handle) == mlistActiveHandles.end() ) + { + mlistActiveHandles.insert(std::make_pair(handle, handleData)); + if (mlistActiveHandles.size()>100) + { + logWarning(__METHOD_NAME__,"too many open handles, number of handles: ", mlistActiveHandles.size()); + } + logInfo(__METHOD_NAME__,handle.handle, handle.handleType); + return (handle); + } } - logInfo(__METHOD_NAME__,handle.handle, handle.handleType); - return (handle); + + logError(__METHOD_NAME__,"could not create new handle, all handles in use!"); + handle.handle=0; + + return(handle); } void CAmRoutingSender::setRoutingReady() diff --git a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp index 2cd2b55..3a576e6 100644 --- a/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp +++ b/AudioManagerCore/test/AmRoutingInterfaceTest/CAmRoutingInterfaceTest.cpp @@ -546,6 +546,103 @@ TEST_F(CAmRoutingInterfaceTest,nothingTodisconnect) ASSERT_TRUE(listHandles.empty()); } +TEST_F(CAmRoutingInterfaceTest,handleOverflow) +{ + am_Handle_s handle,handleOverflow1,handleOverflow2,handleOverflowCheck1,handleOverflowCheck2; + am_sinkID_t sinkID; + am_Sink_s sink; + am_Domain_s domain; + am_domainID_t domainID; + + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_GENIVI_TREBLE; + soundProperty.value = 23; + + sink.listSoundProperties.push_back(soundProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + + + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillRepeatedly(Return(E_OK)); + + //open handles till 50 + for(int i=0;i<50;i++) + { + handle.handle=0; + soundProperty.value = i; + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); + } + //now we ack 2 handles + EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handleOverflow1,sinkID,soundProperty)); + pRoutingReceiver.ackSetSinkSoundProperty(handleOverflow1,E_OK); + + EXPECT_CALL(pMockControlInterface,cbAckSetSinkSoundProperty(_,E_OK)); + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handleOverflow2,sinkID,soundProperty)); + pRoutingReceiver.ackSetSinkSoundProperty(handleOverflow2,E_OK); + + for(int i=52;i<1023;i++) //now we get into the overflow areay + { + handle.handle=0; + soundProperty.value = i; + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); + } + + //the next two handles must be the one we already acked + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handleOverflowCheck1,sinkID,soundProperty)); + ASSERT_EQ(handleOverflow1.handle,handleOverflowCheck1.handle); + + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handleOverflowCheck2,sinkID,soundProperty)); + ASSERT_EQ(handleOverflow2.handle,handleOverflowCheck2.handle); + +} + +TEST_F(CAmRoutingInterfaceTest,handleOverflowAbsolute) +{ + am_Handle_s handle,handleOverflow1,handleOverflow2,handleOverflowCheck1,handleOverflowCheck2; + am_sinkID_t sinkID; + am_Sink_s sink; + am_Domain_s domain; + am_domainID_t domainID; + + pCF.createSink(sink); + pCF.createDomain(domain); + domain.name = "mock"; + domain.busname = "mock"; + sink.sinkID = 2; + sink.domainID = DYNAMIC_ID_BOUNDARY; + am_SoundProperty_s soundProperty; + soundProperty.type = SP_GENIVI_TREBLE; + soundProperty.value = 23; + + sink.listSoundProperties.push_back(soundProperty); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + + + + EXPECT_CALL(pMockInterface,asyncSetSinkSoundProperty(_,sinkID,_)).WillRepeatedly(Return(E_OK)); + + + for(int i=0;i<1023;i++) //we fill up the handles + { + handle.handle=0; + soundProperty.value = i; + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handle,sinkID,soundProperty)); + } + + //the next handle must return 0! + ASSERT_EQ(E_OK, pControlReceiver.setSinkSoundProperty(handleOverflowCheck1,sinkID,soundProperty)); + ASSERT_EQ(handleOverflowCheck1.handle,0); +} + int main(int argc, char **argv) -- cgit v1.2.1 From ff7a091bd6500413853f381d14be55de2e3affa3 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Mon, 13 Feb 2017 18:20:26 +0100 Subject: * if needed the routing graph will be re-created from getRoute after a database change has been observed. Signed-off-by: Christian Linke --- AudioManagerCore/include/CAmGraph.h | 32 +- AudioManagerCore/include/CAmRouter.h | 631 ++-- AudioManagerCore/src/CAmRouter.cpp | 1772 +++++------ .../test/AmRouterMapTest/CAmRouterMapTest.cpp | 3078 ++++++++++---------- .../test/AmRouterMapTest/CAmRouterMapTest.h | 93 +- 5 files changed, 2846 insertions(+), 2760 deletions(-) diff --git a/AudioManagerCore/include/CAmGraph.h b/AudioManagerCore/include/CAmGraph.h index a27d512..45043f7 100644 --- a/AudioManagerCore/include/CAmGraph.h +++ b/AudioManagerCore/include/CAmGraph.h @@ -409,12 +409,12 @@ namespace am */ CAmNode & addNode(const T & in) { - size_t index = mStoreNodes.size(); - mStoreNodes.emplace_back(in, index); - mStoreAdjList.emplace_back(); - mPointersNodes.push_back(&mStoreNodes.back()); - mPointersAdjList.push_back(&mStoreAdjList.back()); - return mStoreNodes.back(); + size_t index = mStoreNodes.size(); + mStoreNodes.emplace_back(in, index); + mStoreAdjList.emplace_back(); + mPointersNodes.push_back(&mStoreNodes.back()); + mPointersAdjList.push_back(&mStoreAdjList.back()); + return mStoreNodes.back(); } /** @@ -463,16 +463,16 @@ namespace am */ void removeNode(const CAmNode & node) { - uint16_t index = node.getIndex(); - removeAllVerticesToNode(node); - mPointersAdjList.erase(mPointersAdjList.begin()+index); - mPointersNodes.erase(mPointersNodes.begin()+index); - auto iter = std::find_if(mStoreNodes.begin(), mStoreNodes.end(), [&node](const CAmNode & otherNode){ - return &otherNode==&node; - }); - if(iter!=mStoreNodes.end()) - mStoreNodes.erase(iter); - updateIndexes(index); + uint16_t index = node.getIndex(); + removeAllVerticesToNode(node); + mPointersAdjList.erase(mPointersAdjList.begin()+index); + mPointersNodes.erase(mPointersNodes.begin()+index); + auto iter = std::find_if(mStoreNodes.begin(), mStoreNodes.end(), [&node](const CAmNode & otherNode){ + return &otherNode==&node; + }); + if(iter!=mStoreNodes.end()) + mStoreNodes.erase(iter); + updateIndexes(index); } /** diff --git a/AudioManagerCore/include/CAmRouter.h b/AudioManagerCore/include/CAmRouter.h index 7543abc..88f73ea 100644 --- a/AudioManagerCore/include/CAmRouter.h +++ b/AudioManagerCore/include/CAmRouter.h @@ -33,334 +33,347 @@ #include "CAmGraph.h" #include "CAmDatabaseHandlerMap.h" - namespace am { -/** - * Optimal path search is implemented with graph which contains nodes - sinks, sources, gateways, converters. - * The nodes are identified by sinkID, sourceID, gatewayID, converterID. - * A possible connection between two nodes represents the facts that the nodes can be connected with one or more connectionFormats (Node[id=1] ---> Node[id=2]). - * It is assumption that the two nodes can be connected. The controller itself decides later whether the connection is possible or not. - * - */ - -/** - * Trace on/off. - */ + /** + * Optimal path search is implemented with graph which contains nodes - sinks, sources, gateways, converters. + * The nodes are identified by sinkID, sourceID, gatewayID, converterID. + * A possible connection between two nodes represents the facts that the nodes can be connected with one or more connectionFormats (Node[id=1] ---> Node[id=2]). + * It is assumption that the two nodes can be connected. The controller itself decides later whether the connection is possible or not. + * + */ + + /** + * Trace on/off. + */ #undef TRACE_GRAPH -/** - * Max paths count returned to the controller - */ + /** + * Max paths count returned to the controller + */ #ifndef MAX_ROUTING_PATHS #define MAX_ROUTING_PATHS 5 #endif -/** - * How many times the routing algorithm should look back into domains. - * - * 0 - no cycles are allowed - * 1 - default is one cycle - * ... - * UINT_MAX - set this define to UINT_MAX in order to allow cycles. - * - */ + /** + * How many times the routing algorithm should look back into domains. + * + * 0 - no cycles are allowed + * 1 - default is one cycle + * ... + * UINT_MAX - set this define to UINT_MAX in order to allow cycles. + * + */ #ifndef MAX_ALLOWED_DOMAIN_CYCLES #define MAX_ALLOWED_DOMAIN_CYCLES 1 #endif -class CAmRouter; - -/** - * A structure used as user data in the graph nodes. - */ -struct am_RoutingNodeData_s -{ - typedef enum:uint8_t {SINK, SOURCE, GATEWAY, CONVERTER} am_NodeDataType_e; - am_NodeDataType_e type; //!< data type:sink, source, gateway or converter - union - { - am_Source_s *source; - am_Sink_s *sink; - am_Gateway_s *gateway; - am_Converter_s *converter; - } data; //!< union pointer to sink, source, gateway or converter - - am_RoutingNodeData_s():type(SINK) - {} - - bool operator==(const am_RoutingNodeData_s & anotherObject) const - { - bool result = false; - if(type==anotherObject.type) - { - result = true; - if(type==SINK) - result &= (data.sink->sinkID==anotherObject.data.sink->sinkID); - else if(type==SOURCE) - result &= (data.source->sourceID==anotherObject.data.source->sourceID); - else if(type==GATEWAY) - result &= (data.gateway->gatewayID==anotherObject.data.gateway->gatewayID); - else if(type==CONVERTER) - result &= (data.converter->converterID==anotherObject.data.converter->converterID); - } - return result; - }; + class CAmRouter; + + /** + * A structure used as user data in the graph nodes. + */ + struct am_RoutingNodeData_s + { + typedef enum + :int + { SINK, SOURCE, GATEWAY, CONVERTER + } am_NodeDataType_e; + am_NodeDataType_e type; //!< data type:sink, source, gateway or converter + union + { + am_Source_s *source; + am_Sink_s *sink; + am_Gateway_s *gateway; + am_Converter_s *converter; + } data; //!< union pointer to sink, source, gateway or converter + + am_RoutingNodeData_s() : + type(SINK) + { + } + + bool operator==(const am_RoutingNodeData_s & anotherObject) const + { + bool result = false; + if (type == anotherObject.type) + { + result = true; + if (type == SINK) + result &= (data.sink->sinkID == anotherObject.data.sink->sinkID); + else if (type == SOURCE) + result &= (data.source->sourceID == anotherObject.data.source->sourceID); + else if (type == GATEWAY) + result &= (data.gateway->gatewayID == anotherObject.data.gateway->gatewayID); + else if (type == CONVERTER) + result &= (data.converter->converterID == anotherObject.data.converter->converterID); + } + return result; + } + ; #ifdef TRACE_GRAPH #define COUT_NODE(HEAD, NAME, ID) \ std::cout << HEAD << "(" << std::setfill('0') << std::setw(4) << ID << " " << NAME << ")"; - void trace() const - { - if(type==SINK) - COUT_NODE("SI", data.sink->name, data.sink->sinkID ) - else if(type==SOURCE) - COUT_NODE("SO", data.source->name, data.source->sourceID ) - else if(type==GATEWAY) - COUT_NODE("GA", data.gateway->name, data.gateway->gatewayID ) - else if(type==CONVERTER) - COUT_NODE("CO", data.converter->name, data.converter->converterID ) - }; + void trace() const + { + if(type==SINK) + COUT_NODE("SI", data.sink->name, data.sink->sinkID ) + else if(type==SOURCE) + COUT_NODE("SO", data.source->name, data.source->sourceID ) + else if(type==GATEWAY) + COUT_NODE("GA", data.gateway->name, data.gateway->gatewayID ) + else if(type==CONVERTER) + COUT_NODE("CO", data.converter->name, data.converter->converterID ) + }; #endif - am_domainID_t domainID() const - { - if(type==SINK) - return data.sink->domainID; - else if(type==SOURCE) - return data.source->domainID; - else if(type==GATEWAY) - return data.gateway->controlDomainID; - else if(type==CONVERTER) - return data.converter->domainID; - return 0; - }; -}; - -typedef am_RoutingNodeData_s::am_NodeDataType_e CAmNodeDataType; -typedef CAmNode CAmRoutingNode; -typedef CAmGraph CAmRoutingGraph; -typedef CAmVertex CAmRoutingVertex; -typedef std::list CAmRoutingListVertices; -typedef std::vector CAmRoutingVertexReferenceList; - -class CAmControlSender; - - -/** - * Implements an autorouting algorithm for connecting sinks and sources via different audio domains. - */ -class CAmRouter: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks -{ - IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler - CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route - bool mOnlyFreeConversionNodes; //!< bool flag whether only disconnected elements should be considered or not - unsigned mMaxAllowedCycles; //!< max allowed cycles, default is 1 - unsigned mMaxPathCount; //!< max paths count returned to the controller, default is 5 - CAmRoutingGraph mRoutingGraph; //!< graph object - std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access - std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access - std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access - std::map> mNodeListConverters;//!< map with pointers to nodes with converters, used for quick access - - /** - * Check whether given converter or gateway has been connected. - * - * @param comp converter or gateway . - */ - template bool isComponentConnected(const Component & comp) - { - return mpDatabaseHandler->isComponentConnected(comp); - } - - /** - * Connect all converters to its sink and sources if possible. - * - */ - void constructConverterConnections(); - - /** - * Connect all gateways to its sink and sources if possible. - * - */ - void constructGatewayConnections(); - - /** - * Connect all sources to the sinks if possible. - * - */ - void constructSourceSinkConnections(); - - /** - * Construct list with all vertices - */ - void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct list with all vertices from given source. - */ - void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct list with all vertices from given sink. - */ - void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct list with all vertices from given converter. - */ - void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Construct list with all vertices from given gateway. - */ - void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list); - - /** - * Connection format permutations. - * - * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. - */ - am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); - am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & route, - std::vector::iterator routingElementIterator, - std::vector::iterator routeIterator, - std::vector & result); - am_Error_e cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath); - - /** - * Helper method. - */ - static int insertPostion(const std::vector& path, const std::vector >& nodes) ; - - -public: - CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); - ~CAmRouter(); - - unsigned getMaxAllowedCycles() { return mMaxAllowedCycles; } - void setMaxAllowedCycles(unsigned count) { mMaxAllowedCycles = count; } - - unsigned getMaxPathCount() { return mMaxPathCount; } - void setMaxPathCount(unsigned count) { mMaxPathCount = count; } - - /** - * Find first mMaxPathCount paths between given source and sink. - * - * @param onlyfree only disconnected elements should be included or not. - * @param sourceID start point. - * @param sinkID end point. - * @param returnList list with all possible paths - * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. - */ - am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); - am_Error_e getRoute(const bool onlyfree, const am_Source_s & source, const am_Sink_s & sink, std::vector & listRoutes); - - /** - * Find first mMaxPathCount paths between given source and sink after the nodes have been loaded. - * - * @param sourceID start point. - * @param sinkID end point. - * @param returnList list with all possible paths - * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. - */ - am_Error_e getRouteFromLoadedNodes(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList); - am_Error_e getRouteFromLoadedNodes(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); - - /** - * Find first mMaxPathCount paths between given source and sink. This method should be called only after 'load' has been called. - * - * @param source start point. - * @param sink end point. - * @param returnList list with all possible paths. - * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. - */ - am_Error_e getFirstNShortestPaths(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); - - /** - * Find the shortest path between given source and sink. This method should be called only after 'load' has been called. - * This method do not pay attention on the parameter mMaxAllowedCycles and goes through all possible paths. - * - * @param source start point. - * @param sink end point. - * @param returnList list with the connection format permutations of the shortest path. - * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. - */ - am_Error_e getShortestPath(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); - - static bool getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - std::vector & sourceFormats, - std::vector & sinkFormats); - static void listPossibleConnectionFormats(std::vector & inListSourceFormats, - std::vector & inListSinkFormats, - std::vector & outListFormats); - static bool getRestrictedOutputFormats(const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - const am_CustomConnectionFormat_t connectionFormat, - std::vector & listFormats); - static am_Error_e getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, - std::vector::iterator iteratorSink, - std::vector & outConnectionFormats); - - static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber); - bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); - /** - * Returns a sink node with given sinkID. - * - * @param sinkID sink id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID); - CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID); - - /** - * Returns a source node with given sourceID. - * - * @param sourceID source id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID); - CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID); - - /** - * Returns a converter node for given sinkID. - * - * @param sinkID sink id. - * @param domainID domain id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID); - - /** - * Returns a gateway node for given sinkID. - * - * @param sinkID sink id. - * @return pointer to node or NULL. - */ - CAmRoutingNode* gatewayNodeWithSinkID(const am_sinkID_t sinkID); - - void load(const bool onlyFree); - void clear(); - - /** - * DEPRECATED! - */ -public: - am_Error_e getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles = false) - __attribute__((deprecated("You should use am_Error_e getFirstNShortestPaths(CAmRoutingNode &, CAmRoutingNode &, std::vector &) instead!"))); - - void getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & resultPath, std::vector & resultNodesPath) - __attribute__((deprecated("You should use am_Error_e getShortestPath(CAmRoutingNode &, CAmRoutingNode &, std::vector &) instead!"))); -}; + am_domainID_t domainID() const + { + if (type == SINK) + return data.sink->domainID; + else if (type == SOURCE) + return data.source->domainID; + else if (type == GATEWAY) + return data.gateway->controlDomainID; + else if (type == CONVERTER) + return data.converter->domainID; + return 0; + } + ; + }; + + typedef am_RoutingNodeData_s::am_NodeDataType_e CAmNodeDataType; + typedef CAmNode CAmRoutingNode; + typedef CAmGraph CAmRoutingGraph; + typedef CAmVertex CAmRoutingVertex; + typedef std::list CAmRoutingListVertices; + typedef std::vector CAmRoutingVertexReferenceList; + + class CAmControlSender; + + /** + * Implements autorouting algorithm for connecting sinks and sources via different audio domains. + */ + class CAmRouter: public CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks + { + IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler + CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route + bool mUpdateGraphNodesAction; //!< Flag which marks whether the graph should be rebuild + unsigned mMaxAllowedCycles; //!< max allowed cycles, default is 1 + unsigned mMaxPathCount; //!< max paths count returned to the controller, default is 5 + CAmRoutingGraph mRoutingGraph; //!< graph object + std::map> mNodeListSources; //!< map with pointers to nodes with sources, used for quick access + std::map> mNodeListSinks; //!< map with pointers to nodes with sinks, used for quick access + std::map> mNodeListGateways; //!< map with pointers to nodes with gateways, used for quick access + std::map> mNodeListConverters; //!< map with pointers to nodes with converters, used for quick access + + /** + * Check whether given converter or gateway has been connected. + * + * @param comp converter or gateway . + */ + template bool isComponentConnected(const Component & comp) + { + return mpDatabaseHandler->isComponentConnected(comp); + } + + /** + * Connect all converters to its sink and sources if possible. + * + */ + void constructConverterConnections(); + + /** + * Connect all gateways to its sink and sources if possible. + * + */ + void constructGatewayConnections(); + + /** + * Connect all sources to the sinks if possible. + * + */ + void constructSourceSinkConnections(); + + /** + * Construct list with all vertices + */ + void getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct list with all vertices from given source. + */ + void getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct list with all vertices from given sink. + */ + void getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct list with all vertices from given converter. + */ + void getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Construct list with all vertices from given gateway. + */ + void getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list); + + /** + * Connection format permutations. + * + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. + */ + am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result); + am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & route, + std::vector::iterator routingElementIterator, std::vector::iterator routeIterator, + std::vector & result); + am_Error_e cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath); + + /** + * Helper method. + */ + static int insertPostion(const std::vector& path, const std::vector >& nodes); + + public: + CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender); + ~CAmRouter(); + + unsigned getMaxAllowedCycles() + { + return mMaxAllowedCycles; + } + void setMaxAllowedCycles(unsigned count) + { + mMaxAllowedCycles = count; + } + + unsigned getMaxPathCount() + { + return mMaxPathCount; + } + void setMaxPathCount(unsigned count) + { + mMaxPathCount = count; + } + + bool getUpdateGraphNodesAction() + { + return mUpdateGraphNodesAction; + } + + /** + * Find first mMaxPathCount paths between given source and sink. This method will call the method load() if the parameter mUpdateGraphNodesAction is set which will rebuild the graph. + * + * @param onlyfree only disconnected elements should be included or not. + * @param sourceID start point. + * @param sinkID end point. + * @param returnList list with all possible paths + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. + */ + am_Error_e getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList); + am_Error_e getRoute(const bool onlyfree, const am_Source_s & source, const am_Sink_s & sink, std::vector & listRoutes); + + /** + * Find first mMaxPathCount paths between given source and sink after the nodes have been loaded. This method doesn't call load(). + * + * @param onlyfree only disconnected elements should be included or not. + * @param sourceID start point. + * @param sinkID end point. + * @param returnList list with all possible paths + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. + */ + am_Error_e getRouteFromLoadedNodes(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList); + am_Error_e getRouteFromLoadedNodes(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes); + + /** + * Find first mMaxPathCount paths between given source and sink. This method doesn't call load(). + * + * @param onlyfree only disconnected elements should be included or not. + * @param cycles allowed domain cycles. + * @param maxPathCount max count of returned paths. + * @param source start point. + * @param sink end point. + * @param returnList list with all possible paths. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. + */ + am_Error_e getFirstNShortestPaths(const bool onlyfree, const unsigned cycles, const unsigned maxPathCount, CAmRoutingNode & source, + CAmRoutingNode & sink, std::vector & resultPath); + + /** + * Find the shortest path between given source and sink. This method doesn't call load(). + * It goes through all possible paths and returns the shortest of them. + * + * @param source start point. + * @param sink end point. + * @param returnList list with the connection format permutations of the shortest path. + * @return E_OK on success(1 or more paths), E_NOT_POSSIBLE if the CF couldn't be matached or E_UNKNOWN in any other error case. + */ + am_Error_e getShortestPath(CAmRoutingNode & source, CAmRoutingNode & sink, std::vector & resultPath); + + static bool getAllowedFormatsFromConvMatrix(const std::vector & convertionMatrix, + const std::vector & listSourceFormats, const std::vector & listSinkFormats, + std::vector & sourceFormats, std::vector & sinkFormats); + static void listPossibleConnectionFormats(std::vector & inListSourceFormats, + std::vector & inListSinkFormats, std::vector & outListFormats); + static bool getRestrictedOutputFormats(const std::vector & convertionMatrix, const std::vector & listSourceFormats, + const std::vector & listSinkFormats, const am_CustomConnectionFormat_t connectionFormat, + std::vector & listFormats); + static am_Error_e getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, + std::vector::iterator iteratorSink, std::vector & outConnectionFormats); + + static bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber); + bool shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID); + /** + * Returns a sink node with given sinkID. + * + * @param sinkID sink id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID); + CAmRoutingNode* sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID); + + /** + * Returns a source node with given sourceID. + * + * @param sourceID source id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID); + CAmRoutingNode* sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID); + + /** + * Returns a converter node for given sinkID. + * + * @param sinkID sink id. + * @param domainID domain id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID); + + /** + * Returns a gateway node for given sinkID. + * + * @param sinkID sink id. + * @return pointer to node or NULL. + */ + CAmRoutingNode* gatewayNodeWithSinkID(const am_sinkID_t sinkID); + + void load(); + void clear(); + + /** + * DEPRECATED! + */ + public: + am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, + std::vector> & resultNodesPath, const bool includeCycles = false, + const bool onlyFree = false) + __attribute__((deprecated("You should use am_Error_e getFirstNShortestPaths(const bool onlyFree, CAmRoutingNode &, CAmRoutingNode &, std::vector &) instead!"))); + }; } /* namespace am */ #endif /* ROUTER_H_ */ diff --git a/AudioManagerCore/src/CAmRouter.cpp b/AudioManagerCore/src/CAmRouter.cpp index 5edd6d5..6f1fe61 100644 --- a/AudioManagerCore/src/CAmRouter.cpp +++ b/AudioManagerCore/src/CAmRouter.cpp @@ -31,945 +31,967 @@ #include "CAmControlSender.h" #include "CAmDltWrapper.h" - - -namespace am { - - -template void getMergeConnectionFormats(const X * element, - const am_CustomConnectionFormat_t connectionFormat, - const std::vector & listConnectionFormats, - std::vector & outListMergeConnectionFormats) +namespace am { - std::vector listRestrictedConnectionFormats; - CAmRouter::getRestrictedOutputFormats(element->convertionMatrix, - element->listSourceFormats, - element->listSinkFormats, - connectionFormat, - listRestrictedConnectionFormats); - std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input - std::insert_iterator > inserter(outListMergeConnectionFormats, outListMergeConnectionFormats.begin()); - set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter); -} + template void getMergeConnectionFormats(const X * element, const am_CustomConnectionFormat_t connectionFormat, + const std::vector & listConnectionFormats, std::vector & outListMergeConnectionFormats) + { + std::vector listRestrictedConnectionFormats; + CAmRouter::getRestrictedOutputFormats(element->convertionMatrix, element->listSourceFormats, element->listSinkFormats, connectionFormat, + listRestrictedConnectionFormats); + std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input + std::insert_iterator > inserter(outListMergeConnectionFormats, outListMergeConnectionFormats.begin()); + set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), + listRestrictedConnectionFormats.end(), inserter); + } -CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : - CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks(), - mpDatabaseHandler(iDatabaseHandler), // - mpControlSender(iSender), - mOnlyFreeConversionNodes(false), - mMaxAllowedCycles(MAX_ALLOWED_DOMAIN_CYCLES), - mMaxPathCount(MAX_ROUTING_PATHS), - mRoutingGraph(), - mNodeListSources(), - mNodeListSinks(), - mNodeListGateways(), - mNodeListConverters() -{ - assert(mpDatabaseHandler); - assert(mpControlSender); -} + CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) : + CAmDatabaseHandlerMap::AmDatabaseObserverCallbacks(), + mpDatabaseHandler(iDatabaseHandler), // + mpControlSender(iSender), + mUpdateGraphNodesAction(true), + mMaxAllowedCycles(MAX_ALLOWED_DOMAIN_CYCLES), + mMaxPathCount(MAX_ROUTING_PATHS), + mRoutingGraph(), + mNodeListSources(), + mNodeListSinks(), + mNodeListGateways(), + mNodeListConverters() + { + assert(mpDatabaseHandler); + assert(mpControlSender); -CAmRouter::~CAmRouter() -{ -} + dboNewSink = [&](const am_Sink_s& sink) + { + mUpdateGraphNodesAction = true; + }; + dboNewSource = [&](const am_Source_s& source) + { + mUpdateGraphNodesAction=true; + }; + dboNewGateway = [&](const am_Gateway_s& gateway) + { + mUpdateGraphNodesAction=true; + }; + dboNewConverter = [&](const am_Converter_s& coverter) + { + mUpdateGraphNodesAction=true; + }; + dboRemovedSink = [&](const am_sinkID_t sinkID, const bool visible) + { + mUpdateGraphNodesAction=true; + }; + dboRemovedSource = [&](const am_sourceID_t sourceID, const bool visible) + { + mUpdateGraphNodesAction=true; + }; + dboRemoveGateway = [&](const am_gatewayID_t gatewayID) + { + mUpdateGraphNodesAction=true; + }; + dboRemoveConverter = [&](const am_converterID_t converterID) + { + mUpdateGraphNodesAction=true; + }; + } -/** - * returns the best route between a source and a sink - * @param onlyfree if true only free gateways are used - * @param sourceID - * @param sinkID - * @param returnList this list contains a set of routes - * @return E_OK in case of success - */ -am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) -{ - load(onlyfree); - return getRouteFromLoadedNodes(sourceID, sinkID, returnList); -} + CAmRouter::~CAmRouter() + { + } + /** + * returns the best route between a source and a sink + * @param onlyfree if true only free gateways are used + * @param sourceID + * @param sinkID + * @param returnList this list contains a set of routes + * @return E_OK in case of success + */ + am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) + { + if (mUpdateGraphNodesAction) + { + load(); + mUpdateGraphNodesAction = false; + } + return getRouteFromLoadedNodes(onlyfree, sourceID, sinkID, returnList); + } -am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) -{ - return getRoute(onlyfree, aSource.sourceID, aSink.sinkID, listRoutes); -} + am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) + { + return getRoute(onlyfree, aSource.sourceID, aSink.sinkID, listRoutes); + } -am_Error_e CAmRouter::getRouteFromLoadedNodes(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & returnList) -{ - returnList.clear(); + am_Error_e CAmRouter::getRouteFromLoadedNodes(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, + std::vector & returnList) + { + returnList.clear(); - CAmRoutingNode* pRootSource = sourceNodeWithID(sourceID); - CAmRoutingNode* pRootSink = sinkNodeWithID(sinkID); + CAmRoutingNode* pRootSource = sourceNodeWithID(sourceID); + CAmRoutingNode* pRootSink = sinkNodeWithID(sinkID); - if(!pRootSource || !pRootSink) - return E_NON_EXISTENT; + if (!pRootSource || !pRootSink) + return E_NON_EXISTENT; - //try to find paths without cycles - const unsigned cycles = mMaxAllowedCycles; - mMaxAllowedCycles = 0; + //try to find paths without cycles + am_Error_e error = getFirstNShortestPaths(onlyfree, 0, mMaxPathCount, *pRootSource, *pRootSink, returnList); - am_Error_e error = getFirstNShortestPaths(*pRootSource, *pRootSink, returnList); + //if no paths have been found, we start a second search with cycles. + if (!returnList.size() && mMaxAllowedCycles > 0) + { + error = getFirstNShortestPaths(onlyfree, mMaxAllowedCycles, mMaxPathCount, *pRootSource, *pRootSink, returnList); + } - mMaxAllowedCycles = cycles; + /* For shortest path use the following call: + * + * error = getShortestPath(*pRootSource, *pRootSink, listRoutes); + */ + return error; + } - //if no paths have been found, we start a second search with cycles. - if( !returnList.size() && cycles>0 ) + am_Error_e CAmRouter::getRouteFromLoadedNodes(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, + std::vector & listRoutes) { - error = getFirstNShortestPaths(*pRootSource, *pRootSink, returnList); + return getRouteFromLoadedNodes(onlyfree, aSource.sourceID, aSink.sinkID, listRoutes); } - /* For shortest path use the following call: - * - * error = getShortestPath(*pRootSource, *pRootSink, listRoutes); - */ - return error; -} - + void CAmRouter::load() + { + clear(); -am_Error_e CAmRouter::getRouteFromLoadedNodes(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes) -{ - return getRouteFromLoadedNodes(aSource.sourceID, aSink.sinkID, listRoutes); -} + am_RoutingNodeData_s nodeDataSrc; + nodeDataSrc.type = CAmNodeDataType::SOURCE; + mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj) + { + nodeDataSrc.data.source = (am_Source_s*)&obj; + auto node = &mRoutingGraph.addNode(nodeDataSrc); + mNodeListSources[nodeDataSrc.data.source->domainID].push_back(node); + }); + + am_RoutingNodeData_s nodeDataSink; + nodeDataSink.type = CAmNodeDataType::SINK; + mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj) + { + nodeDataSink.data.sink = (am_Sink_s*)&obj; + auto node = &mRoutingGraph.addNode(nodeDataSink); + mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(node); + }); + + am_RoutingNodeData_s nodeDataGateway; + nodeDataGateway.type = CAmNodeDataType::GATEWAY; + mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj) + { + nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; + auto node = &mRoutingGraph.addNode(nodeDataGateway); + mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(node); + }); + + am_RoutingNodeData_s nodeDataConverter; + nodeDataConverter.type = CAmNodeDataType::CONVERTER; + mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj) + { + nodeDataConverter.data.converter = (am_Converter_s*)&obj; + auto node = &mRoutingGraph.addNode(nodeDataConverter); + mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(node); + }); -void CAmRouter::load(const bool onlyFree) -{ - clear(); - mOnlyFreeConversionNodes = onlyFree; - - am_RoutingNodeData_s nodeDataSrc; - nodeDataSrc.type = CAmNodeDataType::SOURCE; - mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){ - nodeDataSrc.data.source = (am_Source_s*)&obj; - auto node = &mRoutingGraph.addNode(nodeDataSrc); - mNodeListSources[nodeDataSrc.data.source->domainID].push_back(node); - }); - am_RoutingNodeData_s nodeDataSink; - nodeDataSink.type = CAmNodeDataType::SINK; - mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){ - nodeDataSink.data.sink = (am_Sink_s*)&obj; - auto node = &mRoutingGraph.addNode(nodeDataSink); - mNodeListSinks[nodeDataSink.data.sink->domainID].push_back(node); - }); - am_RoutingNodeData_s nodeDataGateway; - nodeDataGateway.type = CAmNodeDataType::GATEWAY; - mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){ - nodeDataGateway.data.gateway = (am_Gateway_s*)&obj; - auto node = &mRoutingGraph.addNode(nodeDataGateway); - mNodeListGateways[nodeDataGateway.data.gateway->controlDomainID].push_back(node); - }); - am_RoutingNodeData_s nodeDataConverter; - nodeDataConverter.type = CAmNodeDataType::CONVERTER; - mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){ - nodeDataConverter.data.converter = (am_Converter_s*)&obj; - auto node = &mRoutingGraph.addNode(nodeDataConverter); - mNodeListConverters[nodeDataConverter.data.converter->domainID].push_back(node); - }); - - constructConverterConnections(); - constructGatewayConnections(); - constructSourceSinkConnections(); + constructConverterConnections(); + constructGatewayConnections(); + constructSourceSinkConnections(); #ifdef TRACE_GRAPH - mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) { - std::cout << "Node " << node.getIndex() << ":"; - ((CAmRoutingNode &)node).getData().trace(); - std::cout << "-->["; - int count = 0; - std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex){ - am::CAmNode* data = refVertex->getNode(); - if(count>0) - std::cout << ", "; - std::cout << "Node " << data->getIndex() << ":"; - data->getData().trace(); - count++; - }); - std::cout << "]" << std::endl; - }); + mRoutingGraph.trace([&](const CAmRoutingNode & node, const std::vector*> & list) + { + std::cout << "Node " << node.getIndex() << ":"; + ((CAmRoutingNode &)node).getData().trace(); + std::cout << "-->["; + int count = 0; + std::for_each(list.begin(), list.end(), [&](const CAmVertex* refVertex) + { + am::CAmNode* data = refVertex->getNode(); + if(count>0) + std::cout << ", "; + std::cout << "Node " << data->getIndex() << ":"; + data->getData().trace(); + count++; + }); + std::cout << "]" << std::endl; + }); #endif -} + } -void CAmRouter::clear() -{ - mRoutingGraph.clear(); - mNodeListSources.clear(); - mNodeListSinks.clear(); - mNodeListGateways.clear(); - mNodeListConverters.clear(); -} + void CAmRouter::clear() + { + mRoutingGraph.clear(); + mNodeListSources.clear(); + mNodeListSinks.clear(); + mNodeListGateways.clear(); + mNodeListConverters.clear(); + } -CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID) -{ - CAmRoutingNode* result = NULL; - for(auto it = mNodeListSinks.begin(); it!=mNodeListSinks.end(); it++) - { - result = sinkNodeWithID(sinkID, it->first); - if(result) - return result; - } - return result; -} + CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID) + { + CAmRoutingNode* result = NULL; + for (auto it = mNodeListSinks.begin(); it != mNodeListSinks.end(); it++) + { + result = sinkNodeWithID(sinkID, it->first); + if (result) + return result; + } + return result; + } -CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListSinks[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.sink->sinkID==sinkID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} + CAmRoutingNode* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID, const am_domainID_t domainID) + { + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListSinks[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node) + { + return node->getData().data.sink->sinkID==sinkID; + }); + if (iter != value.end()) + result = *iter; + return result; + } -CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID) -{ - CAmRoutingNode* result = NULL; - for(auto it = mNodeListSources.begin(); it!=mNodeListSources.end(); it++) - { - result = sourceNodeWithID(sourceID, it->first); - if(result) - return result; - } - return result; -} + CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID) + { + CAmRoutingNode* result = NULL; + for (auto it = mNodeListSources.begin(); it != mNodeListSources.end(); it++) + { + result = sourceNodeWithID(sourceID, it->first); + if (result) + return result; + } + return result; + } -CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListSources[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sourceID](CAmRoutingNode* node){ - return node->getData().data.source->sourceID==sourceID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} + CAmRoutingNode* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID, const am_domainID_t domainID) + { + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListSources[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sourceID](CAmRoutingNode* node) + { + return node->getData().data.source->sourceID==sourceID; + }); + if (iter != value.end()) + result = *iter; + return result; + } -CAmRoutingNode* CAmRouter::converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID) -{ - CAmRoutingNode* result = NULL; - std::vector & value = mNodeListConverters[domainID]; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.converter->sinkID==sinkID; - }); - if(iter!=value.end()) - result = *iter; - return result; -} + CAmRoutingNode* CAmRouter::converterNodeWithSinkID(const am_sinkID_t sinkID, const am_domainID_t domainID) + { + CAmRoutingNode* result = NULL; + std::vector & value = mNodeListConverters[domainID]; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node) + { + return node->getData().data.converter->sinkID==sinkID; + }); + if (iter != value.end()) + result = *iter; + return result; + } -CAmRoutingNode* CAmRouter::gatewayNodeWithSinkID(const am_sinkID_t sinkID) -{ - for(auto it = mNodeListGateways.begin(); it!=mNodeListGateways.end(); it++) - { - std::vector & value = it->second; - auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node){ - return node->getData().data.gateway->sinkID==sinkID; - }); - if(iter!=value.end()) - return *iter; - } - return NULL; -} + CAmRoutingNode* CAmRouter::gatewayNodeWithSinkID(const am_sinkID_t sinkID) + { + for (auto it = mNodeListGateways.begin(); it != mNodeListGateways.end(); it++) + { + std::vector & value = it->second; + auto iter = std::find_if(value.begin(), value.end(), [sinkID](CAmRoutingNode* node) + { + return node->getData().data.gateway->sinkID==sinkID; + }); + if (iter != value.end()) + return *iter; + } + return NULL; + } -void CAmRouter::constructSourceSinkConnections() -{ - std::vector intersection; - for(auto itSrc = mNodeListSources.begin(); itSrc!=mNodeListSources.end(); itSrc++) - { - for(auto it = itSrc->second.begin(); it!=itSrc->second.end(); it++) - { - CAmRoutingNode* srcNode = *it; - am_RoutingNodeData_s & srcNodeData = srcNode->getData(); - am_Source_s * source = srcNodeData.data.source; - for(auto itSink = mNodeListSinks[itSrc->first].begin(); itSink!=mNodeListSinks[itSrc->first].end(); itSink++) - { - CAmRoutingNode* sinkNode = *itSink; - am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); - am_Sink_s * sink = sinkNodeData.data.sink; - - intersection.clear(); - //Check whether the hidden sink formats match the source formats... - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); - if(intersection.size()>0)//OK match source -> sink - { - mRoutingGraph.connectNodes(*srcNode, *sinkNode, CF_UNKNOWN, 1); - } - } - } - } -} + void CAmRouter::constructSourceSinkConnections() + { + std::vector intersection; + for (auto itSrc = mNodeListSources.begin(); itSrc != mNodeListSources.end(); itSrc++) + { + for (auto it = itSrc->second.begin(); it != itSrc->second.end(); it++) + { + CAmRoutingNode* srcNode = *it; + am_RoutingNodeData_s & srcNodeData = srcNode->getData(); + am_Source_s * source = srcNodeData.data.source; + for (auto itSink = mNodeListSinks[itSrc->first].begin(); itSink != mNodeListSinks[itSrc->first].end(); itSink++) + { + CAmRoutingNode* sinkNode = *itSink; + am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); + am_Sink_s * sink = sinkNodeData.data.sink; + + intersection.clear(); + //Check whether the hidden sink formats match the source formats... + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); + if (intersection.size() > 0) //OK match source -> sink + { + mRoutingGraph.connectNodes(*srcNode, *sinkNode, CF_UNKNOWN, 1); + } + } + } + } + } -void CAmRouter::constructGatewayConnections() -{ - std::vector sourceFormats, sinkFormats; - for(auto iter = mNodeListGateways.begin(); iter!=mNodeListGateways.end(); iter++) - { - for(auto it = iter->second.begin(); it!=iter->second.end(); it++) - { - CAmRoutingNode* gatewayNode = *it; - am_RoutingNodeData_s & gatewayNodeData = gatewayNode->getData(); - am_Gateway_s * gateway = gatewayNodeData.data.gateway; - //Get only gateways with end point in current source domain - if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) - { - //Get the sink connected to the gateway... - CAmRoutingNode *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID, gateway->domainSinkID); - if(gatewaySinkNode) - { - am_RoutingNodeData_s & gatewaySinkData = gatewaySinkNode->getData(); - //Check whether the hidden sink formats match the source formats... - sourceFormats.clear(); - sinkFormats.clear(); - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); - if(gatewaySourceNode) - { - //Connections hidden_sink->gateway->hidden_source - mRoutingGraph.connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1); - mRoutingGraph.connectNodes(*gatewayNode, *gatewaySourceNode, CF_UNKNOWN, 1); - } - } - } - } - } - } -} + void CAmRouter::constructGatewayConnections() + { + std::vector sourceFormats, sinkFormats; + for (auto iter = mNodeListGateways.begin(); iter != mNodeListGateways.end(); iter++) + { + for (auto it = iter->second.begin(); it != iter->second.end(); it++) + { + CAmRoutingNode* gatewayNode = *it; + am_RoutingNodeData_s & gatewayNodeData = gatewayNode->getData(); + am_Gateway_s * gateway = gatewayNodeData.data.gateway; + //Get only gateways with end point in current source domain + + //Get the sink connected to the gateway... + CAmRoutingNode *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID, gateway->domainSinkID); + if (gatewaySinkNode) + { + am_RoutingNodeData_s & gatewaySinkData = gatewaySinkNode->getData(); + //Check whether the hidden sink formats match the source formats... + sourceFormats.clear(); + sinkFormats.clear(); + if (getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, + sinkFormats)) + { + CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); + if (gatewaySourceNode) + { + //Connections hidden_sink->gateway->hidden_source + mRoutingGraph.connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1); + mRoutingGraph.connectNodes(*gatewayNode, *gatewaySourceNode, CF_UNKNOWN, 1); + } + } + } + } + } + } -void CAmRouter::constructConverterConnections() -{ - std::vector sourceFormats, sinkFormats; - - for(auto iter = mNodeListConverters.begin(); iter!=mNodeListConverters.end(); iter++) - { - for(auto it = iter->second.begin(); it!=iter->second.end(); it++) - { - CAmRoutingNode* converterNode = *it; - am_RoutingNodeData_s & converterNodeData = converterNode->getData(); - am_Converter_s * converter = converterNodeData.data.converter; - //Get only converters with end point in current source domain - if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) - { - //Get the sink connected to the converter... - CAmRoutingNode *converterSinkNode = this->sinkNodeWithID(converter->sinkID, converter->domainID); - if(converterSinkNode) - { - am_RoutingNodeData_s & converterSinkData = converterSinkNode->getData(); - //Check whether the hidden sink formats match the source formats... - sourceFormats.clear(); - sinkFormats.clear(); - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); - if(converterSourceNode) - { - //Connections hidden_sink->converter->hidden_source - mRoutingGraph.connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1); - mRoutingGraph.connectNodes(*converterNode, *converterSourceNode, CF_UNKNOWN, 1); - } - } - } - } - } - } -} + void CAmRouter::constructConverterConnections() + { + std::vector sourceFormats, sinkFormats; -void CAmRouter::getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & srcNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector intersection; - am_Source_s * source = srcNodeData.data.source; - std::vector & sinks = mNodeListSinks[source->domainID]; - for(auto itSink = sinks.begin(); itSink!=sinks.end(); itSink++) - { - CAmRoutingNode* sinkNode = *itSink; - am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); - am_Sink_s * sink = sinkNodeData.data.sink; - - intersection.clear(); - //Check whether the hidden sink formats match the source formats... - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); - if(intersection.size()>0)//OK match source -> sink - { - list.emplace_back(sinkNode, CF_UNKNOWN, 1); - } - } -} + for (auto iter = mNodeListConverters.begin(); iter != mNodeListConverters.end(); iter++) + { + for (auto it = iter->second.begin(); it != iter->second.end(); it++) + { + CAmRoutingNode* converterNode = *it; + am_RoutingNodeData_s & converterNodeData = converterNode->getData(); + am_Converter_s * converter = converterNodeData.data.converter; + //Get only converters with end point in current source domain + + //Get the sink connected to the converter... + CAmRoutingNode *converterSinkNode = this->sinkNodeWithID(converter->sinkID, converter->domainID); + if (converterSinkNode) + { + am_RoutingNodeData_s & converterSinkData = converterSinkNode->getData(); + //Check whether the hidden sink formats match the source formats... + sourceFormats.clear(); + sinkFormats.clear(); + if (getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, + sinkFormats)) + { + CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); + if (converterSourceNode) + { + //Connections hidden_sink->converter->hidden_source + mRoutingGraph.connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1); + mRoutingGraph.connectNodes(*converterNode, *converterSourceNode, CF_UNKNOWN, 1); + } + } + } + } + } + } -void CAmRouter::getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & sinkNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector intersection; - am_Sink_s * sink = sinkNodeData.data.sink; - - CAmRoutingNode *converterNode = converterNodeWithSinkID(sink->sinkID, sink->domainID); - if(converterNode) - { - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & converterData = converterNode->getData(); - am_Converter_s * converter = converterData.data.converter; - if(!mOnlyFreeConversionNodes || !isComponentConnected(*converter)) - { - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - list.emplace_back(converterNode, CF_UNKNOWN, 1); - } - } - else - { - std::vector sourceFormats, sinkFormats; - CAmRoutingNode *gatewayNode = gatewayNodeWithSinkID(sink->sinkID); - if(gatewayNode) - { - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & gatewayData = gatewayNode->getData(); - am_Gateway_s * gateway = gatewayData.data.gateway; - if(!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) - { - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - list.emplace_back(gatewayNode, CF_UNKNOWN, 1); - } - } - } + void CAmRouter::getVerticesForSource(const CAmRoutingNode & node, CAmRoutingListVertices & list) + { + am_RoutingNodeData_s & srcNodeData = ((CAmRoutingNode*) &node)->getData(); + std::vector intersection; + am_Source_s * source = srcNodeData.data.source; + std::vector & sinks = mNodeListSinks[source->domainID]; + for (auto itSink = sinks.begin(); itSink != sinks.end(); itSink++) + { + CAmRoutingNode* sinkNode = *itSink; + am_RoutingNodeData_s & sinkNodeData = sinkNode->getData(); + am_Sink_s * sink = sinkNodeData.data.sink; + + intersection.clear(); + //Check whether the hidden sink formats match the source formats... + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, intersection); + if (intersection.size() > 0) //OK match source -> sink + { + list.emplace_back(sinkNode, CF_UNKNOWN, 1); + } + } + } -} + void CAmRouter::getVerticesForSink(const CAmRoutingNode & node, CAmRoutingListVertices & list) + { + am_RoutingNodeData_s & sinkNodeData = ((CAmRoutingNode*) &node)->getData(); + std::vector intersection; + am_Sink_s * sink = sinkNodeData.data.sink; -void CAmRouter::getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - std::vector sourceFormats, sinkFormats; - am_RoutingNodeData_s & converterNodeData = ((CAmRoutingNode*)&node)->getData(); - am_Converter_s * converter = converterNodeData.data.converter; - //Get only converters with end point in current source domain - if(getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); - if(converterSourceNode) - { - list.emplace_back(converterSourceNode, CF_UNKNOWN, 1); - } - } -} + CAmRoutingNode *converterNode = converterNodeWithSinkID(sink->sinkID, sink->domainID); + if (converterNode) + { + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & converterData = converterNode->getData(); + am_Converter_s * converter = converterData.data.converter; -void CAmRouter::getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list) -{ - am_RoutingNodeData_s & gatewayNodeData = ((CAmRoutingNode*)&node)->getData(); - std::vector sourceFormats, sinkFormats; - am_Gateway_s * gateway = gatewayNodeData.data.gateway; - if(getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) - { - CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); - if(gatewaySourceNode) - { - //Connections hidden_sink->gateway->hidden_source - list.emplace_back(gatewaySourceNode, CF_UNKNOWN, 1); - } - } -} + if (getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, + sinkFormats)) + list.emplace_back(converterNode, CF_UNKNOWN, 1); + } + else + { + std::vector sourceFormats, sinkFormats; + CAmRoutingNode *gatewayNode = gatewayNodeWithSinkID(sink->sinkID); + if (gatewayNode) + { + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & gatewayData = gatewayNode->getData(); + am_Gateway_s * gateway = gatewayData.data.gateway; + + if (getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, + sinkFormats)) + list.emplace_back(gatewayNode, CF_UNKNOWN, 1); + } + } -void CAmRouter::getVerticesForNode( - const CAmRoutingNode & node, - CAmRoutingListVertices & list - ) -{ - am_RoutingNodeData_s & nodeData = ((CAmRoutingNode*)&node)->getData(); - if(nodeData.type==CAmNodeDataType::SOURCE) - { - getVerticesForSource(node, list); - } - else if(nodeData.type==CAmNodeDataType::SINK) - { - getVerticesForSink(node, list); - } - else if(nodeData.type==CAmNodeDataType::CONVERTER) - { - getVerticesForConverter(node, list); - } - else if(nodeData.type==CAmNodeDataType::GATEWAY) - { - getVerticesForGateway(node, list); - } -} + } -am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result) -{ - std::vector::iterator routingElementIterator = routeObjects.route.begin(); - std::vector::iterator nodeIterator = nodes.begin(); - if( routingElementIterator!= routeObjects.route.end() && nodeIterator!=nodes.end() ) - return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator, result); - return E_OK; -} + void CAmRouter::getVerticesForConverter(const CAmRoutingNode & node, CAmRoutingListVertices & list) + { + std::vector sourceFormats, sinkFormats; + am_RoutingNodeData_s & converterNodeData = ((CAmRoutingNode*) &node)->getData(); + am_Converter_s * converter = converterNodeData.data.converter; + //Get only converters with end point in current source domain + if (getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converter->domainID); + if (converterSourceNode) + { + list.emplace_back(converterSourceNode, CF_UNKNOWN, 1); + } + } + } -am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, - std::vector & nodes, - std::vector::iterator routingElementIterator, - std::vector::iterator nodeIterator, - std::vector & result) -{ - am_Error_e returnError = E_NOT_POSSIBLE; - std::vector listConnectionFormats; - std::vector listMergeConnectionFormats; - - std::vector::iterator currentNodeIterator = nodeIterator; - std::vector::iterator currentRoutingElementIterator = routingElementIterator; - - if (currentRoutingElementIterator!=routeObjects.route.begin()) - { - std::vector listConnectionFormats; - std::vector::iterator tempIterator = (currentRoutingElementIterator-1); - CAmRoutingNode * currentNode = *currentNodeIterator; - if((returnError = getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats))!=E_OK) - return returnError; - - if(currentNode->getData().type==CAmNodeDataType::GATEWAY) - { - am_Gateway_s *gateway = currentNode->getData().data.gateway; - getMergeConnectionFormats(gateway, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); - } - else if(currentNode->getData().type==CAmNodeDataType::CONVERTER) - { - am_Converter_s *converter = currentNode->getData().data.converter; - getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); - } - else - return (E_UNKNOWN); - currentNodeIterator+=3; - } - else - { - CAmRoutingNode * currentNode = *currentNodeIterator; - if(currentNode->getData().type!=CAmNodeDataType::SOURCE) - return (E_UNKNOWN); - currentNodeIterator++; - - if(currentNodeIterator==nodes.end()) - return (E_UNKNOWN); - - CAmRoutingNode * nodeSink = *currentNodeIterator; - if(nodeSink->getData().type!=CAmNodeDataType::SINK) - return (E_UNKNOWN); - - am_Source_s *source = currentNode->getData().data.source; - am_Sink_s *sink = nodeSink->getData().data.sink; - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats); - currentNodeIterator+=1; //now we are on the next converter/gateway - } - //let the controller decide: - std::vector listPriorityConnectionFormats; - if((returnError = mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects, - listMergeConnectionFormats, listPriorityConnectionFormats))!= E_OK) - return (returnError); - - if (listPriorityConnectionFormats.empty()) - return (E_NOT_POSSIBLE); - //we have the list sorted after priors - now we try one after the other with the next part of the route - std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); - //here we need to check if we are at the end and stop - std::vector::iterator nextIterator = currentRoutingElementIterator + 1;//next pair source and sink - if (nextIterator == routeObjects.route.end()) - { - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) - { - currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; - result.push_back(routeObjects); - } - } - else - { - for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) - { - currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; - doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator, result); - } - } - return (E_OK); -} + void CAmRouter::getVerticesForGateway(const CAmRoutingNode & node, CAmRoutingListVertices & list) + { + am_RoutingNodeData_s & gatewayNodeData = ((CAmRoutingNode*) &node)->getData(); + std::vector sourceFormats, sinkFormats; + am_Gateway_s * gateway = gatewayNodeData.data.gateway; + if (getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats)) + { + CAmRoutingNode *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gateway->domainSourceID); + if (gatewaySourceNode) + { + //Connections hidden_sink->gateway->hidden_source + list.emplace_back(gatewaySourceNode, CF_UNKNOWN, 1); + } + } + } -am_Error_e CAmRouter::cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath) -{ - std::vector result; - am_Error_e err = determineConnectionFormatsForPath(shortestRoute, resultNodesPath, result); - if (err != E_UNKNOWN) - { - resultPath.insert(resultPath.end(), result.begin(), result.end()); + void CAmRouter::getVerticesForNode(const CAmRoutingNode & node, CAmRoutingListVertices & list) + { + am_RoutingNodeData_s & nodeData = ((CAmRoutingNode*) &node)->getData(); + if (nodeData.type == CAmNodeDataType::SOURCE) + { + getVerticesForSource(node, list); + } + else if (nodeData.type == CAmNodeDataType::SINK) + { + getVerticesForSink(node, list); + } + else if (nodeData.type == CAmNodeDataType::CONVERTER) + { + getVerticesForConverter(node, list); + } + else if (nodeData.type == CAmNodeDataType::GATEWAY) + { + getVerticesForGateway(node, list); + } + } + + am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, std::vector & result) + { + std::vector::iterator routingElementIterator = routeObjects.route.begin(); + std::vector::iterator nodeIterator = nodes.begin(); + if (routingElementIterator != routeObjects.route.end() && nodeIterator != nodes.end()) + return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator, result); + return E_OK; + } + + am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects, std::vector & nodes, + std::vector::iterator routingElementIterator, std::vector::iterator nodeIterator, + std::vector & result) + { + am_Error_e returnError = E_NOT_POSSIBLE; + std::vector listConnectionFormats; + std::vector listMergeConnectionFormats; + + std::vector::iterator currentNodeIterator = nodeIterator; + std::vector::iterator currentRoutingElementIterator = routingElementIterator; + + if (currentRoutingElementIterator != routeObjects.route.begin()) + { + std::vector listConnectionFormats; + std::vector::iterator tempIterator = (currentRoutingElementIterator - 1); + CAmRoutingNode * currentNode = *currentNodeIterator; + if ((returnError = getSourceSinkPossibleConnectionFormats(currentNodeIterator + 1, currentNodeIterator + 2, listConnectionFormats)) != E_OK) + return returnError; + + if (currentNode->getData().type == CAmNodeDataType::GATEWAY) + { + am_Gateway_s *gateway = currentNode->getData().data.gateway; + getMergeConnectionFormats(gateway, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); + } + else if (currentNode->getData().type == CAmNodeDataType::CONVERTER) + { + am_Converter_s *converter = currentNode->getData().data.converter; + getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats); + } + else + return (E_UNKNOWN); + currentNodeIterator += 3; + } + else + { + CAmRoutingNode * currentNode = *currentNodeIterator; + if (currentNode->getData().type != CAmNodeDataType::SOURCE) + return (E_UNKNOWN); + currentNodeIterator++; + + if (currentNodeIterator == nodes.end()) + return (E_UNKNOWN); + + CAmRoutingNode * nodeSink = *currentNodeIterator; + if (nodeSink->getData().type != CAmNodeDataType::SINK) + return (E_UNKNOWN); + + am_Source_s *source = currentNode->getData().data.source; + am_Sink_s *sink = nodeSink->getData().data.sink; + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats); + currentNodeIterator += 1; //now we are on the next converter/gateway + } + //let the controller decide: + std::vector listPriorityConnectionFormats; + if ((returnError = mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, + routeObjects, listMergeConnectionFormats, listPriorityConnectionFormats)) != E_OK) + return (returnError); + + if (listPriorityConnectionFormats.empty()) + return (E_NOT_POSSIBLE); + //we have the list sorted after priors - now we try one after the other with the next part of the route + std::vector::iterator connectionFormatIterator = listPriorityConnectionFormats.begin(); + //here we need to check if we are at the end and stop + std::vector::iterator nextIterator = currentRoutingElementIterator + 1; //next pair source and sink + if (nextIterator == routeObjects.route.end()) + { + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + { + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + result.push_back(routeObjects); + } + } + else + { + for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator) + { + currentRoutingElementIterator->connectionFormat = *connectionFormatIterator; + doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator, result); + } + } + return (E_OK); + } + + am_Error_e CAmRouter::cfPermutationsForPath(am_Route_s shortestRoute, std::vector resultNodesPath, std::vector& resultPath) + { + std::vector result; + am_Error_e err = determineConnectionFormatsForPath(shortestRoute, resultNodesPath, result); + if (err != E_UNKNOWN) + { + resultPath.insert(resultPath.end(), result.begin(), result.end()); #ifdef TRACE_GRAPH - std::cout - << "Determined connection formats for path from source:" - << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID - << "\n"; - for (auto routeConnectionFormats : result) - { - std::cout << "["; - for (auto it = routeConnectionFormats.route.begin();it != routeConnectionFormats.route.end(); it++) - { - am_RoutingElement_s& routingElement = *it; - if (it - routeConnectionFormats.route.begin() > 0) - std::cout << " -> "; - - std::cout << routingElement.sourceID << ":" - << routingElement.sinkID << " CF:" - << routingElement.connectionFormat << " D:" - << routingElement.domainID; - } - std::cout << "]\n"; - } + std::cout + << "Determined connection formats for path from source:" + << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID + << "\n"; + for (auto routeConnectionFormats : result) + { + std::cout << "["; + for (auto it = routeConnectionFormats.route.begin();it != routeConnectionFormats.route.end(); it++) + { + am_RoutingElement_s& routingElement = *it; + if (it - routeConnectionFormats.route.begin() > 0) + std::cout << " -> "; + + std::cout << routingElement.sourceID << ":" + << routingElement.sinkID << " CF:" + << routingElement.connectionFormat << " D:" + << routingElement.domainID; + } + std::cout << "]\n"; + } #endif - } + } #ifdef TRACE_GRAPH - else - { - std::cout - << "Error by determining connection formats for path from source:" - << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID - << "\n"; - } + else + { + std::cout + << "Error by determining connection formats for path from source:" + << shortestRoute.sourceID << " to sink:" << shortestRoute.sinkID + << "\n"; + } #endif - return err; -} + return err; + } -am_Error_e CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath) -{ - am_Error_e err = E_OK; - am_Route_s shortestRoute; - std::vector resultNodesPath; - am_RoutingNodeData_s & sinkNodeData = aSink.getData(); - am_RoutingNodeData_s & sourceNodeData = aSource.getData(); - shortestRoute.sinkID = sinkNodeData.data.sink->sinkID; - shortestRoute.sourceID = sourceNodeData.data.source->sourceID; - - mRoutingGraph.getShortestPath(aSource, aSink, [&shortestRoute, &resultNodesPath](const am_GraphPathPosition_e position, CAmRoutingNode & object){ - am_RoutingElement_s * element; - //reverse order - resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); - am_RoutingNodeData_s & routingData = object.getData(); - if(routingData.type==CAmNodeDataType::SINK) - { - auto iter = shortestRoute.route.emplace(shortestRoute.route.begin()); - element = &(*iter); - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SOURCE) - { - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - }); - - if(shortestRoute.route.size()) - { - err = cfPermutationsForPath(shortestRoute, resultNodesPath, resultPath); - } - return err; -} + am_Error_e CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath) + { + am_Error_e err = E_OK; + am_Route_s shortestRoute; + std::vector resultNodesPath; + am_RoutingNodeData_s & sinkNodeData = aSink.getData(); + am_RoutingNodeData_s & sourceNodeData = aSource.getData(); + shortestRoute.sinkID = sinkNodeData.data.sink->sinkID; + shortestRoute.sourceID = sourceNodeData.data.source->sourceID; + + mRoutingGraph.getShortestPath(aSource, aSink, [&shortestRoute, &resultNodesPath](const am_GraphPathPosition_e position, CAmRoutingNode & object) + { + am_RoutingElement_s * element; + //reverse order + resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); + am_RoutingNodeData_s & routingData = object.getData(); + if(routingData.type==CAmNodeDataType::SINK) + { + auto iter = shortestRoute.route.emplace(shortestRoute.route.begin()); + element = &(*iter); + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SOURCE) + { + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + }); + + if (shortestRoute.route.size()) + { + err = cfPermutationsForPath(shortestRoute, resultNodesPath, resultPath); + } + return err; + } -void CAmRouter::getShortestPath(CAmRoutingNode & aSource, CAmRoutingNode & aSink, am_Route_s & path, std::vector & resultNodesPath) -{ - am_Route_s shortestRoute; - am_RoutingNodeData_s & sinkNodeData = aSink.getData(); - am_RoutingNodeData_s & sourceNodeData = aSource.getData(); - shortestRoute.sinkID = sinkNodeData.data.sink->sinkID; - shortestRoute.sourceID = sourceNodeData.data.source->sourceID; - - mRoutingGraph.getShortestPath(aSource, aSink, [&shortestRoute, &resultNodesPath](const am_GraphPathPosition_e position, CAmRoutingNode & object){ - am_RoutingElement_s * element; - //reverse order - resultNodesPath.insert(resultNodesPath.begin(), (CAmRoutingNode*)&object); - am_RoutingNodeData_s & routingData = object.getData(); - if(routingData.type==CAmNodeDataType::SINK) - { - auto iter = shortestRoute.route.emplace(shortestRoute.route.begin()); - element = &(*iter); - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SOURCE) - { - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - }); - - if(shortestRoute.route.size()) - { - std::vector resultPath; - cfPermutationsForPath(shortestRoute, resultNodesPath, resultPath); - if(resultPath.size()) - path = resultPath.front(); - } -} + int CAmRouter::insertPostion(const std::vector& path, const std::vector >& nodes) + { + int index = 0; + if (!nodes.empty()) + { + auto itNodes = nodes.begin(); + for (; itNodes != nodes.end(); itNodes++) + { + if (itNodes->size() > path.size()) + break; + } + if (itNodes == nodes.end()) + index = nodes.size(); + else + index = itNodes - nodes.begin(); + } + return index; + } -int CAmRouter::insertPostion(const std::vector& path, const std::vector >& nodes) -{ - int index = 0; - if (!nodes.empty()) { - auto itNodes = nodes.begin(); - for (; itNodes != nodes.end(); itNodes++) { - if (itNodes->size() > path.size()) - break; - } - if (itNodes == nodes.end()) - index = nodes.size(); - else - index = itNodes - nodes.begin(); - } - return index; -} + am_Error_e CAmRouter::getFirstNShortestPaths(const bool onlyFree, const unsigned cycles, const unsigned maxPathCount, CAmRoutingNode & aSource, + CAmRoutingNode & aSink, std::vector & resultPath) + { + if (aSource.getData().type != CAmNodeDataType::SOURCE || aSink.getData().type != CAmNodeDataType::SINK) + return E_NOT_POSSIBLE; + const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; + const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; + std::vector paths; + std::vector> nodes; + std::vector visitedDomains; + visitedDomains.push_back(((CAmRoutingNode*) &aSource)->getData().domainID()); + + auto cbShouldVisitNode = [&visitedDomains, &cycles, &onlyFree, this](const CAmRoutingNode * node)->bool + { + if(CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles)) + { + const am_RoutingNodeData_s & nodeData = node->getData(); + if(am_RoutingNodeData_s::GATEWAY==nodeData.type) + { + const am_Gateway_s * gateway = nodeData.data.gateway; + return (!onlyFree || !isComponentConnected(*gateway)); + } + else if(am_RoutingNodeData_s::CONVERTER==nodeData.type) + { + const am_Converter_s * converter = nodeData.data.converter; + return (!onlyFree || !isComponentConnected(*converter)); + } + return true; + } + return false; + }; + auto cbWillVisitNode = [&visitedDomains](const CAmRoutingNode * node) + { visitedDomains.push_back(node->getData().domainID());}; + auto cbDidVisitNode = [&visitedDomains](const CAmRoutingNode * node) + { visitedDomains.erase(visitedDomains.end()-1);}; + auto cbDidFinish = [&resultPath, &nodes, &paths, &sinkID, &sourceID](const std::vector & path) + { + int index = CAmRouter::insertPostion(path, nodes); + nodes.emplace(nodes.begin()+index); + paths.emplace(paths.begin()+index); + nodes[index] = path; + am_Route_s & nextRoute = paths[index]; + nextRoute.sinkID = sinkID; + nextRoute.sourceID = sourceID; + am_RoutingElement_s * element; + for(auto it = path.begin(); it!=path.end(); it++) + { + am_RoutingNodeData_s & routingData = (*it)->getData(); + if(routingData.type==CAmNodeDataType::SOURCE) + { + auto iter = nextRoute.route.emplace(nextRoute.route.end()); + element = &(*iter); + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SINK) + { + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + } + }; + + mRoutingGraph.getAllPaths(aSource, aSink, cbShouldVisitNode, cbWillVisitNode, cbDidVisitNode, cbDidFinish); + unsigned pathsFound = 0; + am_Error_e cfError = E_OK; + for (auto it = paths.begin(); pathsFound < maxPathCount && it != paths.end(); it++) + { + cfError = cfPermutationsForPath(*it, nodes[it - paths.begin()], resultPath); + if (E_OK == cfError) + { + pathsFound += (resultPath.size() > 0); + } + } + if (pathsFound) + return E_OK; + else + return E_NOT_POSSIBLE; + } -am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, - CAmRoutingNode & aSink, - std::vector & resultPath, - std::vector> & resultNodesPath, - const bool includeCycles) -{ + bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber) + { + unsigned recourseCounter(0); + if (visitedDomains.size()) + { + if (visitedDomains.back() == nodeDomainID) + return true; + unsigned count = 0; + am_domainID_t lastDomain = 0; + for (auto it = visitedDomains.begin(); it != visitedDomains.end() - 1; it++) + { + if (lastDomain != *it) + { + if (nodeDomainID == *it) + { + recourseCounter++; + if (recourseCounter > maxCyclesNumber) + return false; + } + lastDomain = *it; + } + } + } + return true; + } - if( aSource.getData().type!=CAmNodeDataType::SOURCE || aSink.getData().type!=CAmNodeDataType::SINK ) - return E_NOT_POSSIBLE; - - unsigned cycles; - if(includeCycles) - cycles = UINT_MAX; - else - cycles = 0; - - uint8_t errorsCount = 0, successCount = 0; - const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; - const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; - std::vector paths; - std::vector visitedDomains; - visitedDomains.push_back(((CAmRoutingNode*)&aSource)->getData().domainID()); - mRoutingGraph.getAllPaths(aSource, - aSink, - [&visitedDomains, &cycles](const CAmRoutingNode * node)->bool{ return CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles); }, - [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.push_back(node->getData().domainID()); }, - [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.erase(visitedDomains.end()-1); }, - [&resultPath, &resultNodesPath, &paths, &errorsCount, &successCount, &sinkID, &sourceID](const std::vector & path) { - int index = CAmRouter::insertPostion(path, resultNodesPath); - resultNodesPath.emplace(resultNodesPath.begin()+index); - paths.emplace(paths.begin()+index); - resultNodesPath[index] = path; - am_Route_s & nextRoute = paths[index]; - nextRoute.sinkID = sinkID; - nextRoute.sourceID = sourceID; - am_RoutingElement_s * element; - for(auto it = path.begin(); it!=path.end(); it++) - { - am_RoutingNodeData_s & routingData = (*it)->getData(); - if(routingData.type==CAmNodeDataType::SOURCE) - { - auto iter = nextRoute.route.emplace(nextRoute.route.end()); - element = &(*iter); - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SINK) - { - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - } - }); - - for(auto it = paths.begin(); successCount & visitedDomains, const am_domainID_t nodeDomainID) + { + return CAmRouter::shouldGoInDomain(visitedDomains, nodeDomainID, mMaxAllowedCycles); + } -am_Error_e CAmRouter::getFirstNShortestPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath) -{ - if( aSource.getData().type!=CAmNodeDataType::SOURCE || aSink.getData().type!=CAmNodeDataType::SINK ) - return E_NOT_POSSIBLE; - const unsigned cycles = mMaxAllowedCycles; - const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; - const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; - std::vector paths; - std::vector> nodes; - std::vector visitedDomains; - visitedDomains.push_back(((CAmRoutingNode*)&aSource)->getData().domainID()); - mRoutingGraph.getAllPaths(aSource, - aSink, - [&visitedDomains, &cycles](const CAmRoutingNode * node)->bool{ return CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles); }, - [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.push_back(node->getData().domainID()); }, - [&visitedDomains](const CAmRoutingNode * node){ visitedDomains.erase(visitedDomains.end()-1); }, - [&resultPath, &nodes, &paths, &sinkID, &sourceID](const std::vector & path) { - int index = CAmRouter::insertPostion(path, nodes); - nodes.emplace(nodes.begin()+index); - paths.emplace(paths.begin()+index); - nodes[index] = path; - am_Route_s & nextRoute = paths[index]; - nextRoute.sinkID = sinkID; - nextRoute.sourceID = sourceID; - am_RoutingElement_s * element; - for(auto it = path.begin(); it!=path.end(); it++) - { - am_RoutingNodeData_s & routingData = (*it)->getData(); - if(routingData.type==CAmNodeDataType::SOURCE) - { - auto iter = nextRoute.route.emplace(nextRoute.route.end()); - element = &(*iter); - element->domainID = routingData.data.source->domainID; - element->sourceID = routingData.data.source->sourceID; - element->connectionFormat = CF_UNKNOWN; - } - else if(routingData.type==CAmNodeDataType::SINK) - { - element->domainID = routingData.data.sink->domainID; - element->sinkID = routingData.data.sink->sinkID; - element->connectionFormat = CF_UNKNOWN; - } - } - }); - unsigned pathsFound = 0; - am_Error_e cfError = E_OK; - for(auto it = paths.begin(); pathsFound0); - } - } - if(pathsFound) - return E_OK; - else - return E_NOT_POSSIBLE; -} + bool CAmRouter::getAllowedFormatsFromConvMatrix(const std::vector & convertionMatrix, + const std::vector & listSourceFormats, const std::vector & listSinkFormats, + std::vector & sourceFormats, std::vector & sinkFormats) + { + const size_t sizeSourceFormats = listSourceFormats.size(); + const size_t sizeSinkFormats = listSinkFormats.size(); + const size_t sizeConvertionMatrix = convertionMatrix.size(); -bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID, const unsigned maxCyclesNumber) -{ - unsigned recourseCounter(0); - if(visitedDomains.size()) - { - if(visitedDomains.back()==nodeDomainID) - return true; - unsigned count = 0; - am_domainID_t lastDomain = 0; - for(auto it=visitedDomains.begin(); it!=visitedDomains.end()-1; it++) - { - if(lastDomain!=*it) - { - if(nodeDomainID==*it) - { - recourseCounter++; - if (recourseCounter>maxCyclesNumber) - return false; - } - lastDomain=*it; - } - } - } - return true; -} + if (sizeSourceFormats == 0 || sizeSinkFormats == 0 || sizeConvertionMatrix == 0 || sizeConvertionMatrix != sizeSinkFormats * sizeSourceFormats) + { + return false; + } -bool CAmRouter::shouldGoInDomain(const std::vector & visitedDomains, const am_domainID_t nodeDomainID) -{ - return CAmRouter::shouldGoInDomain(visitedDomains, nodeDomainID, mMaxAllowedCycles); -} + std::vector::const_iterator iterator = convertionMatrix.begin(); + for (; iterator != convertionMatrix.end(); ++iterator) + { + if (true == *iterator) + { + const size_t index = iterator - convertionMatrix.begin(); + size_t idx = index % sizeSourceFormats; + sourceFormats.push_back(listSourceFormats.at(idx)); + idx = index / sizeSourceFormats; + sinkFormats.push_back(listSinkFormats.at(idx)); + } + } + return sourceFormats.size() > 0; + } -bool CAmRouter::getAllowedFormatsFromConvMatrix( const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - std::vector & sourceFormats, - std::vector & sinkFormats) -{ - const size_t sizeSourceFormats = listSourceFormats.size(); - const size_t sizeSinkFormats = listSinkFormats.size(); - const size_t sizeConvertionMatrix = convertionMatrix.size(); - - if(sizeSourceFormats==0||sizeSinkFormats==0||sizeConvertionMatrix==0||sizeConvertionMatrix!=sizeSinkFormats*sizeSourceFormats) - { - return false; - } - - std::vector::const_iterator iterator = convertionMatrix.begin(); - for (; iterator != convertionMatrix.end(); ++iterator) - { - if( true == *iterator ) - { - const size_t index = iterator-convertionMatrix.begin(); - size_t idx = index%sizeSourceFormats; - sourceFormats.push_back(listSourceFormats.at(idx)); - idx = index/sizeSourceFormats; - sinkFormats.push_back(listSinkFormats.at(idx)); - } - } - return sourceFormats.size()>0; -} + void CAmRouter::listPossibleConnectionFormats(std::vector & inListSourceFormats, + std::vector & inListSinkFormats, std::vector & outListFormats) + { + std::sort(inListSourceFormats.begin(), inListSourceFormats.end()); + std::sort(inListSinkFormats.begin(), inListSinkFormats.end()); + std::insert_iterator > inserter(outListFormats, outListFormats.begin()); + set_intersection(inListSourceFormats.begin(), inListSourceFormats.end(), inListSinkFormats.begin(), inListSinkFormats.end(), inserter); + } -void CAmRouter::listPossibleConnectionFormats(std::vector & inListSourceFormats, - std::vector & inListSinkFormats, - std::vector & outListFormats) -{ - std::sort(inListSourceFormats.begin(), inListSourceFormats.end()); - std::sort(inListSinkFormats.begin(), inListSinkFormats.end()); - std::insert_iterator > inserter(outListFormats, outListFormats.begin()); - set_intersection(inListSourceFormats.begin(), inListSourceFormats.end(), inListSinkFormats.begin(), inListSinkFormats.end(), inserter); -} + bool CAmRouter::getRestrictedOutputFormats(const std::vector & convertionMatrix, const std::vector & listSourceFormats, + const std::vector & listSinkFormats, const am_CustomConnectionFormat_t connectionFormat, + std::vector & listFormats) + { + listFormats.clear(); + std::vector::const_iterator rowSinkIterator = listSinkFormats.begin(); + std::vector::const_iterator matrixIterator = convertionMatrix.begin(); + //find the row number of the sink + rowSinkIterator = find(listSinkFormats.begin(), listSinkFormats.end(), connectionFormat); + int rowNumberSink = rowSinkIterator - listSinkFormats.begin(); -bool CAmRouter::getRestrictedOutputFormats(const std::vector & convertionMatrix, - const std::vector & listSourceFormats, - const std::vector & listSinkFormats, - const am_CustomConnectionFormat_t connectionFormat, - std::vector & listFormats) -{ - listFormats.clear(); - std::vector::const_iterator rowSinkIterator = listSinkFormats.begin(); - std::vector::const_iterator matrixIterator = convertionMatrix.begin(); + //go through the convertionMatrix and find out if the conversion is possible, if yes, add connectionFormat ... + std::advance(matrixIterator, rowNumberSink); - //find the row number of the sink - rowSinkIterator = find(listSinkFormats.begin(), listSinkFormats.end(), connectionFormat); - int rowNumberSink = rowSinkIterator - listSinkFormats.begin(); + //iterate line-wise through the matrix and add more formats + do + { + if (*matrixIterator) + { + listFormats.push_back(listSourceFormats.at((matrixIterator - convertionMatrix.begin()) / listSinkFormats.size())); + } + std::advance(matrixIterator, listSinkFormats.size()); + } while (convertionMatrix.end() - matrixIterator > 0); + + return listFormats.size(); + } - //go through the convertionMatrix and find out if the conversion is possible, if yes, add connectionFormat ... - std::advance(matrixIterator, rowNumberSink); + am_Error_e CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, + std::vector::iterator iteratorSink, std::vector & outConnectionFormats) + { + CAmRoutingNode * nodeSink = *iteratorSink; + if (nodeSink->getData().type != CAmNodeDataType::SINK) + return (E_UNKNOWN); + + CAmRoutingNode * nodeSource = *iteratorSource; + if (nodeSource->getData().type != CAmNodeDataType::SOURCE) + return (E_UNKNOWN); + + am_Source_s *source = nodeSource->getData().data.source; + am_Sink_s *sink = nodeSink->getData().data.sink; + listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats); + return (E_OK); + } - //iterate line-wise through the matrix and add more formats - do + am_Error_e CAmRouter::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, + std::vector> & resultNodesPath, const bool includeCycles, const bool onlyFree) { - if (*matrixIterator) + + if (aSource.getData().type != CAmNodeDataType::SOURCE || aSink.getData().type != CAmNodeDataType::SINK) + return E_NOT_POSSIBLE; + + unsigned cycles; + if (includeCycles) + cycles = UINT_MAX; + else + cycles = 0; + + uint8_t errorsCount = 0, successCount = 0; + const am_sinkID_t sinkID = aSink.getData().data.sink->sinkID; + const am_sourceID_t sourceID = aSource.getData().data.source->sourceID; + std::vector paths; + std::vector visitedDomains; + visitedDomains.push_back(((CAmRoutingNode*) &aSource)->getData().domainID()); + mRoutingGraph.getAllPaths(aSource, aSink, [&visitedDomains, &cycles, &onlyFree, this](const CAmRoutingNode * node)->bool + { + if(CAmRouter::shouldGoInDomain(visitedDomains, node->getData().domainID(), cycles)) + { + const am_RoutingNodeData_s & nodeData = node->getData(); + if(am_RoutingNodeData_s::GATEWAY==nodeData.type) + { + const am_Gateway_s * gateway = nodeData.data.gateway; + return (!onlyFree || !isComponentConnected(*gateway)); + } + else if(am_RoutingNodeData_s::CONVERTER==nodeData.type) + { + const am_Converter_s * converter = nodeData.data.converter; + return (!onlyFree || !isComponentConnected(*converter)); + } + return true; + } + return false; + }, [&visitedDomains](const CAmRoutingNode * node) + { + visitedDomains.push_back(node->getData().domainID()); + }, [&visitedDomains](const CAmRoutingNode * node) + { visitedDomains.erase(visitedDomains.end()-1);}, + [&resultPath, &resultNodesPath, &paths, &errorsCount, &successCount, &sinkID, &sourceID](const std::vector & path) + { + int index = CAmRouter::insertPostion(path, resultNodesPath); + resultNodesPath.emplace(resultNodesPath.begin()+index); + paths.emplace(paths.begin()+index); + resultNodesPath[index] = path; + am_Route_s & nextRoute = paths[index]; + nextRoute.sinkID = sinkID; + nextRoute.sourceID = sourceID; + am_RoutingElement_s * element; + for(auto it = path.begin(); it!=path.end(); it++) + { + am_RoutingNodeData_s & routingData = (*it)->getData(); + if(routingData.type==CAmNodeDataType::SOURCE) + { + auto iter = nextRoute.route.emplace(nextRoute.route.end()); + element = &(*iter); + element->domainID = routingData.data.source->domainID; + element->sourceID = routingData.data.source->sourceID; + element->connectionFormat = CF_UNKNOWN; + } + else if(routingData.type==CAmNodeDataType::SINK) + { + element->domainID = routingData.data.sink->domainID; + element->sinkID = routingData.data.sink->sinkID; + element->connectionFormat = CF_UNKNOWN; + } + } + }); + + for (auto it = paths.begin(); successCount < mMaxPathCount && it != paths.end(); it++) { - listFormats.push_back(listSourceFormats.at((matrixIterator - convertionMatrix.begin()) / listSinkFormats.size())); + if (cfPermutationsForPath(*it, resultNodesPath[it - paths.begin()], resultPath) == E_UNKNOWN) + errorsCount++; + else + successCount++; } - std::advance(matrixIterator, listSinkFormats.size()); - } while (convertionMatrix.end() - matrixIterator > 0); - - return listFormats.size(); -} - - -am_Error_e CAmRouter::getSourceSinkPossibleConnectionFormats(std::vector::iterator iteratorSource, - std::vector::iterator iteratorSink, - std::vector & outConnectionFormats) -{ - CAmRoutingNode * nodeSink = *iteratorSink; - if(nodeSink->getData().type!=CAmNodeDataType::SINK) - return (E_UNKNOWN); - - CAmRoutingNode * nodeSource = *iteratorSource; - if(nodeSource->getData().type!=CAmNodeDataType::SOURCE) - return (E_UNKNOWN); - - am_Source_s *source = nodeSource->getData().data.source; - am_Sink_s *sink = nodeSink->getData().data.sink; - listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats); - return (E_OK); -} + if (successCount) + return E_OK; + if (errorsCount) + return E_NOT_POSSIBLE; + return E_OK; + } } diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp index fbba011..11d8c3c 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.cpp @@ -27,32 +27,32 @@ #include "CAmDltWrapper.h" #include "CAmCommandLineSingleton.h" -TCLAP::SwitchArg enableDebug ("V","logDlt","print DLT logs to stdout or dlt-daemon default off",false); - +TCLAP::SwitchArg enableDebug("V", "logDlt", "print DLT logs to stdout or dlt-daemon default off", false); using namespace am; using namespace testing; CAmRouterMapTest::CAmRouterMapTest() : - plistRoutingPluginDirs(), // - plistCommandPluginDirs(), // - pSocketHandler(), // - pControlSender(), // - pDatabaseHandler(), - pRouter(&pDatabaseHandler, &pControlSender), // - pRoutingSender(plistRoutingPluginDirs,dynamic_cast( &pDatabaseHandler )), // - pCommandSender(plistCommandPluginDirs, &pSocketHandler), // - pMockInterface(), // - pMockControlInterface(), // - pRoutingInterfaceBackdoor(), // - pCommandInterfaceBackdoor(), // - pControlInterfaceBackdoor(), // - pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender,&pSocketHandler, &pRouter) + plistRoutingPluginDirs(), // + plistCommandPluginDirs(), // + pSocketHandler(), // + pControlSender(), // + pDatabaseHandler(), + pRouter(&pDatabaseHandler, &pControlSender), // + pRoutingSender(plistRoutingPluginDirs, dynamic_cast(&pDatabaseHandler)), // + pCommandSender(plistCommandPluginDirs, &pSocketHandler), // + pMockInterface(), // + pMockControlInterface(), // + pRoutingInterfaceBackdoor(), // + pCommandInterfaceBackdoor(), // + pControlInterfaceBackdoor(), // + pControlReceiver(&pDatabaseHandler, &pRoutingSender, &pCommandSender, &pSocketHandler, &pRouter) { - pDatabaseHandler.registerObserver(&pRoutingSender); - pDatabaseHandler.registerObserver(&pCommandSender); - pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); - pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); + pDatabaseHandler.registerObserver(&pRoutingSender); + pDatabaseHandler.registerObserver(&pCommandSender); + pDatabaseHandler.registerObserver(&pRouter); + pCommandInterfaceBackdoor.injectInterface(&pCommandSender, &pMockInterface); + pControlInterfaceBackdoor.replaceController(&pControlSender, &pMockControlInterface); } CAmRouterMapTest::~CAmRouterMapTest() @@ -62,22 +62,22 @@ CAmRouterMapTest::~CAmRouterMapTest() void CAmRouterMapTest::SetUp() { - logInfo("Routing Test started "); - am_Domain_s domain; - pCF.createDomain(domain); + logInfo("Routing Test started "); + am_Domain_s domain; + pCF.createDomain(domain); am_domainID_t forgetDomain; am_sinkClass_t forgetSinkClassID; am_SinkClass_s sinkClass; - sinkClass.name="TestSinkClass"; - sinkClass.sinkClassID=1; + sinkClass.name = "TestSinkClass"; + sinkClass.sinkClassID = 1; am_sourceClass_t forgetSourceClassID; am_SourceClass_s sourceClass; - sourceClass.name="TestSourceClass"; - sourceClass.sourceClassID=1; - domain.domainID=4; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,forgetDomain)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSinkClassDB(sinkClass,forgetSinkClassID)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterSourceClassDB(forgetSourceClassID,sourceClass)); + sourceClass.name = "TestSourceClass"; + sourceClass.sourceClassID = 1; + domain.domainID = 4; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain, forgetDomain)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass, forgetSinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(forgetSourceClassID, sourceClass)); } void CAmRouterMapTest::TearDown() @@ -85,161 +85,146 @@ void CAmRouterMapTest::TearDown() } ACTION(returnConnectionFormat){ - arg4=arg3; +arg4=arg3; } void CAmRouterMapTest::enterDomainDB(const std::string & domainName, am_domainID_t & domainID) { - am_Domain_s domain1; - domain1.domainID = 0; - domain1.name = domainName; - domain1.busname = "domain1bus"; - domain1.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID)); + am_Domain_s domain1; + domain1.domainID = 0; + domain1.name = domainName; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID)); } -void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID) +void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, + const std::vector & connectionFormats, am_sourceID_t & sourceID) { - am_Source_s source; - source.domainID = domainID; - source.name = sourceName; - source.sourceState = SS_ON; - source.sourceID = 0; - source.sourceClassID = 5; - source.listConnectionFormats = connectionFormats; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + am_Source_s source; + source.domainID = domainID; + source.name = sourceName; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); } -void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID) +void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, + const std::vector & connectionFormats, am_sinkID_t & sinkID) { - am_Sink_s sink; - sink.domainID = domainID; - sink.name = sinkName; - sink.sinkID = 0; - sink.sinkClassID = 5; - sink.muteState = MS_MUTED; - sink.listConnectionFormats = connectionFormats; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + am_Sink_s sink; + sink.domainID = domainID; + sink.name = sinkName; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats = connectionFormats; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); } -void CAmRouterMapTest::enterGatewayDB(const std::string & gwName, - const am_domainID_t domainSourceID, - const am_domainID_t domainSinkID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_gatewayID_t & gatewayID) +void CAmRouterMapTest::enterGatewayDB(const std::string & gwName, const am_domainID_t domainSourceID, const am_domainID_t domainSinkID, + const std::vector & sourceConnectionFormats, const std::vector & sinkConnectionFormats, + const std::vector & matrix, const am_sourceID_t & sourceID, const am_sinkID_t & sinkID, am_gatewayID_t & gatewayID) { - am_Gateway_s gateway; - gateway.controlDomainID = domainSourceID; - gateway.gatewayID = 0; - gateway.sinkID = sinkID; - gateway.sourceID = sourceID; - gateway.domainSourceID = domainSourceID; - gateway.domainSinkID = domainSinkID; - gateway.listSinkFormats = sinkConnectionFormats; - gateway.listSourceFormats = sourceConnectionFormats; - gateway.convertionMatrix = matrix; - gateway.name = gwName; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + am_Gateway_s gateway; + gateway.controlDomainID = domainSourceID; + gateway.gatewayID = 0; + gateway.sinkID = sinkID; + gateway.sourceID = sourceID; + gateway.domainSourceID = domainSourceID; + gateway.domainSinkID = domainSinkID; + gateway.listSinkFormats = sinkConnectionFormats; + gateway.listSourceFormats = sourceConnectionFormats; + gateway.convertionMatrix = matrix; + gateway.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); } -void CAmRouterMapTest::enterConverterDB(const std::string & gwName, - const am_domainID_t domainID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_converterID_t & converterID) +void CAmRouterMapTest::enterConverterDB(const std::string & gwName, const am_domainID_t domainID, + const std::vector & sourceConnectionFormats, const std::vector & sinkConnectionFormats, + const std::vector & matrix, const am_sourceID_t & sourceID, const am_sinkID_t & sinkID, am_converterID_t & converterID) { - am_Converter_s converter; - converter.converterID = 0; - converter.sinkID = sinkID; - converter.sourceID = sourceID; - converter.domainID = domainID; - converter.listSinkFormats = sinkConnectionFormats; - converter.listSourceFormats = sourceConnectionFormats; - converter.convertionMatrix = matrix; - converter.name = gwName; - ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter,converterID)); + am_Converter_s converter; + converter.converterID = 0; + converter.sinkID = sinkID; + converter.sourceID = sourceID; + converter.domainID = domainID; + converter.listSinkFormats = sinkConnectionFormats; + converter.listSourceFormats = sourceConnectionFormats; + converter.convertionMatrix = matrix; + converter.name = gwName; + ASSERT_EQ(E_OK, pDatabaseHandler.enterConverterDB(converter, converterID)); } -am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, + std::vector & listRoutes, const unsigned countCycles, const unsigned pathsCount) { - pRouter.setMaxAllowedCycles(countCycles); - pRouter.setMaxPathCount(pathsCount); - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - if(shouldReload) - pRouter.load(onlyfree); - am_Error_e error = pRouter.getRouteFromLoadedNodes(aSource, aSink, listRoutes); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << listRoutes.size() <<" routes from " << aSource.sourceID << " to " << aSink.sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); - return error; + return getRoute(onlyfree, shouldReload, aSource.sourceID, aSink.sinkID, listRoutes, countCycles, pathsCount); } -am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, + std::vector& returnList, const unsigned countCycles, const unsigned pathsCount) { - pRouter.setMaxAllowedCycles(countCycles); - pRouter.setMaxPathCount(pathsCount); - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - if(shouldReload) - pRouter.load(onlyfree); - am_Error_e error = pRouter.getRouteFromLoadedNodes(sourceID, sinkID, returnList); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << returnList.size() <<" routes from " << sourceID << " to " << sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); - return error; + pRouter.setMaxAllowedCycles(countCycles); + pRouter.setMaxPathCount(pathsCount); + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + if (shouldReload) + pRouter.load(); + + am_Error_e error = pRouter.getRoute(onlyfree, sourceID, sinkID, returnList); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << returnList.size() << " routes from " << sourceID << " to " << sinkID; + std::cout << " in " << std::chrono::duration(t_end - t_start).count() << " ms\n"; + std::cout.flags(oldflags); + std::cout.precision(oldprecision); + return error; } -am_Error_e CAmRouterMapTest::getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles, const unsigned pathsCount) +am_Error_e CAmRouterMapTest::getAllPaths(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & resultPath, + const unsigned countCycles, const unsigned pathsCount) { - pRouter.setMaxAllowedCycles(countCycles); - pRouter.setMaxPathCount(pathsCount); - std::ios_base::fmtflags oldflags = std::cout.flags(); - std::streamsize oldprecision = std::cout.precision(); - auto t_start = std::chrono::high_resolution_clock::now(); - am_Error_e error = pRouter.getFirstNShortestPaths(aSource, aSink, resultPath); - auto t_end = std::chrono::high_resolution_clock::now(); - std::cout << std::fixed << std::setprecision(2); - std::cout << resultPath.size() - << " routes from " << aSource.getData().data.source->sourceID - << " to " << aSink.getData().data.sink->sinkID; - std::cout << " in " << std::chrono::duration(t_end-t_start).count() << " ms\n"; - std::cout.flags (oldflags); - std::cout.precision (oldprecision); - return error; + std::ios_base::fmtflags oldflags = std::cout.flags(); + std::streamsize oldprecision = std::cout.precision(); + auto t_start = std::chrono::high_resolution_clock::now(); + if (pRouter.getUpdateGraphNodesAction()) + pRouter.load(); + CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(sourceID); + CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sinkID); + + if (!sourceNode || !sinkNode) + return E_NON_EXISTENT; + + am_Error_e error = pRouter.getFirstNShortestPaths(onlyfree, countCycles, pathsCount, *sourceNode, *sinkNode, resultPath); + auto t_end = std::chrono::high_resolution_clock::now(); + std::cout << std::fixed << std::setprecision(2); + std::cout << resultPath.size() << " routes from " << sourceNode->getData().data.source->sourceID << " to " << sinkNode->getData().data.sink->sinkID; + std::cout << " in " << std::chrono::duration(t_end - t_start).count() << " ms\n"; + std::cout.flags(oldflags); + std::cout.precision(oldprecision); + return error; } TEST_F(CAmRouterMapTest,checkInsertedDomain) { - std::vector domains; - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); - domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); - domains.push_back(22); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50, 0)); - domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); - domains.push_back(30); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); - ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); - ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60, 0)); + std::vector domains; + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + domains.push_back(22); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 50, 0)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + domains.push_back(30); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 30, 0)); + ASSERT_FALSE(CAmRouter::shouldGoInDomain(domains, 22, 0)); + ASSERT_TRUE(CAmRouter::shouldGoInDomain(domains, 60, 0)); } //test that checks just sinks and source in a domain but connectionformats do not match @@ -256,14 +241,14 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) domain1.busname = "domain1bus"; domain1.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); am_Source_s source; am_sourceID_t sourceID; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -272,15 +257,14 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) source.sourceClassID = 5; source.listConnectionFormats.push_back(CF_GENIVI_MONO); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); am_Sink_s sink; am_sinkID_t sinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID1; sink.name = "sink1"; @@ -289,8 +273,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); std::vector listRoutes; std::vector listRoutingElements; @@ -309,12 +293,12 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(true, false, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); } //test that checks just sinks and source in a domain @@ -331,14 +315,14 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) domain1.busname = "domain1bus"; domain1.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); am_Source_s source; am_sourceID_t sourceID; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -347,15 +331,14 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) source.sourceClassID = 5; source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); am_Sink_s sink; am_sinkID_t sinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID1; sink.name = "sink1"; @@ -364,8 +347,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); std::vector listRoutes; std::vector listRoutingElements; @@ -384,13 +367,13 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(true, false, sourceDb, sinkDb, listRoutes), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks just 2 domains, one sink one source with only one connection format each @@ -411,15 +394,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) domain2.busname = "domain2bus"; domain2.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); am_Source_s source, gwSource; am_sourceID_t sourceID, gwSourceID; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -435,15 +418,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) gwSource.sourceClassID = 5; gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); am_Sink_s sink, gwSink; am_sinkID_t sinkID, gwSinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID2; sink.name = "sink1"; @@ -459,9 +442,9 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) gwSink.muteState = MS_MUTED; gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); am_Gateway_s gateway; am_gatewayID_t gatewayID; @@ -477,7 +460,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) gateway.convertionMatrix.push_back(true); gateway.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); std::vector listRoutes; std::vector listRoutingElements; @@ -507,12 +490,11 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree) pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(true, true,sourceID,sinkID,listRoutes), E_OK); + ASSERT_EQ(getRoute(true, false, sourceID, sinkID, listRoutes), E_OK); ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } - //test that checks just 2 domains, one sink one source with only one connection format each TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) { @@ -531,15 +513,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) domain2.busname = "domain2bus"; domain2.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); am_Source_s source, gwSource; am_sourceID_t sourceID, gwSourceID; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -555,16 +537,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) gwSource.sourceClassID = 5; gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); am_Sink_s sink, gwSink; am_sinkID_t sinkID, gwSinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID2; sink.name = "sink1"; @@ -580,9 +561,9 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) gwSink.muteState = MS_MUTED; gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); am_Gateway_s gateway; am_gatewayID_t gatewayID; @@ -598,7 +579,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) gateway.convertionMatrix.push_back(true); gateway.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); std::vector listRoutes; std::vector listRoutingElements; @@ -623,32 +604,32 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree) compareRoute.sinkID = sinkID; compareRoute.sourceID = sourceID; - am_Connection_s connection,connection1; - am_connectionID_t id1,id2; - connection.sourceID=sourceID; - connection.sinkID=gwSinkID; - connection.connectionFormat=CF_GENIVI_ANALOG; - connection.connectionID=0; - connection1.sourceID=gwSourceID; - connection1.sinkID=sinkID; - connection1.connectionFormat=CF_GENIVI_ANALOG; - connection1.connectionID=0; + am_Connection_s connection, connection1; + am_connectionID_t id1, id2; + connection.sourceID = sourceID; + connection.sinkID = gwSinkID; + connection.connectionFormat = CF_GENIVI_ANALOG; + connection.connectionID = 0; + connection1.sourceID = gwSourceID; + connection1.sinkID = sinkID; + connection1.connectionFormat = CF_GENIVI_ANALOG; + connection1.connectionID = 0; - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,id1)); - ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection1,id2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection, id1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterConnectionDB(connection1, id2)); am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - listRoutes.clear(); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(true, false, sourceDb, sinkDb, listRoutes), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + listRoutes.clear(); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks just 2 domains, with gateway for each direction (possible circular route) @@ -669,15 +650,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) domain2.busname = "domain2bus"; domain2.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); am_Source_s source, gwSource, gwSource2; am_sourceID_t sourceID, gwSourceID, gwSourceID2; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -700,16 +681,16 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) gwSource2.sourceClassID = 5; gwSource2.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2, gwSourceID2)); am_Sink_s sink, gwSink, gwSink2; am_sinkID_t sinkID, gwSinkID, gwSinkID2; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID2; sink.name = "sink1"; @@ -732,10 +713,10 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) gwSink2.muteState = MS_MUTED; gwSink2.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2, gwSinkID2)); am_Gateway_s gateway, gateway2; am_gatewayID_t gatewayID, gatewayID2; @@ -762,8 +743,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) gateway2.convertionMatrix.push_back(true); gateway2.name = "gateway2"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2, gatewayID2)); std::vector listRoutes; std::vector listRoutingElements; @@ -789,13 +770,13 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(true, true, sourceDb, sinkDb, listRoutes), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(true, false, sourceDb, sinkDb, listRoutes), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks 3 domains, one sink one source, longer lists of connectionformats. @@ -820,17 +801,16 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) domain3.busname = "domain3bus"; domain3.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); am_Source_s source, gwSource, gwSource1; am_sourceID_t sourceID, gwSourceID, gwSourceID1; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; - + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -857,10 +837,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) gwSource1.listConnectionFormats.push_back(CF_GENIVI_STEREO); gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); am_Sink_s sink, gwSink, gwSink1; am_sinkID_t sinkID, gwSinkID, gwSinkID1; @@ -872,8 +852,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_MONO); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; gwSink.domainID = domainID1; gwSink.name = "gwSink"; @@ -891,10 +871,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); gwSink1.listConnectionFormats.push_back(CF_GENIVI_STEREO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); am_Gateway_s gateway, gateway1; am_gatewayID_t gatewayID, gatewayID1; @@ -929,8 +909,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) gateway1.convertionMatrix.push_back(true); gateway1.name = "gateway1"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); std::vector listRoutes; std::vector listRoutingElements; @@ -963,12 +943,12 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks 3 domains, one sink one source, longer lists of connectionformats. @@ -993,9 +973,9 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) domain3.busname = "domain3bus"; domain3.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); am_Source_s source, gwSource, gwSource1; am_sourceID_t sourceID, gwSourceID, gwSourceID1; @@ -1009,8 +989,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) source.listConnectionFormats.push_back(CF_GENIVI_MONO); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; gwSource.domainID = domainID2; gwSource.name = "gwsource1"; @@ -1028,16 +1008,16 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) gwSource1.sourceClassID = 5; gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); am_Sink_s sink, gwSink, gwSink1; am_sinkID_t sinkID, gwSinkID, gwSinkID1; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID3; sink.name = "sink1"; @@ -1061,10 +1041,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) gwSink1.muteState = MS_MUTED; gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); am_Gateway_s gateway, gateway1; am_gatewayID_t gatewayID, gatewayID1; @@ -1096,8 +1076,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) gateway1.convertionMatrix.push_back(true); gateway1.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); std::vector listRoutes; std::vector listRoutingElements; @@ -1130,12 +1110,12 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks 3 domains, one sink one source, longer lists of connectionformats. @@ -1160,16 +1140,16 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) domain3.busname = "domain3bus"; domain3.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); am_Source_s source, gwSource, gwSource1; am_sourceID_t sourceID, gwSourceID, gwSourceID1; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -1193,17 +1173,17 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) gwSource1.sourceClassID = 5; gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); am_Sink_s sink, gwSink, gwSink1; am_sinkID_t sinkID, gwSinkID, gwSinkID1; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID3; sink.name = "sink1"; @@ -1227,10 +1207,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) gwSink1.muteState = MS_MUTED; gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); am_Gateway_s gateway, gateway1; am_gatewayID_t gatewayID, gatewayID1; @@ -1258,8 +1238,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) gateway1.convertionMatrix.push_back(true); gateway1.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); std::vector listRoutes; std::vector listRoutingElements; @@ -1292,12 +1272,12 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks 4 domains, one sink and one source but there are 2 routes because there are 2 gateways @@ -1326,17 +1306,17 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) domain4.busname = "domain4bus"; domain4.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4, domainID4)); am_Source_s source, gwSource, gwSource1, gwSource2, gwSource3; am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2, gwSourceID3; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -1373,12 +1353,12 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) gwSource3.sourceClassID = 5; gwSource3.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3,gwSourceID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2, gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource3, gwSourceID3)); am_Sink_s sink, gwSink, gwSink1, gwSink2, gwSink3; am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2, gwSinkID3; @@ -1418,15 +1398,15 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3,gwSinkID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2, gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink3, gwSinkID3)); am_Gateway_s gateway, gateway1, gateway2, gateway3; am_gatewayID_t gatewayID, gatewayID1, gatewayID2, gatewayID3; @@ -1475,10 +1455,10 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) gateway3.convertionMatrix.push_back(true); gateway3.name = "gateway3"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3,gatewayID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2, gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway3, gatewayID3)); std::vector listRoutes; std::vector listRoutingElements, listRoutingElements1; @@ -1538,20 +1518,22 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes) compareRoute1.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(2), listRoutes.size()); - - bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { - return pCF.compareRoute(compareRoute, ref); - })!=listRoutes.end(); - bool containsRoute2 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) { - return pCF.compareRoute(compareRoute1, ref); - })!=listRoutes.end(); - - ASSERT_TRUE(containsRoute1); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + bool containsRoute1 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) + { + return pCF.compareRoute(compareRoute, ref); + }) != listRoutes.end(); + bool containsRoute2 = std::find_if(listRoutes.begin(), listRoutes.end(), [&](const am_Route_s & ref) + { + return pCF.compareRoute(compareRoute1, ref); + }) != listRoutes.end(); + + ASSERT_TRUE(containsRoute1); ASSERT_TRUE(containsRoute2); } @@ -1577,9 +1559,9 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) domain3.busname = "domain3bus"; domain3.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); am_Source_s source, gwSource, gwSource1; am_sourceID_t sourceID, gwSourceID, gwSourceID1; @@ -1592,8 +1574,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) source.listConnectionFormats.push_back(CF_GENIVI_MONO); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; gwSource.domainID = domainID2; gwSource.name = "gwsource1"; @@ -1609,10 +1591,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) gwSource1.sourceClassID = 5; gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); am_Sink_s sink, gwSink, gwSink1; am_sinkID_t sinkID, gwSinkID, gwSinkID1; @@ -1624,8 +1606,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; gwSink.domainID = domainID1; gwSink.name = "gwSink"; @@ -1641,10 +1623,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) gwSink1.muteState = MS_MUTED; gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); am_Gateway_s gateway, gateway1; am_gatewayID_t gatewayID, gatewayID1; @@ -1671,8 +1653,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) gateway1.convertionMatrix.push_back(true); gateway1.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); std::vector listRoutes; std::vector listRoutingElements; @@ -1705,12 +1687,12 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); } //test that checks just 2 domains, one sink one source with only one connection format each @@ -1731,8 +1713,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) domain2.busname = "domain2bus"; domain2.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); am_Source_s source, gwSource; am_sourceID_t sourceID, gwSourceID; @@ -1745,8 +1727,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) source.listConnectionFormats.push_back(CF_GENIVI_ANALOG); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; gwSource.domainID = domainID2; gwSource.name = "gwsource1"; @@ -1755,16 +1737,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) gwSource.sourceClassID = 5; gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); am_Sink_s sink, gwSink; am_sinkID_t sinkID, gwSinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID2; sink.name = "sink1"; @@ -1780,10 +1761,9 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) gwSink.muteState = MS_MUTED; gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); am_Gateway_s gateway; am_gatewayID_t gatewayID; @@ -1799,7 +1779,7 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) gateway.convertionMatrix.push_back(true); gateway.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); std::vector listRoutes; std::vector listRoutingElements; @@ -1825,12 +1805,12 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks just 2 domains, one sink one source but the connectionformat of source @@ -1851,8 +1831,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) domain2.busname = "domain2bus"; domain2.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); am_Source_s source, gwSource; am_sourceID_t sourceID, gwSourceID; @@ -1865,8 +1845,8 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) source.listConnectionFormats.push_back(CF_GENIVI_STEREO); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; gwSource.domainID = domainID2; gwSource.name = "gwsource1"; @@ -1875,15 +1855,15 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) gwSource.sourceClassID = 5; gwSource.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); am_Sink_s sink, gwSink; am_sinkID_t sinkID, gwSinkID; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID2; sink.name = "sink1"; @@ -1899,9 +1879,9 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) gwSink.muteState = MS_MUTED; gwSink.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); am_Gateway_s gateway; am_gatewayID_t gatewayID; @@ -1917,17 +1897,17 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats) gateway.convertionMatrix.push_back(true); gateway.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); std::vector listRoutes; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); - } + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); +} //test that checks 3 domains, one sink one source. TEST_F(CAmRouterMapTest,simpleRoute3Domains) @@ -1951,16 +1931,16 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) domain3.busname = "domain3bus"; domain3.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); am_Source_s source, gwSource, gwSource1; am_sourceID_t sourceID, gwSourceID, gwSourceID1; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -1983,17 +1963,16 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) gwSource1.sourceClassID = 5; gwSource1.listConnectionFormats.push_back(CF_GENIVI_MONO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); am_Sink_s sink, gwSink, gwSink1; am_sinkID_t sinkID, gwSinkID, gwSinkID1; am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; sink.domainID = domainID3; sink.name = "sink1"; @@ -2016,10 +1995,10 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) gwSink1.muteState = MS_MUTED; gwSink1.listConnectionFormats.push_back(CF_GENIVI_ANALOG); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); am_Gateway_s gateway, gateway1; am_gatewayID_t gatewayID, gatewayID1; @@ -2046,8 +2025,8 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) gateway1.convertionMatrix.push_back(true); gateway1.name = "gateway"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); std::vector listRoutes; std::vector listRoutingElements; @@ -2080,13 +2059,13 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } //test that checks 4 domains, one sink and one source. @@ -2115,17 +2094,17 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) domain4.busname = "domain4bus"; domain4.state = DS_CONTROLLED; - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3,domainID3)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4,domainID4)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1, domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2, domainID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain3, domainID3)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain4, domainID4)); am_Source_s source, gwSource, gwSource1, gwSource2; am_sourceID_t sourceID, gwSourceID, gwSourceID1, gwSourceID2; am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; source.domainID = domainID1; source.name = "source1"; @@ -2155,11 +2134,11 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) gwSource2.sourceClassID = 5; gwSource2.listConnectionFormats.push_back(CF_GENIVI_STEREO); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID,sourceclass)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1,gwSourceID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2,gwSourceID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(source.sourceClassID, sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source, sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource, gwSourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource1, gwSourceID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource2, gwSourceID2)); am_Sink_s sink, gwSink, gwSink1, gwSink2; am_sinkID_t sinkID, gwSinkID, gwSinkID1, gwSinkID2; @@ -2192,14 +2171,14 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) sink.muteState = MS_MUTED; sink.listConnectionFormats.push_back(CF_GENIVI_STEREO); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1,gwSinkID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2,gwSinkID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink, sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink, gwSinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink1, gwSinkID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink2, gwSinkID2)); am_Gateway_s gateway, gateway1, gateway2; am_gatewayID_t gatewayID, gatewayID1, gatewayID2; @@ -2237,9 +2216,9 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) gateway2.convertionMatrix.push_back(true); gateway2.name = "gateway2"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1,gatewayID1)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2,gatewayID2)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway, gatewayID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway1, gatewayID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway2, gatewayID2)); std::vector listRoutes; std::vector listRoutingElements; @@ -2279,112 +2258,112 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains) compareRoute.sourceID = sourceID; am::am_Source_s sourceDb; - am::am_Sink_s sinkDb; - pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); - pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); - listRoutes.clear(); - ASSERT_EQ(getRoute(false, true, sourceDb, sinkDb, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + am::am_Sink_s sinkDb; + pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb); + pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb); + listRoutes.clear(); + ASSERT_EQ(getRoute(false, false, sourceDb, sinkDb, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } TEST_F(CAmRouterMapTest,getAllowedFormatsFromConvMatrix) { - std::vector convertionMatrix; - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - convertionMatrix.push_back(0); - convertionMatrix.push_back(1); - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - - std::vector listSourceFormats; - listSourceFormats.push_back(CF_GENIVI_ANALOG); - listSourceFormats.push_back(CF_GENIVI_STEREO); - - std::vector listSinkFormats; - listSinkFormats.push_back(CF_GENIVI_MONO); - listSinkFormats.push_back(CF_GENIVI_AUTO); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - std::vector sourceFormats; - std::vector sinkFormats; - - ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - ASSERT_TRUE(sourceFormats.size()==3); - ASSERT_TRUE(sinkFormats.size()==3); - ASSERT_TRUE(sourceFormats.at(0)==CF_GENIVI_ANALOG); - ASSERT_TRUE(sourceFormats.at(1)==CF_GENIVI_STEREO); - ASSERT_TRUE(sourceFormats.at(2)==CF_GENIVI_ANALOG); - ASSERT_TRUE(sinkFormats.at(0)==CF_GENIVI_MONO); - ASSERT_TRUE(sinkFormats.at(1)==CF_GENIVI_AUTO); - ASSERT_TRUE(sinkFormats.at(2)==CF_GENIVI_STEREO); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - listSinkFormats.push_back(CF_GENIVI_STEREO); - listSourceFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - convertionMatrix.push_back(0); - listSourceFormats.push_back(CF_GENIVI_STEREO); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); - - sinkFormats.clear(); - sourceFormats.clear(); - convertionMatrix.clear(); - listSinkFormats.clear(); - listSourceFormats.clear(); - - convertionMatrix.push_back(1); - listSinkFormats.push_back(CF_GENIVI_STEREO); - - ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + std::vector convertionMatrix; + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + convertionMatrix.push_back(0); + convertionMatrix.push_back(1); + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + + std::vector listSourceFormats; + listSourceFormats.push_back(CF_GENIVI_ANALOG); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + std::vector listSinkFormats; + listSinkFormats.push_back(CF_GENIVI_MONO); + listSinkFormats.push_back(CF_GENIVI_AUTO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + std::vector sourceFormats; + std::vector sinkFormats; + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + ASSERT_TRUE(sourceFormats.size() == 3); + ASSERT_TRUE(sinkFormats.size() == 3); + ASSERT_TRUE(sourceFormats.at(0) == CF_GENIVI_ANALOG); + ASSERT_TRUE(sourceFormats.at(1) == CF_GENIVI_STEREO); + ASSERT_TRUE(sourceFormats.at(2) == CF_GENIVI_ANALOG); + ASSERT_TRUE(sinkFormats.at(0) == CF_GENIVI_MONO); + ASSERT_TRUE(sinkFormats.at(1) == CF_GENIVI_AUTO); + ASSERT_TRUE(sinkFormats.at(2) == CF_GENIVI_STEREO); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + listSourceFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_TRUE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + convertionMatrix.push_back(0); + listSourceFormats.push_back(CF_GENIVI_STEREO); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); + + sinkFormats.clear(); + sourceFormats.clear(); + convertionMatrix.clear(); + listSinkFormats.clear(); + listSourceFormats.clear(); + + convertionMatrix.push_back(1); + listSinkFormats.push_back(CF_GENIVI_STEREO); + + ASSERT_FALSE(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, listSourceFormats, listSinkFormats, sourceFormats, sinkFormats)); } TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - cf1.push_back(CF_GENIVI_ANALOG); + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_ANALOG); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); - enterSourceDB("source1", domainID1, cf1, sourceID); + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); + enterSourceDB("source1", domainID1, cf1, sourceID); - am_sinkID_t sinkID; - std::vector cf2; - cf2.push_back(CF_GENIVI_ANALOG); - cf2.push_back(CF_GENIVI_MONO); + am_sinkID_t sinkID; + std::vector cf2; + cf2.push_back(CF_GENIVI_ANALOG); + cf2.push_back(CF_GENIVI_MONO); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - enterSinkDB("sink1", domainID1, cf2, sinkID); + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + enterSinkDB("sink1", domainID1, cf2, sinkID); am::am_Source_s source; am::am_Sink_s sink; @@ -2393,75 +2372,74 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Sink) pDatabaseHandler.getSourceInfoDB(sourceID, source); std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; + std::vector listRoutingElements; + am_RoutingElement_s hopp1; - hopp1.sourceID = sourceID; - hopp1.sinkID = sinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = cf2[0]; + hopp1.sourceID = sourceID; + hopp1.sinkID = sinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = cf2[0]; - listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp1); - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID; - compareRoute.sourceID = sourceID; + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID; + compareRoute.sourceID = sourceID; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - cf1.push_back(CF_GENIVI_AUTO); + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + cf1.push_back(CF_GENIVI_AUTO); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); - enterSourceDB("source1", domainID1, cf1, sourceID); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); + enterSourceDB("source1", domainID1, cf1, sourceID); - am_sinkID_t sinkID1, sinkID2; - std::vector cf2; - cf2.push_back(CF_GENIVI_MONO); - cf2.push_back(CF_GENIVI_ANALOG); + am_sinkID_t sinkID1, sinkID2; + std::vector cf2; + cf2.push_back(CF_GENIVI_MONO); + cf2.push_back(CF_GENIVI_ANALOG); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - enterSinkDB("sink1", domainID1, cf2, sinkID1); - enterSinkDB("sink2", domainID1, cf2, sinkID2); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + enterSinkDB("sink1", domainID1, cf2, sinkID1); + enterSinkDB("sink2", domainID1, cf2, sinkID2); - am_sourceID_t gwSourceID; - std::vector cf3; - cf3.push_back(CF_GENIVI_MONO); - cf3.push_back(CF_GENIVI_ANALOG); - enterSourceDB("gwSource1", domainID1, cf3, gwSourceID); + am_sourceID_t gwSourceID; + std::vector cf3; + cf3.push_back(CF_GENIVI_MONO); + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID1, cf3, gwSourceID); - am_sinkID_t gwSinkID; - std::vector cf4; - cf4.push_back(CF_GENIVI_STEREO); - cf4.push_back(CF_GENIVI_ANALOG); - enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + am_sinkID_t gwSinkID; + std::vector cf4; + cf4.push_back(CF_GENIVI_STEREO); + cf4.push_back(CF_GENIVI_ANALOG); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); am_converterID_t converterID; std::vector matrix; matrix.resize(4, false); - matrix[0]=(true); - matrix[1]=(true); + matrix[0] = (true); + matrix[1] = (true); enterConverterDB("converter", domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, converterID); am::am_Source_s source; @@ -2471,87 +2449,86 @@ TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink) pDatabaseHandler.getSourceInfoDB(sourceID, source); std::vector listRoutes; - std::vector listRoutingElements; - am_RoutingElement_s hopp1; - am_RoutingElement_s hopp2; - - hopp1.sourceID = sourceID; - hopp1.sinkID = gwSinkID; - hopp1.domainID = domainID1; - hopp1.connectionFormat = CF_GENIVI_STEREO; - - hopp2.sourceID = gwSourceID; - hopp2.sinkID = sinkID1; - hopp2.domainID = domainID1; - hopp2.connectionFormat = CF_GENIVI_MONO; - - listRoutingElements.push_back(hopp1); - listRoutingElements.push_back(hopp2); - - am_Route_s compareRoute; - compareRoute.route = listRoutingElements; - compareRoute.sinkID = sinkID1; - compareRoute.sourceID = sourceID; - - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0])); + std::vector listRoutingElements; + am_RoutingElement_s hopp1; + am_RoutingElement_s hopp2; + + hopp1.sourceID = sourceID; + hopp1.sinkID = gwSinkID; + hopp1.domainID = domainID1; + hopp1.connectionFormat = CF_GENIVI_STEREO; + + hopp2.sourceID = gwSourceID; + hopp2.sinkID = sinkID1; + hopp2.domainID = domainID1; + hopp2.connectionFormat = CF_GENIVI_MONO; + + listRoutingElements.push_back(hopp1); + listRoutingElements.push_back(hopp2); + + am_Route_s compareRoute; + compareRoute.route = listRoutingElements; + compareRoute.sinkID = sinkID1; + compareRoute.sourceID = sourceID; + + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute, listRoutes[0])); } TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - am_domainID_t domainID1; - enterDomainDB("domain1", domainID1); + am_domainID_t domainID1; + enterDomainDB("domain1", domainID1); - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - std::vector cf2; - cf2.push_back(CF_GENIVI_MONO); - std::vector cf3; - cf3.push_back(CF_GENIVI_AUTO); + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + std::vector cf2; + cf2.push_back(CF_GENIVI_MONO); + std::vector cf3; + cf3.push_back(CF_GENIVI_AUTO); - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cf1, sourceID); + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cf1, sourceID); - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID1, cf3, sinkID); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cf3, sinkID); - am_sourceID_t gwSourceID; - enterSourceDB("gwSource1", domainID1, cf2, gwSourceID); - am_sinkID_t gwSinkID; - enterSinkDB("gwSink1", domainID1, cf1, gwSinkID); + am_sourceID_t gwSourceID; + enterSourceDB("gwSource1", domainID1, cf2, gwSourceID); + am_sinkID_t gwSinkID; + enterSinkDB("gwSink1", domainID1, cf1, gwSinkID); am_converterID_t converterID; std::vector matrix; matrix.push_back(true); enterConverterDB("converter1", domainID1, cf2, cf1, matrix, gwSourceID, gwSinkID, converterID); - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource2", domainID1, cf2, gwSourceID1); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink2", domainID1, cf1, gwSinkID1); + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource2", domainID1, cf2, gwSourceID1); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink2", domainID1, cf1, gwSinkID1); am_converterID_t converterID1; enterConverterDB("converter2", domainID1, cf2, cf1, matrix, gwSourceID1, gwSinkID1, converterID1); - am_sourceID_t gwSourceID2; - enterSourceDB("gwSource3", domainID1, cf3, gwSourceID2); - am_sinkID_t gwSinkID2; - enterSinkDB("gwSink3", domainID1, cf2, gwSinkID2); + am_sourceID_t gwSourceID2; + enterSourceDB("gwSource3", domainID1, cf3, gwSourceID2); + am_sinkID_t gwSinkID2; + enterSinkDB("gwSink3", domainID1, cf2, gwSinkID2); am_converterID_t converterID2; enterConverterDB("converter3", domainID1, cf3, cf2, matrix, gwSourceID2, gwSinkID2, converterID2); @@ -2560,106 +2537,104 @@ TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink) pDatabaseHandler.getSinkInfoDB(sinkID, sink); pDatabaseHandler.getSourceInfoDB(sourceID, source); - std::vector listRoutes; - std::vector listRoutingElements1; - std::vector listRoutingElements2; - am_RoutingElement_s hopp11; - am_RoutingElement_s hopp12; - am_RoutingElement_s hopp13; - am_RoutingElement_s hopp21; - am_RoutingElement_s hopp22; - - hopp11.sourceID = sourceID; - hopp11.sinkID = gwSinkID; - hopp11.domainID = domainID1; - hopp11.connectionFormat = CF_GENIVI_STEREO; - - hopp12.sourceID = gwSourceID; - hopp12.sinkID = gwSinkID2; - hopp12.domainID = domainID1; - hopp12.connectionFormat = CF_GENIVI_MONO; - - hopp21.sourceID = sourceID; - hopp21.sinkID = gwSinkID1; - hopp21.domainID = domainID1; - hopp21.connectionFormat = CF_GENIVI_STEREO; - - hopp22.sourceID = gwSourceID1; - hopp22.sinkID = gwSinkID2; - hopp22.domainID = domainID1; - hopp22.connectionFormat = CF_GENIVI_MONO; - - hopp13.sourceID = gwSourceID2; - hopp13.sinkID = sinkID; - hopp13.domainID = domainID1; - hopp13.connectionFormat = CF_GENIVI_AUTO; - - listRoutingElements1.push_back(hopp11); - listRoutingElements1.push_back(hopp12); - listRoutingElements1.push_back(hopp13); - - listRoutingElements2.push_back(hopp21); - listRoutingElements2.push_back(hopp22); - listRoutingElements2.push_back(hopp13); - - am_Route_s compareRoute1; - compareRoute1.route = listRoutingElements1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(2), listRoutes.size()); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])||pCF.compareRoute(compareRoute1,listRoutes[1])); - - am_Route_s compareRoute2; - compareRoute2.route = listRoutingElements2; - compareRoute2.sinkID = sinkID; - compareRoute2.sourceID = sourceID; - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1])||pCF.compareRoute(compareRoute2,listRoutes[0])); + std::vector listRoutingElements1; + std::vector listRoutingElements2; + am_RoutingElement_s hopp11; + am_RoutingElement_s hopp12; + am_RoutingElement_s hopp13; + am_RoutingElement_s hopp21; + am_RoutingElement_s hopp22; + + hopp11.sourceID = sourceID; + hopp11.sinkID = gwSinkID; + hopp11.domainID = domainID1; + hopp11.connectionFormat = CF_GENIVI_STEREO; + + hopp12.sourceID = gwSourceID; + hopp12.sinkID = gwSinkID2; + hopp12.domainID = domainID1; + hopp12.connectionFormat = CF_GENIVI_MONO; + + hopp21.sourceID = sourceID; + hopp21.sinkID = gwSinkID1; + hopp21.domainID = domainID1; + hopp21.connectionFormat = CF_GENIVI_STEREO; + + hopp22.sourceID = gwSourceID1; + hopp22.sinkID = gwSinkID2; + hopp22.domainID = domainID1; + hopp22.connectionFormat = CF_GENIVI_MONO; + + hopp13.sourceID = gwSourceID2; + hopp13.sinkID = sinkID; + hopp13.domainID = domainID1; + hopp13.connectionFormat = CF_GENIVI_AUTO; + + listRoutingElements1.push_back(hopp11); + listRoutingElements1.push_back(hopp12); + listRoutingElements1.push_back(hopp13); + + listRoutingElements2.push_back(hopp21); + listRoutingElements2.push_back(hopp22); + listRoutingElements2.push_back(hopp13); + + am_Route_s compareRoute1; + compareRoute1.route = listRoutingElements1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(2), listRoutes.size()); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0]) || pCF.compareRoute(compareRoute1, listRoutes[1])); + + am_Route_s compareRoute2; + compareRoute2.route = listRoutingElements2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + ASSERT_TRUE(pCF.compareRoute(compareRoute2, listRoutes[1]) || pCF.compareRoute(compareRoute2, listRoutes[0])); } TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); - am_sourceID_t sourceID; - std::vector cf1; - cf1.push_back(CF_GENIVI_STEREO); - enterSourceDB("source1", domainID1, cf1, sourceID); + am_sourceID_t sourceID; + std::vector cf1; + cf1.push_back(CF_GENIVI_STEREO); + enterSourceDB("source1", domainID1, cf1, sourceID); - am_sinkID_t sinkID; - std::vector cf2; - cf2.push_back(CF_GENIVI_ANALOG); - enterSinkDB("sink1", domainID2, cf2, sinkID); + am_sinkID_t sinkID; + std::vector cf2; + cf2.push_back(CF_GENIVI_ANALOG); + enterSinkDB("sink1", domainID2, cf2, sinkID); - am_sourceID_t gwSourceID; - std::vector cf3; - cf3.push_back(CF_GENIVI_ANALOG); - enterSourceDB("gwSource1", domainID2, cf3, gwSourceID); + am_sourceID_t gwSourceID; + std::vector cf3; + cf3.push_back(CF_GENIVI_ANALOG); + enterSourceDB("gwSource1", domainID2, cf3, gwSourceID); - am_sinkID_t gwSinkID; - std::vector cf4; - cf4.push_back(CF_GENIVI_STEREO); - enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); + am_sinkID_t gwSinkID; + std::vector cf4; + cf4.push_back(CF_GENIVI_STEREO); + enterSinkDB("gwSink1", domainID1, cf4, gwSinkID); am_gatewayID_t gatewayID; std::vector matrix; @@ -2673,58 +2648,59 @@ TEST_F(CAmRouterMapTest,route2Domains1Source1Sink) pDatabaseHandler.getSourceInfoDB(sourceID, source); std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID, sinkID, domainID2, CF_GENIVI_ANALOG}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, gwSinkID, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID, sinkID, domainID2, CF_GENIVI_ANALOG }); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); } TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - am_domainID_t domainID1, domainID2, domainID3; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - enterDomainDB("domain3", domainID3); + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); - std::vector matrix; - matrix.push_back(true); + std::vector matrix; + matrix.push_back(true); am_gatewayID_t gatewayID; enterGatewayDB("gateway", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); @@ -2735,8 +2711,8 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) am_sinkID_t gwSinkID2; enterSinkDB("gwSink2", domainID2, cfMono, gwSinkID2); - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID3, cfStereo, sinkID); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); am_gatewayID_t gatewayID1; enterGatewayDB("gateway", domainID3, domainID2, cfStereo, cfMono, matrix, gwSourceID2, gwSinkID2, gatewayID1); @@ -2749,65 +2725,67 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1Sink) std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID1, gwSinkID2, domainID2, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID2, sinkID, domainID3, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID1, gwSinkID2, domainID2, CF_GENIVI_MONO }); + compareRoute1.route.push_back( + { gwSourceID2, sinkID, domainID3, CF_GENIVI_STEREO }); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); } TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1); - am_sinkID_t coSinkID21; + am_sinkID_t coSinkID21; enterSinkDB("coSink21", domainID1, cfStereo, coSinkID21); - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID1, cfMono, coSourceID21); + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID1, cfMono, coSourceID21); - am_converterID_t converterID1; - enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1); + am_converterID_t converterID1; + enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1); am_sourceID_t gwSourceID1; enterSourceDB("gwSource21", domainID2, cfAuto, gwSourceID1); @@ -2815,11 +2793,11 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) am_gatewayID_t gatewayID; enterGatewayDB("gateway1", domainID2, domainID1, cfAuto, cfMono, matrix, gwSourceID1, gwSinkID1, gatewayID); - am_sinkID_t sinkID1; - enterSinkDB("sink1", domainID2, cfAuto, sinkID1); + am_sinkID_t sinkID1; + enterSinkDB("sink1", domainID2, cfAuto, sinkID1); - am_sinkID_t sinkID2; - enterSinkDB("sink2", domainID1, cfAuto, sinkID2); + am_sinkID_t sinkID2; + enterSinkDB("sink2", domainID1, cfAuto, sinkID2); am::am_Source_s source; am::am_Sink_s sink1; @@ -2830,76 +2808,78 @@ TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1) std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID1; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, coSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({coSourceID21, gwSinkID1, domainID1, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID1, sinkID1, domainID2, CF_GENIVI_AUTO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_EQ(getRoute(false, false, source, sink1, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); - listRoutes.clear(); - ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID1; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, coSinkID21, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { coSourceID21, gwSinkID1, domainID1, CF_GENIVI_MONO }); + compareRoute1.route.push_back( + { gwSourceID1, sinkID1, domainID2, CF_GENIVI_AUTO }); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); + + listRoutes.clear(); + ASSERT_EQ(getRoute(false, false, source, sink2, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); } TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID11; + am_sinkID_t gwSinkID11; enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); - am_sourceID_t gwSourceID11; - enterSourceDB("gwSource11", domainID2, cfAnalog, gwSourceID11); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID11, gwSinkID11, gatewayID1); + am_sourceID_t gwSourceID11; + enterSourceDB("gwSource11", domainID2, cfAnalog, gwSourceID11); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID11, gwSinkID11, gatewayID1); - am_sinkID_t gwSinkID21; + am_sinkID_t gwSinkID21; enterSinkDB("gwSink21", domainID2, cfAnalog, gwSinkID21); am_sourceID_t gwSourceID12; enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); am_gatewayID_t gatewayID2; enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfAnalog, matrix, gwSourceID12, gwSinkID21, gatewayID2); - am_sinkID_t sink1ID; - enterSinkDB("sink1", domainID1, cfAuto, sink1ID); - am_sinkID_t sink2ID; - enterSinkDB("sink2", domainID2, cfAnalog, sink2ID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfAnalog, sink2ID); std::vector listRoutes; @@ -2908,90 +2888,91 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2) pDatabaseHandler.getSinkInfoDB(sink1ID, sink1); pDatabaseHandler.getSourceInfoDB(sourceID, source); - ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink1, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(sink2ID, sink2); - ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(1), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink2, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); - am_Route_s compareRoute1; - compareRoute1.sinkID = sink2ID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID11, sink2ID, domainID2, CF_GENIVI_ANALOG}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID11, sink2ID, domainID2, CF_GENIVI_ANALOG }); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); } TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID11; + am_sinkID_t gwSinkID11; enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11); - am_sourceID_t gwSourceID21; - enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1); - am_sinkID_t gwSinkID21; + am_sinkID_t gwSinkID21; enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); am_sourceID_t gwSourceID12; enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); am_sinkID_t coSinkID21; - enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); - am_converterID_t converterID2; - enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); am_gatewayID_t gatewayID2; enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); - am_sinkID_t sink1ID; - enterSinkDB("sink1", domainID1, cfAuto, sink1ID); - am_sinkID_t sink2ID; - enterSinkDB("sink2", domainID2, cfStereo, sink2ID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domainID1, cfAuto, sink1ID); + am_sinkID_t sink2ID; + enterSinkDB("sink2", domainID2, cfStereo, sink2ID); am::am_Source_s source; am::am_Sink_s sink; @@ -3001,112 +2982,113 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2) std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink1; pDatabaseHandler.getSinkInfoDB(sink2ID, sink1); - ASSERT_EQ(getRoute(false, true, source, sink1, listRoutes, 0), E_OK); - - ASSERT_EQ(static_cast(1), listRoutes.size()); - am_Route_s compareRoute1; - compareRoute1.sinkID = sink2ID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - compareRoute1.route.push_back({coSourceID21, sink2ID, domainID2, CF_GENIVI_STEREO}); - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); + ASSERT_EQ(getRoute(false, false, source, sink1, listRoutes, 0), E_OK); + + ASSERT_EQ(static_cast(1), listRoutes.size()); + am_Route_s compareRoute1; + compareRoute1.sinkID = sink2ID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG }); + compareRoute1.route.push_back( + { coSourceID21, sink2ID, domainID2, CF_GENIVI_STEREO }); + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); } TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - - std::vector matrix; - matrix.push_back(true); - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - std::vector cfFuture1; - cfFuture1.push_back(5); - std::vector cfFuture2; - cfFuture2.push_back(6); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - - am_sinkID_t coSinkID11; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + + std::vector matrix; + matrix.push_back(true); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + std::vector cfFuture1; + cfFuture1.push_back(5); + std::vector cfFuture2; + cfFuture2.push_back(6); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + + am_sinkID_t coSinkID11; enterSinkDB("coSink11", domainID1, cfStereo, coSinkID11); - am_sourceID_t coSourceID11; - enterSourceDB("coSource11", domainID1, cfFuture1, coSourceID11); - am_converterID_t converterID11; - enterConverterDB("converter11", domainID1, cfFuture1, cfStereo, matrix, coSourceID11, coSinkID11, converterID11); + am_sourceID_t coSourceID11; + enterSourceDB("coSource11", domainID1, cfFuture1, coSourceID11); + am_converterID_t converterID11; + enterConverterDB("converter11", domainID1, cfFuture1, cfStereo, matrix, coSourceID11, coSinkID11, converterID11); - am_sinkID_t coSinkID12; + am_sinkID_t coSinkID12; enterSinkDB("coSink12", domainID1, cfStereo, coSinkID12); - am_sourceID_t coSourceID12; - enterSourceDB("coSource12", domainID1, cfFuture2, coSourceID12); - am_converterID_t converterID12; - enterConverterDB("converter12", domainID1, cfFuture2, cfStereo, matrix, coSourceID12, coSinkID12, converterID12); + am_sourceID_t coSourceID12; + enterSourceDB("coSource12", domainID1, cfFuture2, coSourceID12); + am_converterID_t converterID12; + enterConverterDB("converter12", domainID1, cfFuture2, cfStereo, matrix, coSourceID12, coSinkID12, converterID12); - am_sinkID_t coSinkID13; + am_sinkID_t coSinkID13; enterSinkDB("coSink13", domainID1, cfFuture2, coSinkID13); - am_sourceID_t coSourceID13; - enterSourceDB("coSource13", domainID1, cfFuture1, coSourceID13); - am_converterID_t converterID13; - enterConverterDB("converter13", domainID1, cfFuture1, cfFuture2, matrix, coSourceID13, coSinkID13, converterID13); + am_sourceID_t coSourceID13; + enterSourceDB("coSource13", domainID1, cfFuture1, coSourceID13); + am_converterID_t converterID13; + enterConverterDB("converter13", domainID1, cfFuture1, cfFuture2, matrix, coSourceID13, coSinkID13, converterID13); - am_sinkID_t gwSinkID11; + am_sinkID_t gwSinkID11; enterSinkDB("gwSink11", domainID1, cfFuture1, gwSinkID11); - am_sourceID_t gwSourceID21; - enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfFuture1, matrix, gwSourceID21, gwSinkID11, gatewayID1); + am_sourceID_t gwSourceID21; + enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfFuture1, matrix, gwSourceID21, gwSinkID11, gatewayID1); - am_sinkID_t gwSinkID21; + am_sinkID_t gwSinkID21; enterSinkDB("gwSink21", domainID2, cfStereo, gwSinkID21); am_sourceID_t gwSourceID12; enterSourceDB("gwSource12", domainID1, cfAuto, gwSourceID12); am_sinkID_t coSinkID21; - enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); - - am_sourceID_t coSourceID21; - enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + enterSinkDB("coSink21", domainID2, cfAnalog, coSinkID21); - am_converterID_t converterID2; - enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); + am_sourceID_t coSourceID21; + enterSourceDB("coSource21", domainID2, cfStereo, coSourceID21); + am_converterID_t converterID2; + enterConverterDB("converter2", domainID2, cfStereo, cfAnalog, matrix, coSourceID21, coSinkID21, converterID2); am_gatewayID_t gatewayID2; enterGatewayDB("gateway2", domainID1, domainID2, cfAuto, cfStereo, matrix, gwSourceID12, gwSinkID21, gatewayID2); - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID1, cfAuto, sinkID); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID1, cfAuto, sinkID); am::am_Source_s source; am::am_Sink_s sink; @@ -3115,120 +3097,118 @@ TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2) std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes, 0), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes, 0), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); am::am_Sink_s sink2; pDatabaseHandler.getSinkInfoDB(coSinkID21, sink2); - ASSERT_EQ(getRoute(false, true, source, sink2, listRoutes, 0), E_OK); - ASSERT_EQ(static_cast(2), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = coSinkID21; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, coSinkID11, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({coSourceID11, gwSinkID11, domainID1, 5}); - compareRoute1.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - - am_Route_s compareRoute2; - compareRoute2.sinkID = coSinkID21; - compareRoute2.sourceID = sourceID; - compareRoute2.route.push_back({sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO}); - compareRoute2.route.push_back({coSourceID12, coSinkID13, domainID1, 6}); - compareRoute2.route.push_back({coSourceID13, gwSinkID11, domainID1, 5}); - compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[1])||pCF.compareRoute(compareRoute1,listRoutes[0])); - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); + ASSERT_EQ(getRoute(false, false, source, sink2, listRoutes, 0), E_OK); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = coSinkID21; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, coSinkID11, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { coSourceID11, gwSinkID11, domainID1, 5 }); + compareRoute1.route.push_back( + { gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG }); + + am_Route_s compareRoute2; + compareRoute2.sinkID = coSinkID21; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back( + { sourceID, coSinkID12, domainID1, CF_GENIVI_STEREO }); + compareRoute2.route.push_back( + { coSourceID12, coSinkID13, domainID1, 6 }); + compareRoute2.route.push_back( + { coSourceID13, gwSinkID11, domainID1, 5 }); + compareRoute2.route.push_back( + { gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG }); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[1]) || pCF.compareRoute(compareRoute1, listRoutes[0])); + ASSERT_TRUE(pCF.compareRoute(compareRoute2, listRoutes[0]) || pCF.compareRoute(compareRoute2, listRoutes[1])); } TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - - am_domainID_t domain1ID, domain2ID, domain3ID; - enterDomainDB("domain1", domain1ID); - enterDomainDB("domain2", domain2ID); - enterDomainDB("domain3", domain3ID); - - //just make so many cycles as possible - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog = cfStereo; - std::vector cfMono = cfStereo; - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t source1ID; - enterSourceDB("source1", domain1ID, cfStereo, source1ID); - am_sinkID_t gw1SinkID; - enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); - am_sinkID_t gw2SinkID; - enterSinkDB("gw2Sink", domain1ID, cfStereo, gw2SinkID); - am_sourceID_t gw3SourceID; - enterSourceDB("gw3Source", domain1ID, cfAnalog, gw3SourceID); - am_sourceID_t gw4SourceID; - enterSourceDB("gw4Source", domain1ID, cfAnalog, gw4SourceID); - am_sinkID_t gw5SinkID; - enterSinkDB("gw5Sink", domain1ID, cfAnalog, gw5SinkID); - - am_sourceID_t gw1SourceID; - enterSourceDB("gw1Source", domain2ID, cfMono, gw1SourceID); - am_sourceID_t gw2SourceID; - enterSourceDB("gw2Source", domain2ID, cfMono, gw2SourceID); - am_sinkID_t gw3SinkID; - enterSinkDB("gw3Sink", domain2ID, cfMono, gw3SinkID); - am_sinkID_t gw4SinkID; - enterSinkDB("gw4Sink", domain2ID, cfMono, gw4SinkID); - - am_sourceID_t gw5SourceID; - enterSourceDB("gw5Source", domain3ID, cfStereo, gw5SourceID); - am_sinkID_t sink1ID; - enterSinkDB("sink1", domain3ID, cfStereo, sink1ID); - - std::vector matrixT; - matrixT.push_back(true); - std::vector matrixF; - matrixF.push_back(false); - - am_gatewayID_t gateway1ID; - enterGatewayDB("gateway1", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); - am_gatewayID_t gateway2ID; - enterGatewayDB("gateway2", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw2SourceID, gw2SinkID, gateway2ID); - am_gatewayID_t gateway3ID; - enterGatewayDB("gateway3", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw3SourceID, gw3SinkID, gateway3ID); - am_gatewayID_t gateway4ID; - enterGatewayDB("gateway4", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw4SourceID, gw4SinkID, gateway4ID); - am_gatewayID_t gateway5ID; - enterGatewayDB("gateway5", domain3ID, domain1ID, cfStereo, cfAnalog, matrixT, gw5SourceID, gw5SinkID, gateway5ID); - - pRouter.load(false); - - CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); - CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); - - ASSERT_TRUE(sourceNode); - ASSERT_TRUE(sinkNode); - - std::vector listRoutes; - - am_Route_s compareRoute1; - compareRoute1.sinkID = sink1ID; - compareRoute1.sourceID = source1ID; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + + am_domainID_t domain1ID, domain2ID, domain3ID; + enterDomainDB("domain1", domain1ID); + enterDomainDB("domain2", domain2ID); + enterDomainDB("domain3", domain3ID); + + //just make so many cycles as possible + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog = cfStereo; + std::vector cfMono = cfStereo; + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t source1ID; + enterSourceDB("source1", domain1ID, cfStereo, source1ID); + am_sinkID_t gw1SinkID; + enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); + am_sinkID_t gw2SinkID; + enterSinkDB("gw2Sink", domain1ID, cfStereo, gw2SinkID); + am_sourceID_t gw3SourceID; + enterSourceDB("gw3Source", domain1ID, cfAnalog, gw3SourceID); + am_sourceID_t gw4SourceID; + enterSourceDB("gw4Source", domain1ID, cfAnalog, gw4SourceID); + am_sinkID_t gw5SinkID; + enterSinkDB("gw5Sink", domain1ID, cfAnalog, gw5SinkID); + + am_sourceID_t gw1SourceID; + enterSourceDB("gw1Source", domain2ID, cfMono, gw1SourceID); + am_sourceID_t gw2SourceID; + enterSourceDB("gw2Source", domain2ID, cfMono, gw2SourceID); + am_sinkID_t gw3SinkID; + enterSinkDB("gw3Sink", domain2ID, cfMono, gw3SinkID); + am_sinkID_t gw4SinkID; + enterSinkDB("gw4Sink", domain2ID, cfMono, gw4SinkID); + + am_sourceID_t gw5SourceID; + enterSourceDB("gw5Source", domain3ID, cfStereo, gw5SourceID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domain3ID, cfStereo, sink1ID); + + std::vector matrixT; + matrixT.push_back(true); + std::vector matrixF; + matrixF.push_back(false); + + am_gatewayID_t gateway1ID; + enterGatewayDB("gateway1", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); + am_gatewayID_t gateway2ID; + enterGatewayDB("gateway2", domain2ID, domain1ID, cfMono, cfStereo, matrixT, gw2SourceID, gw2SinkID, gateway2ID); + am_gatewayID_t gateway3ID; + enterGatewayDB("gateway3", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw3SourceID, gw3SinkID, gateway3ID); + am_gatewayID_t gateway4ID; + enterGatewayDB("gateway4", domain1ID, domain2ID, cfAnalog, cfMono, matrixT, gw4SourceID, gw4SinkID, gateway4ID); + am_gatewayID_t gateway5ID; + enterGatewayDB("gateway5", domain3ID, domain1ID, cfStereo, cfAnalog, matrixT, gw5SourceID, gw5SinkID, gateway5ID); + + std::vector listRoutes; + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink1ID; + compareRoute1.sourceID = source1ID; #define DO_ASSERT() \ {\ @@ -3238,210 +3218,261 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles) ASSERT_TRUE(didMatch); \ } - getAllPaths(*sourceNode, *sinkNode, listRoutes, UINT_MAX, 10); - ASSERT_EQ(static_cast(9), listRoutes.size()); - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - listRoutes.clear(); - - getAllPaths(*sourceNode, *sinkNode, listRoutes, 1, 10); - ASSERT_EQ(static_cast(5), listRoutes.size()); - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO}); - DO_ASSERT() - - listRoutes.clear(); - - getAllPaths(*sourceNode, *sinkNode, listRoutes); - ASSERT_EQ(static_cast(1), listRoutes.size()); - DO_ASSERT() + ASSERT_EQ(getAllPaths(false, source1ID, sink1ID, listRoutes, UINT_MAX, 10), E_OK); + ASSERT_EQ(static_cast(9), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + listRoutes.clear(); + + ASSERT_EQ(getAllPaths(false, source1ID, sink1ID, listRoutes, 1, 10), E_OK); + ASSERT_EQ(static_cast(5), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw1SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw1SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_STEREO }); + DO_ASSERT() + + listRoutes.clear(); + + ASSERT_EQ(getAllPaths(false, source1ID, sink1ID, listRoutes), E_OK); + ASSERT_EQ(static_cast(1), listRoutes.size()); + DO_ASSERT() } TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles2) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - - am_domainID_t domain1ID, domain2ID, domain3ID; - enterDomainDB("domain1", domain1ID); - enterDomainDB("domain2", domain2ID); - enterDomainDB("domain3", domain3ID); - - //just make so many cycles as possible - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfOther; - cfOther.push_back(CF_GENIVI_AUTO); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - - am_sourceID_t source1ID; - enterSourceDB("source1", domain1ID, cfMono, source1ID); - am_sinkID_t gw1SinkID; - enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); - am_sinkID_t gw2SinkID; - enterSinkDB("gw2Sink", domain1ID, cfMono, gw2SinkID); - am_sourceID_t gw3SourceID; - enterSourceDB("gw3Source", domain1ID, cfStereo, gw3SourceID); - am_sourceID_t gw4SourceID; - enterSourceDB("gw4Source", domain1ID, cfStereo, gw4SourceID); - am_sinkID_t gw5SinkID; - enterSinkDB("gw5Sink", domain1ID, cfStereo, gw5SinkID); - - am_sourceID_t gw1SourceID; - enterSourceDB("gw1Source", domain2ID, cfStereo, gw1SourceID); - am_sourceID_t gw2SourceID; - enterSourceDB("gw2Source", domain2ID, cfStereo, gw2SourceID); - am_sinkID_t gw3SinkID; - enterSinkDB("gw3Sink", domain2ID, cfStereo, gw3SinkID); - am_sinkID_t gw4SinkID; - enterSinkDB("gw4Sink", domain2ID, cfStereo, gw4SinkID); - - am_sourceID_t gw5SourceID; - enterSourceDB("gw5Source", domain3ID, cfOther, gw5SourceID); - am_sinkID_t sink1ID; - enterSinkDB("sink1", domain3ID, cfOther, sink1ID); - - std::vector matrixT; - matrixT.push_back(true); - std::vector matrixF; - matrixF.push_back(false); - - am_gatewayID_t gateway1ID; - enterGatewayDB("gateway1", domain2ID, domain1ID, cfStereo, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); - am_gatewayID_t gateway2ID; - enterGatewayDB("gateway2", domain2ID, domain1ID, cfStereo, cfMono, matrixT, gw2SourceID, gw2SinkID, gateway2ID); - am_gatewayID_t gateway3ID; - enterGatewayDB("gateway3", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw3SourceID, gw3SinkID, gateway3ID); - am_gatewayID_t gateway4ID; - enterGatewayDB("gateway4", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw4SourceID, gw4SinkID, gateway4ID); - am_gatewayID_t gateway5ID; - enterGatewayDB("gateway5", domain3ID, domain1ID, cfOther, cfStereo, matrixT, gw5SourceID, gw5SinkID, gateway5ID); - - pRouter.load(false); - - CAmRoutingNode* sourceNode = pRouter.sourceNodeWithID(source1ID); - CAmRoutingNode* sinkNode = pRouter.sinkNodeWithID(sink1ID); - - ASSERT_TRUE(sourceNode); - ASSERT_TRUE(sinkNode); - - std::vector listRoutes; - - am_Route_s compareRoute1; - compareRoute1.sinkID = sink1ID; - compareRoute1.sourceID = source1ID; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + + am_domainID_t domain1ID, domain2ID, domain3ID; + enterDomainDB("domain1", domain1ID); + enterDomainDB("domain2", domain2ID); + enterDomainDB("domain3", domain3ID); + + //just make so many cycles as possible + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfOther; + cfOther.push_back(CF_GENIVI_AUTO); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + + am_sourceID_t source1ID; + enterSourceDB("source1", domain1ID, cfMono, source1ID); + am_sinkID_t gw1SinkID; + enterSinkDB("gw1Sink", domain1ID, cfStereo, gw1SinkID); + am_sinkID_t gw2SinkID; + enterSinkDB("gw2Sink", domain1ID, cfMono, gw2SinkID); + am_sourceID_t gw3SourceID; + enterSourceDB("gw3Source", domain1ID, cfStereo, gw3SourceID); + am_sourceID_t gw4SourceID; + enterSourceDB("gw4Source", domain1ID, cfStereo, gw4SourceID); + am_sinkID_t gw5SinkID; + enterSinkDB("gw5Sink", domain1ID, cfStereo, gw5SinkID); + + am_sourceID_t gw1SourceID; + enterSourceDB("gw1Source", domain2ID, cfStereo, gw1SourceID); + am_sourceID_t gw2SourceID; + enterSourceDB("gw2Source", domain2ID, cfStereo, gw2SourceID); + am_sinkID_t gw3SinkID; + enterSinkDB("gw3Sink", domain2ID, cfStereo, gw3SinkID); + am_sinkID_t gw4SinkID; + enterSinkDB("gw4Sink", domain2ID, cfStereo, gw4SinkID); + + am_sourceID_t gw5SourceID; + enterSourceDB("gw5Source", domain3ID, cfOther, gw5SourceID); + am_sinkID_t sink1ID; + enterSinkDB("sink1", domain3ID, cfOther, sink1ID); + + std::vector matrixT; + matrixT.push_back(true); + std::vector matrixF; + matrixF.push_back(false); + + am_gatewayID_t gateway1ID; + enterGatewayDB("gateway1", domain2ID, domain1ID, cfStereo, cfStereo, matrixT, gw1SourceID, gw1SinkID, gateway1ID); + am_gatewayID_t gateway2ID; + enterGatewayDB("gateway2", domain2ID, domain1ID, cfStereo, cfMono, matrixT, gw2SourceID, gw2SinkID, gateway2ID); + am_gatewayID_t gateway3ID; + enterGatewayDB("gateway3", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw3SourceID, gw3SinkID, gateway3ID); + am_gatewayID_t gateway4ID; + enterGatewayDB("gateway4", domain1ID, domain2ID, cfStereo, cfStereo, matrixT, gw4SourceID, gw4SinkID, gateway4ID); + am_gatewayID_t gateway5ID; + enterGatewayDB("gateway5", domain3ID, domain1ID, cfOther, cfStereo, matrixT, gw5SourceID, gw5SinkID, gateway5ID); + + std::vector listRoutes; + + am_Route_s compareRoute1; + compareRoute1.sinkID = sink1ID; + compareRoute1.sourceID = source1ID; #define DO_ASSERT() \ {\ @@ -3451,68 +3482,75 @@ TEST_F(CAmRouterMapTest,route3Domains1Source1SinkGwCycles2) ASSERT_TRUE(didMatch); \ } - ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 0, 10), E_NOT_POSSIBLE); - ASSERT_EQ(static_cast(0), listRoutes.size()); - - ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 1, 10), E_OK); - ASSERT_EQ(static_cast(2), listRoutes.size()); - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO}); - DO_ASSERT() - - compareRoute1.route.clear(); - compareRoute1.route.push_back({source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO}); - DO_ASSERT() + ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 0, 10), E_NOT_POSSIBLE); + ASSERT_EQ(static_cast(0), listRoutes.size()); + + ASSERT_EQ(getRoute(false, false, source1ID, sink1ID, listRoutes, 1, 10), E_OK); + ASSERT_EQ(static_cast(2), listRoutes.size()); + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO }); + compareRoute1.route.push_back( + { gw2SourceID, gw4SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw4SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO }); + DO_ASSERT() + + compareRoute1.route.clear(); + compareRoute1.route.push_back( + { source1ID, gw2SinkID, domain1ID, CF_GENIVI_MONO }); + compareRoute1.route.push_back( + { gw2SourceID, gw3SinkID, domain2ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw3SourceID, gw5SinkID, domain1ID, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gw5SourceID, sink1ID, domain3ID, CF_GENIVI_AUTO }); + DO_ASSERT() } TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; - - - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); - - am_domainID_t domainID1, domainID2, domainID3; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); - enterDomainDB("domain3", domainID3); - - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); - std::vector cfAnalog; - cfAnalog.push_back(CF_GENIVI_ANALOG); - std::vector cfMono; - cfMono.push_back(CF_GENIVI_MONO); - std::vector cfAuto; - cfAuto.push_back(CF_GENIVI_AUTO); - - am_sourceID_t sourceID; - enterSourceDB("source1", domainID1, cfStereo, sourceID); - am_sinkID_t gwSinkID1; - enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); + + am_domainID_t domainID1, domainID2, domainID3; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); + enterDomainDB("domain3", domainID3); + + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfAnalog; + cfAnalog.push_back(CF_GENIVI_ANALOG); + std::vector cfMono; + cfMono.push_back(CF_GENIVI_MONO); + std::vector cfAuto; + cfAuto.push_back(CF_GENIVI_AUTO); + + am_sourceID_t sourceID; + enterSourceDB("source1", domainID1, cfStereo, sourceID); + am_sinkID_t gwSinkID1; + enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); am_sinkID_t gwSinkID21; enterSinkDB("gwSink21", domainID1, cfStereo, gwSinkID21); - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1); am_sinkID_t gwSinkID22; enterSinkDB("gwSink22", domainID2, cfMono, gwSinkID22); @@ -3521,35 +3559,35 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) am_sourceID_t gwSourceID22; enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22); - am_sourceID_t cSourceID5; - enterSourceDB("cSource5", domainID3, cfStereo, cSourceID5); - am_sinkID_t cSinkID5; - enterSinkDB("cSink5", domainID3, cfAnalog, cSinkID5); + am_sourceID_t cSourceID5; + enterSourceDB("cSource5", domainID3, cfStereo, cSourceID5); + am_sinkID_t cSinkID5; + enterSinkDB("cSink5", domainID3, cfAnalog, cSinkID5); am_sourceID_t cSourceID3; - enterSourceDB("cSource3", domainID3, cfAnalog, cSourceID3); - am_sinkID_t cSinkID3; - enterSinkDB("cSinkID3", domainID3, cfAuto, cSinkID3); - am_sourceID_t cSourceID4; - enterSourceDB("cSource4", domainID3, cfStereo, cSourceID4); - am_sinkID_t cSinkID4; - enterSinkDB("cSink4", domainID3, cfAnalog, cSinkID4); - am_sinkID_t sinkID; - enterSinkDB("sink1", domainID3, cfStereo, sinkID); - - std::vector matrix; - matrix.push_back(true); + enterSourceDB("cSource3", domainID3, cfAnalog, cSourceID3); + am_sinkID_t cSinkID3; + enterSinkDB("cSinkID3", domainID3, cfAuto, cSinkID3); + am_sourceID_t cSourceID4; + enterSourceDB("cSource4", domainID3, cfStereo, cSourceID4); + am_sinkID_t cSinkID4; + enterSinkDB("cSink4", domainID3, cfAnalog, cSinkID4); + am_sinkID_t sinkID; + enterSinkDB("sink1", domainID3, cfStereo, sinkID); + + std::vector matrix; + matrix.push_back(true); am_gatewayID_t gatewayID; enterGatewayDB("gateway1", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID); am_gatewayID_t gatewayID22; enterGatewayDB("gateway22", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID22, gwSinkID22, gatewayID22); am_gatewayID_t gatewayID21; enterGatewayDB("gateway21", domainID3, domainID1, cfAuto, cfStereo, matrix, gwSourceID21, gwSinkID21, gatewayID21); - am_converterID_t converterID1; - enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, cSourceID3, cSinkID3, converterID1); - am_converterID_t converterID2; - enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, cSourceID4, cSinkID4, converterID2); - am_converterID_t converterID3; - enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, cSourceID5, cSinkID5, converterID3); + am_converterID_t converterID1; + enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, cSourceID3, cSinkID3, converterID1); + am_converterID_t converterID2; + enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, cSourceID4, cSinkID4, converterID2); + am_converterID_t converterID3; + enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, cSourceID5, cSinkID5, converterID3); am::am_Source_s source; am::am_Sink_s sink; @@ -3559,115 +3597,128 @@ TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink) std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes), E_OK); - ASSERT_EQ(static_cast(4), listRoutes.size()); - - am_Route_s compareRoute1; - compareRoute1.sinkID = sinkID; - compareRoute1.sourceID = sourceID; - compareRoute1.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute1.route.push_back({gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute1.route.push_back({cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute1.route.push_back({cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute2; - compareRoute2.sinkID = sinkID; - compareRoute2.sourceID = sourceID; - compareRoute2.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute2.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO}); - compareRoute2.route.push_back({gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute2.route.push_back({cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute2.route.push_back({cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute3; - compareRoute3.sinkID = sinkID; - compareRoute3.sourceID = sourceID; - compareRoute3.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute3.route.push_back({gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute3.route.push_back({cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG}); - compareRoute3.route.push_back({cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO}); - - am_Route_s compareRoute4; - compareRoute4.sinkID = sinkID; - compareRoute4.sourceID = sourceID; - compareRoute4.route.push_back({sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO}); - compareRoute4.route.push_back({gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO}); - compareRoute4.route.push_back({cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG}); - compareRoute4.route.push_back({cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])|| - pCF.compareRoute(compareRoute1,listRoutes[1])|| - pCF.compareRoute(compareRoute1,listRoutes[2])|| - pCF.compareRoute(compareRoute1,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])|| - pCF.compareRoute(compareRoute2,listRoutes[1])|| - pCF.compareRoute(compareRoute2,listRoutes[2])|| - pCF.compareRoute(compareRoute2,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])|| - pCF.compareRoute(compareRoute3,listRoutes[1])|| - pCF.compareRoute(compareRoute3,listRoutes[2])|| - pCF.compareRoute(compareRoute3,listRoutes[3])); - - ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[0])|| - pCF.compareRoute(compareRoute4,listRoutes[1])|| - pCF.compareRoute(compareRoute4,listRoutes[2])|| - pCF.compareRoute(compareRoute4,listRoutes[3])); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes), E_OK); + ASSERT_EQ(static_cast(4), listRoutes.size()); + + am_Route_s compareRoute1; + compareRoute1.sinkID = sinkID; + compareRoute1.sourceID = sourceID; + compareRoute1.route.push_back( + { sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO }); + compareRoute1.route.push_back( + { gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO }); + compareRoute1.route.push_back( + { cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG }); + compareRoute1.route.push_back( + { cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO }); + + am_Route_s compareRoute2; + compareRoute2.sinkID = sinkID; + compareRoute2.sourceID = sourceID; + compareRoute2.route.push_back( + { sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO }); + compareRoute2.route.push_back( + { gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO }); + compareRoute2.route.push_back( + { gwSourceID22, cSinkID3, domainID3, CF_GENIVI_AUTO }); + compareRoute2.route.push_back( + { cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG }); + compareRoute2.route.push_back( + { cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO }); + + am_Route_s compareRoute3; + compareRoute3.sinkID = sinkID; + compareRoute3.sourceID = sourceID; + compareRoute3.route.push_back( + { sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO }); + compareRoute3.route.push_back( + { gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO }); + compareRoute3.route.push_back( + { cSourceID3, cSinkID4, domainID3, CF_GENIVI_ANALOG }); + compareRoute3.route.push_back( + { cSourceID4, sinkID, domainID3, CF_GENIVI_STEREO }); + + am_Route_s compareRoute4; + compareRoute4.sinkID = sinkID; + compareRoute4.sourceID = sourceID; + compareRoute4.route.push_back( + { sourceID, gwSinkID21, domainID1, CF_GENIVI_STEREO }); + compareRoute4.route.push_back( + { gwSourceID21, cSinkID3, domainID3, CF_GENIVI_AUTO }); + compareRoute4.route.push_back( + { cSourceID3, cSinkID5, domainID3, CF_GENIVI_ANALOG }); + compareRoute4.route.push_back( + { cSourceID5, sinkID, domainID3, CF_GENIVI_STEREO }); + + ASSERT_TRUE( + pCF.compareRoute(compareRoute1, listRoutes[0]) || pCF.compareRoute(compareRoute1, listRoutes[1]) || pCF.compareRoute(compareRoute1, listRoutes[2]) + || pCF.compareRoute(compareRoute1, listRoutes[3])); + + ASSERT_TRUE( + pCF.compareRoute(compareRoute2, listRoutes[0]) || pCF.compareRoute(compareRoute2, listRoutes[1]) || pCF.compareRoute(compareRoute2, listRoutes[2]) + || pCF.compareRoute(compareRoute2, listRoutes[3])); + + ASSERT_TRUE( + pCF.compareRoute(compareRoute3, listRoutes[0]) || pCF.compareRoute(compareRoute3, listRoutes[1]) || pCF.compareRoute(compareRoute3, listRoutes[2]) + || pCF.compareRoute(compareRoute3, listRoutes[3])); + + ASSERT_TRUE( + pCF.compareRoute(compareRoute4, listRoutes[0]) || pCF.compareRoute(compareRoute4, listRoutes[1]) || pCF.compareRoute(compareRoute4, listRoutes[2]) + || pCF.compareRoute(compareRoute4, listRoutes[3])); } TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) { - EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); am_SourceClass_s sourceclass; - sourceclass.name="sClass"; - sourceclass.sourceClassID=5; + sourceclass.name = "sClass"; + sourceclass.sourceClassID = 5; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID,sourceclass)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceclass.sourceClassID, sourceclass)); am_SinkClass_s sinkclass; - sinkclass.sinkClassID=5; - sinkclass.name="sname"; + sinkclass.sinkClassID = 5; + sinkclass.name = "sname"; - ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass,sinkclass.sinkClassID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkclass, sinkclass.sinkClassID)); - std::vector matrix; - matrix.push_back(true); - matrix.push_back(false); - matrix.push_back(false); - matrix.push_back(true); - - am_domainID_t domainID1, domainID2; - enterDomainDB("domain1", domainID1); - enterDomainDB("domain2", domainID2); + std::vector matrix; + matrix.push_back(true); + matrix.push_back(false); + matrix.push_back(false); + matrix.push_back(true); - std::vector cfStereo; - cfStereo.push_back(CF_GENIVI_STEREO); + am_domainID_t domainID1, domainID2; + enterDomainDB("domain1", domainID1); + enterDomainDB("domain2", domainID2); - std::vector cfMulti; - cfMulti.push_back(CF_GENIVI_STEREO); - cfMulti.push_back(CF_GENIVI_ANALOG); + std::vector cfStereo; + cfStereo.push_back(CF_GENIVI_STEREO); + std::vector cfMulti; + cfMulti.push_back(CF_GENIVI_STEREO); + cfMulti.push_back(CF_GENIVI_ANALOG); - am_sourceID_t tunerID; - enterSourceDB("Tuner", domainID1, cfStereo, tunerID); + am_sourceID_t tunerID; + enterSourceDB("Tuner", domainID1, cfStereo, tunerID); - am_sinkID_t gwSinkID1; + am_sinkID_t gwSinkID1; enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1); - am_sourceID_t gwSourceID1; - enterSourceDB("gwSource1", domainID2, cfMulti, gwSourceID1); - am_converterID_t gatewayID1; - enterGatewayDB("gateway1", domainID2, domainID1, cfMulti, cfMulti, matrix, gwSourceID1, gwSinkID1, gatewayID1); - - am_sinkID_t rseLeftID; - enterSinkDB("RSE Left", domainID2, cfMulti, rseLeftID); - am_sinkID_t rseRightID; - enterSinkDB("RSE Right", domainID2, cfMulti, rseRightID); - am_sinkID_t rseHeadphoneID; - enterSinkDB("Headphone", domainID2, cfMulti, rseHeadphoneID); + am_sourceID_t gwSourceID1; + enterSourceDB("gwSource1", domainID2, cfMulti, gwSourceID1); + am_converterID_t gatewayID1; + enterGatewayDB("gateway1", domainID2, domainID1, cfMulti, cfMulti, matrix, gwSourceID1, gwSinkID1, gatewayID1); + + am_sinkID_t rseLeftID; + enterSinkDB("RSE Left", domainID2, cfMulti, rseLeftID); + am_sinkID_t rseRightID; + enterSinkDB("RSE Right", domainID2, cfMulti, rseRightID); + am_sinkID_t rseHeadphoneID; + enterSinkDB("Headphone", domainID2, cfMulti, rseHeadphoneID); am::am_Source_s source; am::am_Sink_s sink; @@ -3675,52 +3726,57 @@ TEST_F(CAmRouterMapTest, routeTunerHeadphonePathThroughGWPlus2OtherSinks) pDatabaseHandler.getSourceInfoDB(tunerID, source); std::vector listRoutes; - ASSERT_EQ(getRoute(false, true, source, sink, listRoutes), E_OK); - ASSERT_EQ(listRoutes.size(), static_cast(1)); - - am_Route_s compareRoute1; - compareRoute1.sinkID = rseLeftID; - compareRoute1.sourceID = tunerID; - compareRoute1.route.push_back({tunerID, gwSinkID1, domainID1, CF_GENIVI_STEREO}); - compareRoute1.route.push_back({gwSourceID1, rseLeftID, domainID2, CF_GENIVI_STEREO}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0])); - - listRoutes.clear(); - - am::am_Source_s gwSource; - am::am_Sink_s sink2; - pDatabaseHandler.getSinkInfoDB(rseHeadphoneID, sink2); - pDatabaseHandler.getSourceInfoDB(gwSourceID1, gwSource); - ASSERT_EQ(getRoute(false, true, gwSource, sink2, listRoutes), E_OK); - ASSERT_GT(listRoutes.size(), static_cast(0)); - - am_Route_s compareRoute2; - compareRoute2.sinkID = rseHeadphoneID; - compareRoute2.sourceID = gwSourceID1; - compareRoute2.route.push_back({gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_STEREO}); - am_Route_s compareRoute3; - compareRoute3.sinkID = rseHeadphoneID; - compareRoute3.sourceID = gwSourceID1; - compareRoute3.route.push_back({gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_ANALOG}); - - ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[0])||pCF.compareRoute(compareRoute2,listRoutes[1])); - ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[0])||pCF.compareRoute(compareRoute3,listRoutes[1])); + ASSERT_EQ(getRoute(false, false, source, sink, listRoutes), E_OK); + ASSERT_EQ(listRoutes.size(), static_cast(1)); + + am_Route_s compareRoute1; + compareRoute1.sinkID = rseLeftID; + compareRoute1.sourceID = tunerID; + compareRoute1.route.push_back( + { tunerID, gwSinkID1, domainID1, CF_GENIVI_STEREO }); + compareRoute1.route.push_back( + { gwSourceID1, rseLeftID, domainID2, CF_GENIVI_STEREO }); + + ASSERT_TRUE(pCF.compareRoute(compareRoute1, listRoutes[0])); + + listRoutes.clear(); + + am::am_Source_s gwSource; + am::am_Sink_s sink2; + pDatabaseHandler.getSinkInfoDB(rseHeadphoneID, sink2); + pDatabaseHandler.getSourceInfoDB(gwSourceID1, gwSource); + ASSERT_EQ(getRoute(false, false, gwSource, sink2, listRoutes), E_OK); + ASSERT_GT(listRoutes.size(), static_cast(0)); + + am_Route_s compareRoute2; + compareRoute2.sinkID = rseHeadphoneID; + compareRoute2.sourceID = gwSourceID1; + compareRoute2.route.push_back( + { gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_STEREO }); + am_Route_s compareRoute3; + compareRoute3.sinkID = rseHeadphoneID; + compareRoute3.sourceID = gwSourceID1; + compareRoute3.route.push_back( + { gwSourceID1, rseHeadphoneID, domainID2, CF_GENIVI_ANALOG }); + + ASSERT_TRUE(pCF.compareRoute(compareRoute2, listRoutes[0]) || pCF.compareRoute(compareRoute2, listRoutes[1])); + ASSERT_TRUE(pCF.compareRoute(compareRoute3, listRoutes[0]) || pCF.compareRoute(compareRoute3, listRoutes[1])); } int main(int argc, char **argv) { - try - { - TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!",' ',DAEMONVERSION,true)); - cmd->add(enableDebug); - } - catch (TCLAP::ArgException &e) // catch any exceptions - { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } - CAmCommandLineSingleton::instance()->preparse(argc,argv); - CAmDltWrapper::instanctiateOnce("rTEST","RouterMap Test",enableDebug.getValue(),CAmDltWrapper::logDestination::DAEMON); - logInfo("Routing Test started "); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + try + { + TCLAP::CmdLine* cmd(CAmCommandLineSingleton::instanciateOnce("The team of the AudioManager wishes you a nice day!", ' ', DAEMONVERSION, true)); + cmd->add(enableDebug); + } catch (TCLAP::ArgException &e) // catch any exceptions + { + std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + CAmCommandLineSingleton::instance()->preparse(argc, argv); + CAmDltWrapper::instanctiateOnce("rTEST", "RouterMap Test", enableDebug.getValue(), CAmDltWrapper::logDestination::DAEMON); + logInfo("Routing Test started "); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h index 879f47c..6ecaeaa 100644 --- a/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h +++ b/AudioManagerCore/test/AmRouterMapTest/CAmRouterMapTest.h @@ -14,7 +14,7 @@ * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * -* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 + * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014 * * For further information see http://www.genivi.org/. * @@ -43,59 +43,54 @@ #include "../MockIAmControlSend.h" #include "../MockIAmCommandSend.h" - namespace am { -class CAmRouterMapTest: public ::testing::Test -{ -public: - CAmRouterMapTest(); - ~CAmRouterMapTest(); - std::vector plistRoutingPluginDirs; - std::vector plistCommandPluginDirs; - CAmSocketHandler pSocketHandler; - CAmControlSender pControlSender; - CAmDatabaseHandlerMap pDatabaseHandler; - CAmRouter pRouter; - CAmRoutingSender pRoutingSender; - CAmCommandSender pCommandSender; - MockIAmCommandSend pMockInterface; - MockIAmControlSend pMockControlInterface; - IAmRoutingBackdoor pRoutingInterfaceBackdoor; - IAmCommandBackdoor pCommandInterfaceBackdoor; - IAmControlBackdoor pControlInterfaceBackdoor; - CAmControlReceiver pControlReceiver; - CAmCommonFunctions pCF; - void SetUp(); - void TearDown(); + class CAmRouterMapTest: public ::testing::Test + { + public: + CAmRouterMapTest(); + ~CAmRouterMapTest(); + std::vector plistRoutingPluginDirs; + std::vector plistCommandPluginDirs; + CAmSocketHandler pSocketHandler; + CAmControlSender pControlSender; + CAmDatabaseHandlerMap pDatabaseHandler; + CAmRouter pRouter; + CAmRoutingSender pRoutingSender; + CAmCommandSender pCommandSender; + MockIAmCommandSend pMockInterface; + MockIAmControlSend pMockControlInterface; + IAmRoutingBackdoor pRoutingInterfaceBackdoor; + IAmCommandBackdoor pCommandInterfaceBackdoor; + IAmControlBackdoor pControlInterfaceBackdoor; + CAmControlReceiver pControlReceiver; + CAmCommonFunctions pCF; + void SetUp(); + void TearDown(); - void createMainConnectionSetup(); + void createMainConnectionSetup(); - void enterDomainDB(const std::string & domainName, am_domainID_t & domainID); - void enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sourceID_t & sourceID); - void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, am_sinkID_t & sinkID); - void enterGatewayDB(const std::string & gwName, - const am_domainID_t domainSourceID, - const am_domainID_t domainSinkID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_gatewayID_t & gatewayID); - void enterConverterDB(const std::string & gwName, - const am_domainID_t domainID, - const std::vector & sourceConnectionFormats, - const std::vector & sinkConnectionFormats, - const std::vector & matrix, - const am_sourceID_t & sourceID, - const am_sinkID_t & sinkID, - am_converterID_t & converterID); - am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector& returnList, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); - am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector & listRoutes, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); - am_Error_e getAllPaths(CAmRoutingNode & aSource, CAmRoutingNode & aSink, std::vector & resultPath, const unsigned countCycles=0, const unsigned pathsCount=MAX_ROUTING_PATHS); -}; + void enterDomainDB(const std::string & domainName, am_domainID_t & domainID); + void enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector & connectionFormats, + am_sourceID_t & sourceID); + void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector & connectionFormats, + am_sinkID_t & sinkID); + void enterGatewayDB(const std::string & gwName, const am_domainID_t domainSourceID, const am_domainID_t domainSinkID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, const std::vector & matrix, const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, am_gatewayID_t & gatewayID); + void enterConverterDB(const std::string & gwName, const am_domainID_t domainID, + const std::vector & sourceConnectionFormats, + const std::vector & sinkConnectionFormats, const std::vector & matrix, const am_sourceID_t & sourceID, + const am_sinkID_t & sinkID, am_converterID_t & converterID); + am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_sourceID_t sourceID, const am_sinkID_t sinkID, + std::vector& returnList, const unsigned countCycles = 0, const unsigned pathsCount = MAX_ROUTING_PATHS); + am_Error_e getRoute(const bool onlyfree, const bool shouldReload, const am_Source_s & aSource, const am_Sink_s & aSink, + std::vector & listRoutes, const unsigned countCycles = 0, const unsigned pathsCount = MAX_ROUTING_PATHS); + am_Error_e getAllPaths(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector & resultPath, + const unsigned countCycles = 0, const unsigned pathsCount = MAX_ROUTING_PATHS); + }; } -- cgit v1.2.1