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);
78 RoutingReceiver::~RoutingReceiver()
84 void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
86 mRoutingSender->removeHandle(handle);
89 mDatabaseHandler->changeConnectionFinal(connectionID);
93 mDatabaseHandler->removeConnection(connectionID);
95 mControlSender->cbAckConnect(handle,error);
100 void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
102 mRoutingSender->removeHandle(handle);
105 mDatabaseHandler->removeConnection(connectionID);
107 mControlSender->cbAckDisconnect(handle,error);
112 void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
114 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
115 if(error==E_OK && handleData.sinkID!=0)
117 //todo: check if volume in handleData is same than volume. React to it.
118 mDatabaseHandler->changeSinkVolume(handleData.sinkID,volume);
120 mRoutingSender->removeHandle(handle);
121 mControlSender->cbAckSetSinkVolumeChange(handle,volume,error);
126 void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
128 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
129 if(error==E_OK && handleData.sourceID!=0)
131 //todo: check if volume in handleData is same than volume. React to it.
132 mDatabaseHandler->changeSourceVolume(handleData.sourceID,volume);
134 mRoutingSender->removeHandle(handle);
135 mControlSender->cbAckSetSourceVolumeChange(handle,volume,error);
140 void RoutingReceiver::ackSetSourceState(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.sourceID!=0)
145 //todo: check if volume in handleData is same than volume. React to it.
146 mDatabaseHandler->changeSourceState(handleData.sourceID,handleData.sourceState);
148 mRoutingSender->removeHandle(handle);
149 mControlSender->cbAckSetSourceState(handle,error);
154 void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
156 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
157 if(error==E_OK && handleData.sinkID!=0)
159 mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery,handleData.sinkID);
161 mRoutingSender->removeHandle(handle);
162 mControlSender->cbAckSetSinkSoundProperty(handle,error);
166 void am::RoutingReceiver::ackSetSinkSoundProperties(const am_Handle_s handle, const am_Error_e error)
168 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
169 if(error==E_OK && handleData.sinkID!=0)
171 std::vector<am_SoundProperty_s>::const_iterator it=handleData.soundProperties->begin();
172 for(;it!=handleData.soundProperties->end();++it)
174 mDatabaseHandler->changeSinkSoundPropertyDB(*it,handleData.sinkID);
176 delete handleData.soundProperties;
178 mRoutingSender->removeHandle(handle);
179 mControlSender->cbAckSetSinkSoundProperties(handle,error);
183 void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
185 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
186 if(error==E_OK && handleData.sourceID!=0)
188 mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery,handleData.sourceID);
190 mRoutingSender->removeHandle(handle);
191 mControlSender->cbAckSetSourceSoundProperty(handle,error);
195 void am::RoutingReceiver::ackSetSourceSoundProperties(const am_Handle_s handle, const am_Error_e error)
197 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
198 if(error==E_OK && handleData.sourceID!=0)
200 std::vector<am_SoundProperty_s>::const_iterator it=handleData.soundProperties->begin();
201 for(;it!=handleData.soundProperties->end();++it)
203 mDatabaseHandler->changeSourceSoundPropertyDB(*it,handleData.sourceID);
205 delete handleData.soundProperties;
207 mRoutingSender->removeHandle(handle);
208 mControlSender->cbAckSetSourceSoundProperties(handle,error);
211 void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
213 RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
214 if(error==E_OK && handleData.crossfaderID!=0)
216 //todo: check if volume in handleData is same than volume. React to it.
217 mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID,hotSink);
219 mRoutingSender->removeHandle(handle);
220 mControlSender->cbAckCrossFade(handle,hotSink,error);
225 void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
227 mControlSender->hookSystemSourceVolumeTick(handle,sourceID,volume);
232 void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
234 mControlSender->hookSystemSinkVolumeTick(handle,sinkID,volume);
239 am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID)
241 return mDatabaseHandler->peekDomain(name,domainID);
246 am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID)
248 return mControlSender->hookSystemRegisterDomain(domainData,domainID);
253 am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID)
255 return mControlSender->hookSystemDeregisterDomain(domainID);
260 am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
262 return mControlSender->hookSystemRegisterGateway(gatewayData,gatewayID);
267 am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
269 return mControlSender->hookSystemDeregisterGateway(gatewayID);
274 am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
276 return mDatabaseHandler->peekSink(name,sinkID);
281 am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
283 return mControlSender->hookSystemRegisterSink(sinkData,sinkID);
288 am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID)
290 return mControlSender->hookSystemDeregisterSink(sinkID);
295 am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID)
297 return mDatabaseHandler->peekSource(name,sourceID);
302 am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID)
304 return mControlSender->hookSystemRegisterSource(sourceData,sourceID);
309 am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID)
311 return mControlSender->hookSystemDeregisterSource(sourceID);
316 am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
318 return mControlSender->hookSystemRegisterCrossfader(crossfaderData,crossfaderID);
323 am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID)
325 return mControlSender->hookSystemDeregisterCrossfader(crossfaderID);
330 void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
332 return mControlSender->hookSystemInterruptStateChange(sourceID,interruptState);
337 void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID)
339 mControlSender->hookSystemDomainRegistrationComplete(domainID);
344 void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
346 mControlSender->hookSystemSinkAvailablityStateChange(sinkID,availability);
351 void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
353 mControlSender->hookSystemSourceAvailablityStateChange(sourceID,availability);
358 void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
360 mControlSender->hookSystemDomainStateChange(domainID,domainState);
365 void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
367 mDatabaseHandler->changeConnectionTimingInformation(connectionID,delay);
372 am_Error_e RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & earlyData)
374 mControlSender->hookSystemReceiveEarlyData(earlyData);
376 //todo: change return type to void in EA model
381 am_Error_e RoutingReceiver::peekSinkClassID(const std::string name, const am_sinkClass_t& sinkClassID)
387 am_Error_e RoutingReceiver::peekSourceClassID(const std::string name, const am_sourceClass_t& sourceClassID)
393 am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *& dbusConnectionWrapper) const
395 #ifdef WITH_DBUS_WRAPPER
396 dbusConnectionWrapper=mDBusWrapper;
404 am_Error_e RoutingReceiver::getSocketHandler(SocketHandler *& socketHandler) const
406 #ifdef WITH_SOCKETHANDLER_LOOP
407 socketHandler=mSocketHandler;
414 uint16_t RoutingReceiver::getInterfaceVersion() const
416 return RoutingReceiveVersion;