2 * Copyright (c) 2012 BMW
3 * Copyright (c) copyright 2011-2012 Aricent® Group and its licensors
5 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
6 * \author Sampreeth Ramavana
7 * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
10 * 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,
11 * 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,
12 * subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 * 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.
15 * 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
16 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 * For further information see http://www.genivi.org/.
21 #include "CAmRoutingSenderDbus.h"
24 #include "CAmDbusSend.h"
25 #include "shared/CAmDltWrapper.h"
26 #include "shared/CAmDbusWrapper.h"
30 DLT_DECLARE_CONTEXT(routingDbus)
32 extern "C" IAmRoutingSend* PluginRoutingInterfaceDbusFactory()
34 CAmDltWrapper::instance()->registerContext(routingDbus, "DRS", "DBus Plugin");
35 return (new CAmRoutingSenderDbus());
38 extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface)
40 delete routingSendInterface;
43 CAmRoutingSenderDbus::CAmRoutingSenderDbus() :
44 mpCAmDBusWrapper(), //
45 mpIAmRoutingReceive(), //
46 mpDBusConnection(), //
47 mCAmRoutingDBusMessageHandler(), //
48 mIAmRoutingReceiverShadowDbus(this)
50 log(&routingDbus, DLT_LOG_INFO, "RoutingSender constructed");
53 CAmRoutingSenderDbus::~CAmRoutingSenderDbus()
55 log(&routingDbus, DLT_LOG_INFO, "RoutingSender destructed");
56 CAmDltWrapper::instance()->unregisterContext(routingDbus);
59 am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
61 log(&routingDbus, DLT_LOG_INFO, "startupInterface called");
62 mpIAmRoutingReceive = pIAmRoutingReceive;
63 mIAmRoutingReceiverShadowDbus.setRoutingReceiver(mpIAmRoutingReceive);
64 mpIAmRoutingReceive->getDBusConnectionWrapper(mpCAmDBusWrapper);
65 assert(mpCAmDBusWrapper!=NULL);
66 mpCAmDBusWrapper->getDBusConnection(mpDBusConnection);
67 assert(mpDBusConnection!=NULL);
68 mCAmRoutingDBusMessageHandler.setDBusConnection(mpDBusConnection);
72 void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const
74 version = RoutingSendVersion;
77 void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle)
79 log(&routingDbus, DLT_LOG_INFO, "sending routingReady signal");
80 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingReady");
81 mCAmRoutingDBusMessageHandler.sendMessage();
82 mIAmRoutingReceiverShadowDbus.gotReady(mMapDomains.size(),handle);
85 void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle)
87 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingRundown");
88 mCAmRoutingDBusMessageHandler.sendMessage();
89 mIAmRoutingReceiverShadowDbus.gotRundown(mMapDomains.size(),handle);
92 am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle)
94 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncAbort called");
95 mapHandles_t::iterator iter = mMapHandles.begin();
96 iter = mMapHandles.find(handle.handle);
97 if (iter != mMapHandles.end())
99 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncAbort");
100 send.append(handle.handle);
101 return (send.send());
103 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncAbort could not find interface");
108 am_Error_e CAmRoutingSenderDbus::asyncConnect(const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_CustomAvailabilityReason_t connectionFormat)
110 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncConnect called");
111 mapSources_t::iterator iter = mMapSources.begin();
112 iter = mMapSources.find(sourceID);
113 if (iter != mMapSources.end())
115 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncConnect");
116 send.append(handle.handle);
117 send.append(connectionID);
118 send.append(sourceID);
120 send.append(static_cast<int32_t>(connectionFormat));
121 mMapConnections.insert(std::make_pair(connectionID, (iter->second)));
122 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
123 return (send.sendAsync());
125 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncConnect could not find interface");
129 am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
131 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncDisconnect called");
132 mapConnections_t::iterator iter = mMapConnections.begin();
133 iter = mMapConnections.find(connectionID);
134 if (iter != mMapConnections.end())
136 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncDisconnect");
137 send.append(handle.handle);
138 send.append(connectionID);
139 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
140 return (send.sendAsync());
142 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncDisconnect could not find interface");
146 am_Error_e CAmRoutingSenderDbus::asyncSetSinkVolume(const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time)
148 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkVolume called");
149 mapSinks_t::iterator iter = mMapSinks.begin();
150 iter = mMapSinks.find(sinkID);
151 if (iter != mMapSinks.end())
153 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkVolume");
154 send.append(handle.handle);
157 send.append(static_cast<int16_t>(ramp));
159 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
160 return (send.sendAsync());
162 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkVolume could not find interface");
166 am_Error_e CAmRoutingSenderDbus::asyncSetSourceVolume(const am_Handle_s handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_CustomRampType_t ramp, const am_time_t time)
168 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceVolume called");
169 mapSources_t::iterator iter = mMapSources.begin();
170 iter = mMapSources.find(sourceID);
171 if (iter != mMapSources.end())
173 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceVolume");
174 send.append(handle.handle);
175 send.append(sourceID);
177 send.append(static_cast<int16_t>(ramp));
179 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
180 return (send.sendAsync());
182 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceVolume could not find interface");
186 am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
188 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceState called");
189 mapSources_t::iterator iter = mMapSources.begin();
190 iter = mMapSources.find(sourceID);
191 if (iter != mMapSources.end())
193 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceState");
194 send.append(handle.handle);
195 send.append(sourceID);
196 send.append(static_cast<int32_t>(state));
197 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
198 return (send.sendAsync());
200 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceState could not find interface");
204 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
206 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties called");
207 mapSinks_t::iterator iter = mMapSinks.begin();
208 iter = mMapSinks.find(sinkID);
209 if (iter != mMapSinks.end())
211 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperties");
212 send.append(handle.handle);
214 send.append(listSoundProperties);
215 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
216 return (send.sendAsync());
218 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties could not find interface");
222 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
224 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty called");
225 mapSinks_t::iterator iter = mMapSinks.begin();
226 iter = mMapSinks.find(sinkID);
227 if (iter != mMapSinks.end())
229 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperty");
230 send.append(handle.handle);
232 send.append(soundProperty);
233 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
234 return (send.sendAsync());
236 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty could not find interface");
240 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
242 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties called");
243 mapSources_t::iterator iter = mMapSources.begin();
244 iter = mMapSources.find(sourceID);
245 if (iter != mMapSources.end())
247 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperties");
248 send.append(handle.handle);
249 send.append(sourceID);
250 send.append(listSoundProperties);
251 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
252 return (send.sendAsync());
254 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties could not find interface");
258 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
260 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty called");
261 mapSources_t::iterator iter = mMapSources.begin();
262 iter = mMapSources.find(sourceID);
263 if (iter != mMapSources.end())
265 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperty");
266 send.append(handle.handle);
267 send.append(sourceID);
268 send.append(soundProperty);
269 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
270 return (send.sendAsync());
272 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty could not find interface");
276 am_Error_e CAmRoutingSenderDbus::asyncCrossFade(const am_Handle_s handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_CustomRampType_t rampType, const am_time_t time)
284 return (E_NON_EXISTENT);
287 am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
289 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::setDomainState called");
290 mapDomain_t::iterator iter = mMapDomains.begin();
291 iter = mMapDomains.find(domainID);
292 if (iter != mMapDomains.end())
294 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "setDomainState");
295 send.append(domainID);
296 send.append(static_cast<uint16_t>(domainState));
297 return (send.send());
299 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::setDomainState could not find interface");
303 am_Error_e CAmRoutingSenderDbus::returnBusName(std::string& BusName) const
305 BusName = "DbusRoutingPlugin";
309 void CAmRoutingSenderDbus::removeHandle(uint16_t handle)
311 mMapHandles.erase(handle);
314 void CAmRoutingSenderDbus::addDomainLookup(am_domainID_t domainID, rs_lookupData_s lookupData)
316 mMapDomains.insert(std::make_pair(domainID, lookupData));
319 void CAmRoutingSenderDbus::addSourceLookup(am_sourceID_t sourceID, am_domainID_t domainID)
321 mapDomain_t::iterator iter(mMapDomains.begin());
322 iter = mMapDomains.find(domainID);
323 if (iter != mMapDomains.end())
325 mMapSources.insert(std::make_pair(sourceID, iter->second));
329 void CAmRoutingSenderDbus::addSinkLookup(am_sinkID_t sinkID, am_domainID_t domainID)
331 mapDomain_t::iterator iter(mMapDomains.begin());
332 iter = mMapDomains.find(domainID);
333 if (iter != mMapDomains.end())
335 mMapSinks.insert(std::make_pair(sinkID, iter->second));
339 template <typename TKey> void CAmRoutingSenderDbus::removeEntriesForValue(const rs_lookupData_s & value, std::map<TKey,rs_lookupData_s> & map)
341 typename std::map<TKey,rs_lookupData_s>::iterator it = map.begin();
342 while ( it != map.end() )
344 if (it->second.busname == value.busname &&
345 it->second.interface == value.interface &&
346 it->second.path == value.path)
348 typename std::map<TKey,rs_lookupData_s>::iterator it_tmp = it;
357 void CAmRoutingSenderDbus::removeDomainLookup(am_domainID_t domainID)
359 mapDomain_t::iterator iter(mMapDomains.begin());
360 iter = mMapDomains.find(domainID);
361 if (iter != mMapDomains.end())
363 CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapSources);
364 CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapSinks);
365 CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapHandles);
366 CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapConnections);
367 mMapDomains.erase(domainID);
371 void CAmRoutingSenderDbus::removeSourceLookup(am_sourceID_t sourceID)
373 mMapSources.erase(sourceID);
376 void CAmRoutingSenderDbus::removeSinkLookup(am_sinkID_t sinkID)
378 mMapSinks.erase(sinkID);
381 am_Error_e CAmRoutingSenderDbus::asyncSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes)
385 //todo: implement asyncSetVolumes;
389 am_Error_e CAmRoutingSenderDbus::asyncSetSinkNotificationConfiguration(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)
393 (void) notificationConfiguration;
394 //todo: implement asyncSetSinkNotificationConfiguration;
398 am_Error_e CAmRoutingSenderDbus::asyncSetSourceNotificationConfiguration(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)
402 (void) notificationConfiguration;
403 //todo: implement asyncSetSourceNotificationConfiguration;