2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file ControlReceiver.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
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
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.
26 #include <SocketHandler.h>
27 #include "ControlReceiver.h"
28 #include "DatabaseHandler.h"
29 #include "RoutingSender.h"
30 #include "CommandSender.h"
32 #include "DLTWrapper.h"
37 ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender, SocketHandler *iSocketHandler, Router* iRouter) :
38 mDatabaseHandler(iDatabaseHandler), //
39 mRoutingSender(iRoutingSender), //
40 mCommandSender(iCommandSender), //
41 mSocketHandler(iSocketHandler), //
44 assert(mDatabaseHandler!=NULL);
45 assert(mRoutingSender!=NULL);
46 assert(mCommandSender!=NULL);
47 assert(mSocketHandler!=NULL);
48 assert(mRouter!=NULL);
51 ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender, Router* iRouter) :
52 mDatabaseHandler(iDatabaseHandler), //
53 mRoutingSender(iRoutingSender), //
54 mCommandSender(iCommandSender), //
57 assert(mDatabaseHandler!=NULL);
58 assert(mRoutingSender!=NULL);
59 assert(mCommandSender!=NULL);
60 assert(mRouter!=NULL);
63 ControlReceiver::~ControlReceiver()
67 am_Error_e ControlReceiver::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s> & returnList)
69 mRouter->getRoute(onlyfree, sourceID, sinkID, returnList);
73 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)
75 logInfo("ControlReceiver::connect got called, connectionFormat=", format, "sourceID=", sourceID, "sinkID=", sinkID);
77 am_Connection_s tempConnection;
78 tempConnection.sinkID = sinkID;
79 tempConnection.sourceID = sourceID;
80 tempConnection.connectionFormat = format;
81 tempConnection.connectionID = 0;
83 //todo: enter function to find out what happends if the same connection is in the course of being build up.
84 if (mDatabaseHandler->existConnection(tempConnection))
85 return E_ALREADY_EXISTS; //todo:enter the correct connectionID here?
87 mDatabaseHandler->enterConnectionDB(tempConnection, connectionID);
88 return mRoutingSender->asyncConnect(handle, connectionID, sourceID, sinkID, format);
91 am_Error_e ControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID)
93 logInfo("ControlReceiver::disconnect got called, connectionID=", connectionID);
95 if (!mDatabaseHandler->existConnectionID(connectionID))
96 return E_NON_EXISTENT; //todo: check with EA model and correct
97 return mRoutingSender->asyncDisconnect(handle, connectionID);
100 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)
102 logInfo("ControlReceiver::crossfade got called, hotSource=",hotSource,"crossfaderID=",crossfaderID,"rampType=",rampType,"rampTime=",rampTime);
104 if (!mDatabaseHandler->existcrossFader(crossfaderID))
105 return E_NON_EXISTENT;
106 return mRoutingSender->asyncCrossFade(handle, crossfaderID, hotSource, rampType, rampTime);
109 am_Error_e ControlReceiver::setSourceState(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SourceState_e state)
111 logInfo("ControlReceiver::setSourceState got called, sourceID=",sourceID,"state=",state);
113 am_SourceState_e sourceState;
114 if (mDatabaseHandler->getSoureState(sourceID, sourceState) != E_OK)
116 if (sourceState == state)
118 return mRoutingSender->asyncSetSourceState(handle, sourceID, state);
121 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)
123 logInfo("ControlReceiver::setSinkVolume got called, sinkID=",sinkID,"volume=",volume,"ramp=",ramp, "time=",time);
125 am_volume_t tempVolume;
126 if (mDatabaseHandler->getSinkVolume(sinkID, tempVolume) != E_OK)
128 if (tempVolume == volume)
130 return mRoutingSender->asyncSetSinkVolume(handle, sinkID, volume, ramp, time);
133 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)
135 logInfo("ControlReceiver::setSourceVolume got called, sourceID=",sourceID,"volume=",volume,"ramp=",rampType,"time=",time);
137 am_volume_t tempVolume;
138 if (mDatabaseHandler->getSourceVolume(sourceID, tempVolume) != E_OK)
140 if (tempVolume == volume)
142 return mRoutingSender->asyncSetSourceVolume(handle, sourceID, volume, rampType, time);
145 am_Error_e ControlReceiver::setSinkSoundProperty(am_Handle_s & handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty)
147 logInfo("ControlReceiver::setSinkSoundProperty got called, sinkID=",sinkID,"soundProperty.Type=",soundProperty.type,"soundProperty.value=",soundProperty.value);
150 if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, soundProperty.type, value) != E_OK)
152 if (value == soundProperty.value)
154 return mRoutingSender->asyncSetSinkSoundProperty(handle, sinkID, soundProperty);
157 am_Error_e ControlReceiver::setSinkSoundProperties(am_Handle_s & handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s> & listSoundProperties)
159 logInfo("ControlReceiver::setSinkSoundProperties got called, sinkID=",sinkID);
162 bool noChange = true;
163 std::vector<am_SoundProperty_s>::const_iterator it = listSoundProperties.begin();
164 for (; it != listSoundProperties.end(); ++it)
166 if (mDatabaseHandler->getSinkSoundPropertyValue(sinkID, it->type, value) != E_OK)
168 if (value != it->value)
172 return (E_NO_CHANGE);
173 return (mRoutingSender->asyncSetSinkSoundProperties(handle, listSoundProperties, sinkID));
176 am_Error_e ControlReceiver::setSourceSoundProperty(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty)
178 logInfo("ControlReceiver::setSourceSoundProperty got called, sourceID=",sourceID,"soundProperty.Type=",soundProperty.type,"soundProperty.value=",soundProperty.value);
181 if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, soundProperty.type, value) != E_OK)
183 if (value == soundProperty.value)
185 return mRoutingSender->asyncSetSourceSoundProperty(handle, sourceID, soundProperty);
188 am_Error_e ControlReceiver::setSourceSoundProperties(am_Handle_s & handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s> & listSoundProperties)
190 logInfo("ControlReceiver::setSourceSoundProperties got called, sourceID=",sourceID);
193 bool noChange = true;
194 std::vector<am_SoundProperty_s>::const_iterator it = listSoundProperties.begin();
195 for (; it != listSoundProperties.end(); ++it)
197 if (mDatabaseHandler->getSourceSoundPropertyValue(sourceID, it->type, value) != E_OK)
199 if (value != it->value)
203 return (E_NO_CHANGE);
204 return (mRoutingSender->asyncSetSourceSoundProperties(handle, listSoundProperties, sourceID));
207 am_Error_e ControlReceiver::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
209 logInfo("ControlReceiver::setDomainState got called, domainID=",domainID,"domainState=",domainState);
211 am_DomainState_e tempState = DS_MIN;
212 if (mDatabaseHandler->getDomainState(domainID, tempState) != E_OK)
214 if (tempState == domainState)
216 return mRoutingSender->setDomainState(domainID, domainState);
219 am_Error_e ControlReceiver::abortAction(const am_Handle_s handle)
221 logInfo("ControlReceiver::abortAction got called, handle.type=",handle.handle,"handle.handleType=",handle.handleType);
223 return mRoutingSender->asyncAbort(handle);
226 am_Error_e ControlReceiver::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
228 return mDatabaseHandler->enterDomainDB(domainData, domainID);
231 am_Error_e ControlReceiver::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
233 return mDatabaseHandler->enterMainConnectionDB(mainConnectionData, connectionID);
236 am_Error_e ControlReceiver::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
238 return mDatabaseHandler->enterSinkDB(sinkData, sinkID);
241 am_Error_e ControlReceiver::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
243 return mDatabaseHandler->enterCrossfaderDB(crossfaderData, crossfaderID);
246 am_Error_e ControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
248 return mDatabaseHandler->enterGatewayDB(gatewayData, gatewayID);
251 am_Error_e ControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
253 return mDatabaseHandler->enterSourceDB(sourceData, sourceID);
256 am_Error_e ControlReceiver::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
258 return mDatabaseHandler->enterSinkClassDB(sinkClass, sinkClassID);
261 am_Error_e ControlReceiver::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
263 return mDatabaseHandler->enterSourceClassDB(sourceClassID, sourceClass);
266 am_Error_e ControlReceiver::enterSystemPropertiesListDB(const std::vector<am_SystemProperty_s> & listSystemProperties)
268 return mDatabaseHandler->enterSystemProperties(listSystemProperties);
271 am_Error_e ControlReceiver::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
273 return mDatabaseHandler->changeMainConnectionRouteDB(mainconnectionID, route);
276 am_Error_e ControlReceiver::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
278 return mDatabaseHandler->changeMainConnectionStateDB(mainconnectionID, connectionState);
281 am_Error_e ControlReceiver::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
283 return mDatabaseHandler->changeSinkMainVolumeDB(mainVolume, sinkID);
286 am_Error_e ControlReceiver::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
288 return mDatabaseHandler->changeSinkAvailabilityDB(availability, sinkID);
291 am_Error_e ControlReceiver::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
293 return mDatabaseHandler->changDomainStateDB(domainState, domainID);
296 am_Error_e ControlReceiver::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
298 return mDatabaseHandler->changeSinkMuteStateDB(muteState, sinkID);
301 am_Error_e ControlReceiver::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
303 return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sinkID);
306 am_Error_e ControlReceiver::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
308 return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty, sourceID);
311 am_Error_e ControlReceiver::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
313 return mDatabaseHandler->changeSourceAvailabilityDB(availability, sourceID);
316 am_Error_e ControlReceiver::changeSystemPropertyDB(const am_SystemProperty_s & property)
318 return mDatabaseHandler->changeSystemPropertyDB(property);
321 am_Error_e ControlReceiver::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
323 return mDatabaseHandler->removeMainConnectionDB(mainConnectionID);
326 am_Error_e ControlReceiver::removeSinkDB(const am_sinkID_t sinkID)
328 return mDatabaseHandler->removeSinkDB(sinkID);
331 am_Error_e ControlReceiver::removeSourceDB(const am_sourceID_t sourceID)
333 return mDatabaseHandler->removeSourceDB(sourceID);
336 am_Error_e ControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID)
338 return mDatabaseHandler->removeGatewayDB(gatewayID);
341 am_Error_e ControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
343 return mDatabaseHandler->removeCrossfaderDB(crossfaderID);
346 am_Error_e ControlReceiver::removeDomainDB(const am_domainID_t domainID)
348 return mDatabaseHandler->removeDomainDB(domainID);
351 am_Error_e ControlReceiver::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
353 return mDatabaseHandler->getSourceClassInfoDB(sourceID, classInfo);
356 am_Error_e ControlReceiver::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
358 return mDatabaseHandler->getSinkClassInfoDB(sinkID, sinkClass);
361 am_Error_e ControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
363 return mDatabaseHandler->getGatewayInfoDB(gatewayID, gatewayData);
366 am_Error_e ControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
368 return mDatabaseHandler->getCrossfaderInfoDB(crossfaderID, crossfaderData);
371 am_Error_e ControlReceiver::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
373 return mDatabaseHandler->getListSinksOfDomain(domainID, listSinkID);
376 am_Error_e ControlReceiver::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
378 return mDatabaseHandler->getListSourcesOfDomain(domainID, listSourceID);
381 am_Error_e ControlReceiver::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
383 return mDatabaseHandler->getListCrossfadersOfDomain(domainID, listGatewaysID);
386 am_Error_e ControlReceiver::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
388 return mDatabaseHandler->getListGatewaysOfDomain(domainID, listGatewaysID);
391 am_Error_e ControlReceiver::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
393 return mDatabaseHandler->getListMainConnections(listMainConnections);
396 am_Error_e ControlReceiver::getListDomains(std::vector<am_Domain_s> & listDomains) const
398 return mDatabaseHandler->getListDomains(listDomains);
401 am_Error_e ControlReceiver::getListConnections(std::vector<am_Connection_s> & listConnections) const
403 return mDatabaseHandler->getListConnections(listConnections);
406 am_Error_e ControlReceiver::getListSinks(std::vector<am_Sink_s> & listSinks) const
408 return mDatabaseHandler->getListSinks(listSinks);
411 am_Error_e ControlReceiver::getListSources(std::vector<am_Source_s> & listSources) const
413 return mDatabaseHandler->getListSources(listSources);
416 am_Error_e ControlReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
418 return mDatabaseHandler->getListSourceClasses(listSourceClasses);
421 am_Error_e ControlReceiver::getListHandles(std::vector<am_Handle_s> & listHandles) const
423 return mRoutingSender->getListHandles(listHandles);
426 am_Error_e ControlReceiver::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
428 return mDatabaseHandler->getListCrossfaders(listCrossfaders);
431 am_Error_e ControlReceiver::getListGateways(std::vector<am_Gateway_s> & listGateways) const
433 return mDatabaseHandler->getListGateways(listGateways);
436 am_Error_e ControlReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
438 return mDatabaseHandler->getListSinkClasses(listSinkClasses);
441 am_Error_e ControlReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
443 return mDatabaseHandler->getListSystemProperties(listSystemProperties);
446 am_Error_e ControlReceiver::changeSinkClassInfoDB(const am_SinkClass_s & classInfo)
448 return mDatabaseHandler->changeSinkClassInfoDB(classInfo);
451 am_Error_e ControlReceiver::changeSourceClassInfoDB(const am_SourceClass_s & classInfo)
453 return mDatabaseHandler->changeSourceClassInfoDB(classInfo);
456 am_Error_e ControlReceiver::removeSinkClassDB(const am_sinkClass_t sinkClassID)
458 return mDatabaseHandler->removeSinkClassDB(sinkClassID);
461 am_Error_e ControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceClassID)
463 return mDatabaseHandler->removeSourceClassDB(sourceClassID);
466 void ControlReceiver::setCommandReady()
468 logInfo("ControlReceiver::setCommandReady got called");
469 mCommandSender->cbCommunicationReady();
472 void ControlReceiver::setRoutingReady()
474 logInfo("ControlReceiver::setRoutingReady got called");
475 mRoutingSender->routingInterfacesReady();
478 am_Error_e ControlReceiver::getSocketHandler(SocketHandler *& socketHandler)
480 #ifdef WITH_SOCKETHANDLER_LOOP
481 socketHandler = mSocketHandler;
488 uint16_t ControlReceiver::getInterfaceVersion() const
490 return ControlReceiveVersion;