2 * Copyright (C) 2011, BMW AG
9 * \author Christian Müller (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 Müller 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.
34 #include "audioManagerIncludes.h"
36 const char* routingPluginDirectories[] = { "/home/christian/workspace/gitserver/build/plugins/routing"};
37 uint routingPluginDirectoriesCount = sizeof(routingPluginDirectories) / sizeof(routingPluginDirectories[0]);
45 void Router::registerDatabasehandler(DataBaseHandler* db_handler) {
46 m_dbHandler = db_handler;
49 bool Router::get_Route_from_Source_ID_to_Sink_ID(const bool onlyfree,
50 const source_t Source_ID, const sink_t Sink_ID,
51 std::list<genRoute_t>* ReturnList) {
53 domain_t Source_Domain = m_dbHandler->get_Domain_ID_from_Source_ID(
54 Source_ID); //first find out in which domains the source and sink are
55 domain_t Sink_Domain = m_dbHandler->get_Domain_ID_from_Sink_ID(Sink_ID);
57 if (Source_Domain == -1 || Sink_Domain == -1) {
59 } //if source or sink does not exists, exit here
61 RoutingTree routingtree(Source_Domain); //Build up a Tree from the Source_Domain to every other domain.
62 std::list<RoutingTreeItem*> flattree; //This list is the flat tree
63 std::list<RoutingTreeItem*> matchtree; //This List holds all TreeItems which have the right Domain Sink IDs
64 std::list<gateway_t> gwids; //holds all gateway ids of the route
65 genRoutingElement_t element;
66 std::list<genRoutingElement_t> actualRoutingElement;//intermediate list of current routing pairs
67 genRoute_t actualRoute; //holds the actual Route
68 source_t ReturnSource = 0;
69 sink_t ReturnSink = 0;
70 source_t LastSource = 0;
71 domain_t ReturnDomain = 0;
73 //TODO: kind of unclean. The separation between database and router could be better.
74 m_dbHandler->get_Domain_ID_Tree(onlyfree, &routingtree, &flattree); //Build up the tree out of the database as
76 //we go through the returned flattree and look for our sink, after that flattree holds only treeItems that match
77 for(std::list<RoutingTreeItem*>::iterator rTree=flattree.begin();rTree!=flattree.end();rTree++) {
78 RoutingTreeItem *p=*rTree;
79 if (p->returnDomainID() == Sink_Domain) {
80 matchtree.push_back(*rTree);
84 //No we need to trace back the routes for each entry in matchtree
85 for(std::list<RoutingTreeItem*>::iterator match=matchtree.begin(); match!=matchtree.end(); match++)
87 //getting the route for the actual item
88 actualRoute.len = routingtree.getRoute(*match, &gwids); //This gives only the Gateway IDs we need more
90 //go throught the gatewayids and get more information
91 for (std::list<gateway_t>::iterator i=gwids.begin(); i!=gwids.end();i++) {
92 m_dbHandler->get_Gateway_Source_Sink_Domain_ID_from_ID(*i, &ReturnSource, &ReturnSink,&ReturnDomain);
93 //first routing pair is source to ReturnSink of course;
95 // element.source = Source_ID;
96 // element.sink = ReturnSink;
97 // element.Domain_ID = Source_Domain;
101 // element.source = LastSource;
102 // element.sink = ReturnSink;
103 // element.Domain_ID = ReturnDomain;
105 actualRoutingElement.push_back(element);
106 LastSource = ReturnSource;
108 element.source = LastSource;
109 element.sink = Sink_ID;
110 element.Domain_ID = Sink_Domain;
111 actualRoutingElement.push_back(element);
113 actualRoute.Source_ID = Source_ID;
114 actualRoute.Sink_ID = Sink_ID;
115 actualRoute.route = actualRoutingElement;
116 ReturnList->push_back(actualRoute);
120 //TODO: return actual status !
123 RoutingTreeItem::RoutingTreeItem(const domain_t Domain_Id,
124 const gateway_t Gateway_Id, RoutingTreeItem *parent) {
126 m_domainID = Domain_Id;
127 m_gatewayID = Gateway_Id;
130 RoutingTreeItem::RoutingTreeItem() {
134 RoutingTreeItem::~RoutingTreeItem() {
135 for (std::list<RoutingTreeItem*>::iterator i=childItems.begin();i!=childItems.end();i++) {
140 void RoutingTreeItem::appendChild(RoutingTreeItem *item) {
141 childItems.push_back(item);
144 RoutingTreeItem *RoutingTreeItem::return_Parent() {
148 domain_t RoutingTreeItem::returnDomainID() {
152 gateway_t RoutingTreeItem::returnGatewayID() {
156 RoutingTree::RoutingTree(const domain_t Root_ID) :
157 m_rootItem(RoutingTreeItem(Root_ID)) {
160 RoutingTree::~RoutingTree() {
163 RoutingTreeItem* RoutingTree::insertItem(const domain_t Domain_ID,
164 const gateway_t Gateway_ID, RoutingTreeItem *parentItem) {
165 RoutingTreeItem *newTree = new RoutingTreeItem(Domain_ID, Gateway_ID,
167 parentItem->appendChild(newTree);
168 m_allChildList.push_back(newTree);
172 int RoutingTree::getRoute(RoutingTreeItem* Targetitem, std::list<gateway_t>* route) {
174 RoutingTreeItem *parentItem = Targetitem;
175 while (parentItem != &m_rootItem) {
176 route->push_front(parentItem->returnGatewayID());
178 parentItem = parentItem->return_Parent();
183 int RoutingTree::returnRootDomainID() {
184 return m_rootItem.returnDomainID();
187 RoutingTreeItem* RoutingTree::returnRootItem() {
192 void Bushandler::load_Bus_plugins() {
193 std::list<std::string> sharedLibraryNameList;
195 for (uint dirIndex = 0; dirIndex < routingPluginDirectoriesCount; ++dirIndex) {
196 const char* directoryName = routingPluginDirectories[dirIndex];
197 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for Routing in"),DLT_STRING(directoryName));
198 std::list<std::string> newList=m_core->getSharedLibrariesFromDirectory(directoryName);
199 sharedLibraryNameList.insert(sharedLibraryNameList.end(),newList.begin(),newList.end());
203 // iterate all communicator plugins and start them
204 std::list<std::string>::iterator iter = sharedLibraryNameList.begin();
205 std::list<std::string>::iterator iterEnd = sharedLibraryNameList.end();
207 for (; iter != iterEnd; ++iter)
209 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Loading Routing plugin"),DLT_STRING(iter->c_str()));
211 RoutingSendInterface* (*createFunc)();
212 createFunc = getCreateFunction<RoutingSendInterface*()>(*iter);
215 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
219 RoutingSendInterface* RoutingPlugin = createFunc();
222 if (!RoutingPlugin) {
223 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingPlugin initialization failed. Entry Function not callable"));
229 RoutingPlugin->return_BusName(BusName);
230 newBus.Name=std::string(BusName);
231 newBus.sendInterface=RoutingPlugin;
232 RoutingPlugin->startup_interface(m_receiver,m_core->returnDbusHandler());
233 DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin:"), DLT_STRING(BusName));
234 Busses.push_back(newBus);
238 void Bushandler::StartupInterfaces() {
239 std::list<Bus>::iterator busIter;
240 std::list<Bus>::iterator busStart=Busses.begin();
241 std::list<Bus>::iterator busEnd=Busses.end();
243 for (busIter=busStart;busIter!=busEnd;busIter++) {
244 busIter->sendInterface->system_ready();
245 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Bushandler:Started Interface"), DLT_STRING(busIter->Name.c_str()));
249 void Bushandler::registerReceiver(RoutingReceiver * receiver) {
250 m_receiver = receiver;
253 void Bushandler::registerCore (AudioManagerCore* core) {
257 RoutingSendInterface* Bushandler::getInterfaceforBus(std::string bus) {
259 * \todo this could be done more nicer and faster with a hash lookup or so.. worht it??
261 std::list<Bus>::iterator busIter;
262 std::list<Bus>::iterator busStart=Busses.begin();
263 std::list<Bus>::iterator busEnd=Busses.end();
265 for (busIter=busStart;busIter!=busEnd;busIter++) {
267 if (busIter->Name.compare(bus) == 0) {
268 return busIter->sendInterface;