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