a01164bec77b410d9a0916efd47d0fd768232ddb
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / src / RoutingReceiver.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file RoutingReceiver.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section LicenseRoutingReceiver.h
12 *
13 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
14 * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
15 *
16 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
18 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
19 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
20 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
21 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
22 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
23 *
24 */
25
26 #include "RoutingReceiver.h"
27 #include <assert.h>
28
29 RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender)
30         :mDatabaseHandler(iDatabaseHandler),
31          mRoutingSender(iRoutingSender),
32          mControlSender(iControlSender)
33 {
34         assert(mDatabaseHandler!=0);
35         assert(mRoutingSender!=0);
36         assert(mControlSender!=0);
37 }
38
39
40
41 RoutingReceiver::~RoutingReceiver()
42 {
43 }
44
45
46
47 void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
48 {
49         mRoutingSender->removeHandle(handle);
50         if (error==E_OK)
51         {
52                 mDatabaseHandler->changeConnectionFinal(connectionID);
53         }
54         else
55         {
56                 mDatabaseHandler->removeConnection(connectionID);
57         }
58         mControlSender->cbAckConnect(handle,error);
59 }
60
61
62
63 void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
64 {
65         mRoutingSender->removeHandle(handle);
66         if (error==E_OK)
67         {
68                 mDatabaseHandler->removeConnection(connectionID);
69         }
70         mControlSender->cbAckDisconnect(handle,error);
71 }
72
73
74
75 void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
76 {
77         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
78         if(error==E_OK && handleData.sinkID!=0)
79         {
80                 //todo: check if volume in handleData is same than volume. React to it.
81                 mDatabaseHandler->changeSinkVolume(handleData.sinkID,volume);
82         }
83         mRoutingSender->removeHandle(handle);
84         mControlSender->cbAckSetSinkVolumeChange(handle,volume,error);
85 }
86
87
88
89 void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
90 {
91         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
92         if(error==E_OK && handleData.sourceID!=0)
93         {
94                 //todo: check if volume in handleData is same than volume. React to it.
95                 mDatabaseHandler->changeSourceVolume(handleData.sourceID,volume);
96         }
97         mRoutingSender->removeHandle(handle);
98         mControlSender->cbAckSetSourceVolumeChange(handle,volume,error);
99 }
100
101
102
103 void RoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error)
104 {
105         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
106         if(error==E_OK && handleData.sourceID!=0)
107         {
108                 //todo: check if volume in handleData is same than volume. React to it.
109                 mDatabaseHandler->changeSourceState(handleData.sourceID,handleData.sourceState);
110         }
111         mRoutingSender->removeHandle(handle);
112         mControlSender->cbAckSetSourceState(handle,error);
113 }
114
115
116
117 void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
118 {
119         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
120         if(error==E_OK && handleData.sinkID!=0)
121         {
122                 //todo: check if volume in handleData is same than volume. React to it.
123                 mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery,handleData.sinkID);
124         }
125         mRoutingSender->removeHandle(handle);
126         mControlSender->cbAckSetSinkSoundProperty(handle,error);
127
128 }
129
130
131
132 void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
133 {
134         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
135         if(error==E_OK && handleData.sourceID!=0)
136         {
137                 //todo: check if volume in handleData is same than volume. React to it.
138                 mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery,handleData.sourceID);
139         }
140         mRoutingSender->removeHandle(handle);
141         mControlSender->cbAckSetSourceSoundProperty(handle,error);
142 }
143
144
145
146 void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
147 {
148         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
149         if(error==E_OK && handleData.crossfaderID!=0)
150         {
151                 //todo: check if volume in handleData is same than volume. React to it.
152                 mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID,hotSink);
153         }
154         mRoutingSender->removeHandle(handle);
155         mControlSender->cbAckCrossFade(handle,hotSink,error);
156 }
157
158
159
160 void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
161 {
162         mControlSender->hookSystemSourceVolumeTick(handle,sourceID,volume);
163 }
164
165
166
167 void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
168 {
169         mControlSender->hookSystemSinkVolumeTick(handle,sinkID,volume);
170 }
171
172
173
174 am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID)
175 {
176         return mDatabaseHandler->peekDomain(name,domainID);
177
178 }
179
180
181 am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID)
182 {
183         return mControlSender->hookSystemRegisterDomain(domainData,domainID);
184 }
185
186
187
188 am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID)
189 {
190         return mControlSender->hookSystemDeregisterDomain(domainID);
191 }
192
193
194
195 am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
196 {
197         return mControlSender->hookSystemRegisterGateway(gatewayData,gatewayID);
198 }
199
200
201
202 am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
203 {
204         return mControlSender->hookSystemDeregisterGateway(gatewayID);
205 }
206
207
208
209 am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
210 {
211         return mDatabaseHandler->peekSink(name,sinkID);
212 }
213
214
215
216 am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
217 {
218         return mControlSender->hookSystemRegisterSink(sinkData,sinkID);
219 }
220
221
222
223 am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID)
224 {
225         return mControlSender->hookSystemDeregisterSink(sinkID);
226 }
227
228
229
230 am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID)
231 {
232         return mDatabaseHandler->peekSource(name,sourceID);
233 }
234
235
236
237 am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID)
238 {
239         return mControlSender->hookSystemRegisterSource(sourceData,sourceID);
240 }
241
242
243
244 am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID)
245 {
246         return mControlSender->hookSystemDeregisterSource(sourceID);
247 }
248
249
250
251 am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
252 {
253         return mControlSender->hookSystemRegisterCrossfader(crossfaderData,crossfaderID);
254 }
255
256
257
258 am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID)
259 {
260         return mControlSender->hookSystemDeregisterCrossfader(crossfaderID);
261 }
262
263
264
265 void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
266 {
267         return mControlSender->hookSystemInterruptStateChange(sourceID,interruptState);
268 }
269
270
271
272 void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID)
273 {
274          mControlSender->hookSystemDomainRegistrationComplete(domainID);
275 }
276
277
278
279
280 void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
281 {
282         mControlSender->hookSystemSinkAvailablityStateChange(sinkID,availability);
283 }
284
285
286
287 void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
288 {
289         mControlSender->hookSystemSourceAvailablityStateChange(sourceID,availability);
290 }
291
292
293
294 void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
295 {
296         mControlSender->hookSystemDomainStateChange(domainID,domainState);
297 }
298
299
300
301 void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
302 {
303         mDatabaseHandler->changeConnectionTimingInformation(connectionID,delay);
304 }
305
306
307
308 am_Error_e RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & earlyData)
309 {
310         mControlSender->hookSystemReceiveEarlyData(earlyData);
311         return E_OK;
312         //todo: change return type to void in EA model
313 }
314
315
316
317 am_Error_e RoutingReceiver::peekSinkClassID(const std::string & name, am_sourceClass_t & sourceClassID)
318 {
319         //todo: implement
320 }
321
322 am_Error_e RoutingReceiver::peekSourceClassID(const std::string & name, am_sinkClass_t & sinkClassID)
323 {
324         //todo: implement
325 }
326
327 am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *dbusConnectionWrapper) const
328 {
329         //todo: return DbusWrapper
330 }
331