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