update changelog
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / include / CAmRoutingSender.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 Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
16  *
17  * \file CAmRoutingSender.h
18  * For further information see http://www.genivi.org/.
19  *
20  */
21
22 #ifndef ROUTINGSENDER_H_
23 #define ROUTINGSENDER_H_
24
25 #include "routing/IAmRoutingSend.h"
26 #include <map>
27
28 #ifdef UNIT_TEST //this is needed to test RoutingSender
29 #include "../test/IAmRoutingBackdoor.h"
30 #endif
31
32 namespace am
33 {
34
35 class CAmRoutingReceiver;
36
37 /**
38  * Implements the RoutingSendInterface. Loads all plugins and dispatches calls to the plugins
39  */
40 class CAmRoutingSender
41 {
42 public:
43     CAmRoutingSender(const std::vector<std::string>& listOfPluginDirectories);
44     ~CAmRoutingSender();
45
46     am_Error_e removeHandle(const am_Handle_s& handle);
47     am_Error_e addDomainLookup(const am_Domain_s& domainData);
48     am_Error_e addSourceLookup(const am_Source_s& sourceData);
49     am_Error_e addSinkLookup(const am_Sink_s& sinkData);
50     am_Error_e addCrossfaderLookup(const am_Crossfader_s& crossfaderData);
51     am_Error_e removeDomainLookup(const am_domainID_t domainID);
52     am_Error_e removeSourceLookup(const am_sourceID_t sourceID);
53     am_Error_e removeSinkLookup(const am_sinkID_t sinkID);
54     am_Error_e removeCrossfaderLookup(const am_crossfaderID_t crossfaderID);
55     am_Error_e removeConnectionLookup(const am_connectionID_t connectionID);
56
57     am_Error_e startupInterfaces(CAmRoutingReceiver* iRoutingReceiver);
58     void setRoutingReady();
59     void setRoutingRundown();
60     am_Error_e asyncAbort(const am_Handle_s& handle);
61     am_Error_e asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_CustomConnectionFormat_t connectionFormat);
62     am_Error_e asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID);
63     am_Error_e asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time);
64     am_Error_e asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time);
65     am_Error_e asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state);
66     am_Error_e asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty);
67     am_Error_e asyncSetSourceSoundProperties(am_Handle_s& handle, const std::vector<am_SoundProperty_s>& listSoundProperties, const am_sourceID_t sourceID);
68     am_Error_e asyncSetSinkSoundProperties(am_Handle_s& handle, const std::vector<am_SoundProperty_s>& listSoundProperties, const am_sinkID_t sinkID);
69     am_Error_e asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty);
70     am_Error_e asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_CustomRampType_t rampType, const am_time_t time);
71     am_Error_e setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState);
72     am_Error_e getListHandles(std::vector<am_Handle_s> & listHandles) const;
73     am_Error_e getListPlugins(std::vector<std::string>& interfaces) const;
74     void getInterfaceVersion(std::string& version) const;
75     am_Error_e asyncSetVolumes(am_Handle_s& handle, const std::vector<am_Volumes_s>& listVolumes);
76     am_Error_e asyncSetSinkNotificationConfiguration(am_Handle_s& handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration);
77     am_Error_e asyncSetSourceNotificationConfiguration(am_Handle_s& handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration);
78
79     struct InterfaceNamePairs //!< is used to pair interfaces with busnames
80     {
81         IAmRoutingSend* routingInterface; //!< pointer to the routingInterface
82         std::string busName; //!< the busname
83     };
84
85     class am_handleData_c //!< is used to store data related to handles
86     {
87     public:
88         union
89         {
90             am_sinkID_t sinkID;
91             am_sourceID_t sourceID;
92             am_crossfaderID_t crossfaderID;
93             am_connectionID_t connectionID;
94             am_DataType_u volumeID;
95         };
96
97         union
98         {
99             am_SoundProperty_s soundPropery;
100             am_SourceState_e sourceState;
101             am_volume_t volume;
102             am_HotSink_e hotSink;
103             std::vector<am_SoundProperty_s>* soundProperties;
104             std::vector<am_Volumes_s>* listVolumes;
105             am_NotificationConfiguration_s* notificationConfiguration;
106         };
107
108     };
109
110     am_handleData_c returnHandleData(const am_Handle_s handle) const; //!< returns the handle data associated with a handle
111
112 #ifdef UNIT_TEST //this is needed to test RoutingSender
113     friend class IAmRoutingBackdoor;
114 #endif
115
116 private:
117     struct comparator //!< is needed to sort the handles in the map
118     {
119         bool operator()(const am_Handle_s& a, const am_Handle_s& b) const
120         {
121                 return (a.handle<b.handle || (a.handle==b.handle && a.handleType<b.handleType));
122         }
123     };
124
125     am_Handle_s createHandle(const am_handleData_c& handleData, const am_Handle_e type); //!< creates a handle
126     void unloadLibraries(void); //!< unloads all loaded plugins
127
128     typedef std::map<am_domainID_t, IAmRoutingSend*> DomainInterfaceMap; //!< maps domains to interfaces
129     typedef std::map<am_sinkID_t, IAmRoutingSend*> SinkInterfaceMap; //!< maps sinks to interfaces
130     typedef std::map<am_sourceID_t, IAmRoutingSend*> SourceInterfaceMap; //!< maps sources to interfaces
131     typedef std::map<am_crossfaderID_t, IAmRoutingSend*> CrossfaderInterfaceMap; //!< maps crossfaders to interfaces
132     typedef std::map<am_connectionID_t, IAmRoutingSend*> ConnectionInterfaceMap; //!< maps connections to interfaces
133     typedef std::map<uint16_t, IAmRoutingSend*> HandleInterfaceMap; //!< maps handles to interfaces
134     typedef std::map<am_Handle_s, am_handleData_c, comparator> HandlesMap; //!< maps handleData to handles
135
136     int16_t mHandleCount; //!< is used to create handles
137     HandlesMap mlistActiveHandles; //!< list of all currently "running" handles.
138     std::vector<void*> mListLibraryHandles; //!< list of all loaded pluginInterfaces
139     std::vector<InterfaceNamePairs> mListInterfaces; //!< list of busname/interface relation
140     ConnectionInterfaceMap mMapConnectionInterface; //!< map of connection to interfaces
141     CrossfaderInterfaceMap mMapCrossfaderInterface; //!< map of crossfaders to interface
142     DomainInterfaceMap mMapDomainInterface; //!< map of domains to interfaces
143     SinkInterfaceMap mMapSinkInterface; //!< map of sinks to interfaces
144     SourceInterfaceMap mMapSourceInterface; //!< map of sources to interfaces
145     HandleInterfaceMap mMapHandleInterface; //!< map of handles to interfaces
146     CAmRoutingReceiver *mpRoutingReceiver; //!< pointer to routing receiver
147 };
148
149 }
150
151 #endif /* ROUTINGSENDER_H_ */