b9dc3ac6bb72c373abac4d17c1d99554c9e959dc
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / RoutingReceiver.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file RoutingReceiver.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section LicenseRoutingReceiver.h
12 *
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
15 *
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.
23 *
24 */
25
26 #include "RoutingReceiver.h"
27 #include "RoutingSender.h"
28 #include "DatabaseHandler.h"
29 #include "ControlSender.h"
30 #include <assert.h>
31
32 using namespace am;
33
34 RoutingReceiver::RoutingReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, ControlSender *iControlSender)
35         :mDatabaseHandler(iDatabaseHandler),
36          mRoutingSender(iRoutingSender),
37          mControlSender(iControlSender)
38 {
39         assert(mDatabaseHandler!=0);
40         assert(mRoutingSender!=0);
41         assert(mControlSender!=0);
42 }
43
44
45
46 RoutingReceiver::~RoutingReceiver()
47 {
48 }
49
50
51
52 void RoutingReceiver::ackConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
53 {
54         mRoutingSender->removeHandle(handle);
55         if (error==E_OK)
56         {
57                 mDatabaseHandler->changeConnectionFinal(connectionID);
58         }
59         else
60         {
61                 mDatabaseHandler->removeConnection(connectionID);
62         }
63         mControlSender->cbAckConnect(handle,error);
64 }
65
66
67
68 void RoutingReceiver::ackDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_Error_e error)
69 {
70         mRoutingSender->removeHandle(handle);
71         if (error==E_OK)
72         {
73                 mDatabaseHandler->removeConnection(connectionID);
74         }
75         mControlSender->cbAckDisconnect(handle,error);
76 }
77
78
79
80 void RoutingReceiver::ackSetSinkVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
81 {
82         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
83         if(error==E_OK && handleData.sinkID!=0)
84         {
85                 //todo: check if volume in handleData is same than volume. React to it.
86                 mDatabaseHandler->changeSinkVolume(handleData.sinkID,volume);
87         }
88         mRoutingSender->removeHandle(handle);
89         mControlSender->cbAckSetSinkVolumeChange(handle,volume,error);
90 }
91
92
93
94 void RoutingReceiver::ackSetSourceVolumeChange(const am_Handle_s handle, const am_volume_t volume, const am_Error_e error)
95 {
96         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
97         if(error==E_OK && handleData.sourceID!=0)
98         {
99                 //todo: check if volume in handleData is same than volume. React to it.
100                 mDatabaseHandler->changeSourceVolume(handleData.sourceID,volume);
101         }
102         mRoutingSender->removeHandle(handle);
103         mControlSender->cbAckSetSourceVolumeChange(handle,volume,error);
104 }
105
106
107
108 void RoutingReceiver::ackSetSourceState(const am_Handle_s handle, const am_Error_e error)
109 {
110         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
111         if(error==E_OK && handleData.sourceID!=0)
112         {
113                 //todo: check if volume in handleData is same than volume. React to it.
114                 mDatabaseHandler->changeSourceState(handleData.sourceID,handleData.sourceState);
115         }
116         mRoutingSender->removeHandle(handle);
117         mControlSender->cbAckSetSourceState(handle,error);
118 }
119
120
121
122 void RoutingReceiver::ackSetSinkSoundProperty(const am_Handle_s handle, const am_Error_e error)
123 {
124         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
125         if(error==E_OK && handleData.sinkID!=0)
126         {
127                 //todo: check if volume in handleData is same than volume. React to it.
128                 mDatabaseHandler->changeSinkSoundPropertyDB(handleData.soundPropery,handleData.sinkID);
129         }
130         mRoutingSender->removeHandle(handle);
131         mControlSender->cbAckSetSinkSoundProperty(handle,error);
132
133 }
134
135
136
137 void RoutingReceiver::ackSetSourceSoundProperty(const am_Handle_s handle, const am_Error_e error)
138 {
139         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
140         if(error==E_OK && handleData.sourceID!=0)
141         {
142                 //todo: check if volume in handleData is same than volume. React to it.
143                 mDatabaseHandler->changeSourceSoundPropertyDB(handleData.soundPropery,handleData.sourceID);
144         }
145         mRoutingSender->removeHandle(handle);
146         mControlSender->cbAckSetSourceSoundProperty(handle,error);
147 }
148
149
150
151 void RoutingReceiver::ackCrossFading(const am_Handle_s handle, const am_HotSink_e hotSink, const am_Error_e error)
152 {
153         RoutingSender::am_handleData_c handleData=mRoutingSender->returnHandleData(handle);
154         if(error==E_OK && handleData.crossfaderID!=0)
155         {
156                 //todo: check if volume in handleData is same than volume. React to it.
157                 mDatabaseHandler->changeCrossFaderHotSink(handleData.crossfaderID,hotSink);
158         }
159         mRoutingSender->removeHandle(handle);
160         mControlSender->cbAckCrossFade(handle,hotSink,error);
161 }
162
163
164
165 void RoutingReceiver::ackSourceVolumeTick(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume)
166 {
167         mControlSender->hookSystemSourceVolumeTick(handle,sourceID,volume);
168 }
169
170
171
172 void RoutingReceiver::ackSinkVolumeTick(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume)
173 {
174         mControlSender->hookSystemSinkVolumeTick(handle,sinkID,volume);
175 }
176
177
178
179 am_Error_e RoutingReceiver::peekDomain(const std::string & name, am_domainID_t & domainID)
180 {
181         return mDatabaseHandler->peekDomain(name,domainID);
182
183 }
184
185
186 am_Error_e RoutingReceiver::registerDomain(const am_Domain_s & domainData, am_domainID_t & domainID)
187 {
188         return mControlSender->hookSystemRegisterDomain(domainData,domainID);
189 }
190
191
192
193 am_Error_e RoutingReceiver::deregisterDomain(const am_domainID_t domainID)
194 {
195         return mControlSender->hookSystemDeregisterDomain(domainID);
196 }
197
198
199
200 am_Error_e RoutingReceiver::registerGateway(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
201 {
202         return mControlSender->hookSystemRegisterGateway(gatewayData,gatewayID);
203 }
204
205
206
207 am_Error_e RoutingReceiver::deregisterGateway(const am_gatewayID_t gatewayID)
208 {
209         return mControlSender->hookSystemDeregisterGateway(gatewayID);
210 }
211
212
213
214 am_Error_e RoutingReceiver::peekSink(const std::string& name, am_sinkID_t & sinkID)
215 {
216         return mDatabaseHandler->peekSink(name,sinkID);
217 }
218
219
220
221 am_Error_e RoutingReceiver::registerSink(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
222 {
223         return mControlSender->hookSystemRegisterSink(sinkData,sinkID);
224 }
225
226
227
228 am_Error_e RoutingReceiver::deregisterSink(const am_sinkID_t sinkID)
229 {
230         return mControlSender->hookSystemDeregisterSink(sinkID);
231 }
232
233
234
235 am_Error_e RoutingReceiver::peekSource(const std::string & name, am_sourceID_t & sourceID)
236 {
237         return mDatabaseHandler->peekSource(name,sourceID);
238 }
239
240
241
242 am_Error_e RoutingReceiver::registerSource(const am_Source_s & sourceData, am_sourceID_t & sourceID)
243 {
244         return mControlSender->hookSystemRegisterSource(sourceData,sourceID);
245 }
246
247
248
249 am_Error_e RoutingReceiver::deregisterSource(const am_sourceID_t sourceID)
250 {
251         return mControlSender->hookSystemDeregisterSource(sourceID);
252 }
253
254
255
256 am_Error_e RoutingReceiver::registerCrossfader(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
257 {
258         return mControlSender->hookSystemRegisterCrossfader(crossfaderData,crossfaderID);
259 }
260
261
262
263 am_Error_e RoutingReceiver::deregisterCrossfader(const am_crossfaderID_t crossfaderID)
264 {
265         return mControlSender->hookSystemDeregisterCrossfader(crossfaderID);
266 }
267
268
269
270 void RoutingReceiver::hookInterruptStatusChange(const am_sourceID_t sourceID, const am_InterruptState_e interruptState)
271 {
272         return mControlSender->hookSystemInterruptStateChange(sourceID,interruptState);
273 }
274
275
276
277 void RoutingReceiver::hookDomainRegistrationComplete(const am_domainID_t domainID)
278 {
279          mControlSender->hookSystemDomainRegistrationComplete(domainID);
280 }
281
282
283
284 void RoutingReceiver::hookSinkAvailablityStatusChange(const am_sinkID_t sinkID, const am_Availability_s & availability)
285 {
286         mControlSender->hookSystemSinkAvailablityStateChange(sinkID,availability);
287 }
288
289
290
291 void RoutingReceiver::hookSourceAvailablityStatusChange(const am_sourceID_t sourceID, const am_Availability_s & availability)
292 {
293         mControlSender->hookSystemSourceAvailablityStateChange(sourceID,availability);
294 }
295
296
297
298 void RoutingReceiver::hookDomainStateChange(const am_domainID_t domainID, const am_DomainState_e domainState)
299 {
300         mControlSender->hookSystemDomainStateChange(domainID,domainState);
301 }
302
303
304
305 void RoutingReceiver::hookTimingInformationChanged(const am_connectionID_t connectionID, const am_timeSync_t delay)
306 {
307         mDatabaseHandler->changeConnectionTimingInformation(connectionID,delay);
308 }
309
310
311
312 am_Error_e RoutingReceiver::sendChangedData(const std::vector<am_EarlyData_s> & earlyData)
313 {
314         mControlSender->hookSystemReceiveEarlyData(earlyData);
315         return E_OK;
316         //todo: change return type to void in EA model
317 }
318
319
320
321 am_Error_e RoutingReceiver::peekSinkClassID(const std::string & name, am_sourceClass_t & sourceClassID)
322 {
323         //todo: implement
324         return E_NOT_USED;
325 }
326
327 am_Error_e RoutingReceiver::peekSourceClassID(const std::string & name, am_sinkClass_t & sinkClassID)
328 {
329         //todo: implement
330         return E_NOT_USED;
331 }
332
333 am_Error_e RoutingReceiver::getDBusConnectionWrapper(DBusWrapper *dbusConnectionWrapper) const
334 {
335         //todo: return DbusWrapper
336         return E_NOT_USED;
337 }
338