summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon
diff options
context:
space:
mode:
authorChristian Mueller <christian@lmuc329619u.(none)>2011-12-09 18:43:28 +0100
committerChristian Mueller <christian@lmuc329619u.(none)>2011-12-09 18:43:28 +0100
commitd85e69bbf6d8ec6e087c7af579686923c76079cd (patch)
treee95edbd83f1a7458872dd4ad3df5d346afed7d3a /AudioManagerDaemon
parent5773404eb801e27179b7c3c7803a990145d6e94a (diff)
downloadaudiomanager-d85e69bbf6d8ec6e087c7af579686923c76079cd.tar.gz
Some changes, renaming...
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--AudioManagerDaemon/include/ControlSender.h (renamed from AudioManagerDaemon/include/ControlLoader.h)9
-rw-r--r--AudioManagerDaemon/include/DatabaseHandler.h4
-rw-r--r--AudioManagerDaemon/src/CommandReceiver.cpp10
-rw-r--r--AudioManagerDaemon/src/ControlSender.cpp (renamed from AudioManagerDaemon/src/ControlLoader.cpp)8
-rw-r--r--AudioManagerDaemon/src/DatabaseHandler.cpp86
-rw-r--r--AudioManagerDaemon/src/main.cpp33
-rw-r--r--AudioManagerDaemon/test/databasetest.cpp33
7 files changed, 138 insertions, 45 deletions
diff --git a/AudioManagerDaemon/include/ControlLoader.h b/AudioManagerDaemon/include/ControlSender.h
index 09ffacf..fde029c 100644
--- a/AudioManagerDaemon/include/ControlLoader.h
+++ b/AudioManagerDaemon/include/ControlSender.h
@@ -12,13 +12,10 @@
using namespace am;
-class ControlLoader {
+class ControlSender : private ControlSendInterface {
public:
- ControlLoader();
- virtual ~ControlLoader();
- ControlSendInterface* returnControl();
-private:
- ControlSendInterface* mControler;
+ ControlSender();
+ virtual ~ControlSender();
};
#endif /* CONTROLLOADER_H_ */
diff --git a/AudioManagerDaemon/include/DatabaseHandler.h b/AudioManagerDaemon/include/DatabaseHandler.h
index 6b2c2be..5c99719 100644
--- a/AudioManagerDaemon/include/DatabaseHandler.h
+++ b/AudioManagerDaemon/include/DatabaseHandler.h
@@ -137,10 +137,12 @@ public:
bool existSourceClass(const am_sourceClass_t sourceClassID) const;
private:
+ am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const;
+ bool connectionPartofMainConnection(const am_connectionID_t connectionID,const am_mainConnectionID_t mainConnectionID) const;
bool sqQuery(const std::string& query);
bool openDatabase();
void createTables();
- sqlite3 *mDatabase; //!< pointer to database
+ sqlite3 *mDatabase;
std::string mPath;
bool mFirstStaticSink;
bool mFirstStaticSource;
diff --git a/AudioManagerDaemon/src/CommandReceiver.cpp b/AudioManagerDaemon/src/CommandReceiver.cpp
index b5294bd..604a659 100644
--- a/AudioManagerDaemon/src/CommandReceiver.cpp
+++ b/AudioManagerDaemon/src/CommandReceiver.cpp
@@ -68,7 +68,7 @@ am_Error_e CommandReceiver::setSystemProperty(const am_SystemProperty_s & proper
am_Error_e CommandReceiver::getListMainConnections(std::vector<am_MainConnectionType_s> & listConnections) const
{
- mDatabaseHandler->getListVisibleMainConnections(listConnections);
+ return mDatabaseHandler->getListVisibleMainConnections(listConnections);
}
@@ -76,48 +76,56 @@ am_Error_e CommandReceiver::getListMainConnections(std::vector<am_MainConnection
am_Error_e CommandReceiver::getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const
{
+ return mDatabaseHandler->getListMainSinks(listMainSinks);
}
am_Error_e CommandReceiver::getListMainSources(std::vector<am_SourceType_s>& listMainSources) const
{
+ return mDatabaseHandler->getListMainSources(listMainSources);
}
am_Error_e CommandReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s> & listSoundProperties) const
{
+ return mDatabaseHandler->getListMainSinkSoundProperties(sinkID,listSoundProperties);
}
am_Error_e CommandReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s> & listSourceProperties) const
{
+ return mDatabaseHandler->getListMainSourceSoundProperties(sourceID,listSourceProperties);
}
am_Error_e CommandReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
{
+ return mDatabaseHandler->getListSourceClasses(listSourceClasses);
}
am_Error_e CommandReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
{
+ return mDatabaseHandler->getListSinkClasses(listSinkClasses);
}
am_Error_e CommandReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
{
+ return mDatabaseHandler->getListSystemProperties(listSystemProperties);
}
am_Error_e CommandReceiver::getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t & delay) const
{
+ return mDatabaseHandler->getTimingInformation(mainConnectionID,delay);
}
diff --git a/AudioManagerDaemon/src/ControlLoader.cpp b/AudioManagerDaemon/src/ControlSender.cpp
index 8f5e5ea..bd3787b 100644
--- a/AudioManagerDaemon/src/ControlLoader.cpp
+++ b/AudioManagerDaemon/src/ControlSender.cpp
@@ -5,11 +5,11 @@
* Author: christian
*/
-#include "ControlLoader.h"
+#include "ControlSender.h"
#include "pluginTemplate.h"
#include <string>
-ControlLoader::ControlLoader()
+ControlSender::ControlSender()
{
ControlSendInterface* (*createFunc)();
std::string libPath="/home/christian/workspace/gitserver/build/plugins/control/libPluginControlInterface.so";
@@ -29,13 +29,13 @@ ControlLoader::ControlLoader()
-ControlLoader::~ControlLoader()
+ControlSender::~ControlSender()
{
}
-ControlSendInterface *ControlLoader::returnControl()
+ControlSendInterface *ControlSender::returnControl()
{
return mControler;
}
diff --git a/AudioManagerDaemon/src/DatabaseHandler.cpp b/AudioManagerDaemon/src/DatabaseHandler.cpp
index 948ff94..2284717 100644
--- a/AudioManagerDaemon/src/DatabaseHandler.cpp
+++ b/AudioManagerDaemon/src/DatabaseHandler.cpp
@@ -2801,7 +2801,7 @@ am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectio
{
assert(connectionID!=0);
- sqlite3_stmt* query=NULL;
+ sqlite3_stmt *query=NULL, *queryMainConnections;
int eCode=0;
std::string command= "UPDATE " + std::string(CONNECTION_TABLE) + " set delay=? WHERE connectionID=?";
@@ -2811,20 +2811,98 @@ am_Error_e DatabaseHandler::changeConnectionTimingInformation(const am_connectio
if((eCode=sqlite3_step(query))!=SQLITE_DONE)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Step error code:"),DLT_INT(eCode));
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Step error code:"),DLT_INT(eCode));
return E_DATABASE_ERROR;
}
if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
{
- DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::enterConnectionDB SQLITE Finalize error code:"),DLT_INT(eCode));
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
+ return E_DATABASE_ERROR;
+ }
+
+ //now we need to find all mainConnections that use the changed connection and update their timing
+ am_mainConnectionID_t mainConnectionID;
+ am_timeSync_t tempDelay=0;
+ am_Error_e error;
+ command= "SELECT mainConnectionID FROM " + std::string(MAINCONNECTION_TABLE);
+ sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&queryMainConnections,NULL);
+
+ while((eCode=sqlite3_step(queryMainConnections))==SQLITE_ROW)
+ {
+ mainConnectionID=sqlite3_column_int(queryMainConnections,0);
+ if(connectionPartofMainConnection(connectionID,mainConnectionID))
+ {
+ tempDelay=calculateMainConnectionDelay(mainConnectionID);
+ if ((error=changeDelayMainConnection(tempDelay,mainConnectionID))!= E_OK)
+ {
+ return error;
+ }
+ }
+ }
+
+ if(eCode!=SQLITE_DONE)
+ {
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE error code:"),DLT_INT(eCode));
+ return E_DATABASE_ERROR;
+ }
+
+ if((eCode=sqlite3_finalize(queryMainConnections))!=SQLITE_OK)
+ {
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::changeConnectionTimingInformation SQLITE Finalize error code:"),DLT_INT(eCode));
return E_DATABASE_ERROR;
}
- //todo: add DLT Info Message here
return E_OK;
}
+bool DatabaseHandler::connectionPartofMainConnection(const am_connectionID_t connectionID, const am_mainConnectionID_t mainConnectionID) const
+{
+ sqlite3_stmt* query=NULL;
+ std::string command = "SELECT connectionID FROM MainConnectionRoute"+ int2string(mainConnectionID)+ " WHERE connectionID=" + int2string(connectionID);
+ int eCode=0;
+ bool returnVal=true;
+ sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
+ if ((eCode=sqlite3_step(query))==SQLITE_DONE) returnVal=false;
+ else if (eCode!=SQLITE_ROW)
+ {
+ returnVal=false;
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::connectionPartofMainConnection database error!:"), DLT_INT(eCode))
+ }
+ sqlite3_finalize(query);
+ return returnVal;
+}
+
+am_timeSync_t DatabaseHandler::calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const
+{
+ assert (mainConnectionID!=0);
+ sqlite3_stmt* query=NULL;
+ std::string command = "SELECT delay FROM MainConnectionRoute"+ int2string(mainConnectionID);
+ int eCode=0;
+ am_timeSync_t delay=0;
+ sqlite3_prepare_v2(mDatabase,command.c_str(),-1,&query,NULL);
+ while((eCode=sqlite3_step(query))==SQLITE_ROW)
+ {
+ int16_t temp_delay=sqlite3_column_int(query,0);
+ if (temp_delay!=-1 && delay!=-1) delay+=temp_delay;
+ else delay=-1;
+ }
+ if((eCode=sqlite3_step(query))!=SQLITE_DONE)
+ {
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Step error code:"),DLT_INT(eCode));
+ return E_DATABASE_ERROR;
+ }
+
+ if((eCode=sqlite3_finalize(query))!=SQLITE_OK)
+ {
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("DatabaseHandler::calculateMainConnectionDelay SQLITE Finalize error code:"),DLT_INT(eCode));
+ return E_DATABASE_ERROR;
+ }
+
+ if (delay==0) delay=-1;
+ return delay;
+}
+
void DatabaseHandler::createTables()
{
for(uint16_t i=0;i<sizeof(databaseTables)/sizeof(databaseTables[0]);i++)
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index ef5da21..3aa5f8b 100644
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -6,15 +6,16 @@
*/
//todo: add debug commandline option to allow to use other than memory database
+//todo: make real daemon out of it- systemd conform
+
#include "RoutingReceiver.h"
#include "CommandReceiver.h"
#include "ControlReceiver.h"
#include "DatabaseHandler.h"
-#include "control/ControlSendInterface.h"
-#include "DBusWrapper.h"
-#include "ControlLoader.h"
+#include "ControlSender.h"
#include "CommandSender.h"
#include "RoutingSender.h"
+#include "DBusWrapper.h"
#include <dbus/dbus.h>
#include <dlt/dlt.h>
@@ -36,32 +37,6 @@ int main(int argc, char *argv[])
RoutingSender iRoutingSender;
CommandSender iCommandSender;
- am_Connection_s lowCon;
- am_connectionID_t cID;
- lowCon.connectionID=0;
- lowCon.sinkID=2;
- lowCon.sourceID=3;
- lowCon.connectionFormat=CF_ANALOG;
- lowCon.delay=-1;
- iDatabaseHandler.enterConnectionDB(lowCon,cID);
-
- am_RoutingElement_s re;
- re.connectionFormat=CF_ANALOG;
- re.domainID=1;
- re.sinkID=2;
- re.sourceID=3;
-
- am_MainConnection_s con;
- am_mainConnectionID_t mainC;
- con.connectionID=0;
- con.connectionState=CS_CONNECTING;
- con.route.sinkID=2;
- con.route.sourceID=3;
- con.route.route.push_back(re);
- iControlReceiver.enterMainConnectionDB(con,mainC);
- //ControlLoader iControlLoader;
-// ControlSendInterface* iControlSender =iControlLoader.returnControl();
-
iCommandSender.startupInterface(&iCommandReceiver);
diff --git a/AudioManagerDaemon/test/databasetest.cpp b/AudioManagerDaemon/test/databasetest.cpp
index 25599cd..29f8e98 100644
--- a/AudioManagerDaemon/test/databasetest.cpp
+++ b/AudioManagerDaemon/test/databasetest.cpp
@@ -421,6 +421,39 @@ void databaseTest::createMainConnectionSetup()
ASSERT_EQ(true,equal);
}
+TEST_F(databaseTest,changeConnectionTimingInformationCheckMainConnection)
+{
+ am_Connection_s connection;
+ am_connectionID_t connectionID;
+ std::vector<am_Connection_s> connectionList;
+ std::vector<am_MainConnectionType_s> mainList;
+ createConnection(connection);
+ createMainConnectionSetup();
+ ASSERT_EQ(-E_OK,pDatabaseHandler.getListVisibleMainConnections(mainList));
+ ASSERT_EQ(mainList[0].delay,-1);
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
+ std::vector<am_Connection_s>::iterator iteratorConnectionList=connectionList.begin();
+ for(;iteratorConnectionList<connectionList.end();++iteratorConnectionList)
+ {
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeConnectionTimingInformation(iteratorConnectionList->sinkID,24));
+ }
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListVisibleMainConnections(mainList));
+ ASSERT_NE(mainList[0].delay,-1);
+}
+
+TEST_F(databaseTest,changeConnectionTimingInformation)
+{
+ am_Connection_s connection;
+ am_connectionID_t connectionID;
+ std::vector<am_Connection_s> connectionList;
+ createConnection(connection);
+
+ ASSERT_EQ(E_OK,pDatabaseHandler.enterConnectionDB(connection,connectionID));
+ ASSERT_EQ(E_OK,pDatabaseHandler.changeConnectionTimingInformation(connectionID,24));
+ ASSERT_EQ(E_OK,pDatabaseHandler.getListConnections(connectionList));
+ ASSERT_TRUE(connectionList[0].delay==24);
+}
+
TEST_F(databaseTest,getSinkClassOfSink)
{
std::vector<am_SinkClass_s> sinkClassList;