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