efa24e196ebc008a242e207ecdc8135be3b1f609
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / src / ControlReceiver.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file ControlReceiver.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section License
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
14 *
15 * 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.
16 * 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.
17 * 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>.
18 * 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.
19 * 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.
20 * 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.
21 * 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.
22 *
23 */
24
25 #include "ControlReceiver.h"
26 #include <dlt/dlt.h>
27 #include <assert.h>
28
29 DLT_IMPORT_CONTEXT(AudioManager)
30
31 ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender)
32         : mDatabaseHandler(iDatabaseHandler),
33           mRoutingSender(iRoutingSender),
34           mCommandSender(iCommandSender)
35 {
36         assert(mDatabaseHandler!=NULL);
37         assert(mRoutingSender!=NULL);
38         assert(mCommandSender!=NULL);
39 }
40
41 ControlReceiver::~ControlReceiver()
42 {
43 }
44
45 am_Error_e ControlReceiver::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s> & returnList)
46 {
47         //todo: implement routing algorithm
48 }
49
50
51
52 am_Error_e ControlReceiver::connect(am_Handle_s & handle, am_connectionID_t & connectionID, const am_ConnectionFormat_e format, const am_sourceID_t sourceID, const am_sinkID_t sinkID)
53 {
54         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::connect got called, connectionFormat"),DLT_INT(format),DLT_STRING("sourceID"),DLT_INT(sourceID),DLT_STRING("sinkID"),DLT_INT(sinkID));
55
56         am_Connection_s tempConnection;
57         tempConnection.sinkID=sinkID;
58         tempConnection.sourceID=sourceID;
59         tempConnection.connectionFormat=format;
60         tempConnection.connectionID=0;
61
62         if (mDatabaseHandler->existConnection(tempConnection)) return E_ALREADY_EXISTS; //todo:enter the correct connectionID here?
63
64         mDatabaseHandler->enterConnectionDB(tempConnection,connectionID);
65         return mRoutingSender->asyncConnect(handle,connectionID,sourceID,sinkID,format);
66 }
67
68
69
70 am_Error_e ControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID)
71 {
72         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::disconnect got called, connectionID="),DLT_INT(connectionID));
73
74         if (!mDatabaseHandler->existConnectionID(connectionID)) return E_NON_EXISTENT;   //todo: check with EA model and correct
75         return mRoutingSender->asyncDisconnect(handle,connectionID);
76 }
77
78
79
80 am_Error_e ControlReceiver::crossfade(am_Handle_s & handle, const am_HotSink_e hotSource, const am_crossfaderID_t crossfaderID, const am_RampType_e rampType, const am_time_t rampTime)
81 {
82         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::crossfade got called, hotSource="),DLT_INT(hotSource),DLT_STRING("crossfaderID="),DLT_INT(crossfaderID),DLT_STRING("rampType="),DLT_INT(rampType),DLT_STRING("rampTime="),DLT_INT(rampTime));
83
84         if (!mDatabaseHandler->existcrossFader(crossfaderID)) return E_NON_EXISTENT;
85         return mRoutingSender->asyncCrossFade(handle,crossfaderID,hotSource,rampType,rampTime);
86 }
87
88
89
90 am_Error_e ControlReceiver::setSourceState(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SourceState_e state)
91 {
92         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceState got called, sourceID="),DLT_INT(sourceID),DLT_STRING("state="),DLT_INT(state));
93
94         am_SourceState_e sourceState;
95         if(mDatabaseHandler->getSoureState(sourceID,sourceState)!=E_OK) return E_UNKNOWN;
96         if(sourceState==state) return E_NO_CHANGE;
97         return mRoutingSender->asyncSetSourceState(handle,sourceID,state);
98 }
99
100
101
102 am_Error_e ControlReceiver::setSinkVolume(am_Handle_s & handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)
103 {
104         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSinkVolume got called, sinkID="),DLT_INT(sinkID),DLT_STRING("volume="),DLT_INT(volume),DLT_STRING("ramp="),DLT_INT(ramp),DLT_STRING("time="),DLT_INT(time));
105
106         am_volume_t tempVolume;
107         if(mDatabaseHandler->getSinkVolume(sinkID,tempVolume)!=E_OK) return E_UNKNOWN;
108         if(tempVolume==volume) return E_NO_CHANGE;
109         return mRoutingSender->asyncSetSinkVolume(handle,sinkID,volume,ramp,time);
110 }
111
112
113
114 am_Error_e ControlReceiver::setSourceVolume(am_Handle_s & handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e rampType, const am_time_t time)
115 {
116         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceVolume got called, sourceID="),DLT_INT(sourceID),DLT_STRING("volume="),DLT_INT(volume),DLT_STRING("ramp="),DLT_INT(rampType),DLT_STRING("time="),DLT_INT(time));
117
118         am_volume_t tempVolume;
119         if(mDatabaseHandler->getSourceVolume(sourceID,tempVolume)!=E_OK) return E_UNKNOWN;
120         if(tempVolume==volume) return E_NO_CHANGE;
121         return mRoutingSender->asyncSetSourceVolume(handle,sourceID,volume,rampType,time);
122 }
123
124
125
126 am_Error_e ControlReceiver::setSinkSoundProperty(am_Handle_s & handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty)
127 {
128         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSinkSoundProperty got called, sinkID="),DLT_INT(sinkID),DLT_STRING("soundProperty.Type="),DLT_INT(soundProperty.type),DLT_STRING("soundProperty.value="),DLT_INT(soundProperty.value));
129
130         uint16_t value;
131         if(mDatabaseHandler->getSinkSoundPropertyValue(sinkID,soundProperty.type,value)!=E_OK) return E_UNKNOWN;
132         if(value==soundProperty.value) return E_NO_CHANGE;
133         return mRoutingSender->asyncSetSinkSoundProperty(handle,sinkID,soundProperty);
134 }
135
136
137
138 am_Error_e ControlReceiver::setSourceSoundProperty(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty)
139 {
140         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceSoundProperty got called, sourceID="),DLT_INT(sourceID),DLT_STRING("soundProperty.Type="),DLT_INT(soundProperty.type),DLT_STRING("soundProperty.value="),DLT_INT(soundProperty.value));
141
142         uint16_t value;
143         if(mDatabaseHandler->getSourceSoundPropertyValue(sourceID,soundProperty.type,value)!=E_OK) return E_UNKNOWN;
144         if(value==soundProperty.value) return E_NO_CHANGE;
145         return mRoutingSender->asyncSetSourceSoundProperty(handle,sourceID,soundProperty);
146 }
147
148
149
150 am_Error_e ControlReceiver::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
151 {
152         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setDomainState got called, domainID="),DLT_INT(domainID),DLT_STRING("domainState="),DLT_INT(domainState));
153
154         am_DomainState_e tempState=DS_MIN;
155         if(mDatabaseHandler->getDomainState(domainID,tempState)!=E_OK) return E_UNKNOWN;
156         if(tempState==domainState) return E_NO_CHANGE;
157         return mRoutingSender->setDomainState(domainID,domainState);
158 }
159
160
161
162 am_Error_e ControlReceiver::abortAction(const am_Handle_s handle)
163 {
164         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::abortAction got called, handle.type="),DLT_INT(handle.handle),DLT_STRING("handle.handleType="),DLT_INT(handle.handleType));
165
166         return mRoutingSender->asyncAbort(handle);
167 }
168
169
170
171 am_Error_e ControlReceiver::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
172 {
173         return mDatabaseHandler->enterDomainDB(domainData,domainID);
174 }
175
176
177
178 am_Error_e ControlReceiver::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
179 {
180         return mDatabaseHandler->enterMainConnectionDB(mainConnectionData,connectionID);
181 }
182
183
184
185 am_Error_e ControlReceiver::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
186 {
187         return mDatabaseHandler->enterSinkDB(sinkData,sinkID);
188 }
189
190
191
192 am_Error_e ControlReceiver::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
193 {
194         return mDatabaseHandler->enterCrossfaderDB(crossfaderData,crossfaderID);
195 }
196
197
198
199 am_Error_e ControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
200 {
201         return mDatabaseHandler->enterGatewayDB(gatewayData,gatewayID);
202 }
203
204
205
206 am_Error_e ControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
207 {
208         return mDatabaseHandler->enterSourceDB(sourceData,sourceID);
209 }
210
211 am_Error_e ControlReceiver::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
212 {
213         return mDatabaseHandler->enterSinkClassDB(sinkClass,sinkClassID);
214 }
215
216 am_Error_e ControlReceiver::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
217 {
218         return mDatabaseHandler->enterSourceClassDB(sourceClassID,sourceClass);
219 }
220
221
222 am_Error_e ControlReceiver::enterSystemPropertiesListDB(const std::vector<am_SystemProperty_s> & listSystemProperties)
223 {
224         return mDatabaseHandler->enterSystemProperties(listSystemProperties);
225 }
226
227
228 am_Error_e ControlReceiver::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
229 {
230         return mDatabaseHandler->changeMainConnectionRouteDB(mainconnectionID,route);
231 }
232
233
234
235 am_Error_e ControlReceiver::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
236 {
237         return mDatabaseHandler->changeMainConnectionStateDB(mainconnectionID,connectionState);
238 }
239
240
241
242 am_Error_e ControlReceiver::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
243 {
244         return mDatabaseHandler->changeSinkMainVolumeDB(mainVolume,sinkID);
245 }
246
247
248
249 am_Error_e ControlReceiver::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
250 {
251         return mDatabaseHandler->changeSinkAvailabilityDB(availability,sinkID);
252 }
253
254
255
256 am_Error_e ControlReceiver::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
257 {
258         return mDatabaseHandler->changDomainStateDB(domainState,domainID);
259 }
260
261
262
263 am_Error_e ControlReceiver::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
264 {
265         return mDatabaseHandler->changeSinkMuteStateDB(muteState,sinkID);
266 }
267
268
269
270 am_Error_e ControlReceiver::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
271 {
272         return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty,sinkID);
273 }
274
275
276
277 am_Error_e ControlReceiver::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
278 {
279         return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty,sourceID);
280 }
281
282
283
284 am_Error_e ControlReceiver::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
285 {
286         return mDatabaseHandler->changeSourceAvailabilityDB(availability,sourceID);
287 }
288
289
290
291 am_Error_e ControlReceiver::changeSystemPropertyDB(const am_SystemProperty_s & property)
292 {
293         return mDatabaseHandler->changeSystemPropertyDB(property);
294 }
295
296
297
298 am_Error_e ControlReceiver::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
299 {
300         return mDatabaseHandler->removeMainConnectionDB(mainConnectionID);
301 }
302
303
304
305 am_Error_e ControlReceiver::removeSinkDB(const am_sinkID_t sinkID)
306 {
307         return mDatabaseHandler->removeSinkDB(sinkID);
308 }
309
310
311
312 am_Error_e ControlReceiver::removeSourceDB(const am_sourceID_t sourceID)
313 {
314         return mDatabaseHandler->removeSourceDB(sourceID);
315 }
316
317
318
319 am_Error_e ControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID)
320 {
321         return mDatabaseHandler->removeGatewayDB(gatewayID);
322 }
323
324
325
326 am_Error_e ControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
327 {
328         return mDatabaseHandler->removeCrossfaderDB(crossfaderID);
329 }
330
331
332
333 am_Error_e ControlReceiver::removeDomainDB(const am_domainID_t domainID)
334 {
335         return mDatabaseHandler->removeDomainDB(domainID);
336 }
337
338
339
340 am_Error_e ControlReceiver::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
341 {
342         return mDatabaseHandler->getSourceClassInfoDB(sourceID,classInfo);
343 }
344
345
346 am_Error_e ControlReceiver::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
347 {
348         return mDatabaseHandler->getSinkClassInfoDB(sinkID,sinkClass);
349 }
350
351
352
353 am_Error_e ControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
354 {
355         return mDatabaseHandler->getGatewayInfoDB(gatewayID,gatewayData);
356 }
357
358
359
360 am_Error_e ControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
361 {
362         return mDatabaseHandler->getCrossfaderInfoDB(crossfaderID,crossfaderData);
363 }
364
365
366
367 am_Error_e ControlReceiver::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
368 {
369         return mDatabaseHandler->getListSinksOfDomain(domainID,listSinkID);
370 }
371
372
373
374 am_Error_e ControlReceiver::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
375 {
376         return mDatabaseHandler->getListSourcesOfDomain(domainID,listSourceID);
377 }
378
379
380
381 am_Error_e ControlReceiver::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
382 {
383         return mDatabaseHandler->getListCrossfadersOfDomain(domainID,listGatewaysID);
384 }
385
386
387
388 am_Error_e ControlReceiver::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
389 {
390         return mDatabaseHandler->getListGatewaysOfDomain(domainID,listGatewaysID);
391 }
392
393
394
395 am_Error_e ControlReceiver::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
396 {
397         return mDatabaseHandler->getListMainConnections(listMainConnections);
398 }
399
400
401
402 am_Error_e ControlReceiver::getListDomains(std::vector<am_Domain_s> & listDomains) const
403 {
404         return mDatabaseHandler->getListDomains(listDomains);
405 }
406
407
408
409 am_Error_e ControlReceiver::getListConnections(std::vector<am_Connection_s> & listConnections) const
410 {
411         return mDatabaseHandler->getListConnections(listConnections);
412 }
413
414
415
416 am_Error_e ControlReceiver::getListSinks(std::vector<am_Sink_s> & listSinks) const
417 {
418         return mDatabaseHandler->getListSinks(listSinks);
419 }
420
421
422
423 am_Error_e ControlReceiver::getListSources(std::vector<am_Source_s> & listSources) const
424 {
425         return mDatabaseHandler->getListSources(listSources);
426 }
427
428
429
430 am_Error_e ControlReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
431 {
432         return mDatabaseHandler->getListSourceClasses(listSourceClasses);
433 }
434
435
436
437 am_Error_e ControlReceiver::getListHandles(std::vector<am_Handle_s> & listHandles) const
438 {
439         return mRoutingSender->getListHandles(listHandles);
440 }
441
442
443
444 am_Error_e ControlReceiver::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
445 {
446         return mDatabaseHandler->getListCrossfaders(listCrossfaders);
447 }
448
449
450
451 am_Error_e ControlReceiver::getListGateways(std::vector<am_Gateway_s> & listGateways) const
452 {
453         return mDatabaseHandler->getListGateways(listGateways);
454 }
455
456
457
458 am_Error_e ControlReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
459 {
460         return mDatabaseHandler->getListSinkClasses(listSinkClasses);
461 }
462
463
464 am_Error_e ControlReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
465 {
466         return mDatabaseHandler->getListSystemProperties(listSystemProperties);
467 }
468
469
470 am_Error_e ControlReceiver::changeSinkClassInfoDB(const am_SinkClass_s & classInfo)
471 {
472         mDatabaseHandler->changeSinkClassInfoDB(classInfo);
473 }
474
475 am_Error_e ControlReceiver::changeSourceClassInfoDB(const am_SourceClass_s & classInfo)
476 {
477         mDatabaseHandler->changeSourceClassInfoDB(classInfo);
478 }
479
480 am_Error_e ControlReceiver::removeSinkClassDB(const am_sinkClass_t sinkClassID)
481 {
482         mDatabaseHandler->removeSinkClassDB(sinkClassID);
483 }
484
485 am_Error_e ControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceClassID)
486 {
487         mDatabaseHandler->removeSourceClassDB(sourceClassID);
488 }
489
490 void ControlReceiver::setCommandReady()
491 {
492         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setCommandReady got called"));
493         mCommandSender->cbCommunicationReady();
494 }
495
496 void ControlReceiver::setRoutingReady()
497 {
498         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setRoutingReady got called"));
499         mRoutingSender->routingInterfacesReady();
500 }
501
502
503