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
|
/**
* Copyright (C) 2011, BMW AG
*
* GeniviAudioMananger AudioManagerDaemon
*
* \file CommonFunctions.cpp
*
* \date 20-Oct-2011 3:42:04 PM
* \author Christian Mueller (christian.ei.mueller@bmw.de)
*
* \section License
* GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
* Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
* You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
* Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
* Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
* As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
* Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
*
* THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
*/
#include "CommonFunctions.h"
#include "CommandInterfaceBackdoor.h"
#include "RoutingInterfaceBackdoor.h"
#include "ControlInterfaceBackdoor.h"
#include <assert.h>
#include <sstream>
using namespace am;
CommandInterfaceBackdoor::CommandInterfaceBackdoor() {
}
CommandInterfaceBackdoor::~CommandInterfaceBackdoor() {
}
bool CommandInterfaceBackdoor::unloadPlugins(CommandSender *CommandSender) {
assert(CommandSender != NULL);
CommandSender->unloadLibraries();
CommandSender->mListInterfaces.clear();
if (CommandSender->mListInterfaces.empty())
return true;
return false;
}
bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender,
CommandSendInterface *CommandSendInterface) {
assert(CommandSender != NULL);
assert(CommandSendInterface != NULL);
CommandSender->mListInterfaces.push_back(CommandSendInterface);
return true; //todo: check if it worked
}
RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() {
}
RoutingInterfaceBackdoor::~RoutingInterfaceBackdoor() {
}
bool RoutingInterfaceBackdoor::unloadPlugins(RoutingSender *RoutingSender) {
assert(RoutingSender != NULL);
RoutingSender->unloadLibraries();
RoutingSender->mListInterfaces.clear();
if (RoutingSender->mListInterfaces.empty())
return true;
return false;
}
bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender,
RoutingSendInterface *newInterface, const std::string& busname) {
assert(RoutingSender != NULL);
assert(newInterface != NULL);
RoutingSender::InterfaceNamePairs newInterfacePair;
newInterfacePair.routingInterface = newInterface;
newInterfacePair.busName = busname;
RoutingSender->mListInterfaces.push_back(newInterfacePair);
return true; //todo: check if it worked
}
ControlInterfaceBackdoor::ControlInterfaceBackdoor() {}
ControlInterfaceBackdoor::~ControlInterfaceBackdoor() {}
bool ControlInterfaceBackdoor::replaceController(ControlSender *controlSender, ControlSendInterface *newController)
{
controlSender->mController=newController;
return true;
}
//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 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 CommonFunctions::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 CommonFunctions::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 CommonFunctions::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 CommonFunctions::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 CommonFunctions::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 CommonFunctions::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;
}
std::vector<am_ConnectionFormat_e> CommonFunctions::getStandardConnectionFormatList() {
std::vector < am_ConnectionFormat_e > list;
list.push_back(CF_ANALOG);
list.push_back(CF_STEREO);
return list;
}
std::vector<am_SoundProperty_s> CommonFunctions::getStandardSoundPropertyList() {
std::vector < am_SoundProperty_s > soundPropertyList;
am_SoundProperty_s soundProperty;
soundProperty.type = SP_BASS;
soundProperty.value = 23;
soundPropertyList.push_back(soundProperty);
soundProperty.type = SP_MID;
soundProperty.value = 2;
soundPropertyList.push_back(soundProperty);
return soundPropertyList;
}
std::vector<am_MainSoundProperty_s> CommonFunctions::getStandardMainSoundPropertyList() {
std::vector < am_MainSoundProperty_s > mainSoundPropertyList;
am_MainSoundProperty_s mainSoundProperty;
mainSoundProperty.type = MSP_NAVIGATION_OFFSET;
mainSoundProperty.value = 23;
mainSoundPropertyList.push_back(mainSoundProperty);
mainSoundProperty.type = MSP_TEST;
mainSoundProperty.value = 3;
mainSoundPropertyList.push_back(mainSoundProperty);
return mainSoundPropertyList;
}
void CommonFunctions::createSink(am_Sink_s& sink) const {
sink.name = "AnySink";
sink.domainID = 4;
sink.available.availability = A_AVAILABLE;
sink.available.availabilityReason = AR_NEWMEDIA;
sink.sinkClassID = 1;
sink.listConnectionFormats = getStandardConnectionFormatList();
sink.listSoundProperties = getStandardSoundPropertyList();
sink.listMainSoundProperties = getStandardMainSoundPropertyList();
sink.mainVolume = 12;
sink.muteState = MS_UNMUTED;
sink.visible = true;
sink.volume = 23;
sink.sinkID = 0;
}
void CommonFunctions::createSource(am_Source_s& source) const {
source.name = "AnySource";
source.domainID = 4;
source.available.availability = A_AVAILABLE;
source.available.availabilityReason = AR_NEWMEDIA;
source.sourceClassID = 1;
source.listConnectionFormats = getStandardConnectionFormatList();
source.listSoundProperties = getStandardSoundPropertyList();
source.listMainSoundProperties = getStandardMainSoundPropertyList();
source.interruptState = IS_OFF;
source.visible = true;
source.volume = 23;
source.sourceID = 0;
source.sourceState = SS_ON;
}
void CommonFunctions::createDomain(am_Domain_s & domain) const {
domain.domainID = 0;
domain.name = "AnyDomain";
domain.nodename = "AnyNode";
domain.busname = "AnyBusname";
domain.complete = true;
domain.early = true;
domain.state = DS_CONTROLLED;
}
void CommonFunctions::createGateway(am_Gateway_s & gateway) {
gateway.name = "AnyGateway";
gateway.sinkID = 1;
gateway.sourceID = 2;
gateway.controlDomainID = 1;
gateway.domainSinkID = 3;
gateway.domainSourceID = 4;
gateway.convertionMatrix = getStandardConvertionMatrix();
gateway.listSourceFormats = getStandardConnectionFormatList();
gateway.listSinkFormats = getStandardConnectionFormatList();
gateway.gatewayID = 0;
}
void CommonFunctions::createConnection(am_Connection_s & connection) const {
connection.connectionID = 0;
connection.sinkID = 1;
connection.sourceID = 2;
connection.delay = -1;
connection.connectionFormat = CF_ANALOG;
}
void CommonFunctions::createMainConnection(am_MainConnection_s & mainConnection,
am_Route_s route) const {
mainConnection.connectionID = 0;
mainConnection.connectionState = CS_CONNECTED;
mainConnection.route = route;
mainConnection.delay = -1;
}
std::vector<bool> CommonFunctions::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;
}
void CommonFunctions::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);
}
}
|