2 * Copyright (c) 2012 BMW
4 * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
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.
15 * For further information see http://www.genivi.org/.
24 #include "shared/CAmDltWrapper.h"
25 #include "CAmRoutingSenderCAPI.h"
26 #include "CAmRoutingSenderCommon.h"
33 DLT_DECLARE_CONTEXT(ctxCommandCAPI)
36 extern "C" IAmRoutingSend* PluginRoutingInterfaceCAPIFactory()
38 CAmDltWrapper::instance()->registerContext(ctxCommandCAPI, "DRS", "Common-API Plugin");
39 return (new CAmRoutingSenderCAPI(Am_CAPI));
42 extern "C" void destroyPluginRoutingInterfaceCAPI(IAmRoutingSend* routingSendInterface)
44 delete routingSendInterface;
47 const char * CAmRoutingSenderCAPI::ROUTING_INTERFACE_SERVICE = "local:org.genivi.audiomanager.routinginterface:org.genivi.audiomanager";
49 CAmRoutingSenderCAPI::CAmRoutingSenderCAPI() :
50 mIsServiceStarted(false),
52 mpCAmCAPIWrapper(NULL), //
53 mpIAmRoutingReceive(NULL),
56 log(&ctxCommandCAPI, DLT_LOG_INFO, "RoutingSender constructed");
59 CAmRoutingSenderCAPI::CAmRoutingSenderCAPI(CAmCommonAPIWrapper *aWrapper) :
60 mIsServiceStarted(false),
62 mpCAmCAPIWrapper(aWrapper), //
63 mpIAmRoutingReceive(NULL),
66 log(&ctxCommandCAPI, DLT_LOG_INFO, "CommandSenderCAPI constructor called");
67 assert(mpCAmCAPIWrapper!=NULL);
70 CAmRoutingSenderCAPI::~CAmRoutingSenderCAPI()
72 log(&ctxCommandCAPI, DLT_LOG_INFO, "RoutingSender deallocate");
73 CAmDltWrapper::instance()->unregisterContext(ctxCommandCAPI);
74 tearDownInterface(mpIAmRoutingReceive);
77 am_Error_e CAmRoutingSenderCAPI::startService(IAmRoutingReceive* pIAmRoutingReceive)
79 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
80 if(!mIsServiceStarted)
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) )
88 return (E_NOT_POSSIBLE);
90 mIsServiceStarted = true;
95 am_Error_e CAmRoutingSenderCAPI::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
97 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
98 mpIAmRoutingReceive = pIAmRoutingReceive;
99 return startService(mpIAmRoutingReceive);
102 am_Error_e CAmRoutingSenderCAPI::tearDownInterface(IAmRoutingReceive*)
104 log(&ctxCommandCAPI, DLT_LOG_INFO, __PRETTY_FUNCTION__);
107 if(mIsServiceStarted)
109 mIsServiceStarted = false;
110 mpCAmCAPIWrapper->unregisterStub(CAmRoutingSenderCAPI::ROUTING_INTERFACE_SERVICE);
115 return (E_NOT_POSSIBLE);
118 void CAmRoutingSenderCAPI::getInterfaceVersion(std::string & version) const
120 version = RoutingSendVersion;
123 void CAmRoutingSenderCAPI::setRoutingReady(const uint16_t handle)
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);
131 void CAmRoutingSenderCAPI::setRoutingRundown(const uint16_t handle)
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);
139 am_Error_e CAmRoutingSenderCAPI::asyncAbort(const am_Handle_s handle)
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));
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)
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)
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);
161 am_Error_e CAmRoutingSenderCAPI::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
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)
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);
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)
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)
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);
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)
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)
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);
203 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
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)
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);
217 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
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)
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);
231 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
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)
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);
245 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
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)
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);
259 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
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)
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);
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)
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)
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);
286 am_Error_e CAmRoutingSenderCAPI::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
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));
294 am_Error_e CAmRoutingSenderCAPI::returnBusName(std::string& BusName) const
296 BusName = CAmLookupData::BUS_NAME;
300 am_Error_e CAmRoutingSenderCAPI::asyncSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& volumes)
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)
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);
316 am_Error_e CAmRoutingSenderCAPI::asyncSetSinkNotificationConfiguration(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& nc)
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)
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);
330 am_Error_e CAmRoutingSenderCAPI::asyncSetSourceNotificationConfiguration(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& nc)
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)
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);