* rework of buildsystem
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / ControlReceiver.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file ControlReceiver.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section License
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
14 *
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.
22 *
23 */
24
25 #include <config.h>
26 #include "ControlReceiver.h"
27 #include <assert.h>
28 #include <dlt/dlt.h>
29
30 DLT_IMPORT_CONTEXT(DLT_CONTEXT)
31
32 using namespace am;
33
34 ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender, SocketHandler *iSocketHandler)
35         : mDatabaseHandler(iDatabaseHandler),
36           mRoutingSender(iRoutingSender),
37           mCommandSender(iCommandSender),
38           mSocketHandler(iSocketHandler)
39 {
40         assert(mDatabaseHandler!=NULL);
41         assert(mRoutingSender!=NULL);
42         assert(mCommandSender!=NULL);
43         assert(mSocketHandler!=NULL);
44 }
45
46 ControlReceiver::ControlReceiver(DatabaseHandler *iDatabaseHandler, RoutingSender *iRoutingSender, CommandSender *iCommandSender)
47         : mDatabaseHandler(iDatabaseHandler),
48           mRoutingSender(iRoutingSender),
49           mCommandSender(iCommandSender)
50 {
51 assert(mDatabaseHandler!=NULL);
52 assert(mRoutingSender!=NULL);
53 assert(mCommandSender!=NULL);
54 }
55
56
57 ControlReceiver::~ControlReceiver()
58 {
59 }
60
61 am_Error_e ControlReceiver::getRoute(const bool onlyfree, const am_sourceID_t sourceID, const am_sinkID_t sinkID, std::vector<am_Route_s> & returnList)
62 {
63         //todo: implement routing algorithm
64         return E_NOT_USED;
65 }
66
67
68
69 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)
70 {
71         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::connect got called, connectionFormat"),DLT_INT(format),DLT_STRING("sourceID"),DLT_INT(sourceID),DLT_STRING("sinkID"),DLT_INT(sinkID));
72
73         am_Connection_s tempConnection;
74         tempConnection.sinkID=sinkID;
75         tempConnection.sourceID=sourceID;
76         tempConnection.connectionFormat=format;
77         tempConnection.connectionID=0;
78
79         //todo: enter function to find out what happends if the same connection is in the course of being build up.
80         if (mDatabaseHandler->existConnection(tempConnection)) return E_ALREADY_EXISTS; //todo:enter the correct connectionID here?
81
82         mDatabaseHandler->enterConnectionDB(tempConnection,connectionID);
83         return mRoutingSender->asyncConnect(handle,connectionID,sourceID,sinkID,format);
84 }
85
86
87
88 am_Error_e ControlReceiver::disconnect(am_Handle_s & handle, const am_connectionID_t connectionID)
89 {
90         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::disconnect got called, connectionID="),DLT_INT(connectionID));
91
92         if (!mDatabaseHandler->existConnectionID(connectionID)) return E_NON_EXISTENT;   //todo: check with EA model and correct
93         return mRoutingSender->asyncDisconnect(handle,connectionID);
94 }
95
96
97
98 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)
99 {
100         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::crossfade got called, hotSource="),DLT_INT(hotSource),DLT_STRING("crossfaderID="),DLT_INT(crossfaderID),DLT_STRING("rampType="),DLT_INT(rampType),DLT_STRING("rampTime="),DLT_INT(rampTime));
101
102         if (!mDatabaseHandler->existcrossFader(crossfaderID)) return E_NON_EXISTENT;
103         return mRoutingSender->asyncCrossFade(handle,crossfaderID,hotSource,rampType,rampTime);
104 }
105
106
107
108 am_Error_e ControlReceiver::setSourceState(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SourceState_e state)
109 {
110         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceState got called, sourceID="),DLT_INT(sourceID),DLT_STRING("state="),DLT_INT(state));
111
112         am_SourceState_e sourceState;
113         if(mDatabaseHandler->getSoureState(sourceID,sourceState)!=E_OK) return E_UNKNOWN;
114         if(sourceState==state) return E_NO_CHANGE;
115         return mRoutingSender->asyncSetSourceState(handle,sourceID,state);
116 }
117
118
119
120 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)
121 {
122         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSinkVolume got called, sinkID="),DLT_INT(sinkID),DLT_STRING("volume="),DLT_INT(volume),DLT_STRING("ramp="),DLT_INT(ramp),DLT_STRING("time="),DLT_INT(time));
123
124         am_volume_t tempVolume;
125         if(mDatabaseHandler->getSinkVolume(sinkID,tempVolume)!=E_OK) return E_UNKNOWN;
126         if(tempVolume==volume) return E_NO_CHANGE;
127         return mRoutingSender->asyncSetSinkVolume(handle,sinkID,volume,ramp,time);
128 }
129
130
131
132 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)
133 {
134         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceVolume got called, sourceID="),DLT_INT(sourceID),DLT_STRING("volume="),DLT_INT(volume),DLT_STRING("ramp="),DLT_INT(rampType),DLT_STRING("time="),DLT_INT(time));
135
136         am_volume_t tempVolume;
137         if(mDatabaseHandler->getSourceVolume(sourceID,tempVolume)!=E_OK) return E_UNKNOWN;
138         if(tempVolume==volume) return E_NO_CHANGE;
139         return mRoutingSender->asyncSetSourceVolume(handle,sourceID,volume,rampType,time);
140 }
141
142
143
144 am_Error_e ControlReceiver::setSinkSoundProperty(am_Handle_s & handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty)
145 {
146         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSinkSoundProperty got called, sinkID="),DLT_INT(sinkID),DLT_STRING("soundProperty.Type="),DLT_INT(soundProperty.type),DLT_STRING("soundProperty.value="),DLT_INT(soundProperty.value));
147
148         uint16_t value;
149         if(mDatabaseHandler->getSinkSoundPropertyValue(sinkID,soundProperty.type,value)!=E_OK) return E_UNKNOWN;
150         if(value==soundProperty.value) return E_NO_CHANGE;
151         return mRoutingSender->asyncSetSinkSoundProperty(handle,sinkID,soundProperty);
152 }
153
154
155
156 am_Error_e ControlReceiver::setSourceSoundProperty(am_Handle_s & handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty)
157 {
158         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setSourceSoundProperty got called, sourceID="),DLT_INT(sourceID),DLT_STRING("soundProperty.Type="),DLT_INT(soundProperty.type),DLT_STRING("soundProperty.value="),DLT_INT(soundProperty.value));
159
160         uint16_t value;
161         if(mDatabaseHandler->getSourceSoundPropertyValue(sourceID,soundProperty.type,value)!=E_OK) return E_UNKNOWN;
162         if(value==soundProperty.value) return E_NO_CHANGE;
163         return mRoutingSender->asyncSetSourceSoundProperty(handle,sourceID,soundProperty);
164 }
165
166
167
168 am_Error_e ControlReceiver::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
169 {
170         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setDomainState got called, domainID="),DLT_INT(domainID),DLT_STRING("domainState="),DLT_INT(domainState));
171
172         am_DomainState_e tempState=DS_MIN;
173         if(mDatabaseHandler->getDomainState(domainID,tempState)!=E_OK) return E_UNKNOWN;
174         if(tempState==domainState) return E_NO_CHANGE;
175         return mRoutingSender->setDomainState(domainID,domainState);
176 }
177
178
179
180 am_Error_e ControlReceiver::abortAction(const am_Handle_s handle)
181 {
182         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::abortAction got called, handle.type="),DLT_INT(handle.handle),DLT_STRING("handle.handleType="),DLT_INT(handle.handleType));
183
184         return mRoutingSender->asyncAbort(handle);
185 }
186
187
188
189 am_Error_e ControlReceiver::enterDomainDB(const am_Domain_s & domainData, am_domainID_t & domainID)
190 {
191         return mDatabaseHandler->enterDomainDB(domainData,domainID);
192 }
193
194
195
196 am_Error_e ControlReceiver::enterMainConnectionDB(const am_MainConnection_s & mainConnectionData, am_mainConnectionID_t & connectionID)
197 {
198         return mDatabaseHandler->enterMainConnectionDB(mainConnectionData,connectionID);
199 }
200
201
202
203 am_Error_e ControlReceiver::enterSinkDB(const am_Sink_s & sinkData, am_sinkID_t & sinkID)
204 {
205         return mDatabaseHandler->enterSinkDB(sinkData,sinkID);
206 }
207
208
209
210 am_Error_e ControlReceiver::enterCrossfaderDB(const am_Crossfader_s & crossfaderData, am_crossfaderID_t & crossfaderID)
211 {
212         return mDatabaseHandler->enterCrossfaderDB(crossfaderData,crossfaderID);
213 }
214
215
216
217 am_Error_e ControlReceiver::enterGatewayDB(const am_Gateway_s & gatewayData, am_gatewayID_t & gatewayID)
218 {
219         return mDatabaseHandler->enterGatewayDB(gatewayData,gatewayID);
220 }
221
222
223
224 am_Error_e ControlReceiver::enterSourceDB(const am_Source_s & sourceData, am_sourceID_t & sourceID)
225 {
226         return mDatabaseHandler->enterSourceDB(sourceData,sourceID);
227 }
228
229 am_Error_e ControlReceiver::enterSinkClassDB(const am_SinkClass_s & sinkClass, am_sinkClass_t & sinkClassID)
230 {
231         return mDatabaseHandler->enterSinkClassDB(sinkClass,sinkClassID);
232 }
233
234 am_Error_e ControlReceiver::enterSourceClassDB(am_sourceClass_t & sourceClassID, const am_SourceClass_s & sourceClass)
235 {
236         return mDatabaseHandler->enterSourceClassDB(sourceClassID,sourceClass);
237 }
238
239
240 am_Error_e ControlReceiver::enterSystemPropertiesListDB(const std::vector<am_SystemProperty_s> & listSystemProperties)
241 {
242         return mDatabaseHandler->enterSystemProperties(listSystemProperties);
243 }
244
245
246 am_Error_e ControlReceiver::changeMainConnectionRouteDB(const am_mainConnectionID_t mainconnectionID, const am_Route_s & route)
247 {
248         return mDatabaseHandler->changeMainConnectionRouteDB(mainconnectionID,route);
249 }
250
251
252
253 am_Error_e ControlReceiver::changeMainConnectionStateDB(const am_mainConnectionID_t mainconnectionID, const am_ConnectionState_e connectionState)
254 {
255         return mDatabaseHandler->changeMainConnectionStateDB(mainconnectionID,connectionState);
256 }
257
258
259
260 am_Error_e ControlReceiver::changeSinkMainVolumeDB(const am_mainVolume_t mainVolume, const am_sinkID_t sinkID)
261 {
262         return mDatabaseHandler->changeSinkMainVolumeDB(mainVolume,sinkID);
263 }
264
265
266
267 am_Error_e ControlReceiver::changeSinkAvailabilityDB(const am_Availability_s & availability, const am_sinkID_t sinkID)
268 {
269         return mDatabaseHandler->changeSinkAvailabilityDB(availability,sinkID);
270 }
271
272
273
274 am_Error_e ControlReceiver::changDomainStateDB(const am_DomainState_e domainState, const am_domainID_t domainID)
275 {
276         return mDatabaseHandler->changDomainStateDB(domainState,domainID);
277 }
278
279
280
281 am_Error_e ControlReceiver::changeSinkMuteStateDB(const am_MuteState_e muteState, const am_sinkID_t sinkID)
282 {
283         return mDatabaseHandler->changeSinkMuteStateDB(muteState,sinkID);
284 }
285
286
287
288 am_Error_e ControlReceiver::changeMainSinkSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sinkID_t sinkID)
289 {
290         return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty,sinkID);
291 }
292
293
294
295 am_Error_e ControlReceiver::changeMainSourceSoundPropertyDB(const am_MainSoundProperty_s & soundProperty, const am_sourceID_t sourceID)
296 {
297         return mDatabaseHandler->changeMainSinkSoundPropertyDB(soundProperty,sourceID);
298 }
299
300
301
302 am_Error_e ControlReceiver::changeSourceAvailabilityDB(const am_Availability_s & availability, const am_sourceID_t sourceID)
303 {
304         return mDatabaseHandler->changeSourceAvailabilityDB(availability,sourceID);
305 }
306
307
308
309 am_Error_e ControlReceiver::changeSystemPropertyDB(const am_SystemProperty_s & property)
310 {
311         return mDatabaseHandler->changeSystemPropertyDB(property);
312 }
313
314
315
316 am_Error_e ControlReceiver::removeMainConnectionDB(const am_mainConnectionID_t mainConnectionID)
317 {
318         return mDatabaseHandler->removeMainConnectionDB(mainConnectionID);
319 }
320
321
322
323 am_Error_e ControlReceiver::removeSinkDB(const am_sinkID_t sinkID)
324 {
325         return mDatabaseHandler->removeSinkDB(sinkID);
326 }
327
328
329
330 am_Error_e ControlReceiver::removeSourceDB(const am_sourceID_t sourceID)
331 {
332         return mDatabaseHandler->removeSourceDB(sourceID);
333 }
334
335
336
337 am_Error_e ControlReceiver::removeGatewayDB(const am_gatewayID_t gatewayID)
338 {
339         return mDatabaseHandler->removeGatewayDB(gatewayID);
340 }
341
342
343
344 am_Error_e ControlReceiver::removeCrossfaderDB(const am_crossfaderID_t crossfaderID)
345 {
346         return mDatabaseHandler->removeCrossfaderDB(crossfaderID);
347 }
348
349
350
351 am_Error_e ControlReceiver::removeDomainDB(const am_domainID_t domainID)
352 {
353         return mDatabaseHandler->removeDomainDB(domainID);
354 }
355
356
357
358 am_Error_e ControlReceiver::getSourceClassInfoDB(const am_sourceID_t sourceID, am_SourceClass_s & classInfo) const
359 {
360         return mDatabaseHandler->getSourceClassInfoDB(sourceID,classInfo);
361 }
362
363
364 am_Error_e ControlReceiver::getSinkClassInfoDB(const am_sinkID_t sinkID, am_SinkClass_s & sinkClass) const
365 {
366         return mDatabaseHandler->getSinkClassInfoDB(sinkID,sinkClass);
367 }
368
369
370
371 am_Error_e ControlReceiver::getGatewayInfoDB(const am_gatewayID_t gatewayID, am_Gateway_s & gatewayData) const
372 {
373         return mDatabaseHandler->getGatewayInfoDB(gatewayID,gatewayData);
374 }
375
376
377
378 am_Error_e ControlReceiver::getCrossfaderInfoDB(const am_crossfaderID_t crossfaderID, am_Crossfader_s & crossfaderData) const
379 {
380         return mDatabaseHandler->getCrossfaderInfoDB(crossfaderID,crossfaderData);
381 }
382
383
384
385 am_Error_e ControlReceiver::getListSinksOfDomain(const am_domainID_t domainID, std::vector<am_sinkID_t> & listSinkID) const
386 {
387         return mDatabaseHandler->getListSinksOfDomain(domainID,listSinkID);
388 }
389
390
391
392 am_Error_e ControlReceiver::getListSourcesOfDomain(const am_domainID_t domainID, std::vector<am_sourceID_t> & listSourceID) const
393 {
394         return mDatabaseHandler->getListSourcesOfDomain(domainID,listSourceID);
395 }
396
397
398
399 am_Error_e ControlReceiver::getListCrossfadersOfDomain(const am_domainID_t domainID, std::vector<am_crossfaderID_t> & listGatewaysID) const
400 {
401         return mDatabaseHandler->getListCrossfadersOfDomain(domainID,listGatewaysID);
402 }
403
404
405
406 am_Error_e ControlReceiver::getListGatewaysOfDomain(const am_domainID_t domainID, std::vector<am_gatewayID_t> & listGatewaysID) const
407 {
408         return mDatabaseHandler->getListGatewaysOfDomain(domainID,listGatewaysID);
409 }
410
411
412
413 am_Error_e ControlReceiver::getListMainConnections(std::vector<am_MainConnection_s> & listMainConnections) const
414 {
415         return mDatabaseHandler->getListMainConnections(listMainConnections);
416 }
417
418
419
420 am_Error_e ControlReceiver::getListDomains(std::vector<am_Domain_s> & listDomains) const
421 {
422         return mDatabaseHandler->getListDomains(listDomains);
423 }
424
425
426
427 am_Error_e ControlReceiver::getListConnections(std::vector<am_Connection_s> & listConnections) const
428 {
429         return mDatabaseHandler->getListConnections(listConnections);
430 }
431
432
433
434 am_Error_e ControlReceiver::getListSinks(std::vector<am_Sink_s> & listSinks) const
435 {
436         return mDatabaseHandler->getListSinks(listSinks);
437 }
438
439
440
441 am_Error_e ControlReceiver::getListSources(std::vector<am_Source_s> & listSources) const
442 {
443         return mDatabaseHandler->getListSources(listSources);
444 }
445
446
447
448 am_Error_e ControlReceiver::getListSourceClasses(std::vector<am_SourceClass_s> & listSourceClasses) const
449 {
450         return mDatabaseHandler->getListSourceClasses(listSourceClasses);
451 }
452
453
454
455 am_Error_e ControlReceiver::getListHandles(std::vector<am_Handle_s> & listHandles) const
456 {
457         return mRoutingSender->getListHandles(listHandles);
458 }
459
460
461
462 am_Error_e ControlReceiver::getListCrossfaders(std::vector<am_Crossfader_s> & listCrossfaders) const
463 {
464         return mDatabaseHandler->getListCrossfaders(listCrossfaders);
465 }
466
467
468
469 am_Error_e ControlReceiver::getListGateways(std::vector<am_Gateway_s> & listGateways) const
470 {
471         return mDatabaseHandler->getListGateways(listGateways);
472 }
473
474
475
476 am_Error_e ControlReceiver::getListSinkClasses(std::vector<am_SinkClass_s> & listSinkClasses) const
477 {
478         return mDatabaseHandler->getListSinkClasses(listSinkClasses);
479 }
480
481
482 am_Error_e ControlReceiver::getListSystemProperties(std::vector<am_SystemProperty_s> & listSystemProperties) const
483 {
484         return mDatabaseHandler->getListSystemProperties(listSystemProperties);
485 }
486
487
488 am_Error_e ControlReceiver::changeSinkClassInfoDB(const am_SinkClass_s & classInfo)
489 {
490         return mDatabaseHandler->changeSinkClassInfoDB(classInfo);
491 }
492
493 am_Error_e ControlReceiver::changeSourceClassInfoDB(const am_SourceClass_s & classInfo)
494 {
495         return mDatabaseHandler->changeSourceClassInfoDB(classInfo);
496 }
497
498 am_Error_e ControlReceiver::removeSinkClassDB(const am_sinkClass_t sinkClassID)
499 {
500         return mDatabaseHandler->removeSinkClassDB(sinkClassID);
501 }
502
503 am_Error_e ControlReceiver::removeSourceClassDB(const am_sourceClass_t sourceClassID)
504 {
505         return mDatabaseHandler->removeSourceClassDB(sourceClassID);
506 }
507
508 void ControlReceiver::setCommandReady()
509 {
510         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setCommandReady got called"));
511         mCommandSender->cbCommunicationReady();
512 }
513
514 void ControlReceiver::setRoutingReady()
515 {
516         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("ControlReceiver::setRoutingReady got called"));
517         mRoutingSender->routingInterfacesReady();
518 }
519
520 am_Error_e am::ControlReceiver::getSocketHandler(SocketHandler *& socketHandler)
521 {
522 #ifdef WITH_SOCKETHANDLER_LOOP
523         socketHandler=mSocketHandler;
524         return E_OK;
525 #else
526         return E_UNKNOWN;
527 #endif
528 }
529
530
531
532
533