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
|
/**
* SPDX license identifier: MPL-2.0
*
* Copyright (C) 2012, BMW AG
*
* This file is part of GENIVI Project AudioManager.
*
* Contributions are licensed to the GENIVI Alliance under one or more
* Contribution License Agreements.
*
* \copyright
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* \author Christian Linke, christian.linke@bmw.de BMW 2011,2012
*
* For further information see http://www.genivi.org/.
*
*/
#include "CAmCommonFunctions.h"
#include "IAmCommandBackdoor.h"
#include "IAmRoutingBackdoor.h"
#include "IAmControlBackdoor.h"
#include <cassert>
#include <sstream>
using namespace am;
IAmCommandBackdoor::IAmCommandBackdoor()
{
}
IAmCommandBackdoor::~IAmCommandBackdoor()
{
}
bool IAmCommandBackdoor::unloadPlugins(CAmCommandSender *CommandSender)
{
assert(CommandSender != NULL);
CommandSender->unloadLibraries();
CommandSender->mListInterfaces.clear();
if (CommandSender->mListInterfaces.empty())
return true;
return false;
}
bool IAmCommandBackdoor::injectInterface(CAmCommandSender *CommandSender, IAmCommandSend *CommandSendInterface)
{
assert(CommandSender != NULL);
assert(CommandSendInterface != NULL);
CommandSender->mListInterfaces.push_back(CommandSendInterface);
return true;
}
IAmRoutingBackdoor::IAmRoutingBackdoor()
{
}
IAmRoutingBackdoor::~IAmRoutingBackdoor()
{
}
bool IAmRoutingBackdoor::unloadPlugins(CAmRoutingSender *RoutingSender)
{
assert(RoutingSender != NULL);
RoutingSender->unloadLibraries();
RoutingSender->mListInterfaces.clear();
if (RoutingSender->mListInterfaces.empty())
return true;
return false;
}
bool IAmRoutingBackdoor::injectInterface(CAmRoutingSender *RoutingSender, IAmRoutingSend *newInterface, const std::string& busname)
{
assert(RoutingSender != NULL);
assert(newInterface != NULL);
CAmRoutingSender::InterfaceNamePairs newInterfacePair;
newInterfacePair.routingInterface = newInterface;
newInterfacePair.busName = busname;
RoutingSender->mListInterfaces.push_back(newInterfacePair);
return true;
}
IAmControlBackdoor::IAmControlBackdoor()
{
}
IAmControlBackdoor::~IAmControlBackdoor()
{
}
bool IAmControlBackdoor::replaceController(CAmControlSender *controlSender, IAmControlSend *newController)
{
controlSender->mController = newController;
return controlSender->mController == newController;
}
//int GetRandomNumber(int nLow, int nHigh) {
// return (rand() % (nHigh - nLow + 1)) + nLow;
//}
bool equalSoundProperty(const am_SoundProperty_s a, const am_SoundProperty_s b)
{
return (a.type == b.type && a.value == b.value);
}
bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b)
{
return (a.type == b.type && a.value == b.value);
}
bool equalNotificationConfiguration(const am_NotificationConfiguration_s a, const am_NotificationConfiguration_s b)
{
return (a.parameter == b.parameter && a.status == b.status && a.type == b.type);
}
bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b)
{
return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID && a.sinkID == b.sinkID && a.sourceID == b.sourceID);
}
bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b)
{
return (a.classProperty == b.classProperty && a.value == b.value);
}
std::string int2string(int i)
{
std::stringstream out;
out << i;
return out.str();
}
bool CAmCommonFunctions::compareSource(std::vector<am_Source_s>::iterator listIterator, const am_Source_s& sourceData)
{
return (listIterator->available.availability == sourceData.available.availability) && \
(listIterator->available.availabilityReason == sourceData.available.availabilityReason) &&
(listIterator->sourceClassID == sourceData.sourceClassID) &&
(listIterator->domainID == sourceData.domainID) &&
(listIterator->interruptState == sourceData.interruptState) &&
(listIterator->visible == sourceData.visible) &&
(listIterator->name.compare(sourceData.name) == 0) &&
(listIterator->volume == sourceData.volume) &&
std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sourceData.listConnectionFormats.begin()) &&
std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty) &&
std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sourceData.listSoundProperties.begin(), equalSoundProperty);
}
bool CAmCommonFunctions::compareSink(std::vector<am_Sink_s>::iterator listIterator, const am_Sink_s& sinkData)
{
return (listIterator->available.availability == sinkData.available.availability) && (listIterator->available.availabilityReason == sinkData.available.availabilityReason) && (listIterator->sinkClassID == sinkData.sinkClassID) && (listIterator->domainID == sinkData.domainID) && (listIterator->mainVolume == sinkData.mainVolume) && (listIterator->muteState == sinkData.muteState) && (listIterator->visible == sinkData.visible) && (listIterator->name.compare(sinkData.name) == 0) && (listIterator->volume == sinkData.volume) && std::equal(listIterator->listConnectionFormats.begin(), listIterator->listConnectionFormats.end(), sinkData.listConnectionFormats.begin())
&& std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sinkData.listSoundProperties.begin(), equalSoundProperty);
}
bool CAmCommonFunctions::compareGateway(std::vector<am_Gateway_s>::iterator listIterator, const am_Gateway_s& gatewayData)
{
return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->controlDomainID == gatewayData.controlDomainID) && (listIterator->domainSinkID == gatewayData.domainSinkID) && (listIterator->domainSourceID == gatewayData.domainSourceID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
bool CAmCommonFunctions::compareConverter(std::vector<am_Converter_s>::iterator listIterator, const am_Converter_s& gatewayData)
{
return (listIterator->name.compare(gatewayData.name) == 0) && (listIterator->sinkID == gatewayData.sinkID) && (listIterator->sourceID == gatewayData.sourceID) && (listIterator->domainID == gatewayData.domainID) && std::equal(listIterator->convertionMatrix.begin(), listIterator->convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(listIterator->listSourceFormats.begin(), listIterator->listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(listIterator->listSinkFormats.begin(), listIterator->listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
bool CAmCommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData)
{
return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.controlDomainID == gatewayData.controlDomainID) && (gateway1.domainSinkID == gatewayData.domainSinkID) && (gateway1.domainSourceID == gatewayData.domainSourceID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
bool CAmCommonFunctions::compareConverter1(const am_Converter_s gateway1, const am_Converter_s gatewayData)
{
return (gateway1.name.compare(gatewayData.name) == 0) && (gateway1.sinkID == gatewayData.sinkID) && (gateway1.sourceID == gatewayData.sourceID) && (gateway1.domainID == gatewayData.domainID) && std::equal(gateway1.convertionMatrix.begin(), gateway1.convertionMatrix.end(), gatewayData.convertionMatrix.begin()) && std::equal(gateway1.listSourceFormats.begin(), gateway1.listSourceFormats.end(), gatewayData.listSourceFormats.begin()) && std::equal(gateway1.listSinkFormats.begin(), gateway1.listSinkFormats.end(), gatewayData.listSinkFormats.begin());
}
bool CAmCommonFunctions::compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList)
{
std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin();
for (; sinkListIterator < sinkList.end(); ++sinkListIterator)
{
if (listIterator->sinkID == sinkListIterator->sinkID)
{
return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->muteState == sinkListIterator->muteState) && (listIterator->volume == sinkListIterator->mainVolume) && (listIterator->sinkClassID == sinkListIterator->sinkClassID);
}
}
return false;
}
bool CAmCommonFunctions::compareSinkMainSource(std::vector<am_SourceType_s>::iterator listIterator, const std::vector<am_Source_s>& sourceList)
{
std::vector<am_Source_s>::const_iterator sinkListIterator = sourceList.begin();
for (; sinkListIterator < sourceList.end(); ++sinkListIterator)
{
if (listIterator->sourceID == sinkListIterator->sourceID)
{
return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->sourceClassID == sinkListIterator->sourceClassID);
}
}
return false;
}
bool CAmCommonFunctions::compareRoute(am_Route_s a, am_Route_s b)
{
bool retVal = true;
std::vector<am_RoutingElement_s>::iterator itA = a.route.begin(), itB = b.route.begin();
retVal &= a.sourceID == b.sourceID;
retVal &= a.sinkID == b.sinkID;
for (; itA != a.route.end(); ++itA)
{
retVal &= itA->sinkID == itB->sinkID;
retVal &= itA->sourceID == itB->sourceID;
retVal &= itA->connectionFormat == itB->connectionFormat;
retVal &= itA->domainID == itB->domainID;
itB++;
}
return retVal;
}
std::vector<am_CustomAvailabilityReason_t> CAmCommonFunctions::getStandardConnectionFormatList()
{
std::vector<am_CustomAvailabilityReason_t> list;
list.push_back(CF_GENIVI_ANALOG);
list.push_back(CF_GENIVI_STEREO);
return list;
}
std::vector<am_SoundProperty_s> CAmCommonFunctions::getStandardSoundPropertyList()
{
std::vector<am_SoundProperty_s> soundPropertyList;
am_SoundProperty_s soundProperty;
soundProperty.type = SP_GENIVI_BASS;
soundProperty.value = 23;
soundPropertyList.push_back(soundProperty);
soundProperty.type = SP_GENIVI_MID;
soundProperty.value = 2;
soundPropertyList.push_back(soundProperty);
return soundPropertyList;
}
std::vector<am_MainSoundProperty_s> CAmCommonFunctions::getStandardMainSoundPropertyList()
{
std::vector<am_MainSoundProperty_s> mainSoundPropertyList;
am_MainSoundProperty_s mainSoundProperty;
mainSoundProperty.type = MSP_GENIVI_BASS;
mainSoundProperty.value = 23;
mainSoundPropertyList.push_back(mainSoundProperty);
mainSoundProperty.type = MSP_UNKNOWN;
mainSoundProperty.value = 3;
mainSoundPropertyList.push_back(mainSoundProperty);
return mainSoundPropertyList;
}
void CAmCommonFunctions::createSink(am_Sink_s& sink) const
{
sink.name = "AnySink";
sink.domainID = 4;
sink.available.availability = A_AVAILABLE;
sink.available.availabilityReason = AR_GENIVI_NEWMEDIA;
sink.sinkClassID = 1;
sink.listConnectionFormats = getStandardConnectionFormatList();
sink.listSoundProperties = getStandardSoundPropertyList();
sink.listMainSoundProperties = getStandardMainSoundPropertyList();
sink.listNotificationConfigurations = getStandardNotificationConfigurationList();
sink.listMainNotificationConfigurations = getStandardNotificationConfigurationList();
sink.mainVolume = 12;
sink.muteState = MS_UNMUTED;
sink.visible = true;
sink.volume = 23;
sink.sinkID = 0;
}
void CAmCommonFunctions::createSource(am_Source_s& source) const
{
source.name = "AnySource";
source.domainID = 4;
source.available.availability = A_AVAILABLE;
source.available.availabilityReason = AR_GENIVI_NEWMEDIA;
source.sourceClassID = 1;
source.listConnectionFormats = getStandardConnectionFormatList();
source.listSoundProperties = getStandardSoundPropertyList();
source.listMainSoundProperties = getStandardMainSoundPropertyList();
source.listMainNotificationConfigurations=getStandardNotificationConfigurationList();
source.listNotificationConfigurations=getStandardNotificationConfigurationList();
source.interruptState = IS_OFF;
source.visible = true;
source.volume = 23;
source.sourceID = 0;
source.sourceState = SS_ON;
}
void CAmCommonFunctions::createDomain(am_Domain_s & domain) const
{
domain.domainID = 4;
domain.name = "AnyDomain";
domain.nodename = "AnyNode";
domain.busname = "AnyBusname";
domain.complete = true;
domain.early = true;
domain.state = DS_CONTROLLED;
}
void CAmCommonFunctions::createGateway(am_Gateway_s & gateway)
{
gateway.name = "AnyGateway";
gateway.sinkID = 1;
gateway.sourceID = 2;
gateway.controlDomainID = 4;
gateway.domainSinkID = 4;
gateway.domainSourceID = 4;
gateway.convertionMatrix = getStandardConvertionMatrix();
gateway.listSourceFormats = getStandardConnectionFormatList();
gateway.listSinkFormats = getStandardConnectionFormatList();
gateway.gatewayID = 0;
}
void CAmCommonFunctions::createConverter(am_Converter_s & converter) const
{
converter.name = "AnyConverter";
converter.sinkID = 1;
converter.sourceID = 2;
converter.domainID = 4;
converter.convertionMatrix = getStandardConvertionMatrix();
converter.listSourceFormats = getStandardConnectionFormatList();
converter.listSinkFormats = getStandardConnectionFormatList();
converter.converterID = 0;
}
void CAmCommonFunctions::createConnection(am_Connection_s & connection) const
{
connection.connectionID = 0;
connection.sinkID = 1;
connection.sourceID = 2;
connection.delay = -1;
connection.connectionFormat = CF_GENIVI_ANALOG;
}
std::vector<bool> CAmCommonFunctions::getStandardConvertionMatrix()
{
std::vector<bool> convMatrix;
convMatrix.push_back(true);
convMatrix.push_back(false);
convMatrix.push_back(true);
convMatrix.push_back(false);
convMatrix.push_back(true);
convMatrix.push_back(true);
return convMatrix;
}
std::vector<am_NotificationConfiguration_s> am::CAmCommonFunctions::getStandardNotificationConfigurationList()
{
std::vector<am_NotificationConfiguration_s> listNotificationConfigurations;
am_NotificationConfiguration_s tempNotificationConfiguration;
tempNotificationConfiguration.type=NT_TEST_1;
tempNotificationConfiguration.parameter=12;
tempNotificationConfiguration.status=NS_PERIODIC;
listNotificationConfigurations.push_back(tempNotificationConfiguration);
tempNotificationConfiguration.type=NT_TEST_2;
tempNotificationConfiguration.parameter=16;
tempNotificationConfiguration.status=NS_CHANGE;
listNotificationConfigurations.push_back(tempNotificationConfiguration);
return (listNotificationConfigurations);
}
void CAmCommonFunctions::connectionList2RoutingList(std::vector<am_RoutingElement_s> & routingList, const std::vector<am_Connection_s>& connectionList)
{
am_RoutingElement_s routingElement;
std::vector<am_Connection_s>::const_iterator cIterator = connectionList.begin();
for (; cIterator < connectionList.end(); ++cIterator)
{
routingElement.sinkID = cIterator->sinkID;
routingElement.sourceID = cIterator->sourceID;
routingElement.connectionFormat = cIterator->connectionFormat;
routingElement.domainID = 4; //todo: make this test read out the real value
routingList.push_back(routingElement);
}
}
|