From 9a379652687bacab9a162d89c83829fff411340b Mon Sep 17 00:00:00 2001 From: Jacqueline Molz Date: Wed, 22 Aug 2018 17:26:53 +0200 Subject: Notifying observers of sound properties only by value changes. Fix infinite loop in CAmDltWrapper by logging out enum values exceeding the boundaries. Minor changes: Pull request 36 changed implementation to database macros (review comments) added option "WITH_DATABASE_CHANGE_CHECK" to audiomanagerconfig.h.in whitespace cleanup in test/AmMapHandlerTest/CAmMapHandlerTest.cpp additional cast to uint in DB_UPDATE call in function removeMainConnectionDB to solve error in macro expansion --- AudioManagerCore/src/CAmDatabaseHandlerMap.cpp | 75 ++++++++++++++++++-------- 1 file changed, 52 insertions(+), 23 deletions(-) (limited to 'AudioManagerCore/src/CAmDatabaseHandlerMap.cpp') diff --git a/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp index 8e5c192..4bc94ee 100644 --- a/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp +++ b/AudioManagerCore/src/CAmDatabaseHandlerMap.cpp @@ -33,7 +33,8 @@ #include "CAmRouter.h" #include "CAmDltWrapper.h" -#define __METHOD_NAME__ std::string(std::string("CAmDatabaseHandlerMap::") + __func__) +static std::string __am_className__("CAmDatabaseHandlerMap::"); +#define __METHOD_NAME__ std::string(__am_className__ + __func__) #ifdef WITH_DATABASE_CHANGE_CHECK # define DB_COND_UPDATE_RIE(x, y) \ @@ -1492,26 +1493,37 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSinkSoundPropertyDB(const am_MainSou logError(__METHOD_NAME__, "sinkID must exist"); return (E_NON_EXISTENT); } - + DB_COND_UPDATE_INIT; am_Sink_Database_s &sink = mMappedData.mSinkMap[sinkID]; std::vector::iterator elementIterator = sink.listMainSoundProperties.begin(); for (; elementIterator != sink.listMainSoundProperties.end(); ++elementIterator) { if (elementIterator->type == soundProperty.type) { - DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); - if (sink.cacheMainSoundProperties.size()) + DB_COND_UPDATE(elementIterator->value, soundProperty.value); + if (DB_COND_ISMODIFIED) { - sink.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + if (sink.cacheMainSoundProperties.size()) + { + sink.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + } } break; } } - logVerbose("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); - NOTIFY_OBSERVERS2(dboMainSinkSoundPropertyChanged, sinkID, soundProperty) - return (E_OK); + if (DB_COND_ISMODIFIED) + { + logVerbose("DatabaseHandler::changeMainSinkSoundPropertyDB changed MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); + NOTIFY_OBSERVERS2(dboMainSinkSoundPropertyChanged, sinkID, soundProperty) + return (E_OK); + } + else + { + logVerbose("DatabaseHandler::changeMainSinkSoundPropertyDB called MainSinkSoundProperty of sink:", sinkID, "type:", soundProperty.type, "to:", soundProperty.value); + return (E_NO_CHANGE); + } } am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s &soundProperty, const am_sourceID_t sourceID) @@ -1523,26 +1535,36 @@ am_Error_e CAmDatabaseHandlerMap::changeMainSourceSoundPropertyDB(const am_MainS return (E_NON_EXISTENT); } + DB_COND_UPDATE_INIT; am_Source_Database_s &source = mMappedData.mSourceMap.at(sourceID); std::vector::iterator elementIterator = source.listMainSoundProperties.begin(); for (; elementIterator != source.listMainSoundProperties.end(); ++elementIterator) { if (elementIterator->type == soundProperty.type) { - DB_COND_UPDATE_RIE(elementIterator->value, soundProperty.value); - if (source.cacheMainSoundProperties.size()) + DB_COND_UPDATE(elementIterator->value, soundProperty.value); + if (DB_COND_ISMODIFIED) { - source.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + if (source.cacheMainSoundProperties.size()) + { + source.cacheMainSoundProperties[soundProperty.type] = soundProperty.value; + } } - break; } } - logVerbose("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); - - NOTIFY_OBSERVERS2(dboMainSourceSoundPropertyChanged, sourceID, soundProperty) - return (E_OK); + if (DB_COND_ISMODIFIED) + { + logVerbose("DatabaseHandler::changeMainSourceSoundPropertyDB changed MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); + NOTIFY_OBSERVERS2(dboMainSourceSoundPropertyChanged, sourceID, soundProperty) + return (E_OK); + } + else + { + logVerbose("DatabaseHandler::changeMainSourceSoundPropertyDB called MainSinkSoundProperty of source:", sourceID, "type:", soundProperty.type, "to:", soundProperty.value); + return (E_NO_CHANGE); + } } am_Error_e CAmDatabaseHandlerMap::changeSourceAvailabilityDB(const am_Availability_s &availability, const am_sourceID_t sourceID) @@ -1573,20 +1595,27 @@ am_Error_e CAmDatabaseHandlerMap::changeSourceAvailabilityDB(const am_Availabili am_Error_e CAmDatabaseHandlerMap::changeSystemPropertyDB(const am_SystemProperty_s &property) { + DB_COND_UPDATE_INIT; std::vector::iterator elementIterator = mMappedData.mSystemProperties.begin(); for (; elementIterator != mMappedData.mSystemProperties.end(); ++elementIterator) { if (elementIterator->type == property.type) { - DB_COND_UPDATE_RIE(elementIterator->value, property.value); + DB_COND_UPDATE(elementIterator->value, property.value); } } - logVerbose("DatabaseHandler::changeSystemPropertyDB changed system property"); - - NOTIFY_OBSERVERS1(dboSystemPropertyChanged, property) - - return (E_OK); + if (DB_COND_ISMODIFIED) + { + logVerbose("DatabaseHandler::changeSystemPropertyDB changed system property ", property.type, " to ", property.value); + NOTIFY_OBSERVERS1(dboSystemPropertyChanged, property) + return (E_OK); + } + else + { + logVerbose("DatabaseHandler::changeSystemPropertyDB called for system property ", property.type); + return (E_NO_CHANGE); + } } am_Error_e CAmDatabaseHandlerMap::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID) @@ -1599,7 +1628,7 @@ am_Error_e CAmDatabaseHandlerMap::removeMainConnectionDB(const am_mainConnection } DB_COND_UPDATE_INIT; - DB_COND_UPDATE(mMappedData.mMainConnectionMap[mainConnectionID].mainConnectionID, CS_DISCONNECTED); + DB_COND_UPDATE(mMappedData.mMainConnectionMap[mainConnectionID].mainConnectionID, static_cast(CS_DISCONNECTED)); if (DB_COND_ISMODIFIED) { NOTIFY_OBSERVERS2(dboMainConnectionStateChanged, mainConnectionID, CS_DISCONNECTED) -- cgit v1.2.1