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