diff options
author | Alexandar Donchev <Aleksander.Donchev@partner.bmw.de> | 2015-03-11 19:10:54 +0100 |
---|---|---|
committer | Alexandar Donchev <Aleksander.Donchev@partner.bmw.de> | 2015-03-11 19:10:54 +0100 |
commit | c628fa5304171cd827f56aa475668d99d26ad28a (patch) | |
tree | fda6587626ce2ebfaed367ce767eddc6f3f6d3de /AudioManagerDaemon/src | |
parent | 3ff140d47796839b0d733d2ec83a638bb5d06bb1 (diff) | |
download | audiomanager-c628fa5304171cd827f56aa475668d99d26ad28a.tar.gz |
* Sound property lookup enhancement throught caching . Tests for cached sound properties.
Signed-off-by: Christian Linke <christian.linke@bmw.de>
Signed-off-by: Alexandar Donchev <Aleksander.Donchev@partner.bmw.de>>
Diffstat (limited to 'AudioManagerDaemon/src')
-rw-r--r-- | AudioManagerDaemon/src/CAmControlReceiver.cpp | 48 | ||||
-rw-r--r-- | AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp | 156 | ||||
-rw-r--r-- | AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp | 121 |
3 files changed, 295 insertions, 30 deletions
diff --git a/AudioManagerDaemon/src/CAmControlReceiver.cpp b/AudioManagerDaemon/src/CAmControlReceiver.cpp index f576f5e..6ac7e0a 100644 --- a/AudioManagerDaemon/src/CAmControlReceiver.cpp +++ b/AudioManagerDaemon/src/CAmControlReceiver.cpp @@ -695,5 +695,53 @@ NsmErrorStatus_e CAmControlReceiver::sendLifecycleRequestCompleteNSM(const uint3 } +am_Error_e CAmControlReceiver::getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s>& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListMainSinkSoundProperties was called, sinkID", sinkID); + return (mDatabaseHandler->getListMainSinkSoundProperties(sinkID,listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s>& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListMainSourceSoundProperties was called, sourceID", sourceID); + return (mDatabaseHandler->getListMainSourceSoundProperties(sourceID, listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListSinkSoundProperties was called, sinkID", sinkID); + return (mDatabaseHandler->getListSinkSoundProperties(sinkID,listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + logInfo("CAmControlReceiver::getListSourceSoundProperties was called, sourceID", sourceID); + return (mDatabaseHandler->getListSourceSoundProperties(sourceID, listSoundproperties)); +} + +am_Error_e CAmControlReceiver::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getMainSinkSoundPropertyValue was called, sinkID", sinkID); + return (mDatabaseHandler->getMainSinkSoundPropertyValue(sinkID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getSinkSoundPropertyValue was called, sinkID", sinkID); + return (mDatabaseHandler->getSinkSoundPropertyValue(sinkID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getMainSourceSoundPropertyValue was called, sourceID", sourceID); + return (mDatabaseHandler->getMainSourceSoundPropertyValue(sourceID,propertyType,value)); +} + +am_Error_e CAmControlReceiver::getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const +{ + logInfo("CAmControlReceiver::getSourceSoundPropertyValue was called, sourceID", sourceID); + return (mDatabaseHandler->getSourceSoundPropertyValue(sourceID,propertyType,value)); +} + } diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp index 73daef4..864ae8c 100644 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp @@ -1177,12 +1177,17 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSinkSoundPropertyDB(const am_MainSou { return (E_NON_EXISTENT); } - - std::vector<am_MainSoundProperty_s>::iterator elementIterator = mMappedData.mSinkMap[sinkID].listMainSoundProperties.begin(); - for (;elementIterator != mMappedData.mSinkMap[sinkID].listMainSoundProperties.end(); ++elementIterator) + am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; + std::vector<am_MainSoundProperty_s>::iterator elementIterator = sink.listMainSoundProperties.begin(); + for (;elementIterator != sink.listMainSoundProperties.end(); ++elementIterator) { if (elementIterator->type == soundProperty.type) + { elementIterator->value = soundProperty.value; + if(sink.cacheMainSoundProperties.size()) + sink.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + break; + } } logInfo("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); @@ -1199,12 +1204,17 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainS { return (E_NON_EXISTENT); } - - std::vector<am_MainSoundProperty_s>::iterator elementIterator = mMappedData.mSourceMap[sourceID].listMainSoundProperties.begin(); - for (;elementIterator != mMappedData.mSourceMap[sourceID].listMainSoundProperties.end(); ++elementIterator) + am_Source_Database_s & source = mMappedData.mSourceMap.at(sourceID); + std::vector<am_MainSoundProperty_s>::iterator elementIterator = source.listMainSoundProperties.begin(); + for (;elementIterator != source.listMainSoundProperties.end(); ++elementIterator) { if (elementIterator->type == soundProperty.type) + { elementIterator->value = soundProperty.value; + if(source.cacheMainSoundProperties.size()) + source.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + break; + } } logInfo("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); @@ -1867,6 +1877,30 @@ am_Error_e CAmDatabaseHandlerMap::getListMainSourceSoundProperties(const am_sour return (E_OK); } +am_Error_e CAmDatabaseHandlerMap::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return E_NON_EXISTENT; + + am_Sink_Database_s sink = mMappedData.mSinkMap.at(sinkID); + listSoundproperties = sink.listSoundProperties; + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerMap::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return E_NON_EXISTENT; + + am_Source_Database_s source = mMappedData.mSourceMap.at(sourceID); + listSoundproperties = source.listSoundProperties; + + return (E_OK); +} + am_Error_e CAmDatabaseHandlerMap::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const { listSystemProperties = mMappedData.mSystemProperties; @@ -2326,17 +2360,20 @@ am_Error_e CAmDatabaseHandlerMap::getSinkSoundPropertyValue(const am_sinkID_t si { assert(sinkID!=0); - am_Sink_Database_s const * source = objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); - if( NULL!=source ) + am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=pObject ) { - std::vector<am_SoundProperty_s>::const_iterator iter = source->listSoundProperties.begin(); - for(; iter<source->listSoundProperties.end(); ++iter) + if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) { - if( propertyType == iter->type ) - { - value = iter->value; - return (E_OK); - } + std::vector<am_SoundProperty_s>::const_iterator iter = pObject->listSoundProperties.begin(); + for(; iter<pObject->listSoundProperties.end(); ++iter) + pObject->cacheSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheSoundProperties.find(propertyType); + if(it!=pObject->cacheSoundProperties.end()) + { + value = it->second; + return (E_OK); } } value = -1; @@ -2347,23 +2384,75 @@ am_Error_e CAmDatabaseHandlerMap::getSourceSoundPropertyValue(const am_sourceID_ { assert(sourceID!=0); - am_Source_Database_s const * source = objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); - if( NULL!=source ) + am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=pObject ) { - std::vector<am_SoundProperty_s>::const_iterator iter = source->listSoundProperties.begin(); - for(; iter<source->listSoundProperties.end(); ++iter) + if(pObject->listSoundProperties.size()>0 && 0==pObject->cacheSoundProperties.size()) { - if( propertyType == iter->type ) - { - value = iter->value; - return (E_OK); - } + std::vector<am_SoundProperty_s>::const_iterator iter = pObject->listSoundProperties.begin(); + for(; iter<pObject->listSoundProperties.end(); ++iter) + pObject->cacheSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheSoundProperties.find(propertyType); + if(it!=pObject->cacheSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + value = -1; + return (E_NON_EXISTENT); +} + +am_Error_e CAmDatabaseHandlerMap::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sinkID!=0); + + am_Sink_Database_s * pObject = (am_Sink_Database_s *)objectForKeyIfExistsInMap(sinkID, mMappedData.mSinkMap); + if( NULL!=pObject ) + { + if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) + { + std::vector<am_MainSoundProperty_s>::const_iterator iter = pObject->listMainSoundProperties.begin(); + for(; iter<pObject->listMainSoundProperties.end(); ++iter) + pObject->cacheMainSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheMainSoundProperties.find(propertyType); + if(it!=pObject->cacheMainSoundProperties.end()) + { + value = it->second; + return (E_OK); } } value = -1; return (E_NON_EXISTENT); } +am_Error_e CAmDatabaseHandlerMap::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sourceID!=0); + + am_Source_Database_s * pObject = (am_Source_Database_s *)objectForKeyIfExistsInMap(sourceID, mMappedData.mSourceMap); + if( NULL!=pObject ) + { + if(pObject->listMainSoundProperties.size()>0 && 0==pObject->cacheMainSoundProperties.size()) + { + std::vector<am_MainSoundProperty_s>::const_iterator iter = pObject->listMainSoundProperties.begin(); + for(; iter<pObject->listMainSoundProperties.end(); ++iter) + pObject->cacheMainSoundProperties[iter->type] = iter->value; + } + auto it = pObject->cacheMainSoundProperties.find(propertyType); + if(it!=pObject->cacheMainSoundProperties.end()) + { + value = it->second; + return (E_OK); + } + } + + value = -1; + return (E_NON_EXISTENT); +} + am_Error_e CAmDatabaseHandlerMap::getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const { assert(domainID!=0); @@ -2505,12 +2594,15 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceSoundPropertyDB(const am_SoundProp return (E_NON_EXISTENT); } - std::vector<am_SoundProperty_s>::iterator iter = mMappedData.mSourceMap[sourceID].listSoundProperties.begin(); - for(; iter<mMappedData.mSourceMap[sourceID].listSoundProperties.end(); ++iter) + am_Source_Database_s & source = mMappedData.mSourceMap[sourceID]; + std::vector<am_SoundProperty_s>::iterator iter = source.listSoundProperties.begin(); + for(; iter<source.listSoundProperties.end(); ++iter) { if( soundProperty.type == iter->type ) { iter->value = soundProperty.value; + if(source.cacheSoundProperties.size()) + source.cacheSoundProperties[soundProperty.type] = soundProperty.value; return (E_OK); } } @@ -2525,13 +2617,15 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkSoundPropertyDB(const am_SoundProper { return (E_NON_EXISTENT); } - - std::vector<am_SoundProperty_s>::iterator iter = mMappedData.mSinkMap[sinkID].listSoundProperties.begin(); - for(; iter<mMappedData.mSinkMap[sinkID].listSoundProperties.end(); ++iter) + am_Sink_Database_s & sink = mMappedData.mSinkMap[sinkID]; + std::vector<am_SoundProperty_s>::iterator iter = sink.listSoundProperties.begin(); + for(; iter<sink.listSoundProperties.end(); ++iter) { if( soundProperty.type == iter->type ) { iter->value = soundProperty.value; + if(sink.cacheSoundProperties.size()) + sink.cacheSoundProperties[soundProperty.type] = soundProperty.value; return (E_OK); } } @@ -2621,6 +2715,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceDB(const am_sourceID_t sourceID, c if (!listSoundProperties.empty()) { mMappedData.mSourceMap.at(sourceID).listSoundProperties = listSoundProperties; + mMappedData.mSourceMap.at(sourceID).cacheSoundProperties.clear(); } //check if we have to update the list of connectionformats @@ -2634,6 +2729,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceDB(const am_sourceID_t sourceID, c { mMappedData.mSourceMap.at(sourceID).listMainSoundProperties = listMainSoundProperties; + mMappedData.mSourceMap.at(sourceID).cacheMainSoundProperties.clear(); } else //read out the properties { @@ -2679,6 +2775,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkDB(const am_sinkID_t sinkID, const a if (!listSoundProperties.empty()) { mMappedData.mSinkMap.at(sinkID).listSoundProperties = listSoundProperties; + mMappedData.mSinkMap.at(sinkID).cacheSoundProperties.clear(); } //check if we have to update the list of connectionformats @@ -2691,6 +2788,7 @@ am_Error_e CAmDatabaseHandlerMap::changeSinkDB(const am_sinkID_t sinkID, const a if (!listMainSoundProperties.empty() && sinkVisible(sinkID)) { mMappedData.mSinkMap.at(sinkID).listMainSoundProperties = listMainSoundProperties; + mMappedData.mSinkMap.at(sinkID).cacheSoundProperties.clear(); } else //read out the properties { diff --git a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp index cb95ec6..da86386 100644 --- a/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp +++ b/AudioManagerDaemon/src/CAmDatabaseHandlerSQLite.cpp @@ -2880,7 +2880,71 @@ am_Error_e CAmDatabaseHandlerSQLite::getListMainSourceSoundProperties(const am_s if (eCode != SQLITE_DONE) { - logError("DatabaseHandler::getListMainSinkSoundProperties SQLITE error code:", eCode); + logError("DatabaseHandler::getListMainSourceSoundProperties SQLITE error code:", eCode); + MY_SQLITE_FINALIZE(query) + return (E_DATABASE_ERROR); + } + + MY_SQLITE_FINALIZE(query) + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerSQLite::getListSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences + listSoundproperties.clear(); + + sqlite3_stmt* query = NULL; + int eCode = 0; + am_SoundProperty_s temp; + std::string command = "SELECT soundPropertyType, value FROM SinkSoundProperty" + i2s(sinkID); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(query, 0); + temp.value = sqlite3_column_int(query, 1); + listSoundproperties.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSinkSoundProperties SQLITE error code:", eCode); + MY_SQLITE_FINALIZE(query) + return (E_DATABASE_ERROR); + } + + MY_SQLITE_FINALIZE(query) + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerSQLite::getListSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_SoundProperty_s>& listSoundproperties) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existen, but not shown in sequences + listSoundproperties.clear(); + + sqlite3_stmt* query = NULL; + int eCode = 0; + am_SoundProperty_s temp; + std::string command = "SELECT soundPropertyType, value FROM SourceSoundProperty" + i2s(sourceID); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + temp.type = (am_CustomMainSoundPropertyType_t) sqlite3_column_int(query, 0); + temp.value = sqlite3_column_int(query, 1); + listSoundproperties.push_back(temp); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getListSourceSoundProperties SQLITE error code:", eCode); MY_SQLITE_FINALIZE(query) return (E_DATABASE_ERROR); } @@ -4042,6 +4106,61 @@ am_Error_e CAmDatabaseHandlerSQLite::getSourceVolume(const am_sourceID_t sourceI return (E_OK); } +am_Error_e CAmDatabaseHandlerSQLite::getMainSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sinkID!=0); + if (!existSink(sinkID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT value FROM SinkMainSoundProperty" + i2s(sinkID) + " WHERE soundPropertyType=" + i2s(propertyType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + if ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + value = sqlite3_column_int(query, 0); + } + else + { + logError("DatabaseHandler::getDomainState database error!:", eCode); + MY_SQLITE_FINALIZE(query) + return (E_DATABASE_ERROR); + } + + MY_SQLITE_FINALIZE(query) + + return (E_OK); +} + +am_Error_e CAmDatabaseHandlerSQLite::getMainSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomMainSoundPropertyType_t propertyType, int16_t& value) const +{ + assert(sourceID!=0); + if (!existSource(sourceID)) + return (E_DATABASE_ERROR); // todo: here we could change to non existent, but not shown in sequences + + sqlite3_stmt* query = NULL; + int eCode = 0; + std::string command = "SELECT value FROM SourceMainSoundProperty" + i2s(sourceID) + " WHERE soundPropertyType=" + i2s(propertyType); + MY_SQLITE_PREPARE_V2(mpDatabase, command.c_str(), -1, &query, NULL) + + while ((eCode = sqlite3_step(query)) == SQLITE_ROW) + { + value = sqlite3_column_int(query, 0); + } + + if (eCode != SQLITE_DONE) + { + logError("DatabaseHandler::getSinkSoundPropertyValue SQLITE error code:", eCode); + MY_SQLITE_FINALIZE(query) + return (E_DATABASE_ERROR); + } + + MY_SQLITE_FINALIZE(query) + + return (E_OK); +} + am_Error_e CAmDatabaseHandlerSQLite::getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t & value) const { assert(sinkID!=0); |