93fd9251606c0b8c9d4007a2e0e7b8abb8218ccc
[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 <SocketHandler.h>
28 #ifdef WITH_DBUS_WRAPPER
29 #include <dbus/DBusWrapper.h>
30 #endif
31 #include "DatabaseHandler.h"
32 #include "RoutingSender.h"
33 #include "ControlSender.h"
34 #include <assert.h>
35
36 using namespace am;
37
38 am::RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler)
39         :mDatabaseHandler(iDatabaseHandler),
40          mRoutingSender(iRoutingSender),
41          mControlSender(iControlSender),
42          mSocketHandler(iSocketHandler)
43 {
44 assert(mDatabaseHandler!=NULL);
45 assert(mRoutingSender!=NULL);
46 assert(mControlSender!=NULL);
47 assert(mSocketHandler!=NULL);
48 }
49
50 am::RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, DBusWrapper *iDBusWrapper)
51         :mDatabaseHandler(iDatabaseHandler),
52          mRoutingSender(iRoutingSender),
53          mControlSender(iControlSender),
54          mDBusWrapper(iDBusWrapper)
55 {
56 assert(mDatabaseHandler!=NULL);
57 assert(mRoutingSender!=NULL);
58 assert(mControlSender!=NULL);
59 assert(mDBusWrapper!=NULL);
60 }
61
62 am::RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler, DBusWrapper *iDBusWrapper)
63         :mDatabaseHandler(iDatabaseHandler),
64          mRoutingSender(iRoutingSender),
65          mControlSender(iControlSender),
66          mSocketHandler(iSocketHandler),
67          mDBusWrapper(iDBusWrapper)
68 {
69 assert(mDatabaseHandler!=NULL);
70 assert(mRoutingSender!=NULL);
71 assert(mControlSender!=NULL);
72 assert(mSocketHandler!=NULL);
73 assert(mDBusWrapper!=NULL);
74 }
75
76
77
78 RoutingReceiver::~RoutingReceiver()
79 {
80 }
81
82
83
84 void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
85 {
86         mRoutingSender->removeHandle(handle);
87         if (error==E_OK)
88         {
89                 mDatabaseHandler->changeConnectionFinal(connectionID);
90         }
91         else
92         {
93                 mDatabaseHandler->removeConnection(connectionID);
94         }
95         mControlSender->cbAckConnect(handle,error);
96 }
97
98
99
100 void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
101 {
102         mRoutingSender->removeHandle(handle);
103         if (error==E_OK)
104         {
105                 mDatabaseHandler->removeConnection(connectionID);
106         }
107         mControlSender->cbAckDisconnect(handle,error);
108 }
109
110
111
112 void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
113 {
114         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
115         if(error==E_OK && handleData.sinkID!=0)
116         {
117                 //todo: check if volume in handleData is same than volume. React to it.
118                 mDatabaseHandler->changeSinkVolume(handleData.sinkID,volume);
119         }
120         mRoutingSender->removeHandle(handle);
121         mControlSender->cbAckSetSinkVolumeChange(handle,volume,error);
122 }
123
124
125
126 void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
127 {
128         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
129         if(error==E_OK && handleData.sourceID!=0)
130         {
131                 //todo: check if volume in handleData is same than volume. React to it.
132                 mDatabaseHandler->changeSourceVolume(handleData.sourceID,volume);
133         }
134         mRoutingSender->removeHandle(handle);
135         mControlSender->cbAckSetSourceVolumeChange(handle,volume,error);
136 }
137
138
139
140 void RoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error)
141 {
142         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
143         if(error==E_OK && handleData.sourceID!=0)
144         {
145                 //todo: check if volume in handleData is same than volume. React to it.
146                 mDatabaseHandler->changeSourceState(handleData.sourceID,handleData.sourceState);
147         }
148         mRoutingSender->removeHandle(handle);
149         mControlSender->cbAckSetSourceState(handle,error);
150 }
151
152
153
154 void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
155 {
156         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
157         if(error==E_OK && handleData.sinkID!=0)
158         {
159                 mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery,handleData.sinkID);
160         }
161         mRoutingSender->removeHandle(handle);
162         mControlSender->cbAckSetSinkSoundProperty(handle,error);
163
164 }
165
166 void am::RoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error)
167 {
168         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
169         if(error==E_OK && handleData.sinkID!=0)
170         {
171                 std::vector<am_SoundProperty_s>::const_iterator it=handleData.soundProperties->begin();
172                 for(;it!=handleData.soundProperties->end();++it)
173                 {
174                         mDatabaseHandler->changeSinkSoundPropertyDB(*it,handleData.sinkID);
175                 }
176                 delete handleData.soundProperties;
177         }
178         mRoutingSender->removeHandle(handle);
179         mControlSender->cbAckSetSinkSoundProperties(handle,error);
180 }
181
182
183 void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
184 {
185         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
186         if(error==E_OK && handleData.sourceID!=0)
187         {
188                 mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery,handleData.sourceID);
189         }
190         mRoutingSender->removeHandle(handle);
191         mControlSender->cbAckSetSourceSoundProperty(handle,error);
192 }
193
194
195 void am::RoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error)
196 {
197         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
198         if(error==E_OK && handleData.sourceID!=0)
199         {
200                 std::vector<am_SoundProperty_s>::const_iterator it=handleData.soundProperties->begin();
201                 for(;it!=handleData.soundProperties->end();++it)
202                 {
203                         mDatabaseHandler->changeSourceSoundPropertyDB(*it,handleData.sourceID);
204                 }
205                 delete handleData.soundProperties;
206         }
207         mRoutingSender->removeHandle(handle);
208         mControlSender->cbAckSetSourceSoundProperties(handle,error);
209 }
210
211 void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
212 {
213         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
214         if(error==E_OK && handleData.crossfaderID!=0)
215         {
216                 //todo: check if volume in handleData is same than volume. React to it.
217                 mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID,hotSink);
218         }
219         mRoutingSender->removeHandle(handle);
220         mControlSender->cbAckCrossFade(handle,hotSink,error);
221 }
222
223
224
225 void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
226 {
227         mControlSender->hookSystemSourceVolumeTick(handle,sourceID,volume);
228 }
229
230
231
232 void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
233 {
234         mControlSender->hookSystemSinkVolumeTick(handle,sinkID,volume);
235 }
236
237
238
239 am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID)
240 {
241         return mDatabaseHandler->peekDomain(name,domainID);
242
243 }
244
245
246 am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID)
247 {
248         return mControlSender->hookSystemRegisterDomain(domainData,domainID);
249 }
250
251
252
253 am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID)
254 {
255         return mControlSender->hookSystemDeregisterDomain(domainID);
256 }
257
258
259
260 am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
261 {
262         return mControlSender->hookSystemRegisterGateway(gatewayData,gatewayID);
263 }
264
265
266
267 am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
268 {
269         return mControlSender->hookSystemDeregisterGateway(gatewayID);
270 }
271
272
273
274 am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
275 {
276         return mDatabaseHandler->peekSink(name,sinkID);
277 }
278
279
280
281 am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
282 {
283         return mControlSender->hookSystemRegisterSink(sinkData,sinkID);
284 }
285
286
287
288 am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID)
289 {
290         return mControlSender->hookSystemDeregisterSink(sinkID);
291 }
292
293
294
295 am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID)
296 {
297         return mDatabaseHandler->peekSource(name,sourceID);
298 }
299
300
301
302 am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID)
303 {
304         return mControlSender->hookSystemRegisterSource(sourceData,sourceID);
305 }
306
307
308
309 am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID)
310 {
311         return mControlSender->hookSystemDeregisterSource(sourceID);
312 }
313
314
315
316 am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
317 {
318         return mControlSender->hookSystemRegisterCrossfader(crossfaderData,crossfaderID);
319 }
320
321
322
323 am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID)
324 {
325         return mControlSender->hookSystemDeregisterCrossfader(crossfaderID);
326 }
327
328
329
330 void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
331 {
332         return mControlSender->hookSystemInterruptStateChange(sourceID,interruptState);
333 }
334
335
336
337 void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID)
338 {
339          mControlSender->hookSystemDomainRegistrationComplete(domainID);
340 }
341
342
343
344 void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
345 {
346         mControlSender->hookSystemSinkAvailablityStateChange(sinkID,availability);
347 }
348
349
350
351 void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
352 {
353         mControlSender->hookSystemSourceAvailablityStateChange(sourceID,availability);
354 }
355
356
357
358 void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
359 {
360         mControlSender->hookSystemDomainStateChange(domainID,domainState);
361 }
362
363
364
365 void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
366 {
367         mDatabaseHandler->changeConnectionTimingInformation(connectionID,delay);
368 }
369
370
371
372 am_Error_e RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & earlyData)
373 {
374         mControlSender->hookSystemReceiveEarlyData(earlyData);
375         return E_OK;
376         //todo: change return type to void in EA model
377 }
378
379
380
381 am_Error_e RoutingReceiver::peekSinkClassID(const std::string name, const am_sinkClass_t& sinkClassID)
382 {
383         //todo: implement
384         return E_NOT_USED;
385 }
386
387 am_Error_e RoutingReceiver::peekSourceClassID(const std::string name, const am_sourceClass_t& sourceClassID)
388 {
389         //todo: implement
390         return E_NOT_USED;
391 }
392
393 am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *& dbusConnectionWrapper) const
394 {
395 #ifdef WITH_DBUS_WRAPPER
396         dbusConnectionWrapper=mDBusWrapper;
397         return E_OK;
398 #else
399         return E_UNKNOWN;
400 #endif
401 }
402
403
404 am_Error_e RoutingReceiver::getSocketHandler(SocketHandler *& socketHandler) const
405 {
406 #ifdef WITH_SOCKETHANDLER_LOOP
407         socketHandler=mSocketHandler;
408         return E_OK;
409 #else
410         return E_UNKNOWN;
411 #endif
412 }
413
414 uint16_t RoutingReceiver::getInterfaceVersion() const
415 {
416         return RoutingReceiveVersion;
417 }
418
419
420
421
422