* CAmDatabaseHandlerMap - the main connection now have separate method for id generation.
authorAleksander Donchev <aleksander.donchev@partner.bmw.de>
Tue, 13 Aug 2013 14:52:21 +0000 (16:52 +0200)
committerAleksander Donchev <aleksander.donchev@partner.bmw.de>
Wed, 14 Aug 2013 13:30:45 +0000 (15:30 +0200)
Signed-off-by: Christian Linke <christian.linke@bmw.de>
AudioManagerDaemon/include/CAmDatabaseHandlerMap.h
AudioManagerDaemon/src/CAmDatabaseHandlerMap.cpp

index a928b93..28ec7e6 100644 (file)
@@ -269,7 +269,7 @@ public:
      * The following structure groups the map objects needed for the implementation.
      * Every map object is coupled with an identifier, which hold the current value.
      * DYNAMIC_ID_BOUNDARY is used as initial value everywhere a dynamic id is considered .
-     * The ID's can be increased through the method increaseID(...), which follows the AudioManager logic.
+     * The IDs can be increased through the method increaseID(...), which follows the AudioManager logic.
      * For more information about the static and dynamic IDs, please see the documentation.
      */
     typedef struct CAmMappedData
@@ -310,7 +310,7 @@ public:
        /**
         * \brief Increases a given map ID.
         *
-        * A common method implementing the logic for static and dynamic IDs.
+        * A common method implementing the logic for static and dynamic IDs except main connection ID.
         *
         * @param resultID Pointer to an output variable.
         * @param sourceID Pointer to ID, which will be manipulated.
@@ -321,6 +321,13 @@ public:
         */
        bool increaseID(int16_t * resultID, int16_t * sourceID,
                                                int16_t const desiredStaticID, int16_t const preferedStaticIDBoundary );
+       /**
+                * \brief Increases the main connection ID.
+                *
+                * @param resultID Pointer to an output variable.
+                * @return TRUE on successfully changed ID.
+                */
+       bool increaseMainConnectionID(int16_t * resultID);
 
         template <class TPrintObject> static void print (const TPrintObject & t, std::ostream & output)
         {
index d659ae6..c7a888d 100644 (file)
@@ -345,15 +345,17 @@ void CAmDatabaseHandlerMap::CAmCrossfader::getDescription (std::string & outStri
        outString = fmt.str();
 }
 
-bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t * resultID, int16_t * sourceID,
-                                                                                                       int16_t const desiredStaticID = 0, int16_t const preferedStaticIDBoundary = DYNAMIC_ID_BOUNDARY)
+bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t * resultID,
+                                                                                                                        int16_t * sourceID,
+                                                                                                                        int16_t const desiredStaticID = 0,
+                                                                                                                        int16_t const preferedStaticIDBoundary = DYNAMIC_ID_BOUNDARY)
 {
        if( desiredStaticID > 0 && desiredStaticID < preferedStaticIDBoundary )
        {
                *resultID = desiredStaticID;
                return true;
        }
-       else if( *sourceID < mDefaultIDLimit-1 ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved.
+       else if( *sourceID < mDefaultIDLimit ) //The last used value is 'limit' - 1. e.g. SHRT_MAX - 1, SHRT_MAX is reserved.
        {
                *resultID = (*sourceID)++;
                return true;
@@ -365,19 +367,39 @@ bool CAmDatabaseHandlerMap::CAmMappedData::increaseID(int16_t * resultID, int16_
        }
  }
 
-/**
- * template to converts T to std::string
- * @param x T
- * @return string
- */
-template<typename T>
-inline std::string i2s(T const& x)
+bool CAmDatabaseHandlerMap::CAmMappedData::increaseMainConnectionID(int16_t * resultID)
 {
-    std::ostringstream o;
-    o << x;
-    return (o.str());
+       am_mainConnectionID_t nextID;
+       am_mainConnectionID_t const lastID = mCurrentMainConnectionID;
+       if( mCurrentMainConnectionID < mDefaultIDLimit )
+               nextID = mCurrentMainConnectionID++;
+       else
+               nextID = mCurrentMainConnectionID = 1;
+
+       bool notFreeIDs = false;
+       while( existsObjectWithKeyInMap(nextID, mMainConnectionMap) )
+       {
+               if( mCurrentMainConnectionID < mDefaultIDLimit )
+                       nextID = mCurrentMainConnectionID++;
+               else
+                       nextID = mCurrentMainConnectionID = 1;
+
+               if( mCurrentMainConnectionID == lastID )
+               {
+                       notFreeIDs = true;
+                       break;
+               }
+       }
+       if(notFreeIDs)
+       {
+               *resultID = -1;
+               return false;
+       }
+       *resultID = nextID;
+       return true;
 }
 
+
 CAmDatabaseHandlerMap::CAmDatabaseHandlerMap():        mFirstStaticSink(true), //
                                                                                                                mFirstStaticSource(true), //
                                                                                                                mFirstStaticGateway(true), //
@@ -470,7 +492,7 @@ am_Error_e CAmDatabaseHandlerMap::enterMainConnectionDB(const am_MainConnection_
 
     int16_t delay = 0;
     int16_t nextID = 0;
-       if(mMappedData.increaseID(&nextID, &mMappedData.mCurrentMainConnectionID))
+       if(mMappedData.increaseMainConnectionID(&nextID))
        {
                connectionID = nextID;
                mMappedData.mMainConnectionMap[nextID] = mainConnectionData;