* [GAM-74] resolving issues found by coverity scan
[profile/ivi/genivi/genivi-audio-manager.git] / PluginRoutingInterfaceDbus / src / CAmRoutingSenderDbus.cpp
1 /**
2  *  Copyright (c) 2012 BMW
3  *  Copyright (c) copyright 2011-2012 Aricent® Group  and its licensors
4  *
5  *  \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
6  *  \author Sampreeth Ramavana
7  *
8  *  \copyright
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.
16  *
17  *  For further information see http://www.genivi.org/.
18  */
19
20 #include "CAmRoutingSenderDbus.h"
21 #include <cassert>
22 #include <map>
23 #include "CAmDbusSend.h"
24 #include "shared/CAmDltWrapper.h"
25 #include "shared/CAmDbusWrapper.h"
26
27 namespace am
28 {
29 DLT_DECLARE_CONTEXT(routingDbus)
30
31 extern "C" IAmRoutingSend* PluginRoutingInterfaceDbusFactory()
32 {
33     return (new CAmRoutingSenderDbus());
34 }
35
36 extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface)
37 {
38     delete routingSendInterface;
39 }
40
41 CAmRoutingSenderDbus::CAmRoutingSenderDbus() :
42         mpCAmDBusWrapper(), //
43         mpIAmRoutingReceive(), //
44         mpDBusConnection(), //
45         mCAmRoutingDBusMessageHandler(), //
46         mIAmRoutingReceiverShadowDbus(this)
47 {
48     CAmDltWrapper::instance()->registerContext(routingDbus, "DRS", "DBus Plugin");
49     log(&routingDbus, DLT_LOG_INFO, "RoutingSender constructed");
50 }
51
52 CAmRoutingSenderDbus::~CAmRoutingSenderDbus()
53 {
54     log(&routingDbus, DLT_LOG_INFO, "RoutingSender destructed");
55     CAmDltWrapper::instance()->unregisterContext(routingDbus);
56 }
57
58 am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
59 {
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);
68     return (E_OK);
69 }
70
71 void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const
72 {
73     version = RoutingSendVersion;
74 }
75
76 void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle)
77 {
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);
82 }
83
84 void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle)
85 {
86     mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingRundown");
87     mCAmRoutingDBusMessageHandler.sendMessage();
88     mIAmRoutingReceiverShadowDbus.gotRundown(mMapDomains.size(),handle);
89 }
90
91 am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle)
92 {
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())
97     {
98         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncAbort");
99         send.append(handle.handle);
100         return (send.send());
101     }
102     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncAbort could not find interface");
103     return (E_UNKNOWN);
104
105 }
106
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)
108 {
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())
113     {
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);
118         send.append(sinkID);
119         send.append(static_cast<int16_t>(connectionFormat));
120         mMapConnections.insert(std::make_pair(connectionID, (iter->second)));
121         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
122         return (send.send());
123     }
124     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncConnect could not find interface");
125     return (E_UNKNOWN);
126 }
127
128 am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
129 {
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())
134     {
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.send());
140     }
141     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncDisconnect could not find interface");
142     return (E_UNKNOWN);
143 }
144
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)
146 {
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())
151     {
152         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkVolume");
153         send.append(handle.handle);
154         send.append(sinkID);
155         send.append(volume);
156         send.append(static_cast<int16_t>(ramp));
157         send.append(time);
158         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
159         return (send.send());
160     }
161     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkVolume could not find interface");
162     return (E_UNKNOWN);
163 }
164
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)
166 {
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())
171     {
172         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceVolume");
173         send.append(handle.handle);
174         send.append(sourceID);
175         send.append(volume);
176         send.append(static_cast<int16_t>(ramp));
177         send.append(time);
178         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
179         return (send.send());
180     }
181     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceVolume could not find interface");
182     return (E_UNKNOWN);
183 }
184
185 am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
186 {
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())
191     {
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<int16_t>(state));
196         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
197         return (send.send());
198     }
199     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceState could not find interface");
200     return (E_UNKNOWN);
201 }
202
203 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
204 {
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())
209     {
210         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperties");
211         send.append(handle.handle);
212         send.append(sinkID);
213         send.append(listSoundProperties);
214         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
215         return (send.send());
216     }
217     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties could not find interface");
218     return (E_UNKNOWN);
219 }
220
221 am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
222 {
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())
227     {
228         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperty");
229         send.append(handle.handle);
230         send.append(sinkID);
231         send.append(soundProperty);
232         mMapHandles.insert(std::make_pair(handle.handle, iter->second));
233         return (send.send());
234     }
235     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty could not find interface");
236     return (E_UNKNOWN);
237 }
238
239 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
240 {
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())
245     {
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());
252     }
253     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties could not find interface");
254     return (E_UNKNOWN);
255 }
256
257 am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
258 {
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())
263     {
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());
270     }
271     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty could not find interface");
272     return (E_UNKNOWN);
273 }
274
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)
276 {
277     (void)handle;
278     (void)crossfaderID;
279     (void)hotSink;
280     (void)rampType;
281     (void)time;
282     //todo implement
283     return (E_NON_EXISTENT);
284 }
285
286 am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
287 {
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())
292     {
293         CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "setDomainState");
294         send.append(domainID);
295         send.append(static_cast<int16_t>(domainState));
296         return (send.send());
297     }
298     log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::setDomainState could not find interface");
299     return (E_UNKNOWN);
300 }
301
302 am_Error_e CAmRoutingSenderDbus::returnBusName(std::string& BusName) const
303 {
304     BusName = "DbusRoutingPlugin";
305     return (E_OK);
306 }
307
308 void CAmRoutingSenderDbus::removeHandle(uint16_t handle)
309 {
310     mMapHandles.erase(handle);
311 }
312
313 void CAmRoutingSenderDbus::addDomainLookup(am_domainID_t domainID, rs_lookupData_s lookupData)
314 {
315     mMapDomains.insert(std::make_pair(domainID, lookupData));
316 }
317
318 void CAmRoutingSenderDbus::addSourceLookup(am_sourceID_t sourceID, am_domainID_t domainID)
319 {
320     mapDomain_t::iterator iter(mMapDomains.begin());
321     iter = mMapDomains.find(domainID);
322     if (iter != mMapDomains.end())
323     {
324         mMapSources.insert(std::make_pair(sourceID, iter->second));
325     }
326 }
327
328 void CAmRoutingSenderDbus::addSinkLookup(am_sinkID_t sinkID, am_domainID_t domainID)
329 {
330     mapDomain_t::iterator iter(mMapDomains.begin());
331     iter = mMapDomains.find(domainID);
332     if (iter != mMapDomains.end())
333     {
334         mMapSinks.insert(std::make_pair(sinkID, iter->second));
335     }
336 }
337
338 void CAmRoutingSenderDbus::removeDomainLookup(am_domainID_t domainID)
339 {
340     mMapHandles.erase(domainID);
341 }
342
343 void CAmRoutingSenderDbus::removeSourceLookup(am_sourceID_t sourceID)
344 {
345     mMapHandles.erase(sourceID);
346 }
347
348 void CAmRoutingSenderDbus::removeSinkLookup(am_sinkID_t sinkID)
349 {
350     mMapHandles.erase(sinkID);
351 }
352
353 }
354