summaryrefslogtreecommitdiff
path: root/PluginRoutingInterfaceDbus/src/CAmRoutingSenderDbus.cpp
blob: 06da0e6874901de1ea1e70dd14da58770183f51e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/**
 *  Copyright (c) 2012 BMW
 *  Copyright (c) copyright 2011-2012 Aricent® Group  and its licensors
 *
 *  \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
 *  \author Sampreeth Ramavana
 *  \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
 *
 *  \copyright
 *  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,
 *  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,
 *  subject to the following conditions:
 *  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *  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.
 *  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
 *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  For further information see http://www.genivi.org/.
 */

#include "CAmRoutingSenderDbus.h"
#include <cassert>
#include <map>
#include "CAmDbusSend.h"
#include "shared/CAmDltWrapper.h"
#include "shared/CAmDbusWrapper.h"

namespace am
{
DLT_DECLARE_CONTEXT(routingDbus)

extern "C" IAmRoutingSend* PluginRoutingInterfaceDbusFactory()
{
    CAmDltWrapper::instance()->registerContext(routingDbus, "DRS", "DBus Plugin");
    return (new CAmRoutingSenderDbus());
}

extern "C" void destroyRoutingPluginInterfaceDbus(IAmRoutingSend* routingSendInterface)
{
    delete routingSendInterface;
}

CAmRoutingSenderDbus::CAmRoutingSenderDbus() :
        mpCAmDBusWrapper(), //
        mpIAmRoutingReceive(), //
        mpDBusConnection(), //
        mCAmRoutingDBusMessageHandler(), //
        mIAmRoutingReceiverShadowDbus(this)
{
    log(&routingDbus, DLT_LOG_INFO, "RoutingSender constructed");
}

CAmRoutingSenderDbus::~CAmRoutingSenderDbus()
{
    log(&routingDbus, DLT_LOG_INFO, "RoutingSender destructed");
    CAmDltWrapper::instance()->unregisterContext(routingDbus);
}

am_Error_e CAmRoutingSenderDbus::startupInterface(IAmRoutingReceive* pIAmRoutingReceive)
{
    log(&routingDbus, DLT_LOG_INFO, "startupInterface called");
    mpIAmRoutingReceive = pIAmRoutingReceive;
    mIAmRoutingReceiverShadowDbus.setRoutingReceiver(mpIAmRoutingReceive);
    mpIAmRoutingReceive->getDBusConnectionWrapper(mpCAmDBusWrapper);
    assert(mpCAmDBusWrapper!=NULL);
    mpCAmDBusWrapper->getDBusConnection(mpDBusConnection);
    assert(mpDBusConnection!=NULL);
    mCAmRoutingDBusMessageHandler.setDBusConnection(mpDBusConnection);
    return (E_OK);
}

void CAmRoutingSenderDbus::getInterfaceVersion(std::string & version) const
{
    version = RoutingSendVersion;
}

void CAmRoutingSenderDbus::setRoutingReady(const uint16_t handle)
{
    log(&routingDbus, DLT_LOG_INFO, "sending routingReady signal");
    mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingReady");
    mCAmRoutingDBusMessageHandler.sendMessage();
    mIAmRoutingReceiverShadowDbus.gotReady(mMapDomains.size(),handle);
}

void CAmRoutingSenderDbus::setRoutingRundown(const uint16_t handle)
{
    mCAmRoutingDBusMessageHandler.initSignal(std::string(ROUTING_NODE), "setRoutingRundown");
    mCAmRoutingDBusMessageHandler.sendMessage();
    mIAmRoutingReceiverShadowDbus.gotRundown(mMapDomains.size(),handle);
}

am_Error_e CAmRoutingSenderDbus::asyncAbort(const am_Handle_s handle)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncAbort called");
    mapHandles_t::iterator iter = mMapHandles.begin();
    iter = mMapHandles.find(handle.handle);
    if (iter != mMapHandles.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncAbort");
        send.append(handle.handle);
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncAbort could not find interface");
    return (E_UNKNOWN);

}

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)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncConnect called");
    mapSources_t::iterator iter = mMapSources.begin();
    iter = mMapSources.find(sourceID);
    if (iter != mMapSources.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncConnect");
        send.append(handle.handle);
        send.append(connectionID);
        send.append(sourceID);
        send.append(sinkID);
        send.append(static_cast<int32_t>(connectionFormat));
        mMapConnections.insert(std::make_pair(connectionID, (iter->second)));
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.sendAsync());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncConnect could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncDisconnect(const am_Handle_s handle, const am_connectionID_t connectionID)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncDisconnect called");
    mapConnections_t::iterator iter = mMapConnections.begin();
    iter = mMapConnections.find(connectionID);
    if (iter != mMapConnections.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncDisconnect");
        send.append(handle.handle);
        send.append(connectionID);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.sendAsync());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncDisconnect could not find interface");
    return (E_UNKNOWN);
}

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)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkVolume called");
    mapSinks_t::iterator iter = mMapSinks.begin();
    iter = mMapSinks.find(sinkID);
    if (iter != mMapSinks.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkVolume");
        send.append(handle.handle);
        send.append(sinkID);
        send.append(volume);
        send.append(static_cast<int32_t>(ramp));
        send.append(time);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkVolume could not find interface");
    return (E_UNKNOWN);
}

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)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceVolume called");
    mapSources_t::iterator iter = mMapSources.begin();
    iter = mMapSources.find(sourceID);
    if (iter != mMapSources.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceVolume");
        send.append(handle.handle);
        send.append(sourceID);
        send.append(volume);
        send.append(static_cast<int16_t>(ramp));
        send.append(time);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceVolume could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSourceState(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceState called");
    mapSources_t::iterator iter = mMapSources.begin();
    iter = mMapSources.find(sourceID);
    if (iter != mMapSources.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceState");
        send.append(handle.handle);
        send.append(sourceID);
        send.append(static_cast<int32_t>(state));
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.sendAsync());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceState could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperties(const am_Handle_s handle, const am_sinkID_t sinkID, const std::vector<am_SoundProperty_s>& listSoundProperties)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties called");
    mapSinks_t::iterator iter = mMapSinks.begin();
    iter = mMapSinks.find(sinkID);
    if (iter != mMapSinks.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperties");
        send.append(handle.handle);
        send.append(sinkID);
        send.append(listSoundProperties);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperties could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSinkSoundProperty(const am_Handle_s handle, const am_sinkID_t sinkID, const am_SoundProperty_s& soundProperty)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty called");
    mapSinks_t::iterator iter = mMapSinks.begin();
    iter = mMapSinks.find(sinkID);
    if (iter != mMapSinks.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSinkSoundProperty");
        send.append(handle.handle);
        send.append(sinkID);
        send.append(soundProperty);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSinkSoundProperty could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperties(const am_Handle_s handle, const am_sourceID_t sourceID, const std::vector<am_SoundProperty_s>& listSoundProperties)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties called");
    mapSources_t::iterator iter = mMapSources.begin();
    iter = mMapSources.find(sourceID);
    if (iter != mMapSources.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperties");
        send.append(handle.handle);
        send.append(sourceID);
        send.append(listSoundProperties);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperties could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSourceSoundProperty(const am_Handle_s handle, const am_sourceID_t sourceID, const am_SoundProperty_s& soundProperty)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty called");
    mapSources_t::iterator iter = mMapSources.begin();
    iter = mMapSources.find(sourceID);
    if (iter != mMapSources.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "asyncSetSourceSoundProperty");
        send.append(handle.handle);
        send.append(sourceID);
        send.append(soundProperty);
        mMapHandles.insert(std::make_pair(+handle.handle, iter->second));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::asyncSetSourceSoundProperty could not find interface");
    return (E_UNKNOWN);
}

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)
{
    (void)handle;
    (void)crossfaderID;
    (void)hotSink;
    (void)rampType;
    (void)time;
    //todo implement
    return (E_NON_EXISTENT);
}

am_Error_e CAmRoutingSenderDbus::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
{
    log(&routingDbus, DLT_LOG_INFO, "CAmRoutingSenderDbus::setDomainState called");
    mapDomain_t::iterator iter = mMapDomains.begin();
    iter = mMapDomains.find(domainID);
    if (iter != mMapDomains.end())
    {
        CAmRoutingDbusSend send(mpDBusConnection, iter->second.busname, iter->second.path, iter->second.interface, "setDomainState");
        send.append(domainID);
        send.append(static_cast<int>(domainState));
        return (send.send());
    }
    log(&routingDbus, DLT_LOG_ERROR, "CAmRoutingSenderDbus::setDomainState could not find interface");
    return (E_UNKNOWN);
}

am_Error_e CAmRoutingSenderDbus::returnBusName(std::string& BusName) const
{
    BusName = "DbusRoutingPlugin";
    return (E_OK);
}

void CAmRoutingSenderDbus::removeHandle(uint16_t handle)
{
    mMapHandles.erase(handle);
}

void CAmRoutingSenderDbus::addDomainLookup(am_domainID_t domainID, rs_lookupData_s lookupData)
{
    mMapDomains.insert(std::make_pair(domainID, lookupData));
}

void CAmRoutingSenderDbus::addSourceLookup(am_sourceID_t sourceID, am_domainID_t domainID)
{
    mapDomain_t::iterator iter(mMapDomains.begin());
    iter = mMapDomains.find(domainID);
    if (iter != mMapDomains.end())
    {
        mMapSources.insert(std::make_pair(sourceID, iter->second));
    }
}

void CAmRoutingSenderDbus::addSinkLookup(am_sinkID_t sinkID, am_domainID_t domainID)
{
    mapDomain_t::iterator iter(mMapDomains.begin());
    iter = mMapDomains.find(domainID);
    if (iter != mMapDomains.end())
    {
        mMapSinks.insert(std::make_pair(sinkID, iter->second));
    }
}

template <typename TKey> void  CAmRoutingSenderDbus::removeEntriesForValue(const rs_lookupData_s & value, std::map<TKey,rs_lookupData_s> & map)
{
	typename std::map<TKey,rs_lookupData_s>::iterator it = map.begin();
	while ( it != map.end() )
	{
		if (it->second.busname == value.busname &&
			it->second.interface == value.interface &&
			it->second.path == value.path)
		{
			typename std::map<TKey,rs_lookupData_s>::iterator it_tmp = it;
			it++;
			map.erase(it_tmp);
		}
		else
			++it;
	}
}

void CAmRoutingSenderDbus::removeDomainLookup(am_domainID_t domainID)
{
    mapDomain_t::iterator iter(mMapDomains.begin());
    iter = mMapDomains.find(domainID);
    if (iter != mMapDomains.end())
    {
    	CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapSources);
    	CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapSinks);
    	CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapHandles);
    	CAmRoutingSenderDbus::removeEntriesForValue(iter->second, mMapConnections);
		mMapDomains.erase(domainID);
    }
}

