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
9 * 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,
10 * 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,
11 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13 * 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.
14 * 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
15 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 * For further information see http://www.genivi.org/.
20 #include "CAmRoutingSenderDbus.h"
23 #include "CAmDbusSend.h"
24 #include "shared/CAmDltWrapper.h"
25 #include "shared/CAmDbusWrapper.h"
29 DLT_DECLARE_CONTEXT(routingDbus)
31 extern "C" IAmRoutingSend* PluginRoutingInterfaceDbusFactory()
33 CAmDltWrapper::instance()->registerContext(routingDbus, "DRS", "DBus Plugin");
34 return (new CAmRoutingSenderDbus());
37 extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface)
39 delete routingSendInterface;
42 CAmRoutingSenderDbus::CAmRoutingSenderDbus() :
43 mpCAmDBusWrapper(), //
44 mpIAmRoutingReceive(), //
45 mpDBusConnection(), //
46 mCAmRoutingDBusMessageHandler(), //
47 mIAmRoutingReceiverShadowDbus(this)
49 log(&routingDbus, DLT_LOG_INFO, "RoutingSender constructed");
52 CAmRoutingSenderDbus::~CAmRoutingSenderDbus()
54 log(&routingDbus, DLT_LOG_INFO, "RoutingSender destructed");
55 CAmDltWrapper::instance()->unregisterContext(routingDbus);
58 am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
60 log(&routingDbus, DLT_LOG_INFO, "startupInterface called");
61 mpIAmRoutingReceive = pIAmRoutingReceive;
62 mIAmRoutingReceiverShadowDbus.setRoutingReceiver(mpIAmRoutingReceive);
63 mpIAmRoutingReceive->getDBusConnectionWrapper(mpCAmDBusWrapper);
64 assert(mpCAmDBusWrapper!=NULL);
65 mpCAmDBusWrapper->getDBusConnection(mpDBusConnection);
66 assert(mpDBusConnection!=NULL);
67 mCAmRoutingDBusMessageHandler.setDBusConnection(mpDBusConnection);
71 void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const
73 version = RoutingSendVersion;
76 void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle)
78 log(&routingDbus, DLT_LOG_INFO, "sending routingReady signal");
79 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingReady");
80 mCAmRoutingDBusMessageHandler.sendMessage();
81 mIAmRoutingReceiverShadowDbus.gotReady(mMapDomains.size(),handle);
84 void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle)
86 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingRundown");
87 mCAmRoutingDBusMessageHandler.sendMessage();
88 mIAmRoutingReceiverShadowDbus.gotRundown(mMapDomains.size(),handle);
91 am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle)
93 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncAbort called");
94 mapHandles_t::iterator iter = mMapHandles.begin();
95 iter = mMapHandles.find(handle.handle);
96 if (iter != mMapHandles.end())
98 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncAbort");
99 send.append(handle.handle);
100 return (send.send());
102 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncAbort could not find interface");
107 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_ConnectionFormat_e connectionFormat)
109 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncConnect called");
110 mapSources_t::iterator iter = mMapSources.begin();
111 iter = mMapSources.find(sourceID);
112 if (iter != mMapSources.end())
114 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncConnect");
115 send.append(handle.handle);
116 send.append(connectionID);
117 send.append(sourceID);
119 send.append(static_cast<int32_t>(connectionFormat));
120 mMapConnections.insert(std::make_pair(connectionID, (iter->second)));
121 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
122 return (send.sendAsync());
124 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncConnect could not find interface");
128 am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
130 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncDisconnect called");
131 mapConnections_t::iterator iter = mMapConnections.begin();
132 iter = mMapConnections.find(connectionID);
133 if (iter != mMapConnections.end())
135 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncDisconnect");
136 send.append(handle.handle);
137 send.append(connectionID);
138 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
139 return (send.sendAsync());
141 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncDisconnect could not find interface");
145 am_Error_e CAmRoutingSenderDbus::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)
147 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkVolume called");
148 mapSinks_t::iterator iter = mMapSinks.begin();
149 iter = mMapSinks.find(sinkID);
150 if (iter != mMapSinks.end())
152 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkVolume");
153 send.append(handle.handle);
156 send.append(static_cast<int32_t>(ramp));
158 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
159 return (send.send());
161 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkVolume could not find interface");
165 am_Error_e CAmRoutingSenderDbus::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)
167 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceVolume called");
168 mapSources_t::iterator iter = mMapSources.begin();
169 iter = mMapSources.find(sourceID);
170 if (iter != mMapSources.end())
172 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceVolume");
173 send.append(handle.handle);
174 send.append(sourceID);
176 send.append(static_cast<int16_t>(ramp));
178 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
179 return (send.send());
181 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceVolume could not find interface");
185 am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
187 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceState called");
188 mapSources_t::iterator iter = mMapSources.begin();
189 iter = mMapSources.find(sourceID);
190 if (iter != mMapSources.end())
192 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceState");
193 send.append(handle.handle);
194 send.append(sourceID);
195 send.append(static_cast<int32_t>(state));
196 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
197 return (send.sendAsync());
199 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceState could not find interface");
203 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
205 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties called");
206 mapSinks_t::iterator iter = mMapSinks.begin();
207 iter = mMapSinks.find(sinkID);
208 if (iter != mMapSinks.end())
210 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperties");
211 send.append(handle.handle);
213 send.append(listSoundProperties);
214 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
215 return (send.send());
217 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties could not find interface");
221 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
223 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty called");
224 mapSinks_t::iterator iter = mMapSinks.begin();
225 iter = mMapSinks.find(sinkID);
226 if (iter != mMapSinks.end())
228 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperty");
229 send.append(handle.handle);
231 send.append(soundProperty);
232 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
233 return (send.send());
235 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty could not find interface");
239 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
241 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties called");
242 mapSources_t::iterator iter = mMapSources.begin();
243 iter = mMapSources.find(sourceID);
244 if (iter != mMapSources.end())
246 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperties");
247 send.append(handle.handle);
248 send.append(sourceID);
249 send.append(listSoundProperties);
250 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
251 return (send.send());
253 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties could not find interface");
257 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
259 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty called");
260 mapSources_t::iterator iter = mMapSources.begin();
261 iter = mMapSources.find(sourceID);
262 if (iter != mMapSources.end())
264 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperty");
265 send.append(handle.handle);
266 send.append(sourceID);
267 send.append(soundProperty);
268 mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
269 return (send.send());
271 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty could not find interface");
275 am_Error_e CAmRoutingSenderDbus::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)
283 return (E_NON_EXISTENT);
286 am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
288 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::setDomainState called");
289 mapDomain_t::iterator iter = mMapDomains.begin();
290 iter = mMapDomains.find(domainID);
291 if (iter != mMapDomains.end())
293 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "setDomainState");
294 send.append(domainID);
295 send.append(static_cast<int>(domainState));
296 return (send.send());
298 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::setDomainState could not find interface");
302 am_Error_e CAmRoutingSenderDbus::returnBusName(std::string& BusName) const
304 BusName = "DbusRoutingPlugin";
308 void CAmRoutingSenderDbus::removeHandle(uint16_t handle)
310 mMapHandles.erase(handle);
313 void CAmRoutingSenderDbus::addDomainLookup(am_domainID_t domainID, rs_lookupData_s lookupData)
315 mMapDomains.insert(std::make_pair(domainID, lookupData));
318 void CAmRoutingSenderDbus::addSourceLookup(am_sourceID_t sourceID, am_domainID_t domainID)
320 mapDomain_t::iterator iter(mMapDomains.begin());
321 iter = mMapDomains.find(domainID);
322 if (iter != mMapDomains.end())
324 mMapSources.insert(std::make_pair(sourceID, iter->second));
328 void CAmRoutingSenderDbus::addSinkLookup(am_sinkID_t sinkID, am_domainID_t domainID)
330 mapDomain_t::iterator iter(mMapDomains.begin());
331 iter = mMapDomains.find(domainID);
332 if (iter != mMapDomains.end())
334 mMapSinks.insert(std::make_pair(sinkID, iter->second));
338 void CAmRoutingSenderDbus::removeDomainLookup(am_domainID_t domainID)
340 mMapHandles.erase(domainID);
343 void CAmRoutingSenderDbus::removeSourceLookup(am_sourceID_t sourceID)
345 mMapHandles.erase(sourceID);
348 am_Error_e CAmRoutingSenderDbus::asyncSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes)
352 //todo: implement asyncSetVolumes;
356 am_Error_e CAmRoutingSenderDbus::asyncSetSinkNotificationConfiguration(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)
360 (void) notificationConfiguration;
361 //todo: implement asyncSetSinkNotificationConfiguration;
365 am_Error_e CAmRoutingSenderDbus::asyncSetSourceNotificationConfiguration(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)
369 (void) notificationConfiguration;
370 //todo: implement asyncSetSourceNotificationConfiguration;
374 void CAmRoutingSenderDbus::removeSinkLookup(am_sinkID_t sinkID)
376 mMapHandles.erase(sinkID);