summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--AudioManagerDaemon/CMakeLists.txt2
-rw-r--r--AudioManagerDaemon/docx/03_architecture_overview.dox6
-rw-r--r--AudioManagerDaemon/fidls/AudioManagerTypes.fidl55
-rw-r--r--AudioManagerDaemon/include/CAmControlReceiver.h6
-rw-r--r--AudioManagerDaemon/include/CAmControlSender.h3
-rw-r--r--AudioManagerDaemon/include/CAmDatabaseHandlerMap.h36
-rw-r--r--AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h18
-rw-r--r--AudioManagerDaemon/include/CAmDatabaseObserver.h2
-rw-r--r--AudioManagerDaemon/include/CAmGraph.h622
-rw-r--r--AudioManagerDaemon/include/CAmRouter.h298
-rw-r--r--AudioManagerDaemon/include/CAmRoutingReceiver.h3
-rw-r--r--AudioManagerDaemon/include/IAmDatabaseHandler.h17
-rw-r--r--AudioManagerDaemon/src/CAmControlReceiver.cpp32
-rw-r--r--AudioManagerDaemon/src/CAmControlSender.cpp18
-rw-r--r--AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp270
-rw-r--r--AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp1085
-rw-r--r--AudioManagerDaemon/src/CAmDatabaseObserver.cpp12
-rw-r--r--AudioManagerDaemon/src/CAmRouter.cpp1114
-rw-r--r--AudioManagerDaemon/src/CAmRoutingReceiver.cpp15
-rw-r--r--AudioManagerDaemon/src/CAmRoutingSender.cpp16
-rw-r--r--AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp209
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp251
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp4
-rw-r--r--AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h4
-rw-r--r--AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp1122
-rw-r--r--AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h24
-rw-r--r--AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt2
-rw-r--r--AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp7
-rw-r--r--AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt2
-rw-r--r--AudioManagerDaemon/test/CAmCommonFunctions.cpp23
-rw-r--r--AudioManagerDaemon/test/CAmCommonFunctions.h3
-rw-r--r--AudioManagerDaemon/test/MockIAmControlSend.h6
32 files changed, 4510 insertions, 777 deletions
diff --git a/AudioManagerDaemon/CMakeLists.txt b/AudioManagerDaemon/CMakeLists.txt
index 438c263..e263aea 100644
--- a/AudioManagerDaemon/CMakeLists.txt
+++ b/AudioManagerDaemon/CMakeLists.txt
@@ -163,7 +163,7 @@ IF(WITH_NSM)
# The ALT_DESTINATION is used as fall back if the DESTINATION directory dosen't contain the sources or you just don't want to use the generator.
INCLUDE(CommonAPIGenerator)
COMMON_API_GENERATE_SOUCRES(TARGET COMMON_API
- FIDLS fidls/NodeStateManager.fidl # a list with fidls
+ FIDLS fidls/NodeStateManager.fdepl # a list with fidls
DESTINATION src-gen # a relative path to the build directory or an absolute path
ALT_DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/src-gen # an alternative relative/absolute path with common-api sources, usually in the source tree
DBUS)
diff --git a/AudioManagerDaemon/docx/03_architecture_overview.dox b/AudioManagerDaemon/docx/03_architecture_overview.dox
index 230a99a..c38bb60 100644
--- a/AudioManagerDaemon/docx/03_architecture_overview.dox
+++ b/AudioManagerDaemon/docx/03_architecture_overview.dox
@@ -76,4 +76,10 @@ For every gateway, a controlDomain is defined, this is the domain that registere
the "other end" of the gateway might be unknown. To handle this situation, a domain can "peek" Domains, Sources and Sinks. When
something is peeked, it means that an ID is reserved for a unique name without registering it.\n
If a gateway is deregistered, the source or sink of the controlling domain is deregistered as well - not the one in the "other" domain.
+
+\section converter Converter
+
+Converters are very similar to gateways - the only difference is that they work inside a domain. The usage of gateways is analog to
+gateways.
+
*/
diff --git a/AudioManagerDaemon/fidls/AudioManagerTypes.fidl b/AudioManagerDaemon/fidls/AudioManagerTypes.fidl
index bdfed45..956b400 100644
--- a/AudioManagerDaemon/fidls/AudioManagerTypes.fidl
+++ b/AudioManagerDaemon/fidls/AudioManagerTypes.fidl
@@ -54,7 +54,12 @@ typeCollection am {
<**
@description : a gateway ID
**>
- typedef am_gatewayID_t is UInt16
+ typedef am_gatewayID_t is UInt16
+
+ <**
+ @description : a converter ID
+ **>
+ typedef am_converterID_t is UInt16
<**
@description : a connection ID
@@ -634,6 +639,54 @@ The data is stored row orientated, where the rows are related to the sinksFormat
**>
am_Convertion_L convertionMatrix
}
+
+<**
+ @description : This struct describes the attributes of a gateway.
+ **>
+ struct am_Converter_s {
+
+ <**
+ @description : This is the ID of the gateway, it is unique in the system. There are 2 ways, ID can be created: either it is assigned during the registration process (in a dynamic context, uniqueness will be ensured by the AudioManagerDaemon), or it is a fixed (the project has to ensure the uniqueness of the ID).
+ **>
+ am_converterID_t converterID
+
+ <**
+ @description : The name of the gateway. Must be unique in the whole system.
+ **>
+ String name
+
+ <**
+ @description : The sinkID of the gateway sink-end. The sink is a full blown sink with connectionFormats, sinkClassIDs etc... It makes sense to register the sinks of a gateway as non-visible. Care needs to be taken that the connectionsFormats match with the ones in the conversionMatrix. If the sink is located in the controllingDomain, the ID needs to be retrieved by registering the sink before registering the gateway. In case the sink is in a different domain, the ID needs to be retrieved via peeking.
+ **>
+ am_sinkID_t sinkID
+
+ <**
+ @description : The sourceID of the gateway sink-end. The sink is a full blown source with connectionFormats, sinkClassIDs etc... It makes sense to register the sources of a gateway as non-visible. Care needs to be taken that the connectionsFormats match with the ones in the conversionMatrix. If the source is located in the controllingDomain, the ID needs to be retrieved by registering the source before registering the gateway. In case the source is in a different domain, the ID needs to be retrieved via peeking.
+ **>
+ am_sourceID_t sourceID
+
+ <**
+ @description : The ID of the sink. If the domain is the same like the controlling domain, the ID is known due to registration. If the domain is different, the ID needs to be retrieved via peeking.
+ **>
+ am_domainID_t domainID
+
+ <**
+ @description : This is the list of available formats on the source side of the gateway. It is not defined during the gateway registration but copied from the source registration.
+ **>
+ am_ConnectionFormat_L listSourceFormats
+
+ <**
+ @description : This is the list of available formats on the sink side of the gateway. It is not defined during the gateway registration but copied from the sink registration.
+ **>
+ am_ConnectionFormat_L listSinkFormats
+
+ <**
+ @description : This is matrix holding information about the conversion capability of the gateway, it's length is defined by the length(listSinkFormats) x length(listSourceFormats).
+If a SinkFormat can be converted into a SourceFormat, the vector will hold a 1, if no conversion is possible, a 0.
+The data is stored row orientated, where the rows are related to the sinksFormats and the columns to the sourceFormats. The first value will hold the conversion information from the first sourceFormat to the first sinkFormat for example and the seventh value the information about the 3rd sinkFormat to the 1st sourceFormat in case we would have 3 sourceFormats.
+ **>
+ am_Convertion_L convertionMatrix
+ }
<**
@description : This represents one "hopp" in a route
diff --git a/AudioManagerDaemon/include/CAmControlReceiver.h b/AudioManagerDaemon/include/CAmControlReceiver.h
index 9487d17..b0a9d1a 100644
--- a/AudioManagerDaemon/include/CAmControlReceiver.h
+++ b/AudioManagerDaemon/include/CAmControlReceiver.h
@@ -61,6 +61,7 @@ public:
am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID);
am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID);
am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID);
+ am_Error_e enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID);
am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID);
am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID);
am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass);
@@ -81,6 +82,7 @@ public:
am_Error_e removeSinkDB(const am_sinkID_t sinkID);
am_Error_e removeSourceDB(const am_sourceID_t sourceID);
am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID);
+ am_Error_e removeConverterDB(const am_converterID_t converterID);
am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID);
am_Error_e removeDomainDB(const am_domainID_t domainID);
am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID);
@@ -90,12 +92,14 @@ public:
am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const;
am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const;
am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const;
+ am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const;
am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const;
am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const;
am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t>& listSinkID) const;
am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const;
am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listCrossfadersID) const;
am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const;
+ am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConverterID) const;
am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const;
am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const;
am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const;
@@ -105,6 +109,7 @@ public:
am_Error_e getListHandles(std::vector<am_Handle_s>& listHandles) const;
am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const;
am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const;
+ am_Error_e getListConverters(std::vector<am_Converter_s>& listConverters) const;
am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const;
am_Error_e getListSystemProperties(std::vector<am_SystemProperty_s>& listSystemProperties) const;
void setCommandReady();
@@ -118,6 +123,7 @@ public:
am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix) ;
+ am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
am_Error_e setVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s>& listVolumes) ;
am_Error_e setSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration) ;
am_Error_e setSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration) ;
diff --git a/AudioManagerDaemon/include/CAmControlSender.h b/AudioManagerDaemon/include/CAmControlSender.h
index 58bae0b..fb82484 100644
--- a/AudioManagerDaemon/include/CAmControlSender.h
+++ b/AudioManagerDaemon/include/CAmControlSender.h
@@ -61,7 +61,9 @@ public:
am_Error_e hookSystemRegisterSource(const am_Source_s& sourceData, am_sourceID_t& sourceID) ;
am_Error_e hookSystemDeregisterSource(const am_sourceID_t sourceID) ;
am_Error_e hookSystemRegisterGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) ;
+ am_Error_e hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID);
am_Error_e hookSystemDeregisterGateway(const am_gatewayID_t gatewayID) ;
+ am_Error_e hookSystemDeregisterConverter(const am_converterID_t converterID) ;
am_Error_e hookSystemRegisterCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) ;
am_Error_e hookSystemDeregisterCrossfader(const am_crossfaderID_t crossfaderID) ;
void hookSystemSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume) ;
@@ -92,6 +94,7 @@ public:
am_Error_e hookSystemUpdateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
am_Error_e hookSystemUpdateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
am_Error_e hookSystemUpdateGateway(const am_gatewayID_t gatewayID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFromats, const std::vector<bool>& convertionMatrix) ;
+ am_Error_e hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFromats, const std::vector<bool>& convertionMatrix);
void cbAckSetVolume(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes, const am_Error_e error) ;
void cbAckSetSinkNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ;
void cbAckSetSourceNotificationConfiguration(const am_Handle_s handle, const am_Error_e error) ;
diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
index 0793bf8..0c97185 100644
--- a/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
+++ b/AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
@@ -27,7 +27,9 @@
#include <sstream>
#include <iostream>
#include <unordered_map>
+#include <algorithm>
#include <assert.h>
+#include <vector>
#include "IAmDatabaseHandler.h"
namespace am
@@ -62,6 +64,7 @@ class CAmDatabaseHandlerMap : public IAmDatabaseHandler
bool mFirstStaticSink; //!< bool for dynamic range handling
bool mFirstStaticSource; //!< bool for dynamic range handling
bool mFirstStaticGateway; //!< bool for dynamic range handling
+ bool mFirstStaticConverter; //!< bool for dynamic range handling
bool mFirstStaticSinkClass; //!< bool for dynamic range handling
bool mFirstStaticSourceClass; //!< bool for dynamic range handling
bool mFirstStaticCrossfader; //!< bool for dynamic range handling
@@ -74,6 +77,7 @@ public:
am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID);
am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID);
am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID);
+ am_Error_e enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID);
am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID);
am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID);
am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID);
@@ -104,6 +108,7 @@ public:
am_Error_e removeSinkDB(const am_sinkID_t sinkID);
am_Error_e removeSourceDB(const am_sourceID_t sourceID);
am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID);
+ am_Error_e removeConverterDB(const am_converterID_t converterID);
am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID);
am_Error_e removeDomainDB(const am_domainID_t domainID);
am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID);
@@ -112,6 +117,7 @@ public:
am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const;
am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const;
am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const;
+ am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const;
am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const;
am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const;
am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const;
@@ -124,6 +130,7 @@ public:
am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const;
am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listGatewaysID) const;
am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const;
+ am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConvertersID) const;
am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const;
am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const;
am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const;
@@ -132,6 +139,7 @@ public:
am_Error_e getListSourceClasses(std::vector<am_SourceClass_s>& listSourceClasses) const;
am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const;
am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const;
+ am_Error_e getListConverters(std::vector<am_Converter_s> & listConverters) const;
am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const;
am_Error_e getListVisibleMainConnections(std::vector<am_MainConnectionType_s>& listConnections) const;
am_Error_e getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const;
@@ -147,7 +155,6 @@ public:
am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const;
am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const;
am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const;
- am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree);
am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID);
am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID);
@@ -160,11 +167,12 @@ public:
am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration);
am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration);
am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_CustomAvailabilityReason_t>& listSourceConnectionFormats, const std::vector<am_CustomAvailabilityReason_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
+ am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration);
am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration);
bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const;
- bool existcrossFader(const am_crossfaderID_t crossfaderID) const;
+ bool existCrossFader(const am_crossfaderID_t crossfaderID) const;
bool existConnection(const am_Connection_s & connection) const;
bool existConnectionID(const am_connectionID_t connectionID) const;
bool existSource(const am_sourceID_t sourceID) const;
@@ -175,13 +183,19 @@ public:
bool existSinkName(const std::string& name) const;
bool existDomain(const am_domainID_t domainID) const;
bool existGateway(const am_gatewayID_t gatewayID) const;
+ 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;
+ bool isComponentConnected(const am_Converter_s & converter) const;
void dump( std::ostream & output ) const;
+ am_Error_e enumerateSources(std::function<void(const am_Source_s & element)> cb) const;
+ am_Error_e enumerateSinks(std::function<void(const am_Sink_s & element)> cb) const;
+ am_Error_e enumerateGateways(std::function<void(const am_Gateway_s & element)> cb) const;
+ am_Error_e enumerateConverters(std::function<void(const am_Converter_s & element)> cb) const;
/**
* The following structures extend the base structures with the field 'reserved'.
*/
@@ -260,6 +274,9 @@ public:
AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s)
AM_TYPEDEF_SUBCLASS_END(CAmGateway)
+ AM_TYPEDEF_SUBCLASS_BEGIN(am_Converter_Database_s, am_Converter_s)
+ AM_TYPEDEF_SUBCLASS_END(CAmConverter)
+
AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s)
AM_TYPEDEF_SUBCLASS_END(CAmCrossfader)
@@ -270,6 +287,7 @@ public:
typedef std::unordered_map<am_sinkID_t, CAmSink> CAmMapSink;
typedef std::unordered_map<am_sourceID_t, CAmSource> CAmMapSource;
typedef std::unordered_map<am_gatewayID_t, CAmGateway> CAmMapGateway;
+ typedef std::unordered_map<am_converterID_t, CAmConverter> CAmMapConverter;
typedef std::unordered_map<am_crossfaderID_t, CAmCrossfader> CAmMapCrossfader;
typedef std::unordered_map<am_connectionID_t, CAmConnection> CAmMapConnection;
typedef std::unordered_map<am_mainConnectionID_t, CAmMainConnection> CAmMapMainConnection;
@@ -303,6 +321,7 @@ public:
am_Identifier_s mCurrentSinkID; //!< sink ID
am_Identifier_s mCurrentSourceID; //!< source ID
am_Identifier_s mCurrentGatewayID; //!< gateway ID
+ am_Identifier_s mCurrentConverterID; //!< converter ID
am_Identifier_s mCurrentCrossfaderID; //!< crossfader ID
am_Identifier_s mCurrentConnectionID; //!< connection ID
am_Identifier_s mCurrentMainConnectionID; //!< mainconnection ID
@@ -314,6 +333,7 @@ public:
CAmMapSink mSinkMap; //!< map for sink structures
CAmMapSource mSourceMap; //!< map for source structures
CAmMapGateway mGatewayMap; //!< map for gateway structures
+ CAmMapConverter mConverterMap; //!< map for converter structures
CAmMapCrossfader mCrossfaderMap; //!< map for crossfader structures
CAmMapConnection mConnectionMap; //!< map for connection structures
CAmMapMainConnection mMainConnectionMap; //!< map for main connection structures
@@ -325,13 +345,14 @@ public:
mCurrentSinkID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
mCurrentSourceID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
mCurrentGatewayID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
+ mCurrentConverterID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
mCurrentCrossfaderID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
mCurrentConnectionID(1, AM_MAX_CONNECTIONS),
mCurrentMainConnectionID(1, AM_MAX_MAIN_CONNECTIONS),
mSystemProperties(),
mDomainMap(),mSourceClassesMap(), mSinkClassesMap(), mSinkMap(AM_MAP_CAPACITY), mSourceMap(AM_MAP_CAPACITY),
- mGatewayMap(), mCrossfaderMap(), mConnectionMap(), mMainConnectionMap()
+ mGatewayMap(), mConverterMap(), mCrossfaderMap(), mConnectionMap(), mMainConnectionMap()
{};
/**
* \brief Increases a given map ID.
@@ -386,11 +407,18 @@ public:
bool insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID);
bool insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID);
bool insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID);
+ bool insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID);
bool insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID);
bool insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID);
bool insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass);
const am_Sink_Database_s * sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const;
const am_Source_Database_s * sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const;
+ template <class Component> bool isConnected(const Component & comp) const
+ {
+ return std::find_if(mMappedData.mConnectionMap.begin(), mMappedData.mConnectionMap.end(),[&](const std::pair<am_connectionID_t, am_Connection_Database_s>& rConnection){
+ return (rConnection.second.sinkID == comp.sinkID ||rConnection.second.sourceID ==comp.sourceID);})!=mMappedData.mConnectionMap.end();
+ }
+
CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer
ListConnectionFormat mListConnectionFormat; //!< list of connection formats
diff --git a/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h b/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h
index fad2e57..b53bd7f 100644
--- a/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h
+++ b/AudioManagerDaemon/include/CAmDatabaseHandlerSQLite.h
@@ -53,6 +53,7 @@ private:
bool mFirstStaticSink; //!< bool for dynamic range handling
bool mFirstStaticSource; //!< bool for dynamic range handling
bool mFirstStaticGateway; //!< bool for dynamic range handling
+ bool mFirstStaticConverter; //!< bool for dynamic range handling
bool mFirstStaticSinkClass; //!< bool for dynamic range handling
bool mFirstStaticSourceClass; //!< bool for dynamic range handling
bool mFirstStaticCrossfader; //!< bool for dynamic range handling
@@ -71,6 +72,7 @@ public:
am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID);
am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID);
am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID);
+ am_Error_e enterConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID);
am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID);
am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID);
am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID);
@@ -101,6 +103,7 @@ public:
am_Error_e removeSinkDB(const am_sinkID_t sinkID);
am_Error_e removeSourceDB(const am_sourceID_t sourceID);
am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID);
+ am_Error_e removeConverterDB(const am_converterID_t converterID);
am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID);
am_Error_e removeDomainDB(const am_domainID_t domainID);
am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID);
@@ -109,6 +112,7 @@ public:
am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const;
am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const;
am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const;
+ am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const;
am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const;
am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const;
am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const;
@@ -121,6 +125,7 @@ public:
am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const;
am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listGatewaysID) const;
am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const;
+ am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConvertersID) const;
am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const;
am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const;
am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const;
@@ -129,6 +134,7 @@ public:
am_Error_e getListSourceClasses(std::vector<am_SourceClass_s>& listSourceClasses) const;
am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const;
am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const;
+ am_Error_e getListConverters(std::vector<am_Converter_s> & listConverters) const;
am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const;
am_Error_e getListVisibleMainConnections(std::vector<am_MainConnectionType_s>& listConnections) const;
am_Error_e getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const;
@@ -139,12 +145,12 @@ public:
am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_CustomAvailabilityReason_t> & listConnectionFormats) const;
am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_CustomAvailabilityReason_t> & listConnectionFormats) const;
am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const;
+ am_Error_e getListConverterConnectionFormats(const am_converterID_t converterID, std::vector<bool> & listConnectionFormat) const;
am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const;
am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const;
am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const;
am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const;
am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const;
- am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree);
am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID);
am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID);
@@ -157,11 +163,12 @@ public:
am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration);
am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration);
am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_CustomAvailabilityReason_t>& listSourceConnectionFormats, const std::vector<am_CustomAvailabilityReason_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
+ am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration);
am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration);
bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const;
- bool existcrossFader(const am_crossfaderID_t crossfaderID) const;
+ bool existCrossFader(const am_crossfaderID_t crossfaderID) const;
bool existConnection(const am_Connection_s & connection) const;
bool existConnectionID(const am_connectionID_t connectionID) const;
bool existSource(const am_sourceID_t sourceID) const;
@@ -172,13 +179,20 @@ public:
bool existSinkName(const std::string& name) const;
bool existDomain(const am_domainID_t domainID) const;
bool existGateway(const am_gatewayID_t gatewayID) const;
+ 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;
+ bool isComponentConnected(const am_Converter_s & converter) const;
//todo: Implement dump for SQLite database handler
void dump( std::ostream & output) const { output << __FUNCTION__ << " not implemented!"; };
+ am_Error_e enumerateSources(std::function<void(const am_Source_s & element)> cb) const;
+ am_Error_e enumerateSinks(std::function<void(const am_Sink_s & element)> cb) const;
+ am_Error_e enumerateGateways(std::function<void(const am_Gateway_s & element)> cb) const;
+ am_Error_e enumerateConverters(std::function<void(const am_Converter_s & element)> cb) const;
};
}
diff --git a/AudioManagerDaemon/include/CAmDatabaseObserver.h b/AudioManagerDaemon/include/CAmDatabaseObserver.h
index e3a016d..d6f980d 100644
--- a/AudioManagerDaemon/include/CAmDatabaseObserver.h
+++ b/AudioManagerDaemon/include/CAmDatabaseObserver.h
@@ -49,6 +49,7 @@ public:
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);
@@ -56,6 +57,7 @@ public:
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);
diff --git a/AudioManagerDaemon/include/CAmGraph.h b/AudioManagerDaemon/include/CAmGraph.h
new file mode 100644
index 0000000..16783e6
--- /dev/null
+++ b/AudioManagerDaemon/include/CAmGraph.h
@@ -0,0 +1,622 @@
+/**
+ * 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 Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2014
+ *
+ * \file CAmGraph.h
+ * For further information see http://www.genivi.org/.
+ *
+ */
+
+#ifndef GRAPH_H
+#define GRAPH_H
+
+#include <functional>
+#include <iostream>
+#include <vector>
+#include <map>
+#include <list>
+#include <stack>
+#include <queue>
+#include <algorithm>
+#include <limits.h>
+#include <iomanip>
+#include <cstring>
+#include <set>
+
+
+namespace am
+{
+ /**
+ * Graph element status.
+ */
+ typedef enum:uint8_t
+ {
+ GES_NOT_VISITED,
+ GES_IN_PROGRESS,
+ GES_VISITED
+ }am_GraphElementStatus_e;
+
+ /**
+ * Callback parameter telling on which position in the path we are.
+ */
+ typedef enum:uint8_t
+ {
+ GRAPH_PATH_START, //at the beginning of the path
+ GRAPH_PATH_MIDDLE, //in middle of the path
+ GRAPH_PATH_END //at the end of the path
+ }am_GraphPathPosition_e;
+
+
+ /**
+ * This class is base class for nodes and vertices.
+ */
+ class CAmGraphElement
+ {
+ am_GraphElementStatus_e mStatus; //!< item status
+ public:
+ CAmGraphElement(): mStatus(GES_NOT_VISITED) { };
+ ~CAmGraphElement() { };
+ /**
+ * Setter and getter.
+ */
+ void setStatus(const am_GraphElementStatus_e s) { mStatus = s; };
+ am_GraphElementStatus_e getStatus() const { return mStatus; };
+ };
+
+ template <class NodeData> class CAmNode : public CAmGraphElement
+ {
+ uint16_t mIndex; //!< uint16_t index used for direct access
+ NodeData mData; //!< NodeData user data
+ public:
+ CAmNode(const NodeData & in):CAmGraphElement(), mIndex(0), mData(in) { };
+ CAmNode(const NodeData & in, const uint16_t index):CAmGraphElement(), mIndex(index), mData(in) { };
+ ~CAmNode() { };
+ /**
+ * Setters and getters.
+ */
+ NodeData & getData() { return mData; }
+ uint16_t getIndex() const { return mIndex; }
+ void setIndex(uint16_t index) { mIndex = index; }
+ };
+
+ template <class NodeData, class VertexData> class CAmVertex : public CAmGraphElement
+ {
+ CAmNode<NodeData>* mpNode; //!< CAmNode<NodeData>* pointer to a node
+ VertexData mVertexData; //!< VertexData vertex user data
+ uint16_t mWeight; //!< uint16_t a positive value used in the shortest path algorithms
+ public:
+ CAmVertex(CAmNode<NodeData> *aNode, const VertexData & vertexData, const uint16_t weight):CAmGraphElement(),
+ mpNode(aNode), mVertexData(vertexData), mWeight(weight) { };
+ ~CAmVertex() { };
+ /**
+ * Setters and getters.
+ */
+ CAmNode<NodeData>* getNode() const { return mpNode; }
+ VertexData & getData() { return mVertexData; }
+ uint16_t getWeight() const { return mWeight; }
+ void setWeight(const uint16_t weight) { mWeight=weight; }
+ };
+
+ /**
+ * Class representing a directed or undirected graph. It contains nodes and connections.
+ * T, V are types for custom user data.
+ */
+ template <class T, class V> class CAmGraph
+ {
+ typedef typename std::vector<CAmNode<T>*> CAmListNodePtrs;
+ typedef typename std::list<CAmVertex<T,V>> CAmListVertices;
+ typedef typename std::list<CAmVertex<T,V>>::iterator CAmListVerticesItr;
+ typedef typename std::list<CAmVertex<T,V>>::const_iterator CAmListVerticesItrConst;
+ typedef typename std::list<CAmListVertices> CAmNodesAdjList;
+ typedef typename std::list<CAmListVertices>::iterator CAmNodesAdjListItr;
+ typedef typename std::list<CAmListVertices>::const_iterator CAmNodesAdjListItrConst;
+ typedef typename std::list<CAmNode<T>> CAmListNodes;
+ typedef typename std::list<CAmNode<T>>::iterator CAmListNodesItr;
+ typedef typename std::list<CAmNode<T>>::const_iterator CAmListNodesItrConst;
+ typedef typename std::vector<CAmNode<T>*> CAmNodeReferenceList;
+ typedef typename std::vector<CAmListVertices*> CAmVertexReferenceList;
+
+ CAmListNodes mStoreNodes; //!< CAmListNodes list with all nodes
+ CAmNodesAdjList mStoreAdjList; //!< CAmNodesAdjList adjacency list
+ CAmNodeReferenceList mPointersNodes; //!< CAmNodeReferenceList vector with pointers to nodes for direct access
+ CAmVertexReferenceList mPointersAdjList; //!< CAmVertexReferenceList vector with pointers to vertices for direct access
+ bool mIsCyclic; //!< bool the graph has cycles or not
+
+ /**
+ * Updates the node indexes after adding or removing nodes.
+ *
+ * @param fromIndex updates all nodes from given index.
+ */
+ void updateIndexes(const int16_t fromIndex)
+ {
+ if( fromIndex<mPointersNodes.size() )
+ {
+ for(auto iter = mPointersNodes.begin()+fromIndex; iter!=mPointersNodes.end(); iter++)
+ (*iter)->setIndex(iter-mPointersNodes.begin());
+ }
+ }
+
+
+ /**
+ * Finds the shortest path and the minimal weights from given node.
+ *
+ * @param node start node.
+ * @param minDistance vector with all result distances.
+ * @param previous vector with previous nodes.
+ */
+
+ typedef uint16_t vertex_t;
+ typedef uint16_t weight_t;
+
+ void findShortestsPathsFromNode(const CAmNode<T> & node, std::vector<weight_t> &minDistance, std::vector<CAmNode<T> *> &previous)
+ {
+ typename CAmListVertices::const_iterator nIter;
+ CAmListVertices * neighbors;
+ weight_t dist, weight, v, distanceThroughU;
+ CAmNode<T>* pU;
+ CAmVertex<T,V> * pVertex;
+ CAmNode<T> *pDstNode;
+
+ size_t n = mPointersAdjList.size();
+ std::set<std::pair<weight_t, CAmNode<T>*> > vertexQueue;
+
+ minDistance.clear();
+ minDistance.resize(n, std::numeric_limits<weight_t>::max());
+ minDistance[node.getIndex()] = 0;
+ previous.clear();
+ previous.resize(n, NULL);
+
+ vertexQueue.insert(std::make_pair(minDistance[node.getIndex()], (CAmNode<T>*)&node));
+
+ while (!vertexQueue.empty())
+ {
+ dist = vertexQueue.begin()->first;
+ pU = vertexQueue.begin()->second;
+ vertexQueue.erase(vertexQueue.begin());
+ //todo: terminate the search at this position if you want the path to a target node ( if(pU==target)break; )
+
+ // Visit each edge exiting u
+ neighbors = mPointersAdjList[pU->getIndex()];
+ nIter = neighbors->begin();
+ for (; nIter != neighbors->end(); nIter++)
+ {
+ pVertex = (CAmVertex<T,V> *)&(*nIter);
+ pDstNode = pVertex->getNode();
+
+ v = pDstNode->getIndex();
+ weight = pVertex->getWeight();
+ distanceThroughU = dist + weight;
+ if (distanceThroughU < minDistance[pDstNode->getIndex()])
+ {
+ vertexQueue.erase(std::make_pair(minDistance[v], pDstNode));
+ minDistance[v] = distanceThroughU;
+ previous[v] = pU;
+ vertexQueue.insert(std::make_pair(minDistance[v], pDstNode));
+ }
+ }
+ }
+ }
+
+ /**
+ * Constructs a path to given node after findShortestsPathsFromNode has been called.
+ *
+ * @param node end node.
+ * @param previous vector with previous nodes.
+ * @param result result path.
+ */
+ void constructShortestPathTo(const CAmNode<T> & node, const std::vector<CAmNode<T> *> &previous, CAmListNodePtrs & result)
+ {
+ CAmNode<T> * vertex = (CAmNode<T> *)&node;
+
+ int i=0;
+ while ( (vertex = previous[vertex->getIndex()])!=NULL )
+ {
+ result.insert(result.begin(), vertex);
+ i++;
+ }
+ if(i)
+ result.push_back((CAmNode<T> *)&node);
+ }
+
+ /**
+ * Calls a function with every node from this path after findShortestsPathsFromNode has been called.
+ * The construction of the path is delegated to the caller.
+ *
+ * @param node end node.
+ * @param previous vector with previous nodes.
+ * @param cb callback which is mostly used for constructing.
+ */
+ void constructShortestPathTo(const CAmNode<T> & node, const std::vector<CAmNode<T> *> &previous, std::function<void(const am_GraphPathPosition_e pos, CAmNode<T> &)> cb)
+ {
+ CAmNode<T> * vertex = (CAmNode<T> *)&node;
+ CAmNode<T> * prev = vertex;
+ int i=0;
+ while ( (vertex = previous[vertex->getIndex()])!=NULL )
+ {
+ cb(i==0?GRAPH_PATH_START:GRAPH_PATH_MIDDLE, *prev);
+ prev = vertex;
+ i++;
+ }
+ if(i)
+ cb(GRAPH_PATH_END, *prev);
+ }
+
+ /**
+ * 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.
+ *
+ * @param dst end node.
+ * @param visited vector with current path.
+ * @param cb callback which is mostly used for constructing.
+ */
+ void goThroughAllPaths(const CAmNode<T> & dst, std::vector<CAmNode<T>*> & visited, std::function<void(const CAmNodeReferenceList & path)> cb)
+ {
+ CAmListVertices * nodes = mPointersAdjList[visited.back()->getIndex()];
+ CAmListVerticesItrConst vItr(nodes->begin());
+ for (; vItr != nodes->end(); ++vItr)
+ {
+ const CAmVertex<T,V> & vertex = (*vItr);
+ if(vertex.getNode()->getStatus()!=GES_NOT_VISITED)
+ continue;
+ if (vertex.getNode()==&dst)
+ {
+ vertex.getNode()->setStatus(GES_IN_PROGRESS);
+ visited.push_back(vertex.getNode());
+ //notify observer
+ cb(visited);
+ //remove last node from the list
+ auto last = visited.end()-1;
+ visited.erase(last);
+ vertex.getNode()->setStatus(GES_NOT_VISITED);
+ break;
+ }
+ }
+ vItr = nodes->begin();
+ //bfs like loop
+ for (; vItr != nodes->end(); ++vItr)
+ {
+ const CAmVertex<T,V> & vertex = (*vItr);
+ if(vertex.getNode()->getStatus()!=GES_NOT_VISITED||vertex.getNode()==&dst)
+ continue;
+ vertex.getNode()->setStatus(GES_IN_PROGRESS);
+ visited.push_back(vertex.getNode());
+ goThroughAllPaths(dst, visited, cb);
+ //remove last node from the list
+ auto last = visited.end()-1;
+ visited.erase(last);
+ vertex.getNode()->setStatus(GES_NOT_VISITED);
+ }
+ reset();
+ }
+
+ public:
+ explicit CAmGraph(const std::vector<T> &v):mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList()
+ {
+ typedef typename std::vector<T>::const_iterator inItr;
+ inItr itr(v.begin());
+
+ for (; itr != v.end(); ++itr)
+ {
+ addNode(*itr);
+ }
+
+ mIsCyclic = false;
+ };
+ CAmGraph():mStoreNodes(), mStoreAdjList(), mPointersNodes(), mPointersAdjList(), mIsCyclic(false){};
+ ~CAmGraph(){}
+
+ const CAmListNodes & getNodes() const
+ {
+ return mStoreNodes;
+ }
+
+ /**
+ * Returns pointer to a node which data is equal to the given.
+ * @return pointer to a node or NULL.
+ */
+ const CAmNode<T>* findNode(const T & in)
+ {
+ typename CAmNodeReferenceList::const_iterator itr (mPointersNodes.begin());
+
+ for (; itr != mPointersNodes.end(); ++itr)
+ {
+ if ((*itr)->getData() == in) {
+ return (*itr);
+ }
+ }
+ return NULL;
+ }
+
+ /**
+ * Returns pointer to a vertex which two ends are equal to the given nodes.
+ * @return pointer to a vertex or NULL.
+ */
+ const CAmVertex<T,V>* findVertex(const CAmNode<T> & edge1, const CAmNode<T> & edge2) const
+ {
+ const CAmNode<T> * pEdge2 = (CAmNode<T> *)&edge2;
+ const CAmListVertices * list = mPointersAdjList[edge1.getIndex()];
+ CAmListVerticesItrConst result = std::find_if(list->begin(), list->end(), [&](const CAmVertex<T,V> & refObject){
+ return refObject.getNode()==pEdge2;
+ });
+ if(result!=list->end())
+ return (CAmVertex<T,V>*)&(*result);
+
+ return NULL;
+ }
+
+ bool hasCycles() const
+ {
+ return mIsCyclic;
+ }
+
+
+ /**
+ * Adds a new node to the graph with given user data.
+ * @return reference to the newly inserted node.
+ */
+ CAmNode<T> & 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();
+ }
+
+ /**
+ * Removes a vertex with two ends equal to the given nodes .
+ */
+ void removeVertex(const CAmNode<T> & edge1, const CAmNode<T> & edge2)
+ {
+ const CAmListVertices * list = mPointersAdjList[edge1.getIndex()];
+ CAmListVerticesItr iter = std::find_if(list->begin(), list->end(), [&edge2](const CAmVertex<T,V> & refVertex){
+ return (refVertex.getNode()==&edge2);
+ });
+ if(iter!=list->end())
+ list->erase(iter);
+ }
+
+ /**
+ * Removes all vertices to given node .
+ */
+ void removeAllVerticesToNode(const CAmNode<T> & node)
+ {
+ auto comparator = [&node](const CAmVertex<T,V> & refVertex){
+ return (refVertex.getNode()==&node);
+ };
+ auto itr = mPointersAdjList.begin();
+ for(;itr!=mPointersAdjList.end();itr++)
+ {
+ CAmListVertices * vertices = *itr;
+ auto iterVert = std::find_if(vertices->begin(), vertices->end(), comparator);
+ if(iterVert!=vertices->end())
+ vertices->erase(iterVert);
+ }
+ }
+
+ /**
+ * Removes a node with given user data .
+ */
+ void removeNode(const T & in)
+ {
+ CAmNode<T> * node = findNode(in);
+ if(node!=NULL)
+ removeNode(*node);
+ }
+
+ /**
+ * Removes the given node from the graph .
+ */
+ void removeNode(const CAmNode<T> & 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<T> & otherNode){
+ return &otherNode==&node;
+ });
+ if(iter!=mStoreNodes.end())
+ mStoreNodes.erase(iter);
+ updateIndexes(index);
+ }
+
+ /**
+ * Connect first with last node and set user data and weight to the vertex.
+ */
+ void connectNodes(const CAmNode<T> & first, const CAmNode<T> & last, const V & vertexData, const int16_t weight = 1)
+ {
+ CAmListVertices * list = mPointersAdjList[first.getIndex()];
+ CAmNode<T> * node = mPointersNodes[last.getIndex()];
+ list->emplace_back(node, vertexData, weight);
+ }
+
+ /**
+ * Exists any vertex with two given ends.
+ * @return TRUE on successfully changed ID.
+ */
+ bool isAnyVertex(const CAmNode<T> & edge1, const CAmNode<T> & edge2) const
+ {
+ return findVertex(edge1, edge2)!=NULL;
+ }
+
+ /**
+ * Sets the status of all nodes and vertices to GES_NOT_VISITED.
+ */
+ void reset()
+ {
+ // set all nodes to GES_NOT_VISITED
+ std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [](CAmNode<T> * refNode){
+ if(refNode->getStatus()!= GES_NOT_VISITED)
+ refNode->setStatus(GES_NOT_VISITED);
+ });
+ // set all vertices to GES_NOT_VISITED
+ auto action = [](CAmVertex<T,V> & refVertex){
+ if(refVertex.getStatus()!= GES_NOT_VISITED)
+ refVertex.setStatus(GES_NOT_VISITED);
+ };
+ auto itr1(mPointersAdjList.begin());
+ for (; itr1 != mPointersAdjList.end(); ++itr1)
+ {
+ CAmListVertices * vertices = *itr1;
+ std::for_each(vertices->begin(), vertices->end(), action);
+ }
+ }
+
+ /**
+ * Clears all nodes and vertices.
+ */
+ void clear()
+ {
+ mStoreNodes.clear();
+ mStoreAdjList.clear();
+ mPointersAdjList.clear();
+ mPointersNodes.clear();
+ mPointersAdjList.clear();
+ }
+
+ /**
+ * Goes through all nodes and vertices and calls the callback.
+ */
+ void trace(std::function<void(const CAmNode<T> &, const std::vector<CAmVertex<T,V>*> &)> cb)
+ {
+ std::for_each(mPointersNodes.begin(), mPointersNodes.end(), [&](CAmNode<T> * refNode){
+ CAmListVertices * vertices = mPointersAdjList[refNode->getIndex()];
+ std::vector<CAmVertex<T,V>*> list;
+ std::for_each(vertices->begin(), vertices->end(), [&list](CAmVertex<T,V> & refVertex){
+ list.push_back(&refVertex);
+ });
+ cb(*refNode, list);
+ });
+ }
+
+ /**
+ * Finds the shortest path from given node to all nodes in listTargets.
+ *
+ * @param source start node.
+ * @param listTargets destination nodes.
+ * @param resultPath list with all shortest paths.
+ */
+ void getShortestPath(const CAmNode<T> & source, const CAmListNodePtrs & listTargets, std::vector<CAmListNodePtrs> & resultPath )
+ {
+ const size_t numberOfNodes = mPointersNodes.size();
+ if(numberOfNodes==0)
+ return;
+
+ std::vector<weight_t> min_distance;
+ std::vector<CAmNode<T>*> previous;
+ findShortestsPathsFromNode(source, min_distance, previous);
+
+ for(auto it=listTargets.begin(); it!=listTargets.end(); it++)
+ {
+ CAmNode<T> *node = *it;
+ resultPath.emplace_back();
+ CAmListNodePtrs & path = resultPath.back();
+ constructShortestPathTo(*node, previous, path);
+ if(path.empty())
+ {
+ typename std::vector<CAmListNodePtrs>::iterator iter = resultPath.end();
+ resultPath.erase(--iter);
+ }
+ }
+ }
+
+ /**
+ * Finds the shortest path between two nodes.
+ *
+ * @param source start node.
+ * @param destination destination node.
+ * @param resultPath list with the found shortest paths.
+ */
+ void getShortestPath(const CAmNode<T> & source, const CAmNode<T> & destination, CAmListNodePtrs & resultPath )
+ {
+ const size_t numberOfNodes = mPointersNodes.size();
+ if(numberOfNodes==0)
+ return;
+ std::vector<weight_t> min_distance;
+ std::vector<CAmNode<T>*> previous;
+ findShortestsPathsFromNode(source, min_distance, previous);
+ constructShortestPathTo(destination, previous, resultPath);
+ }
+
+ /**
+ * Finds the shortest path from given node to all nodes in listTargets.
+ * Delegates the construction of the path to the caller.
+ *
+ * @param source start node.
+ * @param listTargets destination nodes.
+ * @param cb callabck.
+ */
+ void getShortestPath(const CAmNode<T> & source,
+ const CAmListNodePtrs & listTargets,
+ std::function<void(const am_GraphPathPosition_e, CAmNode<T> &)> cb )
+ {
+ const size_t numberOfNodes = mPointersNodes.size();
+ if(numberOfNodes==0)
+ return;
+
+ std::vector<weight_t> min_distance;
+ std::vector<CAmNode<T>*> previous;
+ findShortestsPathsFromNode(source, min_distance, previous);
+
+ for(auto it=listTargets.begin(); it!=listTargets.end(); it++)
+ {
+ CAmNode<T>* node = *it;
+ constructShortestPathTo(*node, previous, cb);
+ }
+ }
+
+ /**
+ * Finds the shortest path between two given nodes.
+ * Delegates the construction of the path to the caller.
+ *
+ * @param source start node.
+ * @param destination destination node.
+ * @param cb callabck.
+ */
+ void getShortestPath(const CAmNode<T> & source,
+ const CAmNode<T> & destination,
+ std::function<void(const am_GraphPathPosition_e, CAmNode<T> &)> cb )
+ {
+ const size_t numberOfNodes = mPointersNodes.size();
+ if(numberOfNodes==0)
+ return;
+
+ std::vector<weight_t> min_distance;
+ std::vector<CAmNode<T>*> previous;
+ findShortestsPathsFromNode(source, min_distance, previous);
+ constructShortestPathTo(destination, previous, cb);
+ }
+
+ /**
+ * Finds all possible paths between two given nodes.
+ * Delegates the construction of the path to the caller.
+ *
+ * @param src start node.
+ * @param dst destination node.
+ * @param cb callabck.
+ */
+ void getAllPaths(const CAmNode<T> & src, const CAmNode<T> & dst, std::function<void(const CAmNodeReferenceList & path)> cb)
+ {
+ CAmNodeReferenceList visited;
+ visited.push_back((CAmNode<T>*)&src);
+ goThroughAllPaths(dst, visited, cb);
+ }
+ };
+
+}
+
+#endif
diff --git a/AudioManagerDaemon/include/CAmRouter.h b/AudioManagerDaemon/include/CAmRouter.h
index 76cf5fc..6a3aacc 100644
--- a/AudioManagerDaemon/include/CAmRouter.h
+++ b/AudioManagerDaemon/include/CAmRouter.h
@@ -13,6 +13,7 @@
*
*
* \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
+ * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014
*
* \file CAmRouter.h
* For further information see http://www.genivi.org/.
@@ -22,68 +23,281 @@
#ifndef ROUTER_H_
#define ROUTER_H_
+#include <assert.h>
+#include <vector>
#include "audiomanagertypes.h"
+#include "CAmGraph.h"
+#include "IAmDatabaseHandler.h"
+
namespace am
{
+/**
+ * Optimal path search between a source and a sink is implemented with a graph which contains nodes - sinks, sources, gateways, converters.
+ *
+ * If EXTENDED_ROUTING_GRAPH is defined the graph will contain nodes, which are identified by sinkID, sourceID, gatewayID, converterID and connectionFormat.
+ * All possible connections between all nodes (1 connection is 1 connection format) are represented in the graph (Node[id=1, connectionFormat=1] ---> Node[id=2, connectionFormat=1]).
+ *
+ * If EXTENDED_ROUTING_GRAPH is NOT defined the graph will contain nodes, which 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. This is default.
+ *
+ */
+#undef EXTENDED_ROUTING_GRAPH
+
+/**
+ * Trace on/off.
+ */
+#undef TRACE_GRAPH
+
+
+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
+#ifdef EXTENDED_ROUTING_GRAPH
+ am_CustomConnectionFormat_t inConnectionFormat; //!< input connection format for sink, source, gateway or converter
+ am_CustomConnectionFormat_t outConnectionFormat; //!< output connection format usually for gateways and converters
+#endif
+ 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)
+#ifdef EXTENDED_ROUTING_GRAPH
+ ,inConnectionFormat(CF_UNKNOWN)
+ ,outConnectionFormat(CF_UNKNOWN)
+#endif
+ {}
+
+ bool operator==(const am_RoutingNodeData_s & anotherObject) const
+ {
+ bool result = false;
+ if(type==anotherObject.type)
+ {
+#ifdef EXTENDED_ROUTING_GRAPH
+ result = (inConnectionFormat==anotherObject.inConnectionFormat && outConnectionFormat==anotherObject.outConnectionFormat);
+#else
+ result = true;
+#endif
+ 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
+ void trace() const
+ {
+ if(type==SINK)
+ std::cout << "[SINK:" << data.sink->sinkID << ":" << data.sink->name
+#ifdef EXTENDED_ROUTING_GRAPH
+ << "(" << inConnectionFormat << "," << outConnectionFormat << ")"
+#endif
+ << "]";
+ else if(type==SOURCE)
+ std::cout << "[SOUR:" << data.source->sourceID << ":" << data.source->name
+#ifdef EXTENDED_ROUTING_GRAPH
+ << "(" << inConnectionFormat << "," << outConnectionFormat << ")"
+#endif
+ << "]";
+ else if(type==GATEWAY)
+ std::cout << "[GATE:" << data.gateway->gatewayID << ":" << data.gateway->name
+#ifdef EXTENDED_ROUTING_GRAPH
+ << "(" << inConnectionFormat << "," << outConnectionFormat << ")"
+#endif
+ << "]";
+ else if(type==CONVERTER)
+ std::cout << "[CONV:" << data.converter->converterID << ":" << data.converter->name
+#ifdef EXTENDED_ROUTING_GRAPH
+ << "(" << inConnectionFormat << "," << outConnectionFormat << ")"
+#endif
+ << "]";
+ };
+#endif
+};
+
+#define NodeDataType am_RoutingNodeData_s::am_NodeDataType_e
+
-class IAmDatabaseHandler;
class CAmControlSender;
+
/**
* Implements an autorouting algorithm for connecting sinks and sources via different audio domains.
*/
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
+ CAmGraph<am_RoutingNodeData_s, uint16_t> mRoutingGraph; //!< graph object
+ std::vector<CAmNode<am_RoutingNodeData_s>*> mNodeListSources; //!< vector with pointers to nodes with sources, used for quick access
+ std::vector<CAmNode<am_RoutingNodeData_s>*> mNodeListSinks; //!< vector with pointers to nodes with sinks, used for quick access
+ std::vector<CAmNode<am_RoutingNodeData_s>*> mNodeListGateways; //!< vector with pointers to nodes with gateways, used for quick access
+ std::vector<CAmNode<am_RoutingNodeData_s>*> mNodeListConverters;//!< vector with pointers to nodes with converters, used for quick access
+ std::map<am_sourceID_t, bool> mNodeListSourceStatus; //!< vector with flags preventing going through group of nodes during the path search
+ std::map<am_sinkID_t, bool> mNodeListSinkStatus; //!< vector with flags preventing going through group of nodes during the path search
+ std::map<am_converterID_t, bool> mNodeListConverterStatus; //!< vector with flags preventing going through group of nodes during the path search
+ std::map<am_gatewayID_t, bool> mNodeListGatewayStatus; //!< vector with flags preventing going through group of nodes during the path search
+#ifdef EXTENDED_ROUTING_GRAPH
+ am_Source_s *mpRootSource; //!< pointer to source
+ am_Sink_s *mpRootSink; //!< pointer to sink
+
+ /*
+ * Methods for getting shortest path from the graph.
+ */
+ void getShortestPath(const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultPath);
+ void getShortestPath(std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultPath);
+ void getShortestPath(const am_Source_s & aSource, const am_Sink_s & aSink,
+ std::vector<am_Route_s> & resultPath, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath);
+ void getShortestPath(std::vector<am_Route_s> & routes, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & nodes);
+
+ /**
+ * Returns a sink node with given sinkID and connection format.
+ *
+ * @param sinkID sink id.
+ * @param connectionFormat connection format.
+ * @return pointer to node or NULL.
+ */
+
+ CAmNode<am_RoutingNodeData_s>* sinkNodeWithID(const am_sinkID_t sinkID, const am_CustomConnectionFormat_t connectionFormat);
+ /**
+ * Returns a source node with given sourceID and connection format.
+ *
+ * @param sourceID source id.
+ * @param connectionFormat connection format.
+ * @return pointer to node or NULL.
+ */
+ CAmNode<am_RoutingNodeData_s>* sourceNodeWithID(const am_sourceID_t sourceID, const am_CustomConnectionFormat_t connectionFormat);
+#else
+ CAmNode<am_RoutingNodeData_s> *mpRootSource; //!< pointer to source node
+ CAmNode<am_RoutingNodeData_s> *mpRootSink; //!< pointer to sink node
+
+ am_Error_e determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector<CAmNode<am_RoutingNodeData_s>*> & nodes);
+ am_Error_e doConnectionFormatsForPath(am_Route_s & routeObjects,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & route,
+ std::vector<am_RoutingElement_s>::iterator routingElementIterator,
+ std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator routeIterator);
+ void getShortestPath(const CAmNode<am_RoutingNodeData_s> & source,
+ const CAmNode<am_RoutingNodeData_s> & destination,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & resultPath);
+ void getShortestPath(std::vector<CAmNode<am_RoutingNodeData_s>*> & resultPath);
+ void getShortestPath(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink,
+ am_Route_s & resultPath, std::vector<CAmNode<am_RoutingNodeData_s>*> & resultNodesPath);
+ void getShortestPath(am_Route_s & resultPath, std::vector<CAmNode<am_RoutingNodeData_s>*> & resultNodesPath);
+ am_Error_e getAllPaths(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink,
+ std::vector<am_Route_s> & resultPath, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath);
+ am_Error_e getAllPaths(std::vector<am_Route_s> & resultPath, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath);
+
+ /**
+ * Returns a sink node with given sinkID.
+ *
+ * @param sinkID sink id.
+ * @return pointer to node or NULL.
+ */
+ CAmNode<am_RoutingNodeData_s>* sinkNodeWithID(const am_sinkID_t sinkID);
+
+ /**
+ * Returns a source node with given sourceID.
+ *
+ * @param sourceID source id.
+ * @return pointer to node or NULL.
+ */
+ CAmNode<am_RoutingNodeData_s>* sourceNodeWithID(const am_sourceID_t sourceID);
+#endif
+
+ /**
+ * Makes connection between two nodes.
+ *
+ * @param node1.
+ * @param node2.
+ * @param vertexData associated data.
+ * @param weight connection weight used for finding optimal path.
+ */
+ void connectNodes(const CAmNode<am_RoutingNodeData_s> & node1,
+ const CAmNode<am_RoutingNodeData_s> & node2,
+ const am_CustomConnectionFormat_t vertexData,
+ const int16_t weight = 1);
+ /**
+ * Builds path in a domain from source to sink.
+ *
+ * @param aSource starting point.
+ * @param aSink ending point.
+ */
+ bool routeInSameDomain(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink);
+
+ /**
+ * Builds path from source to sink when the source and the sink belongs to different domains.
+ *
+ * @param aSource starting point.
+ * @param aSink ending point.
+ */
+ bool routeInAnotherDomain(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink);
+ void clear();
+
+ /**
+ * Fills the graph with nodes and connections.
+ *
+ * @param aSource starting point.
+ * @param aSink ending point.
+ */
+ void buildGraph(const am_Source_s & aSource, const am_Sink_s & aSink);
+ template <class Component> bool isComponentConnected(const Component & comp)
+ {
+ return mpDatabaseHandler->isComponentConnected(comp);
+ }
+
public:
CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender);
~CAmRouter();
+
+ /**
+ * Finds all possible 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 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<am_Route_s>& returnList);
+ am_Error_e getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<am_Route_s> & listRoutes);
-private:
- am_Error_e findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector<am_RoutingElement_s>& listRoute, std::vector<am_RoutingElement_s>::iterator routeIterator, std::vector<am_gatewayID_t>::iterator gatewayIterator);
- void listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_CustomConnectionFormat_t>& listFormats) const;
- void listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_CustomConnectionFormat_t sinkConnectionFormat, std::vector<am_CustomConnectionFormat_t>& listFormats) const;
- IAmDatabaseHandler* mpDatabaseHandler; //!< pointer to database handler
- CAmControlSender* mpControlSender; //!< pointer the controlsender - is used to retrieve information for the optimal route
-};
+ /**
+ * Helper methods.
+ */
+ static bool getAllowedFormatsFromConvMatrix(const std::vector<bool> & convertionMatrix,
+ const std::vector<am_CustomConnectionFormat_t> & listSourceFormats,
+ const std::vector<am_CustomConnectionFormat_t> & listSinkFormats,
+ std::vector<am_CustomConnectionFormat_t> & sourceFormats,
+ std::vector<am_CustomConnectionFormat_t> & sinkFormats);
+ static bool getRestrictedOutputFormats(const std::vector<bool> & convertionMatrix,
+ const std::vector<am_CustomConnectionFormat_t> & listSourceFormats,
+ const std::vector<am_CustomConnectionFormat_t> & listSinkFormats,
+ const am_CustomConnectionFormat_t connectionFormat,
+ std::vector<am_CustomConnectionFormat_t> & listFormats);
-/**
- * an item in the routing tree
- */
-class CAmRoutingTreeItem
-{
-public:
- CAmRoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID = 0, CAmRoutingTreeItem *parent = 0);
- ~CAmRoutingTreeItem();
- void appendChild(CAmRoutingTreeItem *newChild); //!< appends a new child
- void returnChildItems(std::vector<CAmRoutingTreeItem*> listChildItems); //!< returns the list of childs
- am_domainID_t returnDomainID() const; //!< returns the domainID of the tree
- am_gatewayID_t returnGatewayID() const; //!< returns the gatewayID of the tree
- CAmRoutingTreeItem* returnParent() const; //!< returns the parent item of the tree
-private:
- std::vector<CAmRoutingTreeItem*> mListChildItems; //!< List of all child items
- am_domainID_t mDomainID; //!< the domain ID of the item
- am_gatewayID_t mGatewayID; //!< the gateway Id
- CAmRoutingTreeItem *mpParentItem; //!< pointer to the parent item
+ static void listPossibleConnectionFormats(std::vector<am_CustomConnectionFormat_t> & inListSourceFormats,
+ std::vector<am_CustomConnectionFormat_t> & inListSinkFormats,
+ std::vector<am_CustomConnectionFormat_t> & outConnectionFormats);
};
-/**
- * a routing tree
- */
-class CAmRoutingTree
-{
-public:
- CAmRoutingTree(const am_domainID_t rootDomainID);
- ~CAmRoutingTree();
- CAmRoutingTreeItem* insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent);
- void getRoute(CAmRoutingTreeItem* targetItem, std::vector<am_gatewayID_t>& listGateways);
- am_domainID_t returnRootDomainID() const;
- CAmRoutingTreeItem* returnRootItem();
-private:
- CAmRoutingTreeItem mRootItem; //!< pointer to root item
- std::vector<CAmRoutingTreeItem*> mListChild; //!< list of all childs
-};
} /* namespace am */
#endif /* ROUTER_H_ */
diff --git a/AudioManagerDaemon/include/CAmRoutingReceiver.h b/AudioManagerDaemon/include/CAmRoutingReceiver.h
index 4eca2aa..bf42f6b 100644
--- a/AudioManagerDaemon/include/CAmRoutingReceiver.h
+++ b/AudioManagerDaemon/include/CAmRoutingReceiver.h
@@ -58,7 +58,9 @@ public:
am_Error_e registerDomain(const am_Domain_s& domainData, am_domainID_t& domainID);
am_Error_e deregisterDomain(const am_domainID_t domainID);
am_Error_e registerGateway(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID);
+ am_Error_e registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID);
am_Error_e deregisterGateway(const am_gatewayID_t gatewayID);
+ am_Error_e deregisterConverter(const am_converterID_t converterID);
am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
am_Error_e registerSink(const am_Sink_s& sinkData, am_sinkID_t& sinkID);
am_Error_e deregisterSink(const am_sinkID_t sinkID);
@@ -82,6 +84,7 @@ public:
void confirmRoutingReady(const uint16_t handle, const am_Error_e error);
void confirmRoutingRundown(const uint16_t handle, const am_Error_e error);
am_Error_e updateGateway(const am_gatewayID_t gatewayID, const std::vector<am_CustomConnectionFormat_t>& listSourceFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkFormats, const std::vector<bool>& convertionMatrix) ;
+ am_Error_e updateConverter(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkFormats, const std::vector<bool>& convertionMatrix);
am_Error_e updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
am_Error_e updateSource(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties) ;
void ackSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& listvolumes, const am_Error_e error) ;
diff --git a/AudioManagerDaemon/include/IAmDatabaseHandler.h b/AudioManagerDaemon/include/IAmDatabaseHandler.h
index 8a36801..e053635 100644
--- a/AudioManagerDaemon/include/IAmDatabaseHandler.h
+++ b/AudioManagerDaemon/include/IAmDatabaseHandler.h
@@ -27,6 +27,7 @@
#include <vector>
#include <string>
#include <iostream>
+#include <functional>
namespace am
{
@@ -62,6 +63,7 @@ public:
virtual am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID) = 0;
virtual am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID) = 0;
virtual am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID) = 0;
+ virtual am_Error_e enterConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID) = 0;
virtual am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID) = 0;
virtual am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID) = 0;
virtual am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID) = 0;
@@ -92,6 +94,7 @@ public:
virtual am_Error_e removeSinkDB(const am_sinkID_t sinkID) = 0;
virtual am_Error_e removeSourceDB(const am_sourceID_t sourceID) = 0;
virtual am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID) = 0;
+ virtual am_Error_e removeConverterDB(const am_converterID_t converterID) = 0;
virtual am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID) = 0;
virtual am_Error_e removeDomainDB(const am_domainID_t domainID) = 0;
virtual am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID) = 0;
@@ -100,6 +103,7 @@ public:
virtual am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const = 0;
virtual am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const = 0;
virtual am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const = 0;
+ virtual am_Error_e getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const = 0;
virtual am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const = 0;
virtual am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const = 0;
virtual am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const = 0;
@@ -112,6 +116,7 @@ public:
virtual am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const = 0;
virtual am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listGatewaysID) const = 0;
virtual am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const = 0;
+ virtual am_Error_e getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConvertersID) const = 0;
virtual am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const = 0;
virtual am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const = 0;
virtual am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const = 0;
@@ -120,6 +125,7 @@ public:
virtual am_Error_e getListSourceClasses(std::vector<am_SourceClass_s>& listSourceClasses) const = 0;
virtual am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const = 0;
virtual am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const = 0;
+ virtual am_Error_e getListConverters(std::vector<am_Converter_s> & listConverters) const = 0;
virtual am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const = 0;
virtual am_Error_e getListVisibleMainConnections(std::vector<am_MainConnectionType_s>& listConnections) const = 0;
virtual am_Error_e getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const = 0;
@@ -135,7 +141,6 @@ public:
virtual am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const = 0;
virtual am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const = 0;
virtual am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const = 0;
- virtual am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree) = 0;
virtual am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID) = 0;
virtual am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID) = 0;
virtual am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID) = 0;
@@ -148,11 +153,12 @@ public:
virtual am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0;
virtual am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration) = 0;
virtual am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix) = 0;
+ virtual am_Error_e changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& 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 existCrossFader(const am_crossfaderID_t crossfaderID) const = 0;
virtual bool existConnection(const am_Connection_s & connection) const = 0;
virtual bool existConnectionID(const am_connectionID_t connectionID) const = 0;
virtual bool existSource(const am_sourceID_t sourceID) const = 0;
@@ -168,9 +174,14 @@ public:
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;
+ virtual bool isComponentConnected(const am_Converter_s & converter) const = 0;
virtual am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const = 0; //!< calculates a new main connection delay
virtual void dump( std::ostream & output) const = 0 ;
+ virtual am_Error_e enumerateSources(std::function<void(const am_Source_s & element)> cb) const = 0 ;
+ virtual am_Error_e enumerateSinks(std::function<void(const am_Sink_s & element)> cb) const = 0 ;
+ virtual am_Error_e enumerateGateways(std::function<void(const am_Gateway_s & element)> cb) const = 0 ;
+ virtual am_Error_e enumerateConverters(std::function<void(const am_Converter_s & element)> cb) const = 0 ;
};
diff --git a/AudioManagerDaemon/src/CAmControlReceiver.cpp b/AudioManagerDaemon/src/CAmControlReceiver.cpp
index ae017e2..f576f5e 100644
--- a/AudioManagerDaemon/src/CAmControlReceiver.cpp
+++ b/AudioManagerDaemon/src/CAmControlReceiver.cpp
@@ -184,6 +184,11 @@ am_Error_e CAmControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData,
return (mDatabaseHandler->enterGatewayDB(gatewayData, gatewayID));
}
+am_Error_e CAmControlReceiver::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID)
+{
+ return (mDatabaseHandler->enterConverterDB(converterData, converterID));
+}
+
am_Error_e CAmControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
{
return (mDatabaseHandler->enterSourceDB(sourceData, sourceID));
@@ -274,6 +279,11 @@ am_Error_e CAmControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID)
return (mDatabaseHandler->removeGatewayDB(gatewayID));
}
+am_Error_e CAmControlReceiver::removeConverterDB(const am_converterID_t converterID)
+{
+ return (mDatabaseHandler->removeConverterDB(converterID));
+}
+
am_Error_e CAmControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
{
return (mDatabaseHandler->removeCrossfaderDB(crossfaderID));
@@ -314,6 +324,12 @@ am_Error_e CAmControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID,
return (mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData));
}
+am_Error_e CAmControlReceiver::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s & converterData) const
+{
+ return (mDatabaseHandler->getConverterInfoDB(converterID, converterData));
+}
+
+
am_Error_e CAmControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
{
return (mDatabaseHandler->getCrossfaderInfoDB(crossfaderID, crossfaderData));
@@ -339,6 +355,11 @@ am_Error_e CAmControlReceiver::getListGatewaysOfDomain(const am_domainID_t domai
return (mDatabaseHandler->getListGatewaysOfDomain(domainID, listGatewaysID));
}
+am_Error_e CAmControlReceiver::getListConvertersOfDomain(const am_domainID_t domainID,std::vector<am_converterID_t>& listConverterID) const
+{
+ return (mDatabaseHandler->getListConvertersOfDomain(domainID,listConverterID));
+}
+
am_Error_e CAmControlReceiver::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
{
return (mDatabaseHandler->getListMainConnections(listMainConnections));
@@ -384,6 +405,11 @@ am_Error_e CAmControlReceiver::getListGateways(std::vector<am_Gateway_s> & listG
return (mDatabaseHandler->getListGateways(listGateways));
}
+am_Error_e CAmControlReceiver::getListConverters(std::vector<am_Converter_s>& listConverters) const
+{
+ return (mDatabaseHandler->getListConverters(listConverters));
+}
+
am_Error_e CAmControlReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
{
return (mDatabaseHandler->getListSinkClasses(listSinkClasses));
@@ -489,6 +515,12 @@ am_Error_e CAmControlReceiver::changeGatewayDB(const am_gatewayID_t gatewayID, c
return (mDatabaseHandler->changeGatewayDB(gatewayID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix));
}
+am_Error_e CAmControlReceiver::changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)
+{
+ logInfo("CAmControlReceiver::changeConverterDB was called with converterID", converterID);
+ return (mDatabaseHandler->changeConverterDB(converterID,listSourceConnectionFormats,listSinkConnectionFormats,convertionMatrix));
+}
+
am_Error_e CAmControlReceiver::setVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s>& listVolumes)
{
logInfo("CAmControlReceiver::setVolumes got called");
diff --git a/AudioManagerDaemon/src/CAmControlSender.cpp b/AudioManagerDaemon/src/CAmControlSender.cpp
index 229a28b..dd3558e 100644
--- a/AudioManagerDaemon/src/CAmControlSender.cpp
+++ b/AudioManagerDaemon/src/CAmControlSender.cpp
@@ -193,12 +193,24 @@ am_Error_e CAmControlSender::hookSystemRegisterGateway(const am_Gateway_s & gate
return (mController->hookSystemRegisterGateway(gatewayData, gatewayID));
}
+am_Error_e CAmControlSender::hookSystemRegisterConverter(const am_Converter_s& converterData, am_converterID_t& converterID)
+{
+ assert(mController);
+ return (mController->hookSystemRegisterConverter(converterData, converterID));
+}
+
am_Error_e CAmControlSender::hookSystemDeregisterGateway(const am_gatewayID_t gatewayID)
{
assert(mController);
return (mController->hookSystemDeregisterGateway(gatewayID));
}
+am_Error_e CAmControlSender::hookSystemDeregisterConverter(const am_converterID_t converterID)
+{
+ assert(mController);
+ return (mController->hookSystemDeregisterConverter(converterID));
+}
+
am_Error_e CAmControlSender::hookSystemRegisterCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
{
assert(mController);
@@ -414,6 +426,12 @@ am_Error_e CAmControlSender::hookSystemUpdateGateway(const am_gatewayID_t gatewa
return (mController->hookSystemUpdateGateway(gatewayID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix));
}
+am_Error_e CAmControlSender::hookSystemUpdateConverter(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFromats, const std::vector<bool>& convertionMatrix)
+{
+ assert(mController);
+ return (mController->hookSystemUpdateConverter(converterID,listSourceConnectionFormats,listSinkConnectionFromats,convertionMatrix));
+}
+
void CAmControlSender::cbAckSetVolume(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes, const am_Error_e error)
{
assert(mController);
diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
index a7b765d..713eea1 100644
--- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
+++ b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp
@@ -26,13 +26,13 @@
#include <fstream>
#include <sstream>
#include <string>
-#include <algorithm>
#include <limits>
#include "CAmDatabaseHandlerMap.h"
#include "CAmDatabaseObserver.h"
#include "CAmRouter.h"
#include "shared/CAmDltWrapper.h"
+
namespace am
{
@@ -428,6 +428,7 @@ bool CAmDatabaseHandlerMap::CAmMappedData::increaseConnectionID(int16_t & result
CAmDatabaseHandlerMap::CAmDatabaseHandlerMap(): mFirstStaticSink(true), //
mFirstStaticSource(true), //
mFirstStaticGateway(true), //
+ mFirstStaticConverter(true), //
mFirstStaticSinkClass(true), //
mFirstStaticSourceClass(true), //
mFirstStaticCrossfader(true), //
@@ -665,7 +666,7 @@ am_Error_e CAmDatabaseHandlerMap::enterCrossfaderDB(const am_Crossfader_s & cros
if (crossfaderData.crossfaderID != 0 || mFirstStaticCrossfader)
{
//check if the ID already exists
- if (existcrossFader(crossfaderData.crossfaderID))
+ if (existCrossFader(crossfaderData.crossfaderID))
{
crossfaderID = crossfaderData.crossfaderID;
return (E_ALREADY_EXISTS);
@@ -758,6 +759,71 @@ am_Error_e CAmDatabaseHandlerMap::enterGatewayDB(const am_Gateway_s & gatewayDat
return (E_OK);
}
+bool CAmDatabaseHandlerMap::insertConverterDB(const am_Converter_s & converteData, am_converterID_t & converterID)
+{
+ int16_t nextID = 0;
+ if(mMappedData.increaseID(nextID, mMappedData.mCurrentConverterID, converteData.converterID))
+ {
+ converterID = nextID;
+ mMappedData.mConverterMap[nextID] = converteData;
+ mMappedData.mConverterMap[nextID].converterID = nextID;
+ return (true);
+ }
+ else
+ {
+ converterID = 0;
+ logInfo(__PRETTY_FUNCTION__,"Max limit reached.");
+ return (false);
+ }
+}
+
+am_Error_e CAmDatabaseHandlerMap::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID)
+{
+ assert(converterData.converterID<DYNAMIC_ID_BOUNDARY);
+ assert(converterData.sinkID!=0);
+ assert(converterData.sourceID!=0);
+ assert(converterData.domainID!=0);
+ assert(!converterData.name.empty());
+ assert(!converterData.convertionMatrix.empty());
+ assert(!converterData.listSinkFormats.empty());
+ assert(!converterData.listSourceFormats.empty());
+
+ //might be that the sinks and sources are not there during registration time
+ //assert(existSink(gatewayData.sinkID));
+ //assert(existSource(gatewayData.sourceID));
+
+ am_converterID_t tempID = 0;
+ am_converterID_t tempIndex = 0;
+ //if gatewayData is zero and the first Static Sink was already entered, the ID is created
+ bool result;
+ if (converterData.converterID != 0 || mFirstStaticConverter)
+ {
+ //check if the ID already exists
+ if (existGateway(converterData.converterID))
+ {
+ converterID = converterData.converterID;
+ return (E_ALREADY_EXISTS);
+ }
+ }
+ result = insertConverterDB(converterData, tempID);
+ if( false == result )
+ return (E_UNKNOWN);
+
+ tempIndex = tempID;
+ //if the ID is not created, we add it to the query
+ if (converterData.converterID == 0 && mFirstStaticConverter)
+ {
+ mFirstStaticConverter = false;
+ }
+ mMappedData.mConverterMap[tempIndex].converterID = tempID;
+ converterID = tempID;
+
+ logInfo("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]);
+ return (E_OK);
+}
+
void CAmDatabaseHandlerMap::dump( std::ostream & output ) const
{
output << std::endl << "****************** DUMP START ******************" << std::endl;
@@ -1274,11 +1340,28 @@ am_Error_e CAmDatabaseHandlerMap::removeGatewayDB(const am_gatewayID_t gatewayID
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerMap::removeConverterDB(const am_converterID_t converterID)
+{
+ assert(converterID!=0);
+
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+
+ mMappedData.mConverterMap.erase(converterID);
+
+ logInfo("DatabaseHandler::removeConverterDB removed:", converterID);
+ if (mpDatabaseObserver)
+ mpDatabaseObserver->removeConverter(converterID);
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerMap::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
{
assert(crossfaderID!=0);
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -1480,10 +1563,24 @@ am_Error_e CAmDatabaseHandlerMap::getGatewayInfoDB(const am_gatewayID_t gatewayI
}
+am_Error_e CAmDatabaseHandlerMap::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const
+{
+ assert(converterID!=0);
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+
+ converterData = mMappedData.mConverterMap.at(converterID);
+
+ return (E_OK);
+
+}
+
am_Error_e CAmDatabaseHandlerMap::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
{
assert(crossfaderID!=0);
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -1574,6 +1671,24 @@ am_Error_e CAmDatabaseHandlerMap::getListGatewaysOfDomain(const am_domainID_t do
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerMap::getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConvertersID) const
+{
+ assert(domainID!=0);
+ listConvertersID.clear();
+ if (!existDomain(domainID))
+ {
+ return (E_NON_EXISTENT);
+ }
+
+ CAmMapConverter::const_iterator elementIterator = mMappedData.mConverterMap.begin();
+ for (;elementIterator != mMappedData.mConverterMap.end(); ++elementIterator)
+ {
+ if (domainID==elementIterator->second.domainID)
+ listConvertersID.push_back(elementIterator->second.converterID);
+ }
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerMap::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
{
listMainConnections.clear();
@@ -1673,6 +1788,17 @@ am_Error_e CAmDatabaseHandlerMap::getListGateways(std::vector<am_Gateway_s> & li
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerMap::getListConverters(std::vector<am_Converter_s> & listConverters) const
+{
+ listConverters.clear();
+
+ std::for_each(mMappedData.mConverterMap.begin(), mMappedData.mConverterMap.end(), [&](const std::pair<am_converterID_t, am_Converter_s>& ref) {
+ listConverters.push_back(ref.second);
+ });
+
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerMap::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
{
listSinkClasses.clear();
@@ -1959,6 +2085,11 @@ bool CAmDatabaseHandlerMap::existGateway(const am_gatewayID_t gatewayID) const
return existsObjectWithKeyInMap(gatewayID, mMappedData.mGatewayMap);
}
+bool CAmDatabaseHandlerMap::existConverter(const am_converterID_t converterID) const
+{
+ return existsObjectWithKeyInMap(converterID, mMappedData.mConverterMap);
+}
+
am_Error_e CAmDatabaseHandlerMap::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
{
assert(sourceID!=0);
@@ -2141,7 +2272,7 @@ bool CAmDatabaseHandlerMap::existConnectionID(const am_connectionID_t connection
* @param crossfaderID the ID of the crossfader to be checked
* @return true if exists
*/
-bool CAmDatabaseHandlerMap::existcrossFader(const am_crossfaderID_t crossfaderID) const
+bool CAmDatabaseHandlerMap::existCrossFader(const am_crossfaderID_t crossfaderID) const
{
return existsObjectWithKeyInMap(crossfaderID, mMappedData.mCrossfaderMap);
}
@@ -2421,7 +2552,7 @@ am_Error_e CAmDatabaseHandlerMap::changeCrossFaderHotSink(const am_crossfaderID_
assert(crossfaderID!=0);
assert(hotsink!=HS_UNKNOWN);
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -2430,54 +2561,16 @@ am_Error_e CAmDatabaseHandlerMap::changeCrossFaderHotSink(const am_crossfaderID_
return (E_OK);
}
-am_Error_e CAmDatabaseHandlerMap::getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree)
+bool CAmDatabaseHandlerMap::isComponentConnected(const am_Gateway_s & gateway) const
{
- am_domainID_t rootID = tree.returnRootDomainID();
- CAmRoutingTreeItem *parent = tree.returnRootItem();
- size_t i = 0;
-
- do
- {
- if (i != 0)
- {
- parent = flatTree.at(i - 1);
- rootID = parent->returnDomainID();
- }
- std::for_each(mMappedData.mGatewayMap.begin(),mMappedData.mGatewayMap.end(), [&](const std::pair<am_gatewayID_t, am_Gateway_s>& refGateway) {
- if( rootID==refGateway.second.domainSinkID )
- {
- if(!onlyfree || std::find_if(mMappedData.mConnectionMap.begin(),
- mMappedData.mConnectionMap.end(),
- [&](const std::pair<am_connectionID_t, am_Connection_Database_s>& refConnection)
- {
- return (refConnection.second.sinkID == refGateway.second.sinkID ||
- refConnection.second.sourceID ==refGateway.second.sourceID);
- })==mMappedData.mConnectionMap.end() )
- {
- // additional check to avoid cyclic routes
- const am_domainID_t domainSourceID = refGateway.second.domainSourceID;
- bool sourceDomainAlreadyHandledAsSink = false;
- for (std::vector<CAmRoutingTreeItem*>::const_iterator iFT = flatTree.begin(); iFT != flatTree.end(); ++iFT)
- {
- if (domainSourceID == (*iFT)->returnParent()->returnDomainID())
- {
- sourceDomainAlreadyHandledAsSink = true;
- break;
- }
- }
-
- if (!sourceDomainAlreadyHandledAsSink)
- {
- // logInfo("DatabaseHandler::getRoutingTree ", rootID, ", ", domainSourceID, ", ", sqlite3_column_int(query, 1));
- flatTree.push_back(tree.insertItem(domainSourceID, refGateway.second.gatewayID, parent));
- }
- }
- }
- });
- i++;
- } while (flatTree.size() > (i - 1));
+ bool ret = isConnected(gateway);
+ return ret;
+}
- return (E_OK);
+bool CAmDatabaseHandlerMap::isComponentConnected(const am_Converter_s & converter) const
+{
+ bool ret = isConnected(converter);
+ return ret;
}
am_Error_e am::CAmDatabaseHandlerMap::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
@@ -2731,6 +2824,37 @@ am_Error_e CAmDatabaseHandlerMap::changeGatewayDB(const am_gatewayID_t gatewayID
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerMap::changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)
+{
+ assert(converterID!=0);
+
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+
+ if (!listSourceConnectionFormats.empty())
+ {
+ mMappedData.mConverterMap.at(converterID).listSourceFormats = listSourceConnectionFormats;
+ }
+
+ if (!listSinkConnectionFormats.empty())
+ {
+ mMappedData.mConverterMap.at(converterID).listSinkFormats = listSinkConnectionFormats;
+ }
+
+ if (!convertionMatrix.empty())
+ {
+ mListConnectionFormat.clear();
+ mListConnectionFormat.insert(std::make_pair(converterID, convertionMatrix));
+ }
+
+ logInfo("DatabaseHandler::changeConverterDB changed Gateway with ID", converterID);
+
+ //todo: check if observer needs to be adopted.
+ return (E_OK);
+}
+
bool changeNotificationConfiguration(std::vector<am_NotificationConfiguration_s> & listNotificationConfigurations, const am_NotificationConfiguration_s & notificationConfiguration)
{
bool changed = false;
@@ -2782,4 +2906,46 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceNotificationConfigurationDB(const
return (E_NON_EXISTENT);
}
+am_Error_e CAmDatabaseHandlerMap::enumerateSources(std::function<void(const am_Source_s & element)> cb) const
+{
+ for(auto it = mMappedData.mSourceMap.begin(); it!=mMappedData.mSourceMap.end(); it++)
+ {
+ const am_Source_Database_s *pObject = &it->second;
+ if( 0==pObject->reserved )
+ cb(*pObject);
+ }
+ return E_OK;
+}
+
+am_Error_e CAmDatabaseHandlerMap::enumerateSinks(std::function<void(const am_Sink_s & element)> cb) const
+{
+ for(auto it = mMappedData.mSinkMap.begin(); it!=mMappedData.mSinkMap.end(); it++)
+ {
+ const am_Sink_Database_s *pObject = &it->second;
+ if( 0==pObject->reserved )
+ cb(*pObject);
+ }
+ return E_OK;
+}
+
+am_Error_e CAmDatabaseHandlerMap::enumerateGateways(std::function<void(const am_Gateway_s & element)> cb) const
+{
+ for(auto it = mMappedData.mGatewayMap.begin(); it!=mMappedData.mGatewayMap.end(); it++)
+ {
+ const am_Gateway_s *pObject = &it->second;
+ cb(*pObject);
+ }
+ return E_OK;
+}
+
+am_Error_e CAmDatabaseHandlerMap::enumerateConverters(std::function<void(const am_Converter_s & element)> cb) const
+{
+ for(auto it = mMappedData.mConverterMap.begin(); it!=mMappedData.mConverterMap.end(); it++)
+ {
+ const am_Converter_s *pObject = &it->second;
+ cb(*pObject);
+ }
+ return E_OK;
+}
+
}
diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp
index 1390fc4..cb95ec6 100644
--- a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp
+++ b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp
@@ -104,6 +104,7 @@ namespace am
#define SOURCE_TABLE "Sources" //!< source table
#define SINK_TABLE "Sinks" //!< sink table
#define GATEWAY_TABLE "Gateways" //!< gateway table
+#define CONVERTER_TABLE "Converters" //!< converter table
#define CROSSFADER_TABLE "Crossfaders" //!< crossfader table
#define CONNECTION_TABLE "Connections" //!< connection table
#define MAINCONNECTION_TABLE "MainConnections" //!< main connection table
@@ -118,6 +119,7 @@ const std::string databaseTables[] =
" Sources (sourceID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domainID INTEGER, name VARCHAR(50), sourceClassID INTEGER, sourceState INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, interruptState INTEGER, reserved BOOL);", //
" Sinks (sinkID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), domainID INTEGER, sinkClassID INTEGER, volume INTEGER, visible BOOL, availability INTEGER, availabilityReason INTEGER, muteState INTEGER, mainVolume INTEGER, reserved BOOL);", //
" Gateways (gatewayID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainSinkID INTEGER, domainSourceID INTEGER, controlDomainID INTEGER);", //
+ " Converters (converterID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID INTEGER, sourceID INTEGER, domainID INTEGER);", //
" Crossfaders (crossfaderID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), sinkID_A INTEGER, sinkID_B INTEGER, sourceID INTEGER, hotSink INTEGER);", //
" Connections (connectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, delay INTEGER, connectionFormat INTEGER, reserved BOOL);", //
" MainConnections (mainConnectionID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, sourceID INTEGER, sinkID INTEGER, connectionState INTEGER, delay INTEGER);", //
@@ -140,6 +142,7 @@ CAmDatabaseHandlerSQLite::CAmDatabaseHandlerSQLite():mpDatabaseObserver(NULL), /
mFirstStaticSink(true), //
mFirstStaticSource(true), //
mFirstStaticGateway(true), //
+ mFirstStaticConverter(true),
mFirstStaticSinkClass(true), //
mFirstStaticSourceClass(true), //
mFirstStaticCrossfader(true), //
@@ -154,6 +157,7 @@ CAmDatabaseHandlerSQLite::CAmDatabaseHandlerSQLite(std::string databasePath):mpD
mFirstStaticSink(true), //
mFirstStaticSource(true), //
mFirstStaticGateway(true), //
+ mFirstStaticConverter(true),
mFirstStaticSinkClass(true), //
mFirstStaticSourceClass(true), //
mFirstStaticCrossfader(true), //
@@ -582,7 +586,7 @@ am_Error_e CAmDatabaseHandlerSQLite::enterCrossfaderDB(const am_Crossfader_s & c
else
{
//check if the ID already exists
- if (existcrossFader(crossfaderData.crossfaderID))
+ if (existCrossFader(crossfaderData.crossfaderID))
return (E_ALREADY_EXISTS);
command = "INSERT INTO " + std::string(CROSSFADER_TABLE) + "(name, sinkID_A, sinkID_B, sourceID, hotSink, crossfaderID) VALUES (?,?,?,?,?,?)";
}
@@ -760,6 +764,119 @@ am_Error_e CAmDatabaseHandlerSQLite::enterGatewayDB(const am_Gateway_s & gateway
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerSQLite::enterConverterDB(const am_Converter_s & converterData, am_converterID_t & converterID)
+{
+ assert(converterData.converterID<DYNAMIC_ID_BOUNDARY);
+ assert(converterData.sinkID!=0);
+ assert(converterData.sourceID!=0);
+ assert(converterData.domainID!=0);
+ assert(!converterData.name.empty());
+ assert(!converterData.convertionMatrix.empty());
+ assert(!converterData.listSinkFormats.empty());
+ assert(!converterData.listSourceFormats.empty());
+
+ //might be that the sinks and sources are not there during registration time
+ //assert(existSink(gatewayData.sinkID));
+ //assert(existSource(gatewayData.sourceID));
+
+ sqlite3_stmt* query = NULL;
+ int eCode = 0;
+ std::string command;
+
+ //if gatewayData is zero and the first Static Sink was already entered, the ID is created
+ if (converterData.converterID == 0 && !mFirstStaticConverter)
+ {
+ command = "INSERT INTO " + std::string(CONVERTER_TABLE) + "(name, sinkID, sourceID, domainID) VALUES (?,?,?,?)";
+ }
+ else
+ {
+ //check if the ID already exists
+ if (existConverter(converterData.converterID))
+ return (E_ALREADY_EXISTS);
+ command = "INSERT INTO " + std::string(CONVERTER_TABLE) + "(name, sinkID, sourceID, domainID, converterID) VALUES (?,?,?,?,?)";
+ }
+
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+ MY_SQLITE_BIND_TEXT(query, 1, converterData.name.c_str(), converterData.name.size(), SQLITE_STATIC)
+ MY_SQLITE_BIND_INT(query, 2, converterData.sinkID)
+ MY_SQLITE_BIND_INT(query, 3, converterData.sourceID)
+ MY_SQLITE_BIND_INT(query, 4, converterData.domainID)
+
+ //if the ID is not created, we add it to the query
+ if (converterData.converterID != 0)
+ {
+ MY_SQLITE_BIND_INT(query, 5, converterData.converterID)
+ }
+
+ //if the first static sink is entered, we need to set it onto the boundary
+ else if (mFirstStaticConverter)
+ {
+ MY_SQLITE_BIND_INT(query, 5, DYNAMIC_ID_BOUNDARY)
+ mFirstStaticConverter = false;
+ }
+
+ if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ converterID = sqlite3_last_insert_rowid(mpDatabase);
+
+ //now the convertion matrix todo: change the map implementation sometimes to blob in sqlite
+ mListConnectionFormat.insert(std::make_pair(converterID, converterData.convertionMatrix));
+
+ command = "CREATE TABLE ConverterSourceFormat" + i2s(converterID) + std::string("(soundFormat INTEGER)");
+ if (!this->sqQuery(command))
+ return (E_DATABASE_ERROR);
+ command = "CREATE TABLE ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat INTEGER)");
+ if (!this->sqQuery(command))
+ return (E_DATABASE_ERROR);
+
+ //fill ConnectionFormats
+ command = "INSERT INTO ConverterSourceFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)");
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+ std::vector<am_CustomConnectionFormat_t>::const_iterator connectionFormatIterator = converterData.listSourceFormats.begin();
+ for (; connectionFormatIterator < converterData.listSourceFormats.end(); ++connectionFormatIterator)
+ {
+ MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
+ if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+ MY_SQLITE_RESET(query)
+ }
+ MY_SQLITE_FINALIZE(query)
+
+ command = "INSERT INTO ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)");
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+ connectionFormatIterator = converterData.listSinkFormats.begin();
+ for (; connectionFormatIterator < converterData.listSinkFormats.end(); ++connectionFormatIterator)
+ {
+ MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
+ if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+ MY_SQLITE_RESET(query)
+ }
+ MY_SQLITE_FINALIZE(query)
+
+ logInfo("DatabaseHandler::enterConverterDB entered new gateway with name", converterData.name, "sourceID:", converterData.sourceID, "sinkID:", converterData.sinkID, "assigned ID:", converterID);
+ am_Converter_s converter = converterData;
+ converter.converterID = converterID;
+ if (mpDatabaseObserver)
+ mpDatabaseObserver->newConverter(converter);
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
{
assert(sourceData.sourceID<DYNAMIC_ID_BOUNDARY);
@@ -1438,11 +1555,28 @@ am_Error_e CAmDatabaseHandlerSQLite::removeGatewayDB(const am_gatewayID_t gatewa
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerSQLite::removeConverterDB(const am_converterID_t converterID)
+{
+ assert(converterID!=0);
+
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+ std::string command = "DELETE from " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID);
+ if (!sqQuery(command))
+ return (E_DATABASE_ERROR);
+ logInfo("DatabaseHandler::removeConverterDB removed:", converterID);
+ if (mpDatabaseObserver)
+ mpDatabaseObserver->removeConverter(converterID);
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
{
assert(crossfaderID!=0);
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -2061,10 +2195,79 @@ am_Error_e CAmDatabaseHandlerSQLite::getGatewayInfoDB(const am_gatewayID_t gatew
}
+am_Error_e CAmDatabaseHandlerSQLite::getConverterInfoDB(const am_converterID_t converterID, am_Converter_s& converterData) const
+{
+ assert(converterID!=0);
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+ sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
+ int eCode = 0;
+ am_CustomConnectionFormat_t tempConnectionFormat;
+ std::string command = "SELECT name, sinkID, sourceID, domainID, converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ converterData.name = std::string((const char*) sqlite3_column_text(query, 0));
+ converterData.sinkID = sqlite3_column_int(query, 1);
+ converterData.sourceID = sqlite3_column_int(query, 2);
+ converterData.domainID = sqlite3_column_int(query, 3);
+ converterData.converterID = sqlite3_column_int(query, 4);
+
+ //convertionMatrix:
+ ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
+ iter = mListConnectionFormat.find(converterData.converterID);
+ if (iter == mListConnectionFormat.end())
+ {
+ logError("DatabaseHandler::getConverterInfoDB database error with convertionFormat");
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+ converterData.convertionMatrix = iter->second;
+
+ //read out the connectionFormats
+ std::string commandConnectionFormat = "SELECT soundFormat FROM ConverterSourceFormat" + i2s(converterData.converterID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0);
+ converterData.listSourceFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSourceConnectionFormat)
+
+ //read out sound properties
+ commandConnectionFormat = "SELECT soundFormat FROM ConverterSinkFormat" + i2s(converterData.converterID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0);
+ converterData.listSinkFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSinkConnectionFormat)
+
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getConverterInfoDB SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ return (E_OK);
+
+}
+
am_Error_e CAmDatabaseHandlerSQLite::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
{
assert(crossfaderID!=0);
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -2226,6 +2429,39 @@ am_Error_e CAmDatabaseHandlerSQLite::getListGatewaysOfDomain(const am_domainID_t
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerSQLite::getListConvertersOfDomain(const am_domainID_t domainID, std::vector<am_converterID_t>& listConvertersID) const
+{
+ assert(domainID!=0);
+ listConvertersID.clear();
+ if (!existDomain(domainID))
+ {
+ return (E_NON_EXISTENT);
+ }
+ sqlite3_stmt* query = NULL;
+ int eCode = 0;
+ am_gatewayID_t temp;
+
+ std::string command = "SELECT converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE domainID=" + i2s(domainID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ temp = sqlite3_column_int(query, 0);
+ listConvertersID.push_back(temp);
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getListConvertersOfDomain SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
{
listMainConnections.clear();
@@ -2332,217 +2568,13 @@ am_Error_e CAmDatabaseHandlerSQLite::getListConnections(std::vector<am_Connectio
am_Error_e CAmDatabaseHandlerSQLite::getListSinks(std::vector<am_Sink_s> & listSinks) const
{
listSinks.clear();
- sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qNotificationConfiguration= NULL, *qMAinSoundProperty = NULL, *qMainNotificationConfiguration= NULL;
- int eCode = 0;
- am_Sink_s temp;
- am_CustomConnectionFormat_t tempConnectionFormat;
- am_SoundProperty_s tempSoundProperty;
- am_MainSoundProperty_s tempMainSoundProperty;
- am_NotificationConfiguration_s tempNotificationConfiguration;
- am_NotificationConfiguration_s tempMainNotificationConfiguration;
- std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
- MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
-
- while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
- {
- temp.name = std::string((const char*) sqlite3_column_text(query, 0));
- temp.domainID = sqlite3_column_int(query, 1);
- temp.sinkClassID = sqlite3_column_int(query, 2);
- temp.volume = sqlite3_column_int(query, 3);
- temp.visible = sqlite3_column_int(query, 4);
- temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 5);
- temp.available.availabilityReason = (am_CustomAvailabilityReason_t) sqlite3_column_int(query, 6);
- temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
- temp.mainVolume = sqlite3_column_int(query, 8);
- temp.sinkID = sqlite3_column_int(query, 9);
-
- //read out the connectionFormats
- std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
- while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
- {
- tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0);
- temp.listConnectionFormats.push_back(tempConnectionFormat);
- }
-
- MY_SQLITE_FINALIZE(qConnectionFormat)
-
- //read out sound properties
- std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
- while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
- {
- tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0);
- tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
- temp.listSoundProperties.push_back(tempSoundProperty);
- }
-
- MY_SQLITE_FINALIZE(qSoundProperty)
-
- //read out notifications
- std::string commandNotificationConfiguration = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(temp.sinkID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandNotificationConfiguration.c_str(), -1, &qNotificationConfiguration, NULL)
- while ((eCode = sqlite3_step(qNotificationConfiguration)) == SQLITE_ROW)
- {
- tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t> (sqlite3_column_int(qNotificationConfiguration, 0));
- tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e> (sqlite3_column_int(qNotificationConfiguration, 1));
- tempNotificationConfiguration.parameter = static_cast<int16_t> (sqlite3_column_int(qNotificationConfiguration, 2));
- temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
- }
-
- MY_SQLITE_FINALIZE(qNotificationConfiguration)
-
- //read out MainSoundProperties if sink is visible
- if(temp.visible)
- {
- std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
- while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
- {
- tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0);
- tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
- temp.listMainSoundProperties.push_back(tempMainSoundProperty);
- }
-
- MY_SQLITE_FINALIZE(qMAinSoundProperty)
-
- //and mainNotificationConfigurations
- std::string commandMainNotificationConfiguration = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(temp.sinkID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandMainNotificationConfiguration.c_str(), -1, &qMainNotificationConfiguration, NULL)
- while ((eCode = sqlite3_step(qMainNotificationConfiguration)) == SQLITE_ROW)
- {
- tempMainNotificationConfiguration.type = static_cast <am_CustomNotificationType_t> (sqlite3_column_int(qMainNotificationConfiguration, 0));
- tempMainNotificationConfiguration.status = static_cast <am_NotificationStatus_e> (sqlite3_column_int(qMainNotificationConfiguration, 1));
- tempMainNotificationConfiguration.parameter = static_cast <uint16_t>(sqlite3_column_int(qMainNotificationConfiguration, 2));
- temp.listMainNotificationConfigurations.push_back(tempMainNotificationConfiguration);
- }
-
- MY_SQLITE_FINALIZE(qMainNotificationConfiguration)
- }
-
- listSinks.push_back(temp);
- temp.listConnectionFormats.clear();
- temp.listMainSoundProperties.clear();
- temp.listSoundProperties.clear();
- }
-
- if (eCode != SQLITE_DONE)
- {
- logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
- MY_SQLITE_FINALIZE(query)
- return (E_DATABASE_ERROR);
- }
-
- MY_SQLITE_FINALIZE(query)
-
- return (E_OK);
+ return enumerateSinks([&](const am_Sink_s & sink){ listSinks.push_back(sink);});
}
am_Error_e CAmDatabaseHandlerSQLite::getListSources(std::vector<am_Source_s> & listSources) const
{
listSources.clear();
- sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qNotification(NULL), *qMainNotification(NULL);
- int eCode = 0;
- am_Source_s temp;
- am_CustomConnectionFormat_t tempConnectionFormat;
- am_SoundProperty_s tempSoundProperty;
- am_MainSoundProperty_s tempMainSoundProperty;
- am_NotificationConfiguration_s tempNotificationConfiguration;
- std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
- MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
-
- while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
- {
- temp.name = std::string((const char*) sqlite3_column_text(query, 0));
- temp.domainID = sqlite3_column_int(query, 1);
- temp.sourceClassID = sqlite3_column_int(query, 2);
- temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
- temp.volume = sqlite3_column_int(query, 4);
- temp.visible = sqlite3_column_int(query, 5);
- temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 6);
- temp.available.availabilityReason = (am_CustomAvailabilityReason_t) sqlite3_column_int(query, 7);
- temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
- temp.sourceID = sqlite3_column_int(query, 9);
-
- //read out the connectionFormats
- std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
- while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
- {
- tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0);
- temp.listConnectionFormats.push_back(tempConnectionFormat);
- }
-
- MY_SQLITE_FINALIZE(qConnectionFormat)
-
- //read out sound properties
- std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
- while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
- {
- tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0);
- tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
- temp.listSoundProperties.push_back(tempSoundProperty);
- }
-
- MY_SQLITE_FINALIZE(qSoundProperty)
-
- std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(temp.sourceID);
- MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL)
-
- while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW)
- {
- tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t>(sqlite3_column_int(qNotification, 0));
- tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qNotification, 1));
- tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qNotification, 2));
- temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
- }
- MY_SQLITE_FINALIZE(qNotification)
-
- //read out MainSoundProperties if source is visible
- if(temp.visible)
- {
- std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
- while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
- {
- tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0);
- tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
- temp.listMainSoundProperties.push_back(tempMainSoundProperty);
- }
-
- MY_SQLITE_FINALIZE(qMAinSoundProperty)
-
- std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(temp.sourceID);
- MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL)
-
- while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW)
- {
- tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t>(sqlite3_column_int(qMainNotification, 0));
- tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qMainNotification, 1));
- tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qMainNotification, 2));
- temp.listMainNotificationConfigurations.push_back(tempNotificationConfiguration);
- }
- MY_SQLITE_FINALIZE(qMainNotification)
- }
-
-
- listSources.push_back(temp);
- temp.listConnectionFormats.clear();
- temp.listMainSoundProperties.clear();
- temp.listSoundProperties.clear();
- }
-
- if (eCode != SQLITE_DONE)
- {
- logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
- MY_SQLITE_FINALIZE(query)
- return (E_DATABASE_ERROR);
- }
-
- MY_SQLITE_FINALIZE(query)
-
- return (E_OK);
+ return enumerateSources([&](const am_Source_s & source){ listSources.push_back(source);});
}
am_Error_e CAmDatabaseHandlerSQLite::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
@@ -2634,72 +2666,13 @@ am_Error_e CAmDatabaseHandlerSQLite::getListCrossfaders(std::vector<am_Crossfade
am_Error_e CAmDatabaseHandlerSQLite::getListGateways(std::vector<am_Gateway_s> & listGateways) const
{
listGateways.clear();
- sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
- int eCode = 0;
- am_Gateway_s temp;
- am_CustomConnectionFormat_t tempConnectionFormat;
-
- std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
- MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
-
- while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
- {
- temp.name = std::string((const char*) sqlite3_column_text(query, 0));
- temp.sinkID = sqlite3_column_int(query, 1);
- temp.sourceID = sqlite3_column_int(query, 2);
- temp.domainSinkID = sqlite3_column_int(query, 3);
- temp.domainSourceID = sqlite3_column_int(query, 4);
- temp.controlDomainID = sqlite3_column_int(query, 5);
- temp.gatewayID = sqlite3_column_int(query, 6);
-
- //convertionMatrix:
- ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
- iter = mListConnectionFormat.find(temp.gatewayID);
- if (iter == mListConnectionFormat.end())
- {
- logError("DatabaseHandler::getListGateways database error with convertionFormat");
-
- return (E_DATABASE_ERROR);
- }
- temp.convertionMatrix = iter->second;
-
- //read out the connectionFormats
- std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
- while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
- {
- tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0);
- temp.listSourceFormats.push_back(tempConnectionFormat);
- }
-
- MY_SQLITE_FINALIZE(qSourceConnectionFormat)
-
- //read out sound properties
- commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
- MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
- while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
- {
- tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0);
- temp.listSinkFormats.push_back(tempConnectionFormat);
- }
-
- MY_SQLITE_FINALIZE(qSinkConnectionFormat)
-
- listGateways.push_back(temp);
- temp.listSinkFormats.clear();
- temp.listSourceFormats.clear();
- }
-
- if (eCode != SQLITE_DONE)
- {
- logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
- MY_SQLITE_FINALIZE(query)
- return (E_DATABASE_ERROR);
- }
-
- MY_SQLITE_FINALIZE(query)
+ return enumerateGateways([&](const am_Gateway_s & gateway){ listGateways.push_back(gateway);});
+}
- return (E_OK);
+am_Error_e CAmDatabaseHandlerSQLite::getListConverters(std::vector<am_Converter_s> & listConverters) const
+{
+ listConverters.clear();
+ return enumerateConverters([&](const am_Converter_s & converter){ listConverters.push_back(converter);});
}
am_Error_e CAmDatabaseHandlerSQLite::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
@@ -3001,6 +2974,21 @@ am_Error_e am::CAmDatabaseHandlerSQLite::getListGatewayConnectionFormats(const a
return (E_OK);
}
+am_Error_e am::CAmDatabaseHandlerSQLite::getListConverterConnectionFormats(const am_converterID_t converterID, std::vector<bool> & listConnectionFormat) const
+{
+ ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
+ iter = mListConnectionFormat.find(converterID);
+ if (iter == mListConnectionFormat.end())
+ {
+ logError("DatabaseHandler::getListConverterConnectionFormats database error with convertionFormat");
+
+ return (E_DATABASE_ERROR);
+ }
+ listConnectionFormat = iter->second;
+
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
{
assert(mainConnectionID!=0);
@@ -3573,6 +3561,26 @@ bool CAmDatabaseHandlerSQLite::existGateway(const am_gatewayID_t gatewayID) cons
return (returnVal);
}
+bool CAmDatabaseHandlerSQLite::existConverter(const am_converterID_t converterID) const
+{
+ sqlite3_stmt* query = NULL;
+ std::string command = "SELECT converterID FROM " + std::string(CONVERTER_TABLE) + " WHERE converterID=" + i2s(converterID);
+ int eCode = 0;
+ bool returnVal = true;
+ MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
+ returnVal = false;
+ else if (eCode != SQLITE_ROW)
+ {
+ returnVal = false;
+ logError("DatabaseHandler::existConverter database error!:", eCode);
+ }
+
+ MY_SQLITE_FINALIZE_BOOL(query)
+ return (returnVal);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t & domainID) const
{
assert(sourceID!=0);
@@ -3928,7 +3936,7 @@ bool CAmDatabaseHandlerSQLite::existConnectionID(const am_connectionID_t connect
* @param crossfaderID the ID of the crossfader to be checked
* @return true if exists
*/
-bool CAmDatabaseHandlerSQLite::existcrossFader(const am_crossfaderID_t crossfaderID) const
+bool CAmDatabaseHandlerSQLite::existCrossFader(const am_crossfaderID_t crossfaderID) const
{
sqlite3_stmt* query = NULL;
std::string command = "SELECT crossfaderID FROM " + std::string(CROSSFADER_TABLE) + " WHERE crossfaderID=?";
@@ -4367,7 +4375,7 @@ am_Error_e CAmDatabaseHandlerSQLite::changeCrossFaderHotSink(const am_crossfader
int eCode = 0;
std::string command;
- if (!existcrossFader(crossfaderID))
+ if (!existCrossFader(crossfaderID))
{
return (E_NON_EXISTENT);
}
@@ -4385,63 +4393,53 @@ am_Error_e CAmDatabaseHandlerSQLite::changeCrossFaderHotSink(const am_crossfader
return (E_OK);
}
-am_Error_e CAmDatabaseHandlerSQLite::getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree)
+bool CAmDatabaseHandlerSQLite::isComponentConnected(const am_Gateway_s & gateway) const
{
- sqlite3_stmt* query = NULL;
- int eCode = 0;
- size_t i = 0;
- std::string command;
- am_domainID_t rootID = tree.returnRootDomainID();
- CAmRoutingTreeItem *parent = tree.returnRootItem();
-
- if (onlyfree)
- {
- command = "SELECT g.domainSourceID,g.gatewayID FROM " + std::string(GATEWAY_TABLE) + " g WHERE domainSinkID=? AND NOT EXISTS (SELECT NULL FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = g.sinkID OR c.sourceID = g.sourceID )";
- }
- else
- {
- command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=?";
- }
-
- do
- {
- if (i != 0)
- {
- parent = flatTree.at(i - 1);
- rootID = parent->returnDomainID();
- }
- MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
- MY_SQLITE_BIND_INT(query, 1, rootID)
-
- while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
- {
- // additional check to avoid cyclic routes
- const am_domainID_t domainSourceID = sqlite3_column_int(query, 0);
- bool sourceDomainAlreadyHandledAsSink = false;
- for (std::vector<CAmRoutingTreeItem*>::const_iterator iFT = flatTree.begin(); iFT != flatTree.end(); ++iFT)
- {
- if (domainSourceID == (*iFT)->returnParent()->returnDomainID()) sourceDomainAlreadyHandledAsSink = true;
- }
-
- if (!sourceDomainAlreadyHandledAsSink)
- {
- // logInfo("DatabaseHandler::getRoutingTree ", rootID, ", ", domainSourceID, ", ", sqlite3_column_int(query, 1));
- flatTree.push_back(tree.insertItem(domainSourceID, sqlite3_column_int(query, 1), parent));
- }
- }
-
- if (eCode != SQLITE_DONE)
- {
- logError("DatabaseHandler::getRoutingTree SQLITE error code:", eCode);
- MY_SQLITE_FINALIZE(query)
- return (E_DATABASE_ERROR);
- }
-
- MY_SQLITE_FINALIZE(query)
- i++;
- } while (flatTree.size() > (i - 1));
+ sqlite3_stmt* query = NULL;
+ int eCode = 0;
+ std::string command;
+ bool returnVal = true;
+ command = "SELECT 1 FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = ? OR c.sourceID = ?";
+
+ MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
+ MY_SQLITE_BIND_INT(query, 1, gateway.sinkID)
+ MY_SQLITE_BIND_INT(query, 2, gateway.sourceID)
+ if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
+ {
+ returnVal = false;
+ }
+ else if (eCode != SQLITE_ROW)
+ {
+ returnVal = false;
+ logError("DatabaseHandler::isComponentConnected database error!:", eCode);
+ }
+ MY_SQLITE_FINALIZE(query)
+ return returnVal;
+}
- return (E_OK);
+bool CAmDatabaseHandlerSQLite::isComponentConnected(const am_Converter_s & converter) const
+{
+ sqlite3_stmt* query = NULL;
+ int eCode = 0;
+ std::string command;
+ bool returnVal = true;
+ command = "SELECT 1 FROM " + std::string(CONNECTION_TABLE) + " c WHERE c.sinkID = ? OR c.sourceID = ?";
+
+ MY_SQLITE_PREPARE_V2_BOOL(mpDatabase, command.c_str(), -1, &query, NULL)
+ MY_SQLITE_BIND_INT(query, 1, converter.sinkID)
+ MY_SQLITE_BIND_INT(query, 2, converter.sourceID)
+ if ((eCode = sqlite3_step(query)) == SQLITE_DONE)
+ {
+ returnVal = false;
+ }
+ else if (eCode != SQLITE_ROW)
+ {
+ returnVal = false;
+ logError("DatabaseHandler::isComponentConnected database error!:", eCode);
+ }
+ MY_SQLITE_FINALIZE(query)
+
+ return returnVal;
}
am_Error_e am::CAmDatabaseHandlerSQLite::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID)
@@ -4979,6 +4977,80 @@ am_Error_e CAmDatabaseHandlerSQLite::changeGatewayDB(const am_gatewayID_t gatewa
return (E_OK);
}
+am_Error_e CAmDatabaseHandlerSQLite::changeConverterDB(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceConnectionFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix)
+{
+ assert(converterID!=0);
+
+ sqlite3_stmt* query = NULL;
+ int eCode = 0;
+ std::string command;
+
+ if (!existConverter(converterID))
+ {
+ return (E_NON_EXISTENT);
+ }
+
+ if (!listSourceConnectionFormats.empty())
+ {
+ //clear Database
+ command = "DELETE from ConverterSourceFormat" + i2s(converterID);
+ if (!sqQuery(command))
+ return (E_DATABASE_ERROR);
+
+ //fill ConnectionFormats
+ command = "INSERT INTO ConverterSourceFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)");
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+ std::vector<am_CustomConnectionFormat_t>::const_iterator connectionFormatIterator = listSourceConnectionFormats.begin();
+ for (; connectionFormatIterator < listSourceConnectionFormats.end(); ++connectionFormatIterator)
+ {
+ MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
+ if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+ MY_SQLITE_RESET(query)
+ }
+ MY_SQLITE_FINALIZE(query)
+ }
+
+ if (!listSinkConnectionFormats.empty())
+ {
+ //clear Database
+ command = "DELETE from ConverterSinkFormat" + i2s(converterID);
+ if (!sqQuery(command))
+ return (E_DATABASE_ERROR);
+
+ command = "INSERT INTO ConverterSinkFormat" + i2s(converterID) + std::string("(soundFormat) VALUES (?)");
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+ std::vector<am_CustomConnectionFormat_t>::const_iterator connectionFormatIterator = listSinkConnectionFormats.begin();
+ for (; connectionFormatIterator < listSinkConnectionFormats.end(); ++connectionFormatIterator)
+ {
+ MY_SQLITE_BIND_INT(query, 1, *connectionFormatIterator)
+ if ((eCode = sqlite3_step(query)) != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::enterConverterDB SQLITE Step error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+ MY_SQLITE_RESET(query)
+ }
+ MY_SQLITE_FINALIZE(query)
+ }
+
+ if (!convertionMatrix.empty())
+ {
+ mListConnectionFormat.clear();
+ mListConnectionFormat.insert(std::make_pair(converterID, convertionMatrix));
+ }
+
+ logInfo("DatabaseHandler::changeConverterDB changed Gateway with ID", converterID);
+
+ //todo: check if observer needs to be adopted.
+ return (E_OK);
+}
+
am_Error_e CAmDatabaseHandlerSQLite::changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s notificationConfiguration)
{
assert(sinkID!=0);
@@ -5048,4 +5120,355 @@ void CAmDatabaseHandlerSQLite::createTables()
}
}
+am_Error_e CAmDatabaseHandlerSQLite::enumerateSources(std::function<void(const am_Source_s & element)> cb) const
+{
+ sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qMAinSoundProperty = NULL, *qNotification(NULL), *qMainNotification(NULL);
+ int eCode = 0;
+ am_Source_s temp;
+ am_CustomConnectionFormat_t tempConnectionFormat;
+ am_SoundProperty_s tempSoundProperty;
+ am_MainSoundProperty_s tempMainSoundProperty;
+ am_NotificationConfiguration_s tempNotificationConfiguration;
+ std::string command = "SELECT name, domainID, sourceClassID, sourceState, volume, visible, availability, availabilityReason, interruptState, sourceID FROM " + std::string(SOURCE_TABLE) + " WHERE reserved=0";
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ temp.name = std::string((const char*) sqlite3_column_text(query, 0));
+ temp.domainID = sqlite3_column_int(query, 1);
+ temp.sourceClassID = sqlite3_column_int(query, 2);
+ temp.sourceState = (am_SourceState_e) sqlite3_column_int(query, 3);
+ temp.volume = sqlite3_column_int(query, 4);
+ temp.visible = sqlite3_column_int(query, 5);
+ temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 6);
+ temp.available.availabilityReason = (am_CustomAvailabilityReason_t) sqlite3_column_int(query, 7);
+ temp.interruptState = (am_InterruptState_e) sqlite3_column_int(query, 8);
+ temp.sourceID = sqlite3_column_int(query, 9);
+
+ //read out the connectionFormats
+ std::string commandConnectionFormat = "SELECT soundFormat FROM SourceConnectionFormat" + i2s(temp.sourceID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0);
+ temp.listConnectionFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qConnectionFormat)
+
+ //read out sound properties
+ std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(temp.sourceID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
+ while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
+ {
+ tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0);
+ tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
+ temp.listSoundProperties.push_back(tempSoundProperty);
+ }
+
+ MY_SQLITE_FINALIZE(qSoundProperty)
+
+ std::string notificationCommand = "SELECT type, status, parameter FROM SourceNotificationConfiguration" + i2s(temp.sourceID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, notificationCommand.c_str(), -1, &qNotification, NULL)
+
+ while ((eCode = sqlite3_step(qNotification)) == SQLITE_ROW)
+ {
+ tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t>(sqlite3_column_int(qNotification, 0));
+ tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qNotification, 1));
+ tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qNotification, 2));
+ temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
+ }
+ MY_SQLITE_FINALIZE(qNotification)
+
+ //read out MainSoundProperties if source is visible
+ if(temp.visible)
+ {
+ std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SourceMainSoundProperty" + i2s(temp.sourceID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
+ while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
+ {
+ tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0);
+ tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
+ temp.listMainSoundProperties.push_back(tempMainSoundProperty);
+ }
+
+ MY_SQLITE_FINALIZE(qMAinSoundProperty)
+
+ std::string mainNotificationCommand = "SELECT type, status, parameter FROM SourceMainNotificationConfiguration" + i2s(temp.sourceID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, mainNotificationCommand.c_str(), -1, &qMainNotification, NULL)
+
+ while ((eCode = sqlite3_step(qMainNotification)) == SQLITE_ROW)
+ {
+ tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t>(sqlite3_column_int(qMainNotification, 0));
+ tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e>(sqlite3_column_int(qMainNotification, 1));
+ tempNotificationConfiguration.parameter= static_cast<int16_t>(sqlite3_column_int(qMainNotification, 2));
+ temp.listMainNotificationConfigurations.push_back(tempNotificationConfiguration);
+ }
+ MY_SQLITE_FINALIZE(qMainNotification)
+ }
+
+
+ cb(temp);
+ temp.listConnectionFormats.clear();
+ temp.listMainSoundProperties.clear();
+ temp.listSoundProperties.clear();
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getListSources SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ return (E_OK);
+}
+
+am_Error_e CAmDatabaseHandlerSQLite::enumerateSinks(std::function<void(const am_Sink_s & element)> cb) const
+{
+ sqlite3_stmt* query = NULL, *qConnectionFormat = NULL, *qSoundProperty = NULL, *qNotificationConfiguration= NULL, *qMAinSoundProperty = NULL, *qMainNotificationConfiguration= NULL;
+ int eCode = 0;
+ am_Sink_s temp;
+ am_CustomConnectionFormat_t tempConnectionFormat;
+ am_SoundProperty_s tempSoundProperty;
+ am_MainSoundProperty_s tempMainSoundProperty;
+ am_NotificationConfiguration_s tempNotificationConfiguration;
+ am_NotificationConfiguration_s tempMainNotificationConfiguration;
+ std::string command = "SELECT name, domainID, sinkClassID, volume, visible, availability, availabilityReason, muteState, mainVolume, sinkID FROM " + std::string(SINK_TABLE) + " WHERE reserved=0";
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ temp.name = std::string((const char*) sqlite3_column_text(query, 0));
+ temp.domainID = sqlite3_column_int(query, 1);
+ temp.sinkClassID = sqlite3_column_int(query, 2);
+ temp.volume = sqlite3_column_int(query, 3);
+ temp.visible = sqlite3_column_int(query, 4);
+ temp.available.availability = (am_Availability_e) sqlite3_column_int(query, 5);
+ temp.available.availabilityReason = (am_CustomAvailabilityReason_t) sqlite3_column_int(query, 6);
+ temp.muteState = (am_MuteState_e) sqlite3_column_int(query, 7);
+ temp.mainVolume = sqlite3_column_int(query, 8);
+ temp.sinkID = sqlite3_column_int(query, 9);
+
+ //read out the connectionFormats
+ std::string commandConnectionFormat = "SELECT soundFormat FROM SinkConnectionFormat" + i2s(temp.sinkID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qConnectionFormat, 0);
+ temp.listConnectionFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qConnectionFormat)
+
+ //read out sound properties
+ std::string commandSoundProperty = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(temp.sinkID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandSoundProperty.c_str(), -1, &qSoundProperty, NULL)
+ while ((eCode = sqlite3_step(qSoundProperty)) == SQLITE_ROW)
+ {
+ tempSoundProperty.type = (am_CustomSoundPropertyType_t) sqlite3_column_int(qSoundProperty, 0);
+ tempSoundProperty.value = sqlite3_column_int(qSoundProperty, 1);
+ temp.listSoundProperties.push_back(tempSoundProperty);
+ }
+
+ MY_SQLITE_FINALIZE(qSoundProperty)
+
+ //read out notifications
+ std::string commandNotificationConfiguration = "SELECT type, status, parameter FROM SinkNotificationConfiguration" + i2s(temp.sinkID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandNotificationConfiguration.c_str(), -1, &qNotificationConfiguration, NULL)
+ while ((eCode = sqlite3_step(qNotificationConfiguration)) == SQLITE_ROW)
+ {
+ tempNotificationConfiguration.type = static_cast<am_CustomNotificationType_t> (sqlite3_column_int(qNotificationConfiguration, 0));
+ tempNotificationConfiguration.status = static_cast<am_NotificationStatus_e> (sqlite3_column_int(qNotificationConfiguration, 1));
+ tempNotificationConfiguration.parameter = static_cast<int16_t> (sqlite3_column_int(qNotificationConfiguration, 2));
+ temp.listNotificationConfigurations.push_back(tempNotificationConfiguration);
+ }
+
+ MY_SQLITE_FINALIZE(qNotificationConfiguration)
+
+ //read out MainSoundProperties if sink is visible
+ if(temp.visible)
+ {
+ std::string commandMainSoundProperty = "SELECT soundPropertyType, value FROM SinkMainSoundProperty" + i2s(temp.sinkID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandMainSoundProperty.c_str(), -1, &qMAinSoundProperty, NULL)
+ while ((eCode = sqlite3_step(qMAinSoundProperty)) == SQLITE_ROW)
+ {
+ tempMainSoundProperty.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(qMAinSoundProperty, 0);
+ tempMainSoundProperty.value = sqlite3_column_int(qMAinSoundProperty, 1);
+ temp.listMainSoundProperties.push_back(tempMainSoundProperty);
+ }
+
+ MY_SQLITE_FINALIZE(qMAinSoundProperty)
+
+ //and mainNotificationConfigurations
+ std::string commandMainNotificationConfiguration = "SELECT type, status, parameter FROM SinkMainNotificationConfiguration" + i2s(temp.sinkID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandMainNotificationConfiguration.c_str(), -1, &qMainNotificationConfiguration, NULL)
+ while ((eCode = sqlite3_step(qMainNotificationConfiguration)) == SQLITE_ROW)
+ {
+ tempMainNotificationConfiguration.type = static_cast <am_CustomNotificationType_t> (sqlite3_column_int(qMainNotificationConfiguration, 0));
+ tempMainNotificationConfiguration.status = static_cast <am_NotificationStatus_e> (sqlite3_column_int(qMainNotificationConfiguration, 1));
+ tempMainNotificationConfiguration.parameter = static_cast <uint16_t>(sqlite3_column_int(qMainNotificationConfiguration, 2));
+ temp.listMainNotificationConfigurations.push_back(tempMainNotificationConfiguration);
+ }
+
+ MY_SQLITE_FINALIZE(qMainNotificationConfiguration)
+ }
+
+ cb(temp);
+ temp.listConnectionFormats.clear();
+ temp.listMainSoundProperties.clear();
+ temp.listSoundProperties.clear();
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getListSinks SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+ return (E_OK);
+}
+
+am_Error_e CAmDatabaseHandlerSQLite::enumerateGateways(std::function<void(const am_Gateway_s & element)> cb) const
+{
+ sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
+ int eCode = 0;
+ am_Gateway_s temp;
+ am_CustomConnectionFormat_t tempConnectionFormat;
+
+ std::string command = "SELECT name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID FROM " + std::string(GATEWAY_TABLE);
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ temp.name = std::string((const char*) sqlite3_column_text(query, 0));
+ temp.sinkID = sqlite3_column_int(query, 1);
+ temp.sourceID = sqlite3_column_int(query, 2);
+ temp.domainSinkID = sqlite3_column_int(query, 3);
+ temp.domainSourceID = sqlite3_column_int(query, 4);
+ temp.controlDomainID = sqlite3_column_int(query, 5);
+ temp.gatewayID = sqlite3_column_int(query, 6);
+
+ //convertionMatrix:
+ ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
+ iter = mListConnectionFormat.find(temp.gatewayID);
+ if (iter == mListConnectionFormat.end())
+ {
+ logError("DatabaseHandler::getListGateways database error with convertionFormat");
+
+ return (E_DATABASE_ERROR);
+ }
+ temp.convertionMatrix = iter->second;
+
+ //read out the connectionFormats
+ std::string commandConnectionFormat = "SELECT soundFormat FROM GatewaySourceFormat" + i2s(temp.gatewayID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0);
+ temp.listSourceFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSourceConnectionFormat)
+
+ //read out sound properties
+ commandConnectionFormat = "SELECT soundFormat FROM GatewaySinkFormat" + i2s(temp.gatewayID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0);
+ temp.listSinkFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSinkConnectionFormat)
+
+ cb(temp);
+ temp.listSinkFormats.clear();
+ temp.listSourceFormats.clear();
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getListGateways SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ return (E_OK);
+}
+
+am_Error_e CAmDatabaseHandlerSQLite::enumerateConverters(std::function<void(const am_Converter_s & element)> cb) const
+{
+ sqlite3_stmt* query = NULL, *qSinkConnectionFormat = NULL, *qSourceConnectionFormat = NULL;
+ int eCode = 0;
+ am_Converter_s temp;
+ am_CustomConnectionFormat_t tempConnectionFormat;
+
+ std::string command = "SELECT name, sinkID, sourceID, domainID, converterID FROM " + std::string(CONVERTER_TABLE);
+ MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL)
+
+ while ((eCode = sqlite3_step(query)) == SQLITE_ROW)
+ {
+ temp.name = std::string((const char*) sqlite3_column_text(query, 0));
+ temp.sinkID = sqlite3_column_int(query, 1);
+ temp.sourceID = sqlite3_column_int(query, 2);
+ temp.domainID = sqlite3_column_int(query, 3);
+ temp.converterID = sqlite3_column_int(query, 4);
+
+ //convertionMatrix:
+ ListConnectionFormat::const_iterator iter = mListConnectionFormat.begin();
+ iter = mListConnectionFormat.find(temp.converterID);
+ if (iter == mListConnectionFormat.end())
+ {
+ logError("DatabaseHandler::getListConverters database error with convertionFormat");
+
+ return (E_DATABASE_ERROR);
+ }
+ temp.convertionMatrix = iter->second;
+
+ //read out the connectionFormats
+ std::string commandConnectionFormat = "SELECT soundFormat FROM ConverterSourceFormat" + i2s(temp.converterID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSourceConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSourceConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSourceConnectionFormat, 0);
+ temp.listSourceFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSourceConnectionFormat)
+
+ //read out sound properties
+ commandConnectionFormat = "SELECT soundFormat FROM ConverterSinkFormat" + i2s(temp.converterID);
+ MY_SQLITE_PREPARE_V2(mpDatabase, commandConnectionFormat.c_str(), -1, &qSinkConnectionFormat, NULL)
+ while ((eCode = sqlite3_step(qSinkConnectionFormat)) == SQLITE_ROW)
+ {
+ tempConnectionFormat = (am_CustomConnectionFormat_t) sqlite3_column_int(qSinkConnectionFormat, 0);
+ temp.listSinkFormats.push_back(tempConnectionFormat);
+ }
+
+ MY_SQLITE_FINALIZE(qSinkConnectionFormat)
+
+ cb(temp);
+ temp.listSinkFormats.clear();
+ temp.listSourceFormats.clear();
+ }
+
+ if (eCode != SQLITE_DONE)
+ {
+ logError("DatabaseHandler::getListConverters SQLITE error code:", eCode);
+ MY_SQLITE_FINALIZE(query)
+ return (E_DATABASE_ERROR);
+ }
+
+ MY_SQLITE_FINALIZE(query)
+
+ return (E_OK);
+}
+
}
diff --git a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp
index 506ec01..57a76cc 100644
--- a/AudioManagerDaemon/src/CAmDatabaseObserver.cpp
+++ b/AudioManagerDaemon/src/CAmDatabaseObserver.cpp
@@ -111,6 +111,12 @@ void CAmDatabaseObserver::newGateway(const am_Gateway_s& 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);
@@ -143,6 +149,12 @@ void CAmDatabaseObserver::removeGateway(const am_gatewayID_t 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);
diff --git a/AudioManagerDaemon/src/CAmRouter.cpp b/AudioManagerDaemon/src/CAmRouter.cpp
index d574e45..6ab0a07 100644
--- a/AudioManagerDaemon/src/CAmRouter.cpp
+++ b/AudioManagerDaemon/src/CAmRouter.cpp
@@ -13,30 +13,83 @@
*
*
* \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
+ * \author Aleksandar Donchev, Aleksander.Donchev@partner.bmw.de BMW 2013,2014
*
* \file CAmRouter.cpp
* For further information see http://www.genivi.org/.
*
*/
-#include "CAmRouter.h"
#include <cassert>
#include <algorithm>
#include <vector>
#include <iterator>
+#include "CAmRouter.h"
#include "IAmDatabaseHandler.h"
#include "CAmControlSender.h"
+#include "shared/CAmDltWrapper.h"
+
+
namespace am {
+
+void getSourceSinkPossibleConnectionFormats(std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator iteratorSource,
+ std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator iteratorSink,
+ std::vector<am_CustomConnectionFormat_t> & outConnectionFormats)
+{
+ CAmNode<am_RoutingNodeData_s> * nodeSink = *iteratorSink;
+ assert(nodeSink->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::SINK);
+
+ CAmNode<am_RoutingNodeData_s> * nodeSource = *iteratorSource;
+ assert(nodeSource->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::SOURCE);
+
+ am_Source_s *source = nodeSource->getData().data.source;
+ am_Sink_s *sink = nodeSink->getData().data.sink;
+ CAmRouter::listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, outConnectionFormats);
+}
+
+template <class X> void getMergeConnectionFormats(const X * element,
+ const am_CustomConnectionFormat_t connectionFormat,
+ const std::vector<am_CustomConnectionFormat_t> & listConnectionFormats,
+ std::vector<am_CustomConnectionFormat_t> & outListMergeConnectionFormats)
+{
+ std::vector<am_CustomConnectionFormat_t> 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<std::vector<am_CustomConnectionFormat_t> > inserter(outListMergeConnectionFormats, outListMergeConnectionFormats.begin());
+ set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter);
+}
+
+
CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSender) :
mpDatabaseHandler(iDatabaseHandler), //
- mpControlSender(iSender)
+ mpControlSender(iSender),
+ mOnlyFreeConversionNodes(false),
+ mRoutingGraph(),
+ mNodeListSources(),
+ mNodeListSinks(),
+ mNodeListGateways(),
+ mNodeListConverters(),
+ mNodeListSourceStatus(),
+ mNodeListSinkStatus(),
+ mNodeListConverterStatus(),
+ mNodeListGatewayStatus(),
+ mpRootSource(0),
+ mpRootSink(0)
{
assert(mpDatabaseHandler);
assert(mpControlSender);
}
+CAmRouter::~CAmRouter()
+{
+}
+
/**
* returns the best route between a source and a sink
* @param onlyfree if true only free gateways are used
@@ -48,213 +101,67 @@ CAmRouter::CAmRouter(IAmDatabaseHandler* iDatabaseHandler, CAmControlSender* iSe
am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s> & returnList)
{
returnList.clear();
- //first find out in which domains the source and sink are
- am_domainID_t sourceDomainID;
- am_domainID_t sinkDomainID;
- if (mpDatabaseHandler->getDomainOfSource(sourceID, sourceDomainID) != E_OK)
- return (E_NON_EXISTENT);
- if (mpDatabaseHandler->getDomainOfSink(sinkID, sinkDomainID) != E_OK)
- return (E_NON_EXISTENT);
-
- if (sourceDomainID == sinkDomainID) //shortcut if the domains are the same...
- {
- //first get the list of possible connection formats
- std::vector<am_CustomConnectionFormat_t> listFormats, listPriorityConnectionFormats;
- listPossibleConnectionFormats(sourceID, sinkID, listFormats);
-
- //dummy route
- am_Route_s route;
- route.sinkID = sinkID;
- route.sourceID = sourceID;
- route.route.clear();
-
- //get the prio of the Controller:
- mpControlSender->getConnectionFormatChoice(sourceID, sinkID, route, listFormats, listPriorityConnectionFormats);
-
- //no possible connection, so no route ! But we report OK since there is no fault ...
- if (listPriorityConnectionFormats.empty())
- return (E_OK);
-
- //return the first item as route:
- am_RoutingElement_s routingElement;
- routingElement.sourceID = sourceID;
- routingElement.sinkID = sinkID;
- routingElement.connectionFormat = listPriorityConnectionFormats[0];
- routingElement.domainID = sourceDomainID;
-
- //Now get a route:
- am_Route_s actualRoute;
- actualRoute.route.push_back(routingElement);
- actualRoute.sourceID = sourceID;
- actualRoute.sinkID = sinkID;
-
- //push it to the return list - we are done here ...
- returnList.push_back(actualRoute);
- return (E_OK);
-
- }
- CAmRoutingTree routingtree(sourceDomainID); //Build up a Tree from the Source_Domain to every other domain.
- std::vector<CAmRoutingTreeItem*> flattree; //This list is the flat tree
- std::vector<CAmRoutingTreeItem*> matchtree;
- std::vector<am_gatewayID_t> listGatewayID; //holds all gateway ids of the route
- am_RoutingElement_s routingElement;
- am_Route_s actualRoute; //holds the actual Route
- am_sourceID_t lastSource = 0;
-
- mpDatabaseHandler->getRoutingTree(onlyfree, routingtree, flattree); //Build up the tree out of the database as
-
- //we go through the returned flattree and look for our sink, after that flattree holds only treeItems that match
- std::vector<CAmRoutingTreeItem*>::iterator iterator = flattree.begin();
- for (; iterator != flattree.end(); ++iterator)
- {
- if ((*iterator)->returnDomainID() == sinkDomainID)
- {
- matchtree.push_back(*iterator);
- }
- }
-
- //No we need to trace back the routes for each entry in matchtree
- iterator = matchtree.begin();
- for (; iterator != matchtree.end(); ++iterator)
- {
- std::vector<am_RoutingElement_s> actualRoutingElement; //intermediate list of current routing pairs
- //getting the route for the actual item
- routingtree.getRoute(*iterator, listGatewayID); //This gives only the Gateway IDs we need more
-
- //go throught the gatewayids and get more information
- std::vector<am_gatewayID_t>::iterator gatewayIterator = listGatewayID.begin();
- for (; gatewayIterator != listGatewayID.end(); ++gatewayIterator)
- {
- am_Gateway_s gatewayData;
- if (mpDatabaseHandler->getGatewayInfoDB(*gatewayIterator, gatewayData) != E_OK)
- return (E_UNKNOWN);
-
- //at the beginning of the route, we connect first the source to the first gateway
- if (gatewayIterator == listGatewayID.begin())
- {
- routingElement.sourceID = sourceID;
- routingElement.domainID = sourceDomainID;
- }
- else
- {
- routingElement.sourceID = lastSource;
- routingElement.domainID = gatewayData.domainSinkID;
- }
- routingElement.sinkID = gatewayData.sinkID;
- actualRoutingElement.push_back(routingElement);
- lastSource = gatewayData.sourceID;
- }
- //at the end of the route, connect to the sink !
- routingElement.sourceID = lastSource;
- routingElement.sinkID = sinkID;
- routingElement.domainID = sinkDomainID;
- actualRoutingElement.push_back(routingElement);
-
- //So now we got the route, what is missing are the connectionFormats...
-
- //Step through the routes and try to use always the best connectionFormat
- std::vector<am_RoutingElement_s>::iterator routingInterator = actualRoutingElement.begin();
- gatewayIterator = listGatewayID.begin();
- if (findBestWay(sinkID, sourceID, actualRoutingElement, routingInterator, gatewayIterator) != E_OK)
- {
- continue;
- }
-
- //add the route to the list of routes...
- actualRoute.sourceID = sourceID;
- actualRoute.sinkID = sinkID;
- actualRoute.route = actualRoutingElement;
- returnList.push_back(actualRoute);
- }
- return (E_OK);
+ am_Source_s source;
+ am_Sink_s sink;
+ mpDatabaseHandler->getSourceInfoDB(sourceID, source);
+ mpDatabaseHandler->getSinkInfoDB(sinkID, sink);
+ return getRoute(onlyfree, source, sink, returnList);
}
-void CAmRouter::listPossibleConnectionFormats(const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_CustomConnectionFormat_t>& listFormats) const
+bool CAmRouter::getAllowedFormatsFromConvMatrix( const std::vector<bool> & convertionMatrix,
+ const std::vector<am_CustomConnectionFormat_t> & listSourceFormats,
+ const std::vector<am_CustomConnectionFormat_t> & listSinkFormats,
+ std::vector<am_CustomConnectionFormat_t> & sourceFormats,
+ std::vector<am_CustomConnectionFormat_t> & sinkFormats)
{
- std::vector<am_CustomConnectionFormat_t> listSourceFormats;
- std::vector<am_CustomConnectionFormat_t> listSinkFormats;
- mpDatabaseHandler->getListSinkConnectionFormats(sinkID, listSinkFormats);
- mpDatabaseHandler->getListSourceConnectionFormats(sourceID, listSourceFormats);
- std::sort(listSinkFormats.begin(), listSinkFormats.end()); //todo: this might be not needed if we use strictly sorted input
- std::sort(listSourceFormats.begin(), listSourceFormats.end()); //todo: this might be not needed if we use strictly sorted input
- std::insert_iterator<std::vector<am_CustomConnectionFormat_t> > inserter(listFormats, listFormats.begin());
- set_intersection(listSourceFormats.begin(), listSourceFormats.end(), listSinkFormats.begin(), listSinkFormats.end(), inserter);
+ 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<bool>::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;
}
-am_Error_e CAmRouter::findBestWay(am_sinkID_t sinkID, am_sourceID_t sourceID, std::vector<am_RoutingElement_s> & listRoute, std::vector<am_RoutingElement_s>::iterator routeIterator, std::vector<am_gatewayID_t>::iterator gatewayIterator)
+void CAmRouter::listPossibleConnectionFormats(std::vector<am_CustomConnectionFormat_t> & inListSourceFormats,
+ std::vector<am_CustomConnectionFormat_t> & inListSinkFormats,
+ std::vector<am_CustomConnectionFormat_t> & outListFormats)
{
- am_Error_e returnError = E_NOT_POSSIBLE;
- std::vector<am_CustomConnectionFormat_t> listConnectionFormats;
- std::vector<am_CustomConnectionFormat_t> listMergeConnectionFormats;
- std::vector<am_CustomConnectionFormat_t> listPriorityConnectionFormats;
- std::vector<am_RoutingElement_s>::iterator nextIterator = routeIterator + 1;
- //get best connection format
- listPossibleConnectionFormats(routeIterator->sourceID, routeIterator->sinkID, listConnectionFormats);
-
- //if we have not just started, we need to take care about the gateways...
- if (routeIterator != listRoute.begin())
- {
- //since we have to deal with Gateways, there are restrictions what connectionFormat we can take. So we need to take the subset of connections that are restricted:
- std::vector<am_CustomConnectionFormat_t> listRestrictedConnectionFormats;
- std::insert_iterator<std::vector<am_CustomConnectionFormat_t> > inserter(listMergeConnectionFormats, listMergeConnectionFormats.begin());
- std::vector<am_RoutingElement_s>::iterator tempIterator(routeIterator);
- tempIterator--;
- listRestrictedOutputFormatsGateways(*gatewayIterator, (tempIterator)->connectionFormat, listRestrictedConnectionFormats);
- std::sort(listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end()); //todo: this might be not needed if we use strictly sorted input
- set_intersection(listConnectionFormats.begin(), listConnectionFormats.end(), listRestrictedConnectionFormats.begin(), listRestrictedConnectionFormats.end(), inserter);
- gatewayIterator++;
- }
- else
- {
- listMergeConnectionFormats = listConnectionFormats;
- }
-
- am_Route_s route;
- route.sinkID = sinkID;
- route.sourceID = sourceID;
- route.route = listRoute;
-
- //let the controller decide:
- mpControlSender->getConnectionFormatChoice(routeIterator->sourceID, routeIterator->sinkID, route, listMergeConnectionFormats, listPriorityConnectionFormats);
-
- //we have the list sorted after prios - now we try one after the other with the next part of the route
- std::vector<am_CustomConnectionFormat_t>::iterator connectionFormatIterator = listPriorityConnectionFormats.begin();
-
- //here we need to check if we are at the end and stop
- if (nextIterator == listRoute.end())
- {
- if (!listPriorityConnectionFormats.empty())
- {
- routeIterator->connectionFormat = listPriorityConnectionFormats.front();
- return (E_OK);
- }
- else
- return (E_NOT_POSSIBLE);
- }
-
- for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator)
- {
- routeIterator->connectionFormat = *connectionFormatIterator;
- if ((returnError = findBestWay(sinkID, sourceID, listRoute, nextIterator, gatewayIterator)) == E_OK)
- {
- break;
- }
- }
-
- return (returnError);
+ std::sort(inListSourceFormats.begin(), inListSourceFormats.end());
+ std::sort(inListSinkFormats.begin(), inListSinkFormats.end());
+ std::insert_iterator<std::vector<am_CustomConnectionFormat_t> > inserter(outListFormats, outListFormats.begin());
+ set_intersection(inListSourceFormats.begin(), inListSourceFormats.end(), inListSinkFormats.begin(), inListSinkFormats.end(), inserter);
}
-void CAmRouter::listRestrictedOutputFormatsGateways(const am_gatewayID_t gatewayID, const am_CustomConnectionFormat_t sinkConnectionFormat, std::vector<am_CustomConnectionFormat_t> & listFormats) const
+
+bool CAmRouter::getRestrictedOutputFormats(const std::vector<bool> & convertionMatrix,
+ const std::vector<am_CustomConnectionFormat_t> & listSourceFormats,
+ const std::vector<am_CustomConnectionFormat_t> & listSinkFormats,
+ const am_CustomConnectionFormat_t connectionFormat,
+ std::vector<am_CustomConnectionFormat_t> & listFormats)
{
listFormats.clear();
- am_Gateway_s gatewayData;
- mpDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData);
- std::vector<am_CustomConnectionFormat_t>::const_iterator rowSinkIterator = gatewayData.listSinkFormats.begin();
- std::vector<bool>::const_iterator matrixIterator = gatewayData.convertionMatrix.begin();
+ std::vector<am_CustomConnectionFormat_t>::const_iterator rowSinkIterator = listSinkFormats.begin();
+ std::vector<bool>::const_iterator matrixIterator = convertionMatrix.begin();
//find the row number of the sink
- rowSinkIterator = find(gatewayData.listSinkFormats.begin(), gatewayData.listSinkFormats.end(), sinkConnectionFormat);
- int rowNumberSink = rowSinkIterator - gatewayData.listSinkFormats.begin();
+ rowSinkIterator = find(listSinkFormats.begin(), listSinkFormats.end(), connectionFormat);
+ int rowNumberSink = rowSinkIterator - listSinkFormats.begin();
//go through the convertionMatrix and find out if the conversion is possible, if yes, add connectionFormat ...
std::advance(matrixIterator, rowNumberSink);
@@ -264,96 +171,817 @@ void CAmRouter::listRestrictedOutputFormatsGateways(const am_gatewayID_t gateway
{
if (*matrixIterator)
{
- listFormats.push_back(gatewayData.listSourceFormats.at((matrixIterator - gatewayData.convertionMatrix.begin()) / gatewayData.listSinkFormats.size()));
+ listFormats.push_back(listSourceFormats.at((matrixIterator - convertionMatrix.begin()) / listSinkFormats.size()));
}
- std::advance(matrixIterator, gatewayData.listSinkFormats.size());
- } while (gatewayData.convertionMatrix.end() - matrixIterator > 0);
+ std::advance(matrixIterator, listSinkFormats.size());
+ } while (convertionMatrix.end() - matrixIterator > 0);
+
+ return listFormats.size();
}
-CAmRouter::~CAmRouter()
+#ifdef EXTENDED_ROUTING_GRAPH
+void appendNodes(CAmGraph<am_RoutingNodeData_s, uint16_t> & routingGraph,
+ const std::vector<am_CustomConnectionFormat_t> & listConnectionFormats,
+ am_RoutingNodeData_s & nodeData,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & nodeList)
{
+ std::for_each(listConnectionFormats.begin(), listConnectionFormats.end(), [&](const am_CustomConnectionFormat_t cf){
+ nodeData.inConnectionFormat = cf;
+ nodeList.push_back(&routingGraph.addNode(nodeData));
+ });
}
-CAmRoutingTreeItem::CAmRoutingTreeItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent) :
- mDomainID(domainID), //
- mGatewayID(gatewayID), //
- mpParentItem(parent)
+void appendNodes(CAmGraph<am_RoutingNodeData_s, uint16_t> & routingGraph,
+ const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats,
+ const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats,
+ const std::vector<bool> & convertionMatrix,
+ am_RoutingNodeData_s & nodeData,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & nodeList)
{
- assert(mDomainID!=0);
+
+ std::vector<am_CustomConnectionFormat_t> sourceFormats, sinkFormats;
+ if(CAmRouter::getAllowedFormatsFromConvMatrix(convertionMatrix, sourceConnectionFormats, sinkConnectionFormats, sourceFormats, sinkFormats))
+ {
+ for(size_t i = 0; i < sourceFormats.size(); i++)
+ {
+ nodeData.inConnectionFormat = sinkFormats[i];
+ nodeData.outConnectionFormat = sourceFormats[i];
+ nodeList.push_back(&routingGraph.addNode(nodeData));
+ }
+ }
}
+#endif
-void CAmRoutingTreeItem::appendChild(CAmRoutingTreeItem *newChild)
+am_Error_e CAmRouter::getRoute(const bool onlyfree, const am_Source_s & aSource, const am_Sink_s & aSink, std::vector<am_Route_s> & listRoutes)
{
- assert(newChild);
- mListChildItems.push_back(newChild);
+ clear();
+ mOnlyFreeConversionNodes = onlyfree;
+
+ // We need to copy the sinks, sources, converters, gateways, because we don't know what store is being used (SQLite or Map).
+ //todo: Don't make copy for map storage.
+ std::deque<am_Source_s> listSources;
+ std::deque<am_Sink_s> listSinks;
+ std::deque<am_Gateway_s> listGateways;
+ std::deque<am_Converter_s> listConverters;
+
+ am_Error_e error = E_OK;
+
+ am_RoutingNodeData_s nodeDataSrc;
+ nodeDataSrc.type = NodeDataType::SOURCE;
+ mpDatabaseHandler->enumerateSources([&](const am_Source_s & obj){
+ listSources.push_back(obj);
+ nodeDataSrc.data.source = &listSources.back();
+ mNodeListSourceStatus[obj.sourceID]=false;
+#ifdef EXTENDED_ROUTING_GRAPH
+ appendNodes(mRoutingGraph, obj.listConnectionFormats, nodeDataSrc, mNodeListSources);
+#else
+ mNodeListSources.push_back(&mRoutingGraph.addNode(nodeDataSrc));
+#endif
+ });
+ am_RoutingNodeData_s nodeDataSink;
+ nodeDataSink.type = NodeDataType::SINK;
+ mpDatabaseHandler->enumerateSinks([&](const am_Sink_s & obj){
+ listSinks.push_back(obj);
+ nodeDataSink.data.sink = &listSinks.back();
+ mNodeListSinkStatus[obj.sinkID]=false;
+#ifdef EXTENDED_ROUTING_GRAPH
+ appendNodes(mRoutingGraph, obj.listConnectionFormats, nodeDataSink, mNodeListSinks);
+#else
+ mNodeListSinks.push_back(&mRoutingGraph.addNode(nodeDataSink));
+#endif
+ });
+ am_RoutingNodeData_s nodeDataGateway;
+ nodeDataGateway.type = NodeDataType::GATEWAY;
+ mpDatabaseHandler->enumerateGateways([&](const am_Gateway_s & obj){
+ listGateways.push_back(obj);
+ nodeDataGateway.data.gateway = &listGateways.back();
+ mNodeListGatewayStatus[obj.gatewayID]=false;
+#ifdef EXTENDED_ROUTING_GRAPH
+ appendNodes(mRoutingGraph, obj.listSourceFormats, obj.listSinkFormats, obj.convertionMatrix, nodeDataGateway, mNodeListGateways);
+#else
+ mNodeListGateways.push_back(&mRoutingGraph.addNode(nodeDataGateway));
+#endif
+ });
+ am_RoutingNodeData_s nodeDataConverter;
+ nodeDataConverter.type = NodeDataType::CONVERTER;
+ mpDatabaseHandler->enumerateConverters([&](const am_Converter_s & obj){
+ listConverters.push_back(obj);
+ nodeDataConverter.data.converter = &listConverters.back();
+ mNodeListConverterStatus[obj.converterID]=false;
+#ifdef EXTENDED_ROUTING_GRAPH
+ appendNodes(mRoutingGraph, obj.listSourceFormats, obj.listSinkFormats, obj.convertionMatrix, nodeDataConverter, mNodeListConverters);
+#else
+ mNodeListConverters.push_back(&mRoutingGraph.addNode(nodeDataConverter));
+#endif
+ });
+
+ buildGraph(aSource, aSink);
+
+#ifdef EXTENDED_ROUTING_GRAPH
+ std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> pathNodes;
+ getShortestPath(listRoutes, pathNodes);
+#else
+ std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> pathNodes;
+ error = getAllPaths(listRoutes, pathNodes);
+#endif
+ return error;
}
-void CAmRoutingTreeItem::returnChildItems(std::vector<CAmRoutingTreeItem*> listChildItems)
+void CAmRouter::buildGraph( const am_Source_s & aSource, const am_Sink_s & aSink)
{
- listChildItems = mListChildItems;
+ //build up a topological sorted graph
+#ifdef EXTENDED_ROUTING_GRAPH
+ mpRootSource = (am_Source_s*)&aSource;
+ mpRootSink = (am_Sink_s*)&aSink;
+ for(auto it1=aSource.listConnectionFormats.begin(); it1!=aSource.listConnectionFormats.end(); it1++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSource = sourceNodeWithID(aSource.sourceID, *it1);
+ for(auto it2=aSink.listConnectionFormats.begin(); it2!=aSink.listConnectionFormats.end(); it2++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSink = sinkNodeWithID(aSink.sinkID, *it2);
+ if(pRootNodeSource && pRootNodeSink)
+ {
+ if(aSource.domainID==aSink.domainID)
+ routeInSameDomain(*pRootNodeSource, *pRootNodeSink);
+ else
+ routeInAnotherDomain(*pRootNodeSource, *pRootNodeSink);
+ }
+ }
+ }
+#else
+ mpRootSource = sourceNodeWithID(aSource.sourceID);
+ mpRootSink = sinkNodeWithID(aSink.sinkID);
+
+ assert(mpRootSource);
+ assert(mpRootSink);
+
+ if(aSource.domainID==aSink.domainID)
+ {
+ routeInSameDomain(*mpRootSource, *mpRootSink);
+ }
+ else
+ {
+ routeInAnotherDomain(*mpRootSource, *mpRootSink);
+ }
+#endif
+#ifdef TRACE_GRAPH
+ mRoutingGraph.trace([&](const CAmNode<am_RoutingNodeData_s> & node, const std::vector<CAmVertex<am_RoutingNodeData_s,uint16_t>*> & list) {
+ std::cout << "Node " << node.getIndex() << " :";
+ ((CAmNode<am_RoutingNodeData_s> &)node).getData().trace();
+ std::cout << "-->";
+ std::for_each(list.begin(), list.end(), [&](const CAmVertex<am_RoutingNodeData_s,uint16_t>* refVertex){
+ am::CAmNode<am::am_RoutingNodeData_s>* data = refVertex->getNode();
+ std::cout << "Node " << data->getIndex() << " :";
+ data->getData().trace();
+ });
+ std::cout << std::endl;
+ });
+#endif
}
+#ifdef EXTENDED_ROUTING_GRAPH
-am_domainID_t CAmRoutingTreeItem::returnDomainID() const
+CAmNode<am_RoutingNodeData_s>* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID, const am_CustomConnectionFormat_t connectionFormat)
{
- return (mDomainID);
+ auto iter = std::find_if(mNodeListSinks.begin(), mNodeListSinks.end(), [sinkID, connectionFormat](CAmNode<am_RoutingNodeData_s>* node){
+ return node->getData().data.sink->sinkID==sinkID && node->getData().inConnectionFormat==connectionFormat;
+ });
+ if(iter!=mNodeListSinks.end())
+ return *iter;
+ return NULL;
}
-am_gatewayID_t CAmRoutingTreeItem::returnGatewayID() const
+CAmNode<am_RoutingNodeData_s>* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID, const am_CustomConnectionFormat_t connectionFormat)
+{
+ auto iter = std::find_if(mNodeListSources.begin(), mNodeListSources.end(), [sourceID, connectionFormat](CAmNode<am_RoutingNodeData_s>* node){
+ return node->getData().data.source->sourceID==sourceID && node->getData().inConnectionFormat==connectionFormat;
+ });
+ if(iter!=mNodeListSources.end())
+ return *iter;
+ return NULL;
+}
+#else
+CAmNode<am_RoutingNodeData_s>* CAmRouter::sinkNodeWithID(const am_sinkID_t sinkID)
{
- return (mGatewayID);
+ auto iter = std::find_if(mNodeListSinks.begin(), mNodeListSinks.end(), [sinkID](CAmNode<am_RoutingNodeData_s>* node){
+ return node->getData().data.sink->sinkID==sinkID;
+ });
+ if(iter!=mNodeListSinks.end())
+ return *iter;
+ return NULL;
}
-CAmRoutingTreeItem* CAmRoutingTreeItem::returnParent() const
+CAmNode<am_RoutingNodeData_s>* CAmRouter::sourceNodeWithID(const am_sourceID_t sourceID)
{
- return (mpParentItem);
+ auto iter = std::find_if(mNodeListSources.begin(), mNodeListSources.end(), [sourceID](CAmNode<am_RoutingNodeData_s>* node){
+ return node->getData().data.source->sourceID==sourceID;
+ });
+ if(iter!=mNodeListSources.end())
+ return *iter;
+ return NULL;
}
+#endif
-CAmRoutingTreeItem::~CAmRoutingTreeItem()
+void CAmRouter::connectNodes(const CAmNode<am_RoutingNodeData_s> & node1,
+ const CAmNode<am_RoutingNodeData_s> & node2,
+ const am_CustomConnectionFormat_t vertexData,
+ const int16_t weight)
{
+ if( !mRoutingGraph.isAnyVertex(node1, node2) )
+ mRoutingGraph.connectNodes(node1, node2, vertexData, weight);
}
-CAmRoutingTree::CAmRoutingTree(const am_domainID_t rootDomainID) :
- mRootItem(CAmRoutingTreeItem(rootDomainID))
+bool CAmRouter::routeInSameDomain(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink)
{
- assert(rootDomainID!=0);
+ am_RoutingNodeData_s & sourceData = aSource.getData();
+ am_RoutingNodeData_s & sinkData = aSink.getData();
+ am_Source_s * source = sourceData.data.source;
+ //If exists connection return
+ if( mRoutingGraph.isAnyVertex(aSource, aSink))
+ return true;
+ if( mNodeListSourceStatus[source->sourceID] )
+ return false;
+ bool result = false;
+ mNodeListSourceStatus[source->sourceID]=true;
+#ifdef EXTENDED_ROUTING_GRAPH
+ if(sourceData.inConnectionFormat!=sinkData.inConnectionFormat) // it is not possible to connect them directly
+ {
+#else
+ am_Sink_s * sink = sinkData.data.sink;
+ std::vector<am_CustomConnectionFormat_t> listFormats;
+ CAmRouter::listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listFormats);
+ if(listFormats.size()==0) // it is not possible to connect them directly
+ {
+#endif
+ bool availableConverter = false;
+ for(auto iter = mNodeListConverters.begin(); iter!=mNodeListConverters.end(); iter++)
+ {
+ CAmNode<am_RoutingNodeData_s>* converterNode = *iter;
+ am_RoutingNodeData_s & converterNodeData = converterNode->getData();
+ am_Converter_s * converter = converterNodeData.data.converter;
+ //Get only converters with end point in current source domain
+ if( !mNodeListConverterStatus[converter->converterID] && converter->domainID==source->domainID && (!mOnlyFreeConversionNodes || !isComponentConnected(*converter)))
+ {
+ //Get the sink connected to the converter...
+ mNodeListConverterStatus[converter->converterID]=true;
+#ifdef EXTENDED_ROUTING_GRAPH
+ CAmNode<am_RoutingNodeData_s> *converterSinkNode = this->sinkNodeWithID(converter->sinkID, converterNodeData.inConnectionFormat);
+#else
+ CAmNode<am_RoutingNodeData_s> *converterSinkNode = this->sinkNodeWithID(converter->sinkID);
+#endif
+ if(converterSinkNode)
+ {
+ am_RoutingNodeData_s & converterSinkData = converterSinkNode->getData();
+ //Check whether the hidden sink formats match the source formats...
+#ifdef EXTENDED_ROUTING_GRAPH
+ if(sourceData.inConnectionFormat==converterSinkData.inConnectionFormat)
+ {
+ CAmNode<am_RoutingNodeData_s> *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converterNodeData.outConnectionFormat);
+ if(converterSourceNode)
+ {
+ am_RoutingNodeData_s & converterSourceData = converterSourceNode->getData();
+ if(converterSourceData.inConnectionFormat==converterSinkData.outConnectionFormat)
+ {
+ availableConverter=true;
+ // Connection source->conv_sink->converter->conv_source
+ this->connectNodes(aSource, *converterSinkNode, converterNodeData.inConnectionFormat, 1);
+ this->connectNodes(*converterSinkNode, *converterNode, converterNodeData.inConnectionFormat, 1);
+ this->connectNodes(*converterNode, *converterSourceNode, converterNodeData.outConnectionFormat, 1);
+ result|=this->routeInSameDomain(*converterSourceNode, aSink);
+ }
+ }
+ }
+ else
+ {
+ //the converter is not suitable, lets try to find paths through another domains
+ bool alternResult = this->routeInAnotherDomain(aSource, *converterSinkNode);
+ if(alternResult)
+ {
+ CAmNode<am_RoutingNodeData_s> *converterSourceNode = this->sourceNodeWithID(converter->sourceID, converterNodeData.outConnectionFormat);
+ if(converterSourceNode)
+ {
+ am_RoutingNodeData_s & converterSourceData = converterSourceNode->getData();
+ if(converterSourceData.inConnectionFormat==converterSinkData.outConnectionFormat)
+ {
+ // Connection source->conv_sink->converter->conv_source
+ this->connectNodes(*converterSinkNode, *converterNode, converterNodeData.inConnectionFormat, 1);
+ this->connectNodes(*converterNode, *converterSourceNode, converterNodeData.outConnectionFormat, 1);
+ result|=this->routeInSameDomain(*converterSourceNode, aSink);
+ }
+ }
+ }
+ }
+#else
+ am_Sink_s * nextSink = converterSinkData.data.sink;
+ std::vector<am_CustomConnectionFormat_t> sourceFormats, sinkFormats, intersection;
+ //Check whether the hidden sink formats match the source formats...
+ CAmRouter::listPossibleConnectionFormats(source->listConnectionFormats, nextSink->listConnectionFormats, intersection);
+ if(intersection.size()>0)//OK match source -> conv_sink
+ {
+ //Are there convertible formats or not
+ if(CAmRouter::getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats))
+ {
+ availableConverter=true;
+ CAmNode<am_RoutingNodeData_s> *nextSourceNode = this->sourceNodeWithID(converter->sourceID);
+ assert(nextSourceNode);
+ //Connections source->hidden_sink->converter->hidden_source
+ this->connectNodes(aSource, *converterSinkNode, CF_UNKNOWN, 1);
+ this->connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1);
+ this->connectNodes(*converterNode, *nextSourceNode, CF_UNKNOWN, 1);
+ //Go ahead with hidden_source and sink
+ result|=this->routeInSameDomain(*nextSourceNode, aSink);
+ }
+ }
+ else
+ {
+ //the converter is not suitable, lets try to find paths through another domains
+ bool alternResult = this->routeInAnotherDomain(aSource, *converterSinkNode);
+ if(alternResult)
+ {
+ if(CAmRouter::getAllowedFormatsFromConvMatrix(converter->convertionMatrix, converter->listSourceFormats, converter->listSinkFormats, sourceFormats, sinkFormats))
+ {
+ CAmNode<am_RoutingNodeData_s> *nextSourceNode = this->sourceNodeWithID(converter->sourceID);
+ assert(nextSourceNode);
+ //Connections source->hidden_sink->converter->hidden_source
+ this->connectNodes(*converterSinkNode, *converterNode, CF_UNKNOWN, 1);
+ this->connectNodes(*converterNode, *nextSourceNode, CF_UNKNOWN, 1);
+ //Go ahead with hidden_source and sink
+ result|=this->routeInSameDomain(*nextSourceNode, aSink);
+ }
+ }
+ }
+#endif
+ }
+ mNodeListConverterStatus[converter->converterID]=false;
+ }
+ }
+ if(!availableConverter)
+ {
+ mNodeListSourceStatus[source->sourceID]=false;
+ result|=this->routeInAnotherDomain(aSource, aSink);
+ }
+ }
+ else
+ {
+ //success only if the source can be connected with the sink
+#ifdef EXTENDED_ROUTING_GRAPH
+ this->connectNodes(aSource, aSink, sourceData.inConnectionFormat, 1);
+#else
+ this->connectNodes(aSource, aSink, CF_UNKNOWN, 1);
+#endif
+ result=true;
+ }
+ mNodeListSourceStatus[source->sourceID]=false;
+ return result;
}
-CAmRoutingTreeItem *CAmRoutingTree::insertItem(const am_domainID_t domainID, const am_gatewayID_t gatewayID, CAmRoutingTreeItem *parent)
+bool CAmRouter::routeInAnotherDomain(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink)
{
- CAmRoutingTreeItem *newTree = new CAmRoutingTreeItem(domainID, gatewayID, parent);
- parent->appendChild(newTree);
- mListChild.push_back(newTree);
- return (newTree);
+ am_RoutingNodeData_s & sourceData = aSource.getData();
+ am_RoutingNodeData_s & sinkData = aSink.getData();
+ am_Source_s * source = sourceData.data.source;
+ am_Sink_s * sink = sinkData.data.sink;
+
+ if(mRoutingGraph.isAnyVertex(aSource, aSink))
+ return true;
+ if( mNodeListSourceStatus[source->sourceID] )
+ return false;
+ mNodeListSourceStatus[source->sourceID]=true;
+#ifndef EXTENDED_ROUTING_GRAPH
+ std::vector<am_CustomConnectionFormat_t> sourceFormats, sinkFormats, intersection;
+#endif
+ bool result = false;
+ for(auto iter = mNodeListGateways.begin(); iter!=mNodeListGateways.end(); iter++)
+ {
+ CAmNode<am_RoutingNodeData_s>* gatewayNode = *iter;
+ am_RoutingNodeData_s & gatewayNodeData = gatewayNode->getData();
+ am_Gateway_s * gateway = gatewayNodeData.data.gateway;
+ //Get only gateways with end point in current source domain
+ if(
+ !mNodeListGatewayStatus[gateway->gatewayID] &&
+ gateway->domainSinkID==source->domainID &&
+ (!mOnlyFreeConversionNodes || !isComponentConnected(*gateway)) )
+ {
+ //Get the sink connected to the gateway...
+ mNodeListGatewayStatus[gateway->gatewayID]=true;
+#ifdef EXTENDED_ROUTING_GRAPH
+ CAmNode<am_RoutingNodeData_s> *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID, gatewayNodeData.inConnectionFormat);
+#else
+ CAmNode<am_RoutingNodeData_s> *gatewaySinkNode = this->sinkNodeWithID(gateway->sinkID);
+#endif
+
+ if(gatewaySinkNode)
+ {
+ am_RoutingNodeData_s & gatewaySinkData = gatewaySinkNode->getData();
+ //Check whether the hidden sink formats match the source formats...
+
+#ifdef EXTENDED_ROUTING_GRAPH
+ if(sourceData.inConnectionFormat==gatewaySinkData.inConnectionFormat)
+ {
+ //Check if the gateway is able to convert any formats...
+ CAmNode<am_RoutingNodeData_s> *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gatewayNodeData.outConnectionFormat);
+ if(gatewaySourceNode)
+ {
+ am_RoutingNodeData_s & gatewaySourceData = gatewaySourceNode->getData();
+ if(gatewaySourceData.inConnectionFormat==gatewayNodeData.outConnectionFormat)
+ {
+ am_Source_s * gatewaySource = gatewaySourceData.data.source;
+ //Connections source->hidden_sink->gateway->hidden_source
+ this->connectNodes(aSource, *gatewaySinkNode, gatewayNodeData.inConnectionFormat, 1);
+ this->connectNodes(*gatewaySinkNode, *gatewayNode, gatewayNodeData.inConnectionFormat, 1);
+ this->connectNodes(*gatewayNode, *gatewaySourceNode, gatewayNodeData.outConnectionFormat, 1);
+ //Go ahead with hidden_source and sink
+ if(gatewaySource->domainID==sink->domainID)
+ result|=this->routeInSameDomain(*gatewaySourceNode, aSink);
+ else
+ result|=this->routeInAnotherDomain(*gatewaySourceNode, aSink);
+ }
+ }
+ }
+ else
+ {
+ //the gateway is not suitable, lets try to find paths within this domains
+ bool alternResult = this->routeInSameDomain(aSource, *gatewaySinkNode);
+ if(alternResult)
+ {
+ CAmNode<am_RoutingNodeData_s> *gatewaySourceNode = this->sourceNodeWithID(gateway->sourceID, gatewayNodeData.outConnectionFormat);
+ if(gatewaySourceNode)
+ {
+ am_RoutingNodeData_s & gatewaySourceData = gatewaySourceNode->getData();
+ if(gatewaySourceData.inConnectionFormat==gatewayNodeData.outConnectionFormat)
+ {
+ am_Source_s * gatewaySource = gatewaySourceData.data.source;
+ //Connections source->hidden_sink->gateway->hidden_source
+ this->connectNodes(aSource, *gatewaySinkNode, gatewayNodeData.inConnectionFormat, 1);
+ this->connectNodes(*gatewaySinkNode, *gatewayNode, gatewayNodeData.inConnectionFormat, 1);
+ this->connectNodes(*gatewayNode, *gatewaySourceNode, gatewayNodeData.outConnectionFormat, 1);
+ //Go ahead with hidden_source and sink
+ if(gatewaySource->domainID==sink->domainID)
+ result|=this->routeInSameDomain(*gatewaySourceNode, aSink);
+ else
+ result|=this->routeInAnotherDomain(*gatewaySourceNode, aSink);
+ }
+ }
+ }
+ }
+#else
+ am_Sink_s * nextSink = gatewaySinkData.data.sink;
+ std::vector<am_CustomConnectionFormat_t> sourceFormats, sinkFormats, intersection;
+ CAmRouter::listPossibleConnectionFormats(source->listConnectionFormats, nextSink->listConnectionFormats, intersection);
+ if(intersection.size()>0)//OK match source -> conv_sink
+ {
+ //Check if the gateway is able to convert any formats...
+ if(CAmRouter::getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats))
+ {
+ CAmNode<am_RoutingNodeData_s> *nextSourceNode = this->sourceNodeWithID(gateway->sourceID);
+ assert(nextSourceNode);
+ am_Source_s * nextSource = nextSourceNode->getData().data.source;
+ //Connections source->hidden_sink->gateway->hidden_source
+ this->connectNodes(aSource, *gatewaySinkNode, CF_UNKNOWN, 1);
+ this->connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1);
+ this->connectNodes(*gatewayNode, *nextSourceNode, CF_UNKNOWN, 1);
+ //Go ahead with hidden_source and sink
+ if(nextSource->domainID==sink->domainID)
+ result|=this->routeInSameDomain(*nextSourceNode, aSink);
+ else
+ result|=this->routeInAnotherDomain(*nextSourceNode, aSink);
+ }
+ }
+ else
+ {
+ //the gateway is not suitable, lets try to find paths within this domains
+ mNodeListSourceStatus[source->sourceID]=false;
+ bool alternResult = this->routeInSameDomain(aSource, *gatewaySinkNode);
+ if(alternResult)
+ {
+ if(CAmRouter::getAllowedFormatsFromConvMatrix(gateway->convertionMatrix, gateway->listSourceFormats, gateway->listSinkFormats, sourceFormats, sinkFormats))
+ {
+ CAmNode<am_RoutingNodeData_s> *nextSourceNode = this->sourceNodeWithID(gateway->sourceID);
+ assert(nextSourceNode);
+ am_Source_s * nextSource = nextSourceNode->getData().data.source;
+ //Connections source->hidden_sink->gateway->hidden_source
+ this->connectNodes(*gatewaySinkNode, *gatewayNode, CF_UNKNOWN, 1);
+ this->connectNodes(*gatewayNode, *nextSourceNode, CF_UNKNOWN, 1);
+ //Go ahead with hidden_source and sink
+ if(nextSource->domainID==sink->domainID)
+ result|=this->routeInSameDomain(*nextSourceNode, aSink);
+ else
+ result|=this->routeInAnotherDomain(*nextSourceNode, aSink);
+ }
+ }
+ }
+#endif
+ }
+ mNodeListGatewayStatus[gateway->gatewayID]=false;
+ }
+ }
+ mNodeListSourceStatus[source->sourceID]=false;
+ return result;
}
-void CAmRoutingTree::getRoute(CAmRoutingTreeItem *targetItem, std::vector<am_gatewayID_t>& listGateways)
+#ifdef EXTENDED_ROUTING_GRAPH
+void CAmRouter::getShortestPath(const am_Source_s & aSource,
+ const am_Sink_s & aSink,
+ std::vector<am_Route_s> & resultPath,
+ std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath)
{
- listGateways.clear();
- CAmRoutingTreeItem *parentItem = targetItem;
- while (parentItem != &mRootItem)
- {
- listGateways.push_back(parentItem->returnGatewayID());
- parentItem = parentItem->returnParent();
- }
- std::reverse(listGateways.begin(), listGateways.end());
+ std::vector<CAmNode<am_RoutingNodeData_s>*> listTargets;
+ std::vector<CAmNode<am_RoutingNodeData_s>*> * pathNodes;
+ am_Route_s *path;
+ am_RoutingElement_s * element;
+ std::function<void(const am_GraphPathPosition_e, CAmNode<am_RoutingNodeData_s> &)> cb = [&](const am_GraphPathPosition_e pos, CAmNode<am_RoutingNodeData_s> & object)
+ {
+ if(pos==GRAPH_PATH_START)
+ {
+ resultNodesPath.emplace_back();
+ pathNodes=&resultNodesPath.back();
+ resultPath.emplace_back();
+ path= &resultPath.back();
+ path->sinkID = aSink.sinkID;
+ path->sourceID = aSource.sourceID;
+ }
+ pathNodes->insert(pathNodes->begin(), (CAmNode<am_RoutingNodeData_s>*)&object);
+
+ am_RoutingNodeData_s & routingData = object.getData();
+
+ if(routingData.type==am_RoutingNodeData_s::am_NodeDataType_e::SINK)
+ {
+ auto iter = path->route.emplace(path->route.begin());
+ element = &(*iter);
+
+ element->domainID = routingData.data.sink->domainID;
+ element->sinkID = routingData.data.sink->sinkID;
+ element->connectionFormat = routingData.inConnectionFormat;
+
+ }
+ else if(routingData.type==am_RoutingNodeData_s::am_NodeDataType_e::SOURCE)
+ {
+ element->domainID = routingData.data.source->domainID;
+ element->sourceID = routingData.data.source->sourceID;
+ element->connectionFormat = routingData.inConnectionFormat;
+ }
+ };
+
+
+ for(auto it2=aSink.listConnectionFormats.begin(); it2!=aSink.listConnectionFormats.end(); it2++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSink = sinkNodeWithID(aSink.sinkID, *it2);
+ if(pRootNodeSink)
+ listTargets.push_back(pRootNodeSink);
+ }
+ if(listTargets.size())
+ {
+ for(auto it1=aSource.listConnectionFormats.begin(); it1!=aSource.listConnectionFormats.end(); it1++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSource = sourceNodeWithID(aSource.sourceID, *it1);
+ if(pRootNodeSource)
+ {
+ mRoutingGraph.getShortestPath(*pRootNodeSource, listTargets, cb);
+ }
+ }
+ }
+}
+
+void CAmRouter::getShortestPath(std::vector<am_Route_s> & routes, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & nodes)
+{
+ getShortestPath(*mpRootSource, *mpRootSink, routes, nodes);
}
-am_domainID_t CAmRoutingTree::returnRootDomainID() const
+void CAmRouter::getShortestPath(const am_Source_s & aSource, const am_Sink_s & aSink,
+ std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultPath)
{
- return (mRootItem.returnDomainID());
+ std::vector<CAmNode<am_RoutingNodeData_s>*> listTargets;
+ for(auto it2=aSink.listConnectionFormats.begin(); it2!=aSink.listConnectionFormats.end(); it2++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSink = sinkNodeWithID(aSink.sinkID, *it2);
+ if(pRootNodeSink)
+ listTargets.push_back(pRootNodeSink);
+ }
+ if(listTargets.size())
+ {
+ for(auto it1=aSource.listConnectionFormats.begin(); it1!=aSource.listConnectionFormats.end(); it1++)
+ {
+ am::CAmNode<am::am_RoutingNodeData_s>* pRootNodeSource = sourceNodeWithID(aSource.sourceID, *it1);
+ if(pRootNodeSource)
+ {
+ mRoutingGraph.getShortestPath(*pRootNodeSource, listTargets, resultPath);
+ }
+ }
+ }
}
+#else
-CAmRoutingTreeItem *CAmRoutingTree::returnRootItem()
+am_Error_e CAmRouter::determineConnectionFormatsForPath(am_Route_s & routeObjects, std::vector<CAmNode<am_RoutingNodeData_s>*> & nodes)
{
- return (&mRootItem);
+ std::vector<am_RoutingElement_s>::iterator routingElementIterator = routeObjects.route.begin();
+ std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator nodeIterator = nodes.begin();
+ if( routingElementIterator!= routeObjects.route.end() && nodeIterator!=nodes.end() )
+ return doConnectionFormatsForPath(routeObjects, nodes, routingElementIterator, nodeIterator);
+ return E_OK;
}
-CAmRoutingTree::~CAmRoutingTree()
+am_Error_e CAmRouter::doConnectionFormatsForPath(am_Route_s & routeObjects,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & nodes,
+ std::vector<am_RoutingElement_s>::iterator routingElementIterator,
+ std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator nodeIterator)
{
- std::vector<CAmRoutingTreeItem*>::iterator it = mListChild.begin();
- for (; it != mListChild.end(); ++it)
+ am_Error_e returnError = E_NOT_POSSIBLE;
+ std::vector<am_CustomConnectionFormat_t> listConnectionFormats;
+ std::vector<am_CustomConnectionFormat_t> listMergeConnectionFormats;
+
+ std::vector<CAmNode<am_RoutingNodeData_s>*>::iterator currentNodeIterator = nodeIterator;
+ std::vector<am_RoutingElement_s>::iterator currentRoutingElementIterator = routingElementIterator;
+
+ if (currentRoutingElementIterator!=routeObjects.route.begin())
{
- delete *it;
+ std::vector<am_CustomConnectionFormat_t> listConnectionFormats;
+ std::vector<am_RoutingElement_s>::iterator tempIterator = (currentRoutingElementIterator-1);
+ CAmNode<am_RoutingNodeData_s> * currentNode = *currentNodeIterator;
+ getSourceSinkPossibleConnectionFormats(currentNodeIterator+1, currentNodeIterator+2, listConnectionFormats);
+
+ if(currentNode->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::GATEWAY)
+ {
+ am_Gateway_s *gateway = currentNode->getData().data.gateway;
+ getMergeConnectionFormats(gateway, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats);
+ }
+ else if(currentNode->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::CONVERTER)
+ {
+ am_Converter_s *converter = currentNode->getData().data.converter;
+ getMergeConnectionFormats(converter, tempIterator->connectionFormat, listConnectionFormats, listMergeConnectionFormats);
+ }
+ currentNodeIterator+=3;
}
+ else
+ {
+ CAmNode<am_RoutingNodeData_s> * currentNode = *currentNodeIterator;
+ assert(currentNode->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::SOURCE);
+
+ currentNodeIterator++;
+ assert(currentNodeIterator!=nodes.end());
+
+ CAmNode<am_RoutingNodeData_s> * nodeSink = *currentNodeIterator;
+ assert(nodeSink->getData().type==am_RoutingNodeData_s::am_NodeDataType_e::SINK);
+
+ am_Source_s *source = currentNode->getData().data.source;
+ am_Sink_s *sink = nodeSink->getData().data.sink;
+ CAmRouter::listPossibleConnectionFormats(source->listConnectionFormats, sink->listConnectionFormats, listMergeConnectionFormats);
+ currentNodeIterator+=1; //now we are on the next converter/gateway
+ }
+
+ //let the controller decide:
+ std::vector<am_CustomConnectionFormat_t> listPriorityConnectionFormats;
+ mpControlSender->getConnectionFormatChoice(currentRoutingElementIterator->sourceID, currentRoutingElementIterator->sinkID, routeObjects,
+ listMergeConnectionFormats, listPriorityConnectionFormats);
+
+ //we have the list sorted after priors - now we try one after the other with the next part of the route
+ std::vector<am_CustomConnectionFormat_t>::iterator connectionFormatIterator = listPriorityConnectionFormats.begin();
+ //here we need to check if we are at the end and stop
+ std::vector<am_RoutingElement_s>::iterator nextIterator = currentRoutingElementIterator + 1;//next pair source and sink
+ if (nextIterator == routeObjects.route.end())
+ {
+ if (!listPriorityConnectionFormats.empty())
+ {
+ currentRoutingElementIterator->connectionFormat = listPriorityConnectionFormats.front();
+ return (E_OK);
+ }
+ else
+ return (E_NOT_POSSIBLE);
+ }
+
+ for (; connectionFormatIterator != listPriorityConnectionFormats.end(); ++connectionFormatIterator)
+ {
+ currentRoutingElementIterator->connectionFormat = *connectionFormatIterator;
+ if ((returnError = doConnectionFormatsForPath(routeObjects, nodes, nextIterator, currentNodeIterator)) == E_OK)
+ {
+ break;
+ }
+ }
+ return (returnError);
+}
+
+void CAmRouter::getShortestPath(const CAmNode<am_RoutingNodeData_s> & source,
+ const CAmNode<am_RoutingNodeData_s> & destination,
+ std::vector<CAmNode<am_RoutingNodeData_s>*> & resultPath)
+{
+ mRoutingGraph.getShortestPath(source, destination, resultPath);
+}
+
+void CAmRouter::getShortestPath(std::vector<CAmNode<am_RoutingNodeData_s>*> & resultPath)
+{
+ getShortestPath(*mpRootSource, *mpRootSink, resultPath);
}
+
+void CAmRouter::getShortestPath(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink,
+ am_Route_s & resultPath, std::vector<CAmNode<am_RoutingNodeData_s>*> & resultNodesPath)
+{
+ am_RoutingElement_s * element;
+ am_RoutingNodeData_s & sinkNodeData = aSink.getData();
+ am_RoutingNodeData_s & sourceNodeData = aSource.getData();
+ resultPath.sinkID = sinkNodeData.data.sink->sinkID;
+ resultPath.sourceID = sourceNodeData.data.source->sourceID;
+
+ std::function<void(const am_GraphPathPosition_e, CAmNode<am_RoutingNodeData_s> &)> cb = [&](const am_GraphPathPosition_e, CAmNode<am_RoutingNodeData_s> & object)
+ {
+ resultNodesPath.insert(resultNodesPath.begin(), (CAmNode<am_RoutingNodeData_s>*)&object);
+ am_RoutingNodeData_s & routingData = object.getData();
+ if(routingData.type==am_RoutingNodeData_s::am_NodeDataType_e::SINK)
+ {
+ auto iter = resultPath.route.emplace(resultPath.route.begin());
+ element = &(*iter);
+ element->domainID = routingData.data.sink->domainID;
+ element->sinkID = routingData.data.sink->sinkID;
+ element->connectionFormat = CF_UNKNOWN;
+ }
+ else if(routingData.type==am_RoutingNodeData_s::am_NodeDataType_e::SOURCE)
+ {
+ element->domainID = routingData.data.source->domainID;
+ element->sourceID = routingData.data.source->sourceID;
+ element->connectionFormat = CF_UNKNOWN;
+ }
+ };
+ mRoutingGraph.getShortestPath(aSource, aSink, cb);
+}
+
+void CAmRouter::getShortestPath(am_Route_s & resultPath, std::vector<CAmNode<am_RoutingNodeData_s>*> & resultNodesPath)
+{
+ getShortestPath(*mpRootSource, *mpRootSink, resultPath, resultNodesPath);
+}
+
+am_Error_e CAmRouter::getAllPaths(CAmNode<am_RoutingNodeData_s> & aSource, CAmNode<am_RoutingNodeData_s> & aSink,
+ std::vector<am_Route_s> & resultPath, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath)
+{
+ uint8_t errorsCount = 0, successCount = 0;
+ mRoutingGraph.getAllPaths(aSource, aSink, [&](const std::vector<CAmNode<am_RoutingNodeData_s>*> & path) {
+ resultNodesPath.push_back(path);
+ resultPath.emplace_back();
+ am_Route_s & nextRoute = resultPath.back();
+ nextRoute.sinkID = aSink.getData().data.sink->sinkID;
+ nextRoute.sourceID = aSource.getData().data.source->sourceID;
+ am_RoutingElement_s * element;
+ for(auto it = path.begin(); it!=path.end(); it++)
+ {
+ am_RoutingNodeData_s & routingData = (*it)->getData();
+ if(routingData.type==am_RoutingNodeData_s::am_NodeDataType_e::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==am_RoutingNodeData_s::am_NodeDataType_e::SINK)
+ {
+ element->domainID = routingData.data.sink->domainID;
+ element->sinkID = routingData.data.sink->sinkID;
+ element->connectionFormat = CF_UNKNOWN;
+ }
+ }
+ am_Error_e err = determineConnectionFormatsForPath(nextRoute, (std::vector<CAmNode<am_RoutingNodeData_s>*> &)path);
+ if(err!=E_OK)
+ {
+ errorsCount++;
+ auto last = resultPath.end()-1;
+ resultPath.erase(last);
+#ifdef TRACE_GRAPH
+ std::cout<<"Error by determining connection formats for path from source:"<<nextRoute.sourceID<<" to sink:"<<nextRoute.sinkID<<"\n";
+#endif
+ }
+ else
+ {
+#ifdef TRACE_GRAPH
+ std::cout<<"Successfully determined connection formats for path from source:"<<nextRoute.sourceID<<" to sink:"<<nextRoute.sinkID<<"\n";
+#endif
+ successCount++;
+ }
+ });
+ if(successCount)
+ return E_OK;
+ if(errorsCount)
+ return E_NOT_POSSIBLE;
+ return E_OK;
+}
+
+am_Error_e CAmRouter::getAllPaths(std::vector<am_Route_s> & resultPath, std::vector<std::vector<CAmNode<am_RoutingNodeData_s>*>> & resultNodesPath)
+{
+ return getAllPaths(*mpRootSource, *mpRootSink, resultPath, resultNodesPath);
+}
+
+#endif
+
+void CAmRouter::clear()
+{
+ mNodeListSourceStatus.clear();
+ mNodeListSinkStatus.clear();
+ mNodeListConverterStatus.clear();
+ mNodeListGatewayStatus.clear();
+
+ mRoutingGraph.clear();
+ mNodeListSources.clear();
+ mNodeListSinks.clear();
+ mNodeListGateways.clear();
+ mNodeListConverters.clear();
+ mpRootSource=NULL;
+ mpRootSink=NULL;
+}
+
+
}
diff --git a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp
index eaa38e1..67bc911 100644
--- a/AudioManagerDaemon/src/CAmRoutingReceiver.cpp
+++ b/AudioManagerDaemon/src/CAmRoutingReceiver.cpp
@@ -238,11 +238,21 @@ am_Error_e CAmRoutingReceiver::registerGateway(const am_Gateway_s & gatewayData,
return (mpControlSender->hookSystemRegisterGateway(gatewayData, gatewayID));
}
+am_Error_e CAmRoutingReceiver::registerConverter(const am_Converter_s& converterData, am_converterID_t& converterID)
+{
+ return (mpControlSender->hookSystemRegisterConverter(converterData, converterID));
+}
+
am_Error_e CAmRoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
{
return (mpControlSender->hookSystemDeregisterGateway(gatewayID));
}
+am_Error_e CAmRoutingReceiver::deregisterConverter(const am_converterID_t converterID)
+{
+ return (mpControlSender->hookSystemDeregisterConverter(converterID));
+}
+
am_Error_e CAmRoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
{
return (mpDatabaseHandler->peekSink(name, sinkID));
@@ -418,6 +428,11 @@ am_Error_e CAmRoutingReceiver::updateGateway(const am_gatewayID_t gatewayID, con
return (mpControlSender->hookSystemUpdateGateway(gatewayID,listSourceFormats,listSinkFormats,convertionMatrix));
}
+am_Error_e CAmRoutingReceiver::updateConverter(const am_converterID_t converterID, const std::vector<am_CustomConnectionFormat_t>& listSourceFormats, const std::vector<am_CustomConnectionFormat_t>& listSinkFormats, const std::vector<bool>& convertionMatrix)
+{
+ return (mpControlSender->hookSystemUpdateConverter(converterID,listSourceFormats,listSinkFormats,convertionMatrix));
+}
+
am_Error_e CAmRoutingReceiver::updateSink(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomConnectionFormat_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties)
{
return (mpControlSender->hookSystemUpdateSink(sinkID,sinkClassID,listSoundProperties,listConnectionFormats,listMainSoundProperties));
diff --git a/AudioManagerDaemon/src/CAmRoutingSender.cpp b/AudioManagerDaemon/src/CAmRoutingSender.cpp
index 1606761..cd9c3d7 100644
--- a/AudioManagerDaemon/src/CAmRoutingSender.cpp
+++ b/AudioManagerDaemon/src/CAmRoutingSender.cpp
@@ -525,7 +525,11 @@ am_Error_e CAmRoutingSender::removeCrossfaderLookup(const am_crossfaderID_t cros
am_Error_e CAmRoutingSender::removeHandle(const am_Handle_s& handle)
{
if (mlistActiveHandles.erase(handle))
+ {
+ logInfo(__PRETTY_FUNCTION__,handle.handle,handle.handleType);
return (E_OK);
+ }
+ logError(__PRETTY_FUNCTION__,"Could not remove handle",handle.handle);
return (E_UNKNOWN);
}
@@ -556,6 +560,7 @@ am_Handle_s CAmRoutingSender::createHandle(const am_handleData_c& handleData, co
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());
+ logInfo(__PRETTY_FUNCTION__,handle.handle, handle.handleType);
return (handle);
}
@@ -570,9 +575,18 @@ CAmRoutingSender::am_handleData_c CAmRoutingSender::returnHandleData(const am_Ha
HandlesMap::const_iterator it = mlistActiveHandles.begin();
it = mlistActiveHandles.find(handle);
if (it!=mlistActiveHandles.end())
- return (it->second);
+ {
+ const am_handleData_c & result = it->second;
+ logInfo(__PRETTY_FUNCTION__, handle.handle, handle.handleType,
+ "connectionID", result.connectionID,
+ "sinkID", result.sinkID,
+ "sourceID",result.sourceID,
+ "sourceState", result.sourceState);
+ return result;
+ }
am_handleData_c handleData;
handleData.sinkID=0;
+ logError(__PRETTY_FUNCTION__,"could not find handle data for handle",handle.handle,handle.handleType);
return (handleData);
}
diff --git a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp
index 1881955..7f0d87d 100644
--- a/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp
+++ b/AudioManagerDaemon/test/AmDatabaseHandlerTest/CAmDatabaseHandlerTest.cpp
@@ -1485,8 +1485,6 @@ TEST_F(CAmDatabaseHandlerTest,getListSinksOfDomain)
TEST_F(CAmDatabaseHandlerTest,getListGatewaysOfDomain)
{
-
-
am_Gateway_s gateway, gateway2;
am_gatewayID_t gatewayID;
am_domainID_t domainID;
@@ -1532,6 +1530,51 @@ TEST_F(CAmDatabaseHandlerTest,getListGatewaysOfDomain)
ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty());
}
+TEST_F(CAmDatabaseHandlerTest,getListConvertersOfDomain)
+{
+ am_Converter_s gateway, gateway2;
+ am_converterID_t gatewayID;
+ am_domainID_t domainID;
+ am_Domain_s domain;
+ std::vector<am_converterID_t> gatewayList, gatewayCheckList;
+ pCF.createConverter(gateway);
+ gateway.converterID = 1;
+ gateway.name = "testGateway";
+ gateway.sourceID = 1;
+ gateway.sinkID = 1;
+ gateway.domainID = 1;
+ pCF.createConverter(gateway2);
+ gateway2.converterID = 2;
+ gateway2.name = "testGateway2";
+ gateway2.sourceID = 1;
+ gateway2.sinkID = 1;
+ gateway2.domainID = 1;
+ pCF.createDomain(domain);
+ gatewayCheckList.push_back(gateway.converterID);
+ gatewayCheckList.push_back(gateway2.converterID);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 1;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(2,gatewayList))
+ << "ERROR: database error";ASSERT_TRUE(gatewayList.empty());
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(1,gatewayList))
+ << "ERROR: database error";
+ ASSERT_TRUE(!gatewayList.empty());
+ ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()));
+}
+
TEST_F(CAmDatabaseHandlerTest,removeDomain)
{
am_Domain_s domain;
@@ -1574,6 +1617,31 @@ TEST_F(CAmDatabaseHandlerTest,removeGateway)
ASSERT_TRUE(listGateways.empty());
}
+TEST_F(CAmDatabaseHandlerTest,removeConverter)
+{
+ am_Converter_s gateway;
+ am_converterID_t gatewayID;
+ std::vector<am_Converter_s> listGateways;
+ pCF.createConverter(gateway);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(listGateways))
+ << "ERROR: database error";
+ ASSERT_TRUE(listGateways.empty());
+}
+
TEST_F(CAmDatabaseHandlerTest,removeSink)
{
am_Sink_s sink;
@@ -1641,10 +1709,14 @@ TEST_F(CAmDatabaseHandlerTest,removeNonexistentGateway)
<< "ERROR: database error";
}
-TEST_F(CAmDatabaseHandlerTest,registerGatewayCorrect)
+TEST_F(CAmDatabaseHandlerTest,removeNonexistentConverter)
{
+ ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(12))
+ << "ERROR: database error";
+}
-
+TEST_F(CAmDatabaseHandlerTest,registerGatewayCorrect)
+{
//initialize gateway
std::vector<am_Gateway_s> returnList;
am_Gateway_s gateway, gateway1, gateway2;
@@ -1705,10 +1777,70 @@ TEST_F(CAmDatabaseHandlerTest,registerGatewayCorrect)
ASSERT_EQ(true, equal);
}
-TEST_F(CAmDatabaseHandlerTest,getGatewayInfo)
+TEST_F(CAmDatabaseHandlerTest,registerConverterCorrect)
{
+ //initialize gateway
+ std::vector<am_Converter_s> returnList;
+ am_Converter_s gateway, gateway1, gateway2;
+ am_converterID_t converterID = 0, converterID1 = 0, converterID2 = 0;
+
+ pCF.createConverter(gateway);
+ pCF.createConverter(gateway1);
+ gateway1.converterID = 20;
+ pCF.createConverter(gateway2);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,converterID))
+ << "ERROR: database error";
+ ASSERT_EQ(100,converterID)
+ << "ERROR: domainID zero";
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,converterID1))
+ << "ERROR: database error";
+ ASSERT_EQ(gateway1.converterID,converterID1)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,converterID2))
+ << "ERROR: database error";
+ ASSERT_EQ(101,converterID2)
+ << "ERROR: domainID zero";
+ //now check if we read out the correct values
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList));
+ bool equal = true;
+ std::vector<am_Converter_s>::iterator listIterator = returnList.begin();
+
+ for (; listIterator < returnList.end(); ++listIterator)
+ {
+ if (listIterator->converterID == converterID)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway);
+ }
+
+ if (listIterator->converterID == converterID1)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway1);
+ }
+
+ if (listIterator->converterID == converterID2)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway2);
+ }
+ }
+
+ ASSERT_EQ(true, equal);
+}
+
+TEST_F(CAmDatabaseHandlerTest,getGatewayInfo)
+{
//initialize gateway
std::vector<am_Gateway_s> returnList;
am_Gateway_s gateway, gateway1, gateway2;
@@ -1774,6 +1906,73 @@ TEST_F(CAmDatabaseHandlerTest,getGatewayInfo)
}
+TEST_F(CAmDatabaseHandlerTest,getConverterInfo)
+{
+ //initialize gateway
+ std::vector<am_Converter_s> returnList;
+ am_Converter_s gateway, gateway1, gateway2;
+ am_converterID_t converterID = 0, converterID1 = 0, converterID2 = 0;
+
+ pCF.createConverter(gateway);
+ pCF.createConverter(gateway1);
+ gateway1.converterID = 20;
+ pCF.createConverter(gateway2);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,converterID))
+ << "ERROR: database error";
+ ASSERT_EQ(100,converterID)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,converterID1))
+ << "ERROR: database error";
+ ASSERT_EQ(gateway1.converterID,converterID1)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,converterID2))
+ << "ERROR: database error";
+ ASSERT_EQ(101,converterID2)
+ << "ERROR: domainID zero";
+
+ //now check if we read out the correct values
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList));
+ bool equal = true;
+ std::vector<am_Converter_s>::iterator listIterator = returnList.begin();
+
+ for (; listIterator < returnList.end(); ++listIterator)
+ {
+ if (listIterator->converterID == converterID)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway);
+ }
+
+ if (listIterator->converterID == converterID1)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway1);
+ }
+
+ if (listIterator->converterID == converterID2)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway2);
+ }
+ }
+
+ ASSERT_EQ(true, equal);
+
+ am_Converter_s gatewayInfo;
+ ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo));
+ ASSERT_TRUE(pCF.compareConverter1(gateway1,gatewayInfo));
+
+}
+
TEST_F(CAmDatabaseHandlerTest,enterSinkThatAlreadyExistFail)
{
//fill the connection database
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
index 29dc8ce..13de48b 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmMapHandlerTest.cpp
@@ -1547,6 +1547,58 @@ TEST_F(CAmMapHandlerTest,getListGatewaysOfDomain)
ASSERT_TRUE(std::equal(gatewayList.begin(),gatewayList.end(),gatewayCheckList.begin()) && !gatewayList.empty());
}
+TEST_F(CAmMapHandlerTest,getListConvertersOfDomain)
+{
+ am_Converter_s converter, converter2;
+ am_converterID_t converterID1, converterID2;
+ am_domainID_t domainID;
+ am_Domain_s domain;
+ std::vector<am_converterID_t> converterList, converterCheckList;
+
+ pCF.createDomain(domain);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain,domainID));
+
+ pCF.createConverter(converter);
+ converter.converterID = 1;
+ converter.name = "testGateway";
+ converter.sourceID = 1;
+ converter.sinkID = 1;
+ converter.domainID = domainID;
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID1))
+ << "ERROR: database error";
+ ASSERT_EQ(true, converterID1==1);
+
+ pCF.createConverter(converter2);
+ converter2.converterID = 2;
+ converter2.name = "testGateway2";
+ converter2.domainID = 4;
+ converter2.sourceID = 1;
+ converter2.sinkID = 1;
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter2,converterID2))
+ << "ERROR: database error";
+ ASSERT_EQ(true, converterID2==2);
+ converterCheckList.push_back(converterID1);
+
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ sink.sinkID = sinkID;
+
+ pCF.createSource(source);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ source.sourceID = sourceID;
+
+ ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.getListConvertersOfDomain(4,converterList))
+ << "ERROR: database error";
+ ASSERT_TRUE(converterList.empty());
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConvertersOfDomain(domainID,converterList))
+ << "ERROR: database error";
+ ASSERT_TRUE(std::equal(converterList.begin(),converterList.end(),converterCheckList.begin()) && !converterList.empty());
+}
+
TEST_F(CAmMapHandlerTest,removeDomain)
{
am_Domain_s domain;
@@ -1564,8 +1616,6 @@ TEST_F(CAmMapHandlerTest,removeDomain)
TEST_F(CAmMapHandlerTest,removeGateway)
{
-
-
am_Gateway_s gateway;
am_gatewayID_t gatewayID;
std::vector<am_Gateway_s> listGateways;
@@ -1589,6 +1639,31 @@ TEST_F(CAmMapHandlerTest,removeGateway)
ASSERT_TRUE(listGateways.empty());
}
+TEST_F(CAmMapHandlerTest,removeConverter)
+{
+ am_Converter_s converter;
+ am_converterID_t converterID;
+ std::vector<am_Converter_s> listConverters;
+ pCF.createConverter(converter);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(converter,converterID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(converterID))
+ << "ERROR: database error";
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConverters(listConverters))
+ << "ERROR: database error";
+ ASSERT_TRUE(listConverters.empty());
+}
+
TEST_F(CAmMapHandlerTest,removeSink)
{
am_Sink_s sink;
@@ -1656,10 +1731,14 @@ TEST_F(CAmMapHandlerTest,removeNonexistentGateway)
<< "ERROR: database error";
}
-TEST_F(CAmMapHandlerTest,registerGatewayCorrect)
+TEST_F(CAmMapHandlerTest,removeNonexistentConverter)
{
+ ASSERT_EQ(E_NON_EXISTENT,pDatabaseHandler.removeConverterDB(12))
+ << "ERROR: database error";
+}
-
+TEST_F(CAmMapHandlerTest,registerGatewayCorrect)
+{
//initialize gateway
std::vector<am_Gateway_s> returnList;
am_Gateway_s gateway, gateway1, gateway2;
@@ -1720,6 +1799,68 @@ TEST_F(CAmMapHandlerTest,registerGatewayCorrect)
ASSERT_EQ(true, equal);
}
+TEST_F(CAmMapHandlerTest,registerConverterCorrect)
+{
+ //initialize gateway
+ std::vector<am_Converter_s> returnList;
+ am_Converter_s gateway, gateway1, gateway2;
+ am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
+
+ pCF.createConverter(gateway);
+ pCF.createConverter(gateway1);
+ gateway1.converterID = 20;
+ pCF.createConverter(gateway2);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(100,gatewayID)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))
+ << "ERROR: database error";
+ ASSERT_EQ(gateway1.converterID,gatewayID1)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))
+ << "ERROR: database error";
+ ASSERT_EQ(101,gatewayID2)
+ << "ERROR: domainID zero";
+
+ //now check if we read out the correct values
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList));
+ bool equal = true;
+ std::vector<am_Converter_s>::iterator listIterator = returnList.begin();
+
+ for (; listIterator < returnList.end(); ++listIterator)
+ {
+ if (listIterator->converterID == gatewayID)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway);
+ }
+
+ if (listIterator->converterID == gatewayID1)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway1);
+ }
+
+ if (listIterator->converterID == gatewayID2)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway2);
+ }
+ }
+
+ ASSERT_EQ(true, equal);
+}
+
TEST_F(CAmMapHandlerTest,getGatewayInfo)
{
@@ -1789,6 +1930,73 @@ TEST_F(CAmMapHandlerTest,getGatewayInfo)
}
+TEST_F(CAmMapHandlerTest,getConverterInfo)
+{
+ //initialize gateway
+ std::vector<am_Converter_s> returnList;
+ am_Converter_s gateway, gateway1, gateway2;
+ am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
+
+ pCF.createConverter(gateway);
+ pCF.createConverter(gateway1);
+ gateway1.converterID = 20;
+ pCF.createConverter(gateway2);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))
+ << "ERROR: database error";
+ ASSERT_EQ(100,gatewayID)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))
+ << "ERROR: database error";
+ ASSERT_EQ(gateway1.converterID,gatewayID1)
+ << "ERROR: domainID zero";
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))
+ << "ERROR: database error";
+ ASSERT_EQ(101,gatewayID2)
+ << "ERROR: domainID zero";
+
+ //now check if we read out the correct values
+ ASSERT_EQ(E_OK, pDatabaseHandler.getListConverters(returnList));
+ bool equal = true;
+ std::vector<am_Converter_s>::iterator listIterator = returnList.begin();
+
+ for (; listIterator < returnList.end(); ++listIterator)
+ {
+ if (listIterator->converterID == gatewayID)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway);
+ }
+
+ if (listIterator->converterID == gatewayID1)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway1);
+ }
+
+ if (listIterator->converterID == gatewayID2)
+ {
+ equal = equal && pCF.compareConverter(listIterator, gateway2);
+ }
+ }
+
+ ASSERT_EQ(true, equal);
+
+ am_Converter_s gatewayInfo;
+ ASSERT_EQ(E_OK, pDatabaseHandler.getConverterInfoDB(20,gatewayInfo));
+ ASSERT_TRUE(pCF.compareConverter1(gateway1,gatewayInfo));
+
+}
+
TEST_F(CAmMapHandlerTest,enterSinkThatAlreadyExistFail)
{
//fill the connection database
@@ -2665,6 +2873,41 @@ TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeGateway)
ASSERT_EQ(E_OK,pDatabaseHandler.removeGatewayDB(gatewayID2))<< "ERROR: database error";
}
+TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeConverter)
+{
+ //initialize gateway
+ std::vector<am_Converter_s> returnList;
+ am_Converter_s gateway, gateway1, gateway2;
+ am_converterID_t gatewayID = 0, gatewayID1 = 0, gatewayID2 = 0;
+ pCF.createConverter(gateway);
+ pCF.createConverter(gateway1);
+ gateway1.converterID = 20;
+ pCF.createConverter(gateway2);
+ am_Sink_s sink;
+ am_Source_s source;
+ am_sinkID_t sinkID;
+ am_sourceID_t sourceID;
+ pCF.createSink(sink);
+ pCF.createSource(source);
+ sink.sinkID = 1;
+ source.sourceID = 2;
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSink(_)).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newSource(_)).Times(1);
+ ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 100))).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway,gatewayID))<< "ERROR: database error";
+ ASSERT_EQ(100,gatewayID)<< "ERROR: domainID zero";
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 20))).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway1,gatewayID1))<< "ERROR: database error";
+ ASSERT_EQ(gateway1.converterID,gatewayID1)<< "ERROR: domainID zero";
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), newConverter(Field(&am_Converter_s::converterID, 101))).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConverterDB(gateway2,gatewayID2))<< "ERROR: database error";
+ ASSERT_EQ(101,gatewayID2)<< "ERROR: domainID zero";
+ EXPECT_CALL(*MockDatabaseObserver::getMockObserverObject(), removeConverter(gatewayID2)).Times(1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.removeConverterDB(gatewayID2))<< "ERROR: database error";
+}
+
TEST_F(CAmMapHandlerObserverCallbacksTest, enter_removeCrossfader)
{
am_Crossfader_s crossfader;
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp b/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp
index 87942c5..fecf214 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/CAmTestDatabaseObserver.cpp
@@ -46,6 +46,8 @@ 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)
@@ -60,6 +62,8 @@ 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)
diff --git a/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h b/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h
index 52f2599..34de3cd 100644
--- a/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h
+++ b/AudioManagerDaemon/test/AmMapHandlerTest/MockDatabaseObserver.h
@@ -47,6 +47,7 @@ public:
virtual void newSource(const am_Source_s& source) = 0;
virtual void newDomain(const am_Domain_s& domain) = 0;
virtual void newGateway(const am_Gateway_s& gateway) = 0;
+ virtual void newConverter(const am_Converter_s& coverter) = 0;
virtual void newCrossfader(const am_Crossfader_s& crossfader) = 0;
virtual void newMainConnection(const am_MainConnectionType_s& mainConnection) = 0;
virtual void removedMainConnection(const am_mainConnectionID_t mainConnection) = 0;
@@ -54,6 +55,7 @@ public:
virtual void removedSource(const am_sourceID_t sourceID, const bool visible) = 0;
virtual void removeDomain(const am_domainID_t domainID) = 0;
virtual void removeGateway(const am_gatewayID_t gatewayID) = 0;
+ virtual void removeConverter(const am_converterID_t converterID) = 0;
virtual void removeCrossfader(const am_crossfaderID_t crossfaderID) = 0;
virtual void mainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState) = 0;
virtual void mainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty) = 0;
@@ -79,6 +81,7 @@ class MockDatabaseObserver : public IAmDatabaseObserver{
MOCK_METHOD1(newSource, void(const am_Source_s& source));
MOCK_METHOD1(newDomain, void(const am_Domain_s& domain));
MOCK_METHOD1(newGateway, void(const am_Gateway_s& gateway));
+ MOCK_METHOD1(newConverter, void(const am_Converter_s& converter));
MOCK_METHOD1(newCrossfader, void(const am_Crossfader_s& crossfader));
MOCK_METHOD1(newMainConnection, void(const am_MainConnectionType_s & mainConnection));
MOCK_METHOD1(removedMainConnection, void(const am_mainConnectionID_t mainConnection));
@@ -86,6 +89,7 @@ class MockDatabaseObserver : public IAmDatabaseObserver{
MOCK_METHOD2(removedSource, void(const am_sourceID_t sourceID, const bool visible));
MOCK_METHOD1(removeDomain, void(const am_domainID_t domainID));
MOCK_METHOD1(removeGateway, void(const am_gatewayID_t gatewayID));
+ MOCK_METHOD1(removeConverter, void(const am_converterID_t converterID));
MOCK_METHOD1(removeCrossfader, void(const am_crossfaderID_t crossfaderID));
MOCK_METHOD2(mainConnectionStateChanged, void(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState));
MOCK_METHOD2(mainSinkSoundPropertyChanged, void(const am_sinkID_t sinkID, const am_MainSoundProperty_s& SoundProperty));
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp
index 2ea9639..a6680e5 100644
--- a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp
+++ b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.cpp
@@ -12,7 +12,7 @@
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
- * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
+ * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014
*
* For further information see http://www.genivi.org/.
*
@@ -22,6 +22,7 @@
#include <string.h>
#include "shared/CAmDltWrapper.h"
+
using namespace am;
using namespace testing;
@@ -65,6 +66,85 @@ ACTION(returnConnectionFormat){
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));
+}
+
+void CAmRouterMapTest::enterSourceDB(const std::string & sourceName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & 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));
+}
+
+void CAmRouterMapTest::enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & 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));
+}
+
+void CAmRouterMapTest::enterGatewayDB(const std::string & gwName,
+ const am_domainID_t domainSourceID,
+ const am_domainID_t domainSinkID,
+ const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats,
+ const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats,
+ const std::vector<bool> & 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));
+}
+
+void CAmRouterMapTest::enterConverterDB(const std::string & gwName,
+ const am_domainID_t domainID,
+ const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats,
+ const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats,
+ const std::vector<bool> & 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));
+}
+
//test that checks just sinks and source in a domain but connectionformats do not match
TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats)
{
@@ -121,9 +201,13 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomainNoMatchFormats)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
-
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(true, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
}
//test that checks just sinks and source in a domain
@@ -182,17 +266,19 @@ TEST_F(CAmRouterMapTest,simpleRoute2withDomain)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
-
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(true, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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
TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree)
{
-
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -290,17 +376,20 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFree)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+
ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
ASSERT_EQ(static_cast<uint>(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
TEST_F(CAmRouterMapTest,simpleRoute2DomainsOnlyFreeNotFree)
{
-
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -412,18 +501,23 @@ TEST_F(CAmRouterMapTest,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(static_cast<uint>(0), listRoutes.size());
-
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(true, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
}
//test that checks just 2 domains, with gateway for each direction (possible circular route)
TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree)
{
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -549,15 +643,19 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsCircularGWOnlyFree)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(true, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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_2)
{
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -709,9 +807,13 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_2)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
}
//test that checks 3 domains, one sink one source, longer lists of connectionformats.
@@ -863,9 +965,13 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats_1)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
}
@@ -1012,9 +1118,13 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsListConnectionFormats)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
}
@@ -1246,23 +1356,27 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains2Routes)
compareRoute1.sinkID = sinkID;
compareRoute1.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(2), listRoutes.size());
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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);
+ 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);
}
//test that checks 3 domains, one sink one source but the connectionformat of third domains do not fit.
TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection)
{
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -1400,14 +1514,17 @@ TEST_F(CAmRouterMapTest,simpleRoute3DomainsNoConnection)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
}
//test that checks just 2 domains, one sink one source with only one connection format each
TEST_F(CAmRouterMapTest,simpleRoute2Domains)
{
-
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -1505,17 +1622,18 @@ TEST_F(CAmRouterMapTest,simpleRoute2Domains)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
-
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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
TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats)
{
-
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -1591,31 +1709,14 @@ TEST_F(CAmRouterMapTest,simpleRoute2DomainsNoMatchConnectionFormats)
ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID));
std::vector<am_Route_s> listRoutes;
- std::vector<am_RoutingElement_s> listRoutingElements;
- am_RoutingElement_s hopp1;
- am_RoutingElement_s hopp2;
-
- hopp1.sinkID = gwSinkID;
- hopp1.sourceID = sourceID;
- hopp1.domainID = domainID1;
- hopp1.connectionFormat = source.listConnectionFormats[0];
-
- hopp2.sinkID = sinkID;
- hopp2.sourceID = gwSourceID;
- hopp2.domainID = domainID2;
- hopp2.connectionFormat = sink.listConnectionFormats[0];
-
- listRoutingElements.push_back(hopp1);
- listRoutingElements.push_back(hopp2);
- am_Route_s compareRoute;
- compareRoute.route = listRoutingElements;
- compareRoute.sinkID = sinkID;
- compareRoute.sourceID = sourceID;
-
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
-}
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+ }
//test that checks 3 domains, one sink one source.
TEST_F(CAmRouterMapTest,simpleRoute3Domains)
@@ -1757,9 +1858,14 @@ TEST_F(CAmRouterMapTest,simpleRoute3Domains)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
}
//test that checks 4 domains, one sink and one source.
@@ -1942,10 +2048,860 @@ TEST_F(CAmRouterMapTest,simpleRoute4Domains)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
- ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes));
- size_t size(1);
- ASSERT_EQ(size, listRoutes.size());
- ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+ am::am_Source_s sourceDb;
+ am::am_Sink_s sinkDb;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sinkDb);
+ pDatabaseHandler.getSourceInfoDB(sourceID, sourceDb);
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, sourceDb, sinkDb, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+TEST_F(CAmRouterMapTest,getAllowedFormatsFromConvMatrix)
+{
+ std::vector<bool> 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<am_CustomConnectionFormat_t> listSourceFormats;
+ listSourceFormats.push_back(CF_GENIVI_ANALOG);
+ listSourceFormats.push_back(CF_GENIVI_STEREO);
+
+ std::vector<am_CustomConnectionFormat_t> listSinkFormats;
+ listSinkFormats.push_back(CF_GENIVI_MONO);
+ listSinkFormats.push_back(CF_GENIVI_AUTO);
+ listSinkFormats.push_back(CF_GENIVI_STEREO);
+
+ std::vector<am_CustomConnectionFormat_t> sourceFormats;
+ std::vector<am_CustomConnectionFormat_t> 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)));
+
+ am_domainID_t domainID1;
+ enterDomainDB("domain1", domainID1);
+
+ am_sourceID_t sourceID;
+ std::vector<am_CustomConnectionFormat_t> cf1;
+ cf1.push_back(CF_GENIVI_STEREO);
+ cf1.push_back(CF_GENIVI_ANALOG);
+ enterSourceDB("source1", domainID1, cf1, sourceID);
+
+ am_sinkID_t sinkID;
+ std::vector<am_CustomConnectionFormat_t> cf2;
+ cf2.push_back(CF_GENIVI_ANALOG);
+ cf2.push_back(CF_GENIVI_MONO);
+ enterSinkDB("sink1", domainID1, cf2, sinkID);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+ std::vector<am_RoutingElement_s> listRoutingElements;
+ am_RoutingElement_s hopp1;
+
+ hopp1.sourceID = sourceID;
+ hopp1.sinkID = sinkID;
+ hopp1.domainID = domainID1;
+ hopp1.connectionFormat = cf2[0];
+
+ listRoutingElements.push_back(hopp1);
+
+ am_Route_s compareRoute;
+ compareRoute.route = listRoutingElements;
+ compareRoute.sinkID = sinkID;
+ compareRoute.sourceID = sourceID;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+TEST_F(CAmRouterMapTest,route1Domain1Source1Converter1Sink)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ am_domainID_t domainID1;
+ enterDomainDB("domain1", domainID1);
+
+ am_sourceID_t sourceID;
+ std::vector<am_CustomConnectionFormat_t> cf1;
+ cf1.push_back(CF_GENIVI_STEREO);
+ cf1.push_back(CF_GENIVI_AUTO);
+ enterSourceDB("source1", domainID1, cf1, sourceID);
+
+ am_sinkID_t sinkID1, sinkID2;
+ std::vector<am_CustomConnectionFormat_t> cf2;
+ cf2.push_back(CF_GENIVI_MONO);
+ cf2.push_back(CF_GENIVI_ANALOG);
+ enterSinkDB("sink1", domainID1, cf2, sinkID1);
+ enterSinkDB("sink2", domainID1, cf2, sinkID2);
+
+ am_sourceID_t gwSourceID;
+ std::vector<am_CustomConnectionFormat_t> cf3;
+ cf3.push_back(CF_GENIVI_MONO);
+ cf3.push_back(CF_GENIVI_ANALOG);
+ enterSourceDB("gwSource1", domainID1, cf3, gwSourceID);
+
+ am_sinkID_t gwSinkID;
+ std::vector<am_CustomConnectionFormat_t> cf4;
+ cf4.push_back(CF_GENIVI_STEREO);
+ cf4.push_back(CF_GENIVI_ANALOG);
+ enterSinkDB("gwSink1", domainID1, cf4, gwSinkID);
+
+ am_converterID_t converterID;
+ std::vector<bool> matrix;
+ matrix.resize(4, false);
+ matrix[0]=(true);
+ matrix[1]=(true);
+ enterConverterDB("converter", domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, converterID);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID1, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+ std::vector<am_RoutingElement_s> 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(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
+}
+
+TEST_F(CAmRouterMapTest,route1Domain1Source3Converters1Sink)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ am_domainID_t domainID1;
+ enterDomainDB("domain1", domainID1);
+
+ std::vector<am_CustomConnectionFormat_t> cf1;
+ cf1.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cf2;
+ cf2.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> cf3;
+ cf3.push_back(CF_GENIVI_AUTO);
+
+ am_sourceID_t sourceID;
+ enterSourceDB("source1", domainID1, cf1, sourceID);
+
+ 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_converterID_t converterID;
+ std::vector<bool> 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_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_converterID_t converterID2;
+ enterConverterDB("converter3", domainID1, cf3, cf2, matrix, gwSourceID2, gwSinkID2, converterID2);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+
+ std::vector<am_Route_s> listRoutes;
+ std::vector<am_RoutingElement_s> listRoutingElements1;
+ std::vector<am_RoutingElement_s> 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(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(2), listRoutes.size());
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
+
+ am_Route_s compareRoute2;
+ compareRoute2.route = listRoutingElements2;
+ compareRoute2.sinkID = sinkID;
+ compareRoute2.sourceID = sourceID;
+ ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1]));
+}
+
+TEST_F(CAmRouterMapTest,route2Domains1Source1Sink)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ am_domainID_t domainID1, domainID2;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+
+ am_sourceID_t sourceID;
+ std::vector<am_CustomConnectionFormat_t> cf1;
+ cf1.push_back(CF_GENIVI_STEREO);
+ enterSourceDB("source1", domainID1, cf1, sourceID);
+
+ am_sinkID_t sinkID;
+ std::vector<am_CustomConnectionFormat_t> cf2;
+ cf2.push_back(CF_GENIVI_ANALOG);
+ enterSinkDB("sink1", domainID2, cf2, sinkID);
+
+ am_sourceID_t gwSourceID;
+ std::vector<am_CustomConnectionFormat_t> cf3;
+ cf3.push_back(CF_GENIVI_ANALOG);
+ enterSourceDB("gwSource1", domainID2, cf3, gwSourceID);
+
+ am_sinkID_t gwSinkID;
+ std::vector<am_CustomConnectionFormat_t> cf4;
+ cf4.push_back(CF_GENIVI_STEREO);
+ enterSinkDB("gwSink1", domainID1, cf4, gwSinkID);
+
+ am_gatewayID_t gatewayID;
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ enterGatewayDB("gateway", domainID2, domainID1, cf3, cf4, matrix, gwSourceID, gwSinkID, gatewayID);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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]));
+}
+
+TEST_F(CAmRouterMapTest,route3Domains1Source1Sink)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ am_domainID_t domainID1, domainID2, domainID3;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+ enterDomainDB("domain3", domainID3);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+
+ am_sourceID_t sourceID;
+ enterSourceDB("source1", domainID1, cfStereo, sourceID);
+
+ am_sinkID_t gwSinkID1;
+ enterSinkDB("gwSink1", domainID1, cfStereo, gwSinkID1);
+
+ am_sourceID_t gwSourceID1;
+ enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1);
+
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+
+ am_gatewayID_t gatewayID;
+ enterGatewayDB("gateway", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID);
+
+ am_sourceID_t gwSourceID2;
+ enterSourceDB("gwSource2", domainID3, cfStereo, gwSourceID2);
+
+ am_sinkID_t gwSinkID2;
+ enterSinkDB("gwSink2", domainID2, cfMono, gwSinkID2);
+
+ am_sinkID_t sinkID;
+ enterSinkDB("sink1", domainID3, cfStereo, sinkID);
+
+ am_gatewayID_t gatewayID1;
+ enterGatewayDB("gateway", domainID3, domainID2, cfStereo, cfMono, matrix, gwSourceID2, gwSinkID2, gatewayID1);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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]));
+}
+
+TEST_F(CAmRouterMapTest,route3Domains1Source3Gateways3Convertres1Sink)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ am_domainID_t domainID1, domainID2, domainID3;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+ enterDomainDB("domain3", domainID3);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> 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_sourceID_t gwSourceID1;
+ enterSourceDB("gwSource1", domainID2, cfMono, gwSourceID1);
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ am_gatewayID_t gatewayID;
+ enterGatewayDB("gateway1", domainID2, domainID1, cfMono, cfStereo, matrix, gwSourceID1, gwSinkID1, gatewayID);
+
+
+ am_sourceID_t gwSourceID21;
+ enterSourceDB("gwSource21", domainID3, cfAuto, gwSourceID21);
+ am_sinkID_t gwSinkID21;
+ enterSinkDB("gwSink21", domainID1, cfMono, gwSinkID21);
+ am_gatewayID_t gatewayID21;
+ enterGatewayDB("gateway21", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID21, gwSinkID21, gatewayID21);
+
+ am_sourceID_t gwSourceID22;
+ enterSourceDB("gwSource22", domainID3, cfAuto, gwSourceID22);
+ am_sinkID_t gwSinkID22;
+ enterSinkDB("gwSink22", domainID2, cfMono, gwSinkID22);
+ am_gatewayID_t gatewayID22;
+ enterGatewayDB("gateway22", domainID3, domainID2, cfAuto, cfMono, matrix, gwSourceID22, gwSinkID22, gatewayID22);
+
+ am_sourceID_t gwSourceID3;
+ enterSourceDB("gwSource3", domainID3, cfAnalog, gwSourceID3);
+ am_sinkID_t gwSinkID3;
+ enterSinkDB("gwSink3", domainID3, cfAuto, gwSinkID3);
+ am_converterID_t converterID1;
+ enterConverterDB("converter1", domainID3, cfAnalog, cfAuto, matrix, gwSourceID3, gwSinkID3, converterID1);
+
+ am_sourceID_t gwSourceID4;
+ enterSourceDB("gwSource4", domainID3, cfStereo, gwSourceID4);
+ am_sinkID_t gwSinkID4;
+ enterSinkDB("gwSink4", domainID3, cfAnalog, gwSinkID4);
+ am_converterID_t converterID2;
+ enterConverterDB("converter2", domainID3, cfStereo, cfAnalog, matrix, gwSourceID4, gwSinkID4, converterID2);
+
+ am_sourceID_t gwSourceID5;
+ enterSourceDB("gwSource5", domainID3, cfStereo, gwSourceID5);
+ am_sinkID_t gwSinkID5;
+ enterSinkDB("gwSink5", domainID3, cfAnalog, gwSinkID5);
+ am_converterID_t converterID3;
+ enterConverterDB("converter3", domainID3, cfStereo, cfAnalog, matrix, gwSourceID5, gwSinkID5, converterID3);
+
+ am_sinkID_t sinkID;
+ enterSinkDB("sink1", domainID3, cfStereo, sinkID);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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, gwSinkID21, domainID1, CF_GENIVI_MONO});
+ compareRoute1.route.push_back({gwSourceID21, 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});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
+
+ 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, gwSinkID21, domainID1, CF_GENIVI_MONO});
+ compareRoute2.route.push_back({gwSourceID21, 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});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute2,listRoutes[1]));
+
+
+ am_Route_s compareRoute3;
+ compareRoute3.sinkID = sinkID;
+ compareRoute3.sourceID = sourceID;
+ compareRoute3.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO});
+ compareRoute3.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO});
+ compareRoute3.route.push_back({gwSourceID22, 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});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute3,listRoutes[2]));
+
+ am_Route_s compareRoute4;
+ compareRoute4.sinkID = sinkID;
+ compareRoute4.sourceID = sourceID;
+ compareRoute4.route.push_back({sourceID, gwSinkID1, domainID1, CF_GENIVI_STEREO});
+ compareRoute4.route.push_back({gwSourceID1, gwSinkID22, domainID2, CF_GENIVI_MONO});
+ compareRoute4.route.push_back({gwSourceID22, 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});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute4,listRoutes[3]));
+}
+
+TEST_F(CAmRouterMapTest,routeSource1Sink2PathThroughConv1Gate1)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ am_domainID_t domainID1, domainID2;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> cfAuto;
+ cfAuto.push_back(CF_GENIVI_AUTO);
+
+ am_sourceID_t sourceID;
+ enterSourceDB("source1", domainID1, cfStereo, sourceID);
+
+ am_sinkID_t gwSinkID1;
+ enterSinkDB("gwSink1", domainID1, cfMono, gwSinkID1);
+
+ am_sinkID_t coSinkID21;
+ enterSinkDB("coSink21", domainID1, cfStereo, coSinkID21);
+
+ am_sourceID_t coSourceID21;
+ enterSourceDB("coSource21", domainID1, cfMono, coSourceID21);
+
+ am_converterID_t converterID1;
+ enterConverterDB("converter1", domainID1, cfMono, cfStereo, matrix, coSourceID21, coSinkID21, converterID1);
+
+ am_sourceID_t gwSourceID1;
+ enterSourceDB("gwSource21", domainID2, cfAuto, gwSourceID1);
+
+ 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 sinkID2;
+ enterSinkDB("sink2", domainID1, cfAuto, sinkID2);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink1;
+ pDatabaseHandler.getSinkInfoDB(sinkID1, sink1);
+ am::am_Sink_s sink2;
+ pDatabaseHandler.getSinkInfoDB(sinkID2, sink2);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink1, listRoutes));
+ ASSERT_EQ(static_cast<uint>(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]));
+
+ listRoutes.clear();
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink2, listRoutes));
+ ASSERT_EQ(static_cast<uint>(0), listRoutes.size());
+}
+
+TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughDomain2)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ am_domainID_t domainID1, domainID2;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> cfAuto;
+ cfAuto.push_back(CF_GENIVI_AUTO);
+
+ am_sourceID_t sourceID;
+ enterSourceDB("source1", domainID1, cfStereo, sourceID);
+
+ 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_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 sinkID;
+ enterSinkDB("sink1", domainID1, cfAuto, sinkID);
+
+ am::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+
+ am_Route_s compareRoute1;
+ compareRoute1.sinkID = sinkID;
+ compareRoute1.sourceID = sourceID;
+ compareRoute1.route.push_back({sourceID, gwSinkID11, domainID1, CF_GENIVI_STEREO});
+ compareRoute1.route.push_back({gwSourceID11, gwSinkID21, domainID2, CF_GENIVI_ANALOG});
+ compareRoute1.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
+}
+
+TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughGate1Conv2Gate2)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ am_domainID_t domainID1, domainID2;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> cfAuto;
+ cfAuto.push_back(CF_GENIVI_AUTO);
+
+ am_sourceID_t sourceID;
+ enterSourceDB("source1", domainID1, cfStereo, sourceID);
+
+ am_sinkID_t gwSinkID11;
+ enterSinkDB("gwSink11", domainID1, cfStereo, gwSinkID11);
+
+ am_sourceID_t gwSourceID21;
+ enterSourceDB("gwSource21", domainID2, cfAnalog, gwSourceID21);
+
+ am_converterID_t gatewayID1;
+ enterGatewayDB("gateway1", domainID2, domainID1, cfAnalog, cfStereo, matrix, gwSourceID21, gwSinkID11, gatewayID1);
+
+ 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);
+
+ 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::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+ ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
+
+ am_Route_s compareRoute1;
+ compareRoute1.sinkID = sinkID;
+ 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, gwSinkID21, domainID2, CF_GENIVI_STEREO});
+ compareRoute1.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
+}
+
+TEST_F(CAmRouterMapTest, routeSource1Sink1PathThroughConv1Gate1Conv2Gate2)
+{
+ EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
+
+ std::vector<bool> matrix;
+ matrix.push_back(true);
+ am_domainID_t domainID1, domainID2;
+ enterDomainDB("domain1", domainID1);
+ enterDomainDB("domain2", domainID2);
+
+ std::vector<am_CustomConnectionFormat_t> cfStereo;
+ cfStereo.push_back(CF_GENIVI_STEREO);
+ std::vector<am_CustomConnectionFormat_t> cfAnalog;
+ cfAnalog.push_back(CF_GENIVI_ANALOG);
+ std::vector<am_CustomConnectionFormat_t> cfMono;
+ cfMono.push_back(CF_GENIVI_MONO);
+ std::vector<am_CustomConnectionFormat_t> cfAuto;
+ cfAuto.push_back(CF_GENIVI_AUTO);
+ std::vector<am_CustomConnectionFormat_t> cfFuture1;
+ cfFuture1.push_back(5);
+ std::vector<am_CustomConnectionFormat_t> 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_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_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_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_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);
+
+ 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::am_Source_s source;
+ am::am_Sink_s sink;
+
+ pDatabaseHandler.getSinkInfoDB(sinkID, sink);
+ pDatabaseHandler.getSourceInfoDB(sourceID, source);
+
+ std::vector<am_Route_s> listRoutes;
+
+ ASSERT_EQ(E_OK, pRouter.getRoute(false, source, sink, listRoutes));
+
+ ASSERT_EQ(static_cast<uint>(2), listRoutes.size());
+
+ am_Route_s compareRoute1;
+ compareRoute1.sinkID = sinkID;
+ 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});
+ compareRoute1.route.push_back({coSourceID21, gwSinkID21, domainID2, CF_GENIVI_STEREO});
+ compareRoute1.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
+
+ am_Route_s compareRoute2;
+ compareRoute2.sinkID = sinkID;
+ 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, gwSinkID21, domainID1, 5});
+ compareRoute2.route.push_back({gwSourceID21, coSinkID21, domainID2, CF_GENIVI_ANALOG});
+ compareRoute2.route.push_back({gwSourceID12, sinkID, domainID1, CF_GENIVI_AUTO});
+ ASSERT_TRUE(pCF.compareRoute(compareRoute1,listRoutes[0]));
}
int main(int argc, char **argv)
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h
index ead077c..19bccfe 100644
--- a/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h
+++ b/AudioManagerDaemon/test/AmRouterMapTest/CAmRouterMapTest.h
@@ -12,7 +12,7 @@
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
-* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
+* \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013, 2014
*
* For further information see http://www.genivi.org/.
*
@@ -72,6 +72,28 @@ public:
void TearDown();
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<am_CustomConnectionFormat_t> & connectionFormats, am_sourceID_t & sourceID);
+ void enterSinkDB(const std::string & sinkName, const am_domainID_t domainID, const std::vector<am_CustomConnectionFormat_t> & connectionFormats, am_sinkID_t & sinkID);
+ void enterGatewayDB(const std::string & gwName,
+ const am_domainID_t domainSourceID,
+ const am_domainID_t domainSinkID,
+ const std::vector<am_CustomConnectionFormat_t> & sourceConnectionFormats,
+ const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats,
+ const std::vector<bool> & 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<am_CustomConnectionFormat_t> & sourceConnectionFormats,
+ const std::vector<am_CustomConnectionFormat_t> & sinkConnectionFormats,
+ const std::vector<bool> & matrix,
+ const am_sourceID_t & sourceID,
+ const am_sinkID_t & sinkID,
+ am_converterID_t & converterID);
+
};
}
diff --git a/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt
index 2b16eda..2209f40 100644
--- a/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt
+++ b/AudioManagerDaemon/test/AmRouterMapTest/CMakeLists.txt
@@ -55,7 +55,7 @@ file(GLOB ROUTINGMAP_SRCS_CXX
"../../src/CAmCommandReceiver.cpp"
"../../src/CAmRoutingReceiver.cpp"
"../../src/CAmDbusWrapper.cpp"
- "../CAmCommonFunctions.cpp"
+ "../CAmCommonFunctions.cpp"
"*.cpp"
)
diff --git a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp
index 2f29e33..f6f523f 100644
--- a/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp
+++ b/AudioManagerDaemon/test/AmRouterTest/CAmRouterTest.cpp
@@ -92,6 +92,7 @@ TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats)
source.listConnectionFormats.push_back(CF_GENIVI_MONO);
ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID));
+ source.sourceID=sourceID;
am_Sink_s sink;
am_sinkID_t sinkID;
@@ -104,6 +105,7 @@ TEST_F(CAmRouterTest,simpleRoute2withDomainNoMatchFormats)
sink.listConnectionFormats.push_back(CF_GENIVI_ANALOG);
ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID));
+ sink.sinkID=sinkID;
std::vector<am_Route_s> listRoutes;
std::vector<am_RoutingElement_s> listRoutingElements;
@@ -191,8 +193,6 @@ TEST_F(CAmRouterTest,simpleRoute2withDomain)
//test that checks just 2 domains, one sink one source with only one connection format each
TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFree)
{
-
-
EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK)));
//initialize 2 domains
@@ -290,6 +290,9 @@ TEST_F(CAmRouterTest,simpleRoute2DomainsOnlyFree)
compareRoute.sinkID = sinkID;
compareRoute.sourceID = sourceID;
+ std::vector<am_Connection_s> listConnections;
+ pDatabaseHandler.getListConnections(listConnections);
+ ASSERT_EQ(0, listConnections.size());
ASSERT_EQ(E_OK, pRouter.getRoute(true,sourceID,sinkID,listRoutes));
ASSERT_EQ(static_cast<uint>(1), listRoutes.size());
ASSERT_TRUE(pCF.compareRoute(compareRoute,listRoutes[0]));
diff --git a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt
index d619b02..b9aa9c5 100644
--- a/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt
+++ b/AudioManagerDaemon/test/AmRoutingInterfaceTest/CMakeLists.txt
@@ -57,7 +57,7 @@ file(GLOB ROUTING_INTERFACE_SRCS_CXX
"../../src/CAmRoutingReceiver.cpp"
"../../src/CAmCommandReceiver.cpp"
"../../src/CAmDbusWrapper.cpp"
- "*.cpp"
+ "*.cpp"
)
IF(WITH_NSM)
diff --git a/AudioManagerDaemon/test/CAmCommonFunctions.cpp b/AudioManagerDaemon/test/CAmCommonFunctions.cpp
index 47b09e6..e615520 100644
--- a/AudioManagerDaemon/test/CAmCommonFunctions.cpp
+++ b/AudioManagerDaemon/test/CAmCommonFunctions.cpp
@@ -157,11 +157,21 @@ bool CAmCommonFunctions::compareGateway(std::vector<am_Gateway_s>::iterator list
return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->controlDomainID == gatewayData.controlDomainID) && (listIterator->domainSinkID == gatewayData.domainSinkID) && (listIterator->domainSourceID == gatewayData.domainSourceID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
+bool CAmCommonFunctions::compareConverter(std::vector<am_Converter_s>::iterator listIterator, const am_Converter_s& gatewayData)
+{
+ return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->domainID == gatewayData.domainID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin());
+}
+
bool CAmCommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData)
{
return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.controlDomainID == gatewayData.controlDomainID) && (gateway1.domainSinkID == gatewayData.domainSinkID) && (gateway1.domainSourceID == gatewayData.domainSourceID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
+bool CAmCommonFunctions::compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData)
+{
+ return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.domainID == gatewayData.domainID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin());
+}
+
bool CAmCommonFunctions::compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList)
{
std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin();
@@ -304,6 +314,19 @@ void CAmCommonFunctions::createGateway(am_Gateway_s & gateway)
}
+void CAmCommonFunctions::createConverter(am_Converter_s & converter) const
+{
+ converter.name = "AnyConverter";
+ converter.sinkID = 1;
+ converter.sourceID = 2;
+ converter.domainID = 1;
+ converter.convertionMatrix = getStandardConvertionMatrix();
+ converter.listSourceFormats = getStandardConnectionFormatList();
+ converter.listSinkFormats = getStandardConnectionFormatList();
+ converter.converterID = 0;
+
+}
+
void CAmCommonFunctions::createConnection(am_Connection_s & connection) const
{
connection.connectionID = 0;
diff --git a/AudioManagerDaemon/test/CAmCommonFunctions.h b/AudioManagerDaemon/test/CAmCommonFunctions.h
index 345d178..ba152c3 100644
--- a/AudioManagerDaemon/test/CAmCommonFunctions.h
+++ b/AudioManagerDaemon/test/CAmCommonFunctions.h
@@ -39,6 +39,8 @@ public:
bool compareSink(std::vector<am_Sink_s>::iterator listIterator, const am_Sink_s& sinkData);
bool compareGateway(std::vector<am_Gateway_s>::iterator listIterator, const am_Gateway_s& gatewayData);
bool compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData);
+ bool compareConverter(std::vector<am_Converter_s>::iterator listIterator, const am_Converter_s& gatewayData);
+ bool compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData);
bool compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList);
bool compareSinkMainSource(std::vector<am_SourceType_s>::iterator listIterator, const std::vector<am_Source_s>& sourceList);
bool compareRoute(am_Route_s a, am_Route_s b);
@@ -47,6 +49,7 @@ public:
void createDomain(am_Domain_s& domain) const;
void createGateway(am_Gateway_s& gateway);
void createConnection(am_Connection_s& connection) const;
+ void createConverter(am_Converter_s & converter) const;
void connectionList2RoutingList(std::vector<am_RoutingElement_s>& routingList, const std::vector<am_Connection_s>& connectionList);
struct sortBySinkID
diff --git a/AudioManagerDaemon/test/MockIAmControlSend.h b/AudioManagerDaemon/test/MockIAmControlSend.h
index 5d9b528..dc9bdc0 100644
--- a/AudioManagerDaemon/test/MockIAmControlSend.h
+++ b/AudioManagerDaemon/test/MockIAmControlSend.h
@@ -71,6 +71,10 @@ class MockIAmControlSend : public IAmControlSend {
am_Error_e(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID));
MOCK_METHOD1(hookSystemDeregisterGateway,
am_Error_e(const am_gatewayID_t gatewayID));
+ MOCK_METHOD2(hookSystemRegisterConverter,
+ am_Error_e(const am_Converter_s& converterData, am_converterID_t& converterID));
+ MOCK_METHOD1(hookSystemDeregisterConverter,
+ am_Error_e(const am_converterID_t converterID));
MOCK_METHOD2(hookSystemRegisterCrossfader,
am_Error_e(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID));
MOCK_METHOD1(hookSystemDeregisterCrossfader,
@@ -129,6 +133,8 @@ class MockIAmControlSend : public IAmControlSend {
am_Error_e(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomAvailabilityReason_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties));
MOCK_METHOD4(hookSystemUpdateGateway,
am_Error_e(const am_gatewayID_t gatewayID, const std::vector<am_CustomAvailabilityReason_t>& listSourceConnectionFormats, const std::vector<am_CustomAvailabilityReason_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix));
+ MOCK_METHOD4(hookSystemUpdateConverter,
+ am_Error_e(const am_converterID_t converterID, const std::vector<am_CustomAvailabilityReason_t>& listSourceConnectionFormats, const std::vector<am_CustomAvailabilityReason_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix));
MOCK_METHOD3(cbAckSetVolumes,
void(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes, const am_Error_e error));
MOCK_METHOD2(cbAckSetSinkNotificationConfiguration,