2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file CommonFunctions.cpp
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
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
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.
23 * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN
26 #include "CommonFunctions.h"
27 #include "CommandInterfaceBackdoor.h"
28 #include "RoutingInterfaceBackdoor.h"
29 #include "ControlInterfaceBackdoor.h"
31 CommandInterfaceBackdoor::CommandInterfaceBackdoor() {
33 CommandInterfaceBackdoor::~CommandInterfaceBackdoor() {
36 bool CommandInterfaceBackdoor::unloadPlugins(CommandSender *CommandSender) {
37 assert(CommandSender != NULL);
38 CommandSender->unloadLibraries();
39 CommandSender->mListInterfaces.clear();
40 if (CommandSender->mListInterfaces.empty())
45 bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender,
46 CommandSendInterface *CommandSendInterface) {
47 assert(CommandSender != NULL);
48 assert(CommandSendInterface != NULL);
49 CommandSender->mListInterfaces.push_back(CommandSendInterface);
50 return true; //todo: check if it worked
53 RoutingInterfaceBackdoor::RoutingInterfaceBackdoor() {
55 RoutingInterfaceBackdoor::~RoutingInterfaceBackdoor() {
58 bool RoutingInterfaceBackdoor::unloadPlugins(RoutingSender *RoutingSender) {
59 assert(RoutingSender != NULL);
60 RoutingSender->unloadLibraries();
61 RoutingSender->mListInterfaces.clear();
62 if (RoutingSender->mListInterfaces.empty())
67 bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender,
68 RoutingSendInterface *newInterface, const std::string& busname) {
69 assert(RoutingSender != NULL);
70 assert(newInterface != NULL);
72 RoutingSender::InterfaceNamePairs newInterfacePair;
73 newInterfacePair.routingInterface = newInterface;
74 newInterfacePair.busName = busname;
75 RoutingSender->mListInterfaces.push_back(newInterfacePair);
76 return true; //todo: check if it worked
79 ControlInterfaceBackdoor::ControlInterfaceBackdoor() {}
81 ControlInterfaceBackdoor::~ControlInterfaceBackdoor() {}
83 bool ControlInterfaceBackdoor::replaceController(ControlSender *controlSender, ControlSendInterface *newController)
85 controlSender->mController=newController;
90 int GetRandomNumber(int nLow, int nHigh) {
91 return (rand() % (nHigh - nLow + 1)) + nLow;
94 bool equalSoundProperty(const am_SoundProperty_s a,
95 const am_SoundProperty_s b) {
96 return (a.type == b.type && a.value == b.value);
99 bool equalMainSoundProperty(const am_MainSoundProperty_s a,
100 const am_MainSoundProperty_s b) {
101 return (a.type == b.type && a.value == b.value);
104 bool equalRoutingElement(const am_RoutingElement_s a,
105 const am_RoutingElement_s b) {
106 return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID
107 && a.sinkID == b.sinkID && a.sourceID == b.sourceID);
110 bool equalClassProperties(const am_ClassProperty_s a,
111 const am_ClassProperty_s b) {
112 return (a.classProperty == b.classProperty && a.value == b.value);
115 std::string int2string(int i) {
116 std::stringstream out;
121 bool CommonFunctions::compareSource(
122 std::vector<am_Source_s>::iterator listIterator,
123 const am_Source_s& sourceData) {
124 return (listIterator->available.availability
125 == sourceData.available.availability)
126 && (listIterator->available.availabilityReason
127 == sourceData.available.availabilityReason)
128 && (listIterator->sourceClassID == sourceData.sourceClassID)
129 && (listIterator->domainID == sourceData.domainID)
130 && (listIterator->interruptState == sourceData.interruptState)
131 && (listIterator->visible == sourceData.visible)
132 && (listIterator->name.compare(sourceData.name) == 0)
133 && (listIterator->volume == sourceData.volume)
134 && std::equal(listIterator->listConnectionFormats.begin(),
135 listIterator->listConnectionFormats.end(),
136 sourceData.listConnectionFormats.begin())
137 && std::equal(listIterator->listMainSoundProperties.begin(),
138 listIterator->listMainSoundProperties.end(),
139 sourceData.listMainSoundProperties.begin(),
140 equalMainSoundProperty)
141 && std::equal(listIterator->listSoundProperties.begin(),
142 listIterator->listSoundProperties.end(),
143 sourceData.listSoundProperties.begin(), equalSoundProperty);
146 bool CommonFunctions::compareSink(std::vector<am_Sink_s>::iterator listIterator,
147 const am_Sink_s& sinkData) {
148 return (listIterator->available.availability
149 == sinkData.available.availability)
150 && (listIterator->available.availabilityReason
151 == sinkData.available.availabilityReason)
152 && (listIterator->sinkClassID == sinkData.sinkClassID)
153 && (listIterator->domainID == sinkData.domainID)
154 && (listIterator->mainVolume == sinkData.mainVolume)
155 && (listIterator->muteState == sinkData.muteState)
156 && (listIterator->visible == sinkData.visible)
157 && (listIterator->name.compare(sinkData.name) == 0)
158 && (listIterator->volume == sinkData.volume)
159 && std::equal(listIterator->listConnectionFormats.begin(),
160 listIterator->listConnectionFormats.end(),
161 sinkData.listConnectionFormats.begin())
162 && std::equal(listIterator->listMainSoundProperties.begin(),
163 listIterator->listMainSoundProperties.end(),
164 sinkData.listMainSoundProperties.begin(),
165 equalMainSoundProperty)
166 && std::equal(listIterator->listSoundProperties.begin(),
167 listIterator->listSoundProperties.end(),
168 sinkData.listSoundProperties.begin(), equalSoundProperty);
171 bool CommonFunctions::compareGateway(
172 std::vector<am_Gateway_s>::iterator listIterator,
173 const am_Gateway_s& gatewayData) {
174 return (listIterator->name.compare(gatewayData.name) == 0)
175 && (listIterator->sinkID == gatewayData.sinkID)
176 && (listIterator->sourceID == gatewayData.sourceID)
177 && (listIterator->controlDomainID == gatewayData.controlDomainID)
178 && (listIterator->domainSinkID == gatewayData.domainSinkID)
179 && (listIterator->domainSourceID == gatewayData.domainSourceID)
180 && std::equal(listIterator->convertionMatrix.begin(),
181 listIterator->convertionMatrix.end(),
182 gatewayData.convertionMatrix.begin())
183 && std::equal(listIterator->listSourceFormats.begin(),
184 listIterator->listSourceFormats.end(),
185 gatewayData.listSourceFormats.begin())
186 && std::equal(listIterator->listSinkFormats.begin(),
187 listIterator->listSinkFormats.end(),
188 gatewayData.listSinkFormats.begin());
191 bool CommonFunctions::compareGateway1(const am_Gateway_s gateway1,
192 const am_Gateway_s gatewayData) {
193 return (gateway1.name.compare(gatewayData.name) == 0)
194 && (gateway1.sinkID == gatewayData.sinkID)
195 && (gateway1.sourceID == gatewayData.sourceID)
196 && (gateway1.controlDomainID == gatewayData.controlDomainID)
197 && (gateway1.domainSinkID == gatewayData.domainSinkID)
198 && (gateway1.domainSourceID == gatewayData.domainSourceID)
199 && std::equal(gateway1.convertionMatrix.begin(),
200 gateway1.convertionMatrix.end(),
201 gatewayData.convertionMatrix.begin())
202 && std::equal(gateway1.listSourceFormats.begin(),
203 gateway1.listSourceFormats.end(),
204 gatewayData.listSourceFormats.begin())
205 && std::equal(gateway1.listSinkFormats.begin(),
206 gateway1.listSinkFormats.end(),
207 gatewayData.listSinkFormats.begin());
210 bool CommonFunctions::compareSinkMainSink(
211 std::vector<am_SinkType_s>::iterator listIterator,
212 const std::vector<am_Sink_s>& sinkList) {
213 std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin();
214 for (; sinkListIterator < sinkList.end(); ++sinkListIterator) {
215 if (listIterator->sinkID == sinkListIterator->sinkID) {
216 return (listIterator->name.compare(sinkListIterator->name) == 0)
217 && (listIterator->availability.availability
218 == sinkListIterator->available.availability)
219 && (listIterator->availability.availabilityReason
220 == sinkListIterator->available.availabilityReason)
221 && (listIterator->muteState == sinkListIterator->muteState)
222 && (listIterator->volume == sinkListIterator->mainVolume)
223 && (listIterator->sinkClassID
224 == sinkListIterator->sinkClassID);
230 bool CommonFunctions::compareSinkMainSource(
231 std::vector<am_SourceType_s>::iterator listIterator,
232 const std::vector<am_Source_s>& sourceList) {
233 std::vector<am_Source_s>::const_iterator sinkListIterator =
235 for (; sinkListIterator < sourceList.end(); ++sinkListIterator) {
236 if (listIterator->sourceID == sinkListIterator->sourceID) {
237 return (listIterator->name.compare(sinkListIterator->name) == 0)
238 && (listIterator->availability.availability
239 == sinkListIterator->available.availability)
240 && (listIterator->availability.availabilityReason
241 == sinkListIterator->available.availabilityReason)
242 && (listIterator->sourceClassID
243 == sinkListIterator->sourceClassID);
249 std::vector<am_ConnectionFormat_e> CommonFunctions::getStandardConnectionFormatList() {
250 std::vector < am_ConnectionFormat_e > list;
251 list.push_back(CF_ANALOG);
252 list.push_back(CF_STEREO);
256 std::vector<am_SoundProperty_s> CommonFunctions::getStandardSoundPropertyList() {
257 std::vector < am_SoundProperty_s > soundPropertyList;
258 am_SoundProperty_s soundProperty;
259 soundProperty.type = SP_BASS;
260 soundProperty.value = 23;
261 soundPropertyList.push_back(soundProperty);
262 soundProperty.type = SP_MID;
263 soundProperty.value = 2;
264 soundPropertyList.push_back(soundProperty);
265 return soundPropertyList;
268 std::vector<am_MainSoundProperty_s> CommonFunctions::getStandardMainSoundPropertyList() {
269 std::vector < am_MainSoundProperty_s > mainSoundPropertyList;
270 am_MainSoundProperty_s mainSoundProperty;
271 mainSoundProperty.type = MSP_NAVIGATION_OFFSET;
272 mainSoundProperty.value = 23;
273 mainSoundPropertyList.push_back(mainSoundProperty);
274 mainSoundProperty.type = MSP_TEST;
275 mainSoundProperty.value = 3;
276 mainSoundPropertyList.push_back(mainSoundProperty);
277 return mainSoundPropertyList;
280 void CommonFunctions::createSink(am_Sink_s& sink) const {
281 sink.name = "AnySink";
283 sink.available.availability = A_AVAILABLE;
284 sink.available.availabilityReason = AR_NEWMEDIA;
285 sink.sinkClassID = 1;
286 sink.listConnectionFormats = getStandardConnectionFormatList();
287 sink.listSoundProperties = getStandardSoundPropertyList();
288 sink.listMainSoundProperties = getStandardMainSoundPropertyList();
289 sink.mainVolume = 12;
290 sink.muteState = MS_UNMUTED;
296 void CommonFunctions::createSource(am_Source_s& source) const {
297 source.name = "AnySource";
299 source.available.availability = A_AVAILABLE;
300 source.available.availabilityReason = AR_NEWMEDIA;
301 source.sourceClassID = 1;
302 source.listConnectionFormats = getStandardConnectionFormatList();
303 source.listSoundProperties = getStandardSoundPropertyList();
304 source.listMainSoundProperties = getStandardMainSoundPropertyList();
305 source.interruptState = IS_OFF;
306 source.visible = true;
309 source.sourceState = SS_ON;
312 void CommonFunctions::createDomain(am_Domain_s & domain) const {
315 domain.name = "AnyDomain";
316 domain.nodename = "AnyNode";
317 domain.busname = "AnyBusname";
318 domain.complete = true;
320 domain.state = DS_CONTROLLED;
323 void CommonFunctions::createGateway(am_Gateway_s & gateway) {
324 gateway.name = "AnyGateway";
326 gateway.sourceID = 2;
327 gateway.controlDomainID = 1;
328 gateway.domainSinkID = 3;
329 gateway.domainSourceID = 4;
330 gateway.convertionMatrix = getStandardConvertionMatrix();
331 gateway.listSourceFormats = getStandardConnectionFormatList();
332 gateway.listSinkFormats = getStandardConnectionFormatList();
333 gateway.gatewayID = 0;
337 void CommonFunctions::createConnection(am_Connection_s & connection) const {
338 connection.connectionID = 0;
339 connection.sinkID = 1;
340 connection.sourceID = 2;
341 connection.delay = -1;
342 connection.connectionFormat = CF_ANALOG;
345 void CommonFunctions::createMainConnection(am_MainConnection_s & mainConnection,
346 am_Route_s route) const {
347 mainConnection.connectionID = 0;
348 mainConnection.connectionState = CS_CONNECTED;
349 mainConnection.route = route;
350 mainConnection.delay = -1;
353 std::vector<bool> CommonFunctions::getStandardConvertionMatrix() {
354 std::vector<bool> convMatrix;
355 convMatrix.push_back(true);
356 convMatrix.push_back(false);
357 convMatrix.push_back(true);
358 convMatrix.push_back(false);
359 convMatrix.push_back(true);
360 convMatrix.push_back(true);
364 void CommonFunctions::connectionList2RoutingList(
365 std::vector<am_RoutingElement_s> & routingList,
366 const std::vector<am_Connection_s>& connectionList) {
367 am_RoutingElement_s routingElement;
368 std::vector<am_Connection_s>::const_iterator cIterator =
369 connectionList.begin();
370 for (; cIterator < connectionList.end(); ++cIterator) {
371 routingElement.sinkID = cIterator->sinkID;
372 routingElement.sourceID = cIterator->sourceID;
373 routingElement.connectionFormat = cIterator->connectionFormat;
374 routingElement.domainID = 4; //todo: make this test read out the real value
375 routingList.push_back(routingElement);