void CAmRoutingSenderDbus::removeSourceLookup(am_sourceID_t sourceID)
{
	mMapSources.erase(sourceID);
}

void CAmRoutingSenderDbus::removeSinkLookup(am_sinkID_t sinkID)
{
    mMapSinks.erase(sinkID);
}

am_Error_e CAmRoutingSenderDbus::asyncSetVolumes(const am_Handle_s handle, const std::vector<am_Volumes_s>& listVolumes)
{
    (void) handle;
    (void) listVolumes;
    //todo: implement asyncSetVolumes;
    return (E_NOT_USED);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSinkNotificationConfiguration(const am_Handle_s handle, const am_sinkID_t sinkID, const am_NotificationConfiguration_s& notificationConfiguration)
{
    (void) handle;
    (void) sinkID;
    (void) notificationConfiguration;
    //todo: implement asyncSetSinkNotificationConfiguration;
    return (E_NOT_USED);
}

am_Error_e CAmRoutingSenderDbus::asyncSetSourceNotificationConfiguration(const am_Handle_s handle, const am_sourceID_t sourceID, const am_NotificationConfiguration_s& notificationConfiguration)
{
    (void) handle;
    (void) sourceID;
    (void) notificationConfiguration;
    //todo: implement asyncSetSourceNotificationConfiguration;
    return (E_NOT_USED);
}

}