b62169e83b6848863c0f7cbadffd76df4f93d2dd
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / test / CommonFunctions.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file CommonFunctions.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section License
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
14 *
15 * 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.
16 * 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.
17 * 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>.
18 * 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.
19 * 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.
20 * 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.
21 * 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.
22 *
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
24 */
25
26 #include "CommonFunctions.h"
27 #include "CommandInterfaceBackdoor.h"
28 #include "RoutingInterfaceBackdoor.h"
29 #include "ControlInterfaceBackdoor.h"
30 #include <assert.h>
31 #include <sstream>
32
33 using namespace am;
34
35 CommandInterfaceBackdoor::CommandInterfaceBackdoor() {
36 }
37 CommandInterfaceBackdoor::~CommandInterfaceBackdoor() {
38 }
39
40 bool CommandInterfaceBackdoor::unloadPlugins(CommandSender *CommandSender) {
41         assert(CommandSender != NULL);
42         CommandSender->unloadLibraries();
43         CommandSender->mListInterfaces.clear();
44         if (CommandSender->mListInterfaces.empty())
45                 return true;
46         return false;
47 }
48
49 bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender,
50                 CommandSendInterface *CommandSendInterface) {
51         assert(CommandSender != NULL);
52         assert(CommandSendInterface != NULL);
53         CommandSender->mListInterfaces.push_back(CommandSendInterface);
54         return true; //todo: check if it worked
55 }
56
57 RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() {
58 }
59 RoutingInterfaceBackdoor::~RoutingInterfaceBackdoor() {
60 }
61
62 bool RoutingInterfaceBackdoor::unloadPlugins(RoutingSender *RoutingSender) {
63         assert(RoutingSender != NULL);
64         RoutingSender->unloadLibraries();
65         RoutingSender->mListInterfaces.clear();
66         if (RoutingSender->mListInterfaces.empty())
67                 return true;
68         return false;
69 }
70
71 bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender,
72         RoutingSendInterface *newInterface, const std::string& busname) {
73         assert(RoutingSender != NULL);
74         assert(newInterface != NULL);
75
76         RoutingSender::InterfaceNamePairs newInterfacePair;
77         newInterfacePair.routingInterface = newInterface;
78         newInterfacePair.busName = busname;
79         RoutingSender->mListInterfaces.push_back(newInterfacePair);
80         return true; //todo: check if it worked
81 }
82
83 ControlInterfaceBackdoor::ControlInterfaceBackdoor() {}
84
85 ControlInterfaceBackdoor::~ControlInterfaceBackdoor() {}
86
87 bool ControlInterfaceBackdoor::replaceController(ControlSender *controlSender, ControlSendInterface *newController)
88 {
89         controlSender->mController=newController;
90         return true;
91 }
92
93
94 //int GetRandomNumber(int nLow, int nHigh) {
95 //      return (rand() % (nHigh - nLow + 1)) + nLow;
96 //}
97
98 bool equalSoundProperty(const am_SoundProperty_s a,
99                 const am_SoundProperty_s b) {
100         return (a.type == b.type && a.value == b.value);
101 }
102
103 bool equalMainSoundProperty(const am_MainSoundProperty_s a,
104                 const am_MainSoundProperty_s b) {
105         return (a.type == b.type && a.value == b.value);
106 }
107
108 bool equalRoutingElement(const am_RoutingElement_s a,
109                 const am_RoutingElement_s b) {
110         return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID
111                         && a.sinkID == b.sinkID && a.sourceID == b.sourceID);
112 }
113
114 bool equalClassProperties(const am_ClassProperty_s a,
115                 const am_ClassProperty_s b) {
116         return (a.classProperty == b.classProperty && a.value == b.value);
117 }
118
119 std::string int2string(int i) {
120         std::stringstream out;
121         out << i;
122         return out.str();
123 }
124
125 bool CommonFunctions::compareSource(
126                 std::vector<am_Source_s>::iterator listIterator,
127                 const am_Source_s& sourceData) {
128         return (listIterator->available.availability
129                         == sourceData.available.availability)
130                         && (listIterator->available.availabilityReason
131                                         == sourceData.available.availabilityReason)
132                         && (listIterator->sourceClassID == sourceData.sourceClassID)
133                         && (listIterator->domainID == sourceData.domainID)
134                         && (listIterator->interruptState == sourceData.interruptState)
135                         && (listIterator->visible == sourceData.visible)
136                         && (listIterator->name.compare(sourceData.name) == 0)
137                         && (listIterator->volume == sourceData.volume)
138                         && std::equal(listIterator->listConnectionFormats.begin(),
139                                         listIterator->listConnectionFormats.end(),
140                                         sourceData.listConnectionFormats.begin())
141                         && std::equal(listIterator->listMainSoundProperties.begin(),
142                                         listIterator->listMainSoundProperties.end(),
143                                         sourceData.listMainSoundProperties.begin(),
144                                         equalMainSoundProperty)
145                         && std::equal(listIterator->listSoundProperties.begin(),
146                                         listIterator->listSoundProperties.end(),
147                                         sourceData.listSoundProperties.begin(), equalSoundProperty);
148 }
149
150 bool CommonFunctions::compareSink(std::vector<am_Sink_s>::iterator listIterator,
151                 const am_Sink_s& sinkData) {
152         return (listIterator->available.availability
153                         == sinkData.available.availability)
154                         && (listIterator->available.availabilityReason
155                                         == sinkData.available.availabilityReason)
156                         && (listIterator->sinkClassID == sinkData.sinkClassID)
157                         && (listIterator->domainID == sinkData.domainID)
158                         && (listIterator->mainVolume == sinkData.mainVolume)
159                         && (listIterator->muteState == sinkData.muteState)
160                         && (listIterator->visible == sinkData.visible)
161                         && (listIterator->name.compare(sinkData.name) == 0)
162                         && (listIterator->volume == sinkData.volume)
163                         && std::equal(listIterator->listConnectionFormats.begin(),
164                                         listIterator->listConnectionFormats.end(),
165                                         sinkData.listConnectionFormats.begin())
166                         && std::equal(listIterator->listMainSoundProperties.begin(),
167                                         listIterator->listMainSoundProperties.end(),
168                                         sinkData.listMainSoundProperties.begin(),
169                                         equalMainSoundProperty)
170                         && std::equal(listIterator->listSoundProperties.begin(),
171                                         listIterator->listSoundProperties.end(),
172                                         sinkData.listSoundProperties.begin(), equalSoundProperty);
173 }
174
175 bool CommonFunctions::compareGateway(
176                 std::vector<am_Gateway_s>::iterator listIterator,
177                 const am_Gateway_s& gatewayData) {
178         return (listIterator->name.compare(gatewayData.name) == 0)
179                         && (listIterator->sinkID == gatewayData.sinkID)
180                         && (listIterator->sourceID == gatewayData.sourceID)
181                         && (listIterator->controlDomainID == gatewayData.controlDomainID)
182                         && (listIterator->domainSinkID == gatewayData.domainSinkID)
183                         && (listIterator->domainSourceID == gatewayData.domainSourceID)
184                         && std::equal(listIterator->convertionMatrix.begin(),
185                                         listIterator->convertionMatrix.end(),
186                                         gatewayData.convertionMatrix.begin())
187                         && std::equal(listIterator->listSourceFormats.begin(),
188                                         listIterator->listSourceFormats.end(),
189                                         gatewayData.listSourceFormats.begin())
190                         && std::equal(listIterator->listSinkFormats.begin(),
191                                         listIterator->listSinkFormats.end(),
192                                         gatewayData.listSinkFormats.begin());
193 }
194
195 bool CommonFunctions::compareGateway1(const am_Gateway_s gateway1,
196                 const am_Gateway_s gatewayData) {
197         return (gateway1.name.compare(gatewayData.name) == 0)
198                         && (gateway1.sinkID == gatewayData.sinkID)
199                         && (gateway1.sourceID == gatewayData.sourceID)
200                         && (gateway1.controlDomainID == gatewayData.controlDomainID)
201                         && (gateway1.domainSinkID == gatewayData.domainSinkID)
202                         && (gateway1.domainSourceID == gatewayData.domainSourceID)
203                         && std::equal(gateway1.convertionMatrix.begin(),
204                                         gateway1.convertionMatrix.end(),
205                                         gatewayData.convertionMatrix.begin())
206                         && std::equal(gateway1.listSourceFormats.begin(),
207                                         gateway1.listSourceFormats.end(),
208                                         gatewayData.listSourceFormats.begin())
209                         && std::equal(gateway1.listSinkFormats.begin(),
210                                         gateway1.listSinkFormats.end(),
211                                         gatewayData.listSinkFormats.begin());
212 }
213
214 bool CommonFunctions::compareSinkMainSink(
215                 std::vector<am_SinkType_s>::iterator listIterator,
216                 const std::vector<am_Sink_s>& sinkList) {
217         std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin();
218         for (; sinkListIterator < sinkList.end(); ++sinkListIterator) {
219                 if (listIterator->sinkID == sinkListIterator->sinkID) {
220                         return (listIterator->name.compare(sinkListIterator->name) == 0)
221                                         && (listIterator->availability.availability
222                                                         == sinkListIterator->available.availability)
223                                         && (listIterator->availability.availabilityReason
224                                                         == sinkListIterator->available.availabilityReason)
225                                         && (listIterator->muteState == sinkListIterator->muteState)
226                                         && (listIterator->volume == sinkListIterator->mainVolume)
227                                         && (listIterator->sinkClassID
228                                                         == sinkListIterator->sinkClassID);
229                 }
230         }
231         return false;
232 }
233
234 bool CommonFunctions::compareSinkMainSource(
235                 std::vector<am_SourceType_s>::iterator listIterator,
236                 const std::vector<am_Source_s>& sourceList) {
237         std::vector<am_Source_s>::const_iterator sinkListIterator =
238                         sourceList.begin();
239         for (; sinkListIterator < sourceList.end(); ++sinkListIterator) {
240                 if (listIterator->sourceID == sinkListIterator->sourceID) {
241                         return (listIterator->name.compare(sinkListIterator->name) == 0)
242                                         && (listIterator->availability.availability
243                                                         == sinkListIterator->available.availability)
244                                         && (listIterator->availability.availabilityReason
245                                                         == sinkListIterator->available.availabilityReason)
246                                         && (listIterator->sourceClassID
247                                                         == sinkListIterator->sourceClassID);
248                 }
249         }
250         return false;
251 }
252
253 std::vector<am_ConnectionFormat_e> CommonFunctions::getStandardConnectionFormatList() {
254         std::vector < am_ConnectionFormat_e > list;
255         list.push_back(CF_ANALOG);
256         list.push_back(CF_STEREO);
257         return list;
258 }
259
260 std::vector<am_SoundProperty_s> CommonFunctions::getStandardSoundPropertyList() {
261         std::vector < am_SoundProperty_s > soundPropertyList;
262         am_SoundProperty_s soundProperty;
263         soundProperty.type = SP_BASS;
264         soundProperty.value = 23;
265         soundPropertyList.push_back(soundProperty);
266         soundProperty.type = SP_MID;
267         soundProperty.value = 2;
268         soundPropertyList.push_back(soundProperty);
269         return soundPropertyList;
270 }
271
272 std::vector<am_MainSoundProperty_s> CommonFunctions::getStandardMainSoundPropertyList() {
273         std::vector < am_MainSoundProperty_s > mainSoundPropertyList;
274         am_MainSoundProperty_s mainSoundProperty;
275         mainSoundProperty.type = MSP_NAVIGATION_OFFSET;
276         mainSoundProperty.value = 23;
277         mainSoundPropertyList.push_back(mainSoundProperty);
278         mainSoundProperty.type = MSP_TEST;
279         mainSoundProperty.value = 3;
280         mainSoundPropertyList.push_back(mainSoundProperty);
281         return mainSoundPropertyList;
282 }
283
284 void CommonFunctions::createSink(am_Sink_s& sink) const {
285         sink.name = "AnySink";
286         sink.domainID = 4;
287         sink.available.availability = A_AVAILABLE;
288         sink.available.availabilityReason = AR_NEWMEDIA;
289         sink.sinkClassID = 1;
290         sink.listConnectionFormats = getStandardConnectionFormatList();
291         sink.listSoundProperties = getStandardSoundPropertyList();
292         sink.listMainSoundProperties = getStandardMainSoundPropertyList();
293         sink.mainVolume = 12;
294         sink.muteState = MS_UNMUTED;
295         sink.visible = true;
296         sink.volume = 23;
297         sink.sinkID = 0;
298 }
299
300 void CommonFunctions::createSource(am_Source_s& source) const {
301         source.name = "AnySource";
302         source.domainID = 4;
303         source.available.availability = A_AVAILABLE;
304         source.available.availabilityReason = AR_NEWMEDIA;
305         source.sourceClassID = 1;
306         source.listConnectionFormats = getStandardConnectionFormatList();
307         source.listSoundProperties = getStandardSoundPropertyList();
308         source.listMainSoundProperties = getStandardMainSoundPropertyList();
309         source.interruptState = IS_OFF;
310         source.visible = true;
311         source.volume = 23;
312         source.sourceID = 0;
313         source.sourceState = SS_ON;
314 }
315
316 void CommonFunctions::createDomain(am_Domain_s & domain) const {
317
318         domain.domainID = 0;
319         domain.name = "AnyDomain";
320         domain.nodename = "AnyNode";
321         domain.busname = "AnyBusname";
322         domain.complete = true;
323         domain.early = true;
324         domain.state = DS_CONTROLLED;
325 }
326
327 void CommonFunctions::createGateway(am_Gateway_s & gateway) {
328         gateway.name = "AnyGateway";
329         gateway.sinkID = 1;
330         gateway.sourceID = 2;
331         gateway.controlDomainID = 1;
332         gateway.domainSinkID = 3;
333         gateway.domainSourceID = 4;
334         gateway.convertionMatrix = getStandardConvertionMatrix();
335         gateway.listSourceFormats = getStandardConnectionFormatList();
336         gateway.listSinkFormats = getStandardConnectionFormatList();
337         gateway.gatewayID = 0;
338
339 }
340
341 void CommonFunctions::createConnection(am_Connection_s & connection) const {
342         connection.connectionID = 0;
343         connection.sinkID = 1;
344         connection.sourceID = 2;
345         connection.delay = -1;
346         connection.connectionFormat = CF_ANALOG;
347 }
348
349 void CommonFunctions::createMainConnection(am_MainConnection_s & mainConnection,
350                 am_Route_s route) const {
351         mainConnection.connectionID = 0;
352         mainConnection.connectionState = CS_CONNECTED;
353         mainConnection.route = route;
354         mainConnection.delay = -1;
355 }
356
357 std::vector<bool> CommonFunctions::getStandardConvertionMatrix() {
358         std::vector<bool> convMatrix;
359         convMatrix.push_back(true);
360         convMatrix.push_back(false);
361         convMatrix.push_back(true);
362         convMatrix.push_back(false);
363         convMatrix.push_back(true);
364         convMatrix.push_back(true);
365         return convMatrix;
366 }
367
368 void CommonFunctions::connectionList2RoutingList(
369                 std::vector<am_RoutingElement_s> & routingList,
370                 const std::vector<am_Connection_s>& connectionList) {
371         am_RoutingElement_s routingElement;
372         std::vector<am_Connection_s>::const_iterator cIterator =
373                         connectionList.begin();
374         for (; cIterator < connectionList.end(); ++cIterator) {
375                 routingElement.sinkID = cIterator->sinkID;
376                 routingElement.sourceID = cIterator->sourceID;
377                 routingElement.connectionFormat = cIterator->connectionFormat;
378                 routingElement.domainID = 4; //todo: make this test read out the real value
379                 routingList.push_back(routingElement);
380         }
381 }
382
383
384
385
386
387
388
389
390