From 9f4c15a8e89d798077ca3edf7f786dbc740aa176 Mon Sep 17 00:00:00 2001 From: christian mueller Date: Wed, 1 Feb 2012 10:50:15 +0100 Subject: * implemented peeksinkclassIDs and peeksourceclassIDs * changed interface of both from const to non-const * corrected include headers to c++ style, eg. * corrected sendChangedData return type to void * implemented tests for sinkclass and sourceclass peeking * fixed bug in sockethandler (FD could not be removed) thanks to Frank --- AudioManagerDaemon/include/DatabaseHandler.h | 3 +- AudioManagerDaemon/include/RoutingReceiver.h | 6 +- AudioManagerDaemon/src/CommandReceiver.cpp | 2 +- AudioManagerDaemon/src/ControlSender.cpp | 2 +- AudioManagerDaemon/src/DBusWrapper.cpp | 4 +- AudioManagerDaemon/src/DatabaseHandler.cpp | 212 +++++++++++++------ AudioManagerDaemon/src/DatabaseObserver.cpp | 3 +- AudioManagerDaemon/src/Router.cpp | 2 +- AudioManagerDaemon/src/RoutingReceiver.cpp | 20 +- AudioManagerDaemon/src/RoutingSender.cpp | 2 +- AudioManagerDaemon/src/SocketHandler.cpp | 17 +- AudioManagerDaemon/src/TelnetServer.cpp | 2 +- AudioManagerDaemon/src/main.cpp | 14 +- AudioManagerDaemon/test/CommonFunctions.cpp | 6 +- AudioManagerDaemon/test/database/databaseTest.cpp | 51 ++++- AudioManagerDaemon/test/routing/routingTest.cpp | 234 +++++++++++++++++++++ .../test/sockethandler/sockethandlerTest.cpp | 3 + .../src/CommandReceiverShadow.cpp | 2 +- .../src/DBusCommandSender.cpp | 2 +- .../src/DBusMessageHandler.cpp | 2 +- .../src/RoutingReceiverAsyncShadow.cpp | 2 +- .../src/RoutingSenderAsync.cpp | 2 +- PluginRoutingInterfaceAsync/test/mocklnterfaces.h | 6 +- includes/routing/RoutingReceiveInterface.h | 21 +- includes/routing/RoutingSendInterface.h | 8 +- 25 files changed, 498 insertions(+), 130 deletions(-) diff --git a/AudioManagerDaemon/include/DatabaseHandler.h b/AudioManagerDaemon/include/DatabaseHandler.h index 96065bd..b182195 100644 --- a/AudioManagerDaemon/include/DatabaseHandler.h +++ b/AudioManagerDaemon/include/DatabaseHandler.h @@ -38,7 +38,6 @@ class RoutingTree; class RoutingTreeItem; #define DYNAMIC_ID_BOUNDARY 100 //!< the value below is reserved for staticIDs, the value above will be assigned to dynamically registered items -//todo: we do not have to create MainSoundProperty tables if visible = false. //todo: check the enum values before entering & changing in the database. //todo: change asserts for dynamic boundary checks into failure answers.# //todo: check autoincrement boundary and set to 16bit limits @@ -135,6 +134,8 @@ public: 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); + am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); + am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); /** * checks for a certain mainConnection * @param mainConnectionID to be checked for diff --git a/AudioManagerDaemon/include/RoutingReceiver.h b/AudioManagerDaemon/include/RoutingReceiver.h index 90885ca..d3675a8 100644 --- a/AudioManagerDaemon/include/RoutingReceiver.h +++ b/AudioManagerDaemon/include/RoutingReceiver.h @@ -72,15 +72,15 @@ public: am_Error_e deregisterSource(const am_sourceID_t sourceID); am_Error_e registerCrossfader(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID); am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID); - am_Error_e peekSinkClassID(const std::string& name, const am_sinkClass_t& sinkClassID); - am_Error_e peekSourceClassID(const std::string& name, const am_sourceClass_t& sourceClassID); + am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID); + am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID); void hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState); void hookDomainRegistrationComplete(const am_domainID_t domainID); void hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s& availability); void hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s& availability); void hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState); void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay); - am_Error_e sendChangedData(const std::vector& earlyData); + void sendChangedData(const std::vector& earlyData); am_Error_e getDBusConnectionWrapper(DBusWrapper*& dbusConnectionWrapper) const; am_Error_e getSocketHandler(SocketHandler*& socketHandler) const; uint16_t getInterfaceVersion() const; diff --git a/AudioManagerDaemon/src/CommandReceiver.cpp b/AudioManagerDaemon/src/CommandReceiver.cpp index b0145f1..6114076 100644 --- a/AudioManagerDaemon/src/CommandReceiver.cpp +++ b/AudioManagerDaemon/src/CommandReceiver.cpp @@ -28,7 +28,7 @@ #include "DLTWrapper.h" #include #include -#include +#include using namespace am; diff --git a/AudioManagerDaemon/src/ControlSender.cpp b/AudioManagerDaemon/src/ControlSender.cpp index 934f594..816ed80 100644 --- a/AudioManagerDaemon/src/ControlSender.cpp +++ b/AudioManagerDaemon/src/ControlSender.cpp @@ -25,7 +25,7 @@ #include "ControlSender.h" #include "PluginTemplate.h" #include "DLTWrapper.h" -#include +#include #include using namespace am; diff --git a/AudioManagerDaemon/src/DBusWrapper.cpp b/AudioManagerDaemon/src/DBusWrapper.cpp index a271017..830dd39 100644 --- a/AudioManagerDaemon/src/DBusWrapper.cpp +++ b/AudioManagerDaemon/src/DBusWrapper.cpp @@ -28,8 +28,8 @@ #include #include #include -#include -#include +#include +#include #include "DLTWrapper.h" using namespace am; diff --git a/AudioManagerDaemon/src/DatabaseHandler.cpp b/AudioManagerDaemon/src/DatabaseHandler.cpp index b1660e9..a8bc443 100644 --- a/AudioManagerDaemon/src/DatabaseHandler.cpp +++ b/AudioManagerDaemon/src/DatabaseHandler.cpp @@ -24,7 +24,7 @@ #include "DatabaseHandler.h" #include "DatabaseObserver.h" -#include +#include #include #include #include @@ -48,12 +48,16 @@ using namespace am; const std::string databaseTables[] = -{ // - " Domains (domainID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), busname VARCHAR(50), nodename VARCHAR(50), early BOOL, complete BOOL, state INTEGER, reserved BOOL);", " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", - " 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, inUse BOOL);", " 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);", " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" }; +{ " Domains (domainID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), busname VARCHAR(50), nodename VARCHAR(50), early BOOL, complete BOOL, state INTEGER, reserved BOOL);", // + " SourceClasses (sourceClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // + " SinkClasses (sinkClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(50));", // + " 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);", // + " 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);", // + " SystemProperties (type INTEGER PRIMARY KEY, value INTEGER);" }; /** * template to converts T to std::string @@ -80,9 +84,6 @@ DatabaseHandler::DatabaseHandler(std::string databasePath) : mListConnectionFormat() { - /** - *\todo: this erases the database. just for testing! - */ std::ifstream infile(mPath.c_str()); if (infile) @@ -111,7 +112,7 @@ am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_dom assert(domainData.domainID==0); assert(!domainData.name.empty()); assert(!domainData.busname.empty()); - assert(domainData.state>=DS_CONTROLLED && domainData.state<=DS_INDEPENDENT_RUNDOWN); + assert(domainData.state>=DS_MIN && domainData.state<=DS_MAX); //first check for a reserved domain sqlite3_stmt* query = NULL, *queryFinal; @@ -175,7 +176,7 @@ am_Error_e DatabaseHandler::enterDomainDB(const am_Domain_s & domainData, am_dom am_Error_e DatabaseHandler::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID) { assert(mainConnectionData.connectionID==0); - assert(mainConnectionData.connectionState>=CS_CONNECTING && mainConnectionData.connectionState<=CS_SUSPENDED); + assert(mainConnectionData.connectionState>=CS_MIN && mainConnectionData.connectionState<=CS_MAX); assert(mainConnectionData.route.sinkID!=0); assert(mainConnectionData.route.sourceID!=0); @@ -283,7 +284,7 @@ am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t assert(sinkData.sinkClassID!=0); // \todo: need to check if class exists? assert(!sinkData.listConnectionFormats.empty()); - assert(sinkData.muteState>=MS_MUTED && sinkData.muteState<=MS_UNMUTED); + assert(sinkData.muteState>=MS_MIN && sinkData.muteState<=MS_MAX); sqlite3_stmt *query = NULL, *queryFinal = NULL; int eCode = 0; @@ -385,8 +386,6 @@ am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t //now we need to create the additional tables: command = "CREATE TABLE SinkConnectionFormat" + i2s(sinkID) + std::string("(soundFormat INTEGER)"); assert(this->sqQuery(command)); - command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); command = "CREATE TABLE SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); assert(this->sqQuery(command)); @@ -406,23 +405,6 @@ am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t sqlite3_reset(query); } - //Fill MainSinkSoundProperties - command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); - sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - //Fill SinkSoundProperties command = "INSERT INTO SinkSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); @@ -440,6 +422,29 @@ am_Error_e DatabaseHandler::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t sqlite3_reset(query); } + if (sinkData.visible == true) + { + command = "CREATE TABLE SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //Fill MainSinkSoundProperties + command = "INSERT INTO SinkMainSoundProperty" + i2s(sinkID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator mainSoundPropertyIterator = sinkData.listMainSoundProperties.begin(); + for (; mainSoundPropertyIterator < sinkData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) + { + sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); + sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSinkDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + } + logInfo("DatabaseHandler::enterSinkDB entered new sink with name", sinkData.name, "domainID:", sinkData.domainID, "classID:", sinkData.sinkClassID, "volume:", sinkData.volume, "assigned ID:", sinkID); am_Sink_s sink = sinkData; sink.sinkID = sinkID; @@ -476,14 +481,14 @@ am_Error_e DatabaseHandler::enterGatewayDB(const am_Gateway_s & gatewayData, am_ //if sinkID is zero and the first Static Sink was already entered, the ID is created if (gatewayData.gatewayID == 0 && !mFirstStaticGateway) { - command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, inUse) VALUES (?,?,?,?,?,?,0)"; + command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID) VALUES (?,?,?,?,?,?)"; } else { //check if the ID already exists if (existGateway(gatewayData.gatewayID)) return E_ALREADY_EXISTS; - command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID, inUse) VALUES (?,?,?,?,?,?,?,0)"; + command = "INSERT INTO " + std::string(GATEWAY_TABLE) + "(name, sinkID, sourceID, domainSinkID, domainSourceID, controlDomainID, gatewayID) VALUES (?,?,?,?,?,?,?)"; } sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); @@ -574,7 +579,7 @@ am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sou assert(sourceData.sourceClassID!=0); // \todo: need to check if class exists? assert(!sourceData.listConnectionFormats.empty()); - assert(sourceData.sourceState>=SS_ON && sourceData.sourceState<=SS_PAUSED); + assert(sourceData.sourceState>=SS_MIN && sourceData.sourceState<=SS_MAX); sqlite3_stmt* query = NULL, *queryFinal = NULL; ; @@ -677,8 +682,6 @@ am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sou //now we need to create the additional tables: command = "CREATE TABLE SourceConnectionFormat" + i2s(sourceID) + std::string("(soundFormat INTEGER)"); assert(this->sqQuery(command)); - command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); - assert(this->sqQuery(command)); command = "CREATE TABLE SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); assert(this->sqQuery(command)); @@ -698,23 +701,6 @@ am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sou sqlite3_reset(query); } - //Fill MainSinkSoundProperties - command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); - sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); - std::vector::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin(); - for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) - { - sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); - sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); - if ((eCode = sqlite3_step(query)) != SQLITE_DONE) - { - logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); - sqlite3_finalize(query); - return E_DATABASE_ERROR; - } - sqlite3_reset(query); - } - //Fill SinkSoundProperties command = "INSERT INTO SourceSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); @@ -732,6 +718,29 @@ am_Error_e DatabaseHandler::enterSourceDB(const am_Source_s & sourceData, am_sou sqlite3_reset(query); } + if (sourceData.visible == true) + { + command = "CREATE TABLE SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType INTEGER, value INTEGER)"); + assert(this->sqQuery(command)); + + //Fill MainSinkSoundProperties + command = "INSERT INTO SourceMainSoundProperty" + i2s(sourceID) + std::string("(soundPropertyType,value) VALUES (?,?)"); + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + std::vector::const_iterator mainSoundPropertyIterator = sourceData.listMainSoundProperties.begin(); + for (; mainSoundPropertyIterator < sourceData.listMainSoundProperties.end(); ++mainSoundPropertyIterator) + { + sqlite3_bind_int(query, 1, mainSoundPropertyIterator->type); + sqlite3_bind_int(query, 2, mainSoundPropertyIterator->value); + if ((eCode = sqlite3_step(query)) != SQLITE_DONE) + { + logError("DatabaseHandler::enterSourceDB SQLITE Step error code:", eCode); + sqlite3_finalize(query); + return E_DATABASE_ERROR; + } + sqlite3_reset(query); + } + } + logInfo("DatabaseHandler::enterSinkDB entered new source with name", sourceData.name, "domainID:", sourceData.domainID, "classID:", sourceData.sourceClassID, "visible:", sourceData.visible, "assigned ID:", sourceID); am_Source_s source = sourceData; @@ -820,6 +829,7 @@ am_Error_e DatabaseHandler::changeMainConnectionRouteDB(const am_mainConnectionI am_Error_e DatabaseHandler::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState) { assert(mainconnectionID!=0); + assert(connectionState>=CS_MIN && connectionState<=CS_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -886,6 +896,8 @@ am_Error_e DatabaseHandler::changeSinkMainVolumeDB(const am_mainVolume_t mainVol am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID) { assert(sinkID!=0); + assert(availability.availability>=A_MIN && availability.availability<=A_MAX); + assert(availability.availabilityReason>=AR_MIN && availability.availabilityReason<=AR_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -921,6 +933,7 @@ am_Error_e DatabaseHandler::changeSinkAvailabilityDB(const am_Availability_s & a am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID) { assert(domainID!=0); + assert(domainState>=DS_MIN && domainState<=DS_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -953,6 +966,7 @@ am_Error_e DatabaseHandler::changDomainStateDB(const am_DomainState_e domainStat am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID) { assert(sinkID!=0); + assert(muteState>=MS_MIN && muteState<=MS_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -987,7 +1001,7 @@ am_Error_e DatabaseHandler::changeSinkMuteStateDB(const am_MuteState_e muteState am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID) { - //todo: add checks if soundproperty exists! + assert(soundProperty.type>=MSP_MIN && soundProperty.type<=MSP_MAX); assert(sinkID!=0); sqlite3_stmt* query = NULL; @@ -1021,7 +1035,7 @@ am_Error_e DatabaseHandler::changeMainSinkSoundPropertyDB(const am_MainSoundProp am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID) { - //todo: add checks if soundproperty exists! + assert(soundProperty.type>=MSP_MIN && soundProperty.type<=MSP_MAX); assert(sourceID!=0); sqlite3_stmt* query = NULL; @@ -1057,6 +1071,8 @@ am_Error_e DatabaseHandler::changeMainSourceSoundPropertyDB(const am_MainSoundPr am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID) { assert(sourceID!=0); + assert(availability.availability>=A_MIN && availability.availability<=A_MAX); + assert(availability.availabilityReason>=AR_MIN && availability.availabilityReason<=AR_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -1091,6 +1107,7 @@ am_Error_e DatabaseHandler::changeSourceAvailabilityDB(const am_Availability_s & am_Error_e DatabaseHandler::changeSystemPropertyDB(const am_SystemProperty_s & property) { + assert(property.type>=SYP_MIN && property.type<=SYP_MAX); sqlite3_stmt* query = NULL; int eCode = 0; std::string command = "UPDATE " + std::string(SYSTEM_TABLE) + " set value=? WHERE type=?"; @@ -1747,7 +1764,7 @@ am_Error_e DatabaseHandler::getListMainConnections(std::vector & listSystemProperties) { + assert(!listSystemProperties.empty()); sqlite3_stmt* query = NULL; int eCode = 0; std::vector::const_iterator listIterator = listSystemProperties.begin(); @@ -3407,6 +3425,7 @@ am_Error_e DatabaseHandler::getSoureState(const am_sourceID_t sourceID, am_Sourc am_Error_e DatabaseHandler::changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState) { assert(sourceID!=0); + assert(sourceState>=SS_MIN && sourceState<=SS_MAX); sqlite3_stmt* query = NULL; std::string command = "UPDATE " + std::string(SOURCE_TABLE) + " SET sourceState=? WHERE sourceID=" + i2s(sourceID); int eCode = 0; @@ -3756,7 +3775,7 @@ am_Error_e DatabaseHandler::changeSourceVolume(const am_sourceID_t sourceID, con am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sourceID_t sourceID) { - //todo: add checks if soundproperty exists! + assert(soundProperty.type>=SP_MIN && soundProperty.type<=SP_MAX); assert(sourceID!=0); sqlite3_stmt* query = NULL; @@ -3791,7 +3810,7 @@ am_Error_e DatabaseHandler::changeSourceSoundPropertyDB(const am_SoundProperty_s am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & soundProperty, const am_sinkID_t sinkID) { - //todo: add checks if soundproperty exists! + assert(soundProperty.type>=SP_MIN && soundProperty.type<=SP_MAX); assert(sinkID!=0); sqlite3_stmt* query = NULL; @@ -3825,6 +3844,7 @@ am_Error_e DatabaseHandler::changeSinkSoundPropertyDB(const am_SoundProperty_s & am_Error_e DatabaseHandler::changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink) { assert(crossfaderID!=0); + assert(hotsink>=HS_MIN && hotsink>=HS_MAX); sqlite3_stmt* query = NULL; int eCode = 0; @@ -3863,7 +3883,14 @@ am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std am_domainID_t rootID = tree.returnRootDomainID(); RoutingTreeItem *parent = tree.returnRootItem(); - command = "SELECT domainSourceID,gatewayID FROM " + std::string(GATEWAY_TABLE) + " WHERE domainSinkID=? AND inUse=?"; + 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 { @@ -3874,7 +3901,6 @@ am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std } sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); sqlite3_bind_int(query, 1, rootID); - sqlite3_bind_int(query, 2, onlyfree); while ((eCode = sqlite3_step(query)) == SQLITE_ROW) { @@ -3900,6 +3926,70 @@ am_Error_e DatabaseHandler::getRoutingTree(bool onlyfree, RoutingTree& tree, std return (E_OK); } +am_Error_e am::DatabaseHandler::peekSinkClassID(const std::string & name, am_sinkClass_t & sinkClassID) +{ + if (name.empty()) + return E_NON_EXISTENT; + + am_Error_e returnVal = E_NON_EXISTENT; + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT sinkClassID FROM " + std::string(SINK_CLASS_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sinkClassID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else if (eCode != SQLITE_DONE) + { + sinkClassID = 0; + logError("DatabaseHandler::peekSinkClassID SQLITE error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::peekSinkClassID SQLITE Finalize error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + return returnVal; +} + +am_Error_e am::DatabaseHandler::peekSourceClassID(const std::string & name, am_sourceClass_t & sourceClassID) +{ + if (name.empty()) + return E_NON_EXISTENT; + + am_Error_e returnVal = E_NON_EXISTENT; + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT sourceClassID FROM " + std::string(SOURCE_CLASS_TABLE) + " WHERE name=?"; + sqlite3_prepare_v2(mDatabase, command.c_str(), -1, &query, NULL); + sqlite3_bind_text(query, 1, name.c_str(), name.size(), SQLITE_STATIC); + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + sourceClassID = sqlite3_column_int(query, 0); + returnVal = E_OK; + } + else if (eCode != SQLITE_DONE) + { + sourceClassID = 0; + logError("DatabaseHandler::peekSourceClassID SQLITE error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + + if ((eCode = sqlite3_finalize(query)) != SQLITE_OK) + { + logError("DatabaseHandler::peekSourceClassID SQLITE Finalize error code:", eCode); + returnVal = E_DATABASE_ERROR; + } + return returnVal; +} + void DatabaseHandler::createTables() { for (uint16_t i = 0; i < sizeof(databaseTables) / sizeof(databaseTables[0]); i++) diff --git a/AudioManagerDaemon/src/DatabaseObserver.cpp b/AudioManagerDaemon/src/DatabaseObserver.cpp index 19e3ea2..97a1d07 100644 --- a/AudioManagerDaemon/src/DatabaseObserver.cpp +++ b/AudioManagerDaemon/src/DatabaseObserver.cpp @@ -26,7 +26,7 @@ #include "CommandSender.h" #include "RoutingSender.h" #include "TelnetServer.h" -#include +#include using namespace am; @@ -50,7 +50,6 @@ DatabaseObserver::DatabaseObserver(CommandSender *iCommandSender, RoutingSender DatabaseObserver::~DatabaseObserver() { - // TODO Auto-generated destructor stub } void DatabaseObserver::newSink(am_Sink_s sink) diff --git a/AudioManagerDaemon/src/Router.cpp b/AudioManagerDaemon/src/Router.cpp index afb6aa1..2e5f905 100644 --- a/AudioManagerDaemon/src/Router.cpp +++ b/AudioManagerDaemon/src/Router.cpp @@ -25,7 +25,7 @@ #include "Router.h" #include "DatabaseHandler.h" #include "ControlSender.h" -#include +#include #include #include #include diff --git a/AudioManagerDaemon/src/RoutingReceiver.cpp b/AudioManagerDaemon/src/RoutingReceiver.cpp index 00575fe..b4b7764 100644 --- a/AudioManagerDaemon/src/RoutingReceiver.cpp +++ b/AudioManagerDaemon/src/RoutingReceiver.cpp @@ -31,7 +31,7 @@ #include "DatabaseHandler.h" #include "RoutingSender.h" #include "ControlSender.h" -#include +#include using namespace am; @@ -310,27 +310,19 @@ void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t conne mDatabaseHandler->changeConnectionTimingInformation(connectionID, delay); } -am_Error_e RoutingReceiver::sendChangedData(const std::vector & earlyData) +void RoutingReceiver::sendChangedData(const std::vector & earlyData) { mControlSender->hookSystemReceiveEarlyData(earlyData); - return E_OK; -//todo: change return type to void in EA model } -am_Error_e RoutingReceiver::peekSinkClassID(const std::string& name, const am_sinkClass_t& sinkClassID) +am_Error_e RoutingReceiver::peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) { - (void) name; - (void) sinkClassID; -//todo: implement - return E_NOT_USED; + return mDatabaseHandler->peekSinkClassID(name,sinkClassID); } -am_Error_e RoutingReceiver::peekSourceClassID(const std::string& name, const am_sourceClass_t& sourceClassID) +am_Error_e RoutingReceiver::peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) { - (void) name; - (void) sourceClassID; -//todo: implement - return E_NOT_USED; + return mDatabaseHandler->peekSourceClassID(name,sourceClassID); } am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *& dbusConnectionWrapper) const diff --git a/AudioManagerDaemon/src/RoutingSender.cpp b/AudioManagerDaemon/src/RoutingSender.cpp index 8b35800..16d04b0 100644 --- a/AudioManagerDaemon/src/RoutingSender.cpp +++ b/AudioManagerDaemon/src/RoutingSender.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "PluginTemplate.h" #include "DLTWrapper.h" diff --git a/AudioManagerDaemon/src/SocketHandler.cpp b/AudioManagerDaemon/src/SocketHandler.cpp index 26f6d66..eb02db4 100644 --- a/AudioManagerDaemon/src/SocketHandler.cpp +++ b/AudioManagerDaemon/src/SocketHandler.cpp @@ -24,14 +24,14 @@ #include "SocketHandler.h" #include -#include +#include #include #include #include #include #include #include -#include +#include #include "DLTWrapper.h" //todo: implement time correction if timer was interrupted by call @@ -135,6 +135,9 @@ void SocketHandler::start_listenting() { //todo: here could be a timer that makes sure naughty plugins return! + //freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines + mListPoll_t listPoll(mListPoll); + //get all indexes of the fired events and save them int hitList hitList.clear(); std::vector::iterator it = mfdPollingArray.begin(); @@ -150,7 +153,7 @@ void SocketHandler::start_listenting() for (; hListIt != hitList.end(); ++hListIt) { shPollFired* fire = NULL; - if ((fire = mListPoll.at(*hListIt).firedCB) != NULL) fire->Call(mfdPollingArray.at(*hListIt), mListPoll.at(*hListIt).handle, mListPoll.at(*hListIt).userData); + if ((fire = listPoll.at(*hListIt).firedCB) != NULL) fire->Call(mfdPollingArray.at(*hListIt), listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData); } //stage 2, lets ask around if some dispatching is necessary, if not, they are taken from the hitlist @@ -158,9 +161,9 @@ void SocketHandler::start_listenting() for (; hListIt != hitList.end(); ++hListIt) { shPollCheck* check = NULL; - if ((check = mListPoll.at(*hListIt).checkCB) != NULL) + if ((check = listPoll.at(*hListIt).checkCB) != NULL) { - if (!check->Call(mListPoll.at(*hListIt).handle, mListPoll.at(*hListIt).userData)) + if (!check->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) { hListIt = hitList.erase(hListIt); } @@ -174,9 +177,9 @@ void SocketHandler::start_listenting() for (; hListIt != hitList.end(); ++hListIt) { shPollDispatch *dispatch = NULL; - if ((dispatch = mListPoll.at(*hListIt).dispatchCB) != NULL) + if ((dispatch = listPoll.at(*hListIt).dispatchCB) != NULL) { - if (!dispatch->Call(mListPoll.at(*hListIt).handle, mListPoll.at(*hListIt).userData)) + if (!dispatch->Call(listPoll.at(*hListIt).handle, listPoll.at(*hListIt).userData)) { hListIt = hitList.erase(hListIt); } diff --git a/AudioManagerDaemon/src/TelnetServer.cpp b/AudioManagerDaemon/src/TelnetServer.cpp index dea5ddc..38e8453 100644 --- a/AudioManagerDaemon/src/TelnetServer.cpp +++ b/AudioManagerDaemon/src/TelnetServer.cpp @@ -23,7 +23,7 @@ */ #include "TelnetServer.h" -#include +#include #include #include #include diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index a57e6c0..faaafdb 100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -26,13 +26,11 @@ * Please make sure to have read the documentation on genivi.org! */ -//todo: make real daemon out of it- systemd conform -//todo: versioning of PluginInterfaces on linux level (.symver stuff) +//todo: create systemd compatibility //todo: all communication like all plugins loaded etc... //todo: seperate documentation of test from normal project //todo: check the startup sequence. Dbus shall be activated last... //todo: there is a bug in the visible flags of sinks and sources. fix it. -//todo: make sure that iterators have a fixed end to prevent crashed while adding vectors while iterating on critical vectors //todo: make sure all configurations are tested //todo: clean up startup sequences controller, command and routing interfaces---- #include @@ -54,13 +52,13 @@ #include #include #include -#include #include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include DLT_DECLARE_CONTEXT(AudioManager) diff --git a/AudioManagerDaemon/test/CommonFunctions.cpp b/AudioManagerDaemon/test/CommonFunctions.cpp index 2a5c8cf..30c8725 100644 --- a/AudioManagerDaemon/test/CommonFunctions.cpp +++ b/AudioManagerDaemon/test/CommonFunctions.cpp @@ -27,7 +27,7 @@ #include "CommandInterfaceBackdoor.h" #include "RoutingInterfaceBackdoor.h" #include "ControlInterfaceBackdoor.h" -#include +#include #include using namespace am; @@ -54,7 +54,7 @@ bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender, Com assert(CommandSender != NULL); assert(CommandSendInterface != NULL); CommandSender->mListInterfaces.push_back(CommandSendInterface); - return true; //todo: check if it worked + return true; } RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() @@ -83,7 +83,7 @@ bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender, Rou newInterfacePair.routingInterface = newInterface; newInterfacePair.busName = busname; RoutingSender->mListInterfaces.push_back(newInterfacePair); - return true; //todo: check if it worked + return true; } ControlInterfaceBackdoor::ControlInterfaceBackdoor() diff --git a/AudioManagerDaemon/test/database/databaseTest.cpp b/AudioManagerDaemon/test/database/databaseTest.cpp index 6122505..a44804b 100644 --- a/AudioManagerDaemon/test/database/databaseTest.cpp +++ b/AudioManagerDaemon/test/database/databaseTest.cpp @@ -147,13 +147,60 @@ void routingTest::createMainConnectionSetup() void routingTest::SetUp() { - logInfo("Database Test started "); } void routingTest::TearDown() { } +TEST_F(routingTest, peekSourceID) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourceClassesChanged()).Times(1); + std::string sourceName("myClassID"); + am_sourceClass_t sourceClassID, peekID; + am_SourceClass_s sourceClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_SOURCE_TYPE; + classProperty.value = 13; + sourceClass.name = sourceName; + sourceClass.sourceClassID = 0; + sourceClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSourceClassID(sourceName,sourceClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceClassDB(sourceClassID,sourceClass)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSourceClassID(sourceName,peekID)); + ASSERT_EQ(sourceClassID, peekID); +} + +TEST_F(routingTest, peekSinkID) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSinkClassesChanged()).Times(1); + std::string sinkName("myClassID"); + am_sinkClass_t sinkClassID, peekID; + am_SinkClass_s sinkClass; + am_ClassProperty_s classProperty; + classProperty.classProperty = CP_SOURCE_TYPE; + classProperty.value = 13; + sinkClass.name = sinkName; + sinkClass.sinkClassID = 0; + sinkClass.listClassProperties.push_back(classProperty); + + //first we peek without an existing class + ASSERT_EQ(E_NON_EXISTENT, pDatabaseHandler.peekSinkClassID(sinkName,sinkClassID)); + + //now we enter the class into the database + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkClassDB(sinkClass,sinkClassID)); + + //first we peek without an existing class + ASSERT_EQ(E_OK, pDatabaseHandler.peekSinkClassID(sinkName,peekID)); + ASSERT_EQ(sinkClassID, peekID); +} + TEST_F(routingTest,crossfaders) { //todo:implement crossfader tests @@ -1592,6 +1639,8 @@ TEST_F(routingTest,enterSinksCorrect) int main(int argc, char **argv) { + DLTWrapper::instance()->registerApp("databse", "databasetest"); + logInfo("Database Test started "); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/AudioManagerDaemon/test/routing/routingTest.cpp b/AudioManagerDaemon/test/routing/routingTest.cpp index fdfbcf8..463bbfd 100644 --- a/AudioManagerDaemon/test/routing/routingTest.cpp +++ b/AudioManagerDaemon/test/routing/routingTest.cpp @@ -77,6 +77,238 @@ ACTION(returnConnectionFormat){ arg3=arg2; } +//test that checks just 2 domains, one sink one source with only one connection format each +TEST_F(routingTest,simpleRoute2DomainsOnlyFree) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2); + EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector 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(true,sourceID,sinkID,listRoutes)); + ASSERT_EQ(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(routingTest,simpleRoute2DomainsOnlyFreeNotFree) +{ + EXPECT_CALL(pMockInterface,cbNumberOfSourcesChanged()).Times(2); + EXPECT_CALL(pMockInterface,cbNumberOfSinksChanged()).Times(2); + EXPECT_CALL(pMockControlInterface,getConnectionFormatChoice(_,_,_,_)).WillRepeatedly(DoAll(returnConnectionFormat(), Return(E_OK))); + + //initialize 2 domains + am_Domain_s domain1, domain2; + am_domainID_t domainID1, domainID2; + + domain1.domainID = 0; + domain1.name = "domain1"; + domain1.busname = "domain1bus"; + domain1.state = DS_CONTROLLED; + domain2.domainID = 0; + domain2.name = "domain2"; + domain2.busname = "domain2bus"; + domain2.state = DS_CONTROLLED; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain1,domainID1)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterDomainDB(domain2,domainID2)); + + am_Source_s source, gwSource; + am_sourceID_t sourceID, gwSourceID; + + source.domainID = domainID1; + source.name = "source1"; + source.sourceState = SS_ON; + source.sourceID = 0; + source.sourceClassID = 5; + source.listConnectionFormats.push_back(CF_ANALOG); + + gwSource.domainID = domainID2; + gwSource.name = "gwsource1"; + gwSource.sourceState = SS_ON; + gwSource.sourceID = 0; + gwSource.sourceClassID = 5; + gwSource.listConnectionFormats.push_back(CF_MONO); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(source,sourceID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSourceDB(gwSource,gwSourceID)); + + am_Sink_s sink, gwSink; + am_sinkID_t sinkID, gwSinkID; + + sink.domainID = domainID2; + sink.name = "sink1"; + sink.sinkID = 0; + sink.sinkClassID = 5; + sink.muteState = MS_MUTED; + sink.listConnectionFormats.push_back(CF_MONO); + + gwSink.domainID = domainID1; + gwSink.name = "gwSink"; + gwSink.sinkID = 0; + gwSink.sinkClassID = 5; + gwSink.muteState = MS_MUTED; + gwSink.listConnectionFormats.push_back(CF_ANALOG); + + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(sink,sinkID)); + ASSERT_EQ(E_OK, pDatabaseHandler.enterSinkDB(gwSink,gwSinkID)); + + am_Gateway_s gateway; + am_gatewayID_t gatewayID; + + gateway.controlDomainID = domainID1; + gateway.gatewayID = 0; + gateway.sinkID = gwSinkID; + gateway.sourceID = gwSourceID; + gateway.domainSourceID = domainID2; + gateway.domainSinkID = domainID1; + gateway.listSinkFormats = gwSink.listConnectionFormats; + gateway.listSourceFormats = gwSource.listConnectionFormats; + gateway.convertionMatrix.push_back(true); + gateway.name = "gateway"; + + ASSERT_EQ(E_OK, pDatabaseHandler.enterGatewayDB(gateway,gatewayID)); + + std::vector listRoutes; + std::vector 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; + + am_Connection_s connection,connection1; + am_connectionID_t id1,id2; + connection.sourceID=sourceID; + connection.sinkID=gwSinkID; + connection.connectionFormat=CF_ANALOG; + connection.connectionID=0; + connection1.sourceID=gwSourceID; + connection1.sinkID=sinkID; + connection1.connectionFormat=CF_ANALOG; + connection1.connectionID=0; + + 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(0, listRoutes.size()); + + ASSERT_EQ(E_OK, pRouter.getRoute(false,sourceID,sinkID,listRoutes)); + ASSERT_EQ(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(routingTest,simpleRoute3DomainsListConnectionFormats_2) { @@ -1477,6 +1709,8 @@ TEST_F(routingTest,simpleRoute4Domains) int main(int argc, char **argv) { + DLTWrapper::instance()->registerApp("routing", "routingtest"); + logInfo("Routing Test started "); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp index 9165fa2..1f1abea 100644 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp +++ b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp @@ -15,6 +15,9 @@ #include #include +//todo: expand test, implement more usecases +//todo: test removeFD + #define SOCK_PATH "/tmp/mysock" using namespace testing; diff --git a/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp b/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp index b1da840..313818f 100644 --- a/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp +++ b/PluginCommandInterfaceDbus/src/CommandReceiverShadow.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "CommandReceiverShadow.h" #include "DBusCommandSender.h" #include "DLTWrapper.h" diff --git a/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp b/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp index 53022de..d85dd34 100644 --- a/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp +++ b/PluginCommandInterfaceDbus/src/DBusCommandSender.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include DLT_DECLARE_CONTEXT(commandDbus) diff --git a/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp b/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp index 66e216b..3dd9172 100644 --- a/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp +++ b/PluginCommandInterfaceDbus/src/DBusMessageHandler.cpp @@ -27,7 +27,7 @@ #include "DBusCommandSender.h" #include "DLTWrapper.h" #include -#include +#include #include DLT_IMPORT_CONTEXT(commandDbus) diff --git a/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp b/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp index 64bfc95..f433a2c 100644 --- a/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp +++ b/PluginRoutingInterfaceAsync/src/RoutingReceiverAsyncShadow.cpp @@ -23,7 +23,7 @@ */ #include "RoutingReceiverAsyncShadow.h" -#include +#include #include #include #include diff --git a/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp b/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp index 9d063bc..d51e943 100644 --- a/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp +++ b/PluginRoutingInterfaceAsync/src/RoutingSenderAsync.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/PluginRoutingInterfaceAsync/test/mocklnterfaces.h b/PluginRoutingInterfaceAsync/test/mocklnterfaces.h index c3caa46..328d416 100644 --- a/PluginRoutingInterfaceAsync/test/mocklnterfaces.h +++ b/PluginRoutingInterfaceAsync/test/mocklnterfaces.h @@ -82,9 +82,9 @@ class MockRoutingReceiveInterface : public RoutingReceiveInterface { MOCK_METHOD1(deregisterCrossfader, am_Error_e(const am_crossfaderID_t crossfaderID)); MOCK_METHOD2(peekSourceClassID, - am_Error_e(const std::string& name, const am_sourceClass_t& sourceClassID)); + am_Error_e(const std::string& name, am_sourceClass_t& sourceClassID)); MOCK_METHOD2(peekSinkClassID, - am_Error_e(const std::string& name, const am_sinkClass_t& sinkClassID)); + am_Error_e(const std::string& name, am_sinkClass_t& sinkClassID)); MOCK_METHOD2(hookInterruptStatusChange, void(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)); MOCK_METHOD1(hookDomainRegistrationComplete, @@ -98,7 +98,7 @@ class MockRoutingReceiveInterface : public RoutingReceiveInterface { MOCK_METHOD2(hookTimingInformationChanged, void(const am_connectionID_t connectionID, const am_timeSync_t delay)); MOCK_METHOD1(sendChangedData, - am_Error_e(const std::vector& earlyData)); + void(const std::vector& earlyData)); MOCK_CONST_METHOD1(getDBusConnectionWrapper, am_Error_e(DBusWrapper*& dbusConnectionWrapper)); MOCK_CONST_METHOD1(getSocketHandler, diff --git a/includes/routing/RoutingReceiveInterface.h b/includes/routing/RoutingReceiveInterface.h index e610f92..c2438a9 100644 --- a/includes/routing/RoutingReceiveInterface.h +++ b/includes/routing/RoutingReceiveInterface.h @@ -22,8 +22,8 @@ * * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN */ -#if !defined(EA_6B5234F4_E3F3_46f3_9B2A_892FD2A0236E__INCLUDED_) -#define EA_6B5234F4_E3F3_46f3_9B2A_892FD2A0236E__INCLUDED_ +#if !defined(EA_21C9D5F3_73BF_4121_9A14_1D76799A05A0__INCLUDED_) +#define EA_21C9D5F3_73BF_4121_9A14_1D76799A05A0__INCLUDED_ #include #include @@ -41,7 +41,7 @@ namespace am { * Routing Receive sendInterface description. This class implements everything from RoutingAdapter -> Audiomanager * @author christian * @version 1.0 - * @created 30-Jan-2012 6:29:29 PM + * @created 01-Feb-2012 9:42:02 AM */ class RoutingReceiveInterface { @@ -248,20 +248,20 @@ namespace am { virtual am_Error_e deregisterCrossfader(const am_crossfaderID_t crossfaderID) =0; /** * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. - * @return E_OK on succes, E_DATABASE_ERROR on error + * @return E_OK on succes, E_DATABASE_ERROR on error, E_NON_EXISTENT if no sourceclass with name is registered * * @param name * @param sourceClassID */ - virtual am_Error_e peekSourceClassID(const std::string& name, const am_sourceClass_t& sourceClassID) =0; + virtual am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID) =0; /** * this function peeks a sourceclassID. It is used by the RoutingPlugins to determine the SinkClassIDs of a sinkClass. - * @return E_OK on succes, E_DATABASE_ERROR on error + * @return E_OK on succes, E_DATABASE_ERROR on error, E_NON_EXISTENT if no sourceclass with name is registered * * @param name * @param sinkClassID */ - virtual am_Error_e peekSinkClassID(const std::string& name, const am_sinkClass_t& sinkClassID) =0; + virtual am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID) =0; /** * is called when a low level interrupt changes it status. * @@ -305,12 +305,11 @@ namespace am { */ virtual void hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay) =0; /** - * this function is used to send out all data that has been changed in an early state. - * @return E_OK on success, E_UNKNOWN on error + * this function is used to send out all data that has been changed in an early state. * * @param earlyData */ - virtual am_Error_e sendChangedData(const std::vector& earlyData) =0; + virtual void sendChangedData(const std::vector& earlyData) =0; /** * this function is used to retrieve a pointer to the dBusConnectionWrapper * @return E_OK if pointer is valid, E_UKNOWN if AudioManager was compiled without DBus Support @@ -332,4 +331,4 @@ namespace am { }; } -#endif // !defined(EA_6B5234F4_E3F3_46f3_9B2A_892FD2A0236E__INCLUDED_) +#endif // !defined(EA_21C9D5F3_73BF_4121_9A14_1D76799A05A0__INCLUDED_) diff --git a/includes/routing/RoutingSendInterface.h b/includes/routing/RoutingSendInterface.h index d046709..6c73d4e 100644 --- a/includes/routing/RoutingSendInterface.h +++ b/includes/routing/RoutingSendInterface.h @@ -22,8 +22,8 @@ * * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN */ -#if !defined(EA_E9CE2BB6_7523_49e4_9B57_31E776765683__INCLUDED_) -#define EA_E9CE2BB6_7523_49e4_9B57_31E776765683__INCLUDED_ +#if !defined(EA_A00AD21A_AC6F_456e_B4DC_9C6AF4F44C3D__INCLUDED_) +#define EA_A00AD21A_AC6F_456e_B4DC_9C6AF4F44C3D__INCLUDED_ #include #include @@ -41,7 +41,7 @@ namespace am { * This class implements everything from Audiomanager -> RoutingAdapter * @author christian * @version 1.0 - * @created 26-Jan-2012 6:00:54 PM + * @created 01-Feb-2012 9:42:02 AM */ class RoutingSendInterface { @@ -196,4 +196,4 @@ namespace am { }; } -#endif // !defined(EA_E9CE2BB6_7523_49e4_9B57_31E776765683__INCLUDED_) +#endif // !defined(EA_A00AD21A_AC6F_456e_B4DC_9C6AF4F44C3D__INCLUDED_) -- cgit v1.2.1