update changelog
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / include / CAmDatabaseHandlerMap.h
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * This file is part of GENIVI Project AudioManager.
5  *
6  * Contributions are licensed to the GENIVI Alliance under one or more
7  * Contribution License Agreements.
8  *
9  * \copyright
10  * This Source Code Form is subject to the terms of the
11  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
12  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  *
15 * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
16  *
17  * \file CAmDatabaseHandlerMap.h
18  * For further information see http://www.genivi.org/.
19  *
20  */
21
22 #ifndef MAPHANDLER_H_
23 #define MAPHANDLER_H_
24
25 #include <stdint.h>
26 #include <limits.h>
27 #include <sstream>
28 #include <iostream>
29 #include <unordered_map>
30 #include "IAmDatabaseHandler.h"
31 #include <cassert>
32
33 namespace am
34 {
35 #ifndef AM_MAP_CAPACITY
36         #define AM_MAP_CAPACITY 0
37 #endif
38
39 #ifndef AM_MAX_CONNECTIONS
40         #define AM_MAX_CONNECTIONS 0x1000
41 #endif
42
43 #ifndef AM_MAX_MAIN_CONNECTIONS
44         #define AM_MAX_MAIN_CONNECTIONS SHRT_MAX
45 #endif
46
47
48
49 //todo: check the enum values before entering & changing in the database.
50 //todo: change asserts for dynamic boundary checks into failure answers.#
51 //todo: check autoincrement boundary and set to 16bit limits
52 //todo: If the sink is part of a gateway, the listconnectionFormats is copied to the gatewayInformation. Check this statement for sinks & sources
53 //todo: exchange last_insert_row id to be more safe
54 //todo: create test to ensure uniqueness of names throughout the database
55 //todo: enforce the uniqueness of names
56
57 /**
58  * This class handles and abstracts the database
59  */
60 class CAmDatabaseHandlerMap : public IAmDatabaseHandler
61 {
62     bool mFirstStaticSink; //!< bool for dynamic range handling
63     bool mFirstStaticSource; //!< bool for dynamic range handling
64     bool mFirstStaticGateway; //!< bool for dynamic range handling
65     bool mFirstStaticSinkClass; //!< bool for dynamic range handling
66     bool mFirstStaticSourceClass; //!< bool for dynamic range handling
67     bool mFirstStaticCrossfader; //!< bool for dynamic range handling
68
69 public:
70         CAmDatabaseHandlerMap();
71     virtual ~CAmDatabaseHandlerMap();
72     am_Error_e enterDomainDB(const am_Domain_s& domainData, am_domainID_t& domainID);
73     am_Error_e enterMainConnectionDB(const am_MainConnection_s& mainConnectionData, am_mainConnectionID_t& connectionID);
74     am_Error_e enterSinkDB(const am_Sink_s& sinkData, am_sinkID_t& sinkID);
75     am_Error_e enterCrossfaderDB(const am_Crossfader_s& crossfaderData, am_crossfaderID_t& crossfaderID);
76     am_Error_e enterGatewayDB(const am_Gateway_s& gatewayData, am_gatewayID_t& gatewayID);
77     am_Error_e enterSourceDB(const am_Source_s& sourceData, am_sourceID_t& sourceID);
78     am_Error_e enterConnectionDB(const am_Connection_s& connection, am_connectionID_t& connectionID);
79     am_Error_e enterSinkClassDB(const am_SinkClass_s& sinkClass, am_sinkClass_t& sinkClassID);
80     am_Error_e enterSourceClassDB(am_sourceClass_t& sourceClassID, const am_SourceClass_s& sourceClass);
81     am_Error_e enterSystemProperties(const std::vector<am_SystemProperty_s>& listSystemProperties);
82     am_Error_e changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const std::vector<am_connectionID_t>& listConnectionID);
83     am_Error_e changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState);
84     am_Error_e changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID);
85     am_Error_e changeSinkAvailabilityDB(const am_Availability_s& availability, const am_sinkID_t sinkID);
86     am_Error_e changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID);
87     am_Error_e changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID);
88     am_Error_e changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sinkID_t sinkID);
89     am_Error_e changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s& soundProperty, const am_sourceID_t sourceID);
90     am_Error_e changeSourceSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sourceID_t sourceID);
91     am_Error_e changeSinkSoundPropertyDB(const am_SoundProperty_s& soundProperty, const am_sinkID_t sinkID);
92     am_Error_e changeSourceAvailabilityDB(const am_Availability_s& availability, const am_sourceID_t sourceID);
93     am_Error_e changeSystemPropertyDB(const am_SystemProperty_s& property);
94     am_Error_e changeDelayMainConnection(const am_timeSync_t & delay, const am_mainConnectionID_t & connectionID);
95     am_Error_e changeSinkClassInfoDB(const am_SinkClass_s& sinkClass);
96     am_Error_e changeSourceClassInfoDB(const am_SourceClass_s& sourceClass);
97     am_Error_e changeConnectionTimingInformation(const am_connectionID_t connectionID, const am_timeSync_t delay);
98     am_Error_e changeConnectionFinal(const am_connectionID_t connectionID);
99     am_Error_e changeSourceState(const am_sourceID_t sourceID, const am_SourceState_e sourceState);
100     am_Error_e changeSinkVolume(const am_sinkID_t sinkID, const am_volume_t volume);
101     am_Error_e changeSourceVolume(const am_sourceID_t sourceID, const am_volume_t volume);
102     am_Error_e changeCrossFaderHotSink(const am_crossfaderID_t crossfaderID, const am_HotSink_e hotsink);
103     am_Error_e removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID);
104     am_Error_e removeSinkDB(const am_sinkID_t sinkID);
105     am_Error_e removeSourceDB(const am_sourceID_t sourceID);
106     am_Error_e removeGatewayDB(const am_gatewayID_t gatewayID);
107     am_Error_e removeCrossfaderDB(const am_crossfaderID_t crossfaderID);
108     am_Error_e removeDomainDB(const am_domainID_t domainID);
109     am_Error_e removeSinkClassDB(const am_sinkClass_t sinkClassID);
110     am_Error_e removeSourceClassDB(const am_sourceClass_t sourceClassID);
111     am_Error_e removeConnection(const am_connectionID_t connectionID);
112     am_Error_e getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s& classInfo) const;
113     am_Error_e getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s& sinkClass) const;
114     am_Error_e getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s& gatewayData) const;
115     am_Error_e getSinkInfoDB(const am_sinkID_t sinkID, am_Sink_s& sinkData) const;
116     am_Error_e getSourceInfoDB(const am_sourceID_t sourceID, am_Source_s& sourceData) const;
117     am_Error_e getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s& crossfaderData) const;
118     am_Error_e getMainConnectionInfoDB(const am_mainConnectionID_t mainConnectionID, am_MainConnection_s& mainConnectionData) const;
119     am_Error_e getSinkVolume(const am_sinkID_t sinkID, am_volume_t& volume) const;
120     am_Error_e getSourceVolume(const am_sourceID_t sourceID, am_volume_t& volume) const;
121     am_Error_e getSinkSoundPropertyValue(const am_sinkID_t sinkID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const;
122     am_Error_e getSourceSoundPropertyValue(const am_sourceID_t sourceID, const am_CustomSoundPropertyType_t propertyType, int16_t& value) const;
123     am_Error_e getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t>& listSinkID) const;
124     am_Error_e getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t>& listSourceID) const;
125     am_Error_e getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t>& listGatewaysID) const;
126     am_Error_e getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t>& listGatewaysID) const;
127     am_Error_e getListMainConnections(std::vector<am_MainConnection_s>& listMainConnections) const;
128     am_Error_e getListDomains(std::vector<am_Domain_s>& listDomains) const;
129     am_Error_e getListConnections(std::vector<am_Connection_s>& listConnections) const;
130     am_Error_e getListSinks(std::vector<am_Sink_s>& listSinks) const;
131     am_Error_e getListSources(std::vector<am_Source_s>& lisSources) const;
132     am_Error_e getListSourceClasses(std::vector<am_SourceClass_s>& listSourceClasses) const;
133     am_Error_e getListCrossfaders(std::vector<am_Crossfader_s>& listCrossfaders) const;
134     am_Error_e getListGateways(std::vector<am_Gateway_s>& listGateways) const;
135     am_Error_e getListSinkClasses(std::vector<am_SinkClass_s>& listSinkClasses) const;
136     am_Error_e getListVisibleMainConnections(std::vector<am_MainConnectionType_s>& listConnections) const;
137     am_Error_e getListMainSinks(std::vector<am_SinkType_s>& listMainSinks) const;
138     am_Error_e getListMainSources(std::vector<am_SourceType_s>& listMainSources) const;
139     am_Error_e getListMainSinkSoundProperties(const am_sinkID_t sinkID, std::vector<am_MainSoundProperty_s>& listSoundProperties) const;
140     am_Error_e getListMainSourceSoundProperties(const am_sourceID_t sourceID, std::vector<am_MainSoundProperty_s>& listSourceProperties) const;
141     am_Error_e getListSystemProperties(std::vector<am_SystemProperty_s>& listSystemProperties) const;
142     am_Error_e getListSinkConnectionFormats(const am_sinkID_t sinkID, std::vector<am_CustomAvailabilityReason_t> & listConnectionFormats) const;
143     am_Error_e getListSourceConnectionFormats(const am_sourceID_t sourceID, std::vector<am_CustomAvailabilityReason_t> & listConnectionFormats) const;
144     am_Error_e getListGatewayConnectionFormats(const am_gatewayID_t gatewayID, std::vector<bool> & listConnectionFormat) const;
145     am_Error_e getTimingInformation(const am_mainConnectionID_t mainConnectionID, am_timeSync_t& delay) const;
146     am_Error_e getDomainOfSource(const am_sourceID_t sourceID, am_domainID_t& domainID) const;
147     am_Error_e getDomainOfSink(const am_sinkID_t sinkID, am_domainID_t& domainID) const;
148     am_Error_e getSoureState(const am_sourceID_t sourceID, am_SourceState_e& sourceState) const;
149     am_Error_e getDomainState(const am_domainID_t domainID, am_DomainState_e& state) const;
150     am_Error_e getRoutingTree(bool onlyfree, CAmRoutingTree& tree, std::vector<CAmRoutingTreeItem*>& flatTree);
151     am_Error_e peekDomain(const std::string& name, am_domainID_t& domainID);
152     am_Error_e peekSink(const std::string& name, am_sinkID_t& sinkID);
153     am_Error_e peekSource(const std::string& name, am_sourceID_t& sourceID);
154     am_Error_e peekSinkClassID(const std::string& name, am_sinkClass_t& sinkClassID);
155     am_Error_e peekSourceClassID(const std::string& name, am_sourceClass_t& sourceClassID);
156     am_Error_e changeSourceDB(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomAvailabilityReason_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties);
157     am_Error_e changeSinkDB(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector<am_SoundProperty_s>& listSoundProperties, const std::vector<am_CustomAvailabilityReason_t>& listConnectionFormats, const std::vector<am_MainSoundProperty_s>& listMainSoundProperties);
158     am_Error_e getListMainSinkNotificationConfigurations(const am_sinkID_t sinkID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations);
159     am_Error_e getListMainSourceNotificationConfigurations(const am_sourceID_t sourceID, std::vector<am_NotificationConfiguration_s>& listMainNotificationConfigurations);
160     am_Error_e changeMainSinkNotificationConfigurationDB(const am_sinkID_t sinkID, const am_NotificationConfiguration_s mainNotificationConfiguration);
161     am_Error_e changeMainSourceNotificationConfigurationDB(const am_sourceID_t sourceID, const am_NotificationConfiguration_s mainNotificationConfiguration);
162     am_Error_e changeGatewayDB(const am_gatewayID_t gatewayID, const std::vector<am_CustomAvailabilityReason_t>& listSourceConnectionFormats, const std::vector<am_CustomAvailabilityReason_t>& listSinkConnectionFormats, const std::vector<bool>& convertionMatrix);
163     am_Error_e changeSinkNotificationConfigurationDB(const am_sinkID_t sinkID,const am_NotificationConfiguration_s notificationConfiguration);
164     am_Error_e changeSourceNotificationConfigurationDB(const am_sourceID_t sourceID,const am_NotificationConfiguration_s notificationConfiguration);
165
166     bool existMainConnection(const am_mainConnectionID_t mainConnectionID) const;
167     bool existcrossFader(const am_crossfaderID_t crossfaderID) const;
168     bool existConnection(const am_Connection_s & connection) const;
169     bool existConnectionID(const am_connectionID_t connectionID) const;
170     bool existSource(const am_sourceID_t sourceID) const;
171     bool existSourceNameOrID(const am_sourceID_t sourceID, const std::string& name) const;
172     bool existSourceName(const std::string& name) const;
173     bool existSink(const am_sinkID_t sinkID) const;
174     bool existSinkNameOrID(const am_sinkID_t sinkID, const std::string& name) const;
175     bool existSinkName(const std::string& name) const;
176     bool existDomain(const am_domainID_t domainID) const;
177     bool existGateway(const am_gatewayID_t gatewayID) const;
178     bool existSinkClass(const am_sinkClass_t sinkClassID) const;
179     bool existSourceClass(const am_sourceClass_t sourceClassID) const;
180     void registerObserver(CAmDatabaseObserver *iObserver);
181     bool sourceVisible(const am_sourceID_t sourceID) const;
182     bool sinkVisible(const am_sinkID_t sinkID) const;
183
184     void dump( std::ostream & output ) const;
185     /**
186      * The following structures extend the base structures with the field 'reserved'.
187      */
188
189 #define AM_TYPEDEF_SUBCLASS_BEGIN(Subclass, Class) \
190         typedef struct Subclass : public Class\
191         {\
192                 Subclass & operator=(const Subclass & anObject) \
193                         {\
194                                 if (this != &anObject)\
195                     {\
196                                         Class::operator=(anObject);\
197                     }\
198                     return *this;\
199                 };\
200                 Subclass & operator=(const Class & anObject)\
201                 {\
202                     if (this != &anObject)\
203                         Class::operator=(anObject);\
204                     return *this;\
205                 };\
206                 void getDescription (std::string & outString) const;\
207
208 #define AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(Subclass, Class) \
209             typedef struct Subclass : public Class\
210             {\
211                 bool reserved;\
212                 Subclass():Class(), reserved(false)\
213                 {};\
214                 Subclass & operator=(const Subclass & anObject)\
215                 {\
216                     if (this != &anObject)\
217                     {\
218                         Class::operator=(anObject);\
219                         reserved = anObject.reserved;\
220                     }\
221                     return *this;\
222                 };\
223                 Subclass & operator=(const Class & anObject)\
224                 {\
225                     if (this != &anObject)\
226                     Class::operator=(anObject);\
227                     return *this;\
228                 };\
229                 void getDescription (std::string & outString) const;\
230
231 #define AM_TYPEDEF_SUBCLASS_END(Typedef) } Typedef; \
232
233     AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Domain_Database_s,am_Domain_s)
234     AM_TYPEDEF_SUBCLASS_END(CAmDomain)
235
236     AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Sink_Database_s,am_Sink_s)
237         void getSinkType(am_SinkType_s & sinkType) const;\
238     AM_TYPEDEF_SUBCLASS_END(CAmSink)
239
240     AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Source_Database_s,am_Source_s)
241         void getSourceType(am_SourceType_s & sourceType) const;\
242     AM_TYPEDEF_SUBCLASS_END(CAmSource)
243
244     AM_TYPEDEF_SUBCLASS_RESERVED_FLAG_BEGIN(am_Connection_Database_s,am_Connection_s)
245     AM_TYPEDEF_SUBCLASS_END(CAmConnection)
246
247     /**
248       * The following structures extend the base structures with print capabilities.
249     */
250     AM_TYPEDEF_SUBCLASS_BEGIN(am_MainConnection_Database_s, am_MainConnection_s)
251         void getMainConnectionType(am_MainConnectionType_s & connectionType) const;\
252     AM_TYPEDEF_SUBCLASS_END(CAmMainConnection)
253
254         AM_TYPEDEF_SUBCLASS_BEGIN(am_SourceClass_Database_s, am_SourceClass_s)
255         AM_TYPEDEF_SUBCLASS_END(CAmSourceClass)
256
257         AM_TYPEDEF_SUBCLASS_BEGIN(am_SinkClass_Database_s, am_SinkClass_s)
258         AM_TYPEDEF_SUBCLASS_END(CAmSinkClass)
259
260         AM_TYPEDEF_SUBCLASS_BEGIN(am_Gateway_Database_s, am_Gateway_s)
261         AM_TYPEDEF_SUBCLASS_END(CAmGateway)
262
263         AM_TYPEDEF_SUBCLASS_BEGIN(am_Crossfader_Database_s, am_Crossfader_s)
264         AM_TYPEDEF_SUBCLASS_END(CAmCrossfader)
265
266     private:
267     typedef std::unordered_map<am_domainID_t, CAmDomain>                                                 CAmMapDomain;
268     typedef std::unordered_map<am_sourceClass_t, CAmSourceClass>                                 CAmMapSourceClass;
269     typedef std::unordered_map<am_sinkClass_t, CAmSinkClass>                                 CAmMapSinkClass;
270     typedef std::unordered_map<am_sinkID_t, CAmSink>                                                     CAmMapSink;
271     typedef std::unordered_map<am_sourceID_t, CAmSource>                                                 CAmMapSource;
272     typedef std::unordered_map<am_gatewayID_t, CAmGateway>                                               CAmMapGateway;
273     typedef std::unordered_map<am_crossfaderID_t, CAmCrossfader>                         CAmMapCrossfader;
274     typedef std::unordered_map<am_connectionID_t, CAmConnection>                                 CAmMapConnection;
275     typedef std::unordered_map<am_mainConnectionID_t, CAmMainConnection>                 CAmMapMainConnection;
276     typedef std::vector<am_SystemProperty_s>                                                                 CAmVectorSystemProperties;
277     /**
278      * The following structure groups the map objects needed for the implementation.
279      * Every map object is coupled with an identifier, which hold the current value.
280      * DYNAMIC_ID_BOUNDARY is used as initial value everywhere a dynamic id is considered .
281      * The IDs can be increased through the method increaseID(...), which follows the AudioManager logic.
282      * For more information about the static and dynamic IDs, please see the documentation.
283      */
284     typedef struct CAmMappedData
285     {
286         /**
287          * The structure encapsulates the id boundary and the current id value.
288          * It defines a range within the id can vary.
289          */
290         struct am_Identifier_s
291         {
292                 int16_t mMin;                   //!< min possible value
293                 int16_t mMax;                   //!< max possible value
294                 int16_t mCurrentValue;  //!< current value
295
296                 am_Identifier_s():mMin(DYNAMIC_ID_BOUNDARY), mMax(SHRT_MAX), mCurrentValue(mMin){};
297                 am_Identifier_s(const int16_t & min, const int16_t &  max):mMin(min), mMax(max), mCurrentValue(mMin){assert(min<max);};
298         };
299
300         am_Identifier_s mCurrentDomainID;                       //!< domain ID
301         am_Identifier_s mCurrentSourceClassesID;        //!< source classes ID
302         am_Identifier_s mCurrentSinkClassesID;          //!< sink classes ID
303         am_Identifier_s mCurrentSinkID;                         //!< sink ID
304         am_Identifier_s mCurrentSourceID;                       //!< source ID
305         am_Identifier_s mCurrentGatewayID;                      //!< gateway ID
306         am_Identifier_s mCurrentCrossfaderID;           //!< crossfader ID
307         am_Identifier_s mCurrentConnectionID;           //!< connection ID
308         am_Identifier_s mCurrentMainConnectionID;       //!< mainconnection ID
309
310         CAmVectorSystemProperties mSystemProperties; //!< vector with system properties
311         CAmMapDomain mDomainMap;                                         //!< map for domain structures
312         CAmMapSourceClass mSourceClassesMap;             //!< map for source classes structures
313         CAmMapSinkClass mSinkClassesMap;                         //!< map for sink classes structures
314         CAmMapSink mSinkMap;                                             //!< map for sink structures
315         CAmMapSource mSourceMap;                                         //!< map for source structures
316         CAmMapGateway mGatewayMap;                                       //!< map for gateway structures
317         CAmMapCrossfader mCrossfaderMap;                         //!< map for crossfader structures
318         CAmMapConnection mConnectionMap;                         //!< map for connection structures
319         CAmMapMainConnection mMainConnectionMap;         //!< map for main connection structures
320
321         CAmMappedData(): //For Domain, MainConnections, Connections we don't have static IDs.
322                 mCurrentDomainID(1, SHRT_MAX),
323                 mCurrentSourceClassesID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
324                 mCurrentSinkClassesID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
325                 mCurrentSinkID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
326                 mCurrentSourceID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
327                 mCurrentGatewayID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
328                 mCurrentCrossfaderID(DYNAMIC_ID_BOUNDARY, SHRT_MAX),
329                 mCurrentConnectionID(1, AM_MAX_CONNECTIONS),
330                 mCurrentMainConnectionID(1, AM_MAX_MAIN_CONNECTIONS),
331
332                 mSystemProperties(),
333                         mDomainMap(),mSourceClassesMap(), mSinkClassesMap(), mSinkMap(AM_MAP_CAPACITY), mSourceMap(AM_MAP_CAPACITY),
334                         mGatewayMap(), mCrossfaderMap(), mConnectionMap(), mMainConnectionMap()
335         {};
336         /**
337          * \brief Increases a given map ID.
338          *
339          * A common method implementing the logic for static and dynamic IDs except main connection ID.
340          *
341          * @param resultID Pointer to an output variable.
342          * @param sourceID Pointer to ID, which will be manipulated.
343          * @param desiredStaticID Not 0 for static IDs and 0 for dynamic IDs.
344          *                                                Usually the static IDs are in interval [1 , DYNAMIC_ID_BOUNDARY]. Default is 0.
345          * @param preferedStaticIDBoundary A limit for a given dynamic ID. Default is DYNAMIC_ID_BOUNDARY.
346          * @return TRUE on successfully changed ID.
347          */
348         bool increaseID(int16_t & resultID, am_Identifier_s & sourceID, int16_t const desiredStaticID);
349         /**
350                  * \brief Increases the main connection ID.
351                  *
352                  * @param resultID Pointer to an output variable.
353                  * @return TRUE on successfully changed ID.
354                  */
355         bool increaseMainConnectionID(int16_t & resultID);
356
357         /**
358                  * \brief Increases the connection ID.
359                  *
360                  * @param resultID Pointer to an output variable.
361                  * @return TRUE on successfully changed ID.
362                  */
363         bool increaseConnectionID(int16_t & resultID);
364
365         template <class TPrintObject> static void print (const TPrintObject & t, std::ostream & output)
366         {
367                 std::string description;
368                 t.getDescription( description );
369                 output << description;
370         }
371         template <typename TPrintMapKey,class TPrintMapObject> static void printMap (const std::unordered_map<TPrintMapKey, TPrintMapObject> & t, std::ostream & output)
372         {
373                 typename std::unordered_map<TPrintMapKey, TPrintMapObject>::const_iterator iter = t.begin();
374                 for(; iter!=t.end(); iter++)
375                         CAmMappedData::print(iter->second, output);
376         }
377     private:
378         template <typename TMapKey,class TMapObject> bool getNextConnectionID(int16_t & resultID, am_Identifier_s & sourceID,
379                                                                                                                                                                   const std::unordered_map<TMapKey, TMapObject> & map);
380     } CAmMappedData;
381     /*
382      * Helper methods.
383      */
384     am_timeSync_t calculateMainConnectionDelay(const am_mainConnectionID_t mainConnectionID) const; //!< calculates a new main connection delay
385     int16_t calculateDelayForRoute(const std::vector<am_connectionID_t>& listConnectionID);
386     bool insertSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID);
387     bool insertCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID);
388     bool insertGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID);
389     bool insertSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID);
390     bool insertSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID);
391     bool insertSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass);
392     const am_Sink_Database_s * sinkWithNameOrID(const am_sinkID_t sinkID, const std::string & name) const;
393     const am_Source_Database_s * sourceWithNameOrID(const am_sourceID_t sourceID, const std::string & name) const;
394
395     CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer
396     ListConnectionFormat mListConnectionFormat; //!< list of connection formats
397     CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class
398 #ifdef UNIT_TEST
399     public:
400     void setConnectionIDRange(const int16_t & min, const int16_t &  max)
401         {
402                 mMappedData.mCurrentConnectionID.mMin = min;
403                 mMappedData.mCurrentConnectionID.mMax = max;
404         }
405         void setMainConnectionIDRange(const int16_t & min, const int16_t &  max)
406         {
407                 mMappedData.mCurrentMainConnectionID.mMin = min;
408                 mMappedData.mCurrentMainConnectionID.mMax = max;
409         }
410         void setSinkIDRange(const int16_t & min, const int16_t &  max)
411         {
412                 mMappedData.mCurrentSinkID.mMin = min;
413                 mMappedData.mCurrentSinkID.mMax = max;
414         }
415 #endif
416 };
417
418 }
419
420 #endif /* MAPHANDLER_H_ */