summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon
diff options
context:
space:
mode:
authorchristian mueller <christian.ei.mueller@bmw.de>2012-02-01 10:50:15 +0100
committerchristian mueller <christian.ei.mueller@bmw.de>2012-02-01 14:01:29 +0100
commit9f4c15a8e89d798077ca3edf7f786dbc740aa176 (patch)
tree878af38925ee08720418790d85b9938877aa452e /AudioManagerDaemon
parent52a769615e476860f3e4c0196fdf7e5159a7a7c1 (diff)
downloadaudiomanager-9f4c15a8e89d798077ca3edf7f786dbc740aa176.tar.gz
* implemented peeksinkclassIDs and peeksourceclassIDs
* changed interface of both from const to non-const * corrected include headers to c++ style, eg. <cassert> * 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
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--AudioManagerDaemon/include/DatabaseHandler.h3
-rw-r--r--AudioManagerDaemon/include/RoutingReceiver.h6
-rw-r--r--AudioManagerDaemon/src/CommandReceiver.cpp2
-rw-r--r--AudioManagerDaemon/src/ControlSender.cpp2
-rw-r--r--AudioManagerDaemon/src/DBusWrapper.cpp4
-rw-r--r--AudioManagerDaemon/src/DatabaseHandler.cpp212
-rw-r--r--AudioManagerDaemon/src/DatabaseObserver.cpp3
-rw-r--r--AudioManagerDaemon/src/Router.cpp2
-rw-r--r--AudioManagerDaemon/src/RoutingReceiver.cpp20
-rw-r--r--AudioManagerDaemon/src/RoutingSender.cpp2
-rw-r--r--AudioManagerDaemon/src/SocketHandler.cpp17
-rw-r--r--AudioManagerDaemon/src/TelnetServer.cpp2
-rw-r--r--AudioManagerDaemon/src/main.cpp14
-rw-r--r--AudioManagerDaemon/test/CommonFunctions.cpp6
-rw-r--r--AudioManagerDaemon/test/database/databaseTest.cpp51
-rw-r--r--AudioManagerDaemon/test/routing/routingTest.cpp234
-rw-r--r--AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp3
17 files changed, 476 insertions, 107 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<am_EarlyData_s>& earlyData);
+ void sendChangedData(const std::vector<am_EarlyData_s>& 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 <SocketHandler.h>
#include <config.h>
-#include <assert.h>
+#include <cassert>
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 <assert.h>
+#include <cassert>
#include <fstream>
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 <fstream>
#include <sstream>
#include <string>
-#include <assert.h>
-#include <stdlib.h>
+#include <cassert>
+#include <cstdlib>
#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 <assert.h>
+#include <cassert>
#include <vector>
#include <fstream>
#include <sstream>
@@ -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<am_MainSoundProperty_s>::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<am_MainSoundProperty_s>::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<am_MainSoundProperty_s>::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<am_MainSoundProperty_s>::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<am_MainConnection
temp.delay = sqlite3_column_int(query, 4);
std::string statement = command1 + i2s(temp.connectionID);
sqlite3_prepare_v2(mDatabase, statement.c_str(), -1, &query1, NULL);
- while ((eCode = sqlite3_step(query1)) == SQLITE_ROW) //todo: check results of eCode1, eCode2
+ while ((eCode = sqlite3_step(query1)) == SQLITE_ROW)
{
int k = sqlite3_column_int(query1, 0);
sqlite3_bind_int(query2, 1, k);
@@ -2865,6 +2882,7 @@ am_Error_e DatabaseHandler::enterSourceClassDB(am_sourceClass_t & sourceClassID,
am_Error_e DatabaseHandler::enterSystemProperties(const std::vector<am_SystemProperty_s> & listSystemProperties)
{
+ assert(!listSystemProperties.empty());
sqlite3_stmt* query = NULL;
int eCode = 0;
std::vector<am_SystemProperty_s>::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 <assert.h>
+#include <cassert>
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 <assert.h>
+#include <cassert>
#include <algorithm>
#include <vector>
#include <iterator>
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 <assert.h>
+#include <cassert>
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<am_EarlyData_s> & earlyData)
+void RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & 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 <utility>
#include <dirent.h>
#include <dlfcn.h>
-#include <assert.h>
+#include <cassert>
#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 <config.h>
-#include <assert.h>
+#include <cassert>
#include <sys/fcntl.h>
#include <sys/errno.h>
#include <sys/poll.h>
#include <algorithm>
#include <time.h>
#include <features.h>
-#include <signal.h>
+#include <csignal>
#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<pollfd>::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 <assert.h>
+#include <cassert>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
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 <config.h>
@@ -54,13 +52,13 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <stdlib.h>
#include <cstdlib>
-#include <assert.h>
+#include <cstdlib>
+#include <cassert>
#include <fcntl.h>
-#include <signal.h>
-#include <string.h>
-#include <stdio.h>
+#include <csignal>
+#include <cstring>
+#include <cstdio>
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 <assert.h>
+#include <cassert>
#include <sstream>
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<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(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<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;
+
+ 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 <fcntl.h>
#include <sys/un.h>
+//todo: expand test, implement more usecases
+//todo: test removeFD
+
#define SOCK_PATH "/tmp/mysock"
using namespace testing;