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"
35 CommandInterfaceBackdoor::CommandInterfaceBackdoor()
38 CommandInterfaceBackdoor::~CommandInterfaceBackdoor()
42 bool CommandInterfaceBackdoor::unloadPlugins(CommandSender *CommandSender)
44 assert(CommandSender != NULL);
45 CommandSender->unloadLibraries();
46 CommandSender->mListInterfaces.clear();
47 if (CommandSender->mListInterfaces.empty())
52 bool CommandInterfaceBackdoor::injectInterface(CommandSender *CommandSender, CommandSendInterface *CommandSendInterface)
54 assert(CommandSender != NULL);
55 assert(CommandSendInterface != NULL);
56 CommandSender->mListInterfaces.push_back(CommandSendInterface);
57 return true; //todo: check if it worked
60 RoutingInterfaceBackdoor::RoutingInterfaceBackdoor()
63 RoutingInterfaceBackdoor::~RoutingInterfaceBackdoor()
67 bool RoutingInterfaceBackdoor::unloadPlugins(RoutingSender *RoutingSender)
69 assert(RoutingSender != NULL);
70 RoutingSender->unloadLibraries();
71 RoutingSender->mListInterfaces.clear();
72 if (RoutingSender->mListInterfaces.empty())
77 bool RoutingInterfaceBackdoor::injectInterface(RoutingSender *RoutingSender, RoutingSendInterface *newInterface, const std::string& busname)
79 assert(RoutingSender != NULL);
80 assert(newInterface != NULL);
82 RoutingSender::InterfaceNamePairs newInterfacePair;
83 newInterfacePair.routingInterface = newInterface;
84 newInterfacePair.busName = busname;
85 RoutingSender->mListInterfaces.push_back(newInterfacePair);
86 return true; //todo: check if it worked
89 ControlInterfaceBackdoor::ControlInterfaceBackdoor()
93 ControlInterfaceBackdoor::~ControlInterfaceBackdoor()
97 bool ControlInterfaceBackdoor::replaceController(ControlSender *controlSender, ControlSendInterface *newController)
99 controlSender->mController = newController;
103 //int GetRandomNumber(int nLow, int nHigh) {
104 // return (rand() % (nHigh - nLow + 1)) + nLow;
107 bool equalSoundProperty(const am_SoundProperty_s a, const am_SoundProperty_s b)
109 return (a.type == b.type && a.value == b.value);
112 bool equalMainSoundProperty(const am_MainSoundProperty_s a, const am_MainSoundProperty_s b)
114 return (a.type == b.type && a.value == b.value);
117 bool equalRoutingElement(const am_RoutingElement_s a, const am_RoutingElement_s b)
119 return (a.connectionFormat == b.connectionFormat && a.domainID == b.domainID && a.sinkID == b.sinkID && a.sourceID == b.sourceID);
122 bool equalClassProperties(const am_ClassProperty_s a, const am_ClassProperty_s b)
124 return (a.classProperty == b.classProperty && a.value == b.value);
127 std::string int2string(int i)
129 std::stringstream out;
134 bool CommonFunctions::compareSource(std::vector<am_Source_s>::iterator listIterator, const am_Source_s& sourceData)
136 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())
137 && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sourceData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sourceData.listSoundProperties.begin(), equalSoundProperty);
140 bool CommonFunctions::compareSink(std::vector<am_Sink_s>::iterator listIterator, const am_Sink_s& sinkData)
142 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())
143 && std::equal(listIterator->listMainSoundProperties.begin(), listIterator->listMainSoundProperties.end(), sinkData.listMainSoundProperties.begin(), equalMainSoundProperty) && std::equal(listIterator->listSoundProperties.begin(), listIterator->listSoundProperties.end(), sinkData.listSoundProperties.begin(), equalSoundProperty);
146 bool CommonFunctions::compareGateway(std::vector<am_Gateway_s>::iterator listIterator, const am_Gateway_s& gatewayData)
148 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());
151 bool CommonFunctions::compareGateway1(const am_Gateway_s gateway1, const am_Gateway_s gatewayData)
153 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());
156 bool CommonFunctions::compareSinkMainSink(std::vector<am_SinkType_s>::iterator listIterator, const std::vector<am_Sink_s>& sinkList)
158 std::vector<am_Sink_s>::const_iterator sinkListIterator = sinkList.begin();
159 for (; sinkListIterator < sinkList.end(); ++sinkListIterator)
161 if (listIterator->sinkID == sinkListIterator->sinkID)
163 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);
169 bool CommonFunctions::compareSinkMainSource(std::vector<am_SourceType_s>::iterator listIterator, const std::vector<am_Source_s>& sourceList)
171 std::vector<am_Source_s>::const_iterator sinkListIterator = sourceList.begin();
172 for (; sinkListIterator < sourceList.end(); ++sinkListIterator)
174 if (listIterator->sourceID == sinkListIterator->sourceID)
176 return (listIterator->name.compare(sinkListIterator->name) == 0) && (listIterator->availability.availability == sinkListIterator->available.availability) && (listIterator->availability.availabilityReason == sinkListIterator->available.availabilityReason) && (listIterator->sourceClassID == sinkListIterator->sourceClassID);
182 bool CommonFunctions::compareRoute(am_Route_s a, am_Route_s b)
185 std::vector<am_RoutingElement_s>::iterator itA = a.route.begin(), itB = b.route.begin();
186 retVal &= a.sourceID == b.sourceID;
187 retVal &= a.sinkID == b.sinkID;
188 for (; itA != a.route.end(); ++itA)
190 retVal &= itA->sinkID == itB->sinkID;
191 retVal &= itA->sourceID == itB->sourceID;
192 retVal &= itA->connectionFormat == itB->connectionFormat;
193 retVal &= itA->domainID == itB->domainID;
199 std::vector<am_ConnectionFormat_e> CommonFunctions::getStandardConnectionFormatList()
201 std::vector<am_ConnectionFormat_e> list;
202 list.push_back(CF_ANALOG);
203 list.push_back(CF_STEREO);
207 std::vector<am_SoundProperty_s> CommonFunctions::getStandardSoundPropertyList()
209 std::vector<am_SoundProperty_s> soundPropertyList;
210 am_SoundProperty_s soundProperty;
211 soundProperty.type = SP_BASS;
212 soundProperty.value = 23;
213 soundPropertyList.push_back(soundProperty);
214 soundProperty.type = SP_MID;
215 soundProperty.value = 2;
216 soundPropertyList.push_back(soundProperty);
217 return soundPropertyList;
220 std::vector<am_MainSoundProperty_s> CommonFunctions::getStandardMainSoundPropertyList()
222 std::vector<am_MainSoundProperty_s> mainSoundPropertyList;
223 am_MainSoundProperty_s mainSoundProperty;
224 mainSoundProperty.type = MSP_NAVIGATION_OFFSET;
225 mainSoundProperty.value = 23;
226 mainSoundPropertyList.push_back(mainSoundProperty);
227 mainSoundProperty.type = MSP_TEST;
228 mainSoundProperty.value = 3;
229 mainSoundPropertyList.push_back(mainSoundProperty);
230 return mainSoundPropertyList;
233 void CommonFunctions::createSink(am_Sink_s& sink) const
235 sink.name = "AnySink";
237 sink.available.availability = A_AVAILABLE;
238 sink.available.availabilityReason = AR_NEWMEDIA;
239 sink.sinkClassID = 1;
240 sink.listConnectionFormats = getStandardConnectionFormatList();
241 sink.listSoundProperties = getStandardSoundPropertyList();
242 sink.listMainSoundProperties = getStandardMainSoundPropertyList();
243 sink.mainVolume = 12;
244 sink.muteState = MS_UNMUTED;
250 void CommonFunctions::createSource(am_Source_s& source) const
252 source.name = "AnySource";
254 source.available.availability = A_AVAILABLE;
255 source.available.availabilityReason = AR_NEWMEDIA;
256 source.sourceClassID = 1;
257 source.listConnectionFormats = getStandardConnectionFormatList();
258 source.listSoundProperties = getStandardSoundPropertyList();
259 source.listMainSoundProperties = getStandardMainSoundPropertyList();
260 source.interruptState = IS_OFF;
261 source.visible = true;
264 source.sourceState = SS_ON;
267 void CommonFunctions::createDomain(am_Domain_s & domain) const
271 domain.name = "AnyDomain";
272 domain.nodename = "AnyNode";
273 domain.busname = "AnyBusname";
274 domain.complete = true;
276 domain.state = DS_CONTROLLED;
279 void CommonFunctions::createGateway(am_Gateway_s & gateway)
281 gateway.name = "AnyGateway";
283 gateway.sourceID = 2;
284 gateway.controlDomainID = 1;
285 gateway.domainSinkID = 3;
286 gateway.domainSourceID = 4;
287 gateway.convertionMatrix = getStandardConvertionMatrix();
288 gateway.listSourceFormats = getStandardConnectionFormatList();
289 gateway.listSinkFormats = getStandardConnectionFormatList();
290 gateway.gatewayID = 0;
294 void CommonFunctions::createConnection(am_Connection_s & connection) const
296 connection.connectionID = 0;
297 connection.sinkID = 1;
298 connection.sourceID = 2;
299 connection.delay = -1;
300 connection.connectionFormat = CF_ANALOG;
303 void CommonFunctions::createMainConnection(am_MainConnection_s & mainConnection, am_Route_s route) const
305 mainConnection.connectionID = 0;
306 mainConnection.connectionState = CS_CONNECTED;
307 mainConnection.route = route;
308 mainConnection.delay = -1;
311 std::vector<bool> CommonFunctions::getStandardConvertionMatrix()
313 std::vector<bool> convMatrix;
314 convMatrix.push_back(true);
315 convMatrix.push_back(false);
316 convMatrix.push_back(true);
317 convMatrix.push_back(false);
318 convMatrix.push_back(true);
319 convMatrix.push_back(true);
323 void CommonFunctions::connectionList2RoutingList(std::vector<am_RoutingElement_s> & routingList, const std::vector<am_Connection_s>& connectionList)
325 am_RoutingElement_s routingElement;
326 std::vector<am_Connection_s>::const_iterator cIterator = connectionList.begin();
327 for (; cIterator < connectionList.end(); ++cIterator)
329 routingElement.sinkID = cIterator->sinkID;
330 routingElement.sourceID = cIterator->sourceID;
331 routingElement.connectionFormat = cIterator->connectionFormat;
332 routingElement.domainID = 4; //todo: make this test read out the real value
333 routingList.push_back(routingElement);