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 return (new CAmRoutingSenderDbus());
36 extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface)
38 delete routingSendInterface;
41 CAmRoutingSenderDbus::CAmRoutingSenderDbus() :
42 mpCAmDBusWrapper(), //
43 mpIAmRoutingReceive(), //
44 mpDBusConnection(), //
45 mCAmRoutingDBusMessageHandler(), //
46 mIAmRoutingReceiverShadowDbus(this)
48 log(&routingDbus, DLT_LOG_INFO, "RoutingSender constructed");
51 CAmRoutingSenderDbus::~CAmRoutingSenderDbus()
53 log(&routingDbus, DLT_LOG_INFO, "RoutingSender destructed");
54 CAmDltWrapper::instance()->unregisterContext(routingDbus);
57 am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
59 log(&routingDbus, DLT_LOG_INFO, "startupInterface called");
60 mpIAmRoutingReceive = pIAmRoutingReceive;
61 mIAmRoutingReceiverShadowDbus.setRoutingReceiver(mpIAmRoutingReceive);
62 mpIAmRoutingReceive->getDBusConnectionWrapper(mpCAmDBusWrapper);
63 assert(mpCAmDBusWrapper!=NULL);
64 mpCAmDBusWrapper->getDBusConnection(mpDBusConnection);
65 assert(mpDBusConnection!=NULL);
66 mCAmRoutingDBusMessageHandler.setDBusConnection(mpDBusConnection);
70 void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const
72 version = RoutingSendVersion;
75 void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle)
77 log(&routingDbus, DLT_LOG_INFO, "sending routingReady signal");
78 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingReady");
79 mCAmRoutingDBusMessageHandler.sendMessage();
80 mIAmRoutingReceiverShadowDbus.gotReady(mMapDomains.size(),handle);
83 void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle)
85 mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingRundown");
86 mCAmRoutingDBusMessageHandler.sendMessage();
87 mIAmRoutingReceiverShadowDbus.gotRundown(mMapDomains.size(),handle);
90 am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle)
92 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncAbort called");
93 mapHandles_t::iterator iter = mMapHandles.begin();
94 iter = mMapHandles.find(handle.handle);
95 if (iter != mMapHandles.end())
97 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncAbort");
98 send.append(handle.handle);
101 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncAbort could not find interface");
106 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)
108 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncConnect called");
109 mapSources_t::iterator iter = mMapSources.begin();
110 iter = mMapSources.find(sourceID);
111 if (iter != mMapSources.end())
113 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncConnect");
114 send.append(handle.handle);
115 send.append(connectionID);
116 send.append(sourceID);
118 send.append(static_cast<int16_t>(connectionFormat));
119 mMapConnections.insert(std::make_pair(connectionID, (iter->second)));
120 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
121 return (send.send());
123 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncConnect could not find interface");
127 am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
129 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncDisconnect called");
130 mapConnections_t::iterator iter = mMapConnections.begin();
131 iter = mMapConnections.find(connectionID);
132 if (iter != mMapConnections.end())
134 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncDisconnect");
135 send.append(handle.handle);
136 send.append(connectionID);
137 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
138 return (send.send());
140 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncDisconnect could not find interface");
144 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)
146 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkVolume called");
147 mapSinks_t::iterator iter = mMapSinks.begin();
148 iter = mMapSinks.find(sinkID);
149 if (iter != mMapSinks.end())
151 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkVolume");
152 send.append(handle.handle);
155 send.append(static_cast<int16_t>(ramp));
157 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
158 return (send.send());
160 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkVolume could not find interface");
164 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)
166 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceVolume called");
167 mapSources_t::iterator iter = mMapSources.begin();
168 iter = mMapSources.find(sourceID);
169 if (iter != mMapSources.end())
171 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceVolume");
172 send.append(handle.handle);
173 send.append(sourceID);
175 send.append(static_cast<int16_t>(ramp));
177 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
178 return (send.send());
180 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceVolume could not find interface");
184 am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
186 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceState called");
187 mapSources_t::iterator iter = mMapSources.begin();
188 iter = mMapSources.find(sourceID);
189 if (iter != mMapSources.end())
191 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceState");
192 send.append(handle.handle);
193 send.append(sourceID);
194 send.append(static_cast<int16_t>(state));
195 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
196 return (send.send());
198 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceState could not find interface");
202 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
204 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties called");
205 mapSinks_t::iterator iter = mMapSinks.begin();
206 iter = mMapSinks.find(sinkID);
207 if (iter != mMapSinks.end())
209 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperties");
210 send.append(handle.handle);
212 send.append(listSoundProperties);
213 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
214 return (send.send());
216 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties could not find interface");
220 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
222 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty called");
223 mapSinks_t::iterator iter = mMapSinks.begin();
224 iter = mMapSinks.find(sinkID);
225 if (iter != mMapSinks.end())
227 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperty");
228 send.append(handle.handle);
230 send.append(soundProperty);
231 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
232 return (send.send());
234 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty could not find interface");
238 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
240 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties called");
241 mapSources_t::iterator iter = mMapSources.begin();
242 iter = mMapSources.find(sourceID);
243 if (iter != mMapSources.end())
245 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperties");
246 send.append(handle.handle);
247 send.append(sourceID);
248 send.append(listSoundProperties);
249 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
250 return (send.send());
252 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties could not find interface");
256 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
258 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty called");
259 mapSources_t::iterator iter = mMapSources.begin();
260 iter = mMapSources.find(sourceID);
261 if (iter != mMapSources.end())
263 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperty");
264 send.append(handle.handle);
265 send.append(sourceID);
266 send.append(soundProperty);
267 mMapHandles.insert(std::make_pair(handle.handle, iter->second));
268 return (send.send());
270 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty could not find interface");
274 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)
282 return (E_NON_EXISTENT);
285 am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
287 log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::setDomainState called");
288 mapDomain_t::iterator iter = mMapDomains.begin();
289 iter = mMapDomains.find(domainID);
290 if (iter != mMapDomains.end())
292 CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "setDomainState");
293 send.append(domainID);
294 send.append(static_cast<int16_t>(domainState));
295 return (send.send());
297 log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::setDomainState could not find interface");
301 am_Error_e CAmRoutingSenderDbus::returnBusName(std::string& BusName) const
303 BusName = "DbusRoutingPlugin";
307 void CAmRoutingSenderDbus::removeHandle(uint16_t handle)
309 mMapHandles.erase(handle);
312 void CAmRoutingSenderDbus::addDomainLookup(am_domainID_t domainID, rs_lookupData_s lookupData)
314 mMapDomains.insert(std::make_pair(domainID, lookupData));
317 void CAmRoutingSenderDbus::addSourceLookup(am_sourceID_t sourceID, am_domainID_t domainID)
319 mapDomain_t::iterator iter(mMapDomains.begin());
320 iter = mMapDomains.find(domainID);
321 if (iter != mMapDomains.end())
323 mMapSources.insert(std::make_pair(sourceID, iter->second));
327 void CAmRoutingSenderDbus::addSinkLookup(am_sinkID_t sinkID, am_domainID_t domainID)
329 mapDomain_t::iterator iter(mMapDomains.begin());
330 iter = mMapDomains.find(domainID);
331 if (iter != mMapDomains.end())
333 mMapSinks.insert(std::make_pair(sinkID, iter->second));
337 void CAmRoutingSenderDbus::removeDomainLookup(am_domainID_t domainID)
339 mMapHandles.erase(domainID);
342 void CAmRoutingSenderDbus::removeSourceLookup(am_sourceID_t sourceID)
344 mMapHandles.erase(sourceID);
347 void CAmRoutingSenderDbus::removeSinkLookup(am_sinkID_t sinkID)
349 mMapHandles.erase(sinkID);