* Bug 123 fixed. Lambda expression compile issues with GCC >= 4.7.x specific compile...
[profile/ivi/genivi/genivi-audio-manager.git] / PluginRoutingInterfaceCAPI / src / CAmRoutingSenderCAPI.cpp
1 /**
2  *  Copyright (c) 2012 BMW
3  *
4  *  \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
5  *
6  *  \copyright
7  *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
8  *  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9  *  subject to the following conditions:
10  *  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
12  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
13  *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14  *
15  *  For further information see http://www.genivi.org/.
16  */
17
18 #include <cassert>
19 #include <map>
20 #include <algorithm>
21 #include <string>
22 #include <vector>
23 #include <set>
24 #include "shared/CAmDltWrapper.h"
25 #include "CAmRoutingSenderCAPI.h"
26 #include "CAmRoutingSenderCommon.h"
27
28
29
30
31 namespace am
32 {
33 DLT_DECLARE_CONTEXT(ctxCommandCAPI)
34
35
36 extern "C" IAmRoutingSend* PluginRoutingInterfaceCAPIFactory()
37 {
38     CAmDltWrapper::instance()->registerContext(ctxCommandCAPI, "DRS", "Common-API Plugin");
39     return (new CAmRoutingSenderCAPI(Am_CAPI));
40 }
41
42 extern "C" void destroyPluginRoutingInterfaceCAPI(IAmRoutingSend* routingSendInterface)
43 {
44     delete routingSendInterface;
45 }
46
47 const char * CAmRoutingSenderCAPI::ROUTING_INTERFACE_SERVICE = "local:org.genivi.audiomanager.routinginterface:org.genivi.audiomanager";
48
49 CAmRoutingSenderCAPI::CAmRoutingSenderCAPI() :
50                 mIsServiceStarted(false),
51                 mLookupData(),
52                                 mpCAmCAPIWrapper(NULL), //
53                                 mpIAmRoutingReceive(NULL),
54                                 mService()
55 {
56     log(&ctxCommandCAPI, DLT_LOG_INFO, "RoutingSender constructed");
57 }
58
59 CAmRoutingSenderCAPI::CAmRoutingSenderCAPI(CAmCommonAPIWrapper *aWrapper) :
60                 mIsServiceStarted(false),
61                 mLookupData(),
62                 mpCAmCAPIWrapper(aWrapper), //
63                 mpIAmRoutingReceive(NULL),
64                 mService()
65 {
66     log(&ctxCommandCAPI, DLT_LOG_INFO, "CommandSenderCAPI constructor called");
67     assert(mpCAmCAPIWrapper!=NULL);
68 }
69
70 CAmRoutingSenderCAPI::~CAmRoutingSenderCAPI()
71 {
72     log(&ctxCommandCAPI, DLT_LOG_INFO, "RoutingSender deallocate");
73     CAmDltWrapper::instance()->unregisterContext(ctxCommandCAPI);
74     tearDownInterface(mpIAmRoutingReceive);
75 }
76
77 am_Error_e CAmRoutingSenderCAPI::startService(IAmRoutingReceive* pIAmRoutingReceive)
78 {
79         log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
80         if(!mIsServiceStarted)
81         {
82                 assert(pIAmRoutingReceive);
83                 mService = std::make_shared<CAmRoutingService>(pIAmRoutingReceive, &mLookupData, mpCAmCAPIWrapper);
84             mService->setRoutingReadyAttribute(org::genivi::am::am_RoutingReady_e::RR_UNKNOWN);
85                 //Registers the service
86                 if( false == mpCAmCAPIWrapper->registerStub(mService, CAmRoutingSenderCAPI::ROUTING_INTERFACE_SERVICE) )
87                 {
88                         return (E_NOT_POSSIBLE);
89                 }
90                 mIsServiceStarted = true;
91         }
92     return (E_OK);
93 }
94
95 am_Error_e CAmRoutingSenderCAPI::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
96 {
97         log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
98     mpIAmRoutingReceive = pIAmRoutingReceive;
99     return startService(mpIAmRoutingReceive);
100 }
101
102 am_Error_e CAmRoutingSenderCAPI::tearDownInterface(IAmRoutingReceive*)
103 {
104         log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
105     if(mpCAmCAPIWrapper)
106     {
107         if(mIsServiceStarted)
108         {
109                 mIsServiceStarted = false;
110                         mpCAmCAPIWrapper->unregisterStub(CAmRoutingSenderCAPI::ROUTING_INTERFACE_SERVICE);
111                         mService.reset();
112         }
113                 return (E_OK);
114     }
115     return (E_NOT_POSSIBLE);
116 }
117
118 void CAmRoutingSenderCAPI::getInterfaceVersion(std::string & version) const
119 {
120     version = RoutingSendVersion;
121 }
122
123 void CAmRoutingSenderCAPI::setRoutingReady(const uint16_t handle)
124 {
125         assert(mpIAmRoutingReceive);
126     log(&ctxCommandCAPI, DLT_LOG_INFO, "sending routingReady signal");
127     mpIAmRoutingReceive->confirmRoutingReady(handle,E_OK);
128     mService->setRoutingReadyAttribute(org::genivi::am::am_RoutingReady_e::RR_READY);
129 }
130
131 void CAmRoutingSenderCAPI::setRoutingRundown(const uint16_t handle)
132 {
133         log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
134         assert(mpIAmRoutingReceive);
135         mService->setRoutingReadyAttribute(org::genivi::am::am_RoutingReady_e::RR_RUNDOWN);
136         mService->gotRundown(mLookupData.numberOfDomains(),handle);
137 }
138
139 am_Error_e CAmRoutingSenderCAPI::asyncAbort(const am_Handle_s handle)
140 {
141     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncAbort called");
142         return mLookupData.asyncAbort(handle,[](const CommonAPI::CallStatus& callStatus){
143                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
144         });
145 }
146
147 am_Error_e CAmRoutingSenderCAPI::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)
148 {
149     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncConnect called");
150         return mLookupData.asyncConnect(handle,connectionID, sourceID, sinkID, connectionFormat, [&,handle,connectionID](const CommonAPI::CallStatus& callStatus){
151                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
152                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
153                 {
154                         org::genivi::am::am_Handle_s dst;
155                         CAmConvertAM2CAPI(handle, dst);
156                         mService->ackConnect(dst, connectionID, org::genivi::am::am_Error_e::E_NON_EXISTENT);
157                 }
158         });
159 }
160
161 am_Error_e CAmRoutingSenderCAPI::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
162 {
163         log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncDisconnect called");
164         return mLookupData.asyncDisconnect(handle,connectionID, [&, handle, connectionID](const CommonAPI::CallStatus& callStatus){
165                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
166                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
167                 {
168                         org::genivi::am::am_Handle_s dst;
169                         CAmConvertAM2CAPI(handle, dst);
170                         mService->ackDisconnect(dst, connectionID, org::genivi::am::am_Error_e::E_NON_EXISTENT);
171                 }
172         });
173 }
174
175 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)
176 {
177     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSinkVolume called");
178         return mLookupData.asyncSetSinkVolume(handle,sinkID, volume, ramp, time, [&, handle, volume](const CommonAPI::CallStatus& callStatus){
179                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
180                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
181                 {
182                         org::genivi::am::am_Handle_s dst;
183                         CAmConvertAM2CAPI(handle, dst);
184                         mService->ackSetSinkVolumeChange(dst, volume, org::genivi::am::am_Error_e::E_NON_EXISTENT);
185                 }
186         });
187 }
188
189 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)
190 {
191     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSourceVolume called");
192         return mLookupData.asyncSetSourceVolume(handle,sourceID, volume, ramp, time, [&, handle, volume](const CommonAPI::CallStatus& callStatus){
193                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
194                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
195                 {
196                         org::genivi::am::am_Handle_s dst;
197                         CAmConvertAM2CAPI(handle, dst);
198                         mService->ackSetSourceVolumeChange(dst, volume, org::genivi::am::am_Error_e::E_NON_EXISTENT);
199                 }
200         });
201 }
202
203 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
204 {
205     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSourceState called");
206         return mLookupData.asyncSetSourceState(handle,sourceID, state,[&, handle](const CommonAPI::CallStatus& callStatus){
207                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
208                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
209                 {
210                         org::genivi::am::am_Handle_s dst;
211                         CAmConvertAM2CAPI(handle, dst);
212                         mService->ackSetSourceState(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
213                 }
214         });
215 }
216
217 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
218 {
219     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSinkSoundProperties called");
220         return mLookupData.asyncSetSinkSoundProperties(handle,sinkID, listSoundProperties, [&, handle](const CommonAPI::CallStatus& callStatus){
221                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
222                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
223                 {
224                         org::genivi::am::am_Handle_s dst;
225                         CAmConvertAM2CAPI(handle, dst);
226                         mService->ackSetSinkSoundProperties(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
227                 }
228         });
229 }
230
231 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
232 {
233     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSinkSoundProperty called");
234         return mLookupData.asyncSetSinkSoundProperty(handle, sinkID, soundProperty, [&, handle](const CommonAPI::CallStatus& callStatus){
235                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
236                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
237                 {
238                         org::genivi::am::am_Handle_s dst;
239                         CAmConvertAM2CAPI(handle, dst);
240                         mService->ackSetSinkSoundProperty(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
241                 }
242         });
243 }
244
245 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
246 {
247     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSourceSoundProperties called");
248         return mLookupData.asyncSetSourceSoundProperties(handle, sourceID, listSoundProperties, [&, handle](const CommonAPI::CallStatus& callStatus){
249                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
250                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
251                 {
252                         org::genivi::am::am_Handle_s dst;
253                         CAmConvertAM2CAPI(handle, dst);
254                         mService->ackSetSourceSoundProperties(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
255                 }
256         });
257 }
258
259 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
260 {
261     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSourceSoundProperty called");
262         return mLookupData.asyncSetSourceSoundProperty(handle, sourceID, soundProperty, [&, handle](const CommonAPI::CallStatus& callStatus){
263                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
264                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
265                 {
266                         org::genivi::am::am_Handle_s dst;
267                         CAmConvertAM2CAPI(handle, dst);
268                         mService->ackSetSourceSoundProperty(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
269                 }
270         });
271 }
272
273 am_Error_e CAmRoutingSenderCAPI::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)
274 {
275         return mLookupData.asyncCrossFade(handle, crossfaderID, hotSink, rampType, time, [&, handle, hotSink](const CommonAPI::CallStatus& callStatus){
276                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
277                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
278                 {
279                         org::genivi::am::am_Handle_s dst;
280                         CAmConvertAM2CAPI(handle, dst);
281                         mService->ackCrossFading(dst, (org::genivi::am::am_HotSink_e)hotSink, org::genivi::am::am_Error_e::E_NON_EXISTENT);
282                 }
283         });
284 }
285
286 am_Error_e CAmRoutingSenderCAPI::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
287 {
288     log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::setDomainState called");
289         return mLookupData.setDomainState(domainID, domainState, [](const CommonAPI::CallStatus& callStatus, org::genivi::am::am_Error_e error){
290                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus),"Error",static_cast<am_Error_e>(error));
291         });
292 }
293
294 am_Error_e CAmRoutingSenderCAPI::returnBusName(std::string& BusName) const
295 {
296     BusName = CAmLookupData::BUS_NAME;
297     return (E_OK);
298 }
299
300 am_Error_e CAmRoutingSenderCAPI::asyncSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& volumes)
301 {
302         log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetVolumes called");
303         return mLookupData.asyncSetVolumes(handle, volumes, [&, handle, volumes](const CommonAPI::CallStatus& callStatus){
304                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
305                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
306                 {
307                         org::genivi::am::am_Handle_s dst;
308                         CAmConvertAM2CAPI(handle, dst);
309                         org::genivi::am::am_Volumes_L list;
310                         CAmConvertAMVector2CAPI(volumes, list);
311                         mService->ackSetVolumes(dst, list, org::genivi::am::am_Error_e::E_NON_EXISTENT);
312                 }
313         });
314 }
315
316 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkNotificationConfiguration(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& nc)
317 {
318         log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSinkNotificationConfiguration called");
319         return mLookupData.asyncSetSinkNotificationConfiguration(handle, sinkID, nc, [&, handle](const CommonAPI::CallStatus& callStatus){
320                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
321                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
322                 {
323                         org::genivi::am::am_Handle_s dst;
324                         CAmConvertAM2CAPI(handle, dst);
325                         mService->ackSinkNotificationConfiguration(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
326                 }
327         });
328 }
329
330 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceNotificationConfiguration(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& nc)
331 {
332         log(&ctxCommandCAPI, DLT_LOG_INFO, "CAmRoutingSenderCAPI::asyncSetSourceNotificationConfiguration called");
333         return mLookupData.asyncSetSourceNotificationConfiguration(handle, sourceID, nc, [&, handle](const CommonAPI::CallStatus& callStatus){
334                 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__, "Response with call status:", static_cast<int16_t>(callStatus));
335                 if (callStatus != CommonAPI::CallStatus::SUCCESS)
336                 {
337                         org::genivi::am::am_Handle_s dst;
338                         CAmConvertAM2CAPI(handle, dst);
339                         mService->ackSourceNotificationConfiguration(dst, org::genivi::am::am_Error_e::E_NON_EXISTENT);
340                 }
341         });
342 }
343
344 }
345