2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file RoutingReceiver.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
11 * \section LicenseRoutingReceiver.h
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
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.
26 #include "RoutingReceiver.h"
27 #include <SocketHandler.h>
28 #ifdef WITH_DBUS_WRAPPER
29 #include <dbus/DBusWrapper.h>
31 #include "DatabaseHandler.h"
32 #include "RoutingSender.h"
33 #include "ControlSender.h"
38 am::RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, SocketHandler *iSocketHandler) :
39 mDatabaseHandler(iDatabaseHandler), //
40 mRoutingSender(iRoutingSender), //
41 mControlSender(iControlSender), //
42 mSocketHandler(iSocketHandler) //
44 assert(mDatabaseHandler!=NULL);
45 assert(mRoutingSender!=NULL);
46 assert(mControlSender!=NULL);
47 assert(mSocketHandler!=NULL);
50 am::RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender, DBusWrapper *iDBusWrapper) :
51 mDatabaseHandler(iDatabaseHandler), //
52 mRoutingSender(iRoutingSender), //
53 mControlSender(iControlSender), //
54 mDBusWrapper(iDBusWrapper) //
56 assert(mDatabaseHandler!=NULL);
57 assert(mRoutingSender!=NULL);
58 assert(mControlSender!=NULL);
59 assert(mDBusWrapper!=NULL);
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) //
69 assert(mDatabaseHandler!=NULL);
70 assert(mRoutingSender!=NULL);
71 assert(mControlSender!=NULL);
72 assert(mSocketHandler!=NULL);
73 assert(mDBusWrapper!=NULL);
76 RoutingReceiver::~RoutingReceiver()
80 void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
82 mRoutingSender->removeHandle(handle);
85 mDatabaseHandler->changeConnectionFinal(connectionID);
89 mDatabaseHandler->removeConnection(connectionID);
91 mControlSender->cbAckConnect(handle, error);
94 void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
96 mRoutingSender->removeHandle(handle);
99 mDatabaseHandler->removeConnection(connectionID);
101 mControlSender->cbAckDisconnect(handle, error);
104 void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
106 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
107 if (error == E_OK && handleData.sinkID != 0)
109 //todo: check if volume in handleData is same than volume. React to it.
110 mDatabaseHandler->changeSinkVolume(handleData.sinkID, volume);
112 mRoutingSender->removeHandle(handle);
113 mControlSender->cbAckSetSinkVolumeChange(handle, volume, error);
116 void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
118 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
119 if (error == E_OK && handleData.sourceID != 0)
121 //todo: check if volume in handleData is same than volume. React to it.
122 mDatabaseHandler->changeSourceVolume(handleData.sourceID, volume);
124 mRoutingSender->removeHandle(handle);
125 mControlSender->cbAckSetSourceVolumeChange(handle, volume, error);
128 void RoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error)
130 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
131 if (error == E_OK && handleData.sourceID != 0)
133 //todo: check if volume in handleData is same than volume. React to it.
134 mDatabaseHandler->changeSourceState(handleData.sourceID, handleData.sourceState);
136 mRoutingSender->removeHandle(handle);
137 mControlSender->cbAckSetSourceState(handle, error);
140 void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
142 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
143 if (error == E_OK && handleData.sinkID != 0)
145 mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery, handleData.sinkID);
147 mRoutingSender->removeHandle(handle);
148 mControlSender->cbAckSetSinkSoundProperty(handle, error);
152 void am::RoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error)
154 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
155 if (error == E_OK && handleData.sinkID != 0)
157 std::vector<am_SoundProperty_s>::const_iterator it = handleData.soundProperties->begin();
158 for (; it != handleData.soundProperties->end(); ++it)
160 mDatabaseHandler->changeSinkSoundPropertyDB(*it, handleData.sinkID);
162 delete handleData.soundProperties;
164 mRoutingSender->removeHandle(handle);
165 mControlSender->cbAckSetSinkSoundProperties(handle, error);
168 void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
170 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
171 if (error == E_OK && handleData.sourceID != 0)
173 mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery, handleData.sourceID);
175 mRoutingSender->removeHandle(handle);
176 mControlSender->cbAckSetSourceSoundProperty(handle, error);
179 void am::RoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error)
181 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
182 if (error == E_OK && handleData.sourceID != 0)
184 std::vector<am_SoundProperty_s>::const_iterator it = handleData.soundProperties->begin();
185 for (; it != handleData.soundProperties->end(); ++it)
187 mDatabaseHandler->changeSourceSoundPropertyDB(*it, handleData.sourceID);
189 delete handleData.soundProperties;
191 mRoutingSender->removeHandle(handle);
192 mControlSender->cbAckSetSourceSoundProperties(handle, error);
195 void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
197 RoutingSender::am_handleData_c handleData = mRoutingSender->returnHandleData(handle);
198 if (error == E_OK && handleData.crossfaderID != 0)
200 //todo: check if volume in handleData is same than volume. React to it.
201 mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID, hotSink);
203 mRoutingSender->removeHandle(handle);
204 mControlSender->cbAckCrossFade(handle, hotSink, error);
207 void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
209 mControlSender->hookSystemSourceVolumeTick(handle, sourceID, volume);
212 void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
214 mControlSender->hookSystemSinkVolumeTick(handle, sinkID, volume);
217 am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID)
219 return mDatabaseHandler->peekDomain(name, domainID);
223 am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID)
225 return mControlSender->hookSystemRegisterDomain(domainData, domainID);
228 am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID)
230 return mControlSender->hookSystemDeregisterDomain(domainID);
233 am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
235 return mControlSender->hookSystemRegisterGateway(gatewayData, gatewayID);
238 am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
240 return mControlSender->hookSystemDeregisterGateway(gatewayID);
243 am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
245 return mDatabaseHandler->peekSink(name, sinkID);
248 am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
250 return mControlSender->hookSystemRegisterSink(sinkData, sinkID);
253 am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID)
255 return mControlSender->hookSystemDeregisterSink(sinkID);
258 am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID)
260 return mDatabaseHandler->peekSource(name, sourceID);
263 am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID)
265 return mControlSender->hookSystemRegisterSource(sourceData, sourceID);
268 am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID)
270 return mControlSender->hookSystemDeregisterSource(sourceID);
273 am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
275 return mControlSender->hookSystemRegisterCrossfader(crossfaderData, crossfaderID);
278 am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID)
280 return mControlSender->hookSystemDeregisterCrossfader(crossfaderID);
283 void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
285 return mControlSender->hookSystemInterruptStateChange(sourceID, interruptState);
288 void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID)
290 mControlSender->hookSystemDomainRegistrationComplete(domainID);
293 void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
295 mControlSender->hookSystemSinkAvailablityStateChange(sinkID, availability);
298 void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
300 mControlSender->hookSystemSourceAvailablityStateChange(sourceID, availability);
303 void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
305 mControlSender->hookSystemDomainStateChange(domainID, domainState);
308 void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
310 mDatabaseHandler->changeConnectionTimingInformation(connectionID, delay);
313 am_Error_e RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & earlyData)
315 mControlSender->hookSystemReceiveEarlyData(earlyData);
317 //todo: change return type to void in EA model
320 am_Error_e RoutingReceiver::peekSinkClassID(const std::string& name, const am_sinkClass_t& sinkClassID)
328 am_Error_e RoutingReceiver::peekSourceClassID(const std::string& name, const am_sourceClass_t& sourceClassID)
331 (void) sourceClassID;
336 am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *& dbusConnectionWrapper) const
338 #ifdef WITH_DBUS_WRAPPER
339 dbusConnectionWrapper = mDBusWrapper;
346 am_Error_e RoutingReceiver::getSocketHandler(SocketHandler *& socketHandler) const
348 #ifdef WITH_SOCKETHANDLER_LOOP
349 socketHandler = mSocketHandler;
356 uint16_t RoutingReceiver::getInterfaceVersion() const
358 return RoutingReceiveVersion